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
This commit is contained in:
Jim Miller
2010-04-13 15:31:41 -07:00
parent fced126829
commit fc5a02225e

View File

@@ -74,9 +74,9 @@ public class DisplaySettings extends PreferenceActivity implements
} }
private void disableUnusableTimeouts(ListPreference screenTimeoutPreference) { private void disableUnusableTimeouts(ListPreference screenTimeoutPreference) {
DevicePolicyManager dpm = final DevicePolicyManager dpm =
(DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE); (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) { if (maxTimeout == 0) {
return; // policy not enforced return; // policy not enforced
} }
@@ -96,7 +96,14 @@ public class DisplaySettings extends PreferenceActivity implements
revisedEntries.toArray(new CharSequence[revisedEntries.size()])); revisedEntries.toArray(new CharSequence[revisedEntries.size()]));
screenTimeoutPreference.setEntryValues( screenTimeoutPreference.setEntryValues(
revisedValues.toArray(new CharSequence[revisedValues.size()])); 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); screenTimeoutPreference.setEnabled(revisedEntries.size() > 0);
} }