Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
/** The default {@link MediaNotification.ActionFactory}. */
/* package */ final class DefaultActionFactory implements MediaNotification.ActionFactory {

private static final String ACTION_CUSTOM = "androidx.media3.session.CUSTOM_NOTIFICATION_ACTION";
private static final String EXTRAS_KEY_ACTION_CUSTOM =
"androidx.media3.session.EXTRAS_KEY_CUSTOM_NOTIFICATION_ACTION";
public static final String EXTRAS_KEY_ACTION_CUSTOM_EXTRAS =
Expand Down Expand Up @@ -162,7 +161,7 @@ private int toKeyCode(@Player.Command long action) {
@SuppressWarnings("PendingIntentMutability") // We can't use SaferPendingIntent
private PendingIntent createCustomActionPendingIntent(
MediaSession mediaSession, String action, Bundle extras) {
Intent intent = new Intent(ACTION_CUSTOM);
Intent intent = new Intent(MediaSessionService.ACTION_CUSTOM_NOTIFICATION_ACTION);
intent.setData(mediaSession.getImpl().getUri());
intent.setComponent(new ComponentName(service, service.getClass()));
intent.putExtra(EXTRAS_KEY_ACTION_CUSTOM, action);
Expand All @@ -182,7 +181,7 @@ public boolean isMediaAction(Intent intent) {

/** Returns whether {@code intent} was part of a {@link #createCustomAction custom action }. */
public boolean isCustomAction(Intent intent) {
return ACTION_CUSTOM.equals(intent.getAction());
return MediaSessionService.ACTION_CUSTOM_NOTIFICATION_ACTION.equals(intent.getAction());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public MediaNotificationManager(
mainHandler = Util.createHandler(Looper.getMainLooper(), /* callback= */ this);
mainExecutor = (runnable) -> Util.postOrRun(mainHandler, runnable);
startSelfIntent = new Intent(mediaSessionService, mediaSessionService.getClass());
startSelfIntent.setAction(MediaSessionService.ACTION_START_SELF);
controllerMap = new HashMap<>();
startedInForeground = false;
isUserEngagedTimeoutEnabled = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,27 @@ default void onForegroundServiceStartNotAllowedException() {}
*/
@UnstableApi public static final int SHOW_NOTIFICATION_FOR_IDLE_PLAYER_AFTER_STOP_OR_ERROR = 3;

/**
* The action of an {@link Intent} sent to this service by itself when it is already running, but
* wishes to move into the foreground state.
*
* <p>To start the service, an app must build a {@link MediaController} or a {@link MediaBrowser}
* that binds to the service instead. Starting the service with {@link
* Context#startForegroundService(Intent)} is highly discouraged.
*/
@UnstableApi
protected static final String ACTION_START_SELF =
"androidx.media3.session.MediaSessionService.ACTION_START_SELF";

/**
* The action of an {@link Intent} sent to this service by the system from the media controls
* notification in case the {@link android.app.PendingIntent} was build by {@link
* DefaultMediaNotificationProvider} that uses {@link DefaultActionFactory}.
*/
@UnstableApi
protected static final String ACTION_CUSTOM_NOTIFICATION_ACTION =
"androidx.media3.session.CUSTOM_NOTIFICATION_ACTION";

private static final String TAG = "MSessionService";

private final Object lock;
Expand Down Expand Up @@ -439,9 +460,8 @@ public IBinder onBind(@Nullable Intent intent) {
/**
* Called when a component calls {@link android.content.Context#startService(Intent)}.
*
* <p>The default implementation handles the incoming media button events. In this case, the
* intent will have the action {@link Intent#ACTION_MEDIA_BUTTON}. Override this method if this
* service also needs to handle actions other than {@link Intent#ACTION_MEDIA_BUTTON}.
* <p>Apps normally don't need to override this method. If you think you need to override this
* method, <a href="https://github.com/androidx/media/issues">file a bug on GitHub</a>.
*
* <p>This method will be called on the main thread.
*/
Expand Down