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

Commit c95af136 authored by mattsziklay's avatar mattsziklay Committed by Matt Sziklay
Browse files

Apply DisplayChange to display disconnect transition.

Modifies the display disconnect transition to include a DisplayChange
that flags the reparentDisplayId, the display that any reparented tasks
will move to.

This DisplayChange will be used by TransitionHandlers to determine any
additional changes to the transition that need to be made. Due to this,
reparent behavior in TaskDisplayArea has largely been reverted to what it was prior to I6ec4b9d305a6bd9497450328dad36bc53179ee7c (with the exception of some freeform organizer tasks not being removed).

Bug: 391652399
Test: Manual; confirm freeform tasks provide display change to Shell on disconnect
Flag: com.android.window.flags.enable_display_disconnect_interaction

Change-Id: I0e5a4ed3276a676b28a9470ab0c2739a7ef7e29e
parent c7b882bc
Loading
Loading
Loading
Loading
+36 −6
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.window;

import static android.view.Display.INVALID_DISPLAY;
import static android.view.WindowManager.transitTypeToString;

import android.annotation.Nullable;
@@ -118,13 +119,15 @@ public final class TransitionRequestInfo implements Parcelable {
    public static final class DisplayChange implements Parcelable {
        private final int mDisplayId;

        // If non-null, these bounds changes should ignore any potential rotation changes.
        /** If non-null, these bounds changes should ignore any potential rotation changes. */
        @Nullable private Rect mStartAbsBounds = null;
        @Nullable private Rect mEndAbsBounds = null;

        private int mStartRotation = WindowConfiguration.ROTATION_UNDEFINED;
        private int mEndRotation = WindowConfiguration.ROTATION_UNDEFINED;
        private boolean mPhysicalDisplayChanged = false;
        /** The display to reparent to on disconnect; if invalid, this isn't a disconnect change. */
        private int mDisconnectReparentDisplay = INVALID_DISPLAY;

        /** Create empty display-change. */
        public DisplayChange(int displayId) {
@@ -158,6 +161,9 @@ public final class TransitionRequestInfo implements Parcelable {
            return mDisplayId;
        }

        /**
         * If non-null, these bounds changes should ignore any potential rotation changes.
         */
        @DataClass.Generated.Member
        public @Nullable Rect getStartAbsBounds() {
            return mStartAbsBounds;
@@ -183,6 +189,17 @@ public final class TransitionRequestInfo implements Parcelable {
            return mPhysicalDisplayChanged;
        }

        /**
         * The display to reparent to on disconnect; if invalid, this isn't a disconnect change.
         */
        @DataClass.Generated.Member
        public int getDisconnectReparentDisplay() {
            return mDisconnectReparentDisplay;
        }

        /**
         * If non-null, these bounds changes should ignore any potential rotation changes.
         */
        @DataClass.Generated.Member
        public @android.annotation.NonNull DisplayChange setStartAbsBounds(@android.annotation.NonNull Rect value) {
            mStartAbsBounds = value;
@@ -213,6 +230,15 @@ public final class TransitionRequestInfo implements Parcelable {
            return this;
        }

        /**
         * The display to reparent to on disconnect; if invalid, this isn't a disconnect change.
         */
        @DataClass.Generated.Member
        public @android.annotation.NonNull DisplayChange setDisconnectReparentDisplay( int value) {
            mDisconnectReparentDisplay = value;
            return this;
        }

        @Override
        @DataClass.Generated.Member
        public String toString() {
@@ -225,7 +251,8 @@ public final class TransitionRequestInfo implements Parcelable {
                    "endAbsBounds = " + mEndAbsBounds + ", " +
                    "startRotation = " + mStartRotation + ", " +
                    "endRotation = " + mEndRotation + ", " +
                    "physicalDisplayChanged = " + mPhysicalDisplayChanged +
                    "physicalDisplayChanged = " + mPhysicalDisplayChanged + ", " +
                    "disconnectReparentDisplay = " + mDisconnectReparentDisplay +
            " }";
        }

@@ -245,6 +272,7 @@ public final class TransitionRequestInfo implements Parcelable {
            if (mEndAbsBounds != null) dest.writeTypedObject(mEndAbsBounds, flags);
            dest.writeInt(mStartRotation);
            dest.writeInt(mEndRotation);
            dest.writeInt(mDisconnectReparentDisplay);
        }

        @Override
@@ -265,6 +293,7 @@ public final class TransitionRequestInfo implements Parcelable {
            Rect endAbsBounds = (flg & 0x4) == 0 ? null : (Rect) in.readTypedObject(Rect.CREATOR);
            int startRotation = in.readInt();
            int endRotation = in.readInt();
            int disconnectReparentDisplay = in.readInt();

            this.mDisplayId = displayId;
            this.mStartAbsBounds = startAbsBounds;
@@ -272,6 +301,7 @@ public final class TransitionRequestInfo implements Parcelable {
            this.mStartRotation = startRotation;
            this.mEndRotation = endRotation;
            this.mPhysicalDisplayChanged = physicalDisplayChanged;
            this.mDisconnectReparentDisplay = disconnectReparentDisplay;

            // onConstructed(); // You can define this method to get a callback
        }
@@ -291,10 +321,10 @@ public final class TransitionRequestInfo implements Parcelable {
        };

        @DataClass.Generated(
                time = 1733334462577L,
                time = 1744851977467L,
                codegenVersion = "1.0.23",
                sourceFile = "frameworks/base/core/java/android/window/TransitionRequestInfo.java",
                inputSignatures = "private final  int mDisplayId\nprivate @android.annotation.Nullable android.graphics.Rect mStartAbsBounds\nprivate @android.annotation.Nullable android.graphics.Rect mEndAbsBounds\nprivate  int mStartRotation\nprivate  int mEndRotation\nprivate  boolean mPhysicalDisplayChanged\nclass DisplayChange extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genToString=true, genSetters=true, genBuilder=false, genConstructor=false)")
                inputSignatures = "private final  int mDisplayId\nprivate @android.annotation.Nullable android.graphics.Rect mStartAbsBounds\nprivate @android.annotation.Nullable android.graphics.Rect mEndAbsBounds\nprivate  int mStartRotation\nprivate  int mEndRotation\nprivate  boolean mPhysicalDisplayChanged\nprivate  int mDisconnectReparentDisplay\nclass DisplayChange extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genToString=true, genSetters=true, genBuilder=false, genConstructor=false)")
        @Deprecated
        private void __metadata() {}

@@ -428,7 +458,7 @@ public final class TransitionRequestInfo implements Parcelable {
        };

        @DataClass.Generated(
                time = 1733334462588L,
                time = 1744851977482L,
                codegenVersion = "1.0.23",
                sourceFile = "frameworks/base/core/java/android/window/TransitionRequestInfo.java",
                inputSignatures = "private @android.annotation.NonNull android.window.WindowContainerToken mTaskFragmentToken\nprivate @android.annotation.NonNull android.app.ActivityManager.RunningTaskInfo mTaskInfo\nclass PipChange extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genToString=true, genSetters=true, genBuilder=false, genConstructor=false)")
@@ -687,7 +717,7 @@ public final class TransitionRequestInfo implements Parcelable {
    };

    @DataClass.Generated(
            time = 1733334462604L,
            time = 1744851977497L,
            codegenVersion = "1.0.23",
            sourceFile = "frameworks/base/core/java/android/window/TransitionRequestInfo.java",
            inputSignatures = "private final @android.view.WindowManager.TransitionType int mType\nprivate @android.annotation.Nullable android.app.ActivityManager.RunningTaskInfo mTriggerTask\nprivate @android.annotation.Nullable android.window.TransitionRequestInfo.PipChange mPipChange\nprivate @android.annotation.Nullable android.window.RemoteTransition mRemoteTransition\nprivate @android.annotation.Nullable android.window.TransitionRequestInfo.DisplayChange mDisplayChange\nprivate final  int mFlags\nprivate final  int mDebugId\n  java.lang.String typeToString()\nclass TransitionRequestInfo extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genToString=true, genSetters=true, genAidl=true)")
+11 −5
Original line number Diff line number Diff line
@@ -31,7 +31,7 @@ import static android.view.Display.INVALID_DISPLAY;
import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_SUSTAINED_PERFORMANCE_MODE;
import static android.view.WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG;
import static android.view.WindowManager.LayoutParams.TYPE_NOTIFICATION_SHADE;
import static android.view.WindowManager.TRANSIT_CHANGE;
import static android.view.WindowManager.TRANSIT_CLOSE;
import static android.view.WindowManager.TRANSIT_FLAG_KEYGUARD_OCCLUDING;
import static android.view.WindowManager.TRANSIT_NONE;
import static android.view.WindowManager.TRANSIT_PIP;
@@ -138,6 +138,7 @@ import android.view.WindowManager;
import android.window.DesktopExperienceFlags;
import android.window.DesktopModeFlags;
import android.window.TaskFragmentAnimationParams;
import android.window.TransitionRequestInfo;
import android.window.WindowContainerToken;

import com.android.internal.annotations.VisibleForTesting;
@@ -2801,14 +2802,19 @@ class RootWindowContainer extends WindowContainer<DisplayContent>
                return;
            }
            if (DesktopExperienceFlags.ENABLE_DISPLAY_DISCONNECT_INTERACTION.isTrue()) {
                final Transition transition = new Transition(TRANSIT_CHANGE, 0 /* flags */,
                final Transition transition = new Transition(TRANSIT_CLOSE, 0 /* flags */,
                        mTransitionController, mWmService.mSyncEngine);
                mTransitionController.startCollectOrQueue(transition, (deferred) -> {
                    displayContent.remove();
                    mWmService.mPossibleDisplayInfoMapper.removePossibleDisplayInfos(displayId);
                    transition.collect(displayContent);
                    transition.setAllReady();
                    TransitionRequestInfo.DisplayChange displayChange =
                            new TransitionRequestInfo.DisplayChange(displayId);
                    displayChange.setDisconnectReparentDisplay(
                            mWindowManager.mUmInternal.getMainDisplayAssignedToUser(mCurrentUser)
                    );

                    mTransitionController.requestStartTransition(transition, null /* startTask */,
                            null /* remoteTransition */, null /* displayChange */);
                            null /* remoteTransition */, displayChange);
                });
            } else {
                displayContent.remove();
+14 −2
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@ import static android.view.WindowManager.TRANSIT_TO_FRONT;
import static android.view.WindowManager.TransitionFlags;
import static android.view.WindowManager.TransitionType;
import static android.view.WindowManager.transitTypeToString;
import static android.window.DesktopExperienceFlags.ENABLE_DISPLAY_DISCONNECT_INTERACTION;
import static android.window.DesktopExperienceFlags.ENABLE_DISPLAY_FOCUS_IN_SHELL_TRANSITIONS;
import static android.window.TaskFragmentAnimationParams.DEFAULT_ANIMATION_BACKGROUND_COLOR;
import static android.window.TransitionInfo.AnimationOptions;
@@ -3402,13 +3403,22 @@ class Transition implements BLASTSyncEngine.TransactionReadyListener {

    /**
     * Applies the new configuration for the changed displays. Returns the activities that should
     * check whether to deliver the new configuration to clients.
     * check whether to deliver the new configuration to clients and whether the changes will
     * potentially affect lifecycles.
     */
    void applyDisplayChangeIfNeeded(@NonNull ArraySet<WindowContainer<?>> activitiesMayChange) {
    boolean applyDisplayChangeIfNeeded(@NonNull ArraySet<WindowContainer<?>> activitiesMayChange) {
        boolean affectsLifecycle = false;
        for (int i = mParticipants.size() - 1; i >= 0; --i) {
            final WindowContainer<?> wc = mParticipants.valueAt(i);
            final DisplayContent dc = wc.asDisplayContent();
            if (dc == null || !mChanges.get(dc).hasChanged()) continue;
            if (ENABLE_DISPLAY_DISCONNECT_INTERACTION.isTrue()
                    && mChanges.get(dc) != null && mChanges.get(dc).mExistenceChanged) {
                dc.remove();
                affectsLifecycle = true;
                mWmService.mPossibleDisplayInfoMapper.removePossibleDisplayInfos(dc.mDisplayId);
                continue;
            }
            final boolean changed = dc.sendNewConfiguration();
            // Set to ready if no other change controls the ready state. But if there is, such as
            // if an activity is pausing, it will call setReady(ar, false) and wait for the next
@@ -3428,6 +3438,7 @@ class Transition implements BLASTSyncEngine.TransactionReadyListener {
                });
            }
        }
        return affectsLifecycle;
    }

    boolean getLegacyIsReady() {
@@ -3607,6 +3618,7 @@ class Transition implements BLASTSyncEngine.TransactionReadyListener {
        }

        boolean hasChanged() {
            if (mExistenceChanged && ENABLE_DISPLAY_DISCONNECT_INTERACTION.isTrue()) return true;
            final boolean currVisible = mContainer.isVisibleRequested();
            // the task including transient launch must promote to root task
            if (currVisible && ((mFlags & ChangeInfo.FLAG_TRANSIENT_LAUNCH) != 0
+3 −1
Original line number Diff line number Diff line
@@ -649,7 +649,9 @@ class WindowOrganizerController extends IWindowOrganizerController.Stub
        try {
            final ArraySet<WindowContainer<?>> haveConfigChanges = new ArraySet<>();
            if (transition != null) {
                transition.applyDisplayChangeIfNeeded(haveConfigChanges);
                if (transition.applyDisplayChangeIfNeeded(haveConfigChanges)) {
                    effects |= TRANSACT_EFFECTS_LIFECYCLE;
                }
                if (!haveConfigChanges.isEmpty()) {
                    effects |= TRANSACT_EFFECTS_CLIENT_CONFIG;
                }