diff options
12 files changed, 143 insertions, 17 deletions
diff --git a/packages/SystemUI/res-keyguard/layout/keyguard_bouncer.xml b/packages/SystemUI/res-keyguard/layout/keyguard_bouncer.xml index 71cdaf5c7091..384e02d62265 100644 --- a/packages/SystemUI/res-keyguard/layout/keyguard_bouncer.xml +++ b/packages/SystemUI/res-keyguard/layout/keyguard_bouncer.xml @@ -22,7 +22,6 @@ android:clipToPadding="false"> <include - style="@style/BouncerSecurityContainer" layout="@layout/keyguard_host_view" android:layout_width="match_parent" android:layout_height="wrap_content" /> diff --git a/packages/SystemUI/res-keyguard/values-sw600dp/styles.xml b/packages/SystemUI/res-keyguard/values-sw600dp/integers.xml index e632e7603259..a35fa3afa8f1 100644 --- a/packages/SystemUI/res-keyguard/values-sw600dp/styles.xml +++ b/packages/SystemUI/res-keyguard/values-sw600dp/integers.xml @@ -1,5 +1,6 @@ +<?xml version="1.0" encoding="utf-8"?> <!-- - ~ Copyright (C) 2014 The Android Open Source Project + ~ Copyright (C) 2021 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. @@ -11,11 +12,12 @@ ~ 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 + ~ limitations under the License. --> - <resources> - <style name="BouncerSecurityContainer"> - <item name="android:layout_gravity">center</item> - </style> -</resources>
\ No newline at end of file + <!-- This needs to be specified in an integer, rather than a style, as it can change in response + to device config changes, and we need to be able to change it without re-inflation. + + 0x11 = center --> + <integer name="keyguard_host_view_gravity">0x11</integer> +</resources> diff --git a/packages/SystemUI/res-keyguard/values/integers.xml b/packages/SystemUI/res-keyguard/values/integers.xml new file mode 100644 index 000000000000..6f14dc9ba2e1 --- /dev/null +++ b/packages/SystemUI/res-keyguard/values/integers.xml @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + ~ Copyright (C) 2021 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. + --> +<resources> + <!-- This needs to be specified in an integer, rather than a style, as it can change in response + to device config changes, and we need to be able to change it without re-inflation. + + 0x50 = bottom, 0x01 = center_horizontal --> + <integer name="keyguard_host_view_gravity">0x51</integer> +</resources> diff --git a/packages/SystemUI/res-keyguard/values/styles.xml b/packages/SystemUI/res-keyguard/values/styles.xml index 8f42cbe31646..2ffc9927480e 100644 --- a/packages/SystemUI/res-keyguard/values/styles.xml +++ b/packages/SystemUI/res-keyguard/values/styles.xml @@ -100,10 +100,6 @@ <item name="android:shadowRadius">?attr/shadowRadius</item> </style> - <style name="BouncerSecurityContainer"> - <item name="android:layout_gravity">center_horizontal|bottom</item> - </style> - <style name="PasswordTheme" parent="Theme.SystemUI"> <item name="android:textColor">?android:attr/textColorPrimary</item> <item name="android:colorControlNormal">?android:attr/textColorPrimary</item> diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardHostViewController.java b/packages/SystemUI/src/com/android/keyguard/KeyguardHostViewController.java index ea60f0d40369..72dd72eb1676 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardHostViewController.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardHostViewController.java @@ -29,6 +29,7 @@ import android.view.KeyEvent; import android.view.View; import android.view.View.OnKeyListener; import android.view.ViewTreeObserver; +import android.widget.FrameLayout; import com.android.keyguard.KeyguardSecurityContainer.SecurityCallback; import com.android.keyguard.KeyguardSecurityModel.SecurityMode; @@ -180,6 +181,7 @@ public class KeyguardHostViewController extends ViewController<KeyguardHostView> /** Initialize the Controller. */ public void onInit() { mKeyguardSecurityContainerController.init(); + updateResources(); } @Override @@ -467,5 +469,23 @@ public class KeyguardHostViewController extends ViewController<KeyguardHostView> mSecurityCallback.finish(strongAuth, currentUser); } - + /** + * Apply keyguard configuration from the currently active resources. This can be called when the + * device configuration changes, to re-apply some resources that are qualified on the device + * configuration. + */ + public void updateResources() { + int gravity = mView.getResources().getInteger(R.integer.keyguard_host_view_gravity); + + // Android SysUI uses a FrameLayout as the top-level, but Auto uses RelativeLayout. + // We're just changing the gravity here though (which can't be applied to RelativeLayout), + // so only attempt the update if mView is inside a FrameLayout. + if (mView.getLayoutParams() instanceof FrameLayout.LayoutParams) { + FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mView.getLayoutParams(); + if (lp.gravity != gravity) { + lp.gravity = gravity; + mView.setLayoutParams(lp); + } + } + } } 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 713daaa9fd4a..6b69103f6030 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBouncer.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBouncer.java @@ -533,6 +533,17 @@ public class KeyguardBouncer { } } + /** + * Apply keyguard configuration from the currently active resources. This can be called when the + * device configuration changes, to re-apply some resources that are qualified on the device + * configuration. + */ + public void updateResources() { + if (mKeyguardViewController != null) { + mKeyguardViewController.updateResources(); + } + } + public void dump(PrintWriter pw) { pw.println("KeyguardBouncer"); pw.println(" isShowing(): " + isShowing()); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java index 5045e95dd53f..c6ef8a3d7ba4 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java @@ -2963,6 +2963,9 @@ public class StatusBar extends SystemUI implements DemoMode, if (mBrightnessMirrorController != null) { mBrightnessMirrorController.updateResources(); } + if (mStatusBarKeyguardViewManager != null) { + mStatusBarKeyguardViewManager.updateResources(); + } mPowerButtonReveal = new PowerButtonReveal(mContext.getResources().getDimensionPixelSize( R.dimen.global_actions_top_padding)); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManager.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManager.java index 81e24cc25aa6..c1f300b49d24 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManager.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManager.java @@ -1084,6 +1084,17 @@ public class StatusBarKeyguardViewManager implements RemoteInputController.Callb || mBouncer.isFullscreenBouncer(); } + /** + * Apply keyguard configuration from the currently active resources. This can be called when the + * device configuration changes, to re-apply some resources that are qualified on the device + * configuration. + */ + public void updateResources() { + if (mBouncer != null) { + mBouncer.updateResources(); + } + } + public void dump(PrintWriter pw) { pw.println("StatusBarKeyguardViewManager:"); pw.println(" mShowing: " + mShowing); diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardHostViewControllerTest.java b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardHostViewControllerTest.java index 64632afe9bfa..714f1f235c52 100644 --- a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardHostViewControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardHostViewControllerTest.java @@ -16,6 +16,9 @@ package com.android.keyguard; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @@ -26,11 +29,14 @@ import android.telephony.TelephonyManager; import android.test.suitebuilder.annotation.SmallTest; import android.testing.AndroidTestingRunner; import android.testing.TestableLooper; +import android.view.Gravity; +import android.view.ViewGroup; +import android.widget.FrameLayout; +import com.android.systemui.R; import com.android.systemui.SysuiTestCase; import com.android.systemui.plugins.ActivityStarter.OnDismissAction; -import org.junit.Assert; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -46,7 +52,7 @@ public class KeyguardHostViewControllerTest extends SysuiTestCase { @Mock private KeyguardUpdateMonitor mKeyguardUpdateMonitor; - @Mock + private KeyguardHostView mKeyguardHostView; @Mock private AudioManager mAudioManager; @@ -66,6 +72,10 @@ public class KeyguardHostViewControllerTest extends SysuiTestCase { @Before public void setup() { + mContext.ensureTestableResources(); + + mKeyguardHostView = new KeyguardHostView(mContext); + when(mKeyguardSecurityContainerControllerFactory.create(any( KeyguardSecurityContainer.SecurityCallback.class))) .thenReturn(mKeyguardSecurityContainerController); @@ -76,10 +86,10 @@ public class KeyguardHostViewControllerTest extends SysuiTestCase { @Test public void testHasDismissActions() { - Assert.assertFalse("Action not set yet", mKeyguardHostViewController.hasDismissActions()); + assertFalse("Action not set yet", mKeyguardHostViewController.hasDismissActions()); mKeyguardHostViewController.setOnDismissAction(mock(OnDismissAction.class), null /* cancelAction */); - Assert.assertTrue("Action should exist", mKeyguardHostViewController.hasDismissActions()); + assertTrue("Action should exist", mKeyguardHostViewController.hasDismissActions()); } @Test @@ -87,4 +97,31 @@ public class KeyguardHostViewControllerTest extends SysuiTestCase { mKeyguardHostViewController.onStartingToHide(); verify(mKeyguardSecurityContainerController).onStartingToHide(); } + + @Test + public void testGravityReappliedOnConfigurationChange() { + FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams( + ViewGroup.LayoutParams.MATCH_PARENT, + ViewGroup.LayoutParams.MATCH_PARENT); + mKeyguardHostView.setLayoutParams(lp); + + // Set initial gravity + mContext.getOrCreateTestableResources().addOverride(R.integer.keyguard_host_view_gravity, + Gravity.CENTER); + + // Kick off the initial pass... + mKeyguardHostViewController.init(); + assertEquals( + ((FrameLayout.LayoutParams) mKeyguardHostView.getLayoutParams()).gravity, + Gravity.CENTER); + + // Now simulate a config change + mContext.getOrCreateTestableResources().addOverride(R.integer.keyguard_host_view_gravity, + Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM); + + mKeyguardHostViewController.updateResources(); + assertEquals( + ((FrameLayout.LayoutParams) mKeyguardHostView.getLayoutParams()).gravity, + Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM); + } } diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/KeyguardBouncerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/KeyguardBouncerTest.java index bc014ec16103..d9e938948f5e 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/KeyguardBouncerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/KeyguardBouncerTest.java @@ -431,4 +431,14 @@ public class KeyguardBouncerTest extends SysuiTestCase { mBouncer.setExpansion(KeyguardBouncer.EXPANSION_VISIBLE); assertThat(mBouncer.inTransit()).isFalse(); } + + @Test + public void testUpdateResources_delegatesToRootView() { + mBouncer.ensureView(); + mBouncer.updateResources(); + + // This is mocked, so won't pick up on the call to updateResources via + // mKeyguardViewController.init(), only updateResources above. + verify(mKeyguardHostViewController).updateResources(); + } } diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManagerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManagerTest.java index 83030eccedd1..45b791715904 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManagerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManagerTest.java @@ -276,4 +276,11 @@ public class StatusBarKeyguardViewManagerTest extends SysuiTestCase { verify(action).onDismiss(); verify(cancelAction, never()).run(); } + + @Test + public void testUpdateResources_delegatesToBouncer() { + mStatusBarKeyguardViewManager.updateResources(); + + verify(mBouncer).updateResources(); + } } diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarTest.java index 253460db0d07..18bdd41dada0 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarTest.java @@ -884,6 +884,13 @@ public class StatusBarTest extends SysuiTestCase { verify(mDozeServiceHost).setDozeSuppressed(false); } + @Test + public void testUpdateResources_updatesBouncer() { + mStatusBar.updateResources(); + + verify(mStatusBarKeyguardViewManager).updateResources(); + } + public static class TestableNotificationInterruptStateProviderImpl extends NotificationInterruptStateProviderImpl { |