Merge "(Re)Introduce "enabled by admin" UI state"
This commit is contained in:
@@ -53,16 +53,25 @@ public class AutoTimePreferenceController extends AbstractPreferenceController
|
|||||||
getTimeCapabilitiesAndConfig().getCapabilities();
|
getTimeCapabilitiesAndConfig().getCapabilities();
|
||||||
int capability = timeCapabilities.getConfigureAutoDetectionEnabledCapability();
|
int capability = timeCapabilities.getConfigureAutoDetectionEnabledCapability();
|
||||||
|
|
||||||
// The preference only has two states: present and not present. The preference is never
|
// The preference has three states: visible, not visible, and visible but disabled.
|
||||||
// present but disabled.
|
// This method handles the "is visible?" check.
|
||||||
if (capability == CAPABILITY_NOT_SUPPORTED
|
switch (capability) {
|
||||||
|| capability == CAPABILITY_NOT_ALLOWED
|
case CAPABILITY_NOT_SUPPORTED:
|
||||||
|| capability == CAPABILITY_NOT_APPLICABLE) {
|
return false;
|
||||||
return false;
|
case CAPABILITY_POSSESSED:
|
||||||
} else if (capability == CAPABILITY_POSSESSED) {
|
return true;
|
||||||
return true;
|
case CAPABILITY_NOT_ALLOWED:
|
||||||
} else {
|
// This case is expected for enterprise restrictions, where the toggle should be
|
||||||
throw new IllegalStateException("Unknown capability=" + capability);
|
// 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)) {
|
if (!(preference instanceof SwitchPreference)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
((SwitchPreference) preference).setChecked(isEnabled());
|
((SwitchPreference) preference).setChecked(isEnabled());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,11 +27,11 @@ import android.app.time.TimeZoneCapabilitiesAndConfig;
|
|||||||
import android.app.time.TimeZoneConfiguration;
|
import android.app.time.TimeZoneConfiguration;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
import androidx.annotation.VisibleForTesting;
|
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
import androidx.preference.SwitchPreference;
|
import androidx.preference.SwitchPreference;
|
||||||
|
|
||||||
|
import com.android.internal.annotations.VisibleForTesting;
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.core.PreferenceControllerMixin;
|
import com.android.settings.core.PreferenceControllerMixin;
|
||||||
import com.android.settingslib.core.AbstractPreferenceController;
|
import com.android.settingslib.core.AbstractPreferenceController;
|
||||||
@@ -63,16 +63,25 @@ public class AutoTimeZonePreferenceController extends AbstractPreferenceControll
|
|||||||
getTimeZoneCapabilitiesAndConfig().getCapabilities();
|
getTimeZoneCapabilitiesAndConfig().getCapabilities();
|
||||||
int capability = timeZoneCapabilities.getConfigureAutoDetectionEnabledCapability();
|
int capability = timeZoneCapabilities.getConfigureAutoDetectionEnabledCapability();
|
||||||
|
|
||||||
// The preference only has two states: present and not present. The preference is never
|
// The preference has three states: visible, not visible, and visible but disabled.
|
||||||
// present but disabled.
|
// This method handles the "is visible?" check.
|
||||||
if (capability == CAPABILITY_NOT_SUPPORTED
|
switch (capability) {
|
||||||
|| capability == CAPABILITY_NOT_ALLOWED
|
case CAPABILITY_NOT_SUPPORTED:
|
||||||
|| capability == CAPABILITY_NOT_APPLICABLE) {
|
return false;
|
||||||
return false;
|
case CAPABILITY_POSSESSED:
|
||||||
} else if (capability == CAPABILITY_POSSESSED) {
|
return true;
|
||||||
return true;
|
case CAPABILITY_NOT_ALLOWED:
|
||||||
} else {
|
// This case is expected for enterprise restrictions, where the toggle should be
|
||||||
throw new IllegalStateException("Unknown capability=" + capability);
|
// 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)) {
|
if (!(preference instanceof SwitchPreference)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
((SwitchPreference) preference).setChecked(isEnabled());
|
((SwitchPreference) preference).setChecked(isEnabled());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user