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

Commit ebe378d2 authored by Christoph Schlosser's avatar Christoph Schlosser
Browse files

Hide pattern by default when a non-touch pointing device is available

When drawing a pattern on the lockscreen using the touch screen or a
mouse the pattern is visible by default for some time.
This change modifies the default value on devices that have a pointing
device, like a mouse or touchpad, attached or connected to their device
to hide the drawn pattern by default. Leaving the default for
touch-only input unchanged.

Flag: com.android.internal.widget.flags.hide_last_char_with_physical_input
Bug: 339270220
Test: atest LockPatternUtilsTest

Change-Id: I2142abe2f469bb65a56be68f07990897083b43b4
parent a8557968
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -1101,12 +1101,20 @@ public class LockPatternUtils {
        return type == CREDENTIAL_TYPE_PATTERN;
    }

    private boolean hasActivePointerDeviceAttached() {
        return !getEnabledNonTouchInputDevices(InputDevice.SOURCE_CLASS_POINTER).isEmpty();
    }

    /**
     * @return Whether the visible pattern is enabled.
     */
    @UnsupportedAppUsage
    public boolean isVisiblePatternEnabled(int userId) {
        return getBoolean(Settings.Secure.LOCK_PATTERN_VISIBLE, true, userId);
        boolean defaultValue = true;
        if (hideLastCharWithPhysicalInput()) {
            defaultValue = !hasActivePointerDeviceAttached();
        }
        return getBoolean(Settings.Secure.LOCK_PATTERN_VISIBLE, defaultValue, userId);
    }

    /**
+57 −0
Original line number Diff line number Diff line
@@ -500,4 +500,61 @@ public class LockPatternUtilsTest {
        session.close();
    }

    @Test
    @EnableFlags(Flags.FLAG_HIDE_LAST_CHAR_WITH_PHYSICAL_INPUT)
    public void isVisiblePatternEnabled_noDevices() throws RemoteException {
        InputManagerGlobal.TestSession session = configureExternalHardwareTest(new InputDevice[0]);
        assertTrue(mLockPatternUtils.isVisiblePatternEnabled(USER_ID));
        session.close();
    }

    @Test
    @EnableFlags(Flags.FLAG_HIDE_LAST_CHAR_WITH_PHYSICAL_INPUT)
    public void isVisiblePatternEnabled_noEnabledDevices() throws RemoteException {
        InputDevice.Builder builder = new InputDevice.Builder();
        builder.setEnabled(false);
        InputManagerGlobal.TestSession session =
                configureExternalHardwareTest(new InputDevice[]{builder.build()});
        assertTrue(mLockPatternUtils.isVisiblePatternEnabled(USER_ID));
        session.close();
    }

    @Test
    @EnableFlags(Flags.FLAG_HIDE_LAST_CHAR_WITH_PHYSICAL_INPUT)
    public void isVisiblePatternEnabled_noPointingDevices() throws RemoteException {
        InputDevice.Builder builder = new InputDevice.Builder();
        builder
                .setEnabled(true)
                .setSources(InputDevice.SOURCE_TOUCHSCREEN);
        InputManagerGlobal.TestSession session =
                configureExternalHardwareTest(new InputDevice[]{builder.build()});
        assertTrue(mLockPatternUtils.isVisiblePatternEnabled(USER_ID));
        session.close();
    }

    @Test
    @EnableFlags(Flags.FLAG_HIDE_LAST_CHAR_WITH_PHYSICAL_INPUT)
    public void isVisiblePatternEnabled_externalPointingDevice() throws RemoteException {
        InputDevice.Builder builder = new InputDevice.Builder();
        builder
                .setEnabled(true)
                .setSources(InputDevice.SOURCE_CLASS_POINTER);
        InputManagerGlobal.TestSession session =
                configureExternalHardwareTest(new InputDevice[]{builder.build()});
        assertFalse(mLockPatternUtils.isVisiblePatternEnabled(USER_ID));
        session.close();
    }

    @Test
    @DisableFlags(Flags.FLAG_HIDE_LAST_CHAR_WITH_PHYSICAL_INPUT)
    public void isVisiblePatternEnabled_externalPointingDeviceOldDefault() throws RemoteException {
        InputDevice.Builder builder = new InputDevice.Builder();
        builder
                .setEnabled(true)
                .setSources(InputDevice.SOURCE_CLASS_POINTER);
        InputManagerGlobal.TestSession session =
                configureExternalHardwareTest(new InputDevice[]{builder.build()});
        assertTrue(mLockPatternUtils.isVisiblePatternEnabled(USER_ID));
        session.close();
    }
}