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