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

Commit 131e63ad authored by RoboErik's avatar RoboErik
Browse files

Add extras to the PlaybackState

This allows apps to include extras that are atomic with play state
changes.

bug:18189125
bug:18103891
Change-Id: Ia3bc5b0dcf29960cb70e2ff3a67ec1fdd48b7a5a
parent 566c1ed1
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -16363,6 +16363,7 @@ package android.media.session {
    method public long getBufferedPosition();
    method public java.util.List<android.media.session.PlaybackState.CustomAction> getCustomActions();
    method public java.lang.CharSequence getErrorMessage();
    method public android.os.Bundle getExtras();
    method public long getLastPositionUpdateTime();
    method public float getPlaybackSpeed();
    method public long getPosition();
@@ -16407,6 +16408,7 @@ package android.media.session {
    method public android.media.session.PlaybackState.Builder setActiveQueueItemId(long);
    method public android.media.session.PlaybackState.Builder setBufferedPosition(long);
    method public android.media.session.PlaybackState.Builder setErrorMessage(java.lang.CharSequence);
    method public android.media.session.PlaybackState.Builder setExtras(android.os.Bundle);
    method public android.media.session.PlaybackState.Builder setState(int, long, float, long);
    method public android.media.session.PlaybackState.Builder setState(int, long, float);
  }
+31 −4
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@
package android.media.session;

import android.annotation.DrawableRes;
import android.annotation.Nullable;
import android.media.RemoteControlClient;
import android.os.Bundle;
import android.os.Parcel;
@@ -232,11 +233,12 @@ public final class PlaybackState implements Parcelable {
    private final CharSequence mErrorMessage;
    private final long mUpdateTime;
    private final long mActiveItemId;
    private final Bundle mExtras;

    private PlaybackState(int state, long position, long updateTime, float speed,
            long bufferedPosition, long transportControls,
            List<PlaybackState.CustomAction> customActions, long activeItemId,
            CharSequence error) {
            CharSequence error, Bundle extras) {
        mState = state;
        mPosition = position;
        mSpeed = speed;
@@ -246,6 +248,7 @@ public final class PlaybackState implements Parcelable {
        mCustomActions = new ArrayList<>(customActions);
        mActiveItemId = activeItemId;
        mErrorMessage = error;
        mExtras = extras;
    }

    private PlaybackState(Parcel in) {
@@ -258,7 +261,7 @@ public final class PlaybackState implements Parcelable {
        mCustomActions = in.createTypedArrayList(CustomAction.CREATOR);
        mActiveItemId = in.readLong();
        mErrorMessage = in.readCharSequence();

        mExtras = in.readBundle();
    }

    @Override
@@ -293,6 +296,7 @@ public final class PlaybackState implements Parcelable {
        dest.writeTypedList(mCustomActions);
        dest.writeLong(mActiveItemId);
        dest.writeCharSequence(mErrorMessage);
        dest.writeBundle(mExtras);
    }

    /**
@@ -394,6 +398,15 @@ public final class PlaybackState implements Parcelable {
        return mActiveItemId;
    }

    /**
     * Get any custom extras that were set on this playback state.
     *
     * @return The extras for this state or null.
     */
    public @Nullable Bundle getExtras() {
        return mExtras;
    }

    /**
     * Get the {@link PlaybackState} state for the given
     * {@link RemoteControlClient} state.
@@ -738,6 +751,7 @@ public final class PlaybackState implements Parcelable {
        private CharSequence mErrorMessage;
        private long mUpdateTime;
        private long mActiveItemId = MediaSession.QueueItem.UNKNOWN_ID;
        private Bundle mExtras;

        /**
         * Creates an initially empty state builder.
@@ -766,6 +780,7 @@ public final class PlaybackState implements Parcelable {
            mErrorMessage = from.mErrorMessage;
            mUpdateTime = from.mUpdateTime;
            mActiveItemId = from.mActiveItemId;
            mExtras = from.mExtras;
        }

        /**
@@ -948,13 +963,25 @@ public final class PlaybackState implements Parcelable {
        }

        /**
         * Build and return the {@link PlaybackState} instance with these values.
         * Set any custom extras to be included with the playback state.
         *
         * @param extras The extras to include.
         * @return this
         */
        public Builder setExtras(Bundle extras) {
            mExtras = extras;
            return this;
        }

        /**
         * Build and return the {@link PlaybackState} instance with these
         * values.
         *
         * @return A new state instance.
         */
        public PlaybackState build() {
            return new PlaybackState(mState, mPosition, mUpdateTime, mSpeed, mBufferedPosition,
                    mActions, mCustomActions, mActiveItemId, mErrorMessage);
                    mActions, mCustomActions, mActiveItemId, mErrorMessage, mExtras);
        }
    }
}