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

Commit c0b10cfe authored by Yeabkal Wubshit's avatar Yeabkal Wubshit
Browse files

Add deviceGoingToSleep param to WindowWakeUpPolicy delegate

We are adding this param to allow wake up delegates to decide
to potentially ignore a wake up event that they think happened
unintentionally. An example is a Wear OS device, where an unintended
touch of the rotary input during a palm-screen-off event may negate
the screen-off sequence.

Bug: 400790919
Test: atest WindowWakeUpPolicyTests
Flag: EXEMPT param addition only, trivial
Change-Id: I4ef3c8a3178b3bf7c4e2b60b9fe41ba32cbd0102
parent 3b3ec4a9
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -5966,7 +5966,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            long whenNanos, int policyFlags) {
        if ((policyFlags & FLAG_WAKE) != 0) {
            if (mWindowWakeUpPolicy.wakeUpFromMotion(displayId, whenNanos / 1000000, source,
                    action == MotionEvent.ACTION_DOWN)) {
                    action == MotionEvent.ACTION_DOWN, mDeviceGoingToSleep)) {
                // Woke up. Pass motion events to user.
                return ACTION_PASS_TO_USER;
            }
@@ -5981,7 +5981,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        // wake up in this case.
        if (isTheaterModeEnabled() && (policyFlags & FLAG_WAKE) != 0) {
            if (mWindowWakeUpPolicy.wakeUpFromMotion(displayId, whenNanos / 1000000, source,
                    action == MotionEvent.ACTION_DOWN)) {
                    action == MotionEvent.ACTION_DOWN, mDeviceGoingToSleep)) {
                // Woke up. Pass motion events to user.
                return ACTION_PASS_TO_USER;
            }
+8 −2
Original line number Diff line number Diff line
@@ -149,16 +149,22 @@ class WindowWakeUpPolicy {
     * @param displayId the id of the display to wake.
     * @param eventTime the timestamp of the event in {@link SystemClock#uptimeMillis()}.
     * @param isDown {@code true} if the event's action is {@link MotionEvent#ACTION_DOWN}.
     * @param deviceGoingToSleep {@code true} if the device is in the middle of going to sleep. This
     *      will be {@code false} if the device is currently fully awake or is fully asleep
     *      (i.e. not trying to go to sleep)
     * @return {@code true} if the policy allows the requested wake up and the request has been
     *      executed; {@code false} otherwise.
     */
    boolean wakeUpFromMotion(int displayId, long eventTime, int source, boolean isDown) {
    boolean wakeUpFromMotion(
            int displayId, long eventTime, int source, boolean isDown,
            boolean deviceGoingToSleep) {
        if (!canWakeUp(mAllowTheaterModeWakeFromMotion)) {
            if (DEBUG) Slog.d(TAG, "Unable to wake up from motion.");
            return false;
        }
        if (mInputWakeUpDelegate != null
                && mInputWakeUpDelegate.wakeUpFromMotion(eventTime, source, isDown)) {
                && mInputWakeUpDelegate.wakeUpFromMotion(
                        eventTime, source, isDown, deviceGoingToSleep)) {
            return true;
        }
        if (perDisplayWakeByTouch()) {
+5 −1
Original line number Diff line number Diff line
@@ -52,10 +52,14 @@ public interface WindowWakeUpPolicyInternal {
         * @param eventTime the timestamp of the event in {@link SystemClock#uptimeMillis()}.
         * @param source the {@link android.view.InputDevice} source that caused the event.
         * @param isDown {@code true} if the event's action is {@link MotionEvent#ACTION_DOWN}.
         * @param deviceGoingToSleep {@code true} if the device is in the middle of going to sleep.
         *      This will be {@code false} if the device is currently fully awake or is fully
         *      asleep (i.e. not trying to go to sleep)
         * @return {@code true} if the delegate handled the wake up. {@code false} if the delegate
         *      decided not to handle the wake up. The policy will execute the wake up in this case.
         */
        boolean wakeUpFromMotion(long eventTime, int source, boolean isDown);
        boolean wakeUpFromMotion(
                long eventTime, int source, boolean isDown, boolean deviceGoingToSleep);
    }

    /**
+15 −11
Original line number Diff line number Diff line
@@ -145,8 +145,8 @@ public final class WindowWakeUpPolicyTests {
        // Verify the policy wake up call succeeds because of the call on the delegate, and not
        // because of a PowerManager wake up.
        assertThat(mPolicy.wakeUpFromMotion(
                mDefaultDisplay.getDisplayId(), 200, SOURCE_TOUCHSCREEN, true)).isTrue();
        verify(mInputWakeUpDelegate).wakeUpFromMotion(200, SOURCE_TOUCHSCREEN, true);
                mDefaultDisplay.getDisplayId(), 200, SOURCE_TOUCHSCREEN, true, false)).isTrue();
        verify(mInputWakeUpDelegate).wakeUpFromMotion(200, SOURCE_TOUCHSCREEN, true, false);
        verifyNoPowerManagerWakeUp();

        setDelegatedMotionWakeUpResult(false);
@@ -154,8 +154,8 @@ public final class WindowWakeUpPolicyTests {
        // Verify the policy wake up call succeeds because of the PowerManager wake up, since the
        // delegate would not handle the wake up request.
        assertThat(mPolicy.wakeUpFromMotion(
                mDefaultDisplay.getDisplayId(), 300, SOURCE_ROTARY_ENCODER, false)).isTrue();
        verify(mInputWakeUpDelegate).wakeUpFromMotion(300, SOURCE_ROTARY_ENCODER, false);
                mDefaultDisplay.getDisplayId(), 300, SOURCE_ROTARY_ENCODER, false, false)).isTrue();
        verify(mInputWakeUpDelegate).wakeUpFromMotion(300, SOURCE_ROTARY_ENCODER, false, false);
        verify(mPowerManager).wakeUp(300, WAKE_REASON_WAKE_MOTION, "android.policy:MOTION");
    }

@@ -214,8 +214,9 @@ public final class WindowWakeUpPolicyTests {

        // Check that the wake up does not happen because the theater mode policy check fails.
        assertThat(mPolicy.wakeUpFromMotion(
                mDefaultDisplay.getDisplayId(), 200, SOURCE_TOUCHSCREEN, true)).isFalse();
        verify(mInputWakeUpDelegate, never()).wakeUpFromMotion(anyLong(), anyInt(), anyBoolean());
                mDefaultDisplay.getDisplayId(), 200, SOURCE_TOUCHSCREEN, true, false)).isFalse();
        verify(mInputWakeUpDelegate, never())
                .wakeUpFromMotion(anyLong(), anyInt(), anyBoolean(), anyBoolean());
    }

    @Test
@@ -227,7 +228,8 @@ public final class WindowWakeUpPolicyTests {
        setBooleanRes(config_allowTheaterModeWakeFromMotion, false);
        mPolicy = new WindowWakeUpPolicy(mContextSpy, mClock);

        mPolicy.wakeUpFromMotion(mDefaultDisplay.getDisplayId(), 200L, SOURCE_TOUCHSCREEN, true);
        mPolicy.wakeUpFromMotion(
                mDefaultDisplay.getDisplayId(), 200L, SOURCE_TOUCHSCREEN, true, false);

        verify(mPowerManager).wakeUp(200L, WAKE_REASON_WAKE_MOTION, "android.policy:MOTION");
    }
@@ -237,7 +239,7 @@ public final class WindowWakeUpPolicyTests {
    public void testWakeUpFromMotion() {
        runPowerManagerUpChecks(
                () -> mPolicy.wakeUpFromMotion(mDefaultDisplay.getDisplayId(),
                        mClock.uptimeMillis(), SOURCE_TOUCHSCREEN, true),
                        mClock.uptimeMillis(), SOURCE_TOUCHSCREEN, true, false),
                config_allowTheaterModeWakeFromMotion,
                WAKE_REASON_WAKE_MOTION,
                "android.policy:MOTION");
@@ -251,7 +253,8 @@ public final class WindowWakeUpPolicyTests {
        mPolicy = new WindowWakeUpPolicy(mContextSpy, mClock);

        boolean displayWokeUp = mPolicy.wakeUpFromMotion(
                displayId, mClock.uptimeMillis(), SOURCE_TOUCHSCREEN, /* isDown= */ true);
                displayId, mClock.uptimeMillis(), SOURCE_TOUCHSCREEN, /* isDown= */ true,
                /* deviceGoingToSleep= */ false);

        // Verify that display is woken up
        assertThat(displayWokeUp).isTrue();
@@ -267,7 +270,8 @@ public final class WindowWakeUpPolicyTests {
        mPolicy = new WindowWakeUpPolicy(mContextSpy, mClock);

        boolean displayWokeUp = mPolicy.wakeUpFromMotion(
                displayId, mClock.uptimeMillis(), SOURCE_TOUCHSCREEN, /* isDown= */ true);
                displayId, mClock.uptimeMillis(), SOURCE_TOUCHSCREEN, /* isDown= */ true,
                /* deviceGoingToSleep= */ false);

        // Verify that power is woken up and display isn't woken up individually
        assertThat(displayWokeUp).isTrue();
@@ -442,7 +446,7 @@ public final class WindowWakeUpPolicyTests {
    }

    private void setDelegatedMotionWakeUpResult(boolean result) {
        when(mInputWakeUpDelegate.wakeUpFromMotion(anyLong(), anyInt(), anyBoolean()))
        when(mInputWakeUpDelegate.wakeUpFromMotion(anyLong(), anyInt(), anyBoolean(), anyBoolean()))
                .thenReturn(result);
    }