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

Commit 687e70c7 authored by Vaibhav Devmurari's avatar Vaibhav Devmurari Committed by Android (Google) Code Review
Browse files

Merge "Fix: Block opening any apps on keyguard without user auth" into main

parents 88cac5de d6152984
Loading
Loading
Loading
Loading
+7 −6
Original line number Original line Diff line number Diff line
@@ -3576,7 +3576,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                }
                }
                break;
                break;
            case KeyEvent.KEYCODE_I:
            case KeyEvent.KEYCODE_I:
                if (firstDown && event.isMetaPressed()) {
                if (firstDown && event.isMetaPressed() && isUserSetupComplete() && !keyguardOn) {
                    showSystemSettings();
                    showSystemSettings();
                    notifyKeyGestureCompleted(event,
                    notifyKeyGestureCompleted(event,
                            KeyGestureEvent.KEY_GESTURE_TYPE_LAUNCH_SYSTEM_SETTINGS);
                            KeyGestureEvent.KEY_GESTURE_TYPE_LAUNCH_SYSTEM_SETTINGS);
@@ -4138,6 +4138,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        int displayId = event.getDisplayId();
        int displayId = event.getDisplayId();
        int modifierState = event.getModifierState();
        int modifierState = event.getModifierState();
        boolean keyguardOn = keyguardOn();
        boolean keyguardOn = keyguardOn();
        boolean canLaunchApp = isUserSetupComplete() && !keyguardOn;
        switch (gestureType) {
        switch (gestureType) {
            case KeyGestureEvent.KEY_GESTURE_TYPE_RECENT_APPS:
            case KeyGestureEvent.KEY_GESTURE_TYPE_RECENT_APPS:
                if (complete) {
                if (complete) {
@@ -4155,7 +4156,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                return true;
                return true;
            case KeyGestureEvent.KEY_GESTURE_TYPE_LAUNCH_ASSISTANT:
            case KeyGestureEvent.KEY_GESTURE_TYPE_LAUNCH_ASSISTANT:
            case KeyGestureEvent.KEY_GESTURE_TYPE_LAUNCH_VOICE_ASSISTANT:
            case KeyGestureEvent.KEY_GESTURE_TYPE_LAUNCH_VOICE_ASSISTANT:
                if (complete) {
                if (complete && canLaunchApp) {
                    launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD,
                    launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD,
                            deviceId, SystemClock.uptimeMillis(),
                            deviceId, SystemClock.uptimeMillis(),
                            AssistUtils.INVOCATION_TYPE_UNKNOWN);
                            AssistUtils.INVOCATION_TYPE_UNKNOWN);
@@ -4168,7 +4169,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                }
                }
                return true;
                return true;
            case KeyGestureEvent.KEY_GESTURE_TYPE_LAUNCH_SYSTEM_SETTINGS:
            case KeyGestureEvent.KEY_GESTURE_TYPE_LAUNCH_SYSTEM_SETTINGS:
                if (complete) {
                if (complete && canLaunchApp) {
                    showSystemSettings();
                    showSystemSettings();
                }
                }
                return true;
                return true;
@@ -4271,7 +4272,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                }
                }
                return true;
                return true;
            case KeyGestureEvent.KEY_GESTURE_TYPE_LAUNCH_SEARCH:
            case KeyGestureEvent.KEY_GESTURE_TYPE_LAUNCH_SEARCH:
                if (complete) {
                if (complete && canLaunchApp) {
                    launchTargetSearchActivity();
                    launchTargetSearchActivity();
                }
                }
                return true;
                return true;
@@ -4352,8 +4353,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                break;
                break;
            case KeyGestureEvent.KEY_GESTURE_TYPE_LAUNCH_APPLICATION:
            case KeyGestureEvent.KEY_GESTURE_TYPE_LAUNCH_APPLICATION:
                AppLaunchData data = event.getAppLaunchData();
                AppLaunchData data = event.getAppLaunchData();
                if (complete && isUserSetupComplete() && !keyguardOn
                if (complete && canLaunchApp && data != null
                        && data != null && mModifierShortcutManager.launchApplication(data)) {
                        && mModifierShortcutManager.launchApplication(data)) {
                    dismissKeyboardShortcutsMenu();
                    dismissKeyboardShortcutsMenu();
                }
                }
                return true;
                return true;
+40 −0
Original line number Original line Diff line number Diff line
@@ -771,4 +771,44 @@ public class KeyGestureEventTests extends ShortcutKeyTestBase {
                        KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_DO_NOT_DISTURB));
                        KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_DO_NOT_DISTURB));
        mPhoneWindowManager.assertZenMode(Settings.Global.ZEN_MODE_OFF);
        mPhoneWindowManager.assertZenMode(Settings.Global.ZEN_MODE_OFF);
    }
    }

    @Test
    public void testLaunchSettingsAndSearchDoesntOpenAnything_withKeyguardOn() {
        mPhoneWindowManager.overrideKeyguardOn(true);

        sendKeyGestureEventComplete(KeyGestureEvent.KEY_GESTURE_TYPE_LAUNCH_SYSTEM_SETTINGS);
        sendKeyGestureEventComplete(KeyGestureEvent.KEY_GESTURE_TYPE_LAUNCH_SEARCH);

        mPhoneWindowManager.assertNoActivityLaunched();
    }

    @Test
    public void testLaunchSettingsAndSearchDoesntOpenAnything_withUserSetupIncomplete() {
        mPhoneWindowManager.overrideIsUserSetupComplete(false);

        sendKeyGestureEventComplete(KeyGestureEvent.KEY_GESTURE_TYPE_LAUNCH_SYSTEM_SETTINGS);
        sendKeyGestureEventComplete(KeyGestureEvent.KEY_GESTURE_TYPE_LAUNCH_SEARCH);

        mPhoneWindowManager.assertNoActivityLaunched();
    }

    @Test
    public void testLaunchAssistantDoesntWork_withKeyguardOn() {
        mPhoneWindowManager.overrideKeyguardOn(true);

        sendKeyGestureEventComplete(KeyGestureEvent.KEY_GESTURE_TYPE_LAUNCH_ASSISTANT);
        sendKeyGestureEventComplete(KeyGestureEvent.KEY_GESTURE_TYPE_LAUNCH_VOICE_ASSISTANT);

        mPhoneWindowManager.assertSearchManagerDoesntLaunchAssist();
    }

    @Test
    public void testLaunchAssistantDoesntWork_withUserSetupIncomplete() {
        mPhoneWindowManager.overrideIsUserSetupComplete(false);

        sendKeyGestureEventComplete(KeyGestureEvent.KEY_GESTURE_TYPE_LAUNCH_ASSISTANT);
        sendKeyGestureEventComplete(KeyGestureEvent.KEY_GESTURE_TYPE_LAUNCH_VOICE_ASSISTANT);

        mPhoneWindowManager.assertSearchManagerDoesntLaunchAssist();
    }
}
}
+15 −0
Original line number Original line Diff line number Diff line
@@ -571,6 +571,10 @@ class TestPhoneWindowManager {
        doNothing().when(mPhoneWindowManager).launchHomeFromHotKey(anyInt());
        doNothing().when(mPhoneWindowManager).launchHomeFromHotKey(anyInt());
    }
    }


    void overrideKeyguardOn(boolean isKeyguardOn) {
        doReturn(isKeyguardOn).when(mPhoneWindowManager).keyguardOn();
    }

    void overrideIsUserSetupComplete(boolean isCompleted) {
    void overrideIsUserSetupComplete(boolean isCompleted) {
        doReturn(isCompleted).when(mPhoneWindowManager).isUserSetupComplete();
        doReturn(isCompleted).when(mPhoneWindowManager).isUserSetupComplete();
    }
    }
@@ -733,6 +737,11 @@ class TestPhoneWindowManager {
        verify(mSearchManager).launchAssist(any());
        verify(mSearchManager).launchAssist(any());
    }
    }


    void assertSearchManagerDoesntLaunchAssist() {
        mTestLooper.dispatchAll();
        verify(mSearchManager, never()).launchAssist(any());
    }

    void assertLaunchSystemSettings() {
    void assertLaunchSystemSettings() {
        mTestLooper.dispatchAll();
        mTestLooper.dispatchAll();
        ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
        ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
@@ -937,4 +946,10 @@ class TestPhoneWindowManager {
        verify(mInputManagerInternal)
        verify(mInputManagerInternal)
                .handleKeyGestureInKeyGestureController(anyInt(), any(), anyInt(), eq(gestureType));
                .handleKeyGestureInKeyGestureController(anyInt(), any(), anyInt(), eq(gestureType));
    }
    }

    void assertNoActivityLaunched() {
        mTestLooper.dispatchAll();
        verify(mContext, never()).startActivityAsUser(any(), any(), any());
        verify(mContext, never()).startActivityAsUser(any(), any());
    }
}
}