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

Commit d8665f23 authored by Jorim Jaggi's avatar Jorim Jaggi
Browse files

Fix issues with duplicate starting window add requests

There might be cases where we have multiple requests to add a
starting window. To protect against this, we
a) Check for existing startingWindow when adding starting window
b) Don't send the message if we already an add request pending
c) Remove any pending requests when we handle one request

There was already existing logic in place that checked whether
we have a starting window. However, that doesn't cover the case
when requests are pending, but the window hasn't been added yet.

Test: Open settings, open any sub-activity, go home, kill
settings, reopen settings. This generates a duplicate add request
almost guaranteed.
Test: go/wm-smoke
Fixes: 75030092

Change-Id: I5cb7fc0a4e7ab13dce3766be6afe1aa4f85df2e7
parent 782d1037
Loading
Loading
Loading
Loading
+65 −53
Original line number Diff line number Diff line
@@ -113,7 +113,10 @@ public class AppWindowContainerController
        mListener.onWindowsGone();
    };

    private final Runnable mAddStartingWindow = () -> {
    private final Runnable mAddStartingWindow = new Runnable() {

        @Override
        public void run() {
            final StartingData startingData;
            final AppWindowToken container;

@@ -123,19 +126,25 @@ public class AppWindowContainerController
                            + " add starting window");
                    return;
                }

                // There can only be one adding request, silly caller!
                mService.mAnimationHandler.removeCallbacks(this);

                startingData = mContainer.startingData;
                container = mContainer;
            }

            if (startingData == null) {
                // Animation has been canceled... do nothing.
            if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "startingData was nulled out before handling"
                if (DEBUG_STARTING_WINDOW)
                    Slog.v(TAG_WM, "startingData was nulled out before handling"
                            + " mAddStartingWindow: " + mContainer);
                return;
            }

            if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Add starting "
                + this + ": startingData=" + container.startingData);
                    + AppWindowContainerController.this + ": startingData="
                    + container.startingData);

            StartingSurface surface = null;
            try {
@@ -171,6 +180,7 @@ public class AppWindowContainerController
            } else if (DEBUG_STARTING_WINDOW) {
                Slog.v(TAG_WM, "Surface returned was null: " + mContainer);
            }
        }
    };

    public AppWindowContainerController(TaskWindowContainerController taskController,
@@ -558,9 +568,11 @@ public class AppWindowContainerController
        // Note: we really want to do sendMessageAtFrontOfQueue() because we
        // want to process the message ASAP, before any other queued
        // messages.
        if (!mService.mAnimationHandler.hasCallbacks(mAddStartingWindow)) {
            if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Enqueueing ADD_STARTING");
            mService.mAnimationHandler.postAtFrontOfQueue(mAddStartingWindow);
        }
    }

    private boolean createSnapshot(TaskSnapshot snapshot) {
        if (snapshot == null) {
+4 −0
Original line number Diff line number Diff line
@@ -1224,6 +1224,10 @@ public class WindowManagerService extends IWindowManager.Stub
                    Slog.w(TAG_WM, "Attempted to add window with exiting application token "
                          + token + ".  Aborting.");
                    return WindowManagerGlobal.ADD_APP_EXITING;
                } else if (type == TYPE_APPLICATION_STARTING && atoken.startingWindow != null) {
                    Slog.w(TAG_WM, "Attempted to add starting window to token with already existing"
                            + " starting window");
                    return WindowManagerGlobal.ADD_DUPLICATE_ADD;
                }
            } else if (rootType == TYPE_INPUT_METHOD) {
                if (token.windowType != TYPE_INPUT_METHOD) {