Skip to content

Commit d3668bf

Browse files
marcbaechingericbaker
authored andcommitted
Don't enforce available commands when connected to legacy session app
This change removes the check for available commands in `sendCustomCommand` of `MediaBrowserImplLegacy.java`. This is in parity with the behavior of legacy controllers/browsers when connected to a legacy app. The test `sendCustomCommandWithMediaItem_commandButtonNotAvailable_permissionDenied` was updated to reflect this change. PiperOrigin-RevId: 780580897 (cherry picked from commit 3174a48)
1 parent 70241e5 commit d3668bf

File tree

3 files changed

+13
-20
lines changed

3 files changed

+13
-20
lines changed

RELEASENOTES.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22

33
## 1.8
44

5+
### 1.8.0-rc02 (2025-07-23)
6+
7+
This release includes the following changes since the
8+
[1.8.0-rc01 release](#180-rc01-2025-07-16):
9+
10+
* Session:
11+
* Remove check for available commands when sending custom commands to a
12+
legacy `MediaBrowserServiceCompat`. This is in parity with the behavior
13+
of legacy controllers/browsers when connected to a legacy app.
14+
515
### 1.8.0-rc01 (2025-07-16)
616

717
This release includes the following changes since the

libraries/session/src/main/java/androidx/media3/session/MediaBrowserImplLegacy.java

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
import java.util.ArrayList;
4444
import java.util.HashMap;
4545
import java.util.List;
46-
import java.util.Objects;
4746
import org.checkerframework.checker.initialization.qual.UnderInitialization;
4847

4948
/** Implementation of MediaBrowser with the {@link MediaBrowserCompat} for legacy support. */
@@ -374,9 +373,7 @@ public void onError(String query, @Nullable Bundle extrasSent) {
374373
@Override
375374
public ListenableFuture<SessionResult> sendCustomCommand(SessionCommand command, Bundle args) {
376375
MediaBrowserCompat browserCompat = getBrowserCompat();
377-
if (browserCompat != null
378-
&& (instance.isSessionCommandAvailable(command)
379-
|| isContainedInCommandButtonsForMediaItems(command))) {
376+
if (browserCompat != null) {
380377
SettableFuture<SessionResult> settable = SettableFuture.create();
381378
browserCompat.sendCustomAction(
382379
command.customAction,
@@ -402,19 +399,6 @@ public void onError(String action, @Nullable Bundle extras, @Nullable Bundle dat
402399
return Futures.immediateFuture(new SessionResult(SessionResult.RESULT_ERROR_PERMISSION_DENIED));
403400
}
404401

405-
// Using this method as a proxy whether an browser is allowed to send a custom action can be
406-
// justified because a MediaBrowserCompat can declare the custom browse actions in onGetRoot()
407-
// specifically for each browser that connects. This is different to Media3 where the command
408-
// buttons for media items are declared on the session level, and are constraint by the available
409-
// session commands granted individually to a controller/browser in onConnect.
410-
private boolean isContainedInCommandButtonsForMediaItems(SessionCommand command) {
411-
if (command.commandCode != SessionCommand.COMMAND_CODE_CUSTOM) {
412-
return false;
413-
}
414-
CommandButton commandButton = commandButtonsForMediaItems.get(command.customAction);
415-
return commandButton != null && Objects.equals(commandButton.sessionCommand, command);
416-
}
417-
418402
private MediaBrowserCompat getBrowserCompat(LibraryParams extras) {
419403
return browserCompats.get(extras);
420404
}

libraries/test_session_current/src/androidTest/java/androidx/media3/session/MediaBrowserListenerWithMediaBrowserServiceCompatTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,7 @@ public void sendCustomCommandWithMediaItem_mediaItemIdConvertedCorrectly() throw
283283
}
284284

285285
@Test
286-
public void sendCustomCommandWithMediaItem_commandButtonNotAvailable_permissionDenied()
287-
throws Exception {
286+
public void sendCustomCommandWithMediaItem_commandButtonNotAvailable_succeeds() throws Exception {
288287
remoteService.setProxyForTest(TEST_MEDIA_ITEMS_WITH_BROWSE_ACTIONS);
289288
MediaBrowser mediaBrowser =
290289
createBrowser(
@@ -312,7 +311,7 @@ public void sendCustomCommandWithMediaItem_commandButtonNotAvailable_permissionD
312311
/* args= */ Bundle.EMPTY))
313312
.get(TIMEOUT_MS, MILLISECONDS);
314313

315-
assertThat(sessionResult.resultCode).isEqualTo(SessionResult.RESULT_ERROR_PERMISSION_DENIED);
314+
assertThat(sessionResult.resultCode).isEqualTo(SessionResult.RESULT_SUCCESS);
316315
}
317316

318317
@Test

0 commit comments

Comments
 (0)