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

Commit ad2a7ce6 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

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

Merge "key-guard Pattern view: Fixed posture on config change (rotate)." into udc-qpr-dev am: 842ba6f0

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/23899555



Change-Id: Ib79aaecf60059f41374e42a2c0a88ca7f804ee05
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 38cde80b 842ba6f0
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 =