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

Commit 346a631a authored by Hongguang Chen's avatar Hongguang Chen
Browse files

Add new long press power button behavior that goes to sleep (doze)

Bug: 414308701
Test: atest PhoneWindowManagerTests
Test: atest PowerKeyGestureTests
Test: manually verified on device
Flag: NONE. This new behavior doesn't touch existing code.
Change-Id: I3e2f0ecd18a1c2df605bcac9b254108f1998e431
parent 2fad0af9
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
@@ -306,6 +306,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
@@ -1492,6 +1493,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;
        }
    }

@@ -6458,6 +6465,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;
@@ -509,6 +510,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();