AudioService: setDeviceVolume no-op when for current device
Disregard device volume commands when addressed for the current device for that stream type. Current use of this API is to control unused/disconnected devices, so doing this prevents - adjusting the volume outside of the legacy volume APIs - prevents feedback loop is the user is using ACTION_VOLUME_CHANGED to react to volume changes, and is issuing volume commands on a device in use. Bug: 267412093 Bug: 271473257 Test: dock/undock Change-Id: Ibc14d28ad9a881ea41c619815f32cfde1f1b7885
This commit is contained in:
@@ -3989,8 +3989,15 @@ public class AudioService extends IAudioService.Stub
|
||||
// VOLUME_CHANGED_ACTION intent to see if the current device is the one being modified
|
||||
final int currDev = getDeviceForStream(vi.getStreamType());
|
||||
|
||||
final boolean skipping = (currDev == ada.getInternalType());
|
||||
|
||||
AudioService.sVolumeLogger.enqueue(new DeviceVolumeEvent(vi.getStreamType(), index, ada,
|
||||
currDev, callingPackage));
|
||||
currDev, callingPackage, skipping));
|
||||
|
||||
if (skipping) {
|
||||
// setDeviceVolume was called on a device currently being used
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO handle unmuting of current audio device
|
||||
// if a stream is not muted but the VolumeInfo is for muting, set the volume index
|
||||
|
||||
@@ -175,15 +175,17 @@ public class AudioServiceEvents {
|
||||
final String mDeviceAddress;
|
||||
final String mCaller;
|
||||
final int mDeviceForStream;
|
||||
final boolean mSkipped;
|
||||
|
||||
DeviceVolumeEvent(int streamType, int index, @NonNull AudioDeviceAttributes device,
|
||||
int deviceForStream, String callingPackage) {
|
||||
int deviceForStream, String callingPackage, boolean skipped) {
|
||||
mStream = streamType;
|
||||
mVolIndex = index;
|
||||
mDeviceNativeType = "0x" + Integer.toHexString(device.getInternalType());
|
||||
mDeviceAddress = device.getAddress();
|
||||
mDeviceForStream = deviceForStream;
|
||||
mCaller = callingPackage;
|
||||
mSkipped = skipped;
|
||||
// log metrics
|
||||
new MediaMetrics.Item(MediaMetrics.Name.AUDIO_VOLUME_EVENT)
|
||||
.set(MediaMetrics.Property.EVENT, "setDeviceVolume")
|
||||
@@ -198,14 +200,18 @@ public class AudioServiceEvents {
|
||||
|
||||
@Override
|
||||
public String eventToString() {
|
||||
return new StringBuilder("setDeviceVolume(stream:")
|
||||
final StringBuilder sb = new StringBuilder("setDeviceVolume(stream:")
|
||||
.append(AudioSystem.streamToString(mStream))
|
||||
.append(" index:").append(mVolIndex)
|
||||
.append(" device:").append(mDeviceNativeType)
|
||||
.append(" addr:").append(mDeviceAddress)
|
||||
.append(") from ").append(mCaller)
|
||||
.append(" currDevForStream:Ox").append(Integer.toHexString(mDeviceForStream))
|
||||
.toString();
|
||||
.append(") from ").append(mCaller);
|
||||
if (mSkipped) {
|
||||
sb.append(" skipped [device in use]");
|
||||
} else {
|
||||
sb.append(" currDevForStream:Ox").append(Integer.toHexString(mDeviceForStream));
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user