From a81b20a80ae556a4b93199c617a8fe467a4a6a3a Mon Sep 17 00:00:00 2001 From: Jean-Michel Trivi Date: Tue, 2 Jul 2019 09:28:16 -0700 Subject: [PATCH] Audio policy: fix HwModuleCollection::getDeviceDescriptor The deprecated method AudioManager.isBluetoothA2dpOn() calls getDeviceConnectionState on APM with an empty address, which caused HwModuleCollection::getDeviceDescriptor to set an empty address on the DeviceDescriptor for the currently connected A2DP device. This method is called by MediaRouter. When the address was reset, the java listener for audio device connection monitoring was reporting the connection of an A2DP device with an empty address, which in turn caused AvrcpManager to behave as if the audio device connection failed. If MediaRouter called isBluetoothA2dpOn() before AvrcpManager received its called for device connection, the error would occur. Bug: 132416679 Test: call isBluetoothA2dpOn() and check for valid address in dumpsys media.audio_policy Test: atest AudioServiceHostTest#testInjectForRecord ; atest AudioHostTest ; atest AudioPlaybackCaptureTest Change-Id: I1370edbbca46657506a990855d06a176f07c54d3 Merged-In: I1370edbbca46657506a990855d06a176f07c54d3 --- .../audiopolicy/common/managerdefinitions/src/HwModule.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/services/audiopolicy/common/managerdefinitions/src/HwModule.cpp b/services/audiopolicy/common/managerdefinitions/src/HwModule.cpp index 96a83377e1..1f9b725a24 100644 --- a/services/audiopolicy/common/managerdefinitions/src/HwModule.cpp +++ b/services/audiopolicy/common/managerdefinitions/src/HwModule.cpp @@ -333,9 +333,10 @@ sp HwModuleCollection::getDeviceDescriptor(const audio_devices if (encodedFormat != AUDIO_FORMAT_DEFAULT) { moduleDevice->setEncodedFormat(encodedFormat); } - moduleDevice->setAddress(devAddress); if (allowToCreate) { moduleDevice->attach(hwModule); + moduleDevice->setAddress(devAddress); + moduleDevice->setName(String8(name)); } return moduleDevice; }