From f63860cd8072bc9a9e5178ff3b60d262999c78fc Mon Sep 17 00:00:00 2001 From: John Spurlock Date: Thu, 19 Feb 2015 09:46:27 -0500 Subject: [PATCH] AudioService: Fire volume-changed intents for all streams. Allow observing all stream changed events, including streams that are bound to another stream via aliasing. Change-Id: I2c1717ce632c4cb045c06785cb1ecc531a221ff8 --- .../android/server/audio/AudioService.java | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/services/core/java/com/android/server/audio/AudioService.java b/services/core/java/com/android/server/audio/AudioService.java index 4ea62ecd0ae69..c19e1d29bb054 100644 --- a/services/core/java/com/android/server/audio/AudioService.java +++ b/services/core/java/com/android/server/audio/AudioService.java @@ -1459,16 +1459,6 @@ public class AudioService extends IAudioService.Stub { flags = updateFlagsForSystemAudio(flags); } mVolumeController.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); - intent.putExtra(AudioManager.EXTRA_VOLUME_STREAM_TYPE, streamType); - intent.putExtra(AudioManager.EXTRA_VOLUME_STREAM_VALUE, index); - intent.putExtra(AudioManager.EXTRA_PREV_VOLUME_STREAM_VALUE, oldIndex); - sendBroadcastToAll(intent); - } } // If Hdmi-CEC system audio mode is on, we show volume bar only when TV @@ -3506,6 +3496,7 @@ public class AudioService extends IAudioService.Stub { private int mIndexMax; private final ConcurrentHashMap mIndex = new ConcurrentHashMap(8, 0.75f, 4); + private final Intent mVolumeChanged; private VolumeStreamState(String settingName, int streamType) { @@ -3517,6 +3508,8 @@ public class AudioService extends IAudioService.Stub { mIndexMax *= 10; readSettings(); + mVolumeChanged = new Intent(AudioManager.VOLUME_CHANGED_ACTION); + mVolumeChanged.putExtra(AudioManager.EXTRA_VOLUME_STREAM_TYPE, mStreamType); } public String getSettingNameForDevice(int device) { @@ -3631,8 +3624,10 @@ public class AudioService extends IAudioService.Stub { } public boolean setIndex(int index, int device) { + boolean changed = false; + int oldIndex; synchronized (VolumeStreamState.class) { - int oldIndex = getIndex(device); + oldIndex = getIndex(device); index = getValidIndex(index); synchronized (mCameraSoundForced) { if ((mStreamType == AudioSystem.STREAM_SYSTEM_ENFORCED) && mCameraSoundForced) { @@ -3641,7 +3636,8 @@ public class AudioService extends IAudioService.Stub { } mIndex.put(device, index); - if (oldIndex != index) { + changed = oldIndex != index; + if (changed) { // Apply change to all streams using this one as alias // if changing volume of current device, also change volume of current // device on aliased stream @@ -3659,11 +3655,16 @@ public class AudioService extends IAudioService.Stub { } } } - return true; - } else { - return false; } } + if (changed) { + oldIndex = (oldIndex + 5) / 10; + index = (index + 5) / 10; + mVolumeChanged.putExtra(AudioManager.EXTRA_VOLUME_STREAM_VALUE, index); + mVolumeChanged.putExtra(AudioManager.EXTRA_PREV_VOLUME_STREAM_VALUE, oldIndex); + sendBroadcastToAll(mVolumeChanged); + } + return changed; } public int getIndex(int device) {