From e37b84d19e4eda05911d6b7c075c9ec3e22142cf Mon Sep 17 00:00:00 2001 From: Hongwei Wang Date: Thu, 28 May 2020 11:37:36 -0700 Subject: [PATCH] Set isInPictureInPictureMode earlier Per https://developer.android.com/guide/topics/ui/picture-in-picture After app requests enterPictureInPictureMode and receives onPause callback, it will continue playback if isInPictureInPictureMode is true. However, with ag/11273366, isInPictureInPictureMode will now return true after the new configuration is dispatched to app, which happens after onPause. This may cause app, following the guidance, to cease playback in PiP mode. Fixes this by setting the internal mIsInPictureInPictureMode earlier right in enterPictureInPictureMode Video: http://go/recall/-/aaaaaabFQoRHlzixHdtY/fVRqG7UWoKkQQhFxPkzcUt Bug: 156924033 Test: manually enter PiP from Twitch Change-Id: I8e0865076fcb756cfa5db39901f460ab5ad69b99 --- core/java/android/app/Activity.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/core/java/android/app/Activity.java b/core/java/android/app/Activity.java index af5fafbc93d4c..87fc8fe392f01 100644 --- a/core/java/android/app/Activity.java +++ b/core/java/android/app/Activity.java @@ -2838,7 +2838,13 @@ public class Activity extends ContextThemeWrapper throw new IllegalStateException("Activity must be resumed to enter" + " picture-in-picture"); } - return ActivityTaskManager.getService().enterPictureInPictureMode(mToken, params); + // Set mIsInPictureInPictureMode earlier and don't wait for + // onPictureInPictureModeChanged callback here. This is to ensure that + // isInPictureInPictureMode returns true in the following onPause callback. + // See https://developer.android.com/guide/topics/ui/picture-in-picture for guidance. + mIsInPictureInPictureMode = ActivityTaskManager.getService().enterPictureInPictureMode( + mToken, params); + return mIsInPictureInPictureMode; } catch (RemoteException e) { return false; }