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
diff --git a/services/core/java/com/android/server/audio/AudioService.java b/services/core/java/com/android/server/audio/AudioService.java
index 4ea62ec..c19e1d2 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 @@
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 @@
private int mIndexMax;
private final ConcurrentHashMap<Integer, Integer> mIndex =
new ConcurrentHashMap<Integer, Integer>(8, 0.75f, 4);
+ private final Intent mVolumeChanged;
private VolumeStreamState(String settingName, int streamType) {
@@ -3517,6 +3508,8 @@
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 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 @@
}
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 @@
}
}
}
- 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) {