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

Commit 1a70a16b authored by Craig Mautner's avatar Craig Mautner
Browse files

Add null checks for quickly disappearing Displays

If a display is removed right after it is added we will get null
when trying to retrieve it from the DisplayManager. Check for that
null before commiting to using that display.

Fixes bug 17478906.

Change-Id: I89ae8cc7387729d678b9b1ed5b1797a93cdde3f9
parent df980618
Loading
Loading
Loading
Loading
+14 −1
Original line number Diff line number Diff line
@@ -350,6 +350,9 @@ public final class ActivityStackSupervisor implements DisplayListener {
            for (int displayNdx = displays.length - 1; displayNdx >= 0; --displayNdx) {
                final int displayId = displays[displayNdx].getDisplayId();
                ActivityDisplay activityDisplay = new ActivityDisplay(displayId);
                if (activityDisplay.mDisplay == null) {
                    throw new IllegalStateException("Default Display does not exist");
                }
                mActivityDisplays.put(displayId, activityDisplay);
            }

@@ -3261,6 +3264,10 @@ public final class ActivityStackSupervisor implements DisplayListener {
            newDisplay = mActivityDisplays.get(displayId) == null;
            if (newDisplay) {
                ActivityDisplay activityDisplay = new ActivityDisplay(displayId);
                if (activityDisplay.mDisplay == null) {
                    Slog.w(TAG, "Display " + displayId + " gone before initialization complete");
                    return;
                }
                mActivityDisplays.put(displayId, activityDisplay);
            }
        }
@@ -3902,8 +3909,14 @@ public final class ActivityStackSupervisor implements DisplayListener {
        ActivityDisplay() {
        }

        // After instantiation, check that mDisplay is not null before using this. The alternative
        // is for this to throw an exception if mDisplayManager.getDisplay() returns null.
        ActivityDisplay(int displayId) {
            init(mDisplayManager.getDisplay(displayId));
            final Display display = mDisplayManager.getDisplay(displayId);
            if (display == null) {
                return;
            }
            init(display);
        }

        void init(Display display) {