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

Commit 6e2e7801 authored by Toni Heidenreich's avatar Toni Heidenreich
Browse files

Improve MediaSession isActive documentation

The current documentation was partially misleading and didn't
fully spell out in all places that the main purpose is to
publish the session to the rest of the system (=make it
discoverable via MediaSessionManager.getActiveSessions)

Also update the log statement when the active state changed
to actually log the new active flag, which currently
accidentally logs the playback state (that is logged separately
whenever it changes).

Bug: 417853575
Test: n/a
Flag: EXEMPT log only change
Change-Id: I7658d26e158564b29dbe4cecc90826c8d5b0c8f2
parent 1a028d5b
Loading
Loading
Loading
Loading
+11 −5
Original line number Diff line number Diff line
@@ -73,7 +73,8 @@ import java.util.Objects;
 * create a {@link MediaController} to interact with the session.
 * <p>
 * To receive commands, media keys, and other events a {@link Callback} must be
 * set with {@link #setCallback(Callback)} and {@link #setActive(boolean)
 * set with {@link #setCallback(Callback)}. To make the session discoverable by
 * other apps, including system apps, {@link #setActive(boolean)
 * setActive(true)} must be called.
 * <p>
 * When an app is finished performing playback it must call {@link #release()}
@@ -398,10 +399,11 @@ public final class MediaSession {
    }

    /**
     * Set if this session is currently active and ready to receive commands. If
     * set to false your session's controller may not be discoverable. You must
     * set the session to active before it can start receiving media button
     * events or transport commands.
     * Set if this session is currently active.
     *
     * <p>If set to false then your session's controller will not be
     * discoverable via {@link MediaSessionManager#getActiveSessions(int)} by
     * other apps, including system apps.
     *
     * @param active Whether this session is active or not.
     */
@@ -420,6 +422,10 @@ public final class MediaSession {
    /**
     * Get the current active state of this session.
     *
     * <p>If false then your session's controller will not be discoverable via
     * {@link MediaSessionManager#getActiveSessions(int)} by other apps,
     * including system apps.
     *
     * @return True if the session is active, false otherwise.
     */
    public boolean isActive() {
+3 −3
Original line number Diff line number Diff line
@@ -170,7 +170,7 @@ public final class MediaSessionManager {
    }

    /**
     * Get a list of controllers for all ongoing sessions. The controllers will
     * Get a list of controllers for all active sessions. The controllers will
     * be provided in priority order with the most important controller at index
     * 0.
     * <p>
@@ -182,7 +182,7 @@ public final class MediaSessionManager {
     *
     * @param notificationListener The enabled notification listener component.
     *            May be null.
     * @return A list of controllers for ongoing sessions.
     * @return A list of controllers for active sessions.
     */
    public @NonNull List<MediaController> getActiveSessions(
            @Nullable ComponentName notificationListener) {
@@ -249,7 +249,7 @@ public final class MediaSessionManager {
     *
     * @param notificationListener The enabled notification listener component. May be null.
     * @param userHandle The user handle to fetch sessions for.
     * @return A list of controllers for ongoing sessions.
     * @return A list of controllers for active sessions.
     * @hide
     */
    @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
+2 −2
Original line number Diff line number Diff line
@@ -372,8 +372,8 @@ public class MediaSessionService extends SystemService implements Monitor {
                    "onSessionActiveStateChanged:"
                            + " record="
                            + record
                            + " playbackState="
                            + playbackState);
                            + " active="
                            + record.isActive());
            reportMediaInteractionEvent(record, isUserEngaged);
            mHandler.postSessionsChanged(record);
        }