From 8a4f26cc56a584dc9951afdce912d8851c0607e6 Mon Sep 17 00:00:00 2001 From: Winson Chung Date: Mon, 7 Aug 2017 15:28:44 -0700 Subject: [PATCH 1/2] Fix issue with PiP callbacks not being handled for secondary users. - With ag/1767862, we do not persist PiP across users, so there is no need for additional logic in SystemUI to dedupe these calls. Since PiP is managed in the primary user's SystemUI process, this logic was prevening the relaunching of the activity. Bug: 64316002 Test: Launch PiP from a secondary user, restart the activity and ensure that it is brought to fullscreen. Change-Id: I49db5cab9f0be7366390d1e36edcaf4d6b05717a --- .../com/android/systemui/pip/phone/PipManager.java | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/pip/phone/PipManager.java b/packages/SystemUI/src/com/android/systemui/pip/phone/PipManager.java index 6c6054cb6d128..b3f992db1b6bc 100644 --- a/packages/SystemUI/src/com/android/systemui/pip/phone/PipManager.java +++ b/packages/SystemUI/src/com/android/systemui/pip/phone/PipManager.java @@ -71,10 +71,6 @@ public class PipManager implements BasePipManager { TaskStackListener mTaskStackListener = new TaskStackListener() { @Override public void onActivityPinned(String packageName, int taskId) { - if (!checkCurrentUserId(mContext, false /* debug */)) { - return; - } - mTouchHandler.onActivityPinned(); mMediaController.onActivityPinned(); mMenuController.onActivityPinned(); @@ -86,10 +82,6 @@ public class PipManager implements BasePipManager { @Override public void onActivityUnpinned() { - if (!checkCurrentUserId(mContext, false /* debug */)) { - return; - } - ComponentName topPipActivity = PipUtils.getTopPinnedActivity(mContext, mActivityManager); mMenuController.onActivityUnpinned(topPipActivity); @@ -116,10 +108,6 @@ public class PipManager implements BasePipManager { @Override public void onPinnedActivityRestartAttempt(boolean clearedTask) { - if (!checkCurrentUserId(mContext, false /* debug */)) { - return; - } - mTouchHandler.getMotionHelper().expandPip(clearedTask /* skipAnimation */); } }; From 9a189d1514c48ec1b0b6684aa7fb93066b4f5872 Mon Sep 17 00:00:00 2001 From: Winson Chung Date: Tue, 8 Aug 2017 12:58:11 -0700 Subject: [PATCH 2/2] Ensure that we register the media session listener for the current user. - Use the per-user calls when fetching/responding to media session events otherwise it will fallback to using the process user. Bug: 64315017 Test: Launch secondary user, enter PiP with media session and no custom actions. Ensure the media session buttons show. Change-Id: I52152223e91f0256ac4135616694e2a293947e3e --- .../pip/phone/PipMediaController.java | 34 ++++++++++++++++--- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/pip/phone/PipMediaController.java b/packages/SystemUI/src/com/android/systemui/pip/phone/PipMediaController.java index 62ec09be2f514..b3a0794f742fa 100644 --- a/packages/SystemUI/src/com/android/systemui/pip/phone/PipMediaController.java +++ b/packages/SystemUI/src/com/android/systemui/pip/phone/PipMediaController.java @@ -26,14 +26,18 @@ import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; +import android.graphics.drawable.Drawable; import android.graphics.drawable.Icon; import android.media.session.MediaController; import android.media.session.MediaSession; import android.media.session.MediaSessionManager; +import android.media.session.MediaSessionManager.OnActiveSessionsChangedListener; import android.media.session.PlaybackState; import android.os.UserHandle; +import com.android.systemui.Dependency; import com.android.systemui.R; +import com.android.systemui.statusbar.policy.UserInfoController; import java.util.ArrayList; import java.util.Collections; @@ -88,13 +92,21 @@ public class PipMediaController { } }; - private MediaController.Callback mPlaybackChangedListener = new MediaController.Callback() { + private final MediaController.Callback mPlaybackChangedListener = new MediaController.Callback() { @Override public void onPlaybackStateChanged(PlaybackState state) { notifyActionsChanged(); } }; + private final MediaSessionManager.OnActiveSessionsChangedListener mSessionsChangedListener = + new OnActiveSessionsChangedListener() { + @Override + public void onActiveSessionsChanged(List controllers) { + resolveActiveMediaController(controllers); + } + }; + private ArrayList mListeners = new ArrayList<>(); public PipMediaController(Context context, IActivityManager activityManager) { @@ -110,9 +122,11 @@ public class PipMediaController { createMediaActions(); mMediaSessionManager = (MediaSessionManager) context.getSystemService(Context.MEDIA_SESSION_SERVICE); - mMediaSessionManager.addOnActiveSessionsChangedListener(controllers -> { - resolveActiveMediaController(controllers); - }, null); + + // The media session listener needs to be re-registered when switching users + UserInfoController userInfoController = Dependency.get(UserInfoController.class); + userInfoController.addCallback((String name, Drawable picture, String userAccount) -> + registerSessionListenerForCurrentUser()); } /** @@ -120,7 +134,8 @@ public class PipMediaController { */ public void onActivityPinned() { // Once we enter PiP, try to find the active media controller for the top most activity - resolveActiveMediaController(mMediaSessionManager.getActiveSessions(null)); + resolveActiveMediaController(mMediaSessionManager.getActiveSessionsForUser(null, + UserHandle.USER_CURRENT)); } /** @@ -200,6 +215,15 @@ public class PipMediaController { FLAG_UPDATE_CURRENT)); } + /** + * Re-registers the session listener for the current user. + */ + private void registerSessionListenerForCurrentUser() { + mMediaSessionManager.removeOnActiveSessionsChangedListener(mSessionsChangedListener); + mMediaSessionManager.addOnActiveSessionsChangedListener(mSessionsChangedListener, null, + UserHandle.USER_CURRENT, null); + } + /** * Tries to find and set the active media controller for the top PiP activity. */