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

Commit 0d0f67f5 authored by RoboErik's avatar RoboErik
Browse files

Update VolumeProvider apis per feedback

Added currentVolume to constructor.
Removed onGetCurrentVolume and notifyVolume changed.
Added setCurrentVolume and getCurrentVolume.
Updated javadoc to make it clear how they're used.

bug:17258168
Change-Id: I24388aab38824b101ccc18810caa09d46aa7afe0
parent 840bb008
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -15920,13 +15920,13 @@ package android.media {
  }
  public abstract class VolumeProvider {
    ctor public VolumeProvider(int, int);
    ctor public VolumeProvider(int, int, int);
    method public final int getCurrentVolume();
    method public final int getMaxVolume();
    method public final int getVolumeControl();
    method public final void notifyVolumeChanged();
    method public void onAdjustVolume(int);
    method public abstract int onGetCurrentVolume();
    method public void onSetVolumeTo(int);
    method public final void setCurrentVolume(int);
    field public static final int VOLUME_CONTROL_ABSOLUTE = 2; // 0x2
    field public static final int VOLUME_CONTROL_FIXED = 0; // 0x0
    field public static final int VOLUME_CONTROL_RELATIVE = 1; // 0x1
+4 −9
Original line number Diff line number Diff line
@@ -2131,7 +2131,7 @@ public class MediaRouter {
            if (mVolume != volume) {
                mVolume = volume;
                if (mSvp != null) {
                    mSvp.notifyVolumeChanged();
                    mSvp.setCurrentVolume(mVolume);
                }
                dispatchRouteVolumeChanged(this);
                if (mGroup != null) {
@@ -2217,7 +2217,7 @@ public class MediaRouter {
                // Only register a new listener if necessary
                if (mSvp == null || mSvp.getVolumeControl() != volumeControl
                        || mSvp.getMaxVolume() != mVolumeMax) {
                    mSvp = new SessionVolumeProvider(volumeControl, mVolumeMax);
                    mSvp = new SessionVolumeProvider(volumeControl, mVolumeMax, mVolume);
                    session.setPlaybackToRemote(mSvp);
                }
            } else {
@@ -2231,13 +2231,8 @@ public class MediaRouter {

        class SessionVolumeProvider extends VolumeProvider {

            public SessionVolumeProvider(int volumeControl, int maxVolume) {
                super(volumeControl, maxVolume);
            }

            @Override
            public int onGetCurrentVolume() {
                return mVcb == null ? 0 : mVcb.route.mVolume;
            public SessionVolumeProvider(int volumeControl, int maxVolume, int currentVolume) {
                super(volumeControl, maxVolume, currentVolume);
            }

            @Override
+30 −13
Original line number Diff line number Diff line
@@ -19,7 +19,9 @@ import android.media.session.MediaSession;

/**
 * Handles requests to adjust or set the volume on a session. This is also used
 * to push volume updates back to the session after a request has been handled.
 * to push volume updates back to the session. The provider must call
 * {@link #setCurrentVolume(int)} each time the volume being provided changes.
 * <p>
 * You can set a volume provider on a session by calling
 * {@link MediaSession#setPlaybackToRemote}.
 */
@@ -46,28 +48,25 @@ public abstract class VolumeProvider {

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

    /**
     * Create a new volume provider for handling volume events. You must specify
     * the type of volume control and the maximum volume that can be used.
     * 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.
     */
    public VolumeProvider(int volumeControl, int maxVolume) {
    public VolumeProvider(int volumeControl, int maxVolume, int currentVolume) {
        mControlType = volumeControl;
        mMaxVolume = maxVolume;
        mCurrentVolume = currentVolume;
    }

    /**
     * Get the current volume of the remote playback.
     *
     * @return The current volume.
     */
    public abstract int onGetCurrentVolume();

    /**
     * Get the volume control type that this volume provider uses.
     *
@@ -87,9 +86,23 @@ public abstract class VolumeProvider {
    }

    /**
     * Notify the system that the volume has been changed.
     * Gets the current volume. This will be the last value set by
     * {@link #setCurrentVolume(int)}.
     *
     * @return The current volume.
     */
    public final int getCurrentVolume() {
        return mCurrentVolume;
    }

    /**
     * Notify the system that the current volume has been changed. This must be
     * called every time the volume changes to ensure it is displayed properly.
     *
     * @param currentVolume The current volume on the output.
     */
    public final void notifyVolumeChanged() {
    public final void setCurrentVolume(int currentVolume) {
        mCurrentVolume = currentVolume;
        if (mCallback != null) {
            mCallback.onVolumeChanged(this);
        }
@@ -97,6 +110,8 @@ public abstract class VolumeProvider {

    /**
     * Override to handle requests to set the volume of the current output.
     * After the volume has been modified {@link #setCurrentVolume} must be
     * called to notify the system.
     *
     * @param volume The volume to set the output to.
     */
@@ -107,6 +122,8 @@ public abstract class VolumeProvider {
     * Override to handle requests to adjust the volume of the current output.
     * Direction will be one of {@link AudioManager#ADJUST_LOWER},
     * {@link AudioManager#ADJUST_RAISE}, {@link AudioManager#ADJUST_SAME}.
     * After the volume has been modified {@link #setCurrentVolume} must be
     * called to notify the system.
     *
     * @param direction The direction to change the volume in.
     */
+2 −2
Original line number Diff line number Diff line
@@ -300,7 +300,7 @@ public final class MediaSession {
        try {
            mBinder.setPlaybackToRemote(volumeProvider.getVolumeControl(),
                    volumeProvider.getMaxVolume());
            mBinder.setCurrentVolume(volumeProvider.onGetCurrentVolume());
            mBinder.setCurrentVolume(volumeProvider.getCurrentVolume());
        } catch (RemoteException e) {
            Log.wtf(TAG, "Failure in setPlaybackToRemote.", e);
        }
@@ -478,7 +478,7 @@ public final class MediaSession {
            return;
        }
        try {
            mBinder.setCurrentVolume(provider.onGetCurrentVolume());
            mBinder.setCurrentVolume(provider.getCurrentVolume());
        } catch (RemoteException e) {
            Log.e(TAG, "Error in notifyVolumeChanged", e);
        }