Fixing Launcher stuck in BACKGROUND_APP state when using overview button

When using overview button, we skip the activtiy animation, which leads
to wrong state. Instead always running the animation and changing the endpoints
accordingly.

Change-Id: Id071b4e74da42c78760519aa29644621afc822e2
diff --git a/quickstep/src/com/android/quickstep/ActivityControlHelper.java b/quickstep/src/com/android/quickstep/ActivityControlHelper.java
index 63fc6cd..4b91810 100644
--- a/quickstep/src/com/android/quickstep/ActivityControlHelper.java
+++ b/quickstep/src/com/android/quickstep/ActivityControlHelper.java
@@ -106,7 +106,7 @@
     void onSwipeUpComplete(T activity);
 
     AnimationFactory prepareRecentsUI(T activity, boolean activityVisible,
-            Consumer<AnimatorPlaybackController> callback);
+            boolean animateActivity, Consumer<AnimatorPlaybackController> callback);
 
     ActivityInitListener createActivityInitListener(BiPredicate<T, Boolean> onInitListener);
 
@@ -214,7 +214,7 @@
 
         @Override
         public AnimationFactory prepareRecentsUI(Launcher activity, boolean activityVisible,
-                Consumer<AnimatorPlaybackController> callback) {
+                boolean animateActivity, Consumer<AnimatorPlaybackController> callback) {
             final LauncherState startState = activity.getStateManager().getState();
 
             LauncherState resetState = startState;
@@ -228,8 +228,8 @@
                 // Since the launcher is not visible, we can safely reset the scroll position.
                 // This ensures then the next swipe up to all-apps starts from scroll 0.
                 activity.getAppsView().reset(false /* animate */);
-                fromState = BACKGROUND_APP;
-                activity.getStateManager().goToState(BACKGROUND_APP, false);
+                fromState = animateActivity ? BACKGROUND_APP : OVERVIEW;
+                activity.getStateManager().goToState(fromState, false);
 
                 // Optimization, hide the all apps view to prevent layout while initializing
                 activity.getAppsView().getContentView().setVisibility(View.GONE);
@@ -268,6 +268,9 @@
                         .createAnimationToNewWorkspace(fromState, endState, accuracy));
                 return;
             }
+            if (fromState == endState) {
+                return;
+            }
 
             AnimatorSet anim = new AnimatorSet();
             if (!activity.getDeviceProfile().isVerticalBarLayout()) {
@@ -470,7 +473,7 @@
 
         @Override
         public AnimationFactory prepareRecentsUI(RecentsActivity activity, boolean activityVisible,
-                Consumer<AnimatorPlaybackController> callback) {
+                boolean animateActivity, Consumer<AnimatorPlaybackController> callback) {
             if (activityVisible) {
                 return (transitionLength, interactionType) -> { };
             }
diff --git a/quickstep/src/com/android/quickstep/OverviewCommandHelper.java b/quickstep/src/com/android/quickstep/OverviewCommandHelper.java
index 3d54b82..1a9915c 100644
--- a/quickstep/src/com/android/quickstep/OverviewCommandHelper.java
+++ b/quickstep/src/com/android/quickstep/OverviewCommandHelper.java
@@ -269,7 +269,7 @@
             activity.<RecentsView>getOverviewPanel().setCurrentTask(mRunningTaskId);
             AbstractFloatingView.closeAllOpenViews(activity, wasVisible);
             AnimationFactory factory = mHelper.prepareRecentsUI(activity, wasVisible,
-                    (controller) -> {
+                    false /* animate activity */, (controller) -> {
                         controller.dispatchOnStart();
                         ValueAnimator anim = controller.getAnimationPlayer()
                                 .setDuration(RECENTS_LAUNCH_DURATION);
@@ -277,9 +277,7 @@
                         anim.start();
                 });
             factory.onRemoteAnimationReceived(null);
-            if (wasVisible) {
-                factory.createActivityController(RECENTS_LAUNCH_DURATION, INTERACTION_NORMAL);
-            }
+            factory.createActivityController(RECENTS_LAUNCH_DURATION, INTERACTION_NORMAL);
             mActivity = activity;
             mRecentsView = mActivity.getOverviewPanel();
             mRecentsView.setRunningTaskIconScaledDown(true);
diff --git a/quickstep/src/com/android/quickstep/WindowTransformSwipeHandler.java b/quickstep/src/com/android/quickstep/WindowTransformSwipeHandler.java
index fa36f6b..a2e9af8 100644
--- a/quickstep/src/com/android/quickstep/WindowTransformSwipeHandler.java
+++ b/quickstep/src/com/android/quickstep/WindowTransformSwipeHandler.java
@@ -418,7 +418,7 @@
         }
 
         mAnimationFactory = mActivityControlHelper.prepareRecentsUI(mActivity,
-                mWasLauncherAlreadyVisible, this::onAnimatorPlaybackControllerCreated);
+                mWasLauncherAlreadyVisible, true, this::onAnimatorPlaybackControllerCreated);
         AbstractFloatingView.closeAllOpenViews(activity, mWasLauncherAlreadyVisible);
 
         if (mWasLauncherAlreadyVisible) {