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

Commit b69ffd4d authored by RoboErik's avatar RoboErik
Browse files

Minimum work to make volume handling work with sessions

This is the minimum change to make adjusting volume work with
MediaSessions. This only affects adjusting the volume and adjusting
the volume with a suggested stream. Adjusting a specific stream or
setting a specific stream will still use the same code.

This does not fix existing remote volume handling in RCC, which
will require a separate change to MediaController.

Change-Id: I5b957ff4bece1ee11e2364e1f216e1c08343c983
parent 283c907a
Loading
Loading
Loading
Loading
+13 −3
Original line number Original line Diff line number Diff line
@@ -634,9 +634,14 @@ public class AudioManager {
        try {
        try {
            if (mUseMasterVolume) {
            if (mUseMasterVolume) {
                service.adjustMasterVolume(direction, flags, mContext.getOpPackageName());
                service.adjustMasterVolume(direction, flags, mContext.getOpPackageName());
            } else {
                if (USE_SESSIONS) {
                    MediaSessionLegacyHelper helper = MediaSessionLegacyHelper.getHelper(mContext);
                    helper.sendAdjustVolumeBy(USE_DEFAULT_STREAM_TYPE, direction, flags);
                } else {
                } else {
                    service.adjustVolume(direction, flags, mContext.getOpPackageName());
                    service.adjustVolume(direction, flags, mContext.getOpPackageName());
                }
                }
            }
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            Log.e(TAG, "Dead object in adjustVolume", e);
            Log.e(TAG, "Dead object in adjustVolume", e);
        }
        }
@@ -664,10 +669,15 @@ public class AudioManager {
        try {
        try {
            if (mUseMasterVolume) {
            if (mUseMasterVolume) {
                service.adjustMasterVolume(direction, flags, mContext.getOpPackageName());
                service.adjustMasterVolume(direction, flags, mContext.getOpPackageName());
            } else {
                if (USE_SESSIONS) {
                    MediaSessionLegacyHelper helper = MediaSessionLegacyHelper.getHelper(mContext);
                    helper.sendAdjustVolumeBy(suggestedStreamType, direction, flags);
                } else {
                } else {
                    service.adjustSuggestedStreamVolume(direction, suggestedStreamType, flags,
                    service.adjustSuggestedStreamVolume(direction, suggestedStreamType, flags,
                            mContext.getOpPackageName());
                            mContext.getOpPackageName());
                }
                }
            }
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            Log.e(TAG, "Dead object in adjustSuggestedStreamVolume", e);
            Log.e(TAG, "Dead object in adjustSuggestedStreamVolume", e);
        }
        }
+4 −0
Original line number Original line Diff line number Diff line
@@ -47,4 +47,8 @@ interface ISession {
    void setMetadata(in MediaMetadata metadata);
    void setMetadata(in MediaMetadata metadata);
    void setPlaybackState(in PlaybackState state);
    void setPlaybackState(in PlaybackState state);
    void setRatingType(int type);
    void setRatingType(int type);

    // These commands relate to volume handling
    void configureVolumeHandling(int type, int arg1, int arg2);
    void setCurrentVolume(int currentVolume);
}
}
 No newline at end of file
+4 −0
Original line number Original line Diff line number Diff line
@@ -45,4 +45,8 @@ oneway interface ISessionCallback {
    void onRewind();
    void onRewind();
    void onSeekTo(long pos);
    void onSeekTo(long pos);
    void onRate(in Rating rating);
    void onRate(in Rating rating);

    // These callbacks are for volume handling
    void onAdjustVolumeBy(int delta);
    void onSetVolumeTo(int value);
}
}
 No newline at end of file
+1 −0
Original line number Original line Diff line number Diff line
@@ -29,4 +29,5 @@ interface ISessionManager {
    ISession createSession(String packageName, in ISessionCallback cb, String tag, int userId);
    ISession createSession(String packageName, in ISessionCallback cb, String tag, int userId);
    List<IBinder> getSessions(in ComponentName compName, int userId);
    List<IBinder> getSessions(in ComponentName compName, int userId);
    void dispatchMediaKeyEvent(in KeyEvent keyEvent, boolean needWakeLock);
    void dispatchMediaKeyEvent(in KeyEvent keyEvent, boolean needWakeLock);
    void dispatchAdjustVolumeBy(int suggestedStream, int delta, int flags);
}
}
 No newline at end of file
+49 −5
Original line number Original line Diff line number Diff line
@@ -124,9 +124,21 @@ public final class MediaSession {
     */
     */
    public static final int DISCONNECT_REASON_SESSION_DESTROYED = 5;
    public static final int DISCONNECT_REASON_SESSION_DESTROYED = 5;


    private static final String KEY_COMMAND = "command";
    /**
    private static final String KEY_EXTRAS = "extras";
     * The session uses local playback. Used for configuring volume handling
    private static final String KEY_CALLBACK = "callback";
     * with the system.
     *
     * @hide
     */
    public static final int VOLUME_TYPE_LOCAL = 1;

    /**
     * The session uses remote playback. Used for configuring volume handling
     * with the system.
     *
     * @hide
     */
    public static final int VOLUME_TYPE_REMOTE = 2;


    private final Object mLock = new Object();
    private final Object mLock = new Object();


@@ -143,6 +155,7 @@ public final class MediaSession {
            = new ArrayMap<String, RouteInterface.EventListener>();
            = new ArrayMap<String, RouteInterface.EventListener>();


    private Route mRoute;
    private Route mRoute;
    private RemoteVolumeProvider mVolumeProvider;


    private boolean mActive = false;;
    private boolean mActive = false;;


@@ -242,7 +255,11 @@ public final class MediaSession {
     * @param stream The {@link AudioManager} stream this session is playing on.
     * @param stream The {@link AudioManager} stream this session is playing on.
     */
     */
    public void setPlaybackToLocal(int stream) {
    public void setPlaybackToLocal(int stream) {
        // TODO
        try {
            mBinder.configureVolumeHandling(VOLUME_TYPE_LOCAL, stream, 0);
        } catch (RemoteException e) {
            Log.wtf(TAG, "Failure in setPlaybackToLocal.", e);
        }
    }
    }


    /**
    /**
@@ -259,7 +276,14 @@ public final class MediaSession {
        if (volumeProvider == null) {
        if (volumeProvider == null) {
            throw new IllegalArgumentException("volumeProvider may not be null!");
            throw new IllegalArgumentException("volumeProvider may not be null!");
        }
        }
        // TODO
        mVolumeProvider = volumeProvider;

        try {
            mBinder.configureVolumeHandling(VOLUME_TYPE_REMOTE, volumeProvider.getVolumeControl(),
                    volumeProvider.getMaxVolume());
        } catch (RemoteException e) {
            Log.wtf(TAG, "Failure in setPlaybackToRemote.", e);
        }
    }
    }


    /**
    /**
@@ -942,6 +966,26 @@ public final class MediaSession {


        }
        }


        /*
         * (non-Javadoc)
         * @see android.media.session.ISessionCallback#onAdjustVolumeBy(int)
         */
        @Override
        public void onAdjustVolumeBy(int delta) throws RemoteException {
            // TODO(epastern): Auto-generated method stub

        }

        /*
         * (non-Javadoc)
         * @see android.media.session.ISessionCallback#onSetVolumeTo(int)
         */
        @Override
        public void onSetVolumeTo(int value) throws RemoteException {
            // TODO(epastern): Auto-generated method stub

        }

    }
    }


    private class CallbackMessageHandler extends Handler {
    private class CallbackMessageHandler extends Handler {
Loading