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

Commit 830fd703 authored by RoboErik's avatar RoboErik Committed by Android Git Automerger
Browse files

am c7ed6f69: Merge "Minimum work to make volume handling work with sessions" into lmp-preview-dev

* commit 'c7ed6f69d474f23df89d36ed94ff0062daa8dcbc':
  Minimum work to make volume handling work with sessions
parents e2c6327a e78755e1
Loading
Loading
Loading
Loading
+13 −3
Original line number Diff line number Diff line
@@ -643,9 +643,14 @@ public class AudioManager {
        try {
            if (mUseMasterVolume) {
                service.adjustMasterVolume(direction, flags, mContext.getOpPackageName());
            } else {
                if (USE_SESSIONS) {
                    MediaSessionLegacyHelper helper = MediaSessionLegacyHelper.getHelper(mContext);
                    helper.sendAdjustVolumeBy(USE_DEFAULT_STREAM_TYPE, direction, flags);
                } else {
                    service.adjustVolume(direction, flags, mContext.getOpPackageName());
                }
            }
        } catch (RemoteException e) {
            Log.e(TAG, "Dead object in adjustVolume", e);
        }
@@ -673,10 +678,15 @@ public class AudioManager {
        try {
            if (mUseMasterVolume) {
                service.adjustMasterVolume(direction, flags, mContext.getOpPackageName());
            } else {
                if (USE_SESSIONS) {
                    MediaSessionLegacyHelper helper = MediaSessionLegacyHelper.getHelper(mContext);
                    helper.sendAdjustVolumeBy(suggestedStreamType, direction, flags);
                } else {
                    service.adjustSuggestedStreamVolume(direction, suggestedStreamType, flags,
                            mContext.getOpPackageName());
                }
            }
        } catch (RemoteException e) {
            Log.e(TAG, "Dead object in adjustSuggestedStreamVolume", e);
        }
+4 −0
Original line number Diff line number Diff line
@@ -47,4 +47,8 @@ interface ISession {
    void setMetadata(in MediaMetadata metadata);
    void setPlaybackState(in PlaybackState state);
    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 Diff line number Diff line
@@ -45,4 +45,8 @@ oneway interface ISessionCallback {
    void onRewind();
    void onSeekTo(long pos);
    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 Diff line number Diff line
@@ -29,4 +29,5 @@ interface ISessionManager {
    ISession createSession(String packageName, in ISessionCallback cb, String tag, int userId);
    List<IBinder> getSessions(in ComponentName compName, int userId);
    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 Diff line number Diff line
@@ -124,9 +124,21 @@ public final class MediaSession {
     */
    public static final int DISCONNECT_REASON_SESSION_DESTROYED = 5;

    private static final String KEY_COMMAND = "command";
    private static final String KEY_EXTRAS = "extras";
    private static final String KEY_CALLBACK = "callback";
    /**
     * The session uses local playback. Used for configuring volume handling
     * 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();

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

    private Route mRoute;
    private RemoteVolumeProvider mVolumeProvider;

    private boolean mActive = false;;

@@ -242,7 +255,11 @@ public final class MediaSession {
     * @param stream The {@link AudioManager} stream this session is playing on.
     */
    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) {
            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 {
Loading