feat(brightness suw): hide brightness preferences if restricted
By default if a RestrictedPreference is restricted then the preference
becomes disabled but still visible. But for brightness preferences in
A11y SUW we'd like to hide them if they're restricted and disabled,
since it's meaningless to show disabled items in SUW.
To achieve this, in PreferenceController#displayPreference we check the
whether the preference is RestrictedPreference and restricted, so we can
decide whether to hide it. Besides, if the preference is restricted and
we hide it, in PreferenceController#getAvailableStatis we also return
CONDITIONALLY_UNAVAILABLE to make consistency.
Bug: 384620216
Flag: com.android.settings.accessibility.add_brightness_settings_in_suw
Test: manually
atest AutoBrightnessPreferenceControllerForSetupWizardTest
atest BrightnessLevelPreferenceControllerForSetupWizardTest
Change-Id: Ifb68b4d64fc111d91a23457882a006002173d232
This commit is contained in:
@@ -19,8 +19,12 @@ package com.android.settings.display;
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.accessibility.Flags;
|
||||
import com.android.settingslib.RestrictedPreferenceHelper;
|
||||
import com.android.settingslib.RestrictedPreferenceHelperProvider;
|
||||
|
||||
/**
|
||||
* The top-level preference controller that updates the adaptive brightness in the SetupWizard.
|
||||
@@ -28,15 +32,35 @@ import com.android.settings.accessibility.Flags;
|
||||
public class AutoBrightnessPreferenceControllerForSetupWizard
|
||||
extends AutoBrightnessPreferenceController {
|
||||
|
||||
private RestrictedPreferenceHelper mRestrictedPreferenceHelper;
|
||||
|
||||
public AutoBrightnessPreferenceControllerForSetupWizard(@NonNull Context context,
|
||||
@NonNull String key) {
|
||||
super(context, key);
|
||||
}
|
||||
|
||||
private boolean isRestricted() {
|
||||
if (mRestrictedPreferenceHelper == null) {
|
||||
return false;
|
||||
}
|
||||
return mRestrictedPreferenceHelper.isDisabledByAdmin()
|
||||
|| mRestrictedPreferenceHelper.isDisabledByEcm();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
Preference preference = screen.findPreference(getPreferenceKey());
|
||||
if (preference instanceof RestrictedPreferenceHelperProvider helperProvider) {
|
||||
mRestrictedPreferenceHelper = helperProvider.getRestrictedPreferenceHelper();
|
||||
preference.setVisible(!isRestricted());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@AvailabilityStatus
|
||||
public int getAvailabilityStatus() {
|
||||
if (!Flags.addBrightnessSettingsInSuw()) {
|
||||
if (!Flags.addBrightnessSettingsInSuw() || isRestricted()) {
|
||||
return CONDITIONALLY_UNAVAILABLE;
|
||||
}
|
||||
return super.getAvailabilityStatus();
|
||||
|
||||
Reference in New Issue
Block a user