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

Commit d0af03e1 authored by Yi Jiang's avatar Yi Jiang Committed by Android (Google) Code Review
Browse files

Merge "Fixes NPE in Screen attention setting" into sc-dev

parents b720318f f54a2be8
Loading
Loading
Loading
Loading
+17 −14
Original line number Diff line number Diff line
@@ -73,7 +73,6 @@ public class AdaptiveSleepPreferenceController {
     * Adds the controlled preference to the provided preference screen.
     */
    public void addToScreen(PreferenceScreen screen) {
        initializePreference();
        updatePreference();
        screen.addPreference(mPreference);
    }
@@ -82,6 +81,7 @@ public class AdaptiveSleepPreferenceController {
     * Updates the appearance of the preference.
     */
    public void updatePreference() {
        initializePreference();
        final EnforcedAdmin enforcedAdmin = mRestrictionUtils.checkIfRestrictionEnforced(mContext,
                UserManager.DISALLOW_CONFIG_SCREEN_TIMEOUT);
        if (enforcedAdmin != null) {
@@ -93,6 +93,7 @@ public class AdaptiveSleepPreferenceController {

    @VisibleForTesting
    void initializePreference() {
        if (mPreference == null) {
            mPreference = new RestrictedSwitchPreference(mContext);
            mPreference.setTitle(R.string.adaptive_sleep_title);
            mPreference.setSummary(R.string.adaptive_sleep_description);
@@ -100,13 +101,15 @@ public class AdaptiveSleepPreferenceController {
            mPreference.setKey(PREFERENCE_KEY);
            mPreference.setOnPreferenceChangeListener((preference, value) -> {
                final boolean isChecked = (Boolean) value;
            mMetricsFeatureProvider.action(mContext, SettingsEnums.ACTION_SCREEN_ATTENTION_CHANGED,
                mMetricsFeatureProvider.action(mContext,
                        SettingsEnums.ACTION_SCREEN_ATTENTION_CHANGED,
                        isChecked);
                Settings.Secure.putInt(mContext.getContentResolver(),
                        Settings.Secure.ADAPTIVE_SLEEP, isChecked ? 1 : DEFAULT_VALUE);
                return true;
            });
        }
    }

    @VisibleForTesting
    boolean isChecked() {