From 9e1bf7c7cca8df2173a5fe1c52ac16011051af89 Mon Sep 17 00:00:00 2001 From: Robert Carr Date: Thu, 31 May 2018 15:39:07 -0700 Subject: [PATCH] Don't "notifyAppStopping" when going to sleep. The WindowManager interprets notifyAppStopping as a signal that the app surface will be destroyed, but in the visible stopped states of going to sleep this may not necessarily be true. notifyAppStopping was only recently introduced for the purposes of handling detach children which isn't needed when turning the screen off. Simply not executing it when turning the screen off should be safe, if a little confusing. Test: Manual of bug + mess around with SV apps a bunch Bug: 80491358 Bug: 72921025 Change-Id: I7dd5d1e144e12ecfba038e15f84f9ae7c02aadd2 --- .../java/com/android/server/am/ActivityRecord.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/services/core/java/com/android/server/am/ActivityRecord.java b/services/core/java/com/android/server/am/ActivityRecord.java index d456f6255426b..220b35ebc6e9f 100644 --- a/services/core/java/com/android/server/am/ActivityRecord.java +++ b/services/core/java/com/android/server/am/ActivityRecord.java @@ -1405,6 +1405,11 @@ final class ActivityRecord extends ConfigurationContainer implements AppWindowCo newIntents.add(intent); } + final boolean isSleeping() { + final ActivityStack stack = getStack(); + return stack != null ? stack.shouldSleepActivities() : service.isSleepingLocked(); + } + /** * Deliver a new Intent to an existing activity, so that its onNewIntent() * method will be called at the proper time. @@ -1415,9 +1420,7 @@ final class ActivityRecord extends ConfigurationContainer implements AppWindowCo intent, getUriPermissionsLocked(), userId); final ReferrerIntent rintent = new ReferrerIntent(intent, referrer); boolean unsent = true; - final ActivityStack stack = getStack(); - final boolean isTopActivityWhileSleeping = isTopRunningActivity() - && (stack != null ? stack.shouldSleepActivities() : service.isSleepingLocked()); + final boolean isTopActivityWhileSleeping = isTopRunningActivity() && isSleeping(); // We want to immediately deliver the intent to the activity if: // - It is currently resumed or paused. i.e. it is currently visible to the user and we want @@ -1645,7 +1648,10 @@ final class ActivityRecord extends ConfigurationContainer implements AppWindowCo parent.onActivityStateChanged(this, state, reason); } - if (state == STOPPING) { + // The WindowManager interprets the app stopping signal as + // an indication that the Surface will eventually be destroyed. + // This however isn't necessarily true if we are going to sleep. + if (state == STOPPING && !isSleeping()) { mWindowContainerController.notifyAppStopping(); } }