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

Commit 0d4b8acf authored by Matt Pietal's avatar Matt Pietal
Browse files

Bouncer - Ensure one-handed mode bouncer side

The bouncer should appear (and remain) on the side the user swipes
up. From then on, it needs to move to the left/right side, depending
on touch.

Fixes: 224170485
Test: atest KeyguardSecurityContainerTest
Change-Id: Idd6f29e4591eacad74480e7928a6c8b82e73f206
parent 352d8d7a
Loading
Loading
Loading
Loading
+12 −8
Original line number Diff line number Diff line
@@ -307,8 +307,6 @@ public class KeyguardSecurityContainer extends FrameLayout {
    void onResume(SecurityMode securityMode, boolean faceAuthEnabled) {
        mSecurityViewFlipper.setWindowInsetsAnimationCallback(mWindowInsetsAnimationCallback);
        updateBiometricRetry(securityMode, faceAuthEnabled);

        setupViewMode();
    }

    void initMode(@Mode int mode, GlobalSettings globalSettings, FalsingManager falsingManager,
@@ -1044,11 +1042,13 @@ public class KeyguardSecurityContainer extends FrameLayout {

        /**
         * Moves the bouncer to align with a tap (most likely in the shade), so the bouncer
         * appears on the same side as a touch. Will not update the user-preference.
         * appears on the same side as a touch.
         */
        @Override
        public void updatePositionByTouchX(float x) {
            updateSecurityViewLocation(x <= mView.getWidth() / 2f, /* animate= */false);
            boolean isTouchOnLeft = x <= mView.getWidth() / 2f;
            updateSideSetting(isTouchOnLeft);
            updateSecurityViewLocation(isTouchOnLeft, /* animate= */false);
        }

        boolean isLeftAligned() {
@@ -1057,6 +1057,13 @@ public class KeyguardSecurityContainer extends FrameLayout {
                == Settings.Global.ONE_HANDED_KEYGUARD_SIDE_LEFT;
        }

        private void updateSideSetting(boolean leftAligned) {
            mGlobalSettings.putInt(
                    Settings.Global.ONE_HANDED_KEYGUARD_SIDE,
                    leftAligned ? Settings.Global.ONE_HANDED_KEYGUARD_SIDE_LEFT
                    : Settings.Global.ONE_HANDED_KEYGUARD_SIDE_RIGHT);
        }

        /**
         * Determine if a tap on this view is on the other side. If so, will animate positions
         * and record the preference to always show on this side.
@@ -1070,10 +1077,7 @@ public class KeyguardSecurityContainer extends FrameLayout {
                    || (!currentlyLeftAligned && (x < mView.getWidth() / 2f))) {

                boolean willBeLeftAligned = !currentlyLeftAligned;
                mGlobalSettings.putInt(
                        Settings.Global.ONE_HANDED_KEYGUARD_SIDE,
                        willBeLeftAligned ? Settings.Global.ONE_HANDED_KEYGUARD_SIDE_LEFT
                        : Settings.Global.ONE_HANDED_KEYGUARD_SIDE_RIGHT);
                updateSideSetting(willBeLeftAligned);

                int keyguardState = willBeLeftAligned
                        ? SysUiStatsLog.KEYGUARD_BOUNCER_STATE_CHANGED__STATE__SWITCH_LEFT
+5 −0
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import static org.mockito.Mockito.when;
import android.content.pm.UserInfo;
import android.content.res.Configuration;
import android.graphics.Insets;
import android.provider.Settings;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;
import android.view.Gravity;
@@ -204,10 +205,14 @@ public class KeyguardSecurityContainerTest extends SysuiTestCase {
        mKeyguardSecurityContainer.updatePositionByTouchX(
                mKeyguardSecurityContainer.getWidth() - 1f);

        verify(mGlobalSettings).putInt(Settings.Global.ONE_HANDED_KEYGUARD_SIDE,
                Settings.Global.ONE_HANDED_KEYGUARD_SIDE_RIGHT);
        verify(mSecurityViewFlipper).setTranslationX(
                mKeyguardSecurityContainer.getWidth() - mSecurityViewFlipper.getWidth());

        mKeyguardSecurityContainer.updatePositionByTouchX(1f);
        verify(mGlobalSettings).putInt(Settings.Global.ONE_HANDED_KEYGUARD_SIDE,
                Settings.Global.ONE_HANDED_KEYGUARD_SIDE_LEFT);

        verify(mSecurityViewFlipper).setTranslationX(0.0f);
    }