From 3043c92bab7fccef447ba97d391c52f531fcab88 Mon Sep 17 00:00:00 2001 From: Louis Chang Date: Mon, 11 Apr 2022 10:22:47 +0800 Subject: [PATCH] Allow resumed activity to turn-screen-on only when being started In order to prevent activity being resumed while top activity finished and unexpectedly wake up device. Bug: 227538244 Test: atest ActivityVisibilityTests#testTurnScreenOnActivity Change-Id: I7b06d3ab4d90e1c3f9b86e8553bb6e6d9823a2c2 --- .../java/com/android/server/wm/ActivityRecord.java | 5 ++++- .../com/android/server/wm/ActivityStartController.java | 10 ++++++++++ .../java/com/android/server/wm/ActivityStarter.java | 6 ++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/wm/ActivityRecord.java b/services/core/java/com/android/server/wm/ActivityRecord.java index 314864e2f917f..12249188a78c3 100644 --- a/services/core/java/com/android/server/wm/ActivityRecord.java +++ b/services/core/java/com/android/server/wm/ActivityRecord.java @@ -5460,7 +5460,10 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A wasStopped, this); mAppStopped = false; // Allow the window to turn the screen on once the app is resumed again. - setCurrentLaunchCanTurnScreenOn(true); + if (mAtmService.getActivityStartController().isInExecution()) { + setCurrentLaunchCanTurnScreenOn(true); + } + if (!wasStopped) { destroySurfaces(true /*cleanupOnResume*/); } diff --git a/services/core/java/com/android/server/wm/ActivityStartController.java b/services/core/java/com/android/server/wm/ActivityStartController.java index 72408b67de410..9771b347cfb14 100644 --- a/services/core/java/com/android/server/wm/ActivityStartController.java +++ b/services/core/java/com/android/server/wm/ActivityStartController.java @@ -90,6 +90,8 @@ public class ActivityStartController { boolean mCheckedForSetup = false; + private boolean mInExecution = false; + /** * TODO(b/64750076): Capture information necessary for dump and * {@link #postStartActivityProcessingForLastStarter} rather than keeping the entire object @@ -123,7 +125,15 @@ public class ActivityStartController { return mFactory.obtain().setIntent(intent).setReason(reason); } + void onExecutionStarted(ActivityStarter starter) { + mInExecution = true; + } + + boolean isInExecution() { + return mInExecution; + } void onExecutionComplete(ActivityStarter starter) { + mInExecution = false; if (mLastStarter == null) { mLastStarter = mFactory.obtain(); } diff --git a/services/core/java/com/android/server/wm/ActivityStarter.java b/services/core/java/com/android/server/wm/ActivityStarter.java index eb912d4c2747b..28c09d39bdb8f 100644 --- a/services/core/java/com/android/server/wm/ActivityStarter.java +++ b/services/core/java/com/android/server/wm/ActivityStarter.java @@ -633,6 +633,8 @@ class ActivityStarter { */ int execute() { try { + onExecutionStarted(); + // Refuse possible leaked file descriptors if (mRequest.intent != null && mRequest.intent.hasFileDescriptors()) { throw new IllegalArgumentException("File descriptors passed in Intent"); @@ -1247,6 +1249,10 @@ class ActivityStarter { mController.onExecutionComplete(this); } + private void onExecutionStarted() { + mController.onExecutionStarted(this); + } + private boolean isHomeApp(int uid, @Nullable String packageName) { if (mService.mHomeProcess != null) { // Fast check