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.content.pm.PackageInfo; 21 22 import androidx.annotation.VisibleForTesting; 23 import androidx.preference.Preference; 24 25 import com.android.settings.SettingsPreferenceFragment; 26 import com.android.settings.applications.AppStateAlarmsAndRemindersBridge; 27 28 /** 29 * Preference controller for 30 * {@link com.android.settings.applications.appinfo.AlarmsAndRemindersDetails} Settings fragment. 31 */ 32 public class AlarmsAndRemindersDetailPreferenceController extends AppInfoPreferenceControllerBase { 33 34 private String mPackageName; 35 AlarmsAndRemindersDetailPreferenceController(Context context, String key)36 public AlarmsAndRemindersDetailPreferenceController(Context context, String key) { 37 super(context, key); 38 } 39 40 @Override getAvailabilityStatus()41 public int getAvailabilityStatus() { 42 return isCandidate() ? AVAILABLE : CONDITIONALLY_UNAVAILABLE; 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 AlarmsAndRemindersDetails.class; 53 } 54 55 @VisibleForTesting getPreferenceSummary()56 CharSequence getPreferenceSummary() { 57 return AlarmsAndRemindersDetails.getSummary(mContext, mParent.getAppEntry()); 58 } 59 60 @VisibleForTesting isCandidate()61 boolean isCandidate() { 62 final PackageInfo packageInfo = mParent.getPackageInfo(); 63 if (packageInfo == null) { 64 return false; 65 } 66 final AppStateAlarmsAndRemindersBridge.AlarmsAndRemindersState appState = 67 new AppStateAlarmsAndRemindersBridge(mContext, null, null).createPermissionState( 68 mPackageName, packageInfo.applicationInfo.uid); 69 return appState.shouldBeVisible(); 70 } 71 setPackageName(String packageName)72 void setPackageName(String packageName) { 73 mPackageName = packageName; 74 } 75 } 76