From 3dd436a5383b2986240cb41cebf2956b2a1ca120 Mon Sep 17 00:00:00 2001 From: Lucas Silva Date: Thu, 12 May 2022 11:07:57 -0400 Subject: [PATCH] Do not wake the device if an activity starts while dozing. Currently, if the dream wakes without any user activity, the screen will turn off. We therefore swap to using requestAwakenInternal, which will keep the screen on by triggering a user activity. CTS tests disable dozing, so this is hard to verify in dream cts tests. Looks like we don't have good coverage for doze service. Bug: 231521765 Test: manually on device Test: atest DreamManagerServiceTestsi Change-Id: I23ac50fded164377ef8b5ea28fb030f4312bbb3d --- .../android/server/dreams/DreamManagerService.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/services/core/java/com/android/server/dreams/DreamManagerService.java b/services/core/java/com/android/server/dreams/DreamManagerService.java index 4e1d899b26a67..63c5456c972be 100644 --- a/services/core/java/com/android/server/dreams/DreamManagerService.java +++ b/services/core/java/com/android/server/dreams/DreamManagerService.java @@ -124,8 +124,10 @@ public final class DreamManagerService extends SystemService { final boolean activityAllowed = activityType == ACTIVITY_TYPE_HOME || activityType == ACTIVITY_TYPE_DREAM || activityType == ACTIVITY_TYPE_ASSISTANT; - if (mCurrentDreamToken != null && !mCurrentDreamIsWaking && !activityAllowed) { - stopDreamInternal(false, "activity starting: " + activityInfo.name); + if (mCurrentDreamToken != null && !mCurrentDreamIsWaking + && !mCurrentDreamIsDozing && !activityAllowed) { + requestAwakenInternal( + "stopping dream due to activity start: " + activityInfo.name); } } }; @@ -229,13 +231,13 @@ public final class DreamManagerService extends SystemService { mPowerManager.nap(time); } - private void requestAwakenInternal() { + private void requestAwakenInternal(String reason) { // Treat an explicit request to awaken as user activity so that the // device doesn't immediately go to sleep if the timeout expired, // for example when being undocked. long time = SystemClock.uptimeMillis(); mPowerManager.userActivity(time, false /*noChangeLights*/); - stopDreamInternal(false /*immediate*/, "request awaken"); + stopDreamInternal(false /*immediate*/, reason); } private void finishSelfInternal(IBinder token, boolean immediate) { @@ -715,7 +717,7 @@ public final class DreamManagerService extends SystemService { final long ident = Binder.clearCallingIdentity(); try { - requestAwakenInternal(); + requestAwakenInternal("request awaken"); } finally { Binder.restoreCallingIdentity(ident); }