1 /* 2 * Copyright (C) 2022 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.display; 18 19 import android.content.Context; 20 import android.provider.Settings; 21 22 import androidx.preference.Preference; 23 import androidx.preference.PreferenceScreen; 24 25 import com.android.settings.R; 26 import com.android.settings.core.TogglePreferenceController; 27 28 /** 29 * Preference for requiring authorization to use home controls for certain devices. 30 */ 31 public class ControlsTrivialPrivacyPreferenceController extends TogglePreferenceController { 32 33 private static final String SETTING_KEY = Settings.Secure.LOCKSCREEN_ALLOW_TRIVIAL_CONTROLS; 34 private static final String DEPENDENCY_SETTING_KEY = Settings.Secure.LOCKSCREEN_SHOW_CONTROLS; 35 ControlsTrivialPrivacyPreferenceController(Context context, String preferenceKey)36 public ControlsTrivialPrivacyPreferenceController(Context context, String preferenceKey) { 37 super(context, preferenceKey); 38 } 39 40 @Override isChecked()41 public boolean isChecked() { 42 return Settings.Secure.getInt(mContext.getContentResolver(), SETTING_KEY, 0) != 0; 43 } 44 45 @Override setChecked(boolean isChecked)46 public boolean setChecked(boolean isChecked) { 47 return Settings.Secure.putInt(mContext.getContentResolver(), SETTING_KEY, 48 isChecked ? 1 : 0); 49 } 50 51 @Override getSummary()52 public CharSequence getSummary() { 53 if (!CustomizableLockScreenUtils.isFeatureEnabled(mContext) 54 && getAvailabilityStatus() == DISABLED_DEPENDENT_SETTING) { 55 return mContext.getText(R.string.lockscreen_trivial_disabled_controls_summary); 56 } 57 58 return mContext.getText(R.string.lockscreen_trivial_controls_summary); 59 } 60 61 @Override updateState(Preference preference)62 public void updateState(Preference preference) { 63 super.updateState(preference); 64 preference.setEnabled(getAvailabilityStatus() != DISABLED_DEPENDENT_SETTING); 65 refreshSummary(preference); 66 } 67 68 @Override getSliceHighlightMenuRes()69 public int getSliceHighlightMenuRes() { 70 return R.string.menu_key_display; 71 } 72 73 @Override getAvailabilityStatus()74 public int getAvailabilityStatus() { 75 return showDeviceControlsSettingsEnabled() ? AVAILABLE : DISABLED_DEPENDENT_SETTING; 76 } 77 showDeviceControlsSettingsEnabled()78 private boolean showDeviceControlsSettingsEnabled() { 79 return CustomizableLockScreenUtils.isFeatureEnabled(mContext) 80 || Settings.Secure.getInt( 81 mContext.getContentResolver(), DEPENDENCY_SETTING_KEY, 0) != 0; 82 } 83 84 @Override displayPreference(PreferenceScreen screen)85 public void displayPreference(PreferenceScreen screen) { 86 super.displayPreference(screen); 87 if (CustomizableLockScreenUtils.isFeatureEnabled(mContext)) { 88 return; 89 } 90 91 Preference currentPreference = screen.findPreference(getPreferenceKey()); 92 currentPreference.setDependency("lockscreen_privacy_controls_switch"); 93 } 94 } 95