From 8e727b4dba5aa46b1ea164572bbc82ae061f1088 Mon Sep 17 00:00:00 2001 From: Neil Fuller Date: Mon, 30 Jan 2023 16:51:56 +0000 Subject: [PATCH] (Re)Introduce "enabled by admin" UI state (Re)Introduce "enabled by admin" / "disabled by admin" SettingsUI state. ag/18665634 changed behavior: When enterprise policy restricts the user's ability to change the "auto time" and "auto time zone" toggle, the toggle was hidden rather than "visible but disabled". Bug 266693620 demonstrates testers are checking for the behavior. This commit returns the old behavior for the "auto time" and "auto time zone" SettingUI behavior, i.e. the user can see the toggle and its setting value, but is told that it is under admin control and the current setting value. See the bug for more info / historic behavior analysis. Bug: 266693620 Test: Manual testing with TestDPC Test: atest to confirm existing tests do not fail Change-Id: I0a605054312547fbd44fc34025ee36b075e05e01 --- .../AutoTimePreferenceController.java | 30 +++++++++++------ .../AutoTimeZonePreferenceController.java | 32 ++++++++++++------- 2 files changed, 41 insertions(+), 21 deletions(-) diff --git a/src/com/android/settings/datetime/AutoTimePreferenceController.java b/src/com/android/settings/datetime/AutoTimePreferenceController.java index 8e54a9e968f..2b158e08a3d 100644 --- a/src/com/android/settings/datetime/AutoTimePreferenceController.java +++ b/src/com/android/settings/datetime/AutoTimePreferenceController.java @@ -53,16 +53,25 @@ public class AutoTimePreferenceController extends AbstractPreferenceController getTimeCapabilitiesAndConfig().getCapabilities(); int capability = timeCapabilities.getConfigureAutoDetectionEnabledCapability(); - // The preference only has two states: present and not present. The preference is never - // present but disabled. - if (capability == CAPABILITY_NOT_SUPPORTED - || capability == CAPABILITY_NOT_ALLOWED - || capability == CAPABILITY_NOT_APPLICABLE) { - return false; - } else if (capability == CAPABILITY_POSSESSED) { - return true; - } else { - throw new IllegalStateException("Unknown capability=" + capability); + // The preference has three states: visible, not visible, and visible but disabled. + // This method handles the "is visible?" check. + switch (capability) { + case CAPABILITY_NOT_SUPPORTED: + return false; + case CAPABILITY_POSSESSED: + return true; + case CAPABILITY_NOT_ALLOWED: + // This case is expected for enterprise restrictions, where the toggle should be + // present but disabled. Disabling is handled declaratively via the + // settings:userRestriction attribute in .xml. The client-side logic is expected to + // concur with the capabilities logic in the system server. + return true; + case CAPABILITY_NOT_APPLICABLE: + // CAPABILITY_NOT_APPLICABLE is not currently expected, so this is return value is + // arbitrary. + return true; + default: + throw new IllegalStateException("Unknown capability=" + capability); } } @@ -71,6 +80,7 @@ public class AutoTimePreferenceController extends AbstractPreferenceController if (!(preference instanceof SwitchPreference)) { return; } + ((SwitchPreference) preference).setChecked(isEnabled()); } diff --git a/src/com/android/settings/datetime/AutoTimeZonePreferenceController.java b/src/com/android/settings/datetime/AutoTimeZonePreferenceController.java index a4d745b8e50..7d1c1b65a27 100644 --- a/src/com/android/settings/datetime/AutoTimeZonePreferenceController.java +++ b/src/com/android/settings/datetime/AutoTimeZonePreferenceController.java @@ -27,11 +27,11 @@ import android.app.time.TimeZoneCapabilitiesAndConfig; import android.app.time.TimeZoneConfiguration; import android.content.Context; -import androidx.annotation.VisibleForTesting; import androidx.preference.Preference; import androidx.preference.PreferenceScreen; import androidx.preference.SwitchPreference; +import com.android.internal.annotations.VisibleForTesting; import com.android.settings.R; import com.android.settings.core.PreferenceControllerMixin; import com.android.settingslib.core.AbstractPreferenceController; @@ -63,16 +63,25 @@ public class AutoTimeZonePreferenceController extends AbstractPreferenceControll getTimeZoneCapabilitiesAndConfig().getCapabilities(); int capability = timeZoneCapabilities.getConfigureAutoDetectionEnabledCapability(); - // The preference only has two states: present and not present. The preference is never - // present but disabled. - if (capability == CAPABILITY_NOT_SUPPORTED - || capability == CAPABILITY_NOT_ALLOWED - || capability == CAPABILITY_NOT_APPLICABLE) { - return false; - } else if (capability == CAPABILITY_POSSESSED) { - return true; - } else { - throw new IllegalStateException("Unknown capability=" + capability); + // The preference has three states: visible, not visible, and visible but disabled. + // This method handles the "is visible?" check. + switch (capability) { + case CAPABILITY_NOT_SUPPORTED: + return false; + case CAPABILITY_POSSESSED: + return true; + case CAPABILITY_NOT_ALLOWED: + // This case is expected for enterprise restrictions, where the toggle should be + // present but disabled. Disabling is handled declaratively via the + // settings:userRestriction attribute in .xml. The client-side logic is expected to + // concur with the capabilities logic in the system server. + return true; + case CAPABILITY_NOT_APPLICABLE: + // CAPABILITY_NOT_APPLICABLE is not currently expected, so this is return value is + // arbitrary. + return true; + default: + throw new IllegalStateException("Unknown capability=" + capability); } } @@ -86,6 +95,7 @@ public class AutoTimeZonePreferenceController extends AbstractPreferenceControll if (!(preference instanceof SwitchPreference)) { return; } + ((SwitchPreference) preference).setChecked(isEnabled()); }