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

Commit 4bc760b9 authored by wilsonshih's avatar wilsonshih
Browse files

Separate the predictive back transition request from start navigation.

When a finger-down event occurs, the system gets the current back
navigation info from the window manager but does not trigger the
animation immediately.
Instead, the predictive back animation is only triggered when the
gesture movement has crossed the threshold. Therefore, the shell can
pilfer pointers earlier, before the threshold is crossed, and it will
not trigger an extra transition if nothing happen.

Flag: com.android.window.flags.predictive_back_delay_wm_transition
Bug: 301195601
Bug: 418854576
Test: atest BackNavigationControllerTests BackAnimationControllerTest
Change-Id: If6beb4dcfea1c87df870fc23072eb8aeb7db881e
parent 4a767ed1
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -375,6 +375,12 @@ interface IActivityTaskManager {
    android.window.BackNavigationInfo startBackNavigation(
            in RemoteCallback navigationObserver, in BackAnimationAdapter adaptor);

    /**
     * This setups the leashed for sysui to animate the current back gesture.
     * Only valid after startBackNavigation.
     */
    void startPredictiveBackAnimation();

    /**
     * registers a callback to be invoked when a background activity launch is aborted.
     *
+0 −7
Original line number Diff line number Diff line
@@ -80,13 +80,6 @@ public final class BackNavigationInfo implements Parcelable {
     */
    public static final String KEY_NAVIGATION_FINISHED = "NavigationFinished";

    /**
     * Key to access the boolean value passed in {#mOnBackNavigationDone} result bundle
     * that represents if back gesture has been triggered.
     * @hide
     */
    public static final String KEY_GESTURE_FINISHED = "GestureFinished";

    /**
     * Touch gestured has transferred to embedded window, Shell should pilfer pointers so the
     * embedded won't receive motion events.
+10 −0
Original line number Diff line number Diff line
@@ -442,6 +442,16 @@ flag {
    }
}

flag {
    name: "predictive_back_delay_wm_transition"
    namespace: "windowing_frontend"
    description: "Separate the predictive back transition request from start navigation"
    bug: "301195601"
    metadata {
      purpose: PURPOSE_BUGFIX
    }
}

flag {
    name: "current_animator_scale_uses_shared_memory"
    namespace: "wear_system_health"
+29 −15
Original line number Diff line number Diff line
@@ -30,7 +30,7 @@ import static android.window.TransitionInfo.FLAG_MOVED_TO_TOP;
import static android.window.TransitionInfo.FLAG_SHOW_WALLPAPER;

import static com.android.internal.jank.InteractionJankMonitor.CUJ_PREDICTIVE_BACK_HOME;
import static com.android.systemui.Flags.predictiveBackDelayWmTransition;
import static com.android.window.flags.Flags.predictiveBackDelayWmTransition;
import static com.android.wm.shell.protolog.ShellProtoLogGroup.WM_SHELL_BACK_PREVIEW;

import android.annotation.NonNull;
@@ -339,12 +339,8 @@ public class BackAnimationController implements RemoteCallable<BackAnimationCont

        @Override
        public void onThresholdCrossed() {
            if (predictiveBackDelayWmTransition()) {
                mShellExecutor.execute(BackAnimationController.this::onThresholdCrossed);
            } else {
            BackAnimationController.this.onThresholdCrossed();
        }
        }

        @Override
        public void setTriggerBack(boolean triggerBack) {
@@ -443,11 +439,6 @@ public class BackAnimationController implements RemoteCallable<BackAnimationCont
    @VisibleForTesting
    public void onThresholdCrossed() {
        mThresholdCrossed = true;
        BackTouchTracker activeTracker = getActiveTracker();
        if (predictiveBackDelayWmTransition() && activeTracker != null && mActiveCallback == null
                && mBackGestureStarted) {
            startBackNavigation(activeTracker);
        }
        // There was no focus window when calling startBackNavigation, still pilfer pointers so
        // the next focus window won't receive motion events.
        if (mBackNavigationInfo == null && mReceivedNullNavigationInfo) {
@@ -466,6 +457,25 @@ public class BackAnimationController implements RemoteCallable<BackAnimationCont
        } else if (shouldDispatchToAnimator) {
            tryPilferPointers();
        }

        if (predictiveBackDelayWmTransition()) {
            mShellExecutor.execute(() -> {
                if (shouldDispatchToAnimator()) {
                    try {
                        mActivityTaskManager.startPredictiveBackAnimation();
                    } catch (RemoteException r) {
                        Log.e(TAG, "Failed to start predictive animation", r);
                        finishBackNavigation(mCurrentTracker.getTriggerBack());
                        return;
                    }
                    final int backType = mBackNavigationInfo.getType();
                    if (!mShellBackAnimationRegistry.startGesture(backType)) {
                        mActiveCallback = null;
                    }
                    requestTopUi(true, backType);
                }
            });
        }
    }

    private boolean isAppProgressGenerationAllowed() {
@@ -575,7 +585,7 @@ public class BackAnimationController implements RemoteCallable<BackAnimationCont
            mPostCommitAnimationInProgress = false;
            mShellExecutor.removeCallbacks(mAnimationTimeoutRunnable);
            startSystemAnimation();
        } else if (!predictiveBackDelayWmTransition()) {
        } else {
            startBackNavigation(touchTracker);
        }
    }
@@ -615,10 +625,12 @@ public class BackAnimationController implements RemoteCallable<BackAnimationCont
        final int backType = backNavigationInfo.getType();
        final boolean shouldDispatchToAnimator = shouldDispatchToAnimator();
        if (shouldDispatchToAnimator) {
            if (!predictiveBackDelayWmTransition()) {
                if (!mShellBackAnimationRegistry.startGesture(backType)) {
                    mActiveCallback = null;
                }
                requestTopUi(true, backType);
            }
            tryPilferPointers();
        } else {
            mActiveCallback = mBackNavigationInfo.getOnBackInvokedCallback();
@@ -829,6 +841,7 @@ public class BackAnimationController implements RemoteCallable<BackAnimationCont
                            ? mBackNavigationInfo.getFocusedTaskId()
                            : INVALID_TASK_ID);
        }
        final boolean hasRequestAnimation = mThresholdCrossed;
        // Reset gesture states.
        mThresholdCrossed = false;
        mPointersPilfered = false;
@@ -858,6 +871,7 @@ public class BackAnimationController implements RemoteCallable<BackAnimationCont
        final int backType = mBackNavigationInfo.getType();
        // Simply trigger and finish back navigation when no animator defined.
        if (!shouldDispatchToAnimator()
                || (!hasRequestAnimation && predictiveBackDelayWmTransition())
                || mShellBackAnimationRegistry.isAnimationCancelledOrNull(backType)) {
            ProtoLog.d(WM_SHELL_BACK_PREVIEW, "Trigger back without dispatching to animator.");
            invokeOrCancelBack(mCurrentTracker);
+1 −11
Original line number Diff line number Diff line
@@ -7,13 +7,3 @@ flag {
    description: "Enable Shade Animations"
    bug: "327732946"
}
 No newline at end of file

flag {
    name: "predictive_back_delay_wm_transition"
    namespace: "systemui"
    description: "Slightly delays the back transition start"
    bug: "301195601"
    metadata {
      purpose: PURPOSE_BUGFIX
    }
}
Loading