diff options
| author | 2025-03-12 12:57:37 -0700 | |
|---|---|---|
| committer | 2025-03-12 17:17:47 -0700 | |
| commit | c0b10cfe5d549799fb227ba4e85d588f06d35ba6 (patch) | |
| tree | 075abbe6b87d0085a0a3c5b7130c32375fbf9add | |
| parent | 3b3ec4a9c704f22cc610b826defb3048b2e075b0 (diff) | |
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
4 files changed, 30 insertions, 16 deletions
diff --git a/services/core/java/com/android/server/policy/PhoneWindowManager.java b/services/core/java/com/android/server/policy/PhoneWindowManager.java index 3230e891db55..38d458767015 100644 --- a/services/core/java/com/android/server/policy/PhoneWindowManager.java +++ b/services/core/java/com/android/server/policy/PhoneWindowManager.java @@ -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; } diff --git a/services/core/java/com/android/server/policy/WindowWakeUpPolicy.java b/services/core/java/com/android/server/policy/WindowWakeUpPolicy.java index 04dbd1fea5d6..0b5ec6e4f495 100644 --- a/services/core/java/com/android/server/policy/WindowWakeUpPolicy.java +++ b/services/core/java/com/android/server/policy/WindowWakeUpPolicy.java @@ -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()) { diff --git a/services/core/java/com/android/server/policy/WindowWakeUpPolicyInternal.java b/services/core/java/com/android/server/policy/WindowWakeUpPolicyInternal.java index 66a003577e9a..962b5a7010ea 100644 --- a/services/core/java/com/android/server/policy/WindowWakeUpPolicyInternal.java +++ b/services/core/java/com/android/server/policy/WindowWakeUpPolicyInternal.java @@ -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); } /** diff --git a/services/tests/wmtests/src/com/android/server/policy/WindowWakeUpPolicyTests.java b/services/tests/wmtests/src/com/android/server/policy/WindowWakeUpPolicyTests.java index 9e59bced01f1..4ecf6abf7860 100644 --- a/services/tests/wmtests/src/com/android/server/policy/WindowWakeUpPolicyTests.java +++ b/services/tests/wmtests/src/com/android/server/policy/WindowWakeUpPolicyTests.java @@ -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); } |