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:
Roy Chou
2024-12-17 06:00:49 +00:00
parent d5d59630b5
commit 79632a9fc5
4 changed files with 164 additions and 16 deletions

View File

@@ -20,8 +20,12 @@ import android.content.Context;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.settings.accessibility.Flags;
import com.android.settingslib.RestrictedPreferenceHelper;
import com.android.settingslib.RestrictedPreferenceHelperProvider;
import com.android.settingslib.core.lifecycle.Lifecycle;
/**
@@ -31,15 +35,35 @@ import com.android.settingslib.core.lifecycle.Lifecycle;
public class BrightnessLevelPreferenceControllerForSetupWizard extends
BrightnessLevelPreferenceController {
private RestrictedPreferenceHelper mRestrictedPreferenceHelper;
public BrightnessLevelPreferenceControllerForSetupWizard(@NonNull Context context,
@Nullable Lifecycle lifecycle) {
super(context, lifecycle);
}
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();