IME stability

Bug: 170739594

Change-Id: Ib667c6dfb321411d59e728a1f34d4803f7293f05
diff --git a/src/com/android/launcher3/allapps/AllAppsInsetTransitionController.java b/src/com/android/launcher3/allapps/AllAppsInsetTransitionController.java
index 01d01ea..93da1c0 100644
--- a/src/com/android/launcher3/allapps/AllAppsInsetTransitionController.java
+++ b/src/com/android/launcher3/allapps/AllAppsInsetTransitionController.java
@@ -57,7 +57,8 @@
 
     // Only purpose of these states is to keep track of fast fling transition
     enum State {
-        RESET, DRAG_START_BOTTOM, FLING_END_TOP,
+        RESET, DRAG_START_BOTTOM, DRAG_START_BOTTOM_IME_CANCELLED,
+        FLING_END_TOP, FLING_END_TOP_IME_CANCELLED,
         DRAG_START_TOP, FLING_END_BOTTOM
     }
     private State mState;
@@ -149,13 +150,12 @@
                                     + " mAnimationController=" + mAnimationController);
                         }
                         if (mState == State.DRAG_START_BOTTOM) {
-                            mApps.getWindowInsetsController().show(WindowInsets.Type.ime());
+                            mState = State.DRAG_START_BOTTOM_IME_CANCELLED;
                         }
                         mAnimationController = null;
                         if (controller != null) {
                             controller.finish(true);
                         }
-
                     }
                 });
     }
@@ -200,7 +200,7 @@
         final int end = mShownAtDown ? mHiddenInsetBottom : mShownInsetBottom;
         inset = Math.max(inset, mHiddenInsetBottom);
         inset = Math.min(inset, mShownInsetBottom);
-        if (DEBUG || false) {
+        if (DEBUG && false) {
             Log.d(TAG, "updateInset mCurrent=" + mCurrent + " mDown="
                     + mDown + " hidden=" + mHiddenInsetBottom
                     + " shown=" + mShownInsetBottom
@@ -228,8 +228,14 @@
             // only called when launcher restarting.
             UiThreadHelper.hideKeyboardAsync(mApps.getContext(), mApps.getWindowToken());
         }
+
         setState(false, true, progress);
+
+
         if (mAnimationController == null) {
+            if (mState == State.FLING_END_TOP_IME_CANCELLED) {
+                mApps.getWindowInsetsController().show(WindowInsets.Type.ime());
+            }
             return;
         }
 
@@ -268,8 +274,12 @@
         } else if (end) {
             if (Float.compare(progress, 1f) == 0 && mState == State.DRAG_START_TOP) {
                 state = State.FLING_END_BOTTOM;
-            } else if (Float.compare(progress, 0f) == 0 && mState == State.DRAG_START_BOTTOM) {
-                state = State.FLING_END_TOP;
+            } else if (Float.compare(progress, 0f) == 0) {
+                if (mState == State.DRAG_START_BOTTOM) {
+                    state = State.FLING_END_TOP;
+                } else if (mState == State.DRAG_START_BOTTOM_IME_CANCELLED) {
+                    state = State.FLING_END_TOP_IME_CANCELLED;
+                }
             }
         }
         if (DEBUG) {