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

Commit 77b46edc authored by Kyunglyul Hyun's avatar Kyunglyul Hyun Committed by Android (Google) Code Review
Browse files

Merge "MediaSession: Add volumeControlId in MediaCotnroller.PlaybackInfo"

parents e33a992c bef875cd
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -27141,9 +27141,11 @@ package android.media {
  public abstract class VolumeProvider {
    ctor public VolumeProvider(int, int, int);
    ctor public VolumeProvider(int, int, int, @Nullable String);
    method public final int getCurrentVolume();
    method public final int getMaxVolume();
    method public final int getVolumeControl();
    method @Nullable public final String getVolumeControlId();
    method public void onAdjustVolume(int);
    method public void onSetVolumeTo(int);
    method public final void setCurrentVolume(int);
@@ -28003,6 +28005,7 @@ package android.media.session {
    method public int getMaxVolume();
    method public int getPlaybackType();
    method public int getVolumeControl();
    method @Nullable public String getVolumeControlId();
    method public void writeToParcel(android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.media.session.MediaController.PlaybackInfo> CREATOR;
    field public static final int PLAYBACK_TYPE_LOCAL = 1; // 0x1
+31 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@
package android.media;

import android.annotation.IntDef;
import android.annotation.Nullable;
import android.media.session.MediaSession;

import java.lang.annotation.Retention;
@@ -60,6 +61,7 @@ public abstract class VolumeProvider {

    private final int mControlType;
    private final int mMaxVolume;
    private final String mControlId;
    private int mCurrentVolume;
    private Callback mCallback;

@@ -73,10 +75,28 @@ public abstract class VolumeProvider {
     * @param maxVolume The maximum allowed volume.
     * @param currentVolume The current volume on the output.
     */

    public VolumeProvider(@ControlType int volumeControl, int maxVolume, int currentVolume) {
        this(volumeControl, maxVolume, currentVolume, null);
    }

    /**
     * Create a new volume provider for handling volume events. You must specify
     * the type of volume control, the maximum volume that can be used, and the
     * current volume on the output.
     *
     * @param volumeControl The method for controlling volume that is used by
     *            this provider.
     * @param maxVolume The maximum allowed volume.
     * @param currentVolume The current volume on the output.
     * @param volumeControlId The volume control id of this provider.
     */
    public VolumeProvider(@ControlType int volumeControl, int maxVolume, int currentVolume,
            @Nullable String volumeControlId) {
        mControlType = volumeControl;
        mMaxVolume = maxVolume;
        mCurrentVolume = currentVolume;
        mControlId = volumeControlId;
    }

    /**
@@ -121,6 +141,17 @@ public abstract class VolumeProvider {
        }
    }

    /**
     * Gets the volume control id. It can be used to identify which volume provider is
     * used by the session.
     *
     * @return the volume control id or {@code null} if it isn't set.
     */
    @Nullable
    public final String getVolumeControlId() {
        return mControlId;
    }

    /**
     * Override to handle requests to set the volume of the current output.
     * After the volume has been modified {@link #setCurrentVolume} must be
+1 −1
Original line number Diff line number Diff line
@@ -48,6 +48,6 @@ interface ISession {

    // These commands relate to volume handling
    void setPlaybackToLocal(in AudioAttributes attributes);
    void setPlaybackToRemote(int control, int max);
    void setPlaybackToRemote(int control, int max, @nullable String controlId);
    void setCurrentVolume(int currentVolume);
}
+26 −1
Original line number Diff line number Diff line
@@ -964,16 +964,26 @@ public final class MediaController {
        private final int mMaxVolume;
        private final int mCurrentVolume;
        private final AudioAttributes mAudioAttrs;
        private final String mVolumeControlId;

        /**
         * @hide
         */
        public PlaybackInfo(int type, int control, int max, int current, AudioAttributes attrs) {
            this(type, control, max, current, attrs, null);
        }

        /**
         * @hide
         */
        public PlaybackInfo(int type, int control, int max, int current, AudioAttributes attrs,
                String volumeControlId) {
            mVolumeType = type;
            mVolumeControl = control;
            mMaxVolume = max;
            mCurrentVolume = current;
            mAudioAttrs = attrs;
            mVolumeControlId = volumeControlId;
        }

        PlaybackInfo(Parcel in) {
@@ -982,6 +992,7 @@ public final class MediaController {
            mMaxVolume = in.readInt();
            mCurrentVolume = in.readInt();
            mAudioAttrs = in.readParcelable(null);
            mVolumeControlId = in.readString();
        }

        /**
@@ -1042,11 +1053,24 @@ public final class MediaController {
            return mAudioAttrs;
        }

        /**
         * Gets the volume control ID for this session. It can be used to identify which
         * volume provider is used by the session.
         *
         * @return the volume control ID for this session or {@code null} if it's local playback
         * or not set.
         * @see VolumeProvider#getVolumeControlId()
         */
        @Nullable
        public String getVolumeControlId() {
            return mVolumeControlId;
        }

        @Override
        public String toString() {
            return "volumeType=" + mVolumeType + ", volumeControl=" + mVolumeControl
                    + ", maxVolume=" + mMaxVolume + ", currentVolume=" + mCurrentVolume
                    + ", audioAttrs=" + mAudioAttrs;
                    + ", audioAttrs=" + mAudioAttrs + ", volumeControlId=" + mVolumeControlId;
        }

        @Override
@@ -1061,6 +1085,7 @@ public final class MediaController {
            dest.writeInt(mMaxVolume);
            dest.writeInt(mCurrentVolume);
            dest.writeParcelable(mAudioAttrs, flags);
            dest.writeString(mVolumeControlId);
        }

        public static final @android.annotation.NonNull Parcelable.Creator<PlaybackInfo> CREATOR =
+1 −1
Original line number Diff line number Diff line
@@ -335,7 +335,7 @@ public final class MediaSession {

        try {
            mBinder.setPlaybackToRemote(volumeProvider.getVolumeControl(),
                    volumeProvider.getMaxVolume());
                    volumeProvider.getMaxVolume(), volumeProvider.getVolumeControlId());
            mBinder.setCurrentVolume(volumeProvider.getCurrentVolume());
        } catch (RemoteException e) {
            Log.wtf(TAG, "Failure in setPlaybackToRemote.", e);
Loading