From d794fa6c94b0732a082a27d0350027d90d90d12d Mon Sep 17 00:00:00 2001 From: Aaron Liu Date: Wed, 9 Aug 2023 10:26:24 -0700 Subject: [PATCH] Fix bugs revolving around user switching. When switching users in the bouncer, we do no invoke startAppearAnimation. Additionally, the theme color change was delayed for roughly 3 seconds after the user switch completes, which reinflates the bouncer view. In order to handle this case, I've moved some logic from startAppearAnimation to onViewAttached. Additionally, when the user switch occurs, we opt to reinflate the bouncer. When the color changes, we do not reinflate the view. Although the view will not adopt the new theme changes, it will change when we leave the bouncer and enter again. Fixes: 292255597 Fixes: 294035459 Fixes: 292123727 Test: switch users from auto confirmation pin to pin and then back. Test: switch users from locked out pattern to pin and then back. Test: switch users from password to pin and then back. Change-Id: I5b851598c09a0587dd241838b4af256b6c533aaa --- .../KeyguardAbsKeyInputViewController.java | 12 +- .../keyguard/KeyguardInputViewController.java | 18 +- .../KeyguardPatternViewController.java | 12 +- .../keyguard/KeyguardPinViewController.java | 8 +- .../KeyguardSecurityContainerController.java | 16 +- ...KeyguardAbsKeyInputViewControllerTest.java | 5 +- .../KeyguardPasswordViewControllerTest.kt | 192 +++++++++--------- .../KeyguardPatternViewControllerTest.kt | 103 +++++----- ...yguardPinBasedInputViewControllerTest.java | 2 + .../keyguard/KeyguardPinViewControllerTest.kt | 16 +- ...KeyguardSecurityContainerControllerTest.kt | 33 ++- .../KeyguardSimPinViewControllerTest.kt | 4 +- .../KeyguardSimPukViewControllerTest.kt | 4 +- 13 files changed, 218 insertions(+), 207 deletions(-) diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardAbsKeyInputViewController.java b/packages/SystemUI/src/com/android/keyguard/KeyguardAbsKeyInputViewController.java index b81e08183cdc4..e3f9de11bf988 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardAbsKeyInputViewController.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardAbsKeyInputViewController.java @@ -102,6 +102,12 @@ public abstract class KeyguardAbsKeyInputViewController @CallSuper protected void onViewAttached() { updateMessageAreaVisibility(); + if (TextUtils.isEmpty(mMessageAreaController.getMessage()) + && getInitialMessageResId() != 0) { + mMessageAreaController.setMessage( + mView.getResources().getString(getInitialMessageResId()), + /* animate= */ false); + } } private void updateMessageAreaVisibility() { @@ -147,12 +153,6 @@ public abstract class KeyguardInputViewController } public void startAppearAnimation() { - if (TextUtils.isEmpty(mMessageAreaController.getMessage()) - && getInitialMessageResId() != 0) { - mMessageAreaController.setMessage( - mView.getResources().getString(getInitialMessageResId()), - /* animate= */ false); - } mView.startAppearAnimation(); } diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardPatternViewController.java b/packages/SystemUI/src/com/android/keyguard/KeyguardPatternViewController.java index 49f788ce8f757..a30b4479fe958 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardPatternViewController.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardPatternViewController.java @@ -238,6 +238,12 @@ public class KeyguardPatternViewController } mView.onDevicePostureChanged(mPostureController.getDevicePosture()); mPostureController.addCallback(mPostureCallback); + // if the user is currently locked out, enforce it. + long deadline = mLockPatternUtils.getLockoutAttemptDeadline( + KeyguardUpdateMonitor.getCurrentUser()); + if (deadline != 0) { + handleAttemptLockout(deadline); + } } @Override @@ -268,12 +274,6 @@ public class KeyguardPatternViewController @Override public void onResume(int reason) { super.onResume(reason); - // if the user is currently locked out, enforce it. - long deadline = mLockPatternUtils.getLockoutAttemptDeadline( - KeyguardUpdateMonitor.getCurrentUser()); - if (deadline != 0) { - handleAttemptLockout(deadline); - } } @Override diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardPinViewController.java b/packages/SystemUI/src/com/android/keyguard/KeyguardPinViewController.java index b3e08c0bc69fe..574a0591bd51d 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardPinViewController.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardPinViewController.java @@ -79,6 +79,10 @@ public class KeyguardPinViewController mPasswordEntry.setUserActivityListener(this::onUserInput); mView.onDevicePostureChanged(mPostureController.getDevicePosture()); mPostureController.addCallback(mPostureCallback); + if (mFeatureFlags.isEnabled(Flags.AUTO_PIN_CONFIRMATION)) { + mPasswordEntry.setUsePinShapes(true); + updateAutoConfirmationState(); + } } protected void onUserInput() { @@ -100,10 +104,6 @@ public class KeyguardPinViewController @Override public void startAppearAnimation() { - if (mFeatureFlags.isEnabled(Flags.AUTO_PIN_CONFIRMATION)) { - mPasswordEntry.setUsePinShapes(true); - updateAutoConfirmationState(); - } super.startAppearAnimation(); } diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainerController.java b/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainerController.java index 6dd35409c8af0..730b6f7aa5267 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainerController.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainerController.java @@ -145,8 +145,19 @@ public class KeyguardSecurityContainerController extends ViewController showPrimarySecurityScreen(false); + new UserSwitcherController.UserSwitchCallback() { + @Override + public void onUserSwitched() { + if (mCurrentUser == KeyguardUpdateMonitor.getCurrentUser()) { + return; + } + mCurrentUser = KeyguardUpdateMonitor.getCurrentUser(); + showPrimarySecurityScreen(false); + reinflateViewFlipper((l) -> {}); + } + }; @VisibleForTesting final Gefingerpoken mGlobalTouchListener = new Gefingerpoken() { @@ -338,7 +349,6 @@ public class KeyguardSecurityContainerController extends ViewController mView.reloadColors()); + mView.reloadColors(); } /** Handles density or font scale changes. */ diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardAbsKeyInputViewControllerTest.java b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardAbsKeyInputViewControllerTest.java index 677d3ff3df690..c894d914bfa3c 100644 --- a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardAbsKeyInputViewControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardAbsKeyInputViewControllerTest.java @@ -180,8 +180,9 @@ public class KeyguardAbsKeyInputViewControllerTest extends SysuiTestCase { } @Test - public void testResume() { - mKeyguardAbsKeyInputViewController.onResume(KeyguardSecurityView.VIEW_REVEALED); + public void testOnViewAttached() { + reset(mLockPatternUtils); + mKeyguardAbsKeyInputViewController.onViewAttached(); verify(mLockPatternUtils).getLockoutAttemptDeadline(anyInt()); } diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPasswordViewControllerTest.kt b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPasswordViewControllerTest.kt index 1a9260c2ede6f..3a9473085583b 100644 --- a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPasswordViewControllerTest.kt +++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPasswordViewControllerTest.kt @@ -20,6 +20,7 @@ import android.testing.AndroidTestingRunner import android.testing.TestableLooper import android.view.inputmethod.InputMethodManager import android.widget.EditText +import android.widget.ImageView import androidx.test.filters.SmallTest import com.android.internal.util.LatencyTracker import com.android.internal.widget.LockPatternUtils @@ -29,6 +30,7 @@ import com.android.systemui.classifier.FalsingCollector import com.android.systemui.flags.FakeFeatureFlags import com.android.systemui.flags.Flags import com.android.systemui.util.concurrency.DelayableExecutor +import com.android.systemui.util.mockito.whenever import org.junit.Before import org.junit.Test import org.junit.runner.RunWith @@ -36,6 +38,7 @@ import org.mockito.ArgumentMatchers.anyBoolean import org.mockito.ArgumentMatchers.anyString import org.mockito.Mock import org.mockito.Mockito +import org.mockito.Mockito.mock import org.mockito.Mockito.never import org.mockito.Mockito.verify import org.mockito.Mockito.`when` @@ -45,104 +48,109 @@ import org.mockito.MockitoAnnotations @RunWith(AndroidTestingRunner::class) @TestableLooper.RunWithLooper class KeyguardPasswordViewControllerTest : SysuiTestCase() { - @Mock private lateinit var keyguardPasswordView: KeyguardPasswordView - @Mock private lateinit var passwordEntry: EditText - @Mock lateinit var keyguardUpdateMonitor: KeyguardUpdateMonitor - @Mock lateinit var securityMode: KeyguardSecurityModel.SecurityMode - @Mock lateinit var lockPatternUtils: LockPatternUtils - @Mock lateinit var keyguardSecurityCallback: KeyguardSecurityCallback - @Mock lateinit var messageAreaControllerFactory: KeyguardMessageAreaController.Factory - @Mock lateinit var latencyTracker: LatencyTracker - @Mock lateinit var inputMethodManager: InputMethodManager - @Mock lateinit var emergencyButtonController: EmergencyButtonController - @Mock lateinit var mainExecutor: DelayableExecutor - @Mock lateinit var falsingCollector: FalsingCollector - @Mock lateinit var keyguardViewController: KeyguardViewController - @Mock private lateinit var mKeyguardMessageArea: BouncerKeyguardMessageArea - @Mock - private lateinit var mKeyguardMessageAreaController: - KeyguardMessageAreaController + @Mock private lateinit var keyguardPasswordView: KeyguardPasswordView + @Mock private lateinit var passwordEntry: EditText + @Mock lateinit var keyguardUpdateMonitor: KeyguardUpdateMonitor + @Mock lateinit var securityMode: KeyguardSecurityModel.SecurityMode + @Mock lateinit var lockPatternUtils: LockPatternUtils + @Mock lateinit var keyguardSecurityCallback: KeyguardSecurityCallback + @Mock lateinit var messageAreaControllerFactory: KeyguardMessageAreaController.Factory + @Mock lateinit var latencyTracker: LatencyTracker + @Mock lateinit var inputMethodManager: InputMethodManager + @Mock lateinit var emergencyButtonController: EmergencyButtonController + @Mock lateinit var mainExecutor: DelayableExecutor + @Mock lateinit var falsingCollector: FalsingCollector + @Mock lateinit var keyguardViewController: KeyguardViewController + @Mock private lateinit var mKeyguardMessageArea: BouncerKeyguardMessageArea + @Mock + private lateinit var mKeyguardMessageAreaController: + KeyguardMessageAreaController - private lateinit var keyguardPasswordViewController: KeyguardPasswordViewController + private lateinit var keyguardPasswordViewController: KeyguardPasswordViewController - @Before - fun setup() { - MockitoAnnotations.initMocks(this) - Mockito.`when`( - keyguardPasswordView.requireViewById( - R.id.bouncer_message_area)) - .thenReturn(mKeyguardMessageArea) - Mockito.`when`(messageAreaControllerFactory.create(mKeyguardMessageArea)) - .thenReturn(mKeyguardMessageAreaController) - Mockito.`when`(keyguardPasswordView.passwordTextViewId).thenReturn(R.id.passwordEntry) - Mockito.`when`(keyguardPasswordView.findViewById(R.id.passwordEntry)) - .thenReturn(passwordEntry) - `when`(keyguardPasswordView.resources).thenReturn(context.resources) - val fakeFeatureFlags = FakeFeatureFlags() - fakeFeatureFlags.set(Flags.REVAMPED_BOUNCER_MESSAGES, true) - keyguardPasswordViewController = - KeyguardPasswordViewController( - keyguardPasswordView, - keyguardUpdateMonitor, - securityMode, - lockPatternUtils, - keyguardSecurityCallback, - messageAreaControllerFactory, - latencyTracker, - inputMethodManager, - emergencyButtonController, - mainExecutor, - mContext.resources, - falsingCollector, - keyguardViewController, - fakeFeatureFlags) - } - - @Test - fun testFocusWhenBouncerIsShown() { - Mockito.`when`(keyguardViewController.isBouncerShowing).thenReturn(true) - Mockito.`when`(keyguardPasswordView.isShown).thenReturn(true) - keyguardPasswordViewController.onResume(KeyguardSecurityView.VIEW_REVEALED) - keyguardPasswordView.post { - verify(keyguardPasswordView).requestFocus() - verify(keyguardPasswordView).showKeyboard() + @Before + fun setup() { + MockitoAnnotations.initMocks(this) + Mockito.`when`( + keyguardPasswordView.requireViewById( + R.id.bouncer_message_area + ) + ) + .thenReturn(mKeyguardMessageArea) + Mockito.`when`(messageAreaControllerFactory.create(mKeyguardMessageArea)) + .thenReturn(mKeyguardMessageAreaController) + Mockito.`when`(keyguardPasswordView.passwordTextViewId).thenReturn(R.id.passwordEntry) + Mockito.`when`(keyguardPasswordView.findViewById(R.id.passwordEntry)) + .thenReturn(passwordEntry) + whenever(keyguardPasswordView.findViewById(R.id.switch_ime_button)) + .thenReturn(mock(ImageView::class.java)) + `when`(keyguardPasswordView.resources).thenReturn(context.resources) + val fakeFeatureFlags = FakeFeatureFlags() + fakeFeatureFlags.set(Flags.REVAMPED_BOUNCER_MESSAGES, true) + keyguardPasswordViewController = + KeyguardPasswordViewController( + keyguardPasswordView, + keyguardUpdateMonitor, + securityMode, + lockPatternUtils, + keyguardSecurityCallback, + messageAreaControllerFactory, + latencyTracker, + inputMethodManager, + emergencyButtonController, + mainExecutor, + mContext.resources, + falsingCollector, + keyguardViewController, + fakeFeatureFlags + ) } - } - @Test - fun testDoNotFocusWhenBouncerIsHidden() { - Mockito.`when`(keyguardViewController.isBouncerShowing).thenReturn(false) - Mockito.`when`(keyguardPasswordView.isShown).thenReturn(true) - keyguardPasswordViewController.onResume(KeyguardSecurityView.VIEW_REVEALED) - verify(keyguardPasswordView, never()).requestFocus() - } - - @Test - fun testHideKeyboardWhenOnPause() { - keyguardPasswordViewController.onPause() - keyguardPasswordView.post { - verify(keyguardPasswordView).clearFocus() - verify(keyguardPasswordView).hideKeyboard() + @Test + fun testFocusWhenBouncerIsShown() { + Mockito.`when`(keyguardViewController.isBouncerShowing).thenReturn(true) + Mockito.`when`(keyguardPasswordView.isShown).thenReturn(true) + keyguardPasswordViewController.onResume(KeyguardSecurityView.VIEW_REVEALED) + keyguardPasswordView.post { + verify(keyguardPasswordView).requestFocus() + verify(keyguardPasswordView).showKeyboard() + } } - } - @Test - fun startAppearAnimation() { - keyguardPasswordViewController.startAppearAnimation() - verify(mKeyguardMessageAreaController) - .setMessage(context.resources.getString(R.string.keyguard_enter_your_password), false) - } + @Test + fun testDoNotFocusWhenBouncerIsHidden() { + Mockito.`when`(keyguardViewController.isBouncerShowing).thenReturn(false) + Mockito.`when`(keyguardPasswordView.isShown).thenReturn(true) + keyguardPasswordViewController.onResume(KeyguardSecurityView.VIEW_REVEALED) + verify(keyguardPasswordView, never()).requestFocus() + } - @Test - fun startAppearAnimation_withExistingMessage() { - `when`(mKeyguardMessageAreaController.message).thenReturn("Unlock to continue.") - keyguardPasswordViewController.startAppearAnimation() - verify(mKeyguardMessageAreaController, never()).setMessage(anyString(), anyBoolean()) - } + @Test + fun testHideKeyboardWhenOnPause() { + keyguardPasswordViewController.onPause() + keyguardPasswordView.post { + verify(keyguardPasswordView).clearFocus() + verify(keyguardPasswordView).hideKeyboard() + } + } - @Test - fun testMessageIsSetWhenReset() { - keyguardPasswordViewController.resetState() - verify(mKeyguardMessageAreaController).setMessage(R.string.keyguard_enter_your_password) - } + @Test + fun testOnViewAttached() { + keyguardPasswordViewController.onViewAttached() + verify(mKeyguardMessageAreaController) + .setMessage(context.resources.getString(R.string.keyguard_enter_your_password), false) + } + + @Test + fun testOnViewAttached_withExistingMessage() { + `when`(mKeyguardMessageAreaController.message).thenReturn("Unlock to continue.") + keyguardPasswordViewController.onViewAttached() + verify(mKeyguardMessageAreaController, never()).setMessage(anyString(), anyBoolean()) + } + + @Test + fun testMessageIsSetWhenReset() { + keyguardPasswordViewController.resetState() + verify(mKeyguardMessageAreaController).setMessage(R.string.keyguard_enter_your_password) + } } diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPatternViewControllerTest.kt b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPatternViewControllerTest.kt index cb182297eae19..051081048d599 100644 --- a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPatternViewControllerTest.kt +++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPatternViewControllerTest.kt @@ -46,6 +46,7 @@ import org.mockito.ArgumentMatchers.anyString import org.mockito.Captor import org.mockito.Mock import org.mockito.Mockito.never +import org.mockito.Mockito.reset import org.mockito.Mockito.verify import org.mockito.Mockito.`when` import org.mockito.MockitoAnnotations @@ -54,35 +55,35 @@ import org.mockito.MockitoAnnotations @RunWith(AndroidTestingRunner::class) @TestableLooper.RunWithLooper class KeyguardPatternViewControllerTest : SysuiTestCase() { - private lateinit var mKeyguardPatternView: KeyguardPatternView + private lateinit var mKeyguardPatternView: KeyguardPatternView - @Mock private lateinit var mKeyguardUpdateMonitor: KeyguardUpdateMonitor + @Mock private lateinit var mKeyguardUpdateMonitor: KeyguardUpdateMonitor - @Mock private lateinit var mSecurityMode: KeyguardSecurityModel.SecurityMode + @Mock private lateinit var mSecurityMode: KeyguardSecurityModel.SecurityMode - @Mock private lateinit var mLockPatternUtils: LockPatternUtils + @Mock private lateinit var mLockPatternUtils: LockPatternUtils - @Mock private lateinit var mKeyguardSecurityCallback: KeyguardSecurityCallback + @Mock private lateinit var mKeyguardSecurityCallback: KeyguardSecurityCallback - @Mock private lateinit var mLatencyTracker: LatencyTracker - private var mFalsingCollector: FalsingCollector = FalsingCollectorFake() + @Mock private lateinit var mLatencyTracker: LatencyTracker + private var mFalsingCollector: FalsingCollector = FalsingCollectorFake() - @Mock private lateinit var mEmergencyButtonController: EmergencyButtonController + @Mock private lateinit var mEmergencyButtonController: EmergencyButtonController - @Mock - private lateinit var mKeyguardMessageAreaControllerFactory: KeyguardMessageAreaController.Factory + @Mock + private lateinit var mKeyguardMessageAreaControllerFactory: + KeyguardMessageAreaController.Factory - @Mock - private lateinit var mKeyguardMessageAreaController: - KeyguardMessageAreaController + @Mock + private lateinit var mKeyguardMessageAreaController: + KeyguardMessageAreaController - @Mock private lateinit var mPostureController: DevicePostureController + @Mock private lateinit var mPostureController: DevicePostureController - private lateinit var mKeyguardPatternViewController: KeyguardPatternViewController - private lateinit var fakeFeatureFlags: FakeFeatureFlags + private lateinit var mKeyguardPatternViewController: KeyguardPatternViewController + private lateinit var fakeFeatureFlags: FakeFeatureFlags - @Captor - lateinit var postureCallbackCaptor: ArgumentCaptor + @Captor lateinit var postureCallbackCaptor: ArgumentCaptor @Before fun setup() { @@ -91,9 +92,8 @@ class KeyguardPatternViewControllerTest : SysuiTestCase() { .thenReturn(mKeyguardMessageAreaController) fakeFeatureFlags = FakeFeatureFlags() fakeFeatureFlags.set(Flags.REVAMPED_BOUNCER_MESSAGES, false) - mKeyguardPatternView = View.inflate(mContext, R.layout.keyguard_pattern_view, null) - as KeyguardPatternView - + mKeyguardPatternView = + View.inflate(mContext, R.layout.keyguard_pattern_view, null) as KeyguardPatternView mKeyguardPatternViewController = KeyguardPatternViewController( @@ -125,8 +125,7 @@ class KeyguardPatternViewControllerTest : SysuiTestCase() { @Test fun onDevicePostureChanged_deviceOpened_propagatedToPatternView() { overrideResource(R.dimen.half_opened_bouncer_height_ratio, 0.5f) - whenever(mPostureController.devicePosture) - .thenReturn(DEVICE_POSTURE_HALF_OPENED) + whenever(mPostureController.devicePosture).thenReturn(DEVICE_POSTURE_HALF_OPENED) mKeyguardPatternViewController.onViewAttached() @@ -159,39 +158,37 @@ class KeyguardPatternViewControllerTest : SysuiTestCase() { return mContext.resources.getFloat(R.dimen.half_opened_bouncer_height_ratio) } - @Test - fun withFeatureFlagOn_oldMessage_isHidden() { - fakeFeatureFlags.set(Flags.REVAMPED_BOUNCER_MESSAGES, true) + @Test + fun withFeatureFlagOn_oldMessage_isHidden() { + fakeFeatureFlags.set(Flags.REVAMPED_BOUNCER_MESSAGES, true) - mKeyguardPatternViewController.onViewAttached() + mKeyguardPatternViewController.onViewAttached() - verify>(mKeyguardMessageAreaController).disable() - } + verify>(mKeyguardMessageAreaController).disable() + } - @Test - fun onPause_resetsText() { - mKeyguardPatternViewController.init() - mKeyguardPatternViewController.onPause() - verify(mKeyguardMessageAreaController).setMessage(R.string.keyguard_enter_your_pattern) - } + @Test + fun onPause_resetsText() { + mKeyguardPatternViewController.init() + mKeyguardPatternViewController.onPause() + verify(mKeyguardMessageAreaController).setMessage(R.string.keyguard_enter_your_pattern) + } - @Test - fun startAppearAnimation() { - mKeyguardPatternViewController.startAppearAnimation() - verify(mKeyguardMessageAreaController) - .setMessage(context.resources.getString(R.string.keyguard_enter_your_pattern), false) - } + @Test + fun testOnViewAttached() { + reset(mKeyguardMessageAreaController) + reset(mLockPatternUtils) + mKeyguardPatternViewController.onViewAttached() + verify(mKeyguardMessageAreaController) + .setMessage(context.resources.getString(R.string.keyguard_enter_your_pattern), false) + verify(mLockPatternUtils).getLockoutAttemptDeadline(anyInt()) + } - @Test - fun startAppearAnimation_withExistingMessage() { - `when`(mKeyguardMessageAreaController.message).thenReturn("Unlock to continue.") - mKeyguardPatternViewController.startAppearAnimation() - verify(mKeyguardMessageAreaController, never()).setMessage(anyString(), anyBoolean()) - } - - @Test - fun resume() { - mKeyguardPatternViewController.onResume(KeyguardSecurityView.VIEW_REVEALED) - verify(mLockPatternUtils).getLockoutAttemptDeadline(anyInt()) - } + @Test + fun testOnViewAttached_withExistingMessage() { + reset(mKeyguardMessageAreaController) + `when`(mKeyguardMessageAreaController.message).thenReturn("Unlock to continue.") + mKeyguardPatternViewController.onViewAttached() + verify(mKeyguardMessageAreaController, never()).setMessage(anyString(), anyBoolean()) + } } diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPinBasedInputViewControllerTest.java b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPinBasedInputViewControllerTest.java index cf86c2192352e..efe1955595ca8 100644 --- a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPinBasedInputViewControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPinBasedInputViewControllerTest.java @@ -100,6 +100,8 @@ public class KeyguardPinBasedInputViewControllerTest extends SysuiTestCase { .thenReturn(mDeleteButton); when(mPinBasedInputView.findViewById(R.id.key_enter)) .thenReturn(mOkButton); + + when(mPinBasedInputView.getResources()).thenReturn(getContext().getResources()); FakeFeatureFlags featureFlags = new FakeFeatureFlags(); featureFlags.set(Flags.REVAMPED_BOUNCER_MESSAGES, true); diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPinViewControllerTest.kt b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPinViewControllerTest.kt index 4dc7652f83cfa..4885838aea51e 100644 --- a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPinViewControllerTest.kt +++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPinViewControllerTest.kt @@ -185,27 +185,27 @@ class KeyguardPinViewControllerTest : SysuiTestCase() { } @Test - fun startAppearAnimation() { + fun testOnViewAttached() { val pinViewController = constructPinViewController(mockKeyguardPinView) - pinViewController.startAppearAnimation() + pinViewController.onViewAttached() verify(keyguardMessageAreaController) .setMessage(context.resources.getString(R.string.keyguard_enter_your_pin), false) } @Test - fun startAppearAnimation_withExistingMessage() { + fun testOnViewAttached_withExistingMessage() { val pinViewController = constructPinViewController(mockKeyguardPinView) Mockito.`when`(keyguardMessageAreaController.message).thenReturn("Unlock to continue.") - pinViewController.startAppearAnimation() + pinViewController.onViewAttached() verify(keyguardMessageAreaController, Mockito.never()).setMessage(anyString(), anyBoolean()) } @Test - fun startAppearAnimation_withAutoPinConfirmationFailedPasswordAttemptsLessThan5() { + fun testOnViewAttached_withAutoPinConfirmationFailedPasswordAttemptsLessThan5() { val pinViewController = constructPinViewController(mockKeyguardPinView) `when`(featureFlags.isEnabled(Flags.AUTO_PIN_CONFIRMATION)).thenReturn(true) `when`(lockPatternUtils.getPinLength(anyInt())).thenReturn(6) @@ -213,7 +213,7 @@ class KeyguardPinViewControllerTest : SysuiTestCase() { `when`(lockPatternUtils.getCurrentFailedPasswordAttempts(anyInt())).thenReturn(3) `when`(passwordTextView.text).thenReturn("") - pinViewController.startAppearAnimation() + pinViewController.onViewAttached() verify(deleteButton).visibility = View.INVISIBLE verify(enterButton).visibility = View.INVISIBLE @@ -222,7 +222,7 @@ class KeyguardPinViewControllerTest : SysuiTestCase() { } @Test - fun startAppearAnimation_withAutoPinConfirmationFailedPasswordAttemptsMoreThan5() { + fun testOnViewAttached_withAutoPinConfirmationFailedPasswordAttemptsMoreThan5() { val pinViewController = constructPinViewController(mockKeyguardPinView) `when`(featureFlags.isEnabled(Flags.AUTO_PIN_CONFIRMATION)).thenReturn(true) `when`(lockPatternUtils.getPinLength(anyInt())).thenReturn(6) @@ -230,7 +230,7 @@ class KeyguardPinViewControllerTest : SysuiTestCase() { `when`(lockPatternUtils.getCurrentFailedPasswordAttempts(anyInt())).thenReturn(6) `when`(passwordTextView.text).thenReturn("") - pinViewController.startAppearAnimation() + pinViewController.onViewAttached() verify(deleteButton).visibility = View.VISIBLE verify(enterButton).visibility = View.VISIBLE diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardSecurityContainerControllerTest.kt b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardSecurityContainerControllerTest.kt index 9ba21da593611..b1e52fb8e826b 100644 --- a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardSecurityContainerControllerTest.kt +++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardSecurityContainerControllerTest.kt @@ -61,6 +61,8 @@ import com.android.systemui.user.domain.interactor.UserInteractor import com.android.systemui.util.kotlin.JavaAdapter import com.android.systemui.util.mockito.any import com.android.systemui.util.mockito.argThat +import com.android.systemui.util.mockito.argumentCaptor +import com.android.systemui.util.mockito.capture import com.android.systemui.util.mockito.mock import com.android.systemui.util.mockito.whenever import com.android.systemui.util.settings.GlobalSettings @@ -587,18 +589,7 @@ class KeyguardSecurityContainerControllerTest : SysuiTestCase() { ArgumentCaptor.forClass(ConfigurationController.ConfigurationListener::class.java) underTest.onViewAttached() verify(configurationController).addCallback(configurationListenerArgumentCaptor.capture()) - clearInvocations(viewFlipperController) configurationListenerArgumentCaptor.value.onThemeChanged() - verify(viewFlipperController).clearViews() - verify(viewFlipperController) - .asynchronouslyInflateView( - eq(SecurityMode.PIN), - any(), - onViewInflatedCallbackArgumentCaptor.capture() - ) - onViewInflatedCallbackArgumentCaptor.value.onViewInflated(inputViewController) - verify(view).reset() - verify(viewFlipperController).reset() verify(view).reloadColors() } @@ -608,16 +599,7 @@ class KeyguardSecurityContainerControllerTest : SysuiTestCase() { ArgumentCaptor.forClass(ConfigurationController.ConfigurationListener::class.java) underTest.onViewAttached() verify(configurationController).addCallback(configurationListenerArgumentCaptor.capture()) - clearInvocations(viewFlipperController) configurationListenerArgumentCaptor.value.onUiModeChanged() - verify(viewFlipperController).clearViews() - verify(viewFlipperController) - .asynchronouslyInflateView( - eq(SecurityMode.PIN), - any(), - onViewInflatedCallbackArgumentCaptor.capture() - ) - onViewInflatedCallbackArgumentCaptor.value.onViewInflated(inputViewController) verify(view).reloadColors() } @@ -849,6 +831,17 @@ class KeyguardSecurityContainerControllerTest : SysuiTestCase() { verify(userSwitcher).setAlpha(0f) } + @Test + fun testOnUserSwitched() { + val userSwitchCallbackArgumentCaptor = + argumentCaptor() + underTest.onViewAttached() + verify(userSwitcherController) + .addUserSwitchCallback(capture(userSwitchCallbackArgumentCaptor)) + userSwitchCallbackArgumentCaptor.value.onUserSwitched() + verify(viewFlipperController).asynchronouslyInflateView(any(), any(), any()) + } + private val registeredSwipeListener: KeyguardSecurityContainer.SwipeListener get() { underTest.onViewAttached() diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardSimPinViewControllerTest.kt b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardSimPinViewControllerTest.kt index a3acc781f2a7f..291dda256c4f3 100644 --- a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardSimPinViewControllerTest.kt +++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardSimPinViewControllerTest.kt @@ -97,6 +97,8 @@ class KeyguardSimPinViewControllerTest : SysuiTestCase() { @Test fun onViewAttached() { underTest.onViewAttached() + verify(keyguardMessageAreaController) + .setMessage(context.resources.getString(R.string.keyguard_enter_your_pin), false) } @Test @@ -120,8 +122,6 @@ class KeyguardSimPinViewControllerTest : SysuiTestCase() { @Test fun startAppearAnimation() { underTest.startAppearAnimation() - verify(keyguardMessageAreaController) - .setMessage(context.resources.getString(R.string.keyguard_enter_your_pin), false) } @Test diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardSimPukViewControllerTest.kt b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardSimPukViewControllerTest.kt index efcf4ddb5c71d..626faa6019701 100644 --- a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardSimPukViewControllerTest.kt +++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardSimPukViewControllerTest.kt @@ -98,6 +98,8 @@ class KeyguardSimPukViewControllerTest : SysuiTestCase() { underTest.onViewAttached() Mockito.verify(keyguardUpdateMonitor) .registerCallback(any(KeyguardUpdateMonitorCallback::class.java)) + Mockito.verify(keyguardMessageAreaController) + .setMessage(context.resources.getString(R.string.keyguard_enter_your_pin), false) } @Test @@ -120,8 +122,6 @@ class KeyguardSimPukViewControllerTest : SysuiTestCase() { @Test fun startAppearAnimation() { underTest.startAppearAnimation() - Mockito.verify(keyguardMessageAreaController) - .setMessage(context.resources.getString(R.string.keyguard_enter_your_pin), false) } @Test