diff --git a/services/core/java/com/android/server/wm/ActivityRecord.java b/services/core/java/com/android/server/wm/ActivityRecord.java index ad281247a7198..d1f4d3c072c99 100644 --- a/services/core/java/com/android/server/wm/ActivityRecord.java +++ b/services/core/java/com/android/server/wm/ActivityRecord.java @@ -2606,7 +2606,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A Slog.v(TAG_USER_LEAVING, "finish() => pause with userLeaving=false"); } stack.startPausingLocked(false /* userLeaving */, false /* uiSleeping */, - null /* resuming */); + null /* resuming */, "finish"); } if (endTask) { @@ -4770,14 +4770,14 @@ 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 */); + // Do nothing if currently in the process of resuming the activity. Otherwise, + // starting to pause it since it is not visible. + if (!mSetToSleep) { break; } + getRootTask().startPausingLocked(mStackSupervisor.mUserLeaving, + false /* uiSleeping */, null /* resuming */, "makeInvisible"); + // fall through case INITIALIZING: case PAUSING: case PAUSED: diff --git a/services/core/java/com/android/server/wm/EventLogTags.logtags b/services/core/java/com/android/server/wm/EventLogTags.logtags index aab901ebcdb69..6c346090578f0 100644 --- a/services/core/java/com/android/server/wm/EventLogTags.logtags +++ b/services/core/java/com/android/server/wm/EventLogTags.logtags @@ -26,7 +26,7 @@ option java_package com.android.server.wm # The Activity Manager failed to pause the given activity. 30012 wm_failed_to_pause (User|1|5),(Token|1|5),(Wanting to pause|3),(Currently pausing|3) # Attempting to pause the current activity -30013 wm_pause_activity (User|1|5),(Token|1|5),(Component Name|3),(User Leaving|3) +30013 wm_pause_activity (User|1|5),(Token|1|5),(Component Name|3),(User Leaving|3),(Reason|3) # Application process has been started # An activity is being destroyed: diff --git a/services/core/java/com/android/server/wm/Task.java b/services/core/java/com/android/server/wm/Task.java index 63f363e1cc149..d5fcc8d437c10 100644 --- a/services/core/java/com/android/server/wm/Task.java +++ b/services/core/java/com/android/server/wm/Task.java @@ -1102,7 +1102,7 @@ class Task extends WindowContainer { && toStack.topRunningActivity() != null) { // Pause the resumed activity on the target stack while re-parenting task on top of it. toStack.startPausingLocked(false /* userLeaving */, false /* uiSleeping */, - null /* resuming */); + null /* resuming */, "reparent"); } final int toStackWindowingMode = toStack.getWindowingMode(); @@ -5340,7 +5340,8 @@ class Task extends WindowContainer { if (DEBUG_USER_LEAVING) Slog.v(TAG_USER_LEAVING, "Sleep => pause with userLeaving=false"); - startPausingLocked(false /* userLeaving */, true /* uiSleeping */, null /* resuming */); + startPausingLocked(false /* userLeaving */, true /* uiSleeping */, null /* resuming */, + "sleep"); shouldSleep = false ; } else if (mPausingActivity != null) { // Still waiting for something to pause; can't sleep yet. @@ -5400,11 +5401,12 @@ class Task extends WindowContainer { * @param resuming The activity we are currently trying to resume or null if this is not being * called as part of resuming the top activity, so we shouldn't try to instigate * a resume here if not null. + * @param reason The reason of pausing the activity. * @return Returns true if an activity now is in the PAUSING state, and we are waiting for * it to tell us when it is done. */ final boolean startPausingLocked(boolean userLeaving, boolean uiSleeping, - ActivityRecord resuming) { + ActivityRecord resuming, String reason) { if (mPausingActivity != null) { Slog.wtf(TAG, "Going to pause when pause is already pending for " + mPausingActivity + " state=" + mPausingActivity.getState()); @@ -5471,7 +5473,7 @@ class Task extends WindowContainer { if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Enqueueing pending pause: " + prev); try { EventLogTags.writeWmPauseActivity(prev.mUserId, System.identityHashCode(prev), - prev.shortComponentName, "userLeaving=" + userLeaving); + prev.shortComponentName, "userLeaving=" + userLeaving, reason); mAtmService.getLifecycleManager().scheduleTransaction(prev.app.getThread(), prev.appToken, PauseActivityItem.obtain(prev.finishing, userLeaving, @@ -5995,7 +5997,8 @@ class Task extends WindowContainer { if (mResumedActivity != null) { if (DEBUG_STATES) Slog.d(TAG_STATES, "resumeTopActivityLocked: Pausing " + mResumedActivity); - pausing |= startPausingLocked(userLeaving, false /* uiSleeping */, next); + pausing |= startPausingLocked(userLeaving, false /* uiSleeping */, next, + "resumeTopActivityInnerLocked"); } if (pausing) { if (DEBUG_SWITCH || DEBUG_STATES) Slog.v(TAG_STATES, diff --git a/services/core/java/com/android/server/wm/TaskDisplayArea.java b/services/core/java/com/android/server/wm/TaskDisplayArea.java index 890f56e50bacc..0d77d1c2cd89f 100644 --- a/services/core/java/com/android/server/wm/TaskDisplayArea.java +++ b/services/core/java/com/android/server/wm/TaskDisplayArea.java @@ -1219,7 +1219,7 @@ final class TaskDisplayArea extends DisplayArea { + " mResumedActivity=" + resumedActivity); } someActivityPaused |= stack.startPausingLocked(userLeaving, false /* uiSleeping*/, - resuming); + resuming, "pauseBackStacks"); } } return someActivityPaused; diff --git a/services/core/java/com/android/server/wm/WindowProcessController.java b/services/core/java/com/android/server/wm/WindowProcessController.java index 8bf0820c7dad3..67d230aae0fb6 100644 --- a/services/core/java/com/android/server/wm/WindowProcessController.java +++ b/services/core/java/com/android/server/wm/WindowProcessController.java @@ -768,7 +768,7 @@ public class WindowProcessController extends ConfigurationContainer