Fixes home button from moving off its origin position after rotation

It is possible to quick scrub from a portrait app to a forced landscape
app to resultantly move the home button off its original position or
even off the screen. Force animation end to reset the position of the
home button and prevent null exceptions of the home button when running
animation end.

Fixes: 73507167
Bug: 70180755
Test: manual - quick switch/scrub between portrait and landscape forced
apps

Change-Id: Iea247b1f75701a171d1ddfd117e2056c2321c835
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/QuickScrubController.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/QuickScrubController.java
index 378858a..ae4edb4 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/QuickScrubController.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/QuickScrubController.java
@@ -123,9 +123,10 @@
         @Override
         public void onAnimationEnd(Animator animation) {
             mNavigationBarView.getHomeButton().setClickable(true);
-            mHomeButtonView = null;
             mQuickScrubActive = false;
             mTranslation = 0;
+            mQuickScrubEndAnimator.setCurrentPlayTime(mQuickScrubEndAnimator.getDuration());
+            mHomeButtonView = null;
         }
     };
 
@@ -146,8 +147,7 @@
                         mIsVertical ? (absVelY > velocityX) : (velocityX > absVelY);
                 if (isValidFling) {
                     mDraggingActive = false;
-                    mButtonAnimator.setIntValues((int) mTranslation, 0);
-                    mButtonAnimator.start();
+                    animateEnd();
                     mHandler.removeCallbacks(mLongPressRunnable);
                     try {
                         final IOverviewProxy overviewProxy = mOverviewEventSender.getProxy();
@@ -225,7 +225,7 @@
                 int x = (int) event.getX();
                 int y = (int) event.getY();
                 // End any existing quickscrub animations before starting the new transition
-                if (mQuickScrubEndAnimator != null) {
+                if (mHomeButtonView != null) {
                     mQuickScrubEndAnimator.end();
                 }
                 mHomeButtonView = homeButton.getCurrentView();
@@ -399,9 +399,7 @@
     private void endQuickScrub(boolean animate) {
         mHandler.removeCallbacks(mLongPressRunnable);
         if (mDraggingActive || mQuickScrubActive) {
-            mButtonAnimator.setIntValues((int) mTranslation, 0);
-            mTrackAnimator.setFloatValues(mTrackAlpha, 0);
-            mQuickScrubEndAnimator.start();
+            animateEnd();
             try {
                 mOverviewEventSender.getProxy().onQuickScrubEnd();
                 if (DEBUG_OVERVIEW_PROXY) {
@@ -410,9 +408,9 @@
             } catch (RemoteException e) {
                 Log.e(TAG, "Failed to send end of quick scrub.", e);
             }
-            if (!animate) {
-                mQuickScrubEndAnimator.end();
-            }
+        }
+        if (mHomeButtonView != null && !animate) {
+            mQuickScrubEndAnimator.end();
         }
         mDraggingActive = false;
     }
@@ -422,6 +420,12 @@
         mHandler.removeCallbacks(mLongPressRunnable);
     }
 
+    private void animateEnd() {
+        mButtonAnimator.setIntValues((int) mTranslation, 0);
+        mTrackAnimator.setFloatValues(mTrackAlpha, 0);
+        mQuickScrubEndAnimator.start();
+    }
+
     private int getDimensionPixelSize(Context context, @DimenRes int resId) {
         return context.getResources().getDimensionPixelSize(resId);
     }