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

Commit 656bfb53 authored by Issei Suzuki's avatar Issei Suzuki
Browse files

Replace old app transition type to new transition type (2/N)

AppTransitionController#getTransitionCompatType scans app transition
requests being set in the setup stage, and decides the app transition
animation.

Bug: 166736358
Test: Changes are behind a flag. No logic change yet.
Change-Id: I4320b04da2569d555369e6698f084d9514e36590
parent 29f0617c
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -409,6 +409,13 @@ public interface WindowManager extends ViewManager {
     */
    int TRANSIT_FLAG_APP_CRASHED = 0x10;

    /**
     * Transition flag: A window in a new task is being opened behind an existing one in another
     * activity's task.
     * @hide
     */
    int TRANSIT_FLAG_OPEN_BEHIND = 0x20;

    /**
     * @hide
     */
@@ -417,7 +424,8 @@ public interface WindowManager extends ViewManager {
            TRANSIT_FLAG_KEYGUARD_GOING_AWAY_NO_ANIMATION,
            TRANSIT_FLAG_KEYGUARD_GOING_AWAY_WITH_WALLPAPER,
            TRANSIT_FLAG_KEYGUARD_GOING_AWAY_SUBTLE_ANIMATION,
            TRANSIT_FLAG_APP_CRASHED
            TRANSIT_FLAG_APP_CRASHED,
            TRANSIT_FLAG_OPEN_BEHIND
    })
    @Retention(RetentionPolicy.SOURCE)
    @interface TransitionFlags {}
+18 −6
Original line number Diff line number Diff line
@@ -241,12 +241,6 @@
      "group": "WM_DEBUG_STATES",
      "at": "com\/android\/server\/wm\/Task.java"
    },
    "-1847087163": {
      "message": "TRANSIT_TASK_OPEN_BEHIND,  adding %s to mOpeningApps",
      "level": "DEBUG",
      "group": "WM_DEBUG_APP_TRANSITIONS",
      "at": "com\/android\/server\/wm\/ActivityRecord.java"
    },
    "-1844540996": {
      "message": "  Initial targets: %s",
      "level": "VERBOSE",
@@ -1195,6 +1189,12 @@
      "group": "WM_DEBUG_WINDOW_TRANSITIONS",
      "at": "com\/android\/server\/wm\/Transition.java"
    },
    "-701167286": {
      "message": "applyAnimation: transit=%s, enter=%b, wc=%s",
      "level": "VERBOSE",
      "group": "WM_DEBUG_APP_TRANSITIONS_ANIM",
      "at": "com\/android\/server\/wm\/WindowContainer.java"
    },
    "-694710814": {
      "message": "Pausing rotation during drag",
      "level": "DEBUG",
@@ -3289,6 +3289,12 @@
      "group": "WM_DEBUG_STATES",
      "at": "com\/android\/server\/wm\/RootWindowContainer.java"
    },
    "1810019902": {
      "message": "TRANSIT_FLAG_OPEN_BEHIND,  adding %s to mOpeningApps",
      "level": "DEBUG",
      "group": "WM_DEBUG_APP_TRANSITIONS",
      "at": "com\/android\/server\/wm\/ActivityRecord.java"
    },
    "1822843721": {
      "message": "Aborted starting %s: startingData=%s",
      "level": "VERBOSE",
@@ -3331,6 +3337,12 @@
      "group": "WM_DEBUG_STATES",
      "at": "com\/android\/server\/wm\/Task.java"
    },
    "1838928243": {
      "message": "handleAppTransitionReady: appTransition=%s openingApps=[%s] closingApps=[%s] transit=%s transitCompat=%s (%b)",
      "level": "VERBOSE",
      "group": "WM_DEBUG_APP_TRANSITIONS",
      "at": "com\/android\/server\/wm\/AppTransitionController.java"
    },
    "1853793312": {
      "message": "Notify removed startingWindow %s",
      "level": "VERBOSE",
+6 −7
Original line number Diff line number Diff line
@@ -208,7 +208,6 @@ import com.android.server.policy.keyguard.KeyguardStateMonitor.StateCallback;
import com.android.server.statusbar.StatusBarManagerInternal;
import com.android.server.vr.VrManagerInternal;
import com.android.server.wm.ActivityTaskManagerInternal;
import com.android.server.wm.AppTransition;
import com.android.server.wm.DisplayPolicy;
import com.android.server.wm.DisplayRotation;
import com.android.server.wm.WindowManagerInternal;
@@ -1959,14 +1958,14 @@ public class PhoneWindowManager implements WindowManagerPolicy {

        mWindowManagerInternal.registerAppTransitionListener(new AppTransitionListener() {
            @Override
            public int onAppTransitionStartingLocked(int transit, long duration,
            public int onAppTransitionStartingLocked(boolean keyguardGoingAway, long duration,
                    long statusBarAnimationStartTime, long statusBarAnimationDuration) {
                return handleStartTransitionForKeyguardLw(transit, duration);
                return handleStartTransitionForKeyguardLw(keyguardGoingAway, duration);
            }

            @Override
            public void onAppTransitionCancelledLocked(int transit) {
                handleStartTransitionForKeyguardLw(transit, 0 /* duration */);
            public void onAppTransitionCancelledLocked(boolean keyguardGoingAway) {
                handleStartTransitionForKeyguardLw(keyguardGoingAway, 0 /* duration */);
            }
        });
        mKeyguardDelegate = new KeyguardServiceDelegate(mContext,
@@ -3194,7 +3193,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        }
    }

    private int handleStartTransitionForKeyguardLw(int transit, long duration) {
    private int handleStartTransitionForKeyguardLw(boolean keyguardGoingAway, long duration) {
        if (mKeyguardOccludedChanged) {
            if (DEBUG_KEYGUARD) Slog.d(TAG, "transition/occluded changed occluded="
                    + mPendingKeyguardOccluded);
@@ -3203,7 +3202,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                return FINISH_LAYOUT_REDO_LAYOUT | FINISH_LAYOUT_REDO_WALLPAPER;
            }
        }
        if (AppTransition.isKeyguardGoingAwayTransit(transit)) {
        if (keyguardGoingAway) {
            if (DEBUG_KEYGUARD) Slog.d(TAG, "Starting keyguard exit animation");
            startKeyguardExitAnimation(SystemClock.uptimeMillis(), duration);
        }
+5 −3
Original line number Diff line number Diff line
@@ -103,6 +103,7 @@ import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
import static android.view.WindowManager.TRANSIT_CLOSE;
import static android.view.WindowManager.TRANSIT_FLAG_OPEN_BEHIND;
import static android.view.WindowManager.TRANSIT_OLD_ACTIVITY_CLOSE;
import static android.view.WindowManager.TRANSIT_OLD_TASK_CLOSE;
import static android.view.WindowManager.TRANSIT_OLD_TASK_OPEN_BEHIND;
@@ -150,7 +151,6 @@ import static com.android.server.wm.ActivityRecordProto.VISIBLE;
import static com.android.server.wm.ActivityRecordProto.VISIBLE_REQUESTED;
import static com.android.server.wm.ActivityRecordProto.VISIBLE_SET_FROM_TRANSFERRED_STARTING_WINDOW;
import static com.android.server.wm.ActivityRecordProto.WINDOW_TOKEN;
import static com.android.server.wm.ActivityTaskSupervisor.PRESERVE_WINDOWS;
import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_APP;
import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_CLEANUP;
import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_RESULTS;
@@ -177,6 +177,7 @@ import static com.android.server.wm.ActivityTaskManagerService.RELAUNCH_REASON_F
import static com.android.server.wm.ActivityTaskManagerService.RELAUNCH_REASON_NONE;
import static com.android.server.wm.ActivityTaskManagerService.RELAUNCH_REASON_WINDOWING_MODE_RESIZE;
import static com.android.server.wm.ActivityTaskManagerService.getInputDispatchingTimeoutMillisLocked;
import static com.android.server.wm.ActivityTaskSupervisor.PRESERVE_WINDOWS;
import static com.android.server.wm.IdentifierProto.HASH_CODE;
import static com.android.server.wm.IdentifierProto.TITLE;
import static com.android.server.wm.IdentifierProto.USER_ID;
@@ -4273,14 +4274,15 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
                displayContent.mClosingApps.add(this);
                mEnteringAnimation = false;
            }
            if (appTransition.getAppTransitionOld() == TRANSIT_OLD_TASK_OPEN_BEHIND) {
            if (appTransition.getAppTransitionOld() == TRANSIT_OLD_TASK_OPEN_BEHIND
                    || (appTransition.getTransitFlags() & TRANSIT_FLAG_OPEN_BEHIND) != 0) {
                // We're launchingBehind, add the launching activity to mOpeningApps.
                final WindowState win = getDisplayContent().findFocusedWindow();
                if (win != null) {
                    final ActivityRecord focusedActivity = win.mActivityRecord;
                    if (focusedActivity != null) {
                        ProtoLog.d(WM_DEBUG_APP_TRANSITIONS,
                                "TRANSIT_TASK_OPEN_BEHIND,  adding %s to mOpeningApps",
                                "TRANSIT_FLAG_OPEN_BEHIND,  adding %s to mOpeningApps",
                                focusedActivity);

                        // Force animation to be loaded.
+81 −26
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import static android.view.WindowManager.TRANSIT_FLAG_KEYGUARD_GOING_AWAY_NO_ANI
import static android.view.WindowManager.TRANSIT_FLAG_KEYGUARD_GOING_AWAY_SUBTLE_ANIMATION;
import static android.view.WindowManager.TRANSIT_FLAG_KEYGUARD_GOING_AWAY_TO_SHADE;
import static android.view.WindowManager.TRANSIT_FLAG_KEYGUARD_GOING_AWAY_WITH_WALLPAPER;
import static android.view.WindowManager.TRANSIT_FLAG_OPEN_BEHIND;
import static android.view.WindowManager.TRANSIT_KEYGUARD_GOING_AWAY;
import static android.view.WindowManager.TRANSIT_KEYGUARD_OCCLUDE;
import static android.view.WindowManager.TRANSIT_KEYGUARD_UNOCCLUDE;
@@ -115,7 +116,6 @@ import android.os.RemoteException;
import android.os.SystemClock;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.util.ArraySet;
import android.util.Pair;
import android.util.Slog;
import android.util.SparseArray;
@@ -340,7 +340,7 @@ public class AppTransition implements Dump {

    boolean isUnoccluding() {
        return WindowManagerService.sUseNewAppTransit
                ? mNextAppTransitionRequests.contains(TRANSIT_OLD_KEYGUARD_UNOCCLUDE)
                ? mNextAppTransitionRequests.contains(TRANSIT_KEYGUARD_UNOCCLUDE)
                : mNextAppTransitionOld == TRANSIT_OLD_KEYGUARD_UNOCCLUDE;
    }

@@ -460,7 +460,7 @@ public class AppTransition implements Dump {
     * @return bit-map of WindowManagerPolicy#FINISH_LAYOUT_REDO_* to indicate whether another
     *         layout pass needs to be done
     */
    int goodToGo(int transit, ActivityRecord topOpeningApp, ArraySet<ActivityRecord> openingApps) {
    int goodToGo(@TransitionOldType int transit, ActivityRecord topOpeningApp) {
        mNextAppTransitionOld = TRANSIT_OLD_UNSET;
        mNextAppTransitionFlags = 0;
        mNextAppTransitionRequests.clear();
@@ -469,7 +469,8 @@ public class AppTransition implements Dump {
                topOpeningApp != null ? topOpeningApp.getAnimatingContainer() : null;
        final AnimationAdapter topOpeningAnim = wc != null ? wc.getAnimation() : null;

        int redoLayout = notifyAppTransitionStartingLocked(transit,
        int redoLayout = notifyAppTransitionStartingLocked(
                AppTransition.isKeyguardGoingAwayTransitOld(transit),
                topOpeningAnim != null ? topOpeningAnim.getDurationHint() : 0,
                topOpeningAnim != null
                        ? topOpeningAnim.getStatusBarTransitionsStartTime()
@@ -494,7 +495,10 @@ public class AppTransition implements Dump {
    }

    void freeze() {
        final int transit = mNextAppTransitionOld;
        final boolean keyguardGoingAway = WindowManagerService.sUseNewAppTransit
                ? mNextAppTransitionRequests.contains(TRANSIT_KEYGUARD_GOING_AWAY)
                : isKeyguardGoingAwayTransitOld(mNextAppTransitionOld);

        // The RemoteAnimationControl didn't register AppTransitionListener and
        // only initialized the finish and timeout callback when goodToGo().
        // So cancel the remote animation here to prevent the animation can't do
@@ -503,9 +507,10 @@ public class AppTransition implements Dump {
            mRemoteAnimationController.cancelAnimation("freeze");
        }
        setAppTransitionOld(TRANSIT_OLD_UNSET, 0 /* flags */);
        mNextAppTransitionRequests.clear();
        clear();
        setReady();
        notifyAppTransitionCancelledLocked(transit);
        notifyAppTransitionCancelledLocked(keyguardGoingAway);
    }

    private void setAppTransitionState(int state) {
@@ -525,6 +530,7 @@ public class AppTransition implements Dump {
    private boolean needsBoosting() {
        final boolean recentsAnimRunning = mService.getRecentsAnimationController() != null;
        return mNextAppTransitionOld != TRANSIT_OLD_UNSET
                || !mNextAppTransitionRequests.isEmpty()
                || mAppTransitionState == APP_STATE_READY
                || mAppTransitionState == APP_STATE_RUNNING
                || recentsAnimRunning;
@@ -550,9 +556,9 @@ public class AppTransition implements Dump {
        }
    }

    private void notifyAppTransitionCancelledLocked(int transit) {
    private void notifyAppTransitionCancelledLocked(boolean keyguardGoingAway) {
        for (int i = 0; i < mListeners.size(); i++) {
            mListeners.get(i).onAppTransitionCancelledLocked(transit);
            mListeners.get(i).onAppTransitionCancelledLocked(keyguardGoingAway);
        }
    }

@@ -562,12 +568,12 @@ public class AppTransition implements Dump {
        }
    }

    private int notifyAppTransitionStartingLocked(int transit, long duration,
    private int notifyAppTransitionStartingLocked(boolean keyguardGoingAway, long duration,
            long statusBarAnimationStartTime, long statusBarAnimationDuration) {
        int redoLayout = 0;
        for (int i = 0; i < mListeners.size(); i++) {
            redoLayout |= mListeners.get(i).onAppTransitionStartingLocked(transit, duration,
                    statusBarAnimationStartTime, statusBarAnimationDuration);
            redoLayout |= mListeners.get(i).onAppTransitionStartingLocked(keyguardGoingAway,
                    duration, statusBarAnimationStartTime, statusBarAnimationDuration);
        }
        return redoLayout;
    }
@@ -1578,7 +1584,8 @@ public class AppTransition implements Dump {
                && !mNextAppTransitionOverrideRequested
                && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE
                && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CLIP_REVEAL
                && mNextAppTransitionOld != TRANSIT_OLD_KEYGUARD_GOING_AWAY;
                && mNextAppTransitionOld != TRANSIT_OLD_KEYGUARD_GOING_AWAY
                && !mNextAppTransitionRequests.contains(TRANSIT_KEYGUARD_GOING_AWAY);
    }

    RemoteAnimationController getRemoteAnimationController() {
@@ -1616,7 +1623,7 @@ public class AppTransition implements Dump {
        }

        Animation a;
        if (isKeyguardGoingAwayTransit(transit) && enter) {
        if (isKeyguardGoingAwayTransitOld(transit) && enter) {
            a = loadKeyguardExitAnimation(transit);
        } else if (transit == TRANSIT_OLD_KEYGUARD_OCCLUDE) {
            a = null;
@@ -1807,6 +1814,7 @@ public class AppTransition implements Dump {
                : STACK_CLIP_AFTER_ANIM;
    }

    @TransitionFlags
    public int getTransitFlags() {
        return mNextAppTransitionFlags;
    }
@@ -2194,6 +2202,8 @@ public class AppTransition implements Dump {
                "TRANSIT_FLAG_KEYGUARD_GOING_AWAY_SUBTLE_ANIMATION"));
        sFlagToString.add(new Pair<>(TRANSIT_FLAG_APP_CRASHED,
                "TRANSIT_FLAG_APP_CRASHED"));
        sFlagToString.add(new Pair<>(TRANSIT_FLAG_OPEN_BEHIND,
                "TRANSIT_FLAG_OPEN_BEHIND"));
    }

    /**
@@ -2305,16 +2315,16 @@ public class AppTransition implements Dump {
                        + "Callers=%s",
                appTransitionOldToString(transit), this, alwaysKeepCurrent,
                mDisplayContent.getDisplayId(), Debug.getCallers(5));
        final boolean allowSetCrashing = !isKeyguardTransit(mNextAppTransitionOld)
        final boolean allowSetCrashing = !isKeyguardTransitOld(mNextAppTransitionOld)
                && transit == TRANSIT_OLD_CRASHING_ACTIVITY_CLOSE;
        if (forceOverride || isKeyguardTransit(transit) || !isTransitionSet()
        if (forceOverride || isKeyguardTransitOld(transit) || !isTransitionSet()
                || mNextAppTransitionOld == TRANSIT_OLD_NONE || allowSetCrashing) {
            setAppTransitionOld(transit, flags);
        }
        // We never want to change from a Keyguard transit to a non-Keyguard transit, as our logic
        // relies on the fact that we always execute a Keyguard transition after preparing one. We
        // also don't want to change away from a crashing transition.
        else if (!alwaysKeepCurrent && !isKeyguardTransit(mNextAppTransitionOld)
        else if (!alwaysKeepCurrent && !isKeyguardTransitOld(mNextAppTransitionOld)
                && mNextAppTransitionOld != TRANSIT_OLD_CRASHING_ACTIVITY_CLOSE) {
            if (transit == TRANSIT_OLD_TASK_OPEN && isTransitionOldEqual(TRANSIT_OLD_TASK_CLOSE)) {
                // Opening a new task always supersedes a close for the anim.
@@ -2323,7 +2333,7 @@ public class AppTransition implements Dump {
                    && isTransitionOldEqual(TRANSIT_OLD_ACTIVITY_CLOSE)) {
                // Opening a new activity always supersedes a close for the anim.
                setAppTransitionOld(transit, flags);
            } else if (isTaskTransit(transit) && isActivityTransit(mNextAppTransitionOld)) {
            } else if (isTaskTransitOld(transit) && isActivityTransitOld(mNextAppTransitionOld)) {
                // Task animations always supersede activity animations, because if we have both, it
                // usually means that activity transition were just trampoline activities.
                setAppTransitionOld(transit, flags);
@@ -2349,39 +2359,39 @@ public class AppTransition implements Dump {
     * @return true if {@param transit} is representing a transition in which Keyguard is going
     *         away, false otherwise
     */
    public static boolean isKeyguardGoingAwayTransit(int transit) {
    public static boolean isKeyguardGoingAwayTransitOld(int transit) {
        return transit == TRANSIT_OLD_KEYGUARD_GOING_AWAY
                || transit == TRANSIT_OLD_KEYGUARD_GOING_AWAY_ON_WALLPAPER;
    }

    static boolean isKeyguardTransit(@TransitionOldType int transit) {
        return isKeyguardGoingAwayTransit(transit) || transit == TRANSIT_OLD_KEYGUARD_OCCLUDE
    static boolean isKeyguardTransitOld(@TransitionOldType int transit) {
        return isKeyguardGoingAwayTransitOld(transit) || transit == TRANSIT_OLD_KEYGUARD_OCCLUDE
                || transit == TRANSIT_OLD_KEYGUARD_UNOCCLUDE;
    }

    static boolean isTaskTransit(@TransitionOldType int transit) {
        return isTaskOpenTransit(transit)
    static boolean isTaskTransitOld(@TransitionOldType int transit) {
        return isTaskOpenTransitOld(transit)
                || transit == TRANSIT_OLD_TASK_CLOSE
                || transit == TRANSIT_OLD_TASK_TO_BACK;
    }

    private static  boolean isTaskOpenTransit(@TransitionOldType int transit) {
    private static  boolean isTaskOpenTransitOld(@TransitionOldType int transit) {
        return transit == TRANSIT_OLD_TASK_OPEN
                || transit == TRANSIT_OLD_TASK_OPEN_BEHIND
                || transit == TRANSIT_OLD_TASK_TO_FRONT;
    }

    static boolean isActivityTransit(@TransitionOldType int transit) {
    static boolean isActivityTransitOld(@TransitionOldType int transit) {
        return transit == TRANSIT_OLD_ACTIVITY_OPEN
                || transit == TRANSIT_OLD_ACTIVITY_CLOSE
                || transit == TRANSIT_OLD_ACTIVITY_RELAUNCH;
    }

    static boolean isChangeTransit(@TransitionOldType int transit) {
    static boolean isChangeTransitOld(@TransitionOldType int transit) {
        return transit == TRANSIT_OLD_TASK_CHANGE_WINDOWING_MODE;
    }

    static boolean isClosingTransit(@TransitionOldType int transit) {
    static boolean isClosingTransitOld(@TransitionOldType int transit) {
        return transit == TRANSIT_OLD_ACTIVITY_CLOSE
                || transit == TRANSIT_OLD_TASK_CLOSE
                || transit == TRANSIT_OLD_WALLPAPER_CLOSE
@@ -2390,6 +2400,51 @@ public class AppTransition implements Dump {
                || transit == TRANSIT_OLD_CRASHING_ACTIVITY_CLOSE;
    }

    static boolean isNormalTransit(@TransitionType int transit) {
        return transit == TRANSIT_OPEN
                || transit == TRANSIT_CLOSE
                || transit == TRANSIT_TO_FRONT
                || transit == TRANSIT_TO_BACK;
    }

    static boolean isKeyguardTransit(@TransitionType int transit) {
        return transit == TRANSIT_KEYGUARD_GOING_AWAY
                || transit == TRANSIT_KEYGUARD_OCCLUDE
                || transit == TRANSIT_KEYGUARD_UNOCCLUDE;
    }

    @TransitionType int getKeyguardTransition() {
        // In case we unocclude Keyguard and occlude it again, meaning that we never actually
        // unoccclude/occlude Keyguard, but just run a normal transition.
        final int occludeIndex = mNextAppTransitionRequests.indexOf(TRANSIT_KEYGUARD_UNOCCLUDE);
        if (occludeIndex != -1
                && occludeIndex < mNextAppTransitionRequests.indexOf(TRANSIT_KEYGUARD_OCCLUDE)) {
            return TRANSIT_NONE;
        }

        for (int i = 0; i < mNextAppTransitionRequests.size(); ++i) {
            final @TransitionType int transit = mNextAppTransitionRequests.get(i);
            if (isKeyguardTransit(transit)) {
                return transit;
            }
        }
        return TRANSIT_NONE;
    }

    @TransitionType int getFirstAppTransition() {
        for (int i = 0; i < mNextAppTransitionRequests.size(); ++i) {
            final @TransitionType int transit = mNextAppTransitionRequests.get(i);
            if (transit != TRANSIT_NONE && !isKeyguardTransit(transit)) {
                return transit;
            }
        }
        return TRANSIT_NONE;
    }

    boolean containsTransitRequest(@TransitionType int transit) {
        return mNextAppTransitionRequests.contains(transit);
    }

    /**
     * @return whether the transition should show the thumbnail being scaled down.
     */
Loading