Create explicit key for testing 'notification controller'
Previously these tests were setting the test-only `KEY_CONTROLLER` bundle value to the prod value of `MediaController.KEY_MEDIA_NOTIFICATION_CONTROLLER_FLAG`, which is a bit confusing because this is intended to be used as a `Bundle` **key** (for a boolean value), and not a value itself. Instead this CL creates a test-only value that can be used by `RemoteMediaSession` and related test-only friends to indicate that something (e.g. error or extras) should only be set on the notification controller. This CL also changes the logic in `MediaSessionProviderService` to avoid needing to special-case checking for this controller key. PiperOrigin-RevId: 641939283
This commit is contained in:
parent
04ca79182a
commit
24462dd77b
@ -37,5 +37,11 @@ public class MediaSessionConstants {
|
||||
public static final String KEY_CONTROLLER = "controllerKey";
|
||||
public static final String KEY_COMMAND_GET_TASKS_UNAVAILABLE = "commandGetTasksUnavailable";
|
||||
|
||||
/**
|
||||
* The key used to identify the notification controller in test-only methods like {@code
|
||||
* RemoteMediaSession#setSessionExtras(String controllerKey, Bundle extras)}.
|
||||
*/
|
||||
public static final String NOTIFICATION_CONTROLLER_KEY = "notificationController";
|
||||
|
||||
private MediaSessionConstants() {}
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ import static android.support.v4.media.MediaMetadataCompat.METADATA_KEY_MEDIA_ID
|
||||
import static android.support.v4.media.MediaMetadataCompat.METADATA_KEY_USER_RATING;
|
||||
import static androidx.media3.common.Player.STATE_ENDED;
|
||||
import static androidx.media3.common.Player.STATE_READY;
|
||||
import static androidx.media3.test.session.common.MediaSessionConstants.NOTIFICATION_CONTROLLER_KEY;
|
||||
import static androidx.media3.test.session.common.MediaSessionConstants.TEST_MEDIA_CONTROLLER_COMPAT_CALLBACK_WITH_MEDIA_SESSION_TEST;
|
||||
import static androidx.media3.test.session.common.MediaSessionConstants.TEST_SET_SHOW_PLAY_BUTTON_IF_SUPPRESSED_TO_FALSE;
|
||||
import static androidx.media3.test.session.common.TestUtils.LONG_TIMEOUT_MS;
|
||||
@ -1082,7 +1083,7 @@ public class MediaControllerCompatCallbackWithMediaSessionTest {
|
||||
errorBundle.putInt("intKey", 99);
|
||||
|
||||
session.sendError(
|
||||
/* controllerKey= */ MediaController.KEY_MEDIA_NOTIFICATION_CONTROLLER_FLAG,
|
||||
/* controllerKey= */ NOTIFICATION_CONTROLLER_KEY,
|
||||
/* errorCode= */ 1,
|
||||
R.string.authentication_required,
|
||||
errorBundle);
|
||||
|
@ -60,6 +60,7 @@ import static androidx.media3.test.session.common.CommonConstants.KEY_VOLUME;
|
||||
import static androidx.media3.test.session.common.MediaSessionConstants.KEY_AVAILABLE_SESSION_COMMANDS;
|
||||
import static androidx.media3.test.session.common.MediaSessionConstants.KEY_COMMAND_GET_TASKS_UNAVAILABLE;
|
||||
import static androidx.media3.test.session.common.MediaSessionConstants.KEY_CONTROLLER;
|
||||
import static androidx.media3.test.session.common.MediaSessionConstants.NOTIFICATION_CONTROLLER_KEY;
|
||||
import static androidx.media3.test.session.common.MediaSessionConstants.TEST_COMMAND_GET_TRACKS;
|
||||
import static androidx.media3.test.session.common.MediaSessionConstants.TEST_CONTROLLER_LISTENER_SESSION_REJECTS;
|
||||
import static androidx.media3.test.session.common.MediaSessionConstants.TEST_GET_CUSTOM_LAYOUT;
|
||||
@ -332,7 +333,7 @@ public class MediaSessionProviderService extends Service {
|
||||
Bundle connectionHints = new Bundle();
|
||||
connectionHints.putBoolean(
|
||||
MediaController.KEY_MEDIA_NOTIFICATION_CONTROLLER_FLAG, true);
|
||||
//noinspection unused
|
||||
connectionHints.putString(KEY_CONTROLLER, NOTIFICATION_CONTROLLER_KEY);
|
||||
ListenableFuture<MediaController> unusedFuture =
|
||||
new MediaController.Builder(getApplicationContext(), session.getToken())
|
||||
.setListener(
|
||||
@ -570,8 +571,8 @@ public class MediaSessionProviderService extends Service {
|
||||
() -> {
|
||||
MediaSession mediaSession = sessionMap.get(sessionId);
|
||||
for (ControllerInfo controllerInfo : mediaSession.getConnectedControllers()) {
|
||||
if (controllerInfo
|
||||
.getConnectionHints()
|
||||
Bundle connectionHints = controllerInfo.getConnectionHints();
|
||||
if (connectionHints
|
||||
.getString(KEY_CONTROLLER, /* defaultValue= */ "")
|
||||
.equals(controllerKey)) {
|
||||
mediaSession.setSessionExtras(controllerInfo, extras);
|
||||
@ -595,14 +596,6 @@ public class MediaSessionProviderService extends Service {
|
||||
if (TextUtils.isEmpty(controllerKey)) {
|
||||
// Broadcast to all connected Media3 controller.
|
||||
mediaSession.sendError(errorCode, errorMessageResId, errorExtras);
|
||||
} else if (controllerKey.equals(
|
||||
MediaController.KEY_MEDIA_NOTIFICATION_CONTROLLER_FLAG)) {
|
||||
// Send to media notification controller.
|
||||
mediaSession.sendError(
|
||||
checkNotNull(mediaSession.getMediaNotificationControllerInfo()),
|
||||
errorCode,
|
||||
errorMessageResId,
|
||||
errorExtras);
|
||||
} else {
|
||||
// Send to controller with the given controller key in connection hints.
|
||||
for (ControllerInfo controllerInfo : mediaSession.getConnectedControllers()) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user