Commit ebe7ece1 by christosts

Session: advertise legacy FLAG_HANDLES_QUEUE_COMMANDS

This change includes 3 things:
- when the legacy media session is created, FLAG_HANDLES_QUEUE_COMMANDS
  is advertised if the player has the COMMAND_CHANGE_MEDIA_ITEMS
  available.
- when the player changes its available commands, a new
  PlaybackStateCompat is sent to the remote media controller to
  advertise the updated PlyabackStateCompat actions.
- when the player changes its available commands, the legacy media
  session flags are sent accoridingly: FLAG_HANDLES_QUEUE_COMMANDS is
  set only if the COMMAND_CHANGE_MEDIA_ITEMS is available.

#minor-release

PiperOrigin-RevId: 506605905
parent a817bd42
...@@ -126,6 +126,7 @@ import org.checkerframework.checker.nullness.compatqual.NullableType; ...@@ -126,6 +126,7 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
private volatile long connectionTimeoutMs; private volatile long connectionTimeoutMs;
@Nullable private FutureCallback<Bitmap> pendingBitmapLoadCallback; @Nullable private FutureCallback<Bitmap> pendingBitmapLoadCallback;
private int sessionFlags;
public MediaSessionLegacyStub( public MediaSessionLegacyStub(
MediaSessionImpl session, MediaSessionImpl session,
...@@ -161,8 +162,6 @@ import org.checkerframework.checker.nullness.compatqual.NullableType; ...@@ -161,8 +162,6 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
sessionCompat.setSessionActivity(sessionActivity); sessionCompat.setSessionActivity(sessionActivity);
} }
sessionCompat.setFlags(MediaSessionCompat.FLAG_HANDLES_QUEUE_COMMANDS);
@SuppressWarnings("nullness:assignment") @SuppressWarnings("nullness:assignment")
@Initialized @Initialized
MediaSessionLegacyStub thisRef = this; MediaSessionLegacyStub thisRef = this;
...@@ -254,6 +253,17 @@ import org.checkerframework.checker.nullness.compatqual.NullableType; ...@@ -254,6 +253,17 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
return false; return false;
} }
private void maybeUpdateFlags(PlayerWrapper playerWrapper) {
int newFlags =
playerWrapper.isCommandAvailable(COMMAND_CHANGE_MEDIA_ITEMS)
? MediaSessionCompat.FLAG_HANDLES_QUEUE_COMMANDS
: 0;
if (sessionFlags != newFlags) {
sessionFlags = newFlags;
sessionCompat.setFlags(sessionFlags);
}
}
private void handleMediaPlayPauseOnHandler(RemoteUserInfo remoteUserInfo) { private void handleMediaPlayPauseOnHandler(RemoteUserInfo remoteUserInfo) {
mediaPlayPauseKeyHandler.clearPendingMediaPlayPauseKey(); mediaPlayPauseKeyHandler.clearPendingMediaPlayPauseKey();
dispatchSessionTaskWithPlayerCommand( dispatchSessionTaskWithPlayerCommand(
...@@ -895,6 +905,13 @@ import org.checkerframework.checker.nullness.compatqual.NullableType; ...@@ -895,6 +905,13 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
} }
@Override @Override
public void onAvailableCommandsChangedFromPlayer(int seq, Player.Commands availableCommands) {
PlayerWrapper playerWrapper = sessionImpl.getPlayerWrapper();
maybeUpdateFlags(playerWrapper);
sessionImpl.getSessionCompat().setPlaybackState(playerWrapper.createPlaybackStateCompat());
}
@Override
public void onDisconnected(int seq) throws RemoteException { public void onDisconnected(int seq) throws RemoteException {
// Calling MediaSessionCompat#release() is already done in release(). // Calling MediaSessionCompat#release() is already done in release().
} }
...@@ -936,6 +953,7 @@ import org.checkerframework.checker.nullness.compatqual.NullableType; ...@@ -936,6 +953,7 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
onDeviceInfoChanged(seq, newPlayerWrapper.getDeviceInfo()); onDeviceInfoChanged(seq, newPlayerWrapper.getDeviceInfo());
// Rest of changes are all notified via PlaybackStateCompat. // Rest of changes are all notified via PlaybackStateCompat.
maybeUpdateFlags(newPlayerWrapper);
@Nullable MediaItem newMediaItem = newPlayerWrapper.getCurrentMediaItemWithCommandCheck(); @Nullable MediaItem newMediaItem = newPlayerWrapper.getCurrentMediaItemWithCommandCheck();
if (oldPlayerWrapper == null if (oldPlayerWrapper == null
|| !Util.areEqual(oldPlayerWrapper.getCurrentMediaItemWithCommandCheck(), newMediaItem)) { || !Util.areEqual(oldPlayerWrapper.getCurrentMediaItemWithCommandCheck(), newMediaItem)) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment