[Bouncer] Update bouncer view with display size.

Updates the bouncer view when display size has changed and when font
scale has changed. When this specific configuration changes, we
invalidate the cache of the view flipper and tell each view mode that
the configuration change has been made. In the UserSwitcher view mode,
we reinflate the user switcher.

Fixes: 257513443
Test: Change display size, turn screen off and on and observe security
view and user switcher has changed size. (On Pin, Password, and pattern)
Test: Change font size and bold font, turn screen off and on and observe security
view and user switcher has changed size. (On Pin, Password, and pattern)
Test: Added unit test.

Change-Id: Iffbbe6f5b0f32f4b40dd70e9bd534b444a8d1ef6
This commit is contained in:
Aaron Liu
2022-11-08 08:50:44 -08:00
parent 00773c6a8e
commit fb36c48bbd
6 changed files with 77 additions and 6 deletions

View File

@@ -727,6 +727,11 @@ public class KeyguardSecurityContainer extends ConstraintLayout {
mViewMode.reloadColors();
}
/** Handles density or font scale changes. */
void onDensityOrFontScaleChanged() {
mViewMode.onDensityOrFontScaleChanged();
}
/**
* Enscapsulates the differences between bouncer modes for the container.
*/
@@ -752,6 +757,9 @@ public class KeyguardSecurityContainer extends ConstraintLayout {
/** Refresh colors */
default void reloadColors() {};
/** Handles density or font scale changes. */
default void onDensityOrFontScaleChanged() {}
/** On a successful auth, optionally handle how the view disappears */
default void startDisappearAnimation(SecurityMode securityMode) {};
@@ -899,14 +907,9 @@ public class KeyguardSecurityContainer extends ConstraintLayout {
mFalsingA11yDelegate = falsingA11yDelegate;
if (mUserSwitcherViewGroup == null) {
LayoutInflater.from(v.getContext()).inflate(
R.layout.keyguard_bouncer_user_switcher,
mView,
true);
mUserSwitcherViewGroup = mView.findViewById(R.id.keyguard_bouncer_user_switcher);
inflateUserSwitcher();
}
updateSecurityViewLocation();
mUserSwitcher = mView.findViewById(R.id.user_switcher_header);
setupUserSwitcher();
mUserSwitcherController.addUserSwitchCallback(mUserSwitchCallback);
}
@@ -936,6 +939,12 @@ public class KeyguardSecurityContainer extends ConstraintLayout {
}
}
@Override
public void onDensityOrFontScaleChanged() {
mView.removeView(mUserSwitcherViewGroup);
inflateUserSwitcher();
}
@Override
public void onDestroy() {
mUserSwitcherController.removeUserSwitchCallback(mUserSwitchCallback);
@@ -1137,6 +1146,15 @@ public class KeyguardSecurityContainer extends ConstraintLayout {
}
}
private void inflateUserSwitcher() {
LayoutInflater.from(mView.getContext()).inflate(
R.layout.keyguard_bouncer_user_switcher,
mView,
true);
mUserSwitcherViewGroup = mView.findViewById(R.id.keyguard_bouncer_user_switcher);
mUserSwitcher = mView.findViewById(R.id.user_switcher_header);
}
interface UserSwitcherCallback {
void showUnlockToContinueMessage();
}

View File

@@ -251,6 +251,11 @@ public class KeyguardSecurityContainerController extends ViewController<Keyguard
public void onUiModeChanged() {
reloadColors();
}
@Override
public void onDensityOrFontScaleChanged() {
KeyguardSecurityContainerController.this.onDensityOrFontScaleChanged();
}
};
private boolean mBouncerVisible = false;
private final KeyguardUpdateMonitorCallback mKeyguardUpdateMonitorCallback =
@@ -727,6 +732,14 @@ public class KeyguardSecurityContainerController extends ViewController<Keyguard
mView.reloadColors();
}
/** Handles density or font scale changes. */
private void onDensityOrFontScaleChanged() {
mSecurityViewFlipperController.onDensityOrFontScaleChanged();
mSecurityViewFlipperController.getSecurityView(mCurrentSecurityMode,
mKeyguardSecurityCallback);
mView.onDensityOrFontScaleChanged();
}
static class Factory {
private final KeyguardSecurityContainer mView;

View File

@@ -83,6 +83,13 @@ public class KeyguardSecurityViewFlipperController
}
}
/** Handles density or font scale changes. */
public void onDensityOrFontScaleChanged() {
mView.removeAllViews();
mChildren.clear();
}
@VisibleForTesting
KeyguardInputViewController<KeyguardInputView> getSecurityView(SecurityMode securityMode,
KeyguardSecurityCallback keyguardSecurityCallback) {

View File

@@ -548,6 +548,22 @@ public class KeyguardSecurityContainerControllerTest extends SysuiTestCase {
verify(mKeyguardPasswordViewControllerMock, never()).showMessage(null, null);
}
@Test
public void onDensityorFontScaleChanged() {
ArgumentCaptor<ConfigurationController.ConfigurationListener>
configurationListenerArgumentCaptor = ArgumentCaptor.forClass(
ConfigurationController.ConfigurationListener.class);
mKeyguardSecurityContainerController.onViewAttached();
verify(mConfigurationController).addCallback(configurationListenerArgumentCaptor.capture());
configurationListenerArgumentCaptor.getValue().onDensityOrFontScaleChanged();
verify(mView).onDensityOrFontScaleChanged();
verify(mKeyguardSecurityViewFlipperController).onDensityOrFontScaleChanged();
verify(mKeyguardSecurityViewFlipperController).getSecurityView(any(SecurityMode.class),
any(KeyguardSecurityCallback.class));
}
private KeyguardSecurityContainer.SwipeListener getRegisteredSwipeListener() {
mKeyguardSecurityContainerController.onViewAttached();
verify(mView).setSwipeListener(mSwipeListenerArgumentCaptor.capture());

View File

@@ -307,6 +307,17 @@ public class KeyguardSecurityContainerTest extends SysuiTestCase {
assertThat(anchor.isClickable()).isTrue();
}
@Test
public void testOnDensityOrFontScaleChanged() {
setupUserSwitcher();
View oldUserSwitcher = mKeyguardSecurityContainer.findViewById(
R.id.keyguard_bouncer_user_switcher);
mKeyguardSecurityContainer.onDensityOrFontScaleChanged();
View newUserSwitcher = mKeyguardSecurityContainer.findViewById(
R.id.keyguard_bouncer_user_switcher);
assertThat(oldUserSwitcher).isNotEqualTo(newUserSwitcher);
}
@Test
public void testTouchesAreRecognizedAsBeingOnTheOtherSideOfSecurity() {
setupUserSwitcher();

View File

@@ -106,4 +106,10 @@ public class KeyguardSecurityViewFlipperControllerTest extends SysuiTestCase {
}
}
}
@Test
public void onDensityOrFontScaleChanged() {
mKeyguardSecurityViewFlipperController.onDensityOrFontScaleChanged();
verify(mView).removeAllViews();
}
}