Rename nested session callback interfaces to just Callback

This is consistent with other nested callback/listener interfaces like
`Player.Listener`.

PiperOrigin-RevId: 449476261
This commit is contained in:
ibaker 2022-05-18 15:22:48 +01:00 committed by Ian Baker
parent 7c235d2b84
commit c78c1f5891
23 changed files with 141 additions and 154 deletions

View File

@ -92,21 +92,20 @@
* Add RTP reader for VP9 * Add RTP reader for VP9
([#47](https://github.com/androidx/media/pull/64)). ([#47](https://github.com/androidx/media/pull/64)).
* Session: * Session:
* Fix NPE in MediaControllerImplLegacy * Fix NPE in MediaControllerImplLegacy
([#59](https://github.com/androidx/media/pull/59)) ([#59](https://github.com/androidx/media/pull/59)).
* Update session position info on timeline * Update session position info on timeline
change([#51](https://github.com/androidx/media/issues/51)) change([#51](https://github.com/androidx/media/issues/51)).
* Fix NPE in MediaControllerImplBase after releasing controller * Fix NPE in MediaControllerImplBase after releasing controller
([#74](https://github.com/androidx/media/issues/74)) ([#74](https://github.com/androidx/media/issues/74)).
* Rename `MediaSession.MediaSessionCallback` to `MediaSession.Callback`
and `MediaLibrarySession.MediaLibrarySession` to
`MediaLibrarySession.Callback` for consistency with other nested
listener and callbacks like `Player.Listener`.
* Data sources: * Data sources:
* Rename `DummyDataSource` to `PlaceHolderDataSource`. * Rename `DummyDataSource` to `PlaceHolderDataSource`.
* Workaround OkHttp interrupt handling. * Workaround OkHttp interrupt handling.
* Remove deprecated symbols: * Remove deprecated symbols:
* Remove `Player.Listener.onTracksChanged`. Use * Remove `Player.Listener.onTracksChanged`. Use
`Player.Listener.onTracksInfoChanged` instead. `Player.Listener.onTracksInfoChanged` instead.
* Remove `Player.getCurrentTrackGroups` and * Remove `Player.getCurrentTrackGroups` and

View File

@ -43,8 +43,7 @@ class PlaybackService : MediaLibraryService() {
private const val SEARCH_QUERY_PREFIX = "androidx://media3-session/setMediaUri" private const val SEARCH_QUERY_PREFIX = "androidx://media3-session/setMediaUri"
} }
private inner class CustomMediaLibrarySessionCallback : private inner class CustomMediaLibrarySessionCallback : MediaLibrarySession.Callback {
MediaLibrarySession.MediaLibrarySessionCallback {
override fun onGetLibraryRoot( override fun onGetLibraryRoot(
session: MediaLibrarySession, session: MediaLibrarySession,
browser: MediaSession.ControllerInfo, browser: MediaSession.ControllerInfo,

View File

@ -26,7 +26,7 @@ public final class MediaConstants {
* A {@link Uri} scheme used in a media uri. * A {@link Uri} scheme used in a media uri.
* *
* @see MediaController#setMediaUri * @see MediaController#setMediaUri
* @see MediaSession.SessionCallback#onSetMediaUri * @see MediaSession.Callback#onSetMediaUri
*/ */
public static final String MEDIA_URI_SCHEME = "androidx"; public static final String MEDIA_URI_SCHEME = "androidx";
@ -34,7 +34,7 @@ public final class MediaConstants {
* A {@link Uri} authority used in a media uri. * A {@link Uri} authority used in a media uri.
* *
* @see MediaController#setMediaUri * @see MediaController#setMediaUri
* @see MediaSession.SessionCallback#onSetMediaUri * @see MediaSession.Callback#onSetMediaUri
*/ */
public static final String MEDIA_URI_AUTHORITY = "media3-session"; public static final String MEDIA_URI_AUTHORITY = "media3-session";
@ -43,7 +43,7 @@ public final class MediaConstants {
* android.support.v4.media.session.MediaControllerCompat.TransportControls#playFromMediaId}. * android.support.v4.media.session.MediaControllerCompat.TransportControls#playFromMediaId}.
* *
* @see MediaController#setMediaUri * @see MediaController#setMediaUri
* @see MediaSession.SessionCallback#onSetMediaUri * @see MediaSession.Callback#onSetMediaUri
*/ */
public static final String MEDIA_URI_PATH_PLAY_FROM_MEDIA_ID = "playFromMediaId"; public static final String MEDIA_URI_PATH_PLAY_FROM_MEDIA_ID = "playFromMediaId";
@ -52,7 +52,7 @@ public final class MediaConstants {
* android.support.v4.media.session.MediaControllerCompat.TransportControls#playFromSearch}. * android.support.v4.media.session.MediaControllerCompat.TransportControls#playFromSearch}.
* *
* @see MediaController#setMediaUri * @see MediaController#setMediaUri
* @see MediaSession.SessionCallback#onSetMediaUri * @see MediaSession.Callback#onSetMediaUri
*/ */
public static final String MEDIA_URI_PATH_PLAY_FROM_SEARCH = "playFromSearch"; public static final String MEDIA_URI_PATH_PLAY_FROM_SEARCH = "playFromSearch";
@ -61,7 +61,7 @@ public final class MediaConstants {
* android.support.v4.media.session.MediaControllerCompat.TransportControls#prepareFromMediaId}. * android.support.v4.media.session.MediaControllerCompat.TransportControls#prepareFromMediaId}.
* *
* @see MediaController#setMediaUri * @see MediaController#setMediaUri
* @see MediaSession.SessionCallback#onSetMediaUri * @see MediaSession.Callback#onSetMediaUri
*/ */
public static final String MEDIA_URI_PATH_PREPARE_FROM_MEDIA_ID = "prepareFromMediaId"; public static final String MEDIA_URI_PATH_PREPARE_FROM_MEDIA_ID = "prepareFromMediaId";
@ -70,7 +70,7 @@ public final class MediaConstants {
* android.support.v4.media.session.MediaControllerCompat.TransportControls#prepareFromSearch}. * android.support.v4.media.session.MediaControllerCompat.TransportControls#prepareFromSearch}.
* *
* @see MediaController#setMediaUri * @see MediaController#setMediaUri
* @see MediaSession.SessionCallback#onSetMediaUri * @see MediaSession.Callback#onSetMediaUri
*/ */
public static final String MEDIA_URI_PATH_PREPARE_FROM_SEARCH = "prepareFromSearch"; public static final String MEDIA_URI_PATH_PREPARE_FROM_SEARCH = "prepareFromSearch";
@ -95,7 +95,7 @@ public final class MediaConstants {
/** /**
* A {@link Uri} query for media id. * A {@link Uri} query for media id.
* *
* @see MediaSession.SessionCallback#onSetMediaUri * @see MediaSession.Callback#onSetMediaUri
* @see MediaController#setMediaUri * @see MediaController#setMediaUri
*/ */
public static final String MEDIA_URI_QUERY_ID = "id"; public static final String MEDIA_URI_QUERY_ID = "id";
@ -103,7 +103,7 @@ public final class MediaConstants {
/** /**
* A {@link Uri} query for search query. * A {@link Uri} query for search query.
* *
* @see MediaSession.SessionCallback#onSetMediaUri * @see MediaSession.Callback#onSetMediaUri
* @see MediaController#setMediaUri * @see MediaController#setMediaUri
*/ */
public static final String MEDIA_URI_QUERY_QUERY = "query"; public static final String MEDIA_URI_QUERY_QUERY = "query";

View File

@ -73,7 +73,7 @@ import org.checkerframework.checker.initialization.qual.Initialized;
* process like another app but may be in the same process as this controller. It implements {@link * process like another app but may be in the same process as this controller. It implements {@link
* Player} and the player commands are sent to the underlying {@link Player} of the connected {@link * Player} and the player commands are sent to the underlying {@link Player} of the connected {@link
* MediaSession}. It also has session-specific commands that can be handled by {@link * MediaSession}. It also has session-specific commands that can be handled by {@link
* MediaSession.SessionCallback}. * MediaSession.Callback}.
* *
* <p>Topics covered here: * <p>Topics covered here:
* *

View File

@ -94,8 +94,8 @@ public abstract class MediaLibraryService extends MediaSessionService {
* <tr> * <tr>
* <td> * <td>
* {@code 21 <= SDK_INT < 28}<br> * {@code 21 <= SDK_INT < 28}<br>
* for {@link MediaLibrarySessionCallback#onConnect onConnect}<br> * for {@link Callback#onConnect onConnect}<br>
* and {@link MediaLibrarySessionCallback#onGetLibraryRoot onGetLibraryRoot} * and {@link Callback#onGetLibraryRoot onGetLibraryRoot}
* </td> * </td>
* <td>Actual package name via {@link Context#getPackageName()}</td> * <td>Actual package name via {@link Context#getPackageName()}</td>
* <td>Actual UID</td> * <td>Actual UID</td>
@ -103,7 +103,7 @@ public abstract class MediaLibraryService extends MediaSessionService {
* <tr> * <tr>
* <td> * <td>
* {@code 21 <= SDK_INT < 28}<br> * {@code 21 <= SDK_INT < 28}<br>
* for other {@link MediaLibrarySessionCallback callbacks} * for other {@link Callback callbacks}
* </td> * </td>
* <td>{@link RemoteUserInfo#LEGACY_CONTROLLER}</td> * <td>{@link RemoteUserInfo#LEGACY_CONTROLLER}</td>
* <td>Negative value</td> * <td>Negative value</td>
@ -118,13 +118,13 @@ public abstract class MediaLibraryService extends MediaSessionService {
public static final class MediaLibrarySession extends MediaSession { public static final class MediaLibrarySession extends MediaSession {
/** /**
* An extended {@link SessionCallback} for the {@link MediaLibrarySession}. * An extended {@link MediaSession.Callback} for the {@link MediaLibrarySession}.
* *
* <p>When you return {@link LibraryResult} with {@link MediaItem media items}, each item must * <p>When you return {@link LibraryResult} with {@link MediaItem media items}, each item must
* have valid {@link MediaItem#mediaId} and specify {@link MediaMetadata#folderType} and {@link * have valid {@link MediaItem#mediaId} and specify {@link MediaMetadata#folderType} and {@link
* MediaMetadata#isPlayable} in its {@link MediaItem#mediaMetadata}. * MediaMetadata#isPlayable} in its {@link MediaItem#mediaMetadata}.
*/ */
public interface MediaLibrarySessionCallback extends SessionCallback { public interface Callback extends MediaSession.Callback {
@Override @Override
default ConnectionResult onConnect(MediaSession session, ControllerInfo controller) { default ConnectionResult onConnect(MediaSession session, ControllerInfo controller) {
@ -361,8 +361,7 @@ public abstract class MediaLibraryService extends MediaSessionService {
*/ */
// Note: Don't override #setSessionCallback() because the callback can be set by the // Note: Don't override #setSessionCallback() because the callback can be set by the
// constructor. // constructor.
public static final class Builder public static final class Builder extends BuilderBase<MediaLibrarySession, Builder, Callback> {
extends BuilderBase<MediaLibrarySession, Builder, MediaLibrarySessionCallback> {
/** /**
* Creates a builder for {@link MediaLibrarySession}. * Creates a builder for {@link MediaLibrarySession}.
@ -377,8 +376,7 @@ public abstract class MediaLibraryService extends MediaSessionService {
// builder can be only instantiated within the MediaLibraryService. // builder can be only instantiated within the MediaLibraryService.
// Ideally it's better to make it inner class of service to enforce, but it violates API // Ideally it's better to make it inner class of service to enforce, but it violates API
// guideline that Builders should be the inner class of the building target. // guideline that Builders should be the inner class of the building target.
public Builder( public Builder(MediaLibraryService service, Player player, Callback callback) {
MediaLibraryService service, Player player, MediaLibrarySessionCallback callback) {
super(service, player, callback); super(service, player, callback);
} }
@ -451,7 +449,7 @@ public abstract class MediaLibraryService extends MediaSessionService {
String id, String id,
Player player, Player player,
@Nullable PendingIntent sessionActivity, @Nullable PendingIntent sessionActivity,
SessionCallback callback, MediaSession.Callback callback,
MediaItemFiller mediaItemFiller, MediaItemFiller mediaItemFiller,
Bundle tokenExtras) { Bundle tokenExtras) {
super(context, id, player, sessionActivity, callback, mediaItemFiller, tokenExtras); super(context, id, player, sessionActivity, callback, mediaItemFiller, tokenExtras);
@ -463,7 +461,7 @@ public abstract class MediaLibraryService extends MediaSessionService {
String id, String id,
Player player, Player player,
@Nullable PendingIntent sessionActivity, @Nullable PendingIntent sessionActivity,
SessionCallback callback, MediaSession.Callback callback,
MediaItemFiller mediaItemFiller, MediaItemFiller mediaItemFiller,
Bundle tokenExtras) { Bundle tokenExtras) {
return new MediaLibrarySessionImpl( return new MediaLibrarySessionImpl(
@ -472,7 +470,7 @@ public abstract class MediaLibraryService extends MediaSessionService {
id, id,
player, player,
sessionActivity, sessionActivity,
(MediaLibrarySession.MediaLibrarySessionCallback) callback, (Callback) callback,
mediaItemFiller, mediaItemFiller,
tokenExtras); tokenExtras);
} }
@ -483,18 +481,17 @@ public abstract class MediaLibraryService extends MediaSessionService {
} }
/** /**
* Notifies a browser that is {@link MediaLibrarySessionCallback#onSubscribe subscribing} to the * Notifies a browser that is {@link Callback#onSubscribe subscribing} to the change to a
* change to a parent's children. If the browser isn't subscribing to the parent, nothing will * parent's children. If the browser isn't subscribing to the parent, nothing will happen.
* happen.
* *
* <p>This only tells the number of child {@link MediaItem media items}. {@link * <p>This only tells the number of child {@link MediaItem media items}. {@link
* MediaLibrarySessionCallback#onGetChildren} will be called by the browser afterwards to get * Callback#onGetChildren} will be called by the browser afterwards to get the list of {@link
* the list of {@link MediaItem media items}. * MediaItem media items}.
* *
* @param browser The browser to notify. * @param browser The browser to notify.
* @param parentId The non-empty id of the parent with changes to its children. * @param parentId The non-empty id of the parent with changes to its children.
* @param itemCount The number of children. * @param itemCount The number of children.
* @param params The parameters given by {@link MediaLibrarySessionCallback#onSubscribe}. * @param params The parameters given by {@link Callback#onSubscribe}.
*/ */
public void notifyChildrenChanged( public void notifyChildrenChanged(
ControllerInfo browser, ControllerInfo browser,
@ -507,9 +504,9 @@ public abstract class MediaLibraryService extends MediaSessionService {
} }
/** /**
* Notifies all browsers that are {@link MediaLibrarySessionCallback#onSubscribe subscribing} to * Notifies all browsers that are {@link Callback#onSubscribe subscribing} to the parent of the
* the parent of the change to its children regardless of the {@link LibraryParams params} given * change to its children regardless of the {@link LibraryParams params} given by {@link
* by {@link MediaLibrarySessionCallback#onSubscribe}. * Callback#onSubscribe}.
* *
* @param parentId The non-empty id of the parent with changes to its children. * @param parentId The non-empty id of the parent with changes to its children.
* @param itemCount The number of children. * @param itemCount The number of children.
@ -523,14 +520,12 @@ public abstract class MediaLibraryService extends MediaSessionService {
} }
/** /**
* Notifies a browser of a change to the {@link MediaLibrarySessionCallback#onSearch search} * Notifies a browser of a change to the {@link Callback#onSearch search} result.
* result.
* *
* @param browser The browser to notify. * @param browser The browser to notify.
* @param query The non-empty search query given by {@link * @param query The non-empty search query given by {@link Callback#onSearch}.
* MediaLibrarySessionCallback#onSearch}.
* @param itemCount The number of items that have been found in the search. * @param itemCount The number of items that have been found in the search.
* @param params The parameters given by {@link MediaLibrarySessionCallback#onSearch}. * @param params The parameters given by {@link Callback#onSearch}.
*/ */
public void notifySearchResultChanged( public void notifySearchResultChanged(
ControllerInfo browser, ControllerInfo browser,

View File

@ -51,7 +51,7 @@ import java.util.concurrent.Future;
/* package */ class MediaLibrarySessionImpl extends MediaSessionImpl { /* package */ class MediaLibrarySessionImpl extends MediaSessionImpl {
private final MediaLibrarySession instance; private final MediaLibrarySession instance;
private final MediaLibrarySession.MediaLibrarySessionCallback callback; private final MediaLibrarySession.Callback callback;
@GuardedBy("lock") @GuardedBy("lock")
private final ArrayMap<ControllerCb, Set<String>> subscriptions; private final ArrayMap<ControllerCb, Set<String>> subscriptions;
@ -62,7 +62,7 @@ import java.util.concurrent.Future;
String id, String id,
Player player, Player player,
@Nullable PendingIntent sessionActivity, @Nullable PendingIntent sessionActivity,
MediaLibrarySession.MediaLibrarySessionCallback callback, MediaLibrarySession.Callback callback,
MediaSession.MediaItemFiller mediaItemFiller, MediaSession.MediaItemFiller mediaItemFiller,
Bundle tokenExtras) { Bundle tokenExtras) {
super(instance, context, id, player, sessionActivity, callback, mediaItemFiller, tokenExtras); super(instance, context, id, player, sessionActivity, callback, mediaItemFiller, tokenExtras);

View File

@ -109,10 +109,9 @@ import java.util.List;
* *
* <p>The instances are thread safe, but should be used on the thread with a looper. * <p>The instances are thread safe, but should be used on the thread with a looper.
* *
* <p>{@link SessionCallback} methods will be called from the application thread associated with the * <p>{@link Callback} methods will be called from the application thread associated with the {@link
* {@link Player#getApplicationLooper() application looper} of the underlying player. When a new * Player#getApplicationLooper() application looper} of the underlying player. When a new player is
* player is set by {@link #setPlayer}, the player should use the same application looper as the * set by {@link #setPlayer}, the player should use the same application looper as the previous one.
* previous one.
* *
* <p>The session listens to events from the underlying player via {@link Player.Listener} and * <p>The session listens to events from the underlying player via {@link Player.Listener} and
* expects the callback methods to be called from the application thread. If the player violates the * expects the callback methods to be called from the application thread. If the player violates the
@ -231,7 +230,7 @@ public class MediaSession {
* <p>Any incoming requests from the {@link MediaController} will be handled on the application * <p>Any incoming requests from the {@link MediaController} will be handled on the application
* thread of the underlying {@link Player}. * thread of the underlying {@link Player}.
*/ */
public static final class Builder extends BuilderBase<MediaSession, Builder, SessionCallback> { public static final class Builder extends BuilderBase<MediaSession, Builder, Callback> {
/** /**
* Creates a builder for {@link MediaSession}. * Creates a builder for {@link MediaSession}.
@ -241,7 +240,7 @@ public class MediaSession {
* @throws IllegalArgumentException if {@link Player#canAdvertiseSession()} returns false. * @throws IllegalArgumentException if {@link Player#canAdvertiseSession()} returns false.
*/ */
public Builder(Context context, Player player) { public Builder(Context context, Player player) {
super(context, player, new SessionCallback() {}); super(context, player, new Callback() {});
} }
/** /**
@ -281,7 +280,7 @@ public class MediaSession {
* @return The builder to allow chaining. * @return The builder to allow chaining.
*/ */
@Override @Override
public Builder setSessionCallback(SessionCallback callback) { public Builder setSessionCallback(Callback callback) {
return super.setSessionCallback(callback); return super.setSessionCallback(callback);
} }
@ -475,7 +474,7 @@ public class MediaSession {
String id, String id,
Player player, Player player,
@Nullable PendingIntent sessionActivity, @Nullable PendingIntent sessionActivity,
SessionCallback callback, Callback callback,
MediaItemFiller mediaItemFiller, MediaItemFiller mediaItemFiller,
Bundle tokenExtras) { Bundle tokenExtras) {
synchronized (STATIC_LOCK) { synchronized (STATIC_LOCK) {
@ -492,7 +491,7 @@ public class MediaSession {
String id, String id,
Player player, Player player,
@Nullable PendingIntent sessionActivity, @Nullable PendingIntent sessionActivity,
SessionCallback callback, Callback callback,
MediaItemFiller mediaItemFiller, MediaItemFiller mediaItemFiller,
Bundle tokenExtras) { Bundle tokenExtras) {
return new MediaSessionImpl( return new MediaSessionImpl(
@ -770,10 +769,10 @@ public class MediaSession {
* <p>The callback methods will be called from the application thread associated with the {@link * <p>The callback methods will be called from the application thread associated with the {@link
* Player#getApplicationLooper() application looper} of the underlying {@link Player}. * Player#getApplicationLooper() application looper} of the underlying {@link Player}.
* *
* <p>If it's not set by {@link MediaSession.Builder#setSessionCallback(SessionCallback)}, the * <p>If it's not set by {@link MediaSession.Builder#setSessionCallback(Callback)}, the session
* session will accept all controllers and all incoming commands by default. * will accept all controllers and all incoming commands by default.
*/ */
public interface SessionCallback { public interface Callback {
/** /**
* Called when a controller is about to connect to this session. Return a {@link * Called when a controller is about to connect to this session. Return a {@link
@ -1033,8 +1032,8 @@ public class MediaSession {
} }
/** /**
* A result for {@link SessionCallback#onConnect(MediaSession, ControllerInfo)} to denote the set * A result for {@link Callback#onConnect(MediaSession, ControllerInfo)} to denote the set of
* of commands that are available for the given {@link ControllerInfo controller}. * commands that are available for the given {@link ControllerInfo controller}.
*/ */
public static final class ConnectionResult { public static final class ConnectionResult {
@ -1195,7 +1194,7 @@ public class MediaSession {
* applied to the subclasses. * applied to the subclasses.
*/ */
/* package */ abstract static class BuilderBase< /* package */ abstract static class BuilderBase<
T extends MediaSession, U extends BuilderBase<T, U, C>, C extends SessionCallback> { T extends MediaSession, U extends BuilderBase<T, U, C>, C extends Callback> {
/* package */ final Context context; /* package */ final Context context;
/* package */ final Player player; /* package */ final Player player;

View File

@ -68,7 +68,6 @@ import androidx.media3.common.util.Util;
import androidx.media3.session.MediaSession.ControllerCb; import androidx.media3.session.MediaSession.ControllerCb;
import androidx.media3.session.MediaSession.ControllerInfo; import androidx.media3.session.MediaSession.ControllerInfo;
import androidx.media3.session.MediaSession.MediaItemFiller; import androidx.media3.session.MediaSession.MediaItemFiller;
import androidx.media3.session.MediaSession.SessionCallback;
import androidx.media3.session.SequencedFutureManager.SequencedFuture; import androidx.media3.session.SequencedFutureManager.SequencedFuture;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.Futures;
@ -108,7 +107,7 @@ import org.checkerframework.checker.initialization.qual.Initialized;
private final PlayerInfoChangedHandler onPlayerInfoChangedHandler; private final PlayerInfoChangedHandler onPlayerInfoChangedHandler;
private final SessionCallback callback; private final MediaSession.Callback callback;
private final MediaItemFiller mediaItemFiller; private final MediaItemFiller mediaItemFiller;
private final Context context; private final Context context;
@ -143,7 +142,7 @@ import org.checkerframework.checker.initialization.qual.Initialized;
String id, String id,
Player player, Player player,
@Nullable PendingIntent sessionActivity, @Nullable PendingIntent sessionActivity,
SessionCallback callback, MediaSession.Callback callback,
MediaItemFiller mediaItemFiller, MediaItemFiller mediaItemFiller,
Bundle tokenExtras) { Bundle tokenExtras) {
this.context = context; this.context = context;

View File

@ -93,7 +93,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
* for the service, the controller binds to the service. {@link #onGetSession(ControllerInfo)} will * for the service, the controller binds to the service. {@link #onGetSession(ControllerInfo)} will
* be called from {@link #onBind(Intent)}. * be called from {@link #onBind(Intent)}.
* *
* <p>After binding, the session's {@link MediaSession.SessionCallback#onConnect(MediaSession, * <p>After binding, the session's {@link MediaSession.Callback#onConnect(MediaSession,
* MediaSession.ControllerInfo)} will be called to accept or reject the connection request from the * MediaSession.ControllerInfo)} will be called to accept or reject the connection request from the
* controller. If it's accepted, the controller will be available and keep the binding. If it's * controller. If it's accepted, the controller will be available and keep the binding. If it's
* rejected, the controller will unbind. * rejected, the controller will unbind.

View File

@ -39,7 +39,7 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
/** /**
* Tests for {@link MediaLibrarySession.MediaLibrarySessionCallback}. * Tests for {@link MediaLibrarySession.Callback}.
* *
* <p>TODO: Make this class extend MediaSessionCallbackTest. TODO: Create MediaLibrarySessionTest * <p>TODO: Make this class extend MediaSessionCallbackTest. TODO: Create MediaLibrarySessionTest
* which extends MediaSessionTest. * which extends MediaSessionTest.
@ -76,8 +76,8 @@ public class MediaLibrarySessionCallbackTest {
LibraryParams testParams = MediaTestUtils.createLibraryParams(); LibraryParams testParams = MediaTestUtils.createLibraryParams();
CountDownLatch latch = new CountDownLatch(1); CountDownLatch latch = new CountDownLatch(1);
MediaLibrarySession.MediaLibrarySessionCallback sessionCallback = MediaLibrarySession.Callback sessionCallback =
new MediaLibrarySession.MediaLibrarySessionCallback() { new MediaLibrarySession.Callback() {
@Override @Override
public ListenableFuture<LibraryResult<Void>> onSubscribe( public ListenableFuture<LibraryResult<Void>> onSubscribe(
MediaLibrarySession session, MediaLibrarySession session,
@ -109,8 +109,8 @@ public class MediaLibrarySessionCallbackTest {
String testParentId = "testUnsubscribeId"; String testParentId = "testUnsubscribeId";
CountDownLatch latch = new CountDownLatch(1); CountDownLatch latch = new CountDownLatch(1);
MediaLibrarySession.MediaLibrarySessionCallback sessionCallback = MediaLibrarySession.Callback sessionCallback =
new MediaLibrarySession.MediaLibrarySessionCallback() { new MediaLibrarySession.Callback() {
@Override @Override
public ListenableFuture<LibraryResult<Void>> onUnsubscribe( public ListenableFuture<LibraryResult<Void>> onUnsubscribe(
MediaLibrarySession session, ControllerInfo browser, String parentId) { MediaLibrarySession session, ControllerInfo browser, String parentId) {

View File

@ -51,7 +51,7 @@ import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
/** Tests for {@link MediaSession.SessionCallback}. */ /** Tests for {@link MediaSession.Callback}. */
@RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class)
@LargeTest @LargeTest
public class MediaSessionCallbackTest { public class MediaSessionCallbackTest {
@ -81,8 +81,8 @@ public class MediaSessionCallbackTest {
@Test @Test
public void onPostConnect_afterConnected() throws Exception { public void onPostConnect_afterConnected() throws Exception {
CountDownLatch latch = new CountDownLatch(1); CountDownLatch latch = new CountDownLatch(1);
MediaSession.SessionCallback callback = MediaSession.Callback callback =
new MediaSession.SessionCallback() { new MediaSession.Callback() {
@Override @Override
public void onPostConnect(MediaSession session, ControllerInfo controller) { public void onPostConnect(MediaSession session, ControllerInfo controller) {
latch.countDown(); latch.countDown();
@ -101,8 +101,8 @@ public class MediaSessionCallbackTest {
@Test @Test
public void onPostConnect_afterConnectionRejected() throws Exception { public void onPostConnect_afterConnectionRejected() throws Exception {
CountDownLatch latch = new CountDownLatch(1); CountDownLatch latch = new CountDownLatch(1);
MediaSession.SessionCallback callback = MediaSession.Callback callback =
new MediaSession.SessionCallback() { new MediaSession.Callback() {
@Override @Override
public MediaSession.ConnectionResult onConnect( public MediaSession.ConnectionResult onConnect(
MediaSession session, ControllerInfo controller) { MediaSession session, ControllerInfo controller) {
@ -127,8 +127,8 @@ public class MediaSessionCallbackTest {
@Test @Test
public void onCommandRequest() throws Exception { public void onCommandRequest() throws Exception {
ArrayList<Integer> commands = new ArrayList<>(); ArrayList<Integer> commands = new ArrayList<>();
MediaSession.SessionCallback callback = MediaSession.Callback callback =
new MediaSession.SessionCallback() { new MediaSession.Callback() {
@Override @Override
public int onPlayerCommandRequest( public int onPlayerCommandRequest(
MediaSession session, ControllerInfo controllerInfo, @Player.Command int command) { MediaSession session, ControllerInfo controllerInfo, @Player.Command int command) {
@ -180,8 +180,8 @@ public class MediaSessionCallbackTest {
AtomicReference<SessionCommand> sessionCommandRef = new AtomicReference<>(); AtomicReference<SessionCommand> sessionCommandRef = new AtomicReference<>();
AtomicReference<Bundle> argsRef = new AtomicReference<>(); AtomicReference<Bundle> argsRef = new AtomicReference<>();
MediaSession.SessionCallback callback = MediaSession.Callback callback =
new MediaSession.SessionCallback() { new MediaSession.Callback() {
@Override @Override
public MediaSession.ConnectionResult onConnect( public MediaSession.ConnectionResult onConnect(
MediaSession session, ControllerInfo controller) { MediaSession session, ControllerInfo controller) {
@ -229,8 +229,8 @@ public class MediaSessionCallbackTest {
CountDownLatch latch = new CountDownLatch(1); CountDownLatch latch = new CountDownLatch(1);
AtomicReference<Uri> uriRef = new AtomicReference<>(); AtomicReference<Uri> uriRef = new AtomicReference<>();
AtomicReference<Bundle> extrasRef = new AtomicReference<>(); AtomicReference<Bundle> extrasRef = new AtomicReference<>();
MediaSession.SessionCallback callback = MediaSession.Callback callback =
new MediaSession.SessionCallback() { new MediaSession.Callback() {
@Override @Override
public int onSetMediaUri( public int onSetMediaUri(
MediaSession session, ControllerInfo controller, Uri uri, Bundle extras) { MediaSession session, ControllerInfo controller, Uri uri, Bundle extras) {
@ -268,8 +268,8 @@ public class MediaSessionCallbackTest {
CountDownLatch latch = new CountDownLatch(1); CountDownLatch latch = new CountDownLatch(1);
AtomicReference<String> mediaIdRef = new AtomicReference<>(); AtomicReference<String> mediaIdRef = new AtomicReference<>();
AtomicReference<Rating> ratingRef = new AtomicReference<>(); AtomicReference<Rating> ratingRef = new AtomicReference<>();
MediaSession.SessionCallback callback = MediaSession.Callback callback =
new MediaSession.SessionCallback() { new MediaSession.Callback() {
@Override @Override
public ListenableFuture<SessionResult> onSetRating( public ListenableFuture<SessionResult> onSetRating(
MediaSession session, ControllerInfo controller, String mediaId, Rating rating) { MediaSession session, ControllerInfo controller, String mediaId, Rating rating) {
@ -306,8 +306,8 @@ public class MediaSessionCallbackTest {
CountDownLatch latch = new CountDownLatch(1); CountDownLatch latch = new CountDownLatch(1);
AtomicReference<Rating> ratingRef = new AtomicReference<>(); AtomicReference<Rating> ratingRef = new AtomicReference<>();
MediaSession.SessionCallback callback = MediaSession.Callback callback =
new MediaSession.SessionCallback() { new MediaSession.Callback() {
@Override @Override
public ListenableFuture<SessionResult> onSetRating( public ListenableFuture<SessionResult> onSetRating(
MediaSession session, ControllerInfo controller, Rating rating) { MediaSession session, ControllerInfo controller, Rating rating) {
@ -508,7 +508,7 @@ public class MediaSessionCallbackTest {
new MediaSession.Builder(context, player) new MediaSession.Builder(context, player)
.setId("testOnConnect") .setId("testOnConnect")
.setSessionCallback( .setSessionCallback(
new MediaSession.SessionCallback() { new MediaSession.Callback() {
@Override @Override
public MediaSession.ConnectionResult onConnect( public MediaSession.ConnectionResult onConnect(
MediaSession session, ControllerInfo controller) { MediaSession session, ControllerInfo controller) {
@ -518,7 +518,7 @@ public class MediaSessionCallbackTest {
} }
connectionHints.set(controller.getConnectionHints()); connectionHints.set(controller.getConnectionHints());
latch.countDown(); latch.countDown();
return MediaSession.SessionCallback.super.onConnect(session, controller); return MediaSession.Callback.super.onConnect(session, controller);
} }
}) })
.build()); .build());
@ -539,7 +539,7 @@ public class MediaSessionCallbackTest {
new MediaSession.Builder(context, player) new MediaSession.Builder(context, player)
.setId("testOnDisconnected") .setId("testOnDisconnected")
.setSessionCallback( .setSessionCallback(
new MediaSession.SessionCallback() { new MediaSession.Callback() {
@Override @Override
public void onDisconnected(MediaSession session, ControllerInfo controller) { public void onDisconnected(MediaSession session, ControllerInfo controller) {
if (TextUtils.equals( if (TextUtils.equals(

View File

@ -48,7 +48,6 @@ import androidx.media3.common.Rating;
import androidx.media3.common.util.Log; import androidx.media3.common.util.Log;
import androidx.media3.common.util.Util; import androidx.media3.common.util.Util;
import androidx.media3.session.MediaSession.ControllerInfo; import androidx.media3.session.MediaSession.ControllerInfo;
import androidx.media3.session.MediaSession.SessionCallback;
import androidx.media3.test.session.common.HandlerThreadTestRule; import androidx.media3.test.session.common.HandlerThreadTestRule;
import androidx.media3.test.session.common.MainLooperTestRule; import androidx.media3.test.session.common.MainLooperTestRule;
import androidx.media3.test.session.common.PollingCheck; import androidx.media3.test.session.common.PollingCheck;
@ -69,7 +68,7 @@ import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
/** Tests for {@link SessionCallback} working with {@link MediaControllerCompat}. */ /** Tests for {@link MediaSession.Callback} working with {@link MediaControllerCompat}. */
@RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class)
@LargeTest @LargeTest
public class MediaSessionCallbackWithMediaControllerCompatTest { public class MediaSessionCallbackWithMediaControllerCompatTest {
@ -117,7 +116,7 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
new MediaSession.Builder(context, player) new MediaSession.Builder(context, player)
.setId("onDisconnected_afterTimeout_isCalled") .setId("onDisconnected_afterTimeout_isCalled")
.setSessionCallback( .setSessionCallback(
new SessionCallback() { new MediaSession.Callback() {
private ControllerInfo connectedController; private ControllerInfo connectedController;
@Override @Override
@ -125,7 +124,7 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
MediaSession session, ControllerInfo controller) { MediaSession session, ControllerInfo controller) {
if (EXPECTED_CONTROLLER_PACKAGE_NAME.equals(controller.getPackageName())) { if (EXPECTED_CONTROLLER_PACKAGE_NAME.equals(controller.getPackageName())) {
connectedController = controller; connectedController = controller;
return SessionCallback.super.onConnect(session, controller); return MediaSession.Callback.super.onConnect(session, controller);
} }
return MediaSession.ConnectionResult.reject(); return MediaSession.ConnectionResult.reject();
} }
@ -156,7 +155,7 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
new MediaSession.Builder(context, player) new MediaSession.Builder(context, player)
.setId("onConnected_afterDisconnectedByTimeout_isCalled") .setId("onConnected_afterDisconnectedByTimeout_isCalled")
.setSessionCallback( .setSessionCallback(
new SessionCallback() { new MediaSession.Callback() {
private ControllerInfo connectedController; private ControllerInfo connectedController;
@Override @Override
@ -165,7 +164,7 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
if (EXPECTED_CONTROLLER_PACKAGE_NAME.equals(controller.getPackageName())) { if (EXPECTED_CONTROLLER_PACKAGE_NAME.equals(controller.getPackageName())) {
connectedController = controller; connectedController = controller;
connectedLatch.countDown(); connectedLatch.countDown();
return SessionCallback.super.onConnect(session, controller); return MediaSession.Callback.super.onConnect(session, controller);
} }
return MediaSession.ConnectionResult.reject(); return MediaSession.ConnectionResult.reject();
} }
@ -657,14 +656,14 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
testArgs.putString("args", "test_args"); testArgs.putString("args", "test_args");
CountDownLatch latch = new CountDownLatch(1); CountDownLatch latch = new CountDownLatch(1);
SessionCallback callback = MediaSession.Callback callback =
new SessionCallback() { new MediaSession.Callback() {
@Override @Override
public MediaSession.ConnectionResult onConnect( public MediaSession.ConnectionResult onConnect(
MediaSession session, ControllerInfo controller) { MediaSession session, ControllerInfo controller) {
if (EXPECTED_CONTROLLER_PACKAGE_NAME.equals(controller.getPackageName())) { if (EXPECTED_CONTROLLER_PACKAGE_NAME.equals(controller.getPackageName())) {
MediaSession.ConnectionResult commands = MediaSession.ConnectionResult commands =
SessionCallback.super.onConnect(session, controller); MediaSession.Callback.super.onConnect(session, controller);
SessionCommands.Builder builder = commands.availableSessionCommands.buildUpon(); SessionCommands.Builder builder = commands.availableSessionCommands.buildUpon();
builder.add(new SessionCommand(testCommand, /* extras= */ Bundle.EMPTY)); builder.add(new SessionCommand(testCommand, /* extras= */ Bundle.EMPTY));
return MediaSession.ConnectionResult.accept( return MediaSession.ConnectionResult.accept(
@ -708,14 +707,14 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
testArgs.putString("args", "test_custom_args"); testArgs.putString("args", "test_custom_args");
SessionCommand customCommand = new SessionCommand(testCommand, /* extras= */ Bundle.EMPTY); SessionCommand customCommand = new SessionCommand(testCommand, /* extras= */ Bundle.EMPTY);
CountDownLatch latch = new CountDownLatch(1); CountDownLatch latch = new CountDownLatch(1);
SessionCallback callback = MediaSession.Callback callback =
new SessionCallback() { new MediaSession.Callback() {
@Override @Override
public MediaSession.ConnectionResult onConnect( public MediaSession.ConnectionResult onConnect(
MediaSession session, ControllerInfo controller) { MediaSession session, ControllerInfo controller) {
if (EXPECTED_CONTROLLER_PACKAGE_NAME.equals(controller.getPackageName())) { if (EXPECTED_CONTROLLER_PACKAGE_NAME.equals(controller.getPackageName())) {
MediaSession.ConnectionResult connectionResult = MediaSession.ConnectionResult connectionResult =
SessionCallback.super.onConnect(session, controller); MediaSession.Callback.super.onConnect(session, controller);
SessionCommands.Builder builder = SessionCommands.Builder builder =
connectionResult.availableSessionCommands.buildUpon().add(customCommand); connectionResult.availableSessionCommands.buildUpon().add(customCommand);
return MediaSession.ConnectionResult.accept( return MediaSession.ConnectionResult.accept(
@ -755,8 +754,8 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
@Test @Test
public void controllerCallback_sessionRejects() throws Exception { public void controllerCallback_sessionRejects() throws Exception {
SessionCallback sessionCallback = MediaSession.Callback sessionCallback =
new SessionCallback() { new MediaSession.Callback() {
@Override @Override
public MediaSession.ConnectionResult onConnect( public MediaSession.ConnectionResult onConnect(
MediaSession session, ControllerInfo controller) { MediaSession session, ControllerInfo controller) {
@ -785,7 +784,7 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putString("key", "value"); bundle.putString("key", "value");
CountDownLatch latch = new CountDownLatch(1); CountDownLatch latch = new CountDownLatch(1);
SessionCallback callback = MediaSession.Callback callback =
new TestSessionCallback() { new TestSessionCallback() {
@Override @Override
public int onSetMediaUri( public int onSetMediaUri(
@ -817,7 +816,7 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putString("key", "value"); bundle.putString("key", "value");
CountDownLatch latch = new CountDownLatch(1); CountDownLatch latch = new CountDownLatch(1);
SessionCallback callback = MediaSession.Callback callback =
new TestSessionCallback() { new TestSessionCallback() {
@Override @Override
public int onSetMediaUri( public int onSetMediaUri(
@ -849,7 +848,7 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putString("key", "value"); bundle.putString("key", "value");
CountDownLatch latch = new CountDownLatch(1); CountDownLatch latch = new CountDownLatch(1);
SessionCallback callback = MediaSession.Callback callback =
new TestSessionCallback() { new TestSessionCallback() {
@Override @Override
public int onSetMediaUri( public int onSetMediaUri(
@ -882,7 +881,7 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putString("key", "value"); bundle.putString("key", "value");
CountDownLatch latch = new CountDownLatch(1); CountDownLatch latch = new CountDownLatch(1);
SessionCallback callback = MediaSession.Callback callback =
new TestSessionCallback() { new TestSessionCallback() {
@Override @Override
public int onSetMediaUri( public int onSetMediaUri(
@ -915,7 +914,7 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putString("key", "value"); bundle.putString("key", "value");
CountDownLatch latch = new CountDownLatch(1); CountDownLatch latch = new CountDownLatch(1);
SessionCallback callback = MediaSession.Callback callback =
new TestSessionCallback() { new TestSessionCallback() {
@Override @Override
public int onSetMediaUri( public int onSetMediaUri(
@ -948,7 +947,7 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putString("key", "value"); bundle.putString("key", "value");
CountDownLatch latch = new CountDownLatch(1); CountDownLatch latch = new CountDownLatch(1);
SessionCallback callback = MediaSession.Callback callback =
new TestSessionCallback() { new TestSessionCallback() {
@Override @Override
public int onSetMediaUri( public int onSetMediaUri(
@ -983,7 +982,7 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
String mediaId = "media_id"; String mediaId = "media_id";
CountDownLatch latch = new CountDownLatch(1); CountDownLatch latch = new CountDownLatch(1);
SessionCallback callback = MediaSession.Callback callback =
new TestSessionCallback() { new TestSessionCallback() {
@Override @Override
public ListenableFuture<SessionResult> onSetRating( public ListenableFuture<SessionResult> onSetRating(
@ -1020,7 +1019,7 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
public void onCommandRequest() throws Exception { public void onCommandRequest() throws Exception {
ArrayList<Integer> commands = new ArrayList<>(); ArrayList<Integer> commands = new ArrayList<>();
CountDownLatch latchForPause = new CountDownLatch(1); CountDownLatch latchForPause = new CountDownLatch(1);
SessionCallback callback = MediaSession.Callback callback =
new TestSessionCallback() { new TestSessionCallback() {
@Override @Override
public int onPlayerCommandRequest( public int onPlayerCommandRequest(
@ -1128,13 +1127,13 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
assertThat(player.hasMethodBeenCalled(MockPlayer.METHOD_PLAY)).isFalse(); assertThat(player.hasMethodBeenCalled(MockPlayer.METHOD_PLAY)).isFalse();
} }
private static class TestSessionCallback implements SessionCallback { private static class TestSessionCallback implements MediaSession.Callback {
@Override @Override
public MediaSession.ConnectionResult onConnect( public MediaSession.ConnectionResult onConnect(
MediaSession session, ControllerInfo controller) { MediaSession session, ControllerInfo controller) {
if (EXPECTED_CONTROLLER_PACKAGE_NAME.equals(controller.getPackageName())) { if (EXPECTED_CONTROLLER_PACKAGE_NAME.equals(controller.getPackageName())) {
return SessionCallback.super.onConnect(session, controller); return MediaSession.Callback.super.onConnect(session, controller);
} }
return MediaSession.ConnectionResult.reject(); return MediaSession.ConnectionResult.reject();
} }

View File

@ -202,13 +202,13 @@ public class MediaSessionKeyEventTest {
} }
} }
private static class TestSessionCallback implements MediaSession.SessionCallback { private static class TestSessionCallback implements MediaSession.Callback {
@Override @Override
public MediaSession.ConnectionResult onConnect( public MediaSession.ConnectionResult onConnect(
MediaSession session, ControllerInfo controller) { MediaSession session, ControllerInfo controller) {
if (expectedControllerPackageName.equals(controller.getPackageName())) { if (expectedControllerPackageName.equals(controller.getPackageName())) {
return MediaSession.SessionCallback.super.onConnect(session, controller); return MediaSession.Callback.super.onConnect(session, controller);
} }
return MediaSession.ConnectionResult.reject(); return MediaSession.ConnectionResult.reject();
} }

View File

@ -300,7 +300,7 @@ public class MediaSessionPermissionTest {
void run(RemoteMediaController controller) throws Exception; void run(RemoteMediaController controller) throws Exception;
} }
private static class MySessionCallback implements MediaSession.SessionCallback { private static class MySessionCallback implements MediaSession.Callback {
public CountDownLatch countDownLatch; public CountDownLatch countDownLatch;
public @Player.Command int command; public @Player.Command int command;
@ -334,8 +334,7 @@ public class MediaSessionPermissionTest {
onCommandRequestCalled = true; onCommandRequestCalled = true;
this.command = command; this.command = command;
countDownLatch.countDown(); countDownLatch.countDown();
return MediaSession.SessionCallback.super.onPlayerCommandRequest( return MediaSession.Callback.super.onPlayerCommandRequest(session, controller, command);
session, controller, command);
} }
@Override @Override

View File

@ -67,12 +67,12 @@ public class MediaSessionPlayerTest {
session = session =
new MediaSession.Builder(ApplicationProvider.getApplicationContext(), player) new MediaSession.Builder(ApplicationProvider.getApplicationContext(), player)
.setSessionCallback( .setSessionCallback(
new MediaSession.SessionCallback() { new MediaSession.Callback() {
@Override @Override
public MediaSession.ConnectionResult onConnect( public MediaSession.ConnectionResult onConnect(
MediaSession session, MediaSession.ControllerInfo controller) { MediaSession session, MediaSession.ControllerInfo controller) {
if (SUPPORT_APP_PACKAGE_NAME.equals(controller.getPackageName())) { if (SUPPORT_APP_PACKAGE_NAME.equals(controller.getPackageName())) {
return MediaSession.SessionCallback.super.onConnect(session, controller); return MediaSession.Callback.super.onConnect(session, controller);
} }
return MediaSession.ConnectionResult.reject(); return MediaSession.ConnectionResult.reject();
} }

View File

@ -21,7 +21,7 @@ import android.content.ComponentName;
import android.content.Context; import android.content.Context;
import androidx.media3.common.MediaMetadata; import androidx.media3.common.MediaMetadata;
import androidx.media3.common.util.Util; import androidx.media3.common.util.Util;
import androidx.media3.session.MediaLibraryService.MediaLibrarySession.MediaLibrarySessionCallback; import androidx.media3.session.MediaLibraryService.MediaLibrarySession;
import androidx.media3.session.MediaSession.ControllerInfo; import androidx.media3.session.MediaSession.ControllerInfo;
import androidx.media3.test.session.common.HandlerThreadTestRule; import androidx.media3.test.session.common.HandlerThreadTestRule;
import androidx.media3.test.session.common.MainLooperTestRule; import androidx.media3.test.session.common.MainLooperTestRule;
@ -67,8 +67,8 @@ public class MediaSessionServiceNotificationTest {
public void setUp() throws Exception { public void setUp() throws Exception {
context = ApplicationProvider.getApplicationContext(); context = ApplicationProvider.getApplicationContext();
MediaLibrarySessionCallback sessionCallback = MediaLibrarySession.Callback sessionCallback =
new MediaLibrarySessionCallback() { new MediaLibrarySession.Callback() {
@Override @Override
public MediaSession.ConnectionResult onConnect( public MediaSession.ConnectionResult onConnect(
MediaSession session, ControllerInfo controller) { MediaSession session, ControllerInfo controller) {
@ -78,7 +78,7 @@ public class MediaSessionServiceNotificationTest {
session.setPlayer(player); session.setPlayer(player);
} }
if (SUPPORT_APP_PACKAGE_NAME.equals(controller.getPackageName())) { if (SUPPORT_APP_PACKAGE_NAME.equals(controller.getPackageName())) {
return MediaLibrarySessionCallback.super.onConnect(session, controller); return MediaLibrarySession.Callback.super.onConnect(session, controller);
} else { } else {
return MediaSession.ConnectionResult.reject(); return MediaSession.ConnectionResult.reject();
} }

View File

@ -113,8 +113,7 @@ public class MediaSessionServiceTest {
/** /**
* Tests whether the controller is connected to the session which is returned from {@link * Tests whether the controller is connected to the session which is returned from {@link
* MediaSessionService#onGetSession(ControllerInfo)}. Also checks whether the connection hints are * MediaSessionService#onGetSession(ControllerInfo)}. Also checks whether the connection hints are
* properly passed to {@link MediaSession.SessionCallback#onConnect(MediaSession, * properly passed to {@link MediaSession.Callback#onConnect(MediaSession, ControllerInfo)}.
* ControllerInfo)}.
*/ */
@Test @Test
public void onGetSession_returnsSession() throws Exception { public void onGetSession_returnsSession() throws Exception {
@ -129,7 +128,7 @@ public class MediaSessionServiceTest {
context, new MockPlayer.Builder().setApplicationLooper(looper).build()) context, new MockPlayer.Builder().setApplicationLooper(looper).build())
.setId("testOnGetSession_returnsSession") .setId("testOnGetSession_returnsSession")
.setSessionCallback( .setSessionCallback(
new MediaSession.SessionCallback() { new MediaSession.Callback() {
@Override @Override
public MediaSession.ConnectionResult onConnect( public MediaSession.ConnectionResult onConnect(
MediaSession session, ControllerInfo controller) { MediaSession session, ControllerInfo controller) {

View File

@ -35,7 +35,6 @@ import androidx.media.MediaSessionManager;
import androidx.media3.common.MediaLibraryInfo; import androidx.media3.common.MediaLibraryInfo;
import androidx.media3.common.util.Log; import androidx.media3.common.util.Log;
import androidx.media3.common.util.Util; import androidx.media3.common.util.Util;
import androidx.media3.session.MediaSession.SessionCallback;
import androidx.media3.test.session.common.HandlerThreadTestRule; import androidx.media3.test.session.common.HandlerThreadTestRule;
import androidx.media3.test.session.common.MainLooperTestRule; import androidx.media3.test.session.common.MainLooperTestRule;
import androidx.media3.test.session.common.TestHandler; import androidx.media3.test.session.common.TestHandler;
@ -86,13 +85,13 @@ public class MediaSessionTest {
new MediaSession.Builder(context, player) new MediaSession.Builder(context, player)
.setId(TAG) .setId(TAG)
.setSessionCallback( .setSessionCallback(
new SessionCallback() { new MediaSession.Callback() {
@Override @Override
public MediaSession.ConnectionResult onConnect( public MediaSession.ConnectionResult onConnect(
MediaSession session, MediaSession.ControllerInfo controller) { MediaSession session, MediaSession.ControllerInfo controller) {
if (TextUtils.equals( if (TextUtils.equals(
context.getPackageName(), controller.getPackageName())) { context.getPackageName(), controller.getPackageName())) {
return SessionCallback.super.onConnect(session, controller); return MediaSession.Callback.super.onConnect(session, controller);
} }
return MediaSession.ConnectionResult.reject(); return MediaSession.ConnectionResult.reject();
} }
@ -322,8 +321,8 @@ public class MediaSessionTest {
public void sendCustomCommand_onConnect() throws Exception { public void sendCustomCommand_onConnect() throws Exception {
CountDownLatch latch = new CountDownLatch(1); CountDownLatch latch = new CountDownLatch(1);
SessionCommand testCommand = new SessionCommand("test", /* extras= */ Bundle.EMPTY); SessionCommand testCommand = new SessionCommand("test", /* extras= */ Bundle.EMPTY);
SessionCallback testSessionCallback = MediaSession.Callback testSessionCallback =
new SessionCallback() { new MediaSession.Callback() {
@Override @Override
public MediaSession.ConnectionResult onConnect( public MediaSession.ConnectionResult onConnect(
MediaSession session, MediaSession.ControllerInfo controller) { MediaSession session, MediaSession.ControllerInfo controller) {
@ -336,7 +335,7 @@ public class MediaSessionTest {
} catch (ExecutionException | InterruptedException | TimeoutException e) { } catch (ExecutionException | InterruptedException | TimeoutException e) {
assertWithMessage("Fail to get result of the returned future.").fail(); assertWithMessage("Fail to get result of the returned future.").fail();
} }
return SessionCallback.super.onConnect(session, controller); return MediaSession.Callback.super.onConnect(session, controller);
} }
@Override @Override
@ -374,13 +373,13 @@ public class MediaSessionTest {
new MediaSession.Builder(context, player) new MediaSession.Builder(context, player)
.setId("getSessionCompatToken_returnsCompatibleWithMediaControllerCompat") .setId("getSessionCompatToken_returnsCompatibleWithMediaControllerCompat")
.setSessionCallback( .setSessionCallback(
new SessionCallback() { new MediaSession.Callback() {
@Override @Override
public MediaSession.ConnectionResult onConnect( public MediaSession.ConnectionResult onConnect(
MediaSession session, MediaSession.ControllerInfo controller) { MediaSession session, MediaSession.ControllerInfo controller) {
if (TextUtils.equals( if (TextUtils.equals(
expectedControllerCompatPackageName, controller.getPackageName())) { expectedControllerCompatPackageName, controller.getPackageName())) {
return SessionCallback.super.onConnect(session, controller); return MediaSession.Callback.super.onConnect(session, controller);
} }
return MediaSession.ConnectionResult.reject(); return MediaSession.ConnectionResult.reject();
} }
@ -412,14 +411,14 @@ public class MediaSessionTest {
public void getControllerVersion() throws Exception { public void getControllerVersion() throws Exception {
CountDownLatch connectedLatch = new CountDownLatch(1); CountDownLatch connectedLatch = new CountDownLatch(1);
AtomicInteger controllerVersionRef = new AtomicInteger(); AtomicInteger controllerVersionRef = new AtomicInteger();
SessionCallback sessionCallback = MediaSession.Callback sessionCallback =
new SessionCallback() { new MediaSession.Callback() {
@Override @Override
public MediaSession.ConnectionResult onConnect( public MediaSession.ConnectionResult onConnect(
MediaSession session, MediaSession.ControllerInfo controller) { MediaSession session, MediaSession.ControllerInfo controller) {
controllerVersionRef.set(controller.getControllerVersion()); controllerVersionRef.set(controller.getControllerVersion());
connectedLatch.countDown(); connectedLatch.countDown();
return SessionCallback.super.onConnect(session, controller); return MediaSession.Callback.super.onConnect(session, controller);
} }
}; };

View File

@ -66,14 +66,14 @@ public class MediaSessionWithMediaControllerCompatTest {
public void getControllerVersion() throws Exception { public void getControllerVersion() throws Exception {
CountDownLatch connectedLatch = new CountDownLatch(1); CountDownLatch connectedLatch = new CountDownLatch(1);
AtomicInteger controllerVersionRef = new AtomicInteger(); AtomicInteger controllerVersionRef = new AtomicInteger();
MediaSession.SessionCallback callback = MediaSession.Callback callback =
new MediaSession.SessionCallback() { new MediaSession.Callback() {
@Override @Override
public MediaSession.ConnectionResult onConnect( public MediaSession.ConnectionResult onConnect(
MediaSession session, MediaSession.ControllerInfo controller) { MediaSession session, MediaSession.ControllerInfo controller) {
controllerVersionRef.set(controller.getControllerVersion()); controllerVersionRef.set(controller.getControllerVersion());
connectedLatch.countDown(); connectedLatch.countDown();
return MediaSession.SessionCallback.super.onConnect(session, controller); return MediaSession.Callback.super.onConnect(session, controller);
} }
}; };

View File

@ -180,7 +180,7 @@ public class MediaSessionProviderService extends Service {
case TEST_CONTROLLER_LISTENER_SESSION_REJECTS: case TEST_CONTROLLER_LISTENER_SESSION_REJECTS:
{ {
builder.setSessionCallback( builder.setSessionCallback(
new MediaSession.SessionCallback() { new MediaSession.Callback() {
@Override @Override
public MediaSession.ConnectionResult onConnect( public MediaSession.ConnectionResult onConnect(
MediaSession session, ControllerInfo controller) { MediaSession session, ControllerInfo controller) {
@ -195,7 +195,7 @@ public class MediaSessionProviderService extends Service {
SessionCommands.CREATOR.fromBundle( SessionCommands.CREATOR.fromBundle(
tokenExtras.getBundle(KEY_AVAILABLE_SESSION_COMMANDS)); tokenExtras.getBundle(KEY_AVAILABLE_SESSION_COMMANDS));
builder.setSessionCallback( builder.setSessionCallback(
new MediaSession.SessionCallback() { new MediaSession.Callback() {
@Override @Override
public MediaSession.ConnectionResult onConnect( public MediaSession.ConnectionResult onConnect(
MediaSession session, ControllerInfo controller) { MediaSession session, ControllerInfo controller) {

View File

@ -64,7 +64,7 @@ import androidx.media3.common.MediaMetadata;
import androidx.media3.common.util.Log; import androidx.media3.common.util.Log;
import androidx.media3.common.util.UnstableApi; import androidx.media3.common.util.UnstableApi;
import androidx.media3.common.util.Util; import androidx.media3.common.util.Util;
import androidx.media3.session.MediaLibraryService.MediaLibrarySession.MediaLibrarySessionCallback; import androidx.media3.session.MediaLibraryService.MediaLibrarySession;
import androidx.media3.session.MediaSession.ControllerInfo; import androidx.media3.session.MediaSession.ControllerInfo;
import androidx.media3.test.session.common.TestHandler; import androidx.media3.test.session.common.TestHandler;
import androidx.media3.test.session.common.TestUtils; import androidx.media3.test.session.common.TestUtils;
@ -142,7 +142,7 @@ public class MockMediaLibraryService extends MediaLibraryService {
MockPlayer player = new MockPlayer.Builder().setApplicationLooper(handler.getLooper()).build(); MockPlayer player = new MockPlayer.Builder().setApplicationLooper(handler.getLooper()).build();
MediaLibrarySessionCallback callback = registry.getSessionCallback(); MediaLibrarySession.Callback callback = registry.getSessionCallback();
session = session =
new MediaLibrarySession.Builder( new MediaLibrarySession.Builder(
MockMediaLibraryService.this, MockMediaLibraryService.this,
@ -169,7 +169,7 @@ public class MockMediaLibraryService extends MediaLibraryService {
} }
} }
private class TestLibrarySessionCallback implements MediaLibrarySessionCallback { private class TestLibrarySessionCallback implements MediaLibrarySession.Callback {
@Override @Override
public MediaSession.ConnectionResult onConnect( public MediaSession.ConnectionResult onConnect(
@ -178,7 +178,7 @@ public class MockMediaLibraryService extends MediaLibraryService {
return MediaSession.ConnectionResult.reject(); return MediaSession.ConnectionResult.reject();
} }
MediaSession.ConnectionResult connectionResult = MediaSession.ConnectionResult connectionResult =
checkNotNull(MediaLibrarySessionCallback.super.onConnect(session, controller)); checkNotNull(MediaLibrarySession.Callback.super.onConnect(session, controller));
SessionCommands.Builder builder = connectionResult.availableSessionCommands.buildUpon(); SessionCommands.Builder builder = connectionResult.availableSessionCommands.buildUpon();
builder.add(new SessionCommand(CUSTOM_ACTION, /* extras= */ Bundle.EMPTY)); builder.add(new SessionCommand(CUSTOM_ACTION, /* extras= */ Bundle.EMPTY));
builder.add(new SessionCommand(CUSTOM_ACTION_ASSERT_PARAMS, /* extras= */ Bundle.EMPTY)); builder.add(new SessionCommand(CUSTOM_ACTION_ASSERT_PARAMS, /* extras= */ Bundle.EMPTY));

View File

@ -60,7 +60,7 @@ public class MockMediaSessionService extends MediaSessionService {
} }
if (session == null) { if (session == null) {
MediaSession.SessionCallback callback = registry.getSessionCallback(); MediaSession.Callback callback = registry.getSessionCallback();
MockPlayer player = MockPlayer player =
new MockPlayer.Builder().setApplicationLooper(handlerThread.getLooper()).build(); new MockPlayer.Builder().setApplicationLooper(handlerThread.getLooper()).build();
session = session =
@ -72,13 +72,13 @@ public class MockMediaSessionService extends MediaSessionService {
return session; return session;
} }
private static class TestSessionCallback implements MediaSession.SessionCallback { private static class TestSessionCallback implements MediaSession.Callback {
@Override @Override
public MediaSession.ConnectionResult onConnect( public MediaSession.ConnectionResult onConnect(
MediaSession session, ControllerInfo controller) { MediaSession session, ControllerInfo controller) {
if (TextUtils.equals(SUPPORT_APP_PACKAGE_NAME, controller.getPackageName())) { if (TextUtils.equals(SUPPORT_APP_PACKAGE_NAME, controller.getPackageName())) {
return MediaSession.SessionCallback.super.onConnect(session, controller); return MediaSession.Callback.super.onConnect(session, controller);
} }
return MediaSession.ConnectionResult.reject(); return MediaSession.ConnectionResult.reject();
} }

View File

@ -20,7 +20,7 @@ import static com.google.common.truth.Truth.assertWithMessage;
import androidx.annotation.GuardedBy; import androidx.annotation.GuardedBy;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.media3.common.util.UnstableApi; import androidx.media3.common.util.UnstableApi;
import androidx.media3.session.MediaLibraryService.MediaLibrarySession.MediaLibrarySessionCallback; import androidx.media3.session.MediaLibraryService.MediaLibrarySession;
import androidx.media3.session.MediaSession.ControllerInfo; import androidx.media3.session.MediaSession.ControllerInfo;
import java.util.List; import java.util.List;
@ -40,7 +40,7 @@ public class TestServiceRegistry {
private MediaSessionService service; private MediaSessionService service;
@GuardedBy("TestServiceRegistry.class") @GuardedBy("TestServiceRegistry.class")
private MediaLibrarySessionCallback sessionCallback; private MediaLibrarySession.Callback sessionCallback;
@GuardedBy("TestServiceRegistry.class") @GuardedBy("TestServiceRegistry.class")
private SessionServiceCallback sessionServiceCallback; private SessionServiceCallback sessionServiceCallback;
@ -82,13 +82,13 @@ public class TestServiceRegistry {
} }
} }
public void setSessionCallback(MediaLibrarySessionCallback sessionCallback) { public void setSessionCallback(MediaLibrarySession.Callback sessionCallback) {
synchronized (TestServiceRegistry.class) { synchronized (TestServiceRegistry.class) {
this.sessionCallback = sessionCallback; this.sessionCallback = sessionCallback;
} }
} }
public MediaLibrarySessionCallback getSessionCallback() { public MediaLibrarySession.Callback getSessionCallback() {
synchronized (TestServiceRegistry.class) { synchronized (TestServiceRegistry.class) {
return sessionCallback; return sessionCallback;
} }