AudioService: fix volume behavior for dock devices

In AudioService.getDeviceVolumeBehaviorInt(), prefer using the
internal device type determined by the AudioDeviceAttributes constructor
rather than converting back from the derived SDK type. This avoids
potential double conversions (internal > SDK > internal) that can yeld
to problems in case of non bijective mapping from internal to SDK types
In AudioDeviceInfo.

Bug: 237378890
Test: make
Change-Id: I8ba167e719d2b060edd0dfe6c549273132cb85d8
This commit is contained in:
Eric Laurent
2022-11-18 12:04:19 +01:00
parent 858e21b54f
commit 4e57c38cc6

View File

@@ -6992,9 +6992,10 @@ public class AudioService extends IAudioService.Stub
private @AudioManager.DeviceVolumeBehavior
int getDeviceVolumeBehaviorInt(@NonNull AudioDeviceAttributes device) {
// translate Java device type to native device type (for the devices masks for full / fixed)
final int audioSystemDeviceOut = AudioDeviceInfo.convertDeviceTypeToInternalDevice(
device.getType());
// Get the internal type set by the AudioDeviceAttributes constructor which is always more
// exact (avoids double conversions) than a conversion from SDK type via
// AudioDeviceInfo.convertDeviceTypeToInternalDevice()
final int audioSystemDeviceOut = device.getInternalType();
int setDeviceVolumeBehavior = retrieveStoredDeviceVolumeBehavior(audioSystemDeviceOut);
if (setDeviceVolumeBehavior != AudioManager.DEVICE_VOLUME_BEHAVIOR_UNSET) {