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 d9eaeeeaf45fd..fc02abf297e10 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 @@ -116,7 +116,7 @@ public class BackAnimationController implements RemoteCallable mAnimationDefinition = new SparseArray<>(); - + @Nullable private IOnBackInvokedCallback mActiveCallback; @VisibleForTesting @@ -180,6 +180,10 @@ public class BackAnimationController implements RemoteCallable { - backNavigationDone[0] = true; - triggerBack[0] = result.getBoolean(KEY_TRIGGER_BACK); - }))); + .setOnBackNavigationDone(new RemoteCallback(result))); triggerBackGesture(); simulateRemoteAnimationStart(type); simulateRemoteAnimationFinished(); mShellExecutor.flushAll(); assertTrue("Navigation Done callback not called for " - + BackNavigationInfo.typeToString(type), backNavigationDone[0]); - assertTrue("TriggerBack should have been true", triggerBack[0]); + + BackNavigationInfo.typeToString(type), result.mBackNavigationDone); + assertTrue("TriggerBack should have been true", result.mTriggerBack); } } - - @Test public void backToHome_dispatchesEvents() throws RemoteException { registerAnimation(BackNavigationInfo.TYPE_RETURN_TO_HOME); @@ -351,6 +345,65 @@ public class BackAnimationControllerTest extends ShellTestCase { verify(mAnimatorCallback, never()).onBackInvoked(); } + @Test + public void animationNotDefined() throws RemoteException { + final int[] testTypes = new int[] { + BackNavigationInfo.TYPE_RETURN_TO_HOME, + BackNavigationInfo.TYPE_CROSS_TASK, + BackNavigationInfo.TYPE_CROSS_ACTIVITY, + BackNavigationInfo.TYPE_DIALOG_CLOSE}; + + for (int type: testTypes) { + final ResultListener result = new ResultListener(); + createNavigationInfo(new BackNavigationInfo.Builder() + .setType(type) + .setOnBackInvokedCallback(mAppCallback) + .setPrepareRemoteAnimation(true) + .setOnBackNavigationDone(new RemoteCallback(result))); + triggerBackGesture(); + simulateRemoteAnimationStart(type); + mShellExecutor.flushAll(); + + assertTrue("Navigation Done callback not called for " + + BackNavigationInfo.typeToString(type), result.mBackNavigationDone); + assertTrue("TriggerBack should have been true", result.mTriggerBack); + } + + verify(mAppCallback, never()).onBackStarted(any()); + verify(mAppCallback, never()).onBackProgressed(any()); + verify(mAppCallback, times(testTypes.length)).onBackInvoked(); + + verify(mAnimatorCallback, never()).onBackStarted(any()); + verify(mAnimatorCallback, never()).onBackProgressed(any()); + verify(mAnimatorCallback, never()).onBackInvoked(); + } + + @Test + public void callbackShouldDeliverProgress() throws RemoteException { + registerAnimation(BackNavigationInfo.TYPE_RETURN_TO_HOME); + + final int type = BackNavigationInfo.TYPE_CALLBACK; + final ResultListener result = new ResultListener(); + createNavigationInfo(new BackNavigationInfo.Builder() + .setType(type) + .setOnBackInvokedCallback(mAppCallback) + .setOnBackNavigationDone(new RemoteCallback(result))); + triggerBackGesture(); + mShellExecutor.flushAll(); + + assertTrue("Navigation Done callback not called for " + + BackNavigationInfo.typeToString(type), result.mBackNavigationDone); + assertTrue("TriggerBack should have been true", result.mTriggerBack); + + verify(mAppCallback, times(1)).onBackStarted(any()); + verify(mAppCallback, times(1)).onBackProgressed(any()); + verify(mAppCallback, times(1)).onBackInvoked(); + + verify(mAnimatorCallback, never()).onBackStarted(any()); + verify(mAnimatorCallback, never()).onBackProgressed(any()); + verify(mAnimatorCallback, never()).onBackInvoked(); + } + private void doMotionEvent(int actionDown, int coordinate) { mController.onMotionEvent( coordinate, coordinate, @@ -377,4 +430,14 @@ public class BackAnimationControllerTest extends ShellTestCase { mController.registerAnimation(type, new BackAnimationRunner(mAnimatorCallback, mBackAnimationRunner)); } + + private static class ResultListener implements RemoteCallback.OnResultListener { + boolean mBackNavigationDone = false; + boolean mTriggerBack = false; + @Override + public void onResult(@Nullable Bundle result) { + mBackNavigationDone = true; + mTriggerBack = result.getBoolean(KEY_TRIGGER_BACK); + } + }; }