• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 androidx.annotation.StringRes;
19 import android.content.Context;
20 import android.content.Intent;
21 import android.content.pm.PackageManager;
22 import android.content.pm.ResolveInfo;
23 
24 import com.android.documentsui.R;
25 import com.android.documentsui.base.DocumentInfo;
26 
27 import java.util.List;
28 
29 /**
30  * Model for clearing the default app that opens a file.
31  */
32 public final class ClearDefaultAppAction extends Action {
33 
ClearDefaultAppAction(Context context, PackageManager pm, DocumentInfo doc)34     public ClearDefaultAppAction(Context context, PackageManager pm, DocumentInfo doc) {
35         super(context, pm, doc);
36     }
37 
38     /**
39      * @return the header for this action. In English it would be "This file opens with"
40      */
41     @Override
getHeader()42     public String getHeader() {
43         return mContext.getString(R.string.handler_app_file_opens_with);
44     }
45 
46     @Override
getButtonIcon()47     public int getButtonIcon() {
48         return R.drawable.ic_action_clear;
49     }
50 
51     /**
52      * Checks if we can clear the default app to open a file.
53      *
54      * @return true if we can clear, false if we can't clear.
55      */
56     @Override
canPerformAction()57     public boolean canPerformAction() {
58         return false;
59     }
60 
61     @Override
getPackageName()62     public String getPackageName() {
63 
64         Intent intent = new Intent(Intent.ACTION_VIEW, mDoc.derivedUri);
65         ResolveInfo resolveInfo = mPm.resolveActivity(intent, 0);
66 
67         if (resolveInfo != null && resolveInfo.activityInfo != null) {
68             return resolveInfo.activityInfo.packageName;
69         } else {
70             return null;
71         }
72     }
73 
getButtonLabel()74     public @StringRes int getButtonLabel() {
75         return R.string.button_clear;
76     }
77 }