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

Commit 881560a6 authored by Darrell Shi's avatar Darrell Shi
Browse files

Safeguard DreamManager in PhoneWindowManager

Currently calls to the DreamManagerInternal inside PhoneWindowManager
rely on an instance being properly cached, which has caused
NullPointerException's in some rare cases. This change ensures that all
references to it within the class go through getDreamManagerInternal()
which fetches the latest service should the local variable be null.

Fix: 401205442
Test: verified that power button press on device after a reboot no
longer crashes
Flag: EXEMPT small bug fix

Change-Id: Ieee5af390a122f90bf7b1bd641d0fff8a8bff380
parent ab5f8b23
Loading
Loading
Loading
Loading
+8 −3
Original line number Diff line number Diff line
@@ -1255,7 +1255,12 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                            mContext.getContentResolver(), Settings.Secure.GLANCEABLE_HUB_ENABLED,
                            1, mCurrentUserId) == 1;

                    if (mDreamManagerInternal.isDreaming() || isKeyguardShowing()) {
                    final DreamManagerInternal dreamManagerInternal = getDreamManagerInternal();
                    if (dreamManagerInternal == null) {
                        break;
                    }

                    if (dreamManagerInternal.isDreaming() || isKeyguardShowing()) {
                        // If the device is already dreaming or on keyguard, go to sleep.
                        sleepDefaultDisplayFromPowerButton(eventTime, 0);
                        break;
@@ -1266,7 +1271,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                    boolean keyguardAvailable = !mLockPatternUtils.isLockScreenDisabled(
                            mCurrentUserId);
                    if (mUserManagerInternal.isUserUnlocked(mCurrentUserId) && hubEnabled
                            && keyguardAvailable && mDreamManagerInternal.dreamConditionActive()) {
                            && keyguardAvailable && dreamManagerInternal.dreamConditionActive()) {
                        // If the hub can be launched, send a message to keyguard.
                        Bundle options = new Bundle();
                        options.putBoolean(EXTRA_TRIGGER_HUB, true);
@@ -1975,7 +1980,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        // but don't actually go home.
        final DreamManagerInternal dreamManagerInternal = getDreamManagerInternal();
        if (dreamManagerInternal != null && dreamManagerInternal.isDreaming()) {
            mDreamManagerInternal.stopDream(false /*immediate*/, "short press on home" /*reason*/);
            dreamManagerInternal.stopDream(false /*immediate*/, "short press on home" /*reason*/);
            return;
        }