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 android.support.annotation.StringRes; 24 import com.android.documentsui.R; 25 import com.android.documentsui.base.DocumentInfo; 26 import com.android.documentsui.roots.ProvidersAccess; 27 28 /** 29 * Model for showing information about a document's provider. 30 */ 31 public final class ShowInProviderAction extends Action { 32 33 private ProvidersAccess mProviders; 34 35 public ShowInProviderAction(Context context, PackageManager pm, DocumentInfo doc, 36 ProvidersAccess providers) { 37 super(context, pm, doc); 38 assert providers != null; 39 mProviders = providers; 40 } 41 42 /** 43 * @return the header of this action. In English it would be "This file belongs to" 44 */ 45 @Override 46 public String getHeader() { 47 return mContext.getString(R.string.handler_app_belongs_to); 48 } 49 50 @Override 51 public int getButtonIcon() { 52 return R.drawable.ic_action_open; 53 } 54 55 /** 56 * Checks if this documents supports opening in the provider. 57 */ 58 @Override 59 public boolean canPerformAction() { 60 if ((mDoc.flags & FLAG_SUPPORTS_SETTINGS) != 0) { 61 return true; 62 } else { 63 return false; 64 } 65 } 66 67 @Override 68 public String getPackageName() { 69 return mProviders.getPackageName(mDoc.derivedUri.getAuthority()); 70 } 71 72 public @StringRes int getButtonLabel() { 73 return R.string.button_show_provider; 74 } 75 }