summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Atneya Nair <atneya@google.com> 2025-02-11 11:15:01 -0800
committer Atneya Nair <atneya@google.com> 2025-02-11 11:15:01 -0800
commit789cc0d07435800580f56a36b13b1845fed00792 (patch)
tree4a8f3ae08bd0e7c8b30d7b15115529e716b7fe40
parent289ca076a2774e88e3e228f75a0f08ba38e63f24 (diff)
[audio] Move sending volume intent to under lock
Modification of this intent is not thread safe. Since dispatching of the intent should be in-order wrt the actual set change, move all of the intent generation and enqueuing code underneath the VSS lock. Test: compiles Bug: 374206971 Flag: EXEMPT bugfix Change-Id: Id023eeed49db2e473e92e3e0d1b328054eacf2c7
-rw-r--r--services/core/java/com/android/server/audio/AudioService.java126
1 files changed, 66 insertions, 60 deletions
diff --git a/services/core/java/com/android/server/audio/AudioService.java b/services/core/java/com/android/server/audio/AudioService.java
index b48d0a6ed547..6b16b131ce0d 100644
--- a/services/core/java/com/android/server/audio/AudioService.java
+++ b/services/core/java/com/android/server/audio/AudioService.java
@@ -9708,72 +9708,78 @@ public class AudioService extends IAudioService.Stub
}
}
}
- }
- }
- if (changed) {
- // If associated to volume group, update group cache
- updateVolumeGroupIndex(device, /* forceMuteState= */ false);
-
- oldIndex = (oldIndex + 5) / 10;
- index = (index + 5) / 10;
- // log base stream changes to the event log
- if (sStreamVolumeAlias.get(mStreamType, /*valueIfKeyNotFound=*/-1) == mStreamType) {
- if (caller == null) {
- Log.w(TAG, "No caller for volume_changed event", new Throwable());
- }
- EventLogTags.writeVolumeChanged(mStreamType, oldIndex, index, mIndexMax / 10,
- caller);
- }
- // fire changed intents for all streams, but only when the device it changed on
- // is the current device
- if ((index != oldIndex) && isCurrentDevice) {
- // for single volume devices, only send the volume change broadcast
- // on the alias stream
- final int streamAlias = sStreamVolumeAlias.get(
- mStreamType, /*valueIfKeyNotFound=*/-1);
- if (!mIsSingleVolume || streamAlias == mStreamType) {
- mVolumeChanged.putExtra(AudioManager.EXTRA_VOLUME_STREAM_VALUE, index);
- mVolumeChanged.putExtra(AudioManager.EXTRA_PREV_VOLUME_STREAM_VALUE,
- oldIndex);
- int extraStreamType = mStreamType;
- // TODO: remove this when deprecating STREAM_BLUETOOTH_SCO
- if (isStreamBluetoothSco(mStreamType)) {
- mVolumeChanged.putExtra(AudioManager.EXTRA_VOLUME_STREAM_TYPE,
- AudioSystem.STREAM_BLUETOOTH_SCO);
- extraStreamType = AudioSystem.STREAM_BLUETOOTH_SCO;
- } else {
- mVolumeChanged.putExtra(AudioManager.EXTRA_VOLUME_STREAM_TYPE,
- mStreamType);
- }
- mVolumeChanged.putExtra(AudioManager.EXTRA_VOLUME_STREAM_TYPE_ALIAS,
- streamAlias);
-
- if (mStreamType == streamAlias) {
- String aliasStreamIndexesString = "";
- if (!aliasStreamIndexes.isEmpty()) {
- aliasStreamIndexesString =
- " aliased streams: " + aliasStreamIndexes;
- }
- AudioService.sVolumeLogger.enqueue(new VolChangedBroadcastEvent(
- extraStreamType, aliasStreamIndexesString, index, oldIndex));
- if (extraStreamType != mStreamType) {
- AudioService.sVolumeLogger.enqueue(new VolChangedBroadcastEvent(
- mStreamType, aliasStreamIndexesString, index, oldIndex));
+ if (changed) {
+ // If associated to volume group, update group cache
+ updateVolumeGroupIndex(device, /* forceMuteState= */ false);
+
+ oldIndex = (oldIndex + 5) / 10;
+ index = (index + 5) / 10;
+ // log base stream changes to the event log
+ if (sStreamVolumeAlias.get(mStreamType, /*valueIfKeyNotFound=*/-1)
+ == mStreamType) {
+ if (caller == null) {
+ Log.w(TAG, "No caller for volume_changed event", new Throwable());
}
+ EventLogTags.writeVolumeChanged(
+ mStreamType, oldIndex, index, mIndexMax / 10, caller);
}
- sendBroadcastToAll(mVolumeChanged, mVolumeChangedOptions);
- if (extraStreamType != mStreamType) {
- // send multiple intents in case we merged voice call and bt sco streams
- mVolumeChanged.putExtra(AudioManager.EXTRA_VOLUME_STREAM_TYPE,
- mStreamType);
- // do not use the options in thid case which could discard
- // the previous intent
- sendBroadcastToAll(mVolumeChanged, null);
+ // fire changed intents for all streams, but only when the device it changed
+ // on
+ // is the current device
+ if ((index != oldIndex) && isCurrentDevice) {
+ // for single volume devices, only send the volume change broadcast
+ // on the alias stream
+ final int streamAlias =
+ sStreamVolumeAlias.get(mStreamType, /*valueIfKeyNotFound=*/-1);
+ if (!mIsSingleVolume || streamAlias == mStreamType) {
+ mVolumeChanged.putExtra(
+ AudioManager.EXTRA_VOLUME_STREAM_VALUE, index);
+ mVolumeChanged.putExtra(
+ AudioManager.EXTRA_PREV_VOLUME_STREAM_VALUE, oldIndex);
+ int extraStreamType = mStreamType;
+ // TODO: remove this when deprecating STREAM_BLUETOOTH_SCO
+ if (isStreamBluetoothSco(mStreamType)) {
+ mVolumeChanged.putExtra(AudioManager.EXTRA_VOLUME_STREAM_TYPE,
+ AudioSystem.STREAM_BLUETOOTH_SCO);
+ extraStreamType = AudioSystem.STREAM_BLUETOOTH_SCO;
+ } else {
+ mVolumeChanged.putExtra(
+ AudioManager.EXTRA_VOLUME_STREAM_TYPE, mStreamType);
+ }
+ mVolumeChanged.putExtra(
+ AudioManager.EXTRA_VOLUME_STREAM_TYPE_ALIAS, streamAlias);
+
+ if (mStreamType == streamAlias) {
+ String aliasStreamIndexesString = "";
+ if (!aliasStreamIndexes.isEmpty()) {
+ aliasStreamIndexesString =
+ " aliased streams: " + aliasStreamIndexes;
+ }
+ AudioService.sVolumeLogger.enqueue(
+ new VolChangedBroadcastEvent(extraStreamType,
+ aliasStreamIndexesString, index, oldIndex));
+ if (extraStreamType != mStreamType) {
+ AudioService.sVolumeLogger.enqueue(
+ new VolChangedBroadcastEvent(mStreamType,
+ aliasStreamIndexesString, index, oldIndex));
+ }
+ }
+ sendBroadcastToAll(mVolumeChanged, mVolumeChangedOptions);
+ if (extraStreamType != mStreamType) {
+ // send multiple intents in case we merged voice call and bt sco
+ // streams
+ mVolumeChanged.putExtra(
+ AudioManager.EXTRA_VOLUME_STREAM_TYPE, mStreamType);
+ // do not use the options in thid case which could discard
+ // the previous intent
+ sendBroadcastToAll(mVolumeChanged, null);
+ }
+ }
}
}
+ return changed;
}
}
- return changed;
}
public int getIndex(int device) {