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

Commit 342dccd9 authored by Shan Huang's avatar Shan Huang Committed by Android (Google) Code Review
Browse files

Merge "Fix back taking multiple swipes." into tm-dev

parents 82f3bb31 83e901d8
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.wm.shell.back;

import android.view.KeyEvent;
import android.view.MotionEvent;
import android.window.BackEvent;

@@ -29,8 +30,14 @@ public interface BackAnimation {

    /**
     * Called when a {@link MotionEvent} is generated by a back gesture.
     *
     * @param event the original {@link MotionEvent}
     * @param action the original {@link KeyEvent#getAction()} when the event was dispatched to
     *               the process. This is forwarded separately because the input pipeline may mutate
     *               the {#event} action state later.
     * @param swipeEdge the edge from which the swipe begins.
     */
    void onBackMotion(MotionEvent event, @BackEvent.SwipeEdge int swipeEdge);
    void onBackMotion(MotionEvent event, int action, @BackEvent.SwipeEdge int swipeEdge);

    /**
     * Sets whether the back gesture is past the trigger threshold or not.
+5 −4
Original line number Diff line number Diff line
@@ -138,8 +138,9 @@ public class BackAnimationController implements RemoteCallable<BackAnimationCont
        }

        @Override
        public void onBackMotion(MotionEvent event, @BackEvent.SwipeEdge int swipeEdge) {
            mShellExecutor.execute(() -> onMotionEvent(event, swipeEdge));
        public void onBackMotion(
                MotionEvent event, int action, @BackEvent.SwipeEdge int swipeEdge) {
            mShellExecutor.execute(() -> onMotionEvent(event, action, swipeEdge));
        }

        @Override
@@ -209,13 +210,13 @@ public class BackAnimationController implements RemoteCallable<BackAnimationCont
     * Called when a new motion event needs to be transferred to this
     * {@link BackAnimationController}
     */
    public void onMotionEvent(MotionEvent event, @BackEvent.SwipeEdge int swipeEdge) {
        int action = event.getActionMasked();
    public void onMotionEvent(MotionEvent event, int action, @BackEvent.SwipeEdge int swipeEdge) {
        if (action == MotionEvent.ACTION_DOWN) {
            initAnimation(event);
        } else if (action == MotionEvent.ACTION_MOVE) {
            onMove(event, swipeEdge);
        } else if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) {
            ProtoLog.d(WM_SHELL_BACK_PREVIEW, "Finishing gesture with event: %s", event);
            onGestureFinished();
        }
    }
+6 −0
Original line number Diff line number Diff line
@@ -118,6 +118,7 @@ public class BackAnimationControllerTest {
                BackNavigationInfo.TYPE_CROSS_ACTIVITY);
        mController.onMotionEvent(
                MotionEvent.obtain(0, 0, MotionEvent.ACTION_DOWN, 0, 0, 0),
                MotionEvent.ACTION_DOWN,
                BackEvent.EDGE_LEFT);
        verify(mTransaction).setBuffer(screenshotSurface, hardwareBuffer);
        verify(mTransaction).setVisibility(screenshotSurface, true);
@@ -133,9 +134,11 @@ public class BackAnimationControllerTest {
                BackNavigationInfo.TYPE_CROSS_ACTIVITY);
        mController.onMotionEvent(
                MotionEvent.obtain(0, 0, MotionEvent.ACTION_DOWN, 0, 0, 0),
                MotionEvent.ACTION_DOWN,
                BackEvent.EDGE_LEFT);
        mController.onMotionEvent(
                MotionEvent.obtain(10, 0, MotionEvent.ACTION_MOVE, 100, 100, 0),
                MotionEvent.ACTION_MOVE,
                BackEvent.EDGE_LEFT);
        verify(mTransaction).setPosition(animationTarget.leash, 100, 100);
        verify(mTransaction, atLeastOnce()).apply();
@@ -151,12 +154,14 @@ public class BackAnimationControllerTest {
        // Check that back start is dispatched.
        mController.onMotionEvent(
                MotionEvent.obtain(0, 0, MotionEvent.ACTION_DOWN, 0, 0, 0),
                MotionEvent.ACTION_DOWN,
                BackEvent.EDGE_LEFT);
        verify(mIOnBackInvokedCallback).onBackStarted();

        // Check that back progress is dispatched.
        mController.onMotionEvent(
                MotionEvent.obtain(10, 0, MotionEvent.ACTION_MOVE, 100, 100, 0),
                MotionEvent.ACTION_MOVE,
                BackEvent.EDGE_LEFT);
        ArgumentCaptor<BackEvent> backEventCaptor = ArgumentCaptor.forClass(BackEvent.class);
        verify(mIOnBackInvokedCallback).onBackProgressed(backEventCaptor.capture());
@@ -166,6 +171,7 @@ public class BackAnimationControllerTest {
        mController.setTriggerBack(true);   // Fake trigger back
        mController.onMotionEvent(
                MotionEvent.obtain(0, 0, MotionEvent.ACTION_UP, 0, 0, 0),
                MotionEvent.ACTION_UP,
                BackEvent.EDGE_LEFT);
        verify(mIOnBackInvokedCallback).onBackInvoked();
    }
+3 −1
Original line number Diff line number Diff line
@@ -480,7 +480,9 @@ public class NavigationBarEdgePanel extends View implements NavigationEdgeBackPl
    public void onMotionEvent(MotionEvent event) {
        if (mBackAnimation != null) {
            mBackAnimation.onBackMotion(
                    event, mIsLeftPanel ? BackEvent.EDGE_LEFT : BackEvent.EDGE_RIGHT);
                    event,
                    event.getActionMasked(),
                    mIsLeftPanel ? BackEvent.EDGE_LEFT : BackEvent.EDGE_RIGHT);
        }
        if (mVelocityTracker == null) {
            mVelocityTracker = VelocityTracker.obtain();