Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fc5a0222 authored by Jim Miller's avatar Jim Miller
Browse files

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
parent fced1268
Loading
Loading
Loading
Loading
+10 −3
Original line number Original line Diff line number Diff line
@@ -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);
    }
    }