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

Commit f1e8a993 authored by Hongguang Chen's avatar Hongguang Chen Committed by Android (Google) Code Review
Browse files

Merge "Add new long press power button behavior that goes to sleep (doze)" into main

parents f34a6928 346a631a
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -1159,6 +1159,7 @@
            3 - Power off (without confirmation)
            4 - Go to voice assist
            5 - Go to assistant (Settings.Secure.ASSISTANT)
            6 - Go to sleep (doze)
    -->
    <integer name="config_longPressOnPowerBehavior">5</integer>

+9 −0
Original line number Diff line number Diff line
@@ -317,6 +317,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3;
    static final int LONG_PRESS_POWER_GO_TO_VOICE_ASSIST = 4;
    static final int LONG_PRESS_POWER_ASSISTANT = 5; // Settings.Secure.ASSISTANT
    static final int LONG_PRESS_POWER_GO_TO_SLEEP = 6;

    // must match: config_veryLongPresOnPowerBehavior in config.xml
    // The config value can be overridden using Settings.Global.POWER_BUTTON_VERY_LONG_PRESS
@@ -1488,6 +1489,12 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                launchAssistAction(null, powerKeyDeviceId, eventTime,
                        AssistUtils.INVOCATION_TYPE_POWER_BUTTON_LONG_PRESS);
                break;
            case LONG_PRESS_POWER_GO_TO_SLEEP:
                mPowerKeyHandled = true;
                performHapticFeedback(HapticFeedbackConstants.LONG_PRESS_POWER_BUTTON,
                        "Power - Long Press - Go To Sleep (Doze)");
                sleepDefaultDisplayFromPowerButton(eventTime, 0);
                break;
        }
    }

@@ -6562,6 +6569,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                return "LONG_PRESS_POWER_GO_TO_VOICE_ASSIST";
            case LONG_PRESS_POWER_ASSISTANT:
                return "LONG_PRESS_POWER_ASSISTANT";
            case LONG_PRESS_POWER_GO_TO_SLEEP:
                return "LONG_PRESS_POWER_GO_TO_SLEEP";
            default:
                return Integer.toString(behavior);
        }
+11 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import static com.android.cts.input.inputeventmatchers.InputEventMatchersKt.with
import static com.android.cts.input.inputeventmatchers.InputEventMatchersKt.withKeyFlags;
import static com.android.server.policy.PhoneWindowManager.LONG_PRESS_POWER_ASSISTANT;
import static com.android.server.policy.PhoneWindowManager.LONG_PRESS_POWER_GLOBAL_ACTIONS;
import static com.android.server.policy.PhoneWindowManager.LONG_PRESS_POWER_GO_TO_SLEEP;
import static com.android.server.policy.PhoneWindowManager.POWER_MULTI_PRESS_TIMEOUT_MILLIS;
import static com.android.server.policy.PhoneWindowManager.SHORT_PRESS_POWER_DREAM_OR_SLEEP;
import static com.android.server.policy.PhoneWindowManager.SHORT_PRESS_POWER_GO_TO_SLEEP;
@@ -152,6 +153,16 @@ public class PowerKeyGestureTests extends ShortcutKeyTestBase {
        mPhoneWindowManager.assertShowGlobalActionsCalled();
    }

    /**
     * Power long press to go to sleep (doze).
     */
    @Test
    public void testPowerLongPressGoToSleep() {
        mPhoneWindowManager.overrideLongPressOnPower(LONG_PRESS_POWER_GO_TO_SLEEP);
        sendKey(KEYCODE_POWER, SingleKeyGestureDetector.sDefaultLongPressTimeout);
        mPhoneWindowManager.assertPowerSleep();
    }

    /**
     * Ignore power press if combination key already triggered.
     */
+2 −0
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ import static com.android.dx.mockito.inline.extended.ExtendedMockito.times;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.verify;
import static com.android.server.policy.PhoneWindowManager.LONG_PRESS_POWER_ASSISTANT;
import static com.android.server.policy.PhoneWindowManager.LONG_PRESS_POWER_GLOBAL_ACTIONS;
import static com.android.server.policy.PhoneWindowManager.LONG_PRESS_POWER_GO_TO_SLEEP;
import static com.android.server.policy.PhoneWindowManager.LONG_PRESS_POWER_GO_TO_VOICE_ASSIST;
import static com.android.server.policy.PhoneWindowManager.LONG_PRESS_POWER_NOTHING;
import static com.android.server.policy.PhoneWindowManager.LONG_PRESS_POWER_SHUT_OFF;
@@ -497,6 +498,7 @@ class TestPhoneWindowManager {
            case LONG_PRESS_POWER_SHUT_OFF:
            case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
            case LONG_PRESS_POWER_GO_TO_VOICE_ASSIST:
            case LONG_PRESS_POWER_GO_TO_SLEEP:
                break;
            case LONG_PRESS_POWER_ASSISTANT:
                setupAssistForLaunch();