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

Commit c0801777 authored by Evan Rosky's avatar Evan Rosky Committed by Android (Google) Code Review
Browse files

Merge "Add per-change flags and wallpaper windows to transitions"

parents 1557e2bf dba8bbfd
Loading
Loading
Loading
Loading
+61 −2
Original line number Diff line number Diff line
@@ -57,6 +57,32 @@ public final class TransitionInfo implements Parcelable {
    })
    public @interface TransitionMode {}

    /** No flags */
    public static final int FLAG_NONE = 0;

    /** The container shows the wallpaper behind it. */
    public static final int FLAG_SHOW_WALLPAPER = 1;

    /** The container IS the wallpaper. */
    public static final int FLAG_IS_WALLPAPER = 1 << 1;

    /** The container is translucent. */
    public static final int FLAG_TRANSLUCENT = 1 << 2;

    // TODO: remove when starting-window is moved to Task
    /** The container is the recipient of a transferred starting-window */
    public static final int FLAG_STARTING_WINDOW_TRANSFER_RECIPIENT = 1 << 3;

    /** @hide */
    @IntDef(prefix = { "FLAG_" }, value = {
            FLAG_NONE,
            FLAG_SHOW_WALLPAPER,
            FLAG_IS_WALLPAPER,
            FLAG_TRANSLUCENT,
            FLAG_STARTING_WINDOW_TRANSFER_RECIPIENT
    })
    public @interface ChangeFlags {}

    private final @WindowManager.TransitionOldType int mType;
    private final @WindowManager.TransitionFlags int mFlags;
    private final ArrayList<Change> mChanges = new ArrayList<>();
@@ -198,12 +224,33 @@ public final class TransitionInfo implements Parcelable {
        }
    }

    /** Converts change flags into a string representation. */
    @NonNull
    public static String flagsToString(@ChangeFlags int flags) {
        if (flags == 0) return "NONE";
        final StringBuilder sb = new StringBuilder();
        if ((flags & FLAG_SHOW_WALLPAPER) != 0) {
            sb.append("SHOW_WALLPAPER");
        }
        if ((flags & FLAG_IS_WALLPAPER) != 0) {
            sb.append("IS_WALLPAPER");
        }
        if ((flags & FLAG_TRANSLUCENT) != 0) {
            sb.append((sb.length() == 0 ? "" : "|") + "TRANSLUCENT");
        }
        if ((flags & FLAG_STARTING_WINDOW_TRANSFER_RECIPIENT) != 0) {
            sb.append((sb.length() == 0 ? "" : "|") + "STARTING_WINDOW_TRANSFER");
        }
        return sb.toString();
    }

    /** Represents the change a WindowContainer undergoes during a transition */
    public static final class Change implements Parcelable {
        private final WindowContainerToken mContainer;
        private WindowContainerToken mParent;
        private final SurfaceControl mLeash;
        private @TransitionMode int mMode = TRANSIT_NONE;
        private @ChangeFlags int mFlags = FLAG_NONE;
        private final Rect mStartAbsBounds = new Rect();
        private final Rect mEndAbsBounds = new Rect();
        private final Point mEndRelOffset = new Point();
@@ -219,6 +266,7 @@ public final class TransitionInfo implements Parcelable {
            mLeash = new SurfaceControl();
            mLeash.readFromParcel(in);
            mMode = in.readInt();
            mFlags = in.readInt();
            mStartAbsBounds.readFromParcel(in);
            mEndAbsBounds.readFromParcel(in);
            mEndRelOffset.readFromParcel(in);
@@ -234,6 +282,11 @@ public final class TransitionInfo implements Parcelable {
            mMode = mode;
        }

        /** Sets the flags for this change */
        public void setFlags(@ChangeFlags int flags) {
            mFlags = flags;
        }

        /** Sets the bounds this container occupied before the change in screen space */
        public void setStartAbsBounds(@Nullable Rect rect) {
            mStartAbsBounds.set(rect);
@@ -269,6 +322,11 @@ public final class TransitionInfo implements Parcelable {
            return mMode;
        }

        /** @return the flags for this change. */
        public @ChangeFlags int getFlags() {
            return mFlags;
        }

        /**
         * @return the bounds of the container before the change. It may be empty if the container
         * is coming into existence.
@@ -308,6 +366,7 @@ public final class TransitionInfo implements Parcelable {
            dest.writeTypedObject(mParent, flags);
            mLeash.writeToParcel(dest, flags);
            dest.writeInt(mMode);
            dest.writeInt(mFlags);
            mStartAbsBounds.writeToParcel(dest, flags);
            mEndAbsBounds.writeToParcel(dest, flags);
            mEndRelOffset.writeToParcel(dest, flags);
@@ -336,8 +395,8 @@ public final class TransitionInfo implements Parcelable {
        @Override
        public String toString() {
            return "{" + mContainer + "(" + mParent + ") leash=" + mLeash
                    + " m=" + modeToString(mMode) + " sb=" + mStartAbsBounds
                    + " eb=" + mEndAbsBounds + " eo=" + mEndRelOffset + "}";
                    + " m=" + modeToString(mMode) + " f=" + flagsToString(mFlags) + " sb="
                    + mStartAbsBounds + " eb=" + mEndAbsBounds + " eo=" + mEndRelOffset + "}";
        }
    }
}
+6 −0
Original line number Diff line number Diff line
@@ -67,6 +67,12 @@
      "group": "WM_ERROR",
      "at": "com\/android\/server\/wm\/WindowManagerService.java"
    },
    "-2036671725": {
      "message": "      SKIP: is wallpaper",
      "level": "VERBOSE",
      "group": "WM_DEBUG_WINDOW_TRANSITIONS",
      "at": "com\/android\/server\/wm\/Transition.java"
    },
    "-2029985709": {
      "message": "setFocusedTask: taskId=%d",
      "level": "DEBUG",
+9 −2
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import static android.view.WindowManager.TRANSIT_CLOSE;
import static android.view.WindowManager.TRANSIT_OPEN;
import static android.view.WindowManager.TRANSIT_TO_BACK;
import static android.view.WindowManager.TRANSIT_TO_FRONT;
import static android.window.TransitionInfo.FLAG_STARTING_WINDOW_TRANSFER_RECIPIENT;

import android.animation.Animator;
import android.animation.ValueAnimator;
@@ -166,8 +167,14 @@ public class Transitions {
                if (isOpening) {
                    // put on top and fade in
                    t.setLayer(leash, info.getChanges().size() - i);
                    if ((change.getFlags() & FLAG_STARTING_WINDOW_TRANSFER_RECIPIENT) != 0) {
                        // This received a transferred starting window, so make it immediately
                        // visible.
                        t.setAlpha(leash, 1.f);
                    } else {
                        t.setAlpha(leash, 0.f);
                        startExampleAnimation(transitionToken, leash, true /* show */);
                    }
                } else {
                    // put on bottom and leave it visible without fade
                    t.setLayer(leash, -i);
+6 −3
Original line number Diff line number Diff line
@@ -573,7 +573,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
    private final WindowState.UpdateReportedVisibilityResults mReportedVisibilityResults =
            new WindowState.UpdateReportedVisibilityResults();

    private boolean mUseTransferredAnimation;
    boolean mUseTransferredAnimation;

    /**
     * @see #currentLaunchCanTurnScreenOn()
@@ -3500,8 +3500,8 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A

                ProtoLog.v(WM_DEBUG_ADD_REMOVE,
                        "Removing starting %s from %s", tStartingWindow, fromActivity);
                fromActivity.removeChild(tStartingWindow);
                addWindow(tStartingWindow);
                mAtmService.getTransitionController().collect(tStartingWindow);
                tStartingWindow.reparent(this, POSITION_TOP);

                // Propagate other interesting state between the tokens. If the old token is displayed,
                // we should immediately force the new one to be displayed. If it is animating, we need
@@ -3526,6 +3526,9 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
                    // the token we transfer the animation over. Thus, set this flag to indicate
                    // we've transferred the animation.
                    mUseTransferredAnimation = true;
                } else if (mAtmService.getTransitionController().getTransitionPlayer() != null) {
                    // In the new transit system, just set this every time we transfer the window
                    mUseTransferredAnimation = true;
                }
                // Post cleanup after the visibility and animation are transferred.
                fromActivity.postWindowRemoveStartingWindowCleanup(tStartingWindow);
+82 −8
Original line number Diff line number Diff line
@@ -30,6 +30,10 @@ import static android.view.WindowManager.TRANSIT_NONE;
import static android.view.WindowManager.TRANSIT_OPEN;
import static android.view.WindowManager.TRANSIT_TO_BACK;
import static android.view.WindowManager.TRANSIT_TO_FRONT;
import static android.window.TransitionInfo.FLAG_IS_WALLPAPER;
import static android.window.TransitionInfo.FLAG_SHOW_WALLPAPER;
import static android.window.TransitionInfo.FLAG_STARTING_WINDOW_TRANSFER_RECIPIENT;
import static android.window.TransitionInfo.FLAG_TRANSLUCENT;

import android.annotation.IntDef;
import android.annotation.NonNull;
@@ -160,8 +164,20 @@ class Transition extends Binder implements BLASTSyncEngine.TransactionReadyListe
        }
        if (mParticipants.contains(wc)) return;
        mSyncEngine.addToSyncSet(mSyncId, wc);
        mChanges.put(wc, new ChangeInfo(wc));
        ChangeInfo info = mChanges.get(wc);
        if (info == null) {
            info = new ChangeInfo(wc);
            mChanges.put(wc, info);
        }
        mParticipants.add(wc);
        if (info.mShowWallpaper) {
            // Collect the wallpaper so it is part of the sync set.
            final WindowContainer wallpaper =
                    wc.getDisplayContent().mWallpaperController.getTopVisibleWallpaper();
            if (wallpaper != null) {
                collect(wallpaper);
            }
        }
    }

    /**
@@ -386,6 +402,10 @@ class Transition extends Binder implements BLASTSyncEngine.TransactionReadyListe
        return -1;
    }

    private static boolean isWallpaper(WindowContainer wc) {
        return wc instanceof WallpaperWindowToken;
    }

    /**
     * Under some conditions (eg. all visible targets within a parent container are transitioning
     * the same way) the transition can be "promoted" to the parent container. This means an
@@ -403,6 +423,10 @@ class Transition extends Binder implements BLASTSyncEngine.TransactionReadyListe
                    parent == null ? "no parent" : ("parent can't be target " + parent));
            return false;
        }
        if (isWallpaper(target)) {
            ProtoLog.v(ProtoLogGroup.WM_DEBUG_WINDOW_TRANSITIONS, "      SKIP: is wallpaper");
            return false;
        }
        @TransitionInfo.TransitionMode int mode = TRANSIT_NONE;
        // Go through all siblings of this target to see if any of them would prevent
        // the target from promoting.
@@ -604,18 +628,32 @@ class Transition extends Binder implements BLASTSyncEngine.TransactionReadyListe
    static TransitionInfo calculateTransitionInfo(int type, int flags,
            ArraySet<WindowContainer> targets, ArrayMap<WindowContainer, ChangeInfo> changes) {
        final TransitionInfo out = new TransitionInfo(type, flags);
        if (targets.isEmpty()) {

        final ArraySet<WindowContainer> appTargets = new ArraySet<>();
        final ArraySet<WindowContainer> wallpapers = new ArraySet<>();
        for (int i = targets.size() - 1; i >= 0; --i) {
            (isWallpaper(targets.valueAt(i)) ? wallpapers : appTargets).add(targets.valueAt(i));
        }

        // Find the top-most shared ancestor of app targets
        WindowContainer ancestor = null;
        for (int i = appTargets.size() - 1; i >= 0; --i) {
            final WindowContainer wc = appTargets.valueAt(i);
            ancestor = wc;
            break;
        }
        if (ancestor == null) {
            out.setRootLeash(new SurfaceControl(), 0, 0);
            return out;
        }
        ancestor = ancestor.getParent();

        // Find the top-most shared ancestor
        WindowContainer ancestor = targets.valueAt(0).getParent();
        // Go up ancestor parent chain until all topTargets are descendants.
        // Go up ancestor parent chain until all targets are descendants.
        ancestorLoop:
        while (ancestor != null) {
            for (int i = 1; i < targets.size(); ++i) {
                if (!targets.valueAt(i).isDescendantOf(ancestor)) {
            for (int i = appTargets.size() - 1; i >= 0; --i) {
                final WindowContainer wc = appTargets.valueAt(i);
                if (!wc.isDescendantOf(ancestor)) {
                    ancestor = ancestor.getParent();
                    continue ancestorLoop;
                }
@@ -623,7 +661,8 @@ class Transition extends Binder implements BLASTSyncEngine.TransactionReadyListe
            break;
        }

        // Sort targets top-to-bottom in Z.
        // Sort targets top-to-bottom in Z. Check ALL targets here in case the display area itself
        // is animating: then we want to include wallpapers at the right position.
        ArrayList<WindowContainer> sortedTargets = new ArrayList<>();
        addMembersInOrder(ancestor, targets, sortedTargets);

@@ -640,6 +679,14 @@ class Transition extends Binder implements BLASTSyncEngine.TransactionReadyListe
        t.close();
        out.setRootLeash(rootLeash, ancestor.getBounds().left, ancestor.getBounds().top);

        // add the wallpapers at the bottom
        for (int i = wallpapers.size() - 1; i >= 0; --i) {
            final WindowContainer wc = wallpapers.valueAt(i);
            // If the displayarea itself is animating, then the wallpaper was already added.
            if (wc.isDescendantOf(ancestor)) break;
            sortedTargets.add(wc);
        }

        // Convert all the resolved ChangeInfos into TransactionInfo.Change objects in order.
        final int count = sortedTargets.size();
        for (int i = 0; i < count; ++i) {
@@ -656,6 +703,7 @@ class Transition extends Binder implements BLASTSyncEngine.TransactionReadyListe
            change.setEndAbsBounds(target.getBounds());
            change.setEndRelOffset(target.getBounds().left - target.getParent().getBounds().left,
                    target.getBounds().top - target.getParent().getBounds().top);
            change.setFlags(info.getChangeFlags(target));
            out.addChange(change);
        }

@@ -678,17 +726,20 @@ class Transition extends Binder implements BLASTSyncEngine.TransactionReadyListe
        boolean mVisible;
        int mWindowingMode;
        final Rect mAbsoluteBounds = new Rect();
        boolean mShowWallpaper;

        ChangeInfo(@NonNull WindowContainer origState) {
            mVisible = origState.isVisibleRequested();
            mWindowingMode = origState.getWindowingMode();
            mAbsoluteBounds.set(origState.getBounds());
            mShowWallpaper = origState.showWallpaper();
        }

        @VisibleForTesting
        ChangeInfo(boolean visible, boolean existChange) {
            mVisible = visible;
            mExistenceChanged = existChange;
            mShowWallpaper = false;
        }

        boolean hasChanged(@NonNull WindowContainer newState) {
@@ -716,6 +767,29 @@ class Transition extends Binder implements BLASTSyncEngine.TransactionReadyListe
            }
        }

        @TransitionInfo.ChangeFlags
        int getChangeFlags(@NonNull WindowContainer wc) {
            int flags = 0;
            if (mShowWallpaper || wc.showWallpaper()) {
                flags |= FLAG_SHOW_WALLPAPER;
            }
            if (!wc.fillsParent()) {
                // TODO(b/172695805): hierarchical check. This is non-trivial because for containers
                //                    it is effected by child visibility but needs to work even
                //                    before visibility is committed. This means refactoring some
                //                    checks to use requested visibility.
                flags |= FLAG_TRANSLUCENT;
            }
            if (wc instanceof ActivityRecord
                    && wc.asActivityRecord().mUseTransferredAnimation) {
                flags |= FLAG_STARTING_WINDOW_TRANSFER_RECIPIENT;
            }
            if (isWallpaper(wc)) {
                flags |= FLAG_IS_WALLPAPER;
            }
            return flags;
        }

        void addChild(@NonNull WindowContainer wc) {
            if (mChildren == null) {
                mChildren = new ArraySet<>();
Loading