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

Commit 4bbcc654 authored by Eric Laurent's avatar Eric Laurent Committed by Jean-Baptiste Queru
Browse files

Display a fixed volume silder when docked.

Align UI indication to volume policy when docked: the music volume
cannot be adjusted when docked or connected to HDMI. Display
a disabled slider at max volume in this case to be consistent.

Bug 4335692.

Change-Id: I6f8db143b0e2ecf54e4bdacd88afdeb661a98a18
parent 3b772c6b
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -699,9 +699,12 @@ public class VolumePanel extends Handler implements OnSeekBarChangeListener, Vie
            if (sc.seekbarView.getMax() != max) {
                sc.seekbarView.setMax(max);
            }

            sc.seekbarView.setProgress(index);
            if (streamType != mAudioManager.getMasterStreamType()
                    && streamType != AudioService.STREAM_REMOTE_MUSIC && isMuted(streamType)) {
            if (((flags & AudioManager.FLAG_FIXED_VOLUME) != 0) ||
                    (streamType != mAudioManager.getMasterStreamType() &&
                     streamType != AudioService.STREAM_REMOTE_MUSIC &&
                     isMuted(streamType))) {
                sc.seekbarView.setEnabled(false);
            } else {
                sc.seekbarView.setEnabled(true);
+7 −0
Original line number Diff line number Diff line
@@ -313,6 +313,13 @@ public class AudioManager {
     */
    public static final int FLAG_VIBRATE = 1 << 4;

    /**
     * Indicates to VolumePanel that the volume slider should be disabled as user
     * cannot change the stream volume
     * @hide
     */
    public static final int FLAG_FIXED_VOLUME = 1 << 5;

    /**
     * Ringer mode that will be silent and will not vibrate. (This overrides the
     * vibrate setting.)
+113 −83
Original line number Diff line number Diff line
@@ -424,6 +424,11 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
     */
    public final static int STREAM_REMOTE_MUSIC = -200;

    // Devices for which the volume is fixed and VolumePanel slider should be disabled
    final int mFixedVolumeDevices = AudioSystem.DEVICE_OUT_AUX_DIGITAL |
            AudioSystem.DEVICE_OUT_DGTL_DOCK_HEADSET |
            AudioSystem.DEVICE_OUT_ALL_USB;

    ///////////////////////////////////////////////////////////////////////////
    // Construction
    ///////////////////////////////////////////////////////////////////////////
@@ -762,6 +767,15 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
            return;
        }

        int index;
        int oldIndex;

        if ((streamTypeAlias == AudioSystem.STREAM_MUSIC) &&
               ((device & mFixedVolumeDevices) != 0)) {
            flags |= AudioManager.FLAG_FIXED_VOLUME;
            index = mStreamStates[streamType].getMaxIndex();
            oldIndex = index;
        } else {
            // If either the client forces allowing ringer modes for this adjustment,
            // or the stream type is one that is affected by ringer modes
            if (((flags & AudioManager.FLAG_ALLOW_RINGER_MODES) != 0) ||
@@ -781,8 +795,7 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
            }

            // If stream is muted, adjust last audible index only
        int index;
        final int oldIndex = mStreamStates[streamType].getIndex(device,
            oldIndex = mStreamStates[streamType].getIndex(device,
                    (mStreamStates[streamType].muteCount() != 0) /* lastAudible */);

            if (streamState.muteCount() != 0) {
@@ -813,7 +826,7 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
                }
                index = mStreamStates[streamType].getIndex(device, false  /* lastAudible */);
            }

        }
        sendVolumeUpdate(streamType, oldIndex, index, flags);
    }

@@ -839,9 +852,16 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
        VolumeStreamState streamState = mStreamStates[mStreamVolumeAlias[streamType]];

        final int device = getDeviceForStream(streamType);
        int oldIndex;

        if ((mStreamVolumeAlias[streamType] == AudioSystem.STREAM_MUSIC) &&
                ((device & mFixedVolumeDevices) != 0)) {
            flags |= AudioManager.FLAG_FIXED_VOLUME;
            index = mStreamStates[streamType].getMaxIndex();
            oldIndex = index;
        } else {
            // get last audible index if stream is muted, current index otherwise
        final int oldIndex = streamState.getIndex(device,
            oldIndex = streamState.getIndex(device,
                                            (streamState.muteCount() != 0) /* lastAudible */);

            index = rescaleIndex(index * 10, streamType, mStreamVolumeAlias[streamType]);
@@ -872,7 +892,7 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
            // get last audible index if stream is muted, current index otherwise
            index = mStreamStates[streamType].getIndex(device,
                                    (mStreamStates[streamType].muteCount() != 0) /* lastAudible */);

        }
        sendVolumeUpdate(streamType, oldIndex, index, flags);
    }

@@ -988,6 +1008,7 @@ public class AudioService extends IAudioService.Stub implements OnFinished {

        mVolumePanel.postVolumeChanged(streamType, flags);

        if ((flags & AudioManager.FLAG_FIXED_VOLUME) == 0) {
            oldIndex = (oldIndex + 5) / 10;
            index = (index + 5) / 10;
            Intent intent = new Intent(AudioManager.VOLUME_CHANGED_ACTION);
@@ -996,6 +1017,7 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
            intent.putExtra(AudioManager.EXTRA_PREV_VOLUME_STREAM_VALUE, oldIndex);
            sendBroadcastToAll(intent);
        }
    }

    // UI update and Broadcast Intent
    private void sendMasterVolumeUpdate(int flags, int oldVolume, int newVolume) {
@@ -1109,7 +1131,15 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
    public int getStreamVolume(int streamType) {
        ensureValidStreamType(streamType);
        int device = getDeviceForStream(streamType);
        return (mStreamStates[streamType].getIndex(device, false  /* lastAudible */) + 5) / 10;
        int index;

        if ((mStreamVolumeAlias[streamType] == AudioSystem.STREAM_MUSIC) &&
                (device & mFixedVolumeDevices) != 0) {
            index = mStreamStates[streamType].getMaxIndex();
        } else {
            index = mStreamStates[streamType].getIndex(device, false  /* lastAudible */);
        }
        return (index + 5) / 10;
    }

    public int getMasterVolume() {