Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 978ecf99 authored by axfordjc's avatar axfordjc Committed by Jonathon Axford
Browse files

key-guard Pattern view: Fixed posture on config change (rotate).

Layout of the pattern depends on both configuration (orientation) and posture. Now the layout (pattern margins) are updated when either changes, previous margins where only updated on posture change and not config change.

Added tests for posture changed check.

Fixes: 290175864
Test: KeyguardPatternViewControllerTest
Change-Id: Idbcf8b5aa8eabeaafd50ee0cc96e8e6b2aa9875f
parent 4321cd2b
Loading
Loading
Loading
Loading
+15 −1
Original line number Diff line number Diff line
@@ -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;
@@ -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);
@@ -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);
    }
+27 −1
Original line number Diff line number Diff line
@@ -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
@@ -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)
@@ -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)

@@ -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 =