Fix 2582241: Update selection based on user setting instead.
When the user adds a DPM, Settings removes all display
timeout options with t > maxTimeout. It was incorrectly
setting the preference to maxTimeout.
The corrected code picks the user's preference if less
than maxTimeout or nothing otherwise.
Change-Id: I5a47fdce89f4cf216fd76bb585c3c0120b39db92
diff --git a/src/com/android/settings/DisplaySettings.java b/src/com/android/settings/DisplaySettings.java
index 813df00..fbb07c1 100644
--- a/src/com/android/settings/DisplaySettings.java
+++ b/src/com/android/settings/DisplaySettings.java
@@ -74,9 +74,9 @@
}
private void disableUnusableTimeouts(ListPreference screenTimeoutPreference) {
- DevicePolicyManager dpm =
+ final DevicePolicyManager dpm =
(DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
- long maxTimeout = dpm != null ? dpm.getMaximumTimeToLock(null) : 0;
+ final long maxTimeout = dpm != null ? dpm.getMaximumTimeToLock(null) : 0;
if (maxTimeout == 0) {
return; // policy not enforced
}
@@ -96,7 +96,14 @@
revisedEntries.toArray(new CharSequence[revisedEntries.size()]));
screenTimeoutPreference.setEntryValues(
revisedValues.toArray(new CharSequence[revisedValues.size()]));
- screenTimeoutPreference.setValue(String.valueOf(maxTimeout));
+ final int userPreference = Integer.valueOf(screenTimeoutPreference.getValue());
+ if (userPreference <= maxTimeout) {
+ screenTimeoutPreference.setValue(String.valueOf(userPreference));
+ } else {
+ // There will be no highlighted selection since nothing in the list matches
+ // maxTimeout. The user can still select anything less than maxTimeout.
+ // TODO: maybe append maxTimeout to the list and mark selected.
+ }
}
screenTimeoutPreference.setEnabled(revisedEntries.size() > 0);
}