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

Commit a1398df0 authored by Jamie Garside's avatar Jamie Garside Committed by Android (Google) Code Review
Browse files

Merge "Ensure bouncer in correct position on swipe. Remove orientationlistener." into sc-dev

parents 6f927be4 caf8a9bf
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -487,5 +487,9 @@ public class KeyguardHostViewController extends ViewController<KeyguardHostView>
                mView.setLayoutParams(lp);
            }
        }

        if (mKeyguardSecurityContainerController != null) {
            mKeyguardSecurityContainerController.updateResources();
        }
    }
}
+9 −11
Original line number Diff line number Diff line
@@ -33,7 +33,6 @@ import android.util.MathUtils;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.OrientationEventListener;
import android.view.VelocityTracker;
import android.view.View;
import android.view.ViewConfiguration;
@@ -107,7 +106,6 @@ public class KeyguardSecurityContainer extends FrameLayout {
    private boolean mOneHandedMode = false;
    private SecurityMode mSecurityMode = SecurityMode.Invalid;
    private ViewPropertyAnimator mRunningOneHandedAnimator;
    private final OrientationEventListener mOrientationEventListener;

    private final WindowInsetsAnimation.Callback mWindowInsetsAnimationCallback =
            new WindowInsetsAnimation.Callback(DISPATCH_MODE_STOP) {
@@ -247,13 +245,6 @@ public class KeyguardSecurityContainer extends FrameLayout {
        super(context, attrs, defStyle);
        mSpringAnimation = new SpringAnimation(this, DynamicAnimation.Y);
        mViewConfiguration = ViewConfiguration.get(context);

        mOrientationEventListener = new OrientationEventListener(context) {
            @Override
            public void onOrientationChanged(int orientation) {
                updateLayoutForSecurityMode(mSecurityMode);
            }
        };
    }

    void onResume(SecurityMode securityMode, boolean faceAuthEnabled) {
@@ -262,7 +253,6 @@ public class KeyguardSecurityContainer extends FrameLayout {
        updateBiometricRetry(securityMode, faceAuthEnabled);

        updateLayoutForSecurityMode(securityMode);
        mOrientationEventListener.enable();
    }

    void updateLayoutForSecurityMode(SecurityMode securityMode) {
@@ -385,7 +375,6 @@ public class KeyguardSecurityContainer extends FrameLayout {
            mAlertDialog = null;
        }
        mSecurityViewFlipper.setWindowInsetsAnimationCallback(null);
        mOrientationEventListener.disable();
    }

    @Override
@@ -663,6 +652,15 @@ public class KeyguardSecurityContainer extends FrameLayout {
                        childState << MEASURED_HEIGHT_STATE_SHIFT));
    }

    @Override
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
        super.onLayout(changed, left, top, right, bottom);

        // After a layout pass, we need to re-place the inner bouncer, as our bounds may have
        // changed.
        updateSecurityViewLocation(/* animate= */false);
    }

    void showAlmostAtWipeDialog(int attempts, int remaining, int userType) {
        String message = null;
        switch (userType) {
+17 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import static com.android.systemui.DejankUtils.whitelistIpcs;
import android.app.admin.DevicePolicyManager;
import android.content.Intent;
import android.content.res.ColorStateList;
import android.content.res.Configuration;
import android.metrics.LogMaker;
import android.os.UserHandle;
import android.util.Log;
@@ -74,6 +75,8 @@ public class KeyguardSecurityContainerController extends ViewController<Keyguard
    private final SecurityCallback mSecurityCallback;
    private final ConfigurationController mConfigurationController;

    private int mLastOrientation = Configuration.ORIENTATION_UNDEFINED;

    private SecurityMode mCurrentSecurityMode = SecurityMode.Invalid;

    private final Gefingerpoken mGlobalTouchListener = new Gefingerpoken() {
@@ -212,6 +215,7 @@ public class KeyguardSecurityContainerController extends ViewController<Keyguard
        mAdminSecondaryLockScreenController = adminSecondaryLockScreenControllerFactory.create(
                mKeyguardSecurityCallback);
        mConfigurationController = configurationController;
        mLastOrientation = getResources().getConfiguration().orientation;
    }

    @Override
@@ -498,6 +502,19 @@ public class KeyguardSecurityContainerController extends ViewController<Keyguard
        return getCurrentSecurityController();
    }

    /**
     * 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 newOrientation = getResources().getConfiguration().orientation;
        if (newOrientation != mLastOrientation) {
            mLastOrientation = newOrientation;
            mView.updateLayoutForSecurityMode(mCurrentSecurityMode);
        }
    }

    static class Factory {

        private final KeyguardSecurityContainer mView;
+23 −0
Original line number Diff line number Diff line
@@ -25,9 +25,11 @@ import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import android.content.res.Configuration;
import android.content.res.Resources;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;
@@ -96,6 +98,9 @@ public class KeyguardSecurityContainerControllerTest extends SysuiTestCase {
    private ConfigurationController mConfigurationController;
    @Mock
    private EmergencyButtonController mEmergencyButtonController;
    @Mock
    private Resources mResources;
    private Configuration mConfiguration;

    private KeyguardSecurityContainerController mKeyguardSecurityContainerController;
    private KeyguardPasswordViewController mKeyguardPasswordViewController;
@@ -103,6 +108,11 @@ public class KeyguardSecurityContainerControllerTest extends SysuiTestCase {

    @Before
    public void setup() {
        mConfiguration = new Configuration();
        mConfiguration.setToDefaults(); // Defaults to ORIENTATION_UNDEFINED.

        when(mResources.getConfiguration()).thenReturn(mConfiguration);
        when(mView.getResources()).thenReturn(mResources);
        when(mAdminSecondaryLockScreenControllerFactory.create(any(KeyguardSecurityCallback.class)))
                .thenReturn(mAdminSecondaryLockScreenController);
        when(mSecurityViewFlipper.getWindowInsetsController()).thenReturn(mWindowInsetsController);
@@ -154,4 +164,17 @@ public class KeyguardSecurityContainerControllerTest extends SysuiTestCase {
        verify(mWindowInsetsController).controlWindowInsetsAnimation(
                eq(ime()), anyLong(), any(), any(), any());
    }

    @Test
    public void onResourcesUpdate_callsThroughOnRotationChange() {
        // Rotation is the same, shouldn't cause an update
        mKeyguardSecurityContainerController.updateResources();
        verify(mView, times(0)).updateLayoutForSecurityMode(any());

        // Update rotation. Should trigger update
        mConfiguration.orientation = Configuration.ORIENTATION_LANDSCAPE;

        mKeyguardSecurityContainerController.updateResources();
        verify(mView, times(1)).updateLayoutForSecurityMode(any());
    }
}