diff options
4 files changed, 86 insertions, 23 deletions
diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardPasswordView.java b/packages/SystemUI/src/com/android/keyguard/KeyguardPasswordView.java index 7cc37c476e31..81cf3aef4bc8 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardPasswordView.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardPasswordView.java @@ -140,12 +140,6 @@ public class KeyguardPasswordView extends KeyguardAbsKeyInputView mImm.hideSoftInputFromWindow(getWindowToken(), 0); } - @Override - public void reset() { - super.reset(); - mPasswordEntry.requestFocus(); - } - private void updateSwitchImeButton() { // If there's more than one IME, enable the IME switcher button final boolean wasVisible = mSwitchImeButton.getVisibility() == View.VISIBLE; @@ -193,8 +187,6 @@ public class KeyguardPasswordView extends KeyguardAbsKeyInputView // Set selected property on so the view can send accessibility events. mPasswordEntry.setSelected(true); - mPasswordEntry.requestFocus(); - mSwitchImeButton = findViewById(R.id.switch_ime_button); mSwitchImeButton.setOnClickListener(new OnClickListener() { @Override diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardPinBasedInputView.java b/packages/SystemUI/src/com/android/keyguard/KeyguardPinBasedInputView.java index 1d3f9a13c631..a2befefba79e 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardPinBasedInputView.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardPinBasedInputView.java @@ -23,13 +23,16 @@ import android.view.KeyEvent; import android.view.MotionEvent; import android.view.View; +import com.android.internal.annotations.VisibleForTesting; + /** * A Pin based Keyguard input view */ public abstract class KeyguardPinBasedInputView extends KeyguardAbsKeyInputView implements View.OnKeyListener, View.OnTouchListener { - protected PasswordTextView mPasswordEntry; + @VisibleForTesting + PasswordTextView mPasswordEntry; private View mOkButton; private View mDeleteButton; private View mButton0; @@ -52,12 +55,6 @@ public abstract class KeyguardPinBasedInputView extends KeyguardAbsKeyInputView } @Override - public void reset() { - mPasswordEntry.requestFocus(); - super.reset(); - } - - @Override protected boolean onRequestFocusInDescendants(int direction, Rect previouslyFocusedRect) { // send focus to the password field return mPasswordEntry.requestFocus(direction, previouslyFocusedRect); @@ -238,6 +235,12 @@ public abstract class KeyguardPinBasedInputView extends KeyguardAbsKeyInputView } @Override + public void onResume(int reason) { + super.onResume(reason); + mPasswordEntry.requestFocus(); + } + + @Override public boolean onTouch(View v, MotionEvent event) { if (event.getActionMasked() == MotionEvent.ACTION_DOWN) { doHapticKeyClick(); 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 3e01aec85139..f13415103b9d 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBouncer.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBouncer.java @@ -54,6 +54,8 @@ public class KeyguardBouncer { private static final String TAG = "KeyguardBouncer"; static final float ALPHA_EXPANSION_THRESHOLD = 0.95f; + private static final float EXPANSION_HIDDEN = 1f; + private static final float EXPANSION_VISIBLE = 0f; protected final Context mContext; protected final ViewMediatorCallback mCallback; @@ -71,10 +73,15 @@ public class KeyguardBouncer { } }; private final Runnable mRemoveViewRunnable = this::removeView; + protected KeyguardHostView mKeyguardView; + private final Runnable mResetRunnable = ()-> { + if (mKeyguardView != null) { + mKeyguardView.reset(); + } + }; private int mStatusBarHeight; - private float mExpansion; - protected KeyguardHostView mKeyguardView; + private float mExpansion = EXPANSION_HIDDEN; protected ViewGroup mRoot; private boolean mShowingSoon; private int mBouncerPromptReason; @@ -96,7 +103,7 @@ public class KeyguardBouncer { } public void show(boolean resetSecuritySelection) { - show(resetSecuritySelection, true /* notifyFalsing */); + show(resetSecuritySelection, true /* animated */); } /** @@ -120,8 +127,7 @@ public class KeyguardBouncer { // Later, at the end of the animation, when the bouncer is at the top of the screen, // onFullyShown() will be called and FalsingManager will stop recording touches. if (animated) { - mFalsingManager.onBouncerShown(); - setExpansion(0); + setExpansion(EXPANSION_VISIBLE); } if (resetSecuritySelection) { @@ -152,6 +158,7 @@ public class KeyguardBouncer { mShowingSoon = true; // Split up the work over multiple frames. + DejankUtils.removeCallbacks(mResetRunnable); DejankUtils.postAfterTraversal(mShowRunnable); mCallback.onBouncerVisiblityChanged(true /* shown */); @@ -181,6 +188,7 @@ public class KeyguardBouncer { mRoot.setVisibility(View.INVISIBLE); } mFalsingManager.onBouncerHidden(); + DejankUtils.postAfterTraversal(mResetRunnable); } } @@ -210,6 +218,9 @@ public class KeyguardBouncer { mKeyguardView.requestLayout(); } mShowingSoon = false; + if (mExpansion == EXPANSION_VISIBLE) { + mKeyguardView.onResume(); + } StatsLog.write(StatsLog.KEYGUARD_BOUNCER_STATE_CHANGED, StatsLog.KEYGUARD_BOUNCER_STATE_CHANGED__STATE__SHOWN); } @@ -303,7 +314,7 @@ public class KeyguardBouncer { public boolean isShowing() { return (mShowingSoon || (mRoot != null && mRoot.getVisibility() == View.VISIBLE)) - && mExpansion == 0 && !isAnimatingAway(); + && mExpansion == EXPANSION_VISIBLE && !isAnimatingAway(); } /** @@ -337,10 +348,10 @@ public class KeyguardBouncer { mKeyguardView.setTranslationY(fraction * mKeyguardView.getHeight()); } - if (fraction == 0 && oldExpansion != 0) { + if (fraction == EXPANSION_VISIBLE && oldExpansion != EXPANSION_VISIBLE) { onFullyShown(); mExpansionCallback.onFullyShown(); - } else if (fraction == 1 && oldExpansion != 0) { + } else if (fraction == EXPANSION_HIDDEN && oldExpansion != EXPANSION_HIDDEN) { onFullyHidden(); mExpansionCallback.onFullyHidden(); } diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPinBasedInputViewTest.java b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPinBasedInputViewTest.java new file mode 100644 index 000000000000..e79c9d0c5455 --- /dev/null +++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPinBasedInputViewTest.java @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2018 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +package com.android.keyguard; + +import static org.mockito.Mockito.verify; + +import android.support.test.filters.SmallTest; +import android.testing.AndroidTestingRunner; +import android.testing.TestableLooper.RunWithLooper; +import android.view.LayoutInflater; + +import com.android.systemui.SysuiTestCase; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +@SmallTest +@RunWith(AndroidTestingRunner.class) +@RunWithLooper(setAsMainLooper = true) +public class KeyguardPinBasedInputViewTest extends SysuiTestCase { + + @Mock + private PasswordTextView mPasswordTextView; + private KeyguardPinBasedInputView mKeyguardPinView; + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + LayoutInflater inflater = LayoutInflater.from(getContext()); + mKeyguardPinView = + (KeyguardPinBasedInputView) inflater.inflate(R.layout.keyguard_pin_view, null); + mKeyguardPinView.mPasswordEntry = mPasswordTextView; + } + + @Test + public void onResume_requestsFocus() { + mKeyguardPinView.onResume(KeyguardSecurityView.SCREEN_ON); + verify(mPasswordTextView).requestFocus(); + } +} |