From 47df3d96a123b667804325d52258108e9ae5c053 Mon Sep 17 00:00:00 2001 From: Louis Chang Date: Mon, 5 Jun 2023 10:04:10 +0000 Subject: [PATCH] Avoid unexpected turning screen on when top activity finishes The ActivityRecord#mCurrentLaunchCanTurnScreenOn is true while the Activity was started and created. However, another activity may immediately started afterward. Once the top activity finishes while the display is off, the display was unexpected turn on since the next top activity is able to turn screen on. Reset the can-turn-screen-on state of the last started activity when starting a new activity. Cherry picked I2c2d15e1a1a68d583d42dde69aef2f596cd064b5 to master due to b/286408867. Code was merged via `-s ours` and is missing even though the sha exists on the target branch. Cherry pick is required to bring in the code. Manually remove the "Merged in" directive to allow for downstream propagation. Bug: 270827073 Bug: 241961202 Test: verified on sample app (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:2af9efb27589bb1a233a5db1d4da303fd09c32e8) Change-Id: I9b257a432004fa00caf0c2e3750ba76ab3382fc1 --- .../core/java/com/android/server/wm/ActivityStarter.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/services/core/java/com/android/server/wm/ActivityStarter.java b/services/core/java/com/android/server/wm/ActivityStarter.java index 534072c6bb87c..dce3a38f1d90c 100644 --- a/services/core/java/com/android/server/wm/ActivityStarter.java +++ b/services/core/java/com/android/server/wm/ActivityStarter.java @@ -897,6 +897,11 @@ class ActivityStarter { } mLastStartReason = request.reason; mLastStartActivityTimeMs = System.currentTimeMillis(); + // Reset the ActivityRecord#mCurrentLaunchCanTurnScreenOn state of last start activity in + // case the state is not yet consumed during rapid activity launch. + if (mLastStartActivityRecord != null) { + mLastStartActivityRecord.setCurrentLaunchCanTurnScreenOn(false); + } mLastStartActivityRecord = null; final IApplicationThread caller = request.caller;