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

Commit f54a2be8 authored by Yi Jiang's avatar Yi Jiang
Browse files

Fixes NPE in Screen attention setting

Bug: 186904496
Test: make RunSettingsRoboTests
    ROBOTEST_FILTER=com.android.settings.display
Change-Id: I9bd1e6824e19cf8ea281f7af482d13ef47f36256
parent 177d7698
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() {