Keyguard: Fix missing IME, and apply better animations

Password bouncer: animate the text field alpha and y positioning along
with the IME reveal. Also fix the ordering of focus events to ensure
the soft keyboard appears.

Fixes: 174020436
Fixes: 175243820
Test: SystemUITests
Change-Id: I62898870f57da1cd5b3da6bc4a2cfb23fe95097f
diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardInputView.java b/packages/SystemUI/src/com/android/keyguard/KeyguardInputView.java
index d42a53c..d58b95c 100644
--- a/packages/SystemUI/src/com/android/keyguard/KeyguardInputView.java
+++ b/packages/SystemUI/src/com/android/keyguard/KeyguardInputView.java
@@ -43,6 +43,10 @@
 
     abstract CharSequence getTitle();
 
+    void animateForIme(float interpolatedFraction) {
+        return;
+    }
+
     boolean disallowInterceptTouch(MotionEvent event) {
         return false;
     }
diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardPasswordView.java b/packages/SystemUI/src/com/android/keyguard/KeyguardPasswordView.java
index aaa5efe..92b65b2 100644
--- a/packages/SystemUI/src/com/android/keyguard/KeyguardPasswordView.java
+++ b/packages/SystemUI/src/com/android/keyguard/KeyguardPasswordView.java
@@ -136,24 +136,14 @@
 
     @Override
     public void startAppearAnimation() {
+        // Reset state, and let IME animation reveal the view as it slides in
         setAlpha(0f);
         setTranslationY(0f);
-        animate()
-                .alpha(1)
-                .withLayer()
-                .setDuration(300)
-                .setInterpolator(mLinearOutSlowInInterpolator);
     }
 
     @Override
-    public boolean startDisappearAnimation(Runnable finishRunnable) {
-        animate()
-                .alpha(0f)
-                .translationY(mDisappearYTranslation)
-                .setInterpolator(mFastOutLinearInInterpolator)
-                .setDuration(100)
-                .withEndAction(finishRunnable);
-        return true;
+    public void animateForIme(float interpolatedFraction) {
+        setAlpha(interpolatedFraction);
     }
 
     @Override
diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardPasswordViewController.java b/packages/SystemUI/src/com/android/keyguard/KeyguardPasswordViewController.java
index 5e33917..0f1c3c8 100644
--- a/packages/SystemUI/src/com/android/keyguard/KeyguardPasswordViewController.java
+++ b/packages/SystemUI/src/com/android/keyguard/KeyguardPasswordViewController.java
@@ -194,14 +194,18 @@
     @Override
     public void onResume(int reason) {
         super.onResume(reason);
-        // Wait a bit to focus the field so the focusable flag on the window is already set then.
-        mMainExecutor.execute(() -> {
-            if (mView.isShown() && mPasswordEntry.isEnabled()) {
-                mPasswordEntry.requestFocus();
-                if (reason != KeyguardSecurityView.SCREEN_ON || mShowImeAtScreenOn) {
-                    mInputMethodManager.showSoftInput(
-                            mPasswordEntry, InputMethodManager.SHOW_IMPLICIT);
-                }
+
+        mPasswordEntry.requestFocus();
+        if (reason != KeyguardSecurityView.SCREEN_ON || mShowImeAtScreenOn) {
+            showInput();
+        }
+    }
+
+    private void showInput() {
+        mPasswordEntry.post(() -> {
+            if (mPasswordEntry.isFocused() && mView.isShown()) {
+                mInputMethodManager.showSoftInput(
+                        mPasswordEntry, InputMethodManager.SHOW_IMPLICIT);
             }
         });
     }
diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainer.java b/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainer.java
index b62ea6b..42f3cc7 100644
--- a/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainer.java
+++ b/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainer.java
@@ -119,21 +119,24 @@
                 @Override
                 public WindowInsets onProgress(WindowInsets windowInsets,
                         List<WindowInsetsAnimation> list) {
-                    int translationY = 0;
                     if (mDisappearAnimRunning) {
                         mSecurityViewFlipper.setTranslationY(
                                 mInitialBounds.bottom - mFinalBounds.bottom);
                     } else {
+                        int translationY = 0;
+                        float interpolatedFraction = 1f;
                         for (WindowInsetsAnimation animation : list) {
                             if ((animation.getTypeMask() & WindowInsets.Type.ime()) == 0) {
                                 continue;
                             }
+                            interpolatedFraction = animation.getInterpolatedFraction();
+
                             final int paddingBottom = (int) MathUtils.lerp(
                                     mInitialBounds.bottom - mFinalBounds.bottom, 0,
-                                    animation.getInterpolatedFraction());
+                                    interpolatedFraction);
                             translationY += paddingBottom;
                         }
-                        mSecurityViewFlipper.setTranslationY(translationY);
+                        mSecurityViewFlipper.animateForIme(translationY, interpolatedFraction);
                     }
                     return windowInsets;
                 }
@@ -141,7 +144,7 @@
                 @Override
                 public void onEnd(WindowInsetsAnimation animation) {
                     if (!mDisappearAnimRunning) {
-                        mSecurityViewFlipper.setTranslationY(0);
+                        mSecurityViewFlipper.animateForIme(0, /* interpolatedFraction */ 1f);
                     }
                 }
             };
diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityViewFlipper.java b/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityViewFlipper.java
index b8439af..7773fe9 100644
--- a/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityViewFlipper.java
+++ b/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityViewFlipper.java
@@ -83,6 +83,16 @@
         return "";
     }
 
+    /**
+      * Translate the entire view, and optionally inform the wrapped view of the progress
+      * so it can animate with the parent.
+      */
+    public void animateForIme(int translationY, float interpolatedFraction) {
+        super.setTranslationY(translationY);
+        KeyguardInputView v = getSecurityView();
+        if (v != null) v.animateForIme(interpolatedFraction);
+    }
+
     @Override
     protected boolean checkLayoutParams(ViewGroup.LayoutParams p) {
         return p instanceof LayoutParams;
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBouncer.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBouncer.java
index db0713c..81e63baf 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBouncer.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBouncer.java
@@ -451,10 +451,6 @@
         }
     }
 
-    public boolean onBackPressed() {
-        return mKeyguardViewController != null && mKeyguardViewController.handleBackKey();
-    }
-
     /**
      * @return True if and only if the security method should be shown before showing the
      * notifications on Keyguard, like SIM PIN/PUK.