Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b214efbb authored by RoboErik's avatar RoboErik
Browse files

Expose a way to set a PendingIntent for restarting playback

This is to allow apps to set a PendingIntent to restart playback. This
is not persisted across reboots but will allow music to start playing
again for the life of the system. Only the most recent priority app with
a PI set will be cached. This also deprecates methods in AudioManager
that do this and unhides the unregister method in MediaSessionManager.

Change-Id: I66fbf5856333468d8cb8a3022809778ba00d426e
parent e34c09da
Loading
Loading
Loading
Loading
+10 −8
Original line number Diff line number Diff line
@@ -14142,10 +14142,10 @@ package android.media {
    method public void loadSoundEffects();
    method public void playSoundEffect(int);
    method public void playSoundEffect(int, float);
    method public void registerMediaButtonEventReceiver(android.content.ComponentName);
    method public void registerMediaButtonEventReceiver(android.app.PendingIntent);
    method public void registerRemoteControlClient(android.media.RemoteControlClient);
    method public boolean registerRemoteController(android.media.RemoteController);
    method public deprecated void registerMediaButtonEventReceiver(android.content.ComponentName);
    method public deprecated void registerMediaButtonEventReceiver(android.app.PendingIntent);
    method public deprecated void registerRemoteControlClient(android.media.RemoteControlClient);
    method public deprecated boolean registerRemoteController(android.media.RemoteController);
    method public int requestAudioFocus(android.media.AudioManager.OnAudioFocusChangeListener, int, int);
    method public deprecated void setBluetoothA2dpOn(boolean);
    method public void setBluetoothScoOn(boolean);
@@ -14164,10 +14164,10 @@ package android.media {
    method public void startBluetoothSco();
    method public void stopBluetoothSco();
    method public void unloadSoundEffects();
    method public void unregisterMediaButtonEventReceiver(android.content.ComponentName);
    method public void unregisterMediaButtonEventReceiver(android.app.PendingIntent);
    method public void unregisterRemoteControlClient(android.media.RemoteControlClient);
    method public void unregisterRemoteController(android.media.RemoteController);
    method public deprecated void unregisterMediaButtonEventReceiver(android.content.ComponentName);
    method public deprecated void unregisterMediaButtonEventReceiver(android.app.PendingIntent);
    method public deprecated void unregisterRemoteControlClient(android.media.RemoteControlClient);
    method public deprecated void unregisterRemoteController(android.media.RemoteController);
    field public static final java.lang.String ACTION_AUDIO_BECOMING_NOISY = "android.media.AUDIO_BECOMING_NOISY";
    field public static final deprecated java.lang.String ACTION_SCO_AUDIO_STATE_CHANGED = "android.media.SCO_AUDIO_STATE_CHANGED";
    field public static final java.lang.String ACTION_SCO_AUDIO_STATE_UPDATED = "android.media.ACTION_SCO_AUDIO_STATE_UPDATED";
@@ -16643,6 +16643,7 @@ package android.media.session {
    method public void setExtras(android.os.Bundle);
    method public void setFlags(int);
    method public void setLaunchActivity(android.app.PendingIntent);
    method public void setMediaButtonReceiver(android.app.PendingIntent);
    method public void setMediaRouter(android.media.routing.MediaRouter);
    method public void setMetadata(android.media.MediaMetadata);
    method public void setPlaybackState(android.media.session.PlaybackState);
@@ -16705,6 +16706,7 @@ package android.media.session {
  public final class MediaSessionManager {
    method public void addActiveSessionsListener(android.media.session.MediaSessionManager.SessionListener, android.content.ComponentName);
    method public java.util.List<android.media.session.MediaController> getActiveSessions(android.content.ComponentName);
    method public void removeActiveSessionsListener(android.media.session.MediaSessionManager.SessionListener);
  }
  public static abstract class MediaSessionManager.SessionListener {
+26 −2
Original line number Diff line number Diff line
@@ -27,7 +27,10 @@ import android.content.Intent;
import android.media.RemoteController.OnClientUpdateListener;
import android.media.audiopolicy.AudioPolicy;
import android.media.audiopolicy.AudioPolicyConfig;
import android.media.session.MediaController;
import android.media.session.MediaSession;
import android.media.session.MediaSessionLegacyHelper;
import android.media.session.MediaSessionManager;
import android.os.Binder;
import android.os.Handler;
import android.os.IBinder;
@@ -2218,7 +2221,9 @@ public class AudioManager {
     *      that will receive the media button intent. This broadcast receiver must be declared
     *      in the application manifest. The package of the component must match that of
     *      the context you're registering from.
     * @deprecated Use {@link MediaSession#setMediaButtonReceiver(PendingIntent)} instead.
     */
    @Deprecated
    public void registerMediaButtonEventReceiver(ComponentName eventReceiver) {
        if (eventReceiver == null) {
            return;
@@ -2244,9 +2249,12 @@ public class AudioManager {
     * you know you will continue running for the full time until unregistering the
     * PendingIntent.
     * @param eventReceiver target that will receive media button intents.  The PendingIntent
     * will be sent as-is when a media button action occurs, with {@link Intent#EXTRA_KEY_EVENT}
     * added and holding the key code of the media button that was pressed.
     * will be sent an {@link Intent#ACTION_MEDIA_BUTTON} event when a media button action
     * occurs, with {@link Intent#EXTRA_KEY_EVENT} added and holding the key code of the
     * media button that was pressed.
     * @deprecated Use {@link MediaSession#setMediaButtonReceiver(PendingIntent)} instead.
     */
    @Deprecated
    public void registerMediaButtonEventReceiver(PendingIntent eventReceiver) {
        if (eventReceiver == null) {
            return;
@@ -2271,7 +2279,9 @@ public class AudioManager {
     * Unregister the receiver of MEDIA_BUTTON intents.
     * @param eventReceiver identifier of a {@link android.content.BroadcastReceiver}
     *      that was registered with {@link #registerMediaButtonEventReceiver(ComponentName)}.
     * @deprecated Use {@link MediaSession} instead.
     */
    @Deprecated
    public void unregisterMediaButtonEventReceiver(ComponentName eventReceiver) {
        if (eventReceiver == null) {
            return;
@@ -2289,7 +2299,9 @@ public class AudioManager {
     * Unregister the receiver of MEDIA_BUTTON intents.
     * @param eventReceiver same PendingIntent that was registed with
     *      {@link #registerMediaButtonEventReceiver(PendingIntent)}.
     * @deprecated Use {@link MediaSession} instead.
     */
    @Deprecated
    public void unregisterMediaButtonEventReceiver(PendingIntent eventReceiver) {
        if (eventReceiver == null) {
            return;
@@ -2311,7 +2323,9 @@ public class AudioManager {
     * @param rcClient The remote control client from which remote controls will receive
     *      information to display.
     * @see RemoteControlClient
     * @deprecated Use {@link MediaSession} instead.
     */
    @Deprecated
    public void registerRemoteControlClient(RemoteControlClient rcClient) {
        if ((rcClient == null) || (rcClient.getRcMediaIntent() == null)) {
            return;
@@ -2324,7 +2338,9 @@ public class AudioManager {
     * remote controls.
     * @param rcClient The remote control client to unregister.
     * @see #registerRemoteControlClient(RemoteControlClient)
     * @deprecated Use {@link MediaSession} instead.
     */
    @Deprecated
    public void unregisterRemoteControlClient(RemoteControlClient rcClient) {
        if ((rcClient == null) || (rcClient.getRcMediaIntent() == null)) {
            return;
@@ -2342,7 +2358,11 @@ public class AudioManager {
     * @param rctlr the object to register.
     * @return true if the {@link RemoteController} was successfully registered, false if an
     *     error occurred, due to an internal system error, or insufficient permissions.
     * @deprecated Use
     * {@link MediaSessionManager#addActiveSessionsListener(android.media.session.MediaSessionManager.SessionListener, ComponentName)}
     * and {@link MediaController} instead.
     */
    @Deprecated
    public boolean registerRemoteController(RemoteController rctlr) {
        if (rctlr == null) {
            return false;
@@ -2355,7 +2375,11 @@ public class AudioManager {
     * Unregisters a {@link RemoteController}, causing it to no longer receive media metadata and
     * playback state information, and no longer be capable of controlling playback.
     * @param rctlr the object to unregister.
     * @deprecated Use
     * {@link MediaSessionManager#removeActiveSessionsListener(android.media.session.MediaSessionManager.SessionListener)}
     * instead.
     */
    @Deprecated
    public void unregisterRemoteController(RemoteController rctlr) {
        if (rctlr == null) {
            return;
+3 −1
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ import android.graphics.Bitmap;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.format.Time;
import android.util.ArrayMap;
import android.util.Log;
import android.util.SparseArray;
@@ -73,7 +74,8 @@ public final class MediaMetadata implements Parcelable {
    public static final String METADATA_KEY_COMPILATION = "android.media.metadata.COMPILATION";

    /**
     * The date the media was created or published as TODO determine format.
     * The date the media was created or published. The format is unspecified
     * but RFC 3339 is recommended.
     */
    public static final String METADATA_KEY_DATE = "android.media.metadata.DATE";

+1 −2
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@
package android.media.session;

import android.app.PendingIntent;
import android.content.ComponentName;
import android.content.pm.ParceledListSlice;
import android.media.AudioAttributes;
import android.media.MediaMetadata;
@@ -37,7 +36,7 @@ interface ISession {
    void setFlags(int flags);
    void setActive(boolean active);
    void setMediaRouter(in IMediaRouter router);
    void setMediaButtonReceiver(in ComponentName mbr);
    void setMediaButtonReceiver(in PendingIntent mbr);
    void setLaunchPendingIntent(in PendingIntent pi);
    void destroy();

+6 −5
Original line number Diff line number Diff line
@@ -254,13 +254,14 @@ public final class MediaSession {
    }

    /**
     * Set a media button event receiver component to use to restart playback
     * after an app has been stopped.
     * Set a pending intent for your media button receiver to allow restarting
     * playback after the session has been stopped. If your app is started in
     * this way an {@link Intent#ACTION_MEDIA_BUTTON} intent will be sent via
     * the pending intent.
     *
     * @param mbr The receiver component to send the media button event to.
     * @hide
     * @param mbr The {@link PendingIntent} to send the media button event to.
     */
    public void setMediaButtonReceiver(@Nullable ComponentName mbr) {
    public void setMediaButtonReceiver(@Nullable PendingIntent mbr) {
        try {
            mBinder.setMediaButtonReceiver(mbr);
        } catch (RemoteException e) {
Loading