Loading packages/SystemUI/src/com/android/keyguard/KeyguardPatternView.java +15 −1 Original line number Diff line number Diff line Loading @@ -16,8 +16,10 @@ package com.android.keyguard; import static com.android.systemui.statusbar.policy.DevicePostureController.DEVICE_POSTURE_HALF_OPENED; import static com.android.systemui.statusbar.policy.DevicePostureController.DEVICE_POSTURE_UNKNOWN; import android.content.Context; import android.content.res.Configuration; import android.graphics.Rect; import android.os.SystemClock; import android.text.TextUtils; Loading Loading @@ -74,6 +76,7 @@ public class KeyguardPatternView extends KeyguardInputView BouncerKeyguardMessageArea mSecurityMessageDisplay; private View mEcaView; private ConstraintLayout mContainer; @DevicePostureInt private int mLastDevicePosture = DEVICE_POSTURE_UNKNOWN; public KeyguardPatternView(Context context) { this(context, null); Loading @@ -95,14 +98,25 @@ public class KeyguardPatternView extends KeyguardInputView mContext, android.R.interpolator.fast_out_linear_in)); } @Override protected void onConfigurationChanged(Configuration newConfig) { updateMargins(); } void onDevicePostureChanged(@DevicePostureInt int posture) { mLastDevicePosture = posture; updateMargins(); } private void updateMargins() { // Update the guideline based on the device posture... float halfOpenPercentage = mContext.getResources().getFloat(R.dimen.half_opened_bouncer_height_ratio); ConstraintSet cs = new ConstraintSet(); cs.clone(mContainer); cs.setGuidelinePercent(R.id.pattern_top_guideline, posture == DEVICE_POSTURE_HALF_OPENED cs.setGuidelinePercent(R.id.pattern_top_guideline, mLastDevicePosture == DEVICE_POSTURE_HALF_OPENED ? halfOpenPercentage : 0.0f); cs.applyTo(mContainer); } Loading packages/SystemUI/tests/src/com/android/keyguard/KeyguardPatternViewControllerTest.kt +27 −1 Original line number Diff line number Diff line Loading @@ -32,15 +32,18 @@ import com.android.systemui.flags.FakeFeatureFlags import com.android.systemui.flags.Flags import com.android.systemui.statusbar.policy.DevicePostureController import com.android.systemui.statusbar.policy.DevicePostureController.DEVICE_POSTURE_HALF_OPENED import com.android.systemui.statusbar.policy.DevicePostureController.DEVICE_POSTURE_OPENED import com.android.systemui.util.mockito.any import com.android.systemui.util.mockito.whenever import com.google.common.truth.Truth.assertThat import org.junit.Before import org.junit.Test import org.junit.runner.RunWith import org.mockito.ArgumentCaptor import org.mockito.ArgumentMatchers.anyBoolean import org.mockito.ArgumentMatchers.anyInt import org.mockito.ArgumentMatchers.anyString import org.mockito.Captor import org.mockito.Mock import org.mockito.Mockito.never import org.mockito.Mockito.verify Loading Loading @@ -78,6 +81,9 @@ class KeyguardPatternViewControllerTest : SysuiTestCase() { private lateinit var mKeyguardPatternViewController: KeyguardPatternViewController private lateinit var fakeFeatureFlags: FakeFeatureFlags @Captor lateinit var postureCallbackCaptor: ArgumentCaptor<DevicePostureController.Callback> @Before fun setup() { MockitoAnnotations.initMocks(this) Loading Loading @@ -107,7 +113,7 @@ class KeyguardPatternViewControllerTest : SysuiTestCase() { } @Test fun tabletopPostureIsDetectedFromStart() { fun onViewAttached_deviceHalfFolded_propagatedToPatternView() { overrideResource(R.dimen.half_opened_bouncer_height_ratio, 0.5f) whenever(mPostureController.devicePosture).thenReturn(DEVICE_POSTURE_HALF_OPENED) Loading @@ -116,6 +122,26 @@ class KeyguardPatternViewControllerTest : SysuiTestCase() { assertThat(getPatternTopGuideline()).isEqualTo(getExpectedTopGuideline()) } @Test fun onDevicePostureChanged_deviceOpened_propagatedToPatternView() { overrideResource(R.dimen.half_opened_bouncer_height_ratio, 0.5f) whenever(mPostureController.devicePosture) .thenReturn(DEVICE_POSTURE_HALF_OPENED) mKeyguardPatternViewController.onViewAttached() // Verify view begins in posture state DEVICE_POSTURE_HALF_OPENED assertThat(getPatternTopGuideline()).isEqualTo(getExpectedTopGuideline()) // Simulate posture change to state DEVICE_POSTURE_OPENED with callback verify(mPostureController).addCallback(postureCallbackCaptor.capture()) val postureCallback: DevicePostureController.Callback = postureCallbackCaptor.value postureCallback.onPostureChanged(DEVICE_POSTURE_OPENED) // Verify view is now in posture state DEVICE_POSTURE_OPENED assertThat(getPatternTopGuideline()).isNotEqualTo(getExpectedTopGuideline()) } private fun getPatternTopGuideline(): Float { val cs = ConstraintSet() val container = Loading Loading
packages/SystemUI/src/com/android/keyguard/KeyguardPatternView.java +15 −1 Original line number Diff line number Diff line Loading @@ -16,8 +16,10 @@ package com.android.keyguard; import static com.android.systemui.statusbar.policy.DevicePostureController.DEVICE_POSTURE_HALF_OPENED; import static com.android.systemui.statusbar.policy.DevicePostureController.DEVICE_POSTURE_UNKNOWN; import android.content.Context; import android.content.res.Configuration; import android.graphics.Rect; import android.os.SystemClock; import android.text.TextUtils; Loading Loading @@ -74,6 +76,7 @@ public class KeyguardPatternView extends KeyguardInputView BouncerKeyguardMessageArea mSecurityMessageDisplay; private View mEcaView; private ConstraintLayout mContainer; @DevicePostureInt private int mLastDevicePosture = DEVICE_POSTURE_UNKNOWN; public KeyguardPatternView(Context context) { this(context, null); Loading @@ -95,14 +98,25 @@ public class KeyguardPatternView extends KeyguardInputView mContext, android.R.interpolator.fast_out_linear_in)); } @Override protected void onConfigurationChanged(Configuration newConfig) { updateMargins(); } void onDevicePostureChanged(@DevicePostureInt int posture) { mLastDevicePosture = posture; updateMargins(); } private void updateMargins() { // Update the guideline based on the device posture... float halfOpenPercentage = mContext.getResources().getFloat(R.dimen.half_opened_bouncer_height_ratio); ConstraintSet cs = new ConstraintSet(); cs.clone(mContainer); cs.setGuidelinePercent(R.id.pattern_top_guideline, posture == DEVICE_POSTURE_HALF_OPENED cs.setGuidelinePercent(R.id.pattern_top_guideline, mLastDevicePosture == DEVICE_POSTURE_HALF_OPENED ? halfOpenPercentage : 0.0f); cs.applyTo(mContainer); } Loading
packages/SystemUI/tests/src/com/android/keyguard/KeyguardPatternViewControllerTest.kt +27 −1 Original line number Diff line number Diff line Loading @@ -32,15 +32,18 @@ import com.android.systemui.flags.FakeFeatureFlags import com.android.systemui.flags.Flags import com.android.systemui.statusbar.policy.DevicePostureController import com.android.systemui.statusbar.policy.DevicePostureController.DEVICE_POSTURE_HALF_OPENED import com.android.systemui.statusbar.policy.DevicePostureController.DEVICE_POSTURE_OPENED import com.android.systemui.util.mockito.any import com.android.systemui.util.mockito.whenever import com.google.common.truth.Truth.assertThat import org.junit.Before import org.junit.Test import org.junit.runner.RunWith import org.mockito.ArgumentCaptor import org.mockito.ArgumentMatchers.anyBoolean import org.mockito.ArgumentMatchers.anyInt import org.mockito.ArgumentMatchers.anyString import org.mockito.Captor import org.mockito.Mock import org.mockito.Mockito.never import org.mockito.Mockito.verify Loading Loading @@ -78,6 +81,9 @@ class KeyguardPatternViewControllerTest : SysuiTestCase() { private lateinit var mKeyguardPatternViewController: KeyguardPatternViewController private lateinit var fakeFeatureFlags: FakeFeatureFlags @Captor lateinit var postureCallbackCaptor: ArgumentCaptor<DevicePostureController.Callback> @Before fun setup() { MockitoAnnotations.initMocks(this) Loading Loading @@ -107,7 +113,7 @@ class KeyguardPatternViewControllerTest : SysuiTestCase() { } @Test fun tabletopPostureIsDetectedFromStart() { fun onViewAttached_deviceHalfFolded_propagatedToPatternView() { overrideResource(R.dimen.half_opened_bouncer_height_ratio, 0.5f) whenever(mPostureController.devicePosture).thenReturn(DEVICE_POSTURE_HALF_OPENED) Loading @@ -116,6 +122,26 @@ class KeyguardPatternViewControllerTest : SysuiTestCase() { assertThat(getPatternTopGuideline()).isEqualTo(getExpectedTopGuideline()) } @Test fun onDevicePostureChanged_deviceOpened_propagatedToPatternView() { overrideResource(R.dimen.half_opened_bouncer_height_ratio, 0.5f) whenever(mPostureController.devicePosture) .thenReturn(DEVICE_POSTURE_HALF_OPENED) mKeyguardPatternViewController.onViewAttached() // Verify view begins in posture state DEVICE_POSTURE_HALF_OPENED assertThat(getPatternTopGuideline()).isEqualTo(getExpectedTopGuideline()) // Simulate posture change to state DEVICE_POSTURE_OPENED with callback verify(mPostureController).addCallback(postureCallbackCaptor.capture()) val postureCallback: DevicePostureController.Callback = postureCallbackCaptor.value postureCallback.onPostureChanged(DEVICE_POSTURE_OPENED) // Verify view is now in posture state DEVICE_POSTURE_OPENED assertThat(getPatternTopGuideline()).isNotEqualTo(getExpectedTopGuideline()) } private fun getPatternTopGuideline(): Float { val cs = ConstraintSet() val container = Loading