diff options
| author | 2017-08-09 18:52:42 +0000 | |
|---|---|---|
| committer | 2017-08-09 18:52:42 +0000 | |
| commit | fc596b1cf69cd740337392b7bc8384302d3b58b0 (patch) | |
| tree | 16e344dd7cc3099893a539b8f5983366e11fa70c | |
| parent | 54ad8c1f1571ecf6acaf0513752b9fa397044215 (diff) | |
| parent | 9a189d1514c48ec1b0b6684aa7fb93066b4f5872 (diff) | |
Merge changes I52152223,I49db5cab into oc-dr1-dev
* changes:
Ensure that we register the media session listener for the current user.
Fix issue with PiP callbacks not being handled for secondary users.
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/pip/phone/PipManager.java | 12 | ||||
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/pip/phone/PipMediaController.java | 34 |
2 files changed, 29 insertions, 17 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 6c6054cb6d12..b3f992db1b6b 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 */); } }; 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 62ec09be2f51..b3a0794f742f 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<MediaController> controllers) { + resolveActiveMediaController(controllers); + } + }; + private ArrayList<ActionListener> 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)); } /** @@ -201,6 +216,15 @@ public class PipMediaController { } /** + * 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. */ private void resolveActiveMediaController(List<MediaController> controllers) { |