diff --git a/services/audio_policy/server/include/service/audio_policy_service.h b/services/audio_policy/server/include/service/audio_policy_service.h index 50cc40bcdd017c3dc59a114535f5bc315f05c92b..f2d224c5a31ffda2b77f51b264fd36a714d45c2a 100644 --- a/services/audio_policy/server/include/service/audio_policy_service.h +++ b/services/audio_policy/server/include/service/audio_policy_service.h @@ -237,7 +237,7 @@ private: int32_t ActivateNewDevice(std::string networkId, DeviceType deviceType, bool isRemote); - DeviceType FetchHighPriorityDevice(); + DeviceType FetchHighPriorityDevice(bool isOutputDevice); void UpdateConnectedDevices(const AudioDeviceDescriptor& deviceDescriptor, std::vector>& desc, bool status); @@ -301,13 +301,20 @@ private: DEVICE_TYPE_USB_HEADSET, DEVICE_TYPE_WIRED_HEADSET }; - std::vector priorityList = { + std::vector outputPriorityList_ = { DEVICE_TYPE_BLUETOOTH_SCO, DEVICE_TYPE_BLUETOOTH_A2DP, DEVICE_TYPE_USB_HEADSET, DEVICE_TYPE_WIRED_HEADSET, DEVICE_TYPE_SPEAKER }; + std::vector inputPriorityList_ = { + DEVICE_TYPE_BLUETOOTH_SCO, + DEVICE_TYPE_BLUETOOTH_A2DP, + DEVICE_TYPE_USB_HEADSET, + DEVICE_TYPE_WIRED_HEADSET, + DEVICE_TYPE_MIC + }; std::vector> volumeGroups_; std::vector> interruptGroups_; diff --git a/services/audio_policy/server/src/service/audio_policy_service.cpp b/services/audio_policy/server/src/service/audio_policy_service.cpp index be17816bf418e3528097ba6ef013714960039946..2d6947e43199bbfa22b7030a65c14ad9410e9f48 100644 --- a/services/audio_policy/server/src/service/audio_policy_service.cpp +++ b/services/audio_policy/server/src/service/audio_policy_service.cpp @@ -302,7 +302,7 @@ int32_t AudioPolicyService::SelectOutputDevice(sptr audioRe // switch between local devices if (!isCurrentRemoteRenderer && LOCAL_NETWORK_ID == networkId && currentActiveDevice_ != deviceType) { if (deviceType == DeviceType::DEVICE_TYPE_DEFAULT) { - deviceType = FetchHighPriorityDevice(); + deviceType = FetchHighPriorityDevice(true); } return SelectNewDevice(DeviceRole::OUTPUT_DEVICE, deviceType); } @@ -508,6 +508,9 @@ int32_t AudioPolicyService::SelectInputDevice(sptr audioCap // switch between local devices if (LOCAL_NETWORK_ID == networkId && activeInputDevice_ != deviceType) { + if (deviceType == DeviceType::DEVICE_TYPE_DEFAULT) { + deviceType = FetchHighPriorityDevice(false); + } return SelectNewDevice(DeviceRole::INPUT_DEVICE, deviceType); } @@ -732,11 +735,11 @@ std::vector> AudioPolicyService::GetDevices(DeviceFl return deviceList; } -DeviceType AudioPolicyService::FetchHighPriorityDevice() +DeviceType AudioPolicyService::FetchHighPriorityDevice(bool isOutputDevice = true) { AUDIO_DEBUG_LOG("Entered AudioPolicyService::%{public}s", __func__); - DeviceType priorityDevice = DEVICE_TYPE_SPEAKER; - + DeviceType priorityDevice = isOutputDevice ? DEVICE_TYPE_SPEAKER : DEVICE_TYPE_MIC; + std::vector priorityList = isOutputDevice ? outputPriorityList_ : inputPriorityList_; for (const auto &device : priorityList) { auto isPresent = [&device, this] (const sptr &desc) { CHECK_AND_RETURN_RET_LOG(desc != nullptr, false, "Invalid device descriptor");