Merge "Pass the values of the MotionEvent instead of the event instance itself to BackAnimation." into tm-dev
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/back/BackAnimation.java b/libs/WindowManager/Shell/src/com/android/wm/shell/back/BackAnimation.java
index e71a59d..8c0affb 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/back/BackAnimation.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/back/BackAnimation.java
@@ -31,13 +31,15 @@
     /**
      * 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
+     * @param touchX the X touch position of the {@link MotionEvent}.
+     * @param touchY the Y touch position of the {@link MotionEvent}.
+     * @param keyAction 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, int action, @BackEvent.SwipeEdge int swipeEdge);
+    void onBackMotion(float touchX, float touchY, int keyAction,
+            @BackEvent.SwipeEdge int swipeEdge);
 
     /**
      * Sets whether the back gesture is past the trigger threshold or not.
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/back/BackAnimationController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/back/BackAnimationController.java
index 0cb56d7..0cf2b28 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/back/BackAnimationController.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/back/BackAnimationController.java
@@ -184,8 +184,8 @@
 
         @Override
         public void onBackMotion(
-                MotionEvent event, int action, @BackEvent.SwipeEdge int swipeEdge) {
-            mShellExecutor.execute(() -> onMotionEvent(event, action, swipeEdge));
+                float touchX, float touchY, int keyAction, @BackEvent.SwipeEdge int swipeEdge) {
+            mShellExecutor.execute(() -> onMotionEvent(touchX, touchY, keyAction, swipeEdge));
         }
 
         @Override
@@ -256,33 +256,34 @@
      * Called when a new motion event needs to be transferred to this
      * {@link BackAnimationController}
      */
-    public void onMotionEvent(MotionEvent event, int action, @BackEvent.SwipeEdge int swipeEdge) {
+    public void onMotionEvent(float touchX, float touchY, int keyAction,
+            @BackEvent.SwipeEdge int swipeEdge) {
         if (mTransitionInProgress) {
             return;
         }
-        if (action == MotionEvent.ACTION_MOVE) {
+        if (keyAction == MotionEvent.ACTION_MOVE) {
             if (!mBackGestureStarted) {
                 // Let the animation initialized here to make sure the onPointerDownOutsideFocus
                 // could be happened when ACTION_DOWN, it may change the current focus that we
                 // would access it when startBackNavigation.
-                initAnimation(event);
+                initAnimation(touchX, touchY);
             }
-            onMove(event, swipeEdge);
-        } else if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) {
+            onMove(touchX, touchY, swipeEdge);
+        } else if (keyAction == MotionEvent.ACTION_UP || keyAction == MotionEvent.ACTION_CANCEL) {
             ProtoLog.d(WM_SHELL_BACK_PREVIEW,
-                    "Finishing gesture with event action: %d", action);
+                    "Finishing gesture with event action: %d", keyAction);
             onGestureFinished();
         }
     }
 
-    private void initAnimation(MotionEvent event) {
+    private void initAnimation(float touchX, float touchY) {
         ProtoLog.d(WM_SHELL_BACK_PREVIEW, "initAnimation mMotionStarted=%b", mBackGestureStarted);
         if (mBackGestureStarted || mBackNavigationInfo != null) {
             Log.e(TAG, "Animation is being initialized but is already started.");
             finishAnimation();
         }
 
-        mInitTouchLocation.set(event.getX(), event.getY());
+        mInitTouchLocation.set(touchX, touchY);
         mBackGestureStarted = true;
 
         try {
@@ -351,18 +352,18 @@
         mTransaction.setVisibility(screenshotSurface, true);
     }
 
-    private void onMove(MotionEvent event, @BackEvent.SwipeEdge int swipeEdge) {
+    private void onMove(float touchX, float touchY, @BackEvent.SwipeEdge int swipeEdge) {
         if (!mBackGestureStarted || mBackNavigationInfo == null) {
             return;
         }
-        int deltaX = Math.round(event.getX() - mInitTouchLocation.x);
+        int deltaX = Math.round(touchX - mInitTouchLocation.x);
         float progressThreshold = PROGRESS_THRESHOLD >= 0 ? PROGRESS_THRESHOLD : mProgressThreshold;
         float progress = Math.min(Math.max(Math.abs(deltaX) / progressThreshold, 0), 1);
         int backType = mBackNavigationInfo.getType();
         RemoteAnimationTarget animationTarget = mBackNavigationInfo.getDepartingAnimationTarget();
 
         BackEvent backEvent = new BackEvent(
-                event.getX(), event.getY(), progress, swipeEdge, animationTarget);
+                touchX, touchY, progress, swipeEdge, animationTarget);
         IOnBackInvokedCallback targetCallback = null;
         if (shouldDispatchToLauncher(backType)) {
             targetCallback = mBackToLauncherCallback;
diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/back/BackAnimationControllerTest.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/back/BackAnimationControllerTest.java
index fcfcbfa..e7c5cb2 100644
--- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/back/BackAnimationControllerTest.java
+++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/back/BackAnimationControllerTest.java
@@ -298,7 +298,7 @@
 
     private void doMotionEvent(int actionDown, int coordinate) {
         mController.onMotionEvent(
-                MotionEvent.obtain(0, mEventTime, actionDown, coordinate, coordinate, 0),
+                coordinate, coordinate,
                 actionDown,
                 BackEvent.EDGE_LEFT);
         mEventTime += 10;
diff --git a/packages/SystemUI/src/com/android/systemui/navigationbar/gestural/NavigationBarEdgePanel.java b/packages/SystemUI/src/com/android/systemui/navigationbar/gestural/NavigationBarEdgePanel.java
index a74c596..eba9d3f 100644
--- a/packages/SystemUI/src/com/android/systemui/navigationbar/gestural/NavigationBarEdgePanel.java
+++ b/packages/SystemUI/src/com/android/systemui/navigationbar/gestural/NavigationBarEdgePanel.java
@@ -486,7 +486,7 @@
     public void onMotionEvent(MotionEvent event) {
         if (mBackAnimation != null) {
             mBackAnimation.onBackMotion(
-                    event,
+                    event.getX(), event.getY(),
                     event.getActionMasked(),
                     mIsLeftPanel ? BackEvent.EDGE_LEFT : BackEvent.EDGE_RIGHT);
         }