From e11fb91ddb6da156de2fd1c81969a4987aecf1f9 Mon Sep 17 00:00:00 2001 From: axfordjc Date: Mon, 17 Jul 2023 09:00:28 +0000 Subject: [PATCH] Landscape PIN bouncer: refactor of portrait layout Portrait layout moved to a separate file and is now included in keyguard_pin_view. This is done in preparation for the implementation of a landscape layout for the pin view where the portrait layout will be referenced multiple times, so the refactor is to avoid code duplication in the future (as the separate portrait layout file can be included multiple times, avoiding duplication). Bug: 293427037 Test: KeyguardSecurityViewFlipperControllerTest Change-Id: I5d7c8c02f6c448755cb5726fd9d59524d9f2719a --- .../res-keyguard/layout/keyguard_pin_view.xml | 200 +--------------- .../layout/keyguard_pin_view_portrait.xml | 218 ++++++++++++++++++ ...KeyguardSecurityViewFlipperController.java | 25 +- ...uardSecurityViewFlipperControllerTest.java | 5 + 4 files changed, 248 insertions(+), 200 deletions(-) create mode 100644 packages/SystemUI/res-keyguard/layout/keyguard_pin_view_portrait.xml diff --git a/packages/SystemUI/res-keyguard/layout/keyguard_pin_view.xml b/packages/SystemUI/res-keyguard/layout/keyguard_pin_view.xml index c7d2d81ded36b..29e14c57a047e 100644 --- a/packages/SystemUI/res-keyguard/layout/keyguard_pin_view.xml +++ b/packages/SystemUI/res-keyguard/layout/keyguard_pin_view.xml @@ -16,202 +16,10 @@ ** limitations under the License. */ --> - - - + android:layout_height="match_parent"> - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + diff --git a/packages/SystemUI/res-keyguard/layout/keyguard_pin_view_portrait.xml b/packages/SystemUI/res-keyguard/layout/keyguard_pin_view_portrait.xml new file mode 100644 index 0000000000000..f3cd9e49b49ce --- /dev/null +++ b/packages/SystemUI/res-keyguard/layout/keyguard_pin_view_portrait.xml @@ -0,0 +1,218 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityViewFlipperController.java b/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityViewFlipperController.java index fbacd6818648b..bc5b1ba9a294b 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityViewFlipperController.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityViewFlipperController.java @@ -117,15 +117,19 @@ public class KeyguardSecurityViewFlipperController KeyguardSecurityCallback keyguardSecurityCallback, @Nullable OnViewInflatedCallback onViewInflatedListener) { int layoutId = getLayoutIdFor(securityMode); - if (layoutId != 0) { - if (DEBUG) Log.v(TAG, "inflating on bg thread id = " + layoutId); + int viewID = getKeyguardInputViewId(securityMode); + if (layoutId != 0 && viewID != 0) { + if (DEBUG) { + Log.v(TAG, "inflating on bg thread id = " + + layoutId + " . viewID = " + viewID); + } mAsyncLayoutInflater.inflate(layoutId, mView, (view, resId, parent) -> { mView.addView(view); KeyguardInputViewController childController = mKeyguardSecurityViewControllerFactory.create( - (KeyguardInputView) view, securityMode, - keyguardSecurityCallback); + (KeyguardInputView) view.findViewById(viewID), + securityMode, keyguardSecurityCallback); childController.init(); mChildren.add(childController); if (onViewInflatedListener != null) { @@ -147,6 +151,19 @@ public class KeyguardSecurityViewFlipperController } } + private int getKeyguardInputViewId(SecurityMode securityMode) { + //Keyguard Input View is not the root view of the layout, use these IDs for lookup. + 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; + default: + return 0; + } + } + /** 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/KeyguardSecurityViewFlipperControllerTest.java b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardSecurityViewFlipperControllerTest.java index cd187540ba742..64e1458c42d41 100644 --- a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardSecurityViewFlipperControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardSecurityViewFlipperControllerTest.java @@ -138,6 +138,11 @@ 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,