From 14fa99be68f21103f7840ed6c1e82f6ac6fadcf6 Mon Sep 17 00:00:00 2001 From: axfordjc Date: Tue, 29 Aug 2023 09:30:48 +0000 Subject: Bouncer refactor - prep for motion layout implementation This change partially reverts change ag/24059927 (Change-Id: I3fd6010605d6b5fc5800d5463cd3da5f54ecd88a) because the use of re-inflation caused many issues (b/296567469) TLDR: - removed re-inflation of bouncer on rotate - now call updateConstraints() method instead Previously: - used a new landscape layout and reinflated on rotate, but re-inflation caused many many issues. Now: - bouncers will be refactored to use a single motion layout. E.G., ag/24654828 - transition between landscape or portrait constraints on rotate Flag: WHEN FLAG OFF - old portrait layout always used (no change in behaviour) WHEN FLAG ON - new layout used, constraints updated to match current orientation (once per rotate, once on device posture change, and once after inflate) Bug: 293252410 Bug: 296567469 Test: KeyguardSecurityContainerControllerTest, KeyguardSecurityViewFlipperControllerTest Change-Id: Ibfdf2e0eb1e0cf1a44b8fd43ac4bcffc91818027 --- .../res-keyguard/layout-land/keyguard_pin_view.xml | 25 --- .../layout-sw600dp-land/keyguard_pin_view.xml | 25 --- .../res-keyguard/layout/keyguard_pin_view.xml | 203 +++++++++++++++++- .../layout/keyguard_pin_view_landscape.xml | 231 --------------------- .../layout/keyguard_pin_view_portrait.xml | 218 ------------------- packages/SystemUI/res/values-sw600dp/bools.xml | 8 + packages/SystemUI/res/values/bools.xml | 8 + .../com/android/keyguard/KeyguardInputView.java | 5 + .../KeyguardSecurityContainerController.java | 8 +- .../keyguard/KeyguardSecurityViewFlipper.java | 8 + .../KeyguardSecurityViewFlipperController.java | 40 ++-- .../KeyguardSecurityContainerControllerTest.kt | 45 ---- .../KeyguardSecurityViewFlipperControllerTest.java | 5 - 13 files changed, 257 insertions(+), 572 deletions(-) delete mode 100644 packages/SystemUI/res-keyguard/layout-land/keyguard_pin_view.xml delete mode 100644 packages/SystemUI/res-keyguard/layout-sw600dp-land/keyguard_pin_view.xml delete mode 100644 packages/SystemUI/res-keyguard/layout/keyguard_pin_view_landscape.xml delete mode 100644 packages/SystemUI/res-keyguard/layout/keyguard_pin_view_portrait.xml diff --git a/packages/SystemUI/res-keyguard/layout-land/keyguard_pin_view.xml b/packages/SystemUI/res-keyguard/layout-land/keyguard_pin_view.xml deleted file mode 100644 index cd7ab986844c..000000000000 --- a/packages/SystemUI/res-keyguard/layout-land/keyguard_pin_view.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - diff --git a/packages/SystemUI/res-keyguard/layout-sw600dp-land/keyguard_pin_view.xml b/packages/SystemUI/res-keyguard/layout-sw600dp-land/keyguard_pin_view.xml deleted file mode 100644 index 80cc8c06680a..000000000000 --- a/packages/SystemUI/res-keyguard/layout-sw600dp-land/keyguard_pin_view.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - diff --git a/packages/SystemUI/res-keyguard/layout/keyguard_pin_view.xml b/packages/SystemUI/res-keyguard/layout/keyguard_pin_view.xml index 29e14c57a047..f3cd9e49b49c 100644 --- a/packages/SystemUI/res-keyguard/layout/keyguard_pin_view.xml +++ b/packages/SystemUI/res-keyguard/layout/keyguard_pin_view.xml @@ -1,7 +1,7 @@ - + android:layout_height="match_parent" + android:layout_gravity="center_horizontal|bottom" + android:clipChildren="false" + android:clipToPadding="false" + android:orientation="vertical" + androidprv:layout_maxWidth="@dimen/keyguard_security_width"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + diff --git a/packages/SystemUI/res-keyguard/layout/keyguard_pin_view_landscape.xml b/packages/SystemUI/res-keyguard/layout/keyguard_pin_view_landscape.xml deleted file mode 100644 index e00742d80017..000000000000 --- a/packages/SystemUI/res-keyguard/layout/keyguard_pin_view_landscape.xml +++ /dev/null @@ -1,231 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/packages/SystemUI/res-keyguard/layout/keyguard_pin_view_portrait.xml b/packages/SystemUI/res-keyguard/layout/keyguard_pin_view_portrait.xml deleted file mode 100644 index f3cd9e49b49c..000000000000 --- a/packages/SystemUI/res-keyguard/layout/keyguard_pin_view_portrait.xml +++ /dev/null @@ -1,218 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/packages/SystemUI/res/values-sw600dp/bools.xml b/packages/SystemUI/res/values-sw600dp/bools.xml index 05e38bdb8389..d7ddf00f91c2 100644 --- a/packages/SystemUI/res/values-sw600dp/bools.xml +++ b/packages/SystemUI/res/values-sw600dp/bools.xml @@ -18,4 +18,12 @@ true + + + false diff --git a/packages/SystemUI/res/values/bools.xml b/packages/SystemUI/res/values/bools.xml index 405a59fe1cc7..91d3a88dcc89 100644 --- a/packages/SystemUI/res/values/bools.xml +++ b/packages/SystemUI/res/values/bools.xml @@ -51,4 +51,12 @@ This configuration will only apply when config_remoteInsetsControllerControlsSystemBars. is set to true. --> false + + + true diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardInputView.java b/packages/SystemUI/src/com/android/keyguard/KeyguardInputView.java index c9d906911dbc..a72d8137663b 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardInputView.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardInputView.java @@ -64,6 +64,11 @@ public abstract class KeyguardInputView extends LinearLayout { return false; } + /** Change motion layout constraint set based on orientation */ + protected void updateConstraints(int orientation) { + //Unless overridden, never update constrains (keeping default portrait constraints) + } + protected AnimatorListenerAdapter getAnimationListener(int cuj) { return new AnimatorListenerAdapter() { private boolean mIsCancel; diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainerController.java b/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainerController.java index d90785dd266d..8fcddce646ea 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainerController.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainerController.java @@ -369,11 +369,9 @@ public class KeyguardSecurityContainerController extends ViewController { mView.addView(view); KeyguardInputViewController childController = mKeyguardSecurityViewControllerFactory.create( - (KeyguardInputView) view.findViewById(viewID), + (KeyguardInputView) view, securityMode, keyguardSecurityCallback); childController.init(); mChildren.add(childController); if (onViewInflatedListener != null) { onViewInflatedListener.onViewInflated(childController); + + // Portrait constrains are default + if (mFeatureFlags.isEnabled(LOCKSCREEN_ENABLE_LANDSCAPE) + && + getResources().getBoolean(R.bool.update_bouncer_constraints)) { + // updateConstraints based on orientation (only on small screens) + updateConstraints(getResources().getConfiguration().orientation); + } } }); } } private int getLayoutIdFor(SecurityMode securityMode) { + // TODO (b/297863911, b/297864907) - implement motion layout for other bouncers switch (securityMode) { case Pattern: return R.layout.keyguard_pattern_view; case PIN: return R.layout.keyguard_pin_view; @@ -151,19 +161,23 @@ public class KeyguardSecurityViewFlipperController } } - private int getKeyguardInputViewId(SecurityMode securityMode) { - //Keyguard Input View is not the root view of the layout, use these IDs for lookup. + private int getLegacyLayoutIdFor(SecurityMode securityMode) { switch (securityMode) { - case Pattern: return R.id.keyguard_pattern_view; - case PIN: return R.id.keyguard_pin_view; - case Password: return R.id.keyguard_password_view; - case SimPin: return R.id.keyguard_sim_pin_view; - case SimPuk: return R.id.keyguard_sim_puk_view; + case Pattern: return R.layout.keyguard_pattern_view; + case PIN: return R.layout.keyguard_pin_view; + case Password: return R.layout.keyguard_password_view; + case SimPin: return R.layout.keyguard_sim_pin_view; + case SimPuk: return R.layout.keyguard_sim_puk_view; default: return 0; } } + /** Updates the keyguard view's constraints based on orientation */ + public void updateConstraints(int orientation) { + mView.updateConstraints(orientation); + } + /** Makes the supplied child visible if it is contained win this view, */ public void show(KeyguardInputViewController childController) { int index = childController.getIndexIn(mView); diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardSecurityContainerControllerTest.kt b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardSecurityContainerControllerTest.kt index 6bff4ce4aad9..eb83e2ac9e0f 100644 --- a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardSecurityContainerControllerTest.kt +++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardSecurityContainerControllerTest.kt @@ -622,51 +622,6 @@ class KeyguardSecurityContainerControllerTest : SysuiTestCase() { configurationListenerArgumentCaptor.value.onUiModeChanged() verify(view).reloadColors() } - @Test - fun onOrientationChanged_landscapeKeyguardFlagDisabled_blockReinflate() { - featureFlags.set(Flags.LOCKSCREEN_ENABLE_LANDSCAPE, false) - - // Run onOrientationChanged - val configurationListenerArgumentCaptor = - ArgumentCaptor.forClass(ConfigurationController.ConfigurationListener::class.java) - underTest.onViewAttached() - verify(configurationController).addCallback(configurationListenerArgumentCaptor.capture()) - clearInvocations(viewFlipperController) - configurationListenerArgumentCaptor.value.onOrientationChanged( - Configuration.ORIENTATION_LANDSCAPE - ) - // Verify view is reinflated when flag is on - verify(viewFlipperController, never()).clearViews() - verify(viewFlipperController, never()) - .asynchronouslyInflateView( - eq(SecurityMode.PIN), - any(), - onViewInflatedCallbackArgumentCaptor.capture() - ) - } - - @Test - fun onOrientationChanged_landscapeKeyguardFlagEnabled_doesReinflate() { - featureFlags.set(Flags.LOCKSCREEN_ENABLE_LANDSCAPE, true) - - // Run onOrientationChanged - val configurationListenerArgumentCaptor = - ArgumentCaptor.forClass(ConfigurationController.ConfigurationListener::class.java) - underTest.onViewAttached() - verify(configurationController).addCallback(configurationListenerArgumentCaptor.capture()) - clearInvocations(viewFlipperController) - configurationListenerArgumentCaptor.value.onOrientationChanged( - Configuration.ORIENTATION_LANDSCAPE - ) - // Verify view is reinflated when flag is on - verify(viewFlipperController).clearViews() - verify(viewFlipperController) - .asynchronouslyInflateView( - eq(SecurityMode.PIN), - any(), - onViewInflatedCallbackArgumentCaptor.capture() - ) - } @Test fun hasDismissActions() { diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardSecurityViewFlipperControllerTest.java b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardSecurityViewFlipperControllerTest.java index 68c2f59722ad..19bc8186eee5 100644 --- a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardSecurityViewFlipperControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardSecurityViewFlipperControllerTest.java @@ -140,11 +140,6 @@ public class KeyguardSecurityViewFlipperControllerTest extends SysuiTestCase { @Test public void asynchronouslyInflateView_setNeedsInput() { - when(mKeyguardSecurityViewControllerFactory.create( - any(), any(SecurityMode.class), - any(KeyguardSecurityCallback.class))) - .thenReturn(mKeyguardInputViewController); - ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(AsyncLayoutInflater.OnInflateFinishedListener.class); mKeyguardSecurityViewFlipperController.asynchronouslyInflateView(SecurityMode.PIN, -- cgit v1.2.3-59-g8ed1b