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