Switch play FGS exemption to use custom action instead of commands

Custom actions are more naturally associated with a user intent
than commands (that are meant to be used for automated inter-app
communication without user interaction).

PiperOrigin-RevId: 705797057
This commit is contained in:
tonihei 2024-12-13 01:41:20 -08:00 committed by Copybara-Service
parent 83b5eb0040
commit 3bce3af1a3
2 changed files with 9 additions and 3 deletions

View File

@ -417,8 +417,9 @@ import org.checkerframework.checker.nullness.qual.NonNull;
if (Util.SDK_INT >= 31 && platformController != null) { if (Util.SDK_INT >= 31 && platformController != null) {
// Ensure the platform session gets allow-listed to start a foreground service after receiving // Ensure the platform session gets allow-listed to start a foreground service after receiving
// the play command. // the play command.
platformController.sendCommand( platformController
MediaConstants.SESSION_COMMAND_MEDIA3_PLAY_REQUEST, /* args= */ null, /* cb= */ null); .getTransportControls()
.sendCustomAction(MediaConstants.SESSION_COMMAND_MEDIA3_PLAY_REQUEST, /* args= */ null);
} }
dispatchRemoteSessionTaskWithPlayerCommand( dispatchRemoteSessionTaskWithPlayerCommand(

View File

@ -281,7 +281,8 @@ import org.checkerframework.checker.initialization.qual.Initialized;
public void onCommand(String commandName, @Nullable Bundle args, @Nullable ResultReceiver cb) { public void onCommand(String commandName, @Nullable Bundle args, @Nullable ResultReceiver cb) {
checkStateNotNull(commandName); checkStateNotNull(commandName);
if (commandName.equals(MediaConstants.SESSION_COMMAND_MEDIA3_PLAY_REQUEST)) { if (commandName.equals(MediaConstants.SESSION_COMMAND_MEDIA3_PLAY_REQUEST)) {
// Ignore, no need to handle this command here. // Only applicable to controllers on Media3 1.5, where this command was sent via sendCommand
// instead of sendCustomAction. No need to handle this command here.
return; return;
} }
if (commandName.equals(MediaConstants.SESSION_COMMAND_REQUEST_SESSION3_TOKEN) && cb != null) { if (commandName.equals(MediaConstants.SESSION_COMMAND_REQUEST_SESSION3_TOKEN) && cb != null) {
@ -305,6 +306,10 @@ import org.checkerframework.checker.initialization.qual.Initialized;
@Override @Override
public void onCustomAction(String action, @Nullable Bundle args) { public void onCustomAction(String action, @Nullable Bundle args) {
if (action.equals(MediaConstants.SESSION_COMMAND_MEDIA3_PLAY_REQUEST)) {
// Ignore, no need to handle the custom action.
return;
}
SessionCommand command = new SessionCommand(action, /* extras= */ Bundle.EMPTY); SessionCommand command = new SessionCommand(action, /* extras= */ Bundle.EMPTY);
dispatchSessionTaskWithSessionCommand( dispatchSessionTaskWithSessionCommand(
command, command,