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

Commit 51fa6bcb authored by RoboErik's avatar RoboErik
Browse files

b/15757378 Expose APIs for listening to active sessions

This allows apps that are registered notification listeners to
listen to the set of active sessions.

Change-Id: I1e108951a5049d138208e88b155c0ec9b95fbdb0
parent bbc9cd32
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -15829,7 +15829,14 @@ package android.media.session {
  }
  public final class MediaSessionManager {
    method public void addActiveSessionsListener(android.media.session.MediaSessionManager.SessionListener, android.content.ComponentName);
    method public android.media.session.MediaSession createSession(java.lang.String);
    method public java.util.List<android.media.session.MediaController> getActiveSessions(android.content.ComponentName);
  }
  public static abstract class MediaSessionManager.SessionListener {
    ctor public MediaSessionManager.SessionListener();
    method public abstract void onActiveSessionsChanged(java.util.List<android.media.session.MediaController>);
  }
  public final class MediaSessionToken implements android.os.Parcelable {
+4 −3
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.os.SystemClock;
import android.os.UserHandle;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.KeyEvent;
@@ -793,12 +794,12 @@ public final class RemoteController
        final ComponentName listenerComponent = new ComponentName(mContext,
                mOnClientUpdateListener.getClass());
        mSessionManager.addActiveSessionsListener(mSessionListener, listenerComponent,
                ActivityManager.getCurrentUser());
                UserHandle.myUserId());
        mSessionListener.onActiveSessionsChanged(mSessionManager
                .getActiveSessions(listenerComponent));
        if (DEBUG) {
            Log.d(TAG, "Registered session listener with component " + listenerComponent
                    + " for user " + ActivityManager.getCurrentUser());
                    + " for user " + UserHandle.myUserId());
        }
    }

@@ -809,7 +810,7 @@ public final class RemoteController
        mSessionManager.removeActiveSessionsListener(mSessionListener);
        if (DEBUG) {
            Log.d(TAG, "Unregistered session listener for user "
                    + ActivityManager.getCurrentUser());
                    + UserHandle.myUserId());
        }
    }

+18 −3
Original line number Diff line number Diff line
@@ -109,7 +109,6 @@ public final class MediaSessionManager {
     * @param notificationListener The enabled notification listener component.
     *            May be null.
     * @return A list of controllers for ongoing sessions
     * @hide
     */
    public List<MediaController> getActiveSessions(ComponentName notificationListener) {
        return getActiveSessionsForUser(notificationListener, UserHandle.myUserId());
@@ -145,6 +144,24 @@ public final class MediaSessionManager {
        return controllers;
    }

    /**
     * Add a listener to be notified when the list of active sessions
     * changes.This requires the
     * android.Manifest.permission.MEDIA_CONTENT_CONTROL permission be held by
     * the calling app. You may also retrieve this list if your app is an
     * enabled notification listener using the
     * {@link NotificationListenerService} APIs, in which case you must pass the
     * {@link ComponentName} of your enabled listener.
     *
     * @param sessionListener The listener to add.
     * @param notificationListener The enabled notification listener component.
     *            May be null.
     */
    public void addActiveSessionsListener(SessionListener sessionListener,
            ComponentName notificationListener) {
        addActiveSessionsListener(sessionListener, notificationListener, UserHandle.myUserId());
    }

    /**
     * Add a listener to be notified when the list of active sessions
     * changes.This requires the
@@ -236,8 +253,6 @@ public final class MediaSessionManager {
    /**
     * Listens for changes to the list of active sessions. This can be added
     * using {@link #addActiveSessionsListener}.
     *
     * @hide
     */
    public static abstract class SessionListener {
        /**
+3 −0
Original line number Diff line number Diff line
@@ -383,6 +383,9 @@ public class MediaSessionService extends SystemService implements Monitor {
            // You may not access another user's content as an enabled listener.
            return false;
        }
        if (DEBUG) {
            Log.d(TAG, "Checking if enabled notification listener " + compName);
        }
        if (compName != null) {
            final String enabledNotifListeners = Settings.Secure.getStringForUser(mContentResolver,
                    Settings.Secure.ENABLED_NOTIFICATION_LISTENERS,