From 9cbadee7412303bb080370647e960917e417075f Mon Sep 17 00:00:00 2001 From: Louis Chang Date: Mon, 5 Oct 2020 11:51:52 +0800 Subject: [PATCH] Pausing the resumed activity when making it invisible A resumed activity was added to stopping activity lists while making it invisible without having state changes. So, the activity won't be resumed if it becomes visible again because the activity is already in the resumed state. mSetToSleep was used in 9b8ece2, which wasn't a reliable way to determine if the activity is resuming because it gets updates until set to sleep. Now we use Task#mInResumeTopActivity instead. Bug: 160435184 Test: atest ActivityRecordTests Change-Id: I3509ba75e3f2d87c863d52c0fb07d69cbfe41764 --- .../java/com/android/server/wm/ActivityRecord.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/services/core/java/com/android/server/wm/ActivityRecord.java b/services/core/java/com/android/server/wm/ActivityRecord.java index 8f2e60ec1f080..746bc0eaff3c7 100644 --- a/services/core/java/com/android/server/wm/ActivityRecord.java +++ b/services/core/java/com/android/server/wm/ActivityRecord.java @@ -4761,14 +4761,15 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A supportsEnterPipOnTaskSwitch = false; break; case RESUMED: - // If the app is capable of entering PIP, we should try pausing it now - // so it can PIP correctly. - if (deferHidingClient) { - getRootTask().startPausingLocked( - mStackSupervisor.mUserLeaving /* userLeaving */, - false /* uiSleeping */, null /* resuming */, "makeInvisible"); + // Do nothing if currently in the process of resuming the activity. Otherwise, + // starting to pause it since it is not visible. + if (task.mInResumeTopActivity + && task.topRunningActivity(true /* focusableOnly */) == this) { break; } + getRootTask().startPausingLocked(mStackSupervisor.mUserLeaving, + false /* uiSleeping */, null /* resuming */, "makeInvisible"); + // fall through case INITIALIZING: case PAUSING: case PAUSED: