From ff898c640764b5c25414b58ebef0e51f25a3d1a9 Mon Sep 17 00:00:00 2001 From: Vadim Caen Date: Wed, 2 Mar 2022 16:57:07 +0100 Subject: [PATCH] Ensure no animation is run except for HOME ... and directly reset the animation state for other cases. Fixes: 222769294 Test: BackAnimationControllerTest#verifyAnimationFinishes Change-Id: If04885065076ef7e3c15f5cce2c1d040bd92b494 --- .../shell/back/BackAnimationController.java | 76 ++----------------- .../back/BackAnimationControllerTest.java | 49 +++++++++++- 2 files changed, 54 insertions(+), 71 deletions(-) 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 93ee3f5378e8f..577ced53f9925 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 @@ -19,9 +19,6 @@ package com.android.wm.shell.back; import static com.android.wm.shell.common.ExecutorUtils.executeRemoteCallWithTaskPermission; import static com.android.wm.shell.protolog.ShellProtoLogGroup.WM_SHELL_BACK_PREVIEW; -import android.animation.Animator; -import android.animation.AnimatorListenerAdapter; -import android.animation.ValueAnimator; import android.annotation.NonNull; import android.annotation.Nullable; import android.app.ActivityTaskManager; @@ -223,14 +220,11 @@ public class BackAnimationController implements RemoteCallable= 0 ? PROGRESS_THRESHOLD : mProgressThreshold; float progress = Math.min(Math.max(Math.abs(deltaX) / progressThreshold, 0), 1); int backType = mBackNavigationInfo.getType(); @@ -317,11 +309,7 @@ public class BackAnimationController implements RemoteCallable { - if (mBackNavigationInfo == null) { - return; - } - float fraction = animation1.getAnimatedFraction(); - int deltaX = Math.round(mTouchEventDelta.x - (mTouchEventDelta.x * fraction)); - int deltaY = Math.round(mTouchEventDelta.y - (mTouchEventDelta.y * fraction)); - RemoteAnimationTarget animationTarget = - mBackNavigationInfo.getDepartingAnimationTarget(); - if (animationTarget != null) { - mTransaction.setPosition(animationTarget.leash, deltaX, deltaY); - mTransaction.apply(); - } - }); - - animation.addListener(new AnimatorListenerAdapter() { - @Override - public void onAnimationEnd(Animator animation) { - ProtoLog.d(WM_SHELL_BACK_PREVIEW, "BackAnimationController: onAnimationEnd"); - finishAnimation(); - } - }); - animation.start(); - } - - private void prepareTransition() { - ProtoLog.d(WM_SHELL_BACK_PREVIEW, "prepareTransition()"); - mTriggerBack = false; - mBackGestureStarted = false; - } - /** * Sets to true when the back gesture has passed the triggering threshold, false otherwise. */ 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 7c1fae3a849b4..a905dcaebc6b8 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 @@ -16,10 +16,16 @@ package com.android.wm.shell.back; +import static android.window.BackNavigationInfo.KEY_TRIGGER_BACK; + import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import android.app.IActivityTaskManager; @@ -101,6 +107,14 @@ public class BackAnimationControllerTest { } } + private void createNavigationInfo(BackNavigationInfo.Builder builder) { + try { + doReturn(builder.build()).when(mActivityTaskManager).startBackNavigation(); + } catch (RemoteException ex) { + ex.rethrowFromSystemServer(); + } + } + RemoteAnimationTarget createAnimationTarget() { SurfaceControl topWindowLeash = new SurfaceControl(); return new RemoteAnimationTarget(-1, RemoteAnimationTarget.MODE_CLOSING, topWindowLeash, @@ -109,6 +123,18 @@ public class BackAnimationControllerTest { true, null, null, null, false, -1); } + private void triggerBackGesture() { + MotionEvent event = MotionEvent.obtain(0, 0, MotionEvent.ACTION_DOWN, 0, 0, 0); + mController.onMotionEvent(event, event.getAction(), BackEvent.EDGE_LEFT); + + event = MotionEvent.obtain(10, 0, MotionEvent.ACTION_MOVE, 100, 100, 0); + mController.onMotionEvent(event, event.getAction(), BackEvent.EDGE_LEFT); + + mController.setTriggerBack(true); + event = MotionEvent.obtain(10, 0, MotionEvent.ACTION_UP, 100, 100, 0); + mController.onMotionEvent(event, event.getAction(), BackEvent.EDGE_LEFT); + } + @Test @Ignore("b/207481538") public void crossActivity_screenshotAttachedAndVisible() { @@ -140,10 +166,31 @@ public class BackAnimationControllerTest { MotionEvent.obtain(10, 0, MotionEvent.ACTION_MOVE, 100, 100, 0), MotionEvent.ACTION_MOVE, BackEvent.EDGE_LEFT); - verify(mTransaction).setPosition(animationTarget.leash, 100, 100); + // b/207481538, we check that the surface is not moved for now, we can re-enable this once + // we implement the animation + verify(mTransaction, never()).setScale(eq(screenshotSurface), anyInt(), anyInt()); + verify(mTransaction, never()).setPosition(animationTarget.leash, 100, 100); verify(mTransaction, atLeastOnce()).apply(); } + @Test + public void verifyAnimationFinishes() { + RemoteAnimationTarget animationTarget = createAnimationTarget(); + boolean[] backNavigationDone = new boolean[]{false}; + boolean[] triggerBack = new boolean[]{false}; + createNavigationInfo(new BackNavigationInfo.Builder() + .setDepartingAnimationTarget(animationTarget) + .setType(BackNavigationInfo.TYPE_CROSS_ACTIVITY) + .setOnBackNavigationDone( + new RemoteCallback(result -> { + backNavigationDone[0] = true; + triggerBack[0] = result.getBoolean(KEY_TRIGGER_BACK); + }))); + triggerBackGesture(); + assertTrue("Navigation Done callback not called", backNavigationDone[0]); + assertTrue("TriggerBack should have been true", triggerBack[0]); + } + @Test public void backToHome_dispatchesEvents() throws RemoteException { mController.setBackToLauncherCallback(mIOnBackInvokedCallback);