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

Commit 6dc455b9 authored by Riddle Hsu's avatar Riddle Hsu Committed by Android (Google) Code Review
Browse files

Merge "Avoid detached surface from returning to hierarchy" into main

parents 3a4677e0 e12c2f0e
Loading
Loading
Loading
Loading
+2 −20
Original line number Diff line number Diff line
@@ -880,8 +880,6 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
    })
    @interface SplashScreenBehavior { }

    // TODO: Have a WindowContainer state for tracking exiting/deferred removal.
    boolean mIsExiting;
    // Force an app transition to be ran in the case the visibility of the app did not change.
    // We use this for the case of moving a Root Task to the back with multiple activities, and the
    // top activity enters PIP; the bottom activity's visibility stays the same, but we need to
@@ -1227,10 +1225,9 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
            pw.print(" lastAllDrawn="); pw.print(mLastAllDrawn);
            pw.println(")");
        }
        if (mStartingData != null || firstWindowDrawn || mIsExiting) {
        if (mStartingData != null || firstWindowDrawn) {
            pw.print(prefix); pw.print("startingData="); pw.print(mStartingData);
            pw.print(" firstWindowDrawn="); pw.print(firstWindowDrawn);
            pw.print(" mIsExiting="); pw.println(mIsExiting);
            pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn);
        }
        if (mStartingWindow != null || mStartingData != null || mStartingSurface != null
                || startingMoved || mVisibleSetFromTransferredStartingWindow) {
@@ -4370,21 +4367,6 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        super.removeImmediately();
    }

    @Override
    void removeIfPossible() {
        mIsExiting = false;
        removeAllWindowsIfPossible();
        removeImmediately();
    }

    @Override
    boolean handleCompleteDeferredRemoval() {
        if (mIsExiting) {
            removeIfPossible();
        }
        return super.handleCompleteDeferredRemoval();
    }

    void onRemovedFromDisplay() {
        if (mRemovingFromDisplay) {
            return;
+0 −1
Original line number Diff line number Diff line
@@ -1753,7 +1753,6 @@ class Transition implements BLASTSyncEngine.TransactionReadyListener {
        }
    }

    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE)
    static boolean containsChangeFor(WindowContainer wc, ArrayList<ChangeInfo> list) {
        for (int i = list.size() - 1; i >= 0; --i) {
            if (list.get(i).mContainer == wc) return true;
+10 −0
Original line number Diff line number Diff line
@@ -471,6 +471,16 @@ class TransitionController {
        return false;
    }

    /** Returns {@code true} if the `wc` is a target of a playing transition. */
    boolean isPlayingTarget(@NonNull WindowContainer<?> wc) {
        for (int i = mPlayingTransitions.size() - 1; i >= 0; --i) {
            if (Transition.containsChangeFor(wc, mPlayingTransitions.get(i).mTargets)) {
                return true;
            }
        }
        return false;
    }

    /** Returns {@code true} if the finishing transition contains `wc`. */
    boolean inFinishingTransition(WindowContainer<?> wc) {
        return mFinishingTransition != null && mFinishingTransition.isInTransition(wc);
+1 −1
Original line number Diff line number Diff line
@@ -2109,7 +2109,7 @@ public class WindowManagerService extends IWindowManager.Stub
        ProtoLog.v(WM_DEBUG_ADD_REMOVE, "Removing %s from %s", win, token);
        // Window will already be removed from token before this post clean-up method is called.
        if (token.isEmpty() && !token.mPersistOnEmpty) {
            token.removeImmediately();
            token.removeIfPossible();
        }

        if (win.mActivityRecord != null) {
+28 −0
Original line number Diff line number Diff line
@@ -90,6 +90,9 @@ class WindowToken extends WindowContainer<WindowState> {
    // Is key dispatching paused for this token?
    boolean paused = false;

    /** Whether this container should be removed when it no longer animates. */
    boolean mIsExiting;

    /** The owner has {@link android.Manifest.permission#MANAGE_APP_TOKENS} */
    final boolean mOwnerCanManageAppTokens;

@@ -276,6 +279,28 @@ class WindowToken extends WindowContainer<WindowState> {
        }
    }

    @Override
    void removeIfPossible() {
        if (mTransitionController.isPlayingTarget(this)) {
            // Defer removing this container until the transition is finished. So the removal can
            // execute after the finish transaction (see Transition#buildFinishTransaction) which
            // may reparent it to original parent.
            mIsExiting = true;
            return;
        }
        mIsExiting = false;
        removeAllWindowsIfPossible();
        removeImmediately();
    }

    @Override
    boolean handleCompleteDeferredRemoval() {
        if (mIsExiting) {
            removeIfPossible();
        }
        return super.handleCompleteDeferredRemoval();
    }

    /**
     * @return The scale for applications running in compatibility mode. Multiply the size in the
     *         application by this scale will be the size in the screen.
@@ -725,6 +750,9 @@ class WindowToken extends WindowContainer<WindowState> {
            pw.print("fixedRotationConfig=");
            pw.println(mFixedRotationTransformState.mRotatedOverrideConfiguration);
        }
        if (mIsExiting) {
            pw.print(prefix); pw.println("isExiting=true");
        }
    }

    @Override
Loading