From f2aeed46da2be41262036a2b7ab26150d4e1b5a8 Mon Sep 17 00:00:00 2001 From: Ben Lin Date: Thu, 17 Oct 2019 15:53:07 -0700 Subject: [PATCH] Check for PIPable activities after moving task to back. When we move a task to the back, there is a possibility that the previous stack won't be put into a paused state if it's in a multi-resume environment (e.g. freeform windows). If that's the case and the activity is eligible for PIP, we pause the task so that PIP mode can be triggered via onUserLeaveHint. We pause the task instead of using ATM#requestPictureInPictureMode because the latter is not able to handle the two scenarios we want to support on minimize: 1. If the app wants to enter PIP -> enter PIP 2. If the app doesn't want to -> put the app to stopped Using requestPIPMode works for 1. but won't put the app to stopped when the app decides not to enter PIP. Pausing the task explicitely does handle both cases correctly, as it triggers onUserLeaveHint and only puts the app to stopped if the app did not enter PIP mode. Also, don't call on resumeFocusedStacksTopActivities when in a multi-resume environment. There is nothing to resume, and the focused stack is already updated when moving the task back. Bug: 142680249 Bug: 141156846 Test: In an environment with freeform window, try: 1) Minimizing a PIPable activity - sees it enters PIP 2) With two windows in freeform, try switching focus and see they perform as expected 3) Minimizing an activity that supports PIP but doesn't want to enter PIP on onUserLeaveHint - it gets STOPPED Change-Id: I59811a56a954d32458d741b8f44ccd37f5729094 --- .../java/com/android/server/wm/ActivityRecord.java | 13 ++++++++++--- .../java/com/android/server/wm/ActivityStack.java | 4 ++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/services/core/java/com/android/server/wm/ActivityRecord.java b/services/core/java/com/android/server/wm/ActivityRecord.java index e79b804f76f9c..4e7e5ef038c00 100644 --- a/services/core/java/com/android/server/wm/ActivityRecord.java +++ b/services/core/java/com/android/server/wm/ActivityRecord.java @@ -4607,7 +4607,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A // the current contract for "auto-Pip" is that the app should enter it before onPause // returns. Just need to confirm this reasoning makes sense. final boolean deferHidingClient = canEnterPictureInPicture - && !isState(STOPPING, STOPPED, PAUSED); + && !isState(STARTED, STOPPING, STOPPED, PAUSED); setDeferHidingClient(deferHidingClient); setVisibility(false); @@ -4618,9 +4618,16 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A // activity is hidden supportsEnterPipOnTaskSwitch = false; break; - - case INITIALIZING: 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 */); + break; + } + case INITIALIZING: case PAUSING: case PAUSED: case STARTED: diff --git a/services/core/java/com/android/server/wm/ActivityStack.java b/services/core/java/com/android/server/wm/ActivityStack.java index 8bf46bc7c2e84..fcadf66e870e1 100644 --- a/services/core/java/com/android/server/wm/ActivityStack.java +++ b/services/core/java/com/android/server/wm/ActivityStack.java @@ -2951,9 +2951,9 @@ class ActivityStack extends Task { mRootWindowContainer.ensureVisibilityAndConfig(null /* starting */, getDisplay().mDisplayId, false /* markFrozenIfConfigChanged */, false /* deferResume */); + } else { + mRootWindowContainer.resumeFocusedStacksTopActivities(); } - - mRootWindowContainer.resumeFocusedStacksTopActivities(); return true; }