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

Commit 272e161c authored by RoboErik's avatar RoboErik
Browse files

send volume button events to adjustSuggestedStream instead of adjustStream

This way the audio system can route the adjustments correctly when a bt
headset is connected.

bug:17281977
Change-Id: Ic41d038e47179baffc86e539562da285446148c7
parent 5dfa0a5f
Loading
Loading
Loading
Loading
+4 −0
Original line number Original line Diff line number Diff line
@@ -26,6 +26,10 @@ import com.android.server.LocalServices;
 */
 */
public abstract class AudioManagerInternal {
public abstract class AudioManagerInternal {


    public abstract void adjustSuggestedStreamVolumeForUid(int streamType, int direction,
            int flags,
            String callingPackage, int uid);

    public abstract void adjustStreamVolumeForUid(int streamType, int direction, int flags,
    public abstract void adjustStreamVolumeForUid(int streamType, int direction, int flags,
            String callingPackage, int uid);
            String callingPackage, int uid);


+16 −1
Original line number Original line Diff line number Diff line
@@ -904,6 +904,12 @@ public class AudioService extends IAudioService.Stub {
    /** @see AudioManager#adjustVolume(int, int) */
    /** @see AudioManager#adjustVolume(int, int) */
    public void adjustSuggestedStreamVolume(int direction, int suggestedStreamType, int flags,
    public void adjustSuggestedStreamVolume(int direction, int suggestedStreamType, int flags,
            String callingPackage) {
            String callingPackage) {
        adjustSuggestedStreamVolume(direction, suggestedStreamType, flags, callingPackage,
                Binder.getCallingUid());
    }

    private void adjustSuggestedStreamVolume(int direction, int suggestedStreamType, int flags,
            String callingPackage, int uid) {
        if (DEBUG_VOL) Log.d(TAG, "adjustSuggestedStreamVolume() stream="+suggestedStreamType
        if (DEBUG_VOL) Log.d(TAG, "adjustSuggestedStreamVolume() stream="+suggestedStreamType
                + ", flags=" + flags);
                + ", flags=" + flags);
        int streamType;
        int streamType;
@@ -928,7 +934,7 @@ public class AudioService extends IAudioService.Stub {
            if (DEBUG_VOL) Log.d(TAG, "Volume controller suppressed adjustment");
            if (DEBUG_VOL) Log.d(TAG, "Volume controller suppressed adjustment");
        }
        }


        adjustStreamVolume(streamType, direction, flags, callingPackage);
        adjustStreamVolume(streamType, direction, flags, callingPackage, uid);
    }
    }


    /** @see AudioManager#adjustStreamVolume(int, int, int) */
    /** @see AudioManager#adjustStreamVolume(int, int, int) */
@@ -5339,6 +5345,15 @@ public class AudioService extends IAudioService.Stub {
     * LocalServices.
     * LocalServices.
     */
     */
    final class AudioServiceInternal extends AudioManagerInternal {
    final class AudioServiceInternal extends AudioManagerInternal {

        @Override
        public void adjustSuggestedStreamVolumeForUid(int streamType, int direction, int flags,
                String callingPackage, int uid) {
            // direction and stream type swap here because the public
            // adjustSuggested has a different order than the other methods.
            adjustSuggestedStreamVolume(direction, streamType, flags, callingPackage, uid);
        }

        @Override
        @Override
        public void adjustStreamVolumeForUid(int streamType, int direction, int flags,
        public void adjustStreamVolumeForUid(int streamType, int direction, int flags,
                String callingPackage, int uid) {
                String callingPackage, int uid) {
+15 −4
Original line number Original line Diff line number Diff line
@@ -229,8 +229,14 @@ public class MediaSessionRecord implements IBinder.DeathRecipient {
     * {@link AudioManager#ADJUST_SAME}.
     * {@link AudioManager#ADJUST_SAME}.
     *
     *
     * @param direction The direction to adjust volume in.
     * @param direction The direction to adjust volume in.
     * @param flags Any of the flags from {@link AudioManager}.
     * @param packageName The package that made the original volume request.
     * @param uid The uid that made the original volume request.
     * @param useSuggested True to use adjustSuggestedStreamVolume instead of
     *            adjustStreamVolume.
     */
     */
    public void adjustVolume(int direction, int flags, String packageName, int uid) {
    public void adjustVolume(int direction, int flags, String packageName, int uid,
            boolean useSuggested) {
        if (isPlaybackActive(false) || hasFlag(MediaSession.FLAG_EXCLUSIVE_GLOBAL_PRIORITY)) {
        if (isPlaybackActive(false) || hasFlag(MediaSession.FLAG_EXCLUSIVE_GLOBAL_PRIORITY)) {
            flags &= ~AudioManager.FLAG_PLAY_SOUND;
            flags &= ~AudioManager.FLAG_PLAY_SOUND;
        }
        }
@@ -241,8 +247,13 @@ public class MediaSessionRecord implements IBinder.DeathRecipient {
        }
        }
        if (mVolumeType == PlaybackInfo.PLAYBACK_TYPE_LOCAL) {
        if (mVolumeType == PlaybackInfo.PLAYBACK_TYPE_LOCAL) {
            int stream = AudioAttributes.toLegacyStreamType(mAudioAttrs);
            int stream = AudioAttributes.toLegacyStreamType(mAudioAttrs);
            mAudioManagerInternal.adjustStreamVolumeForUid(stream, direction, flags, packageName,
            if (useSuggested) {
                    uid);
                mAudioManagerInternal.adjustSuggestedStreamVolumeForUid(stream, direction, flags,
                        packageName, uid);
            } else {
                mAudioManagerInternal.adjustStreamVolumeForUid(stream, direction, flags,
                        packageName, uid);
            }
        } else {
        } else {
            if (mVolumeControlType == VolumeProvider.VOLUME_CONTROL_FIXED) {
            if (mVolumeControlType == VolumeProvider.VOLUME_CONTROL_FIXED) {
                // Nothing to do, the volume cannot be changed
                // Nothing to do, the volume cannot be changed
@@ -1020,7 +1031,7 @@ public class MediaSessionRecord implements IBinder.DeathRecipient {
            int uid = Binder.getCallingUid();
            int uid = Binder.getCallingUid();
            final long token = Binder.clearCallingIdentity();
            final long token = Binder.clearCallingIdentity();
            try {
            try {
                MediaSessionRecord.this.adjustVolume(direction, flags, packageName, uid);
                MediaSessionRecord.this.adjustVolume(direction, flags, packageName, uid, false);
            } finally {
            } finally {
                Binder.restoreCallingIdentity(token);
                Binder.restoreCallingIdentity(token);
            }
            }
+1 −1
Original line number Original line Diff line number Diff line
@@ -814,7 +814,7 @@ public class MediaSessionService extends SystemService implements Monitor {
                }
                }
            } else {
            } else {
                session.adjustVolume(direction, flags, getContext().getPackageName(),
                session.adjustVolume(direction, flags, getContext().getPackageName(),
                        UserHandle.myUserId());
                        UserHandle.myUserId(), true);
                if (session.getPlaybackType() == PlaybackInfo.PLAYBACK_TYPE_REMOTE
                if (session.getPlaybackType() == PlaybackInfo.PLAYBACK_TYPE_REMOTE
                        && mRvc != null) {
                        && mRvc != null) {
                    try {
                    try {