1 /* 2 * Copyright (C) 2021 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.text.TextUtils; 21 22 import androidx.preference.Preference; 23 import androidx.preference.PreferenceScreen; 24 25 import com.android.settings.core.BasePreferenceController; 26 import com.android.settings.overlay.FeatureFactory; 27 28 /** Contains logic that deals with showing extra app info in app settings. */ 29 public class ExtraAppInfoPreferenceController extends BasePreferenceController { 30 31 private final ExtraAppInfoFeatureProvider mExtraAppInfoFeatureProvider; 32 ExtraAppInfoPreferenceController(Context context, String key)33 public ExtraAppInfoPreferenceController(Context context, String key) { 34 super(context, key); 35 mExtraAppInfoFeatureProvider = 36 FeatureFactory.getFactory(context).getExtraAppInfoFeatureProvider(); 37 } 38 39 @Override getAvailabilityStatus()40 public int getAvailabilityStatus() { 41 return mExtraAppInfoFeatureProvider.isSupported(mContext) 42 ? AVAILABLE : UNSUPPORTED_ON_DEVICE; 43 } 44 45 @Override handlePreferenceTreeClick(Preference preference)46 public boolean handlePreferenceTreeClick(Preference preference) { 47 if (TextUtils.equals(getPreferenceKey(), preference.getKey())) { 48 mExtraAppInfoFeatureProvider.launchExtraAppInfoSettings(mContext); 49 return true; 50 } 51 return super.handlePreferenceTreeClick(preference); 52 } 53 54 @Override getSummary()55 public CharSequence getSummary() { 56 return mExtraAppInfoFeatureProvider.getSummary(mContext); 57 } 58 59 @Override displayPreference(PreferenceScreen screen)60 public void displayPreference(PreferenceScreen screen) { 61 super.displayPreference(screen); 62 63 if (mExtraAppInfoFeatureProvider != null) { 64 final Preference preference = screen.findPreference(getPreferenceKey()); 65 preference.setEnabled(mExtraAppInfoFeatureProvider.isEnabled(preference.getContext())); 66 } 67 } 68 69 /** 70 * Set the local package name 71 */ setPackageName(String packageName)72 public void setPackageName(String packageName) { 73 if (mExtraAppInfoFeatureProvider != null) { 74 mExtraAppInfoFeatureProvider.setPackageName(packageName); 75 } 76 } 77 } 78