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.pm.PackageInfo; 21 import android.os.UserManager; 22 23 import androidx.annotation.VisibleForTesting; 24 import androidx.preference.Preference; 25 26 import com.android.settings.SettingsPreferenceFragment; 27 import com.android.settings.applications.AppStateInstallAppsBridge; 28 29 public class ExternalSourceDetailPreferenceController extends AppInfoPreferenceControllerBase { 30 31 private String mPackageName; 32 ExternalSourceDetailPreferenceController(Context context, String key)33 public ExternalSourceDetailPreferenceController(Context context, String key) { 34 super(context, key); 35 } 36 37 @Override getAvailabilityStatus()38 public int getAvailabilityStatus() { 39 if (UserManager.get(mContext).isManagedProfile()) { 40 return DISABLED_FOR_USER; 41 } 42 return isPotentialAppSource() ? AVAILABLE : DISABLED_FOR_USER; 43 } 44 45 @Override updateState(Preference preference)46 public void updateState(Preference preference) { 47 preference.setSummary(getPreferenceSummary()); 48 } 49 50 @Override getDetailFragmentClass()51 protected Class<? extends SettingsPreferenceFragment> getDetailFragmentClass() { 52 return ExternalSourcesDetails.class; 53 } 54 55 @VisibleForTesting getPreferenceSummary()56 CharSequence getPreferenceSummary() { 57 return ExternalSourcesDetails.getPreferenceSummary(mContext, mParent.getAppEntry()); 58 } 59 60 @VisibleForTesting isPotentialAppSource()61 boolean isPotentialAppSource() { 62 final PackageInfo packageInfo = mParent.getPackageInfo(); 63 if (packageInfo == null) { 64 return false; 65 } 66 AppStateInstallAppsBridge.InstallAppsState appState = 67 new AppStateInstallAppsBridge(mContext, null, null).createInstallAppsStateFor( 68 mPackageName, packageInfo.applicationInfo.uid); 69 return appState.isPotentialAppSource(); 70 } 71 setPackageName(String packageName)72 public void setPackageName(String packageName) { 73 mPackageName = packageName; 74 } 75 } 76