Merge "Make KeyguardBouncer react to device config changes." into sc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
c5b1339d29
@@ -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" />
|
||||
|
||||
@@ -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>
|
||||
<!-- 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>
|
||||
23
packages/SystemUI/res-keyguard/values/integers.xml
Normal file
23
packages/SystemUI/res-keyguard/values/integers.xml
Normal file
@@ -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>
|
||||
@@ -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>
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user