Merge changes I52152223,I49db5cab into oc-dr1-dev
am: fc596b1cf6
Change-Id: I53f12c1d0854d56ad0e700bf028fd68b47917e1f
This commit is contained in:
@@ -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 */);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user