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

Commit a0be92c8 authored by Schneider Victor-tulias's avatar Schneider Victor-tulias
Browse files

Add debug logs to help identify when setRecentsAttachedToAppWindow will not animate properly.

Bug: 244593270
Test: Manually checked logs
Change-Id: Ie6d0395a45a025d1562a722154d3dd3b42618ccc
parent 888f7454
Loading
Loading
Loading
Loading
+55 −20
Original line number Diff line number Diff line
@@ -273,7 +273,7 @@ public abstract class AbsSwipeUpHandler<T extends StatefulActivity<S>,
    private AnimatorControllerWithResistance mLauncherTransitionController;
    private boolean mHasEndedLauncherTransition;

    private AnimationFactory mAnimationFactory = (t) -> { };
    private AnimationFactory mAnimationFactory = (t, s) -> { };

    private boolean mWasLauncherAlreadyVisible;

@@ -508,7 +508,9 @@ public abstract class AbsSwipeUpHandler<T extends StatefulActivity<S>,
            Runnable initAnimFactory = () -> {
                mAnimationFactory = mActivityInterface.prepareRecentsUI(mDeviceState,
                        mWasLauncherAlreadyVisible, this::onAnimatorPlaybackControllerCreated);
                maybeUpdateRecentsAttachedState(false /* animate */);
                maybeUpdateRecentsAttachedState(
                        false /* animate */,
                        new ActiveGestureLog.CompoundString("on Launcher start (animate=false)"));
                if (mGestureState.getEndTarget() != null) {
                    // Update the end target in case the gesture ended before we init.
                    mAnimationFactory.setEndTarget(mGestureState.getEndTarget());
@@ -617,7 +619,8 @@ public abstract class AbsSwipeUpHandler<T extends StatefulActivity<S>,
    }

    private void initializeLauncherAnimationController() {
        buildAnimationController();
        buildAnimationController(new ActiveGestureLog.CompoundString(
                "initializing launcher animation controller"));

        Object traceToken = TraceHelper.INSTANCE.beginSection("logToggleRecents",
                TraceHelper.FLAG_IGNORE_BINDERS);
@@ -636,7 +639,11 @@ public abstract class AbsSwipeUpHandler<T extends StatefulActivity<S>,
            @Override
            public void onMotionPauseDetected() {
                mHasMotionEverBeenPaused = true;
                maybeUpdateRecentsAttachedState(true/* animate */, true/* moveFocusedTask */);
                maybeUpdateRecentsAttachedState(
                        true/* animate */,
                        true/* moveFocusedTask */,
                        new ActiveGestureLog.CompoundString(
                                "motion pause detected (animate=true)"));
                performHapticFeedback();
            }

@@ -647,12 +654,13 @@ public abstract class AbsSwipeUpHandler<T extends StatefulActivity<S>,
        };
    }

    private void maybeUpdateRecentsAttachedState() {
        maybeUpdateRecentsAttachedState(true /* animate */);
    private void maybeUpdateRecentsAttachedState(ActiveGestureLog.CompoundString reason) {
        maybeUpdateRecentsAttachedState(true /* animate */, reason.append(" (animate=true)"));
    }

    private void maybeUpdateRecentsAttachedState(boolean animate) {
        maybeUpdateRecentsAttachedState(animate, false /* moveFocusedTask */);
    private void maybeUpdateRecentsAttachedState(
            boolean animate, ActiveGestureLog.CompoundString reason) {
        maybeUpdateRecentsAttachedState(animate, false /* moveFocusedTask */, reason);
    }

    /**
@@ -664,7 +672,8 @@ public abstract class AbsSwipeUpHandler<T extends StatefulActivity<S>,
     * @param animate whether to animate when attaching RecentsView
     * @param moveFocusedTask whether to move focused task to front when attaching
     */
    private void maybeUpdateRecentsAttachedState(boolean animate, boolean moveFocusedTask) {
    private void maybeUpdateRecentsAttachedState(
            boolean animate, boolean moveFocusedTask, ActiveGestureLog.CompoundString reason) {
        if (!mDeviceState.isFullyGesturalNavMode() || mRecentsView == null) {
            return;
        }
@@ -674,14 +683,25 @@ public abstract class AbsSwipeUpHandler<T extends StatefulActivity<S>,
        final boolean recentsAttachedToAppWindow;
        if (mGestureState.getEndTarget() != null) {
            recentsAttachedToAppWindow = mGestureState.getEndTarget().recentsAttachedToAppWindow;
            reason.append("; gesture state end target != null (attached=")
                    .append(Boolean.toString(recentsAttachedToAppWindow))
                    .append(")");
        } else if (mContinuingLastGesture
                && mRecentsView.getRunningTaskIndex() != mRecentsView.getNextPage()) {
            recentsAttachedToAppWindow = true;
            reason.append("; continuing last gesture (attached=true)");
        } else if (runningTaskTarget != null && isNotInRecents(runningTaskTarget)) {
            // The window is going away so make sure recents is always visible in this case.
            recentsAttachedToAppWindow = true;
            reason.append("; make sure recents is always visible (attached=true)");
        } else {
            recentsAttachedToAppWindow = mHasMotionEverBeenPaused || mIsLikelyToStartNewTask;
            reason.append(mHasMotionEverBeenPaused
                            ? "; motion has been paused"
                            : "; gesture is likely to start a new task")
                    .append(" (attached=")
                    .append(Boolean.toString(recentsAttachedToAppWindow))
                    .append(")");
        }
        if (moveFocusedTask && !mAnimationFactory.hasRecentsEverAttachedToAppWindow()
                && recentsAttachedToAppWindow) {
@@ -689,7 +709,8 @@ public abstract class AbsSwipeUpHandler<T extends StatefulActivity<S>,
            // TaskView jumping to new position as we move the tasks.
            mRecentsView.moveFocusedTaskToFront();
        }
        mAnimationFactory.setRecentsAttachedToAppWindow(recentsAttachedToAppWindow, animate);
        mAnimationFactory.setRecentsAttachedToAppWindow(
                recentsAttachedToAppWindow, animate, reason);

        // Reapply window transform throughout the attach animation, as the animation affects how
        // much the window is bound by overscroll (vs moving freely).
@@ -709,22 +730,29 @@ public abstract class AbsSwipeUpHandler<T extends StatefulActivity<S>,
    }

    public void setIsLikelyToStartNewTask(boolean isLikelyToStartNewTask) {
        setIsLikelyToStartNewTask(isLikelyToStartNewTask, true /* animate */);
        setIsLikelyToStartNewTask(
                isLikelyToStartNewTask,
                true /* animate */,
                new ActiveGestureLog.CompoundString(
                        "setting gesture likely to start (animate=true)"));
    }

    private void setIsLikelyToStartNewTask(boolean isLikelyToStartNewTask, boolean animate) {
    private void setIsLikelyToStartNewTask(
            boolean isLikelyToStartNewTask,
            boolean animate,
            ActiveGestureLog.CompoundString reason) {
        if (mIsLikelyToStartNewTask != isLikelyToStartNewTask) {
            mIsLikelyToStartNewTask = isLikelyToStartNewTask;
            maybeUpdateRecentsAttachedState(animate);
            maybeUpdateRecentsAttachedState(animate, reason);
        }
    }

    private void buildAnimationController() {
    private void buildAnimationController(ActiveGestureLog.CompoundString reason) {
        if (!canCreateNewOrUpdateExistingLauncherTransitionController()) {
            return;
        }
        initTransitionEndpoints(mActivity.getDeviceProfile());
        mAnimationFactory.createActivityInterface(mTransitionDragLength);
        mAnimationFactory.createActivityInterface(mTransitionDragLength, reason);
    }

    /**
@@ -739,7 +767,7 @@ public abstract class AbsSwipeUpHandler<T extends StatefulActivity<S>,
    @Override
    public WindowInsets onApplyWindowInsets(View view, WindowInsets windowInsets) {
        WindowInsets result = view.onApplyWindowInsets(windowInsets);
        buildAnimationController();
        buildAnimationController(new ActiveGestureLog.CompoundString("applying window insets"));
        // Reapply the current shift to ensure it takes new insets into account, e.g. when long
        // pressing to stash taskbar without moving the finger.
        updateFinalShift();
@@ -911,7 +939,10 @@ public abstract class AbsSwipeUpHandler<T extends StatefulActivity<S>,
            });
        }
        notifyGestureStartedAsync();
        setIsLikelyToStartNewTask(isLikelyToStartNewTask, false /* animate */);
        setIsLikelyToStartNewTask(
                isLikelyToStartNewTask,
                false /* animate */,
                new ActiveGestureLog.CompoundString("on gesture started (animate=false)"));
        mStateCallback.setStateOnUiThread(STATE_GESTURE_STARTED);
        mGestureStarted = true;
        SystemUiProxy.INSTANCE.get(mContext).notifySwipeUpGestureStarted();
@@ -993,7 +1024,8 @@ public abstract class AbsSwipeUpHandler<T extends StatefulActivity<S>,

    private void onSettledOnEndTarget() {
        // Fast-finish the attaching animation if it's still running.
        maybeUpdateRecentsAttachedState(false);
        maybeUpdateRecentsAttachedState(false, new ActiveGestureLog.CompoundString(
                "on settled on end target (animate=false)"));
        final GestureEndTarget endTarget = mGestureState.getEndTarget();
        // Wait until the given View (if supplied) draws before resuming the last task.
        View postResumeLastTask = mActivityInterface.onSettledOnEndTarget(endTarget);
@@ -1299,7 +1331,8 @@ public abstract class AbsSwipeUpHandler<T extends StatefulActivity<S>,
    @UiThread
    private void animateToProgressInternal(float start, float end, long duration,
            Interpolator interpolator, GestureEndTarget target, PointF velocityPxPerMs) {
        maybeUpdateRecentsAttachedState();
        maybeUpdateRecentsAttachedState(new ActiveGestureLog.CompoundString(
                "animate to progress internal"));

        // If we are transitioning to launcher, then listen for the activity to be restarted while
        // the transition is in progress
@@ -1618,7 +1651,9 @@ public abstract class AbsSwipeUpHandler<T extends StatefulActivity<S>,
                    mRecentsView.post(mRecentsView::resetTaskVisuals);
                }
                // Make sure recents is in its final state
                maybeUpdateRecentsAttachedState(false);
                maybeUpdateRecentsAttachedState(
                        false, new ActiveGestureLog.CompoundString(
                                "setting up window animation (animate=false)"));
                mActivityInterface.onSwipeUpToHomeComplete(mDeviceState);
            }
        });
+37 −5
Original line number Diff line number Diff line
@@ -57,6 +57,7 @@ import com.android.launcher3.touch.PagedOrientationHandler;
import com.android.launcher3.util.DisplayController;
import com.android.launcher3.util.NavigationMode;
import com.android.launcher3.views.ScrimView;
import com.android.quickstep.util.ActiveGestureLog;
import com.android.quickstep.util.ActivityInitListener;
import com.android.quickstep.util.AnimatorControllerWithResistance;
import com.android.quickstep.views.RecentsView;
@@ -393,14 +394,16 @@ public abstract class BaseActivityInterface<STATE_TYPE extends BaseState<STATE_T

    public interface AnimationFactory {

        void createActivityInterface(long transitionLength);
        void createActivityInterface(long transitionLength, ActiveGestureLog.CompoundString reason);

        /**
         * @param attached Whether to show RecentsView alongside the app window. If false, recents
         *                 will be hidden by some property we can animate, e.g. alpha.
         * @param animate Whether to animate recents to/from its new attached state.
         * @param reason Explanation for why this method is being called with the given param values
         */
        default void setRecentsAttachedToAppWindow(boolean attached, boolean animate) { }
        default void setRecentsAttachedToAppWindow(
                boolean attached, boolean animate, ActiveGestureLog.CompoundString reason) { }

        default boolean isRecentsAttachedToAppWindow() {
            return false;
@@ -442,7 +445,8 @@ public abstract class BaseActivityInterface<STATE_TYPE extends BaseState<STATE_T
        }

        @Override
        public void createActivityInterface(long transitionLength) {
        public void createActivityInterface(
                long transitionLength, ActiveGestureLog.CompoundString reason) {
            PendingAnimation pa = new PendingAnimation(transitionLength * 2);
            createBackgroundToOverviewAnim(mActivity, pa);
            AnimatorPlaybackController controller = pa.createPlaybackController();
@@ -465,13 +469,29 @@ public abstract class BaseActivityInterface<STATE_TYPE extends BaseState<STATE_T
            // (because we set the animation as the current state animation), so we reapply the
            // attached state here as well to ensure recents is shown/hidden appropriately.
            if (DisplayController.getNavigationMode(mActivity) == NavigationMode.NO_BUTTON) {
                setRecentsAttachedToAppWindow(mIsAttachedToWindow, false);
                setRecentsAttachedToAppWindow(
                        mIsAttachedToWindow,
                        false,
                        reason.append("; reapplying the attached state (attached=")
                                .append(Boolean.toString(mIsAttachedToWindow))
                                .append(", animate=false)"));
            }
        }

        @Override
        public void setRecentsAttachedToAppWindow(boolean attached, boolean animate) {
        public void setRecentsAttachedToAppWindow(
                boolean attached, boolean animate, ActiveGestureLog.CompoundString reason) {
            // TODO(b/244593270): remove these logs; too verbose
            ActiveGestureLog.INSTANCE.addLog(
                    new ActiveGestureLog.CompoundString("setRecentsAttachedToAppWindow: attached=")
                            .append(Boolean.toString(attached))
                            .append(", animate=")
                            .append(Boolean.toString(animate))
                            .append(", reason=")
                            .append(reason));
            if (mIsAttachedToWindow == attached && animate) {
                ActiveGestureLog.INSTANCE.addLog(new ActiveGestureLog.CompoundString(
                        "setRecentsAttachedToAppWindow: exiting early"));
                return;
            }
            mIsAttachedToWindow = attached;
@@ -488,9 +508,21 @@ public abstract class BaseActivityInterface<STATE_TYPE extends BaseState<STATE_T
                    .cancelStateElementAnimation(INDEX_RECENTS_TRANSLATE_X_ANIM);
            if (!recentsView.isShown() && animate) {
                ADJACENT_PAGE_HORIZONTAL_OFFSET.set(recentsView, fromTranslation);
                ActiveGestureLog.INSTANCE.addLog(new ActiveGestureLog.CompoundString(
                        "setRecentsAttachedToAppWindow: recents view not shown, setting ")
                        .append("ADJACENT_PAGE_HORIZONTAL_OFFSET to ")
                        .append(Float.toString(fromTranslation)));
            } else {
                fromTranslation = ADJACENT_PAGE_HORIZONTAL_OFFSET.get(recentsView);
            }
                ActiveGestureLog.INSTANCE.addLog(new ActiveGestureLog.CompoundString(
                        "setRecentsAttachedToAppWindow: updating fromTranslation to ")
                        .append(Float.toString(fromTranslation)));
            }
            ActiveGestureLog.INSTANCE.addLog(new ActiveGestureLog.CompoundString(
                    "setRecentsAttachedToAppWindow: fromTranslation=")
                    .append(Float.toString(fromTranslation))
                    .append(", toTranslation=")
                    .append(Float.toString(toTranslation)));
            if (!animate) {
                ADJACENT_PAGE_HORIZONTAL_OFFSET.set(recentsView, toTranslation);
            } else {