OSDN Git Service

Fix 2582241: Update selection based on user setting instead.
authorJim Miller <jaggies@google.com>
Tue, 13 Apr 2010 22:31:41 +0000 (15:31 -0700)
committerJim Miller <jaggies@google.com>
Tue, 13 Apr 2010 22:31:41 +0000 (15:31 -0700)
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

src/com/android/settings/DisplaySettings.java

index 813df00..fbb07c1 100644 (file)
@@ -74,9 +74,9 @@ public class DisplaySettings extends PreferenceActivity implements
     }
 
     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 @@ public class DisplaySettings extends PreferenceActivity implements
                     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);
     }