• 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 
17 package com.android.settings.applications.appinfo;
18 
19 import android.content.Context;
20 import android.content.Intent;
21 import android.os.UserManager;
22 
23 import androidx.preference.Preference;
24 
25 import com.android.settings.R;
26 import com.android.settings.Utils;
27 import com.android.settings.applications.AppStoreUtil;
28 import com.android.settingslib.applications.AppUtils;
29 
30 public class AppInstallerInfoPreferenceController extends AppInfoPreferenceControllerBase {
31 
32     private String mPackageName;
33     private String mInstallerPackage;
34     private CharSequence mInstallerLabel;
35 
AppInstallerInfoPreferenceController(Context context, String key)36     public AppInstallerInfoPreferenceController(Context context, String key) {
37         super(context, key);
38     }
39 
40     @Override
getAvailabilityStatus()41     public int getAvailabilityStatus() {
42         if (UserManager.get(mContext).isManagedProfile()) {
43             return DISABLED_FOR_USER;
44         }
45 
46         if (AppUtils.isMainlineModule(mContext.getPackageManager(), mPackageName)) {
47             return DISABLED_FOR_USER;
48         }
49 
50         return mInstallerLabel != null ? AVAILABLE : DISABLED_FOR_USER;
51     }
52 
53     @Override
updateState(Preference preference)54     public void updateState(Preference preference) {
55         final int detailsStringId = AppUtils.isInstant(mParent.getPackageInfo().applicationInfo)
56                 ? R.string.instant_app_details_summary
57                 : R.string.app_install_details_summary;
58         preference.setSummary(mContext.getString(detailsStringId, mInstallerLabel));
59 
60         Intent intent = AppStoreUtil.getAppStoreLink(mContext, mInstallerPackage, mPackageName);
61         if (intent != null) {
62             preference.setIntent(intent);
63         } else {
64             preference.setEnabled(false);
65         }
66     }
67 
setPackageName(String packageName)68     public void setPackageName(String packageName) {
69         mPackageName = packageName;
70         mInstallerPackage = AppStoreUtil.getInstallerPackageName(mContext, mPackageName);
71         mInstallerLabel = Utils.getApplicationLabel(mContext, mInstallerPackage);
72     }
73 }
74