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