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

Commit 5af27744 authored by Francois Gaffie's avatar Francois Gaffie Committed by Eric Laurent
Browse files

AudioService: fix redundant stream volume init



When applying volume from a VolumeGroupState,
skip stream volume update if this stream is already managed by a
VolumeStreamState.

Test: set Music volume & reboot & dumpsys audio
    Ensure indexes matches
Signed-off-by: default avatarFrancois Gaffie <francois.gaffie@renault.com>
Change-Id: If80f6324865d1fb076cc4de3ee72591e4653bf74
parent fa53b7a5
Loading
Loading
Loading
Loading
+27 −3
Original line number Diff line number Diff line
@@ -5250,14 +5250,29 @@ public class AudioService extends IAudioService.Stub
            return mIndexMin;
        }

        private boolean isValidLegacyStreamType() {
            return (mLegacyStreamType != AudioSystem.STREAM_DEFAULT)
                    && (mLegacyStreamType < mStreamStates.length);
        }

        public void applyAllVolumes() {
            synchronized (VolumeGroupState.class) {
                int deviceForStream = AudioSystem.DEVICE_NONE;
                int volumeIndexForStream = 0;
                if (isValidLegacyStreamType()) {
                    // Prevent to apply settings twice when group is associated to public stream
                    deviceForStream = getDeviceForStream(mLegacyStreamType);
                    volumeIndexForStream = getStreamVolume(mLegacyStreamType);
                }
                // apply device specific volumes first
                int index;
                for (int i = 0; i < mIndexMap.size(); i++) {
                    final int device = mIndexMap.keyAt(i);
                    if (device != AudioSystem.DEVICE_OUT_DEFAULT) {
                        index = mIndexMap.valueAt(i);
                        if (device == deviceForStream && volumeIndexForStream == index) {
                            continue;
                        }
                        if (DEBUG_VOL) {
                            Log.v(TAG, "applyAllVolumes: restore index " + index + " for group "
                                    + mAudioVolumeGroup.name() + " and device "
@@ -5273,6 +5288,13 @@ public class AudioService extends IAudioService.Stub
                    Log.v(TAG, "applyAllVolumes: restore default device index " + index
                            + " for group " + mAudioVolumeGroup.name());
                }
                if (isValidLegacyStreamType()) {
                    int defaultStreamIndex = (mStreamStates[mLegacyStreamType]
                            .getIndex(AudioSystem.DEVICE_OUT_DEFAULT) + 5) / 10;
                    if (defaultStreamIndex == index) {
                        return;
                    }
                }
                setVolumeIndexInt(index, AudioSystem.DEVICE_OUT_DEFAULT, 0 /*flags*/);
            }
        }
@@ -5283,8 +5305,9 @@ public class AudioService extends IAudioService.Stub
            }
            if (DEBUG_VOL) {
                Log.v(TAG, "persistVolumeGroup: storing index " + getIndex(device) + " for group "
                        + mAudioVolumeGroup.name() + " and device "
                        + AudioSystem.getOutputDeviceName(device));
                        + mAudioVolumeGroup.name()
                        + ", device " + AudioSystem.getOutputDeviceName(device)
                        + " and User=" + ActivityManager.getCurrentUser());
            }
            boolean success = Settings.System.putIntForUser(mContentResolver,
                    getSettingNameForDevice(device),
@@ -5319,7 +5342,8 @@ public class AudioService extends IAudioService.Stub
                    }
                    if (DEBUG_VOL) {
                        Log.v(TAG, "readSettings: found stored index " + getValidIndex(index)
                                 + " for group " + mAudioVolumeGroup.name() + ", device: " + name);
                                 + " for group " + mAudioVolumeGroup.name() + ", device: " + name
                                 + ", User=" + ActivityManager.getCurrentUser());
                    }
                    mIndexMap.put(device, getValidIndex(index));
                }