1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.android.documentsui.inspector.actions; 17 18 import static android.provider.DocumentsContract.Document.FLAG_SUPPORTS_SETTINGS; 19 20 import android.content.Context; 21 import android.content.pm.PackageManager; 22 23 import androidx.annotation.StringRes; 24 25 import com.android.documentsui.R; 26 import com.android.documentsui.base.DocumentInfo; 27 import com.android.documentsui.roots.ProvidersAccess; 28 29 /** 30 * Model for showing information about a document's provider. 31 */ 32 public final class ShowInProviderAction extends Action { 33 34 private ProvidersAccess mProviders; 35 ShowInProviderAction(Context context, PackageManager pm, DocumentInfo doc, ProvidersAccess providers)36 public ShowInProviderAction(Context context, PackageManager pm, DocumentInfo doc, 37 ProvidersAccess providers) { 38 super(context, pm, doc); 39 assert providers != null; 40 mProviders = providers; 41 } 42 43 /** 44 * @return the header of this action. In English it would be "This file belongs to" 45 */ 46 @Override getHeader()47 public String getHeader() { 48 return mContext.getString(R.string.handler_app_belongs_to); 49 } 50 51 @Override getButtonIcon()52 public int getButtonIcon() { 53 return R.drawable.ic_action_open; 54 } 55 56 /** 57 * Checks if this documents supports opening in the provider. 58 */ 59 @Override canPerformAction()60 public boolean canPerformAction() { 61 if ((mDoc.flags & FLAG_SUPPORTS_SETTINGS) != 0) { 62 return true; 63 } else { 64 return false; 65 } 66 } 67 68 @Override getPackageName()69 public String getPackageName() { 70 return mProviders.getPackageName(mDoc.userId, mDoc.derivedUri.getAuthority()); 71 } 72 getButtonLabel()73 public @StringRes int getButtonLabel() { 74 return R.string.button_show_provider; 75 } 76 }