Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,9 @@
`MediaSessionCompat` could dispatch an unsupported `onPrepareFrom*`
callback instead of `onPlayFrom*`, or dispatch `onPlay()` without
re-initializing the requested media item.
* Fix `NullPointerException` in legacy `MediaBrowser` when receiving a
custom command response
([#3432](https://github.com/androidx/media/issues/3432)).
* UI:
* Add `TrackSelectionState` and `TrackSelectionParametersState` classes
and their corresponding Composable state remember functions to the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,15 +402,19 @@ public void onProgressUpdate(String action, Bundle extras, Bundle data) {
@Override
public void onResult(
String action, @Nullable Bundle extras, @Nullable Bundle resultData) {
Bundle mergedBundles = new Bundle(extras);
mergedBundles.putAll(resultData);
Bundle mergedBundles = extras == null ? new Bundle() : new Bundle(extras);
if (resultData != null) {
mergedBundles.putAll(resultData);
}
settable.set(new SessionResult(SessionResult.RESULT_SUCCESS, mergedBundles));
}

@Override
public void onError(String action, @Nullable Bundle extras, @Nullable Bundle data) {
Bundle mergedBundles = new Bundle(extras);
mergedBundles.putAll(data);
Bundle mergedBundles = extras == null ? new Bundle() : new Bundle(extras);
if (data != null) {
mergedBundles.putAll(data);
}
settable.set(new SessionResult(SessionResult.RESULT_ERROR_UNKNOWN, mergedBundles));
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,52 @@ public void onFailure(Throwable t) {}
assertThat(sessionResultRef.get().extras.getString("key-1")).isEqualTo("error-from-service");
}

@Test
public void sendCustomCommand_nullResultFromService_returnsSuccessWithArgs() throws Exception {
remoteService.setProxyForTest(TEST_SEND_CUSTOM_COMMAND);
MediaBrowser browser = createBrowser(/* listener= */ null);
Bundle args = new Bundle();
args.putBoolean("request_null_result", true);

SessionResult sessionResult =
threadTestRule
.getHandler()
.postAndSync(
() ->
browser.sendCustomCommand(
new SessionCommand(
MediaConstants.CUSTOM_COMMAND_DOWNLOAD, /* extras= */ Bundle.EMPTY),
args))
.get(TIMEOUT_MS, MILLISECONDS);

assertThat(sessionResult.resultCode).isEqualTo(SessionResult.RESULT_SUCCESS);
assertThat(sessionResult.extras.getBoolean("request_null_result")).isTrue();
}

@Test
public void sendCustomCommand_nullErrorFromService_returnsErrorWithArgs() throws Exception {
remoteService.setProxyForTest(TEST_SEND_CUSTOM_COMMAND);
MediaBrowser browser = createBrowser(/* listener= */ null);
Bundle args = new Bundle();
args.putBoolean("request_error", true);
args.putBoolean("request_null_result", true);

SessionResult sessionResult =
threadTestRule
.getHandler()
.postAndSync(
() ->
browser.sendCustomCommand(
new SessionCommand(
MediaConstants.CUSTOM_COMMAND_DOWNLOAD, /* extras= */ Bundle.EMPTY),
args))
.get(TIMEOUT_MS, MILLISECONDS);

assertThat(sessionResult.resultCode).isEqualTo(SessionResult.RESULT_ERROR_UNKNOWN);
assertThat(sessionResult.extras.getBoolean("request_error")).isTrue();
assertThat(sessionResult.extras.getBoolean("request_null_result")).isTrue();
}

@Test
public void sendCustomCommand_successFromSession_correctAsyncResultReceivalConfirmed()
throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -623,9 +623,19 @@ public BrowserRoot onGetRoot(

@Override
public void onCustomAction(String action, Bundle extras, Result<Bundle> result) {
if (extras != null
&& extras.getBoolean("request_null_result", /* defaultValue= */ false)) {
if (extras.getBoolean("request_error", /* defaultValue= */ false)) {
result.sendError(/* extras= */ null);
} else {
result.sendResult(/* result= */ null);
}
return;
}
Bundle resultBundle = new Bundle();
if (action.equals(MediaConstants.CUSTOM_COMMAND_DOWNLOAD)) {
if (extras.getBoolean("request_error", /* defaultValue= */ false)) {
if (extras != null
&& extras.getBoolean("request_error", /* defaultValue= */ false)) {
resultBundle.putString("key-1", "error-from-service");
result.sendError(resultBundle);
} else {
Expand Down