From 4e57c38cc6ec665f32be2ead7966aaf574f0cf7a Mon Sep 17 00:00:00 2001 From: Eric Laurent Date: Fri, 18 Nov 2022 12:04:19 +0100 Subject: [PATCH] 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 --- .../core/java/com/android/server/audio/AudioService.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/services/core/java/com/android/server/audio/AudioService.java b/services/core/java/com/android/server/audio/AudioService.java index 53fcf32935257..23535bfb9c248 100644 --- a/services/core/java/com/android/server/audio/AudioService.java +++ b/services/core/java/com/android/server/audio/AudioService.java @@ -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) {