diff --git a/frameworks/js/napi/audiomanager/napi_audio_session_manager.cpp b/frameworks/js/napi/audiomanager/napi_audio_session_manager.cpp index 3e9e49fea28cfa9040f88deab81c48b28af7d131..c05af5b7acc71183aef8469a01d5240b278671c5 100644 --- a/frameworks/js/napi/audiomanager/napi_audio_session_manager.cpp +++ b/frameworks/js/napi/audiomanager/napi_audio_session_manager.cpp @@ -101,8 +101,8 @@ napi_value NapiAudioSessionMgr::Init(napi_env env, napi_value exports) DECLARE_NAPI_FUNCTION("selectMediaInputDevice", SelectMediaInputDevice), DECLARE_NAPI_FUNCTION("getSelectedMediaInputDevice", GetSelectedMediaInputDevice), DECLARE_NAPI_FUNCTION("clearSelectedMediaInputDevice", ClearSelectedMediaInputDevice), - DECLARE_NAPI_FUNCTION("preferBluetoothAndNearlinkRecord", PreferBluetoothAndNearlinkRecord), - DECLARE_NAPI_FUNCTION("getPreferBluetoothAndNearlinkRecord", GetPreferBluetoothAndNearlinkRecord), + DECLARE_NAPI_FUNCTION("setBluetoothAndNearlinkPreferredRecordCategory", PreferBluetoothAndNearlinkRecord), + DECLARE_NAPI_FUNCTION("getBluetoothAndNearlinkPreferredRecordCategory", GetPreferBluetoothAndNearlinkRecord), }; status = napi_define_class(env, AUDIO_SESSION_MGR_NAPI_CLASS_NAME.c_str(), NAPI_AUTO_LENGTH, Construct, nullptr, @@ -481,6 +481,7 @@ void NapiAudioSessionMgr::RegisterAvaiableDeviceChangeCallback(napi_env env, nap napi_value NapiAudioSessionMgr::On(napi_env env, napi_callback_info info) { const size_t requireArgc = ARGS_TWO; + const size_t maxArgc = ARGS_THREE; size_t argc = ARGS_THREE; napi_value undefinedResult = nullptr; @@ -489,7 +490,8 @@ napi_value NapiAudioSessionMgr::On(napi_env env, napi_callback_info info) napi_value args[requireArgc + PARAM1] = {nullptr, nullptr, nullptr}; napi_value jsThis = nullptr; napi_status status = napi_get_cb_info(env, info, &argc, args, &jsThis, nullptr); - CHECK_AND_RETURN_RET_LOG(status == napi_ok && argc == requireArgc, NapiAudioError::ThrowErrorAndReturn(env, + bool isArgcCountRight = argc == requireArgc || argc == maxArgc; + CHECK_AND_RETURN_RET_LOG(status == napi_ok && isArgcCountRight, NapiAudioError::ThrowErrorAndReturn(env, NAPI_ERR_INPUT_INVALID, "mandatory parameters are left unspecified"), "status for arguments error"); @@ -501,11 +503,14 @@ napi_value NapiAudioSessionMgr::On(napi_env env, napi_callback_info info) std::string callbackName = NapiParamUtils::GetStringArgument(env, args[PARAM0]); AUDIO_DEBUG_LOG("AudioStreamMgrNapi: On callbackName: %{public}s", callbackName.c_str()); - napi_valuetype handler = napi_undefined; - napi_typeof(env, args[PARAM1], &handler); - CHECK_AND_RETURN_RET_LOG( - handler == napi_function, NapiAudioError::ThrowErrorAndReturn(env, NAPI_ERR_INPUT_INVALID, - "incorrect parameter types: The type of handler must be function"), "handler is invalid"); + if (argc == requireArgc) { + napi_valuetype handler = napi_undefined; + napi_typeof(env, args[PARAM1], &handler); + CHECK_AND_RETURN_RET_LOG( + handler == napi_function, NapiAudioError::ThrowErrorAndReturn(env, NAPI_ERR_INPUT_INVALID, + "incorrect parameter types: The type of handler must be function"), "handler is invalid"); + } + RegisterCallback(env, jsThis, args, callbackName); return undefinedResult; } @@ -843,6 +848,7 @@ napi_value NapiAudioSessionMgr::SelectMediaInputDevice(napi_env env, napi_callba auto inputParser = [env, context](size_t argc, napi_value *argv) { NAPI_CHECK_ARGS_RETURN_VOID(context, argc >= ARGS_ONE, "invalid arguments", NAPI_ERR_INVALID_PARAM); + context->deviceDescriptor = std::make_shared(); NapiParamUtils::GetAudioDeviceDescriptor(env, context->deviceDescriptor, context->bArgTransFlag, argv[PARAM0]); }; @@ -975,9 +981,13 @@ napi_value NapiAudioSessionMgr::PreferBluetoothAndNearlinkRecord(napi_env env, n auto inputParser = [env, context](size_t argc, napi_value *argv) { NAPI_CHECK_ARGS_RETURN_VOID(context, argc >= ARGS_ONE, "invalid arguments", NAPI_ERR_INPUT_INVALID); - context->status = NapiParamUtils::GetValueBoolean(env, context->isTrue, argv[PARAM0]); - NAPI_CHECK_ARGS_RETURN_VOID(context, context->status == napi_ok, "GetValueBoolean failed", + context->status = NapiParamUtils::GetValueUInt32(env, context->category, argv[PARAM0]); + NAPI_CHECK_ARGS_RETURN_VOID(context, context->status == napi_ok, "GetValueInt32 failed", NAPI_ERR_INPUT_INVALID); + if (!NapiAudioEnum::IsLegalBluetoothAndNearlinkPreferredRecordCategory(context->category)) { + NapiAudioError::ThrowError(env, NAPI_ERR_INVALID_PARAM, + "parameter verification failed: category wrong value"); + } }; context->GetCbInfo(env, info, inputParser); @@ -994,8 +1004,9 @@ napi_value NapiAudioSessionMgr::PreferBluetoothAndNearlinkRecord(napi_env env, n CHECK_AND_RETURN_LOG(CheckAudioSessionStatus(napiSessionMgr, context), "context object state is error."); + auto category = static_cast(context->category); context->intValue = - napiSessionMgr->audioSessionMngr_->PreferBluetoothAndNearlinkRecord(context->isTrue); + napiSessionMgr->audioSessionMngr_->PreferBluetoothAndNearlinkRecord(category); NAPI_CHECK_ARGS_RETURN_VOID(context, context->intValue == SUCCESS, "PreferBluetoothAndNearlinkRecord failed", NAPI_ERR_SYSTEM); }; diff --git a/frameworks/js/napi/audiomanager/napi_audio_session_manager.h b/frameworks/js/napi/audiomanager/napi_audio_session_manager.h index f6c910709a93a8bf6d8e8f6adcc3ea5bf043efc0..6e318f91b6287b792562bfd00df371be2ddc1f4c 100644 --- a/frameworks/js/napi/audiomanager/napi_audio_session_manager.h +++ b/frameworks/js/napi/audiomanager/napi_audio_session_manager.h @@ -50,6 +50,7 @@ private: NapiAudioSessionMgr *objectInfo; AudioSessionStrategy audioSessionStrategy; int32_t deviceType; + uint32_t category; std::shared_ptr deviceDescriptor; bool bArgTransFlag = false; }; diff --git a/frameworks/js/napi/common/napi_audio_enum.cpp b/frameworks/js/napi/common/napi_audio_enum.cpp index a478696166222cbb06b8eb4dbc14bbc6902956b6..30c9dd204cdd400a21c188f14e430baff86c16ca 100644 --- a/frameworks/js/napi/common/napi_audio_enum.cpp +++ b/frameworks/js/napi/common/napi_audio_enum.cpp @@ -1490,6 +1490,23 @@ bool NapiAudioEnum::IsValidSourceType(int32_t intValue) } } +bool NapiAudioEnum::IsLegalBluetoothAndNearlinkPreferredRecordCategory(uint32_t category) +{ + bool result = false; + switch (category) { + case BluetoothAndNearlinkPreferredRecordCategory::PREFERRED_NONE: + case BluetoothAndNearlinkPreferredRecordCategory::PREFERRED_DEFAULT: + case BluetoothAndNearlinkPreferredRecordCategory::PREFERRED_LOW_LATENCY: + case BluetoothAndNearlinkPreferredRecordCategory::PREFERRED_HIGH_QUALITY: + result = true; + break; + default: + result = false; + break; + } + return result; +} + bool NapiAudioEnum::IsLegalDeviceUsage(int32_t usage) { bool result = false; diff --git a/frameworks/js/napi/common/napi_audio_enum.h b/frameworks/js/napi/common/napi_audio_enum.h index 3d44de7041b1f655ebde2a465168d86b4a9b9497..1c167b421b14cb468afbcd86e59472cf822ce503 100644 --- a/frameworks/js/napi/common/napi_audio_enum.h +++ b/frameworks/js/napi/common/napi_audio_enum.h @@ -159,6 +159,7 @@ public: static bool IsLegalInputArgumentAudioLoopbackReverbPreset(int32_t preset); static bool IsLegalInputArgumentAudioLoopbackEqualizerPreset(int32_t preset); static bool IsLegalInputArgumentSessionScene(int32_t scene); + static bool IsLegalBluetoothAndNearlinkPreferredRecordCategory(uint32_t category); private: static void Destructor(napi_env env, void *nativeObject, void *finalizeHint); diff --git a/frameworks/native/audiopolicy/include/audio_policy_manager.h b/frameworks/native/audiopolicy/include/audio_policy_manager.h index c02ab69db6940d4f276a4cb79969ec5ebe194200..72d4dba35a6b4b8ab26a4e15ecd4bd6cc20693f0 100644 --- a/frameworks/native/audiopolicy/include/audio_policy_manager.h +++ b/frameworks/native/audiopolicy/include/audio_policy_manager.h @@ -425,9 +425,9 @@ public: int32_t ClearSelectedInputDevice(); - int32_t PreferBluetoothAndNearlinkRecord(bool isPreferred); + int32_t PreferBluetoothAndNearlinkRecord(BluetoothAndNearlinkPreferredRecordCategory category); - bool GetPreferBluetoothAndNearlinkRecord(); + BluetoothAndNearlinkPreferredRecordCategory GetPreferBluetoothAndNearlinkRecord(); int32_t SetAvailableDeviceChangeCallback(const int32_t clientId, const AudioDeviceUsage usage, const std::shared_ptr& callback); diff --git a/frameworks/native/ohaudio/OHAudioSessionManager.cpp b/frameworks/native/ohaudio/OHAudioSessionManager.cpp index a0f996192d8e75a71e69e9c35fbbaa318647d1b3..4d98f7c3e2eca87bff2bdd8b1548b3bd3d5a4c70 100644 --- a/frameworks/native/ohaudio/OHAudioSessionManager.cpp +++ b/frameworks/native/ohaudio/OHAudioSessionManager.cpp @@ -133,13 +133,16 @@ OH_AudioCommon_Result OH_AudioSessionManager_GetAvailableDevices(OH_AudioSession OH_AudioCommon_Result OH_AudioSessionManager_SelectMediaInputDevice( OH_AudioSessionManager *audioSessionManager, OH_AudioDeviceDescriptor *deviceDescriptor) { - if (audioSessionManager == nullptr || deviceDescriptor == nullptr) { - AUDIO_ERR_LOG("Invalid params!"); - return AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM; - } + CHECK_AND_RETURN_RET_LOG(audioSessionManager != nullptr, + AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM, "audioSessionManager is nullptr"); OHAudioSessionManager *ohAudioSessionManager = convertManager(audioSessionManager); CHECK_AND_RETURN_RET_LOG(ohAudioSessionManager != nullptr, AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM, "ohAudioSessionManager is nullptr"); + + if (deviceDescriptor == nullptr) { + return ohAudioSessionManager->ClearSelectedMediaInputDevice(); + } + OHAudioDeviceDescriptor* ohDeviceDescriptor = convertDeviceDescriptor(deviceDescriptor); CHECK_AND_RETURN_RET_LOG(ohDeviceDescriptor != nullptr, AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM, "ohDeviceDescriptor is nullptr"); @@ -150,36 +153,25 @@ OH_AudioCommon_Result OH_AudioSessionManager_SelectMediaInputDevice( } OH_AudioCommon_Result OH_AudioSessionManager_GetSelectedMediaInputDevice( - OH_AudioSessionManager *audioSessionManager, OH_AudioDeviceDescriptor *deviceDescriptor) + OH_AudioSessionManager *audioSessionManager, OH_AudioDeviceDescriptor **audioDeviceDescriptor) { - if (audioSessionManager == nullptr || deviceDescriptor == nullptr) { + if (audioSessionManager == nullptr || audioDeviceDescriptor == nullptr) { AUDIO_ERR_LOG("Invalid params!"); return AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM; } OHAudioSessionManager *ohAudioSessionManager = convertManager(audioSessionManager); CHECK_AND_RETURN_RET_LOG(ohAudioSessionManager != nullptr, AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM, "ohAudioSessionManager is nullptr"); - deviceDescriptor = ohAudioSessionManager->GetSelectedMediaInputDevice(); - CHECK_AND_RETURN_RET_LOG(deviceDescriptor != nullptr, - AUDIOCOMMON_RESULT_ERROR_NO_MEMORY, "*deviceDescriptor is nullptr"); + *audioDeviceDescriptor = ohAudioSessionManager->GetSelectedMediaInputDevice(); + CHECK_AND_RETURN_RET_LOG(*audioDeviceDescriptor != nullptr, + AUDIOCOMMON_RESULT_ERROR_NO_MEMORY, "*audioDeviceDescriptor is nullptr"); return AUDIOCOMMON_RESULT_SUCCESS; } -OH_AudioCommon_Result OH_AudioSessionManager_ClearSelectedMediaInputDevice(OH_AudioSessionManager *audioSessionManager) -{ - if (audioSessionManager == nullptr) { - AUDIO_ERR_LOG("Invalid params!"); - return AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM; - } - OHAudioSessionManager *ohAudioSessionManager = convertManager(audioSessionManager); - CHECK_AND_RETURN_RET_LOG(ohAudioSessionManager != nullptr, - AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM, "ohAudioSessionManager is nullptr"); - return ohAudioSessionManager->ClearSelectedMediaInputDevice(); -} - -OH_AudioCommon_Result OH_AudioSessionManager_PreferBluetoothAndNearlinkRecord( - OH_AudioSessionManager *audioSessionManager, bool enable) +OH_AudioCommon_Result OH_AudioSessionManager_SetBluetoothAndNearlinkPreferredRecordCategory( + OH_AudioSessionManager *audioSessionManager, + OH_AudioSession_BluetoothAndNearlinkPreferredRecordCategory category) { if (audioSessionManager == nullptr) { AUDIO_ERR_LOG("Invalid params!"); @@ -188,11 +180,15 @@ OH_AudioCommon_Result OH_AudioSessionManager_PreferBluetoothAndNearlinkRecord( OHAudioSessionManager *ohAudioSessionManager = convertManager(audioSessionManager); CHECK_AND_RETURN_RET_LOG(ohAudioSessionManager != nullptr, AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM, "ohAudioSessionManager is nullptr"); - return ohAudioSessionManager->PreferBluetoothAndNearlinkRecord(enable); + + OHOS::AudioStandard::BluetoothAndNearlinkPreferredRecordCategory preferCategory = + static_cast(category); + return ohAudioSessionManager->PreferBluetoothAndNearlinkRecord(preferCategory); } -OH_AudioCommon_Result OH_AudioSessionManager_IsPreferredBluetoothAndNearlinkRecord( - OH_AudioSessionManager *audioSessionManager, bool *enable) +OH_AudioCommon_Result OH_AudioSessionManager_GetBluetoothAndNearlinkPreferredRecordCategory( + OH_AudioSessionManager *audioSessionManager, + OH_AudioSession_BluetoothAndNearlinkPreferredRecordCategory *category) { if (audioSessionManager == nullptr) { AUDIO_ERR_LOG("Invalid params!"); @@ -201,13 +197,9 @@ OH_AudioCommon_Result OH_AudioSessionManager_IsPreferredBluetoothAndNearlinkReco OHAudioSessionManager *ohAudioSessionManager = convertManager(audioSessionManager); CHECK_AND_RETURN_RET_LOG(ohAudioSessionManager != nullptr, AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM, "ohAudioSessionManager is nullptr"); - *enable = ohAudioSessionManager->IsPreferredBluetoothAndNearlinkRecord(); + auto preferCategory = ohAudioSessionManager->GetPreferredBluetoothAndNearlinkRecord(); + *category = static_cast(preferCategory); - if (*enable == true) { - AUDIO_INFO_LOG("is preferred Bluetooth and Nearlink"); - } else { - AUDIO_INFO_LOG("is not preferred Bluetooth and Nearlink"); - } return AUDIOCOMMON_RESULT_SUCCESS; } @@ -304,6 +296,24 @@ OH_AudioCommon_Result OH_AudioSessionManager_ReleaseDevices( return AUDIOCOMMON_RESULT_SUCCESS; } +OH_AudioCommon_Result OH_AudioSessionManager_ReleaseDevice( + OH_AudioSessionManager *audioSessionManager, + OH_AudioDeviceDescriptor *audioDeviceDescriptor) +{ + OHAudioSessionManager *ohAudioSessionManager = convertManager(audioSessionManager); + CHECK_AND_RETURN_RET_LOG(ohAudioSessionManager != nullptr, + AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM, "ohAudioSessionManager is nullptr"); + CHECK_AND_RETURN_RET_LOG(audioDeviceDescriptor != nullptr, + AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM, "audioDeviceDescriptor is nullptr"); + + OHAudioDeviceDescriptor *ohAudioDeviceDescriptor = + (OHAudioDeviceDescriptor*)audioDeviceDescriptor; + if (ohAudioDeviceDescriptor != nullptr) { + delete ohAudioDeviceDescriptor; + } + return AUDIOCOMMON_RESULT_SUCCESS; +} + OH_AudioCommon_Result OH_AudioSessionManager_RegisterCurrentOutputDeviceChangeCallback( OH_AudioSessionManager *audioSessionManager, OH_AudioSession_CurrentOutputDeviceChangedCallback callback) @@ -529,18 +539,20 @@ OH_AudioCommon_Result OHAudioSessionManager::ClearSelectedMediaInputDevice() return result == 0 ? AUDIOCOMMON_RESULT_SUCCESS : AUDIOCOMMON_RESULT_ERROR_ILLEGAL_STATE; } -OH_AudioCommon_Result OHAudioSessionManager::PreferBluetoothAndNearlinkRecord(bool enable) +OH_AudioCommon_Result OHAudioSessionManager::PreferBluetoothAndNearlinkRecord( + BluetoothAndNearlinkPreferredRecordCategory category) { CHECK_AND_RETURN_RET_LOG(audioSessionManager_ != nullptr, AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM, "failed, audioSessionManager_ is null"); - int32_t result = audioSessionManager_->PreferBluetoothAndNearlinkRecord(enable); + int32_t result = audioSessionManager_->PreferBluetoothAndNearlinkRecord(category); return result == 0 ? AUDIOCOMMON_RESULT_SUCCESS : AUDIOCOMMON_RESULT_ERROR_ILLEGAL_STATE; } -bool OHAudioSessionManager::IsPreferredBluetoothAndNearlinkRecord() +BluetoothAndNearlinkPreferredRecordCategory OHAudioSessionManager::GetPreferredBluetoothAndNearlinkRecord() { CHECK_AND_RETURN_RET_LOG(audioSessionManager_ != nullptr, - false, "failed, audioSessionManager_ is null"); + BluetoothAndNearlinkPreferredRecordCategory::PREFERRED_NONE, + "failed, audioSessionManager_ is null"); return audioSessionManager_->GetPreferBluetoothAndNearlinkRecord(); } diff --git a/frameworks/native/ohaudio/OHAudioSessionManager.h b/frameworks/native/ohaudio/OHAudioSessionManager.h index 2ca130f79fb6a429446e1fcf11629689747299f6..8fef4993b63a9145da3036493ca971585c530301 100644 --- a/frameworks/native/ohaudio/OHAudioSessionManager.h +++ b/frameworks/native/ohaudio/OHAudioSessionManager.h @@ -168,8 +168,8 @@ public: OH_AudioCommon_Result SelectMediaInputDevice(const std::shared_ptr &deviceDescriptor); OH_AudioDeviceDescriptor *GetSelectedMediaInputDevice(); OH_AudioCommon_Result ClearSelectedMediaInputDevice(); - OH_AudioCommon_Result PreferBluetoothAndNearlinkRecord(bool enable); - bool IsPreferredBluetoothAndNearlinkRecord(); + OH_AudioCommon_Result PreferBluetoothAndNearlinkRecord(BluetoothAndNearlinkPreferredRecordCategory category); + BluetoothAndNearlinkPreferredRecordCategory GetPreferredBluetoothAndNearlinkRecord(); OH_AudioCommon_Result SetAvailableDeviceChangeCallback( AudioDeviceUsage deviceUsage, OH_AudioSession_AvailableDeviceChangedCallback callback); diff --git a/interfaces/inner_api/native/audiocommon/include/audio_info.h b/interfaces/inner_api/native/audiocommon/include/audio_info.h index 6ab761a85cf820cb3eec1fba3f6ad20ca605429a..b7e7777a3bc7f25ef9d8b2fa07f7d001c3604fd9 100644 --- a/interfaces/inner_api/native/audiocommon/include/audio_info.h +++ b/interfaces/inner_api/native/audiocommon/include/audio_info.h @@ -889,6 +889,30 @@ enum AudioDeviceUsage : uint32_t { D_ALL_DEVICES = 15, }; +enum BluetoothAndNearlinkPreferredRecordCategory : uint32_t { + /** + * @brief Not prefer to use bluetooth and nearlink record. + */ + PREFERRED_NONE = 0, + + /** + * @brief Prefer to use bluetooth and nearlink record. + * However, whether to use low latency or high quality recording + * dpends on system. + */ + PREFERRED_DEFAULT = 1, + + /** + * @brief Prefer to use bluetooth and nearlink low latency mode to record. + */ + PREFERRED_LOW_LATENCY = 2, + + /** + * @brief Prefer to use bluetooth and nearlink high quality mode to record. + */ + PREFERRED_HIGH_QUALITY = 3, +}; + enum FilterMode : uint32_t { INCLUDE = 0, EXCLUDE, diff --git a/interfaces/inner_api/native/audiomanager/include/audio_session_manager.h b/interfaces/inner_api/native/audiomanager/include/audio_session_manager.h index 6a4cb5e80aec8db479bb9251c42e5077b9949e75..ed48d45b3040e53651aa74e1cb9b7ae146e4f862 100644 --- a/interfaces/inner_api/native/audiomanager/include/audio_session_manager.h +++ b/interfaces/inner_api/native/audiomanager/include/audio_session_manager.h @@ -341,9 +341,9 @@ public: */ int32_t ClearSelectedInputDevice(); - int32_t PreferBluetoothAndNearlinkRecord(bool isPreferred); + int32_t PreferBluetoothAndNearlinkRecord(BluetoothAndNearlinkPreferredRecordCategory category); - bool GetPreferBluetoothAndNearlinkRecord(); + BluetoothAndNearlinkPreferredRecordCategory GetPreferBluetoothAndNearlinkRecord(); private: std::mutex setDefaultOutputDeviceMutex_; diff --git a/interfaces/kits/c/audio_manager/native_audio_session_manager.h b/interfaces/kits/c/audio_manager/native_audio_session_manager.h index aa69628ac32fc4e2bd93f8d336924a29dfba3e2b..105a9600b9e7617609903d1532ba373ec50a0cef 100644 --- a/interfaces/kits/c/audio_manager/native_audio_session_manager.h +++ b/interfaces/kits/c/audio_manager/native_audio_session_manager.h @@ -178,6 +178,36 @@ typedef enum { DEACTIVATED_TIMEOUT = 1, } OH_AudioSession_DeactivatedReason; +/** + * @brief Enumerates the categories application prefer to use + * when recording with bluetooth and nearlink. + * + * @since 21 + */ +typedef enum { + /** + * @brief Not prefer to use bluetooth and nearlink record. + */ + PREFERRED_NONE = 0, + + /** + * @brief Prefer to use bluetooth and nearlink record. + * However, whether to use low latency or high quality recording + * dpends on system. + */ + PREFERRED_DEFAULT = 1, + + /** + * @brief Prefer to use bluetooth and nearlink low latency mode to record. + */ + PREFERRED_LOW_LATENCY = 2, + + /** + * @brief Prefer to use bluetooth and nearlink high quality mode to record. + */ + PREFERRED_HIGH_QUALITY = 3, +} OH_AudioSession_BluetoothAndNearlinkPreferredRecordCategory; + /** * @brief declare the audio session strategy * diff --git a/services/audio_policy/client/service/src/audio_policy_manager_device.cpp b/services/audio_policy/client/service/src/audio_policy_manager_device.cpp index c5ce3bad28b458bc0f851c9f59cbc255ccc6b8eb..5e6a23a39988fa695a9ea280e5d001d503478719 100644 --- a/services/audio_policy/client/service/src/audio_policy_manager_device.cpp +++ b/services/audio_policy/client/service/src/audio_policy_manager_device.cpp @@ -82,6 +82,8 @@ int32_t AudioPolicyManager::SelectInputDevice(std::shared_ptrSelectInputDevice(audioDeviceDescriptor); } @@ -468,20 +470,22 @@ int32_t AudioPolicyManager::ClearSelectedInputDevice() return gsp->ClearSelectedInputDevice(); } -int32_t AudioPolicyManager::PreferBluetoothAndNearlinkRecord(bool isPreferred) +int32_t AudioPolicyManager::PreferBluetoothAndNearlinkRecord(BluetoothAndNearlinkPreferredRecordCategory category) { const sptr gsp = GetAudioPolicyManagerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, ERROR, "audio policy manager proxy is NULL."); - return gsp->PreferBluetoothAndNearlinkRecord(isPreferred); + int32_t result = CheckAudioPolicyClientRegisted(); + CHECK_AND_RETURN_RET(result == SUCCESS, result); + return gsp->PreferBluetoothAndNearlinkRecord(category); } -bool AudioPolicyManager::GetPreferBluetoothAndNearlinkRecord() +BluetoothAndNearlinkPreferredRecordCategory AudioPolicyManager::GetPreferBluetoothAndNearlinkRecord() { const sptr gsp = GetAudioPolicyManagerProxy(); - CHECK_AND_RETURN_RET_LOG(gsp != nullptr, ERROR, "audio policy manager proxy is NULL."); - bool isPreferred = false; - gsp->GetPreferBluetoothAndNearlinkRecord(isPreferred); - return isPreferred; + CHECK_AND_RETURN_RET_LOG(gsp != nullptr, PREFERRED_NONE, "audio policy manager proxy is NULL."); + uint32_t category = PREFERRED_NONE; + gsp->GetPreferBluetoothAndNearlinkRecord(category); + return static_cast(category); } int32_t AudioPolicyManager::SetAvailableDeviceChangeCallback(const int32_t clientId, const AudioDeviceUsage usage, diff --git a/services/audio_policy/idl/IAudioPolicy.idl b/services/audio_policy/idl/IAudioPolicy.idl index c4d922a041388611c106b5eaf491bba6ee412154..f4bb8cad925489231de6b566ef7de49388127278 100644 --- a/services/audio_policy/idl/IAudioPolicy.idl +++ b/services/audio_policy/idl/IAudioPolicy.idl @@ -303,8 +303,8 @@ interface IAudioPolicy { void SelectInputDevice([in] sharedptr audioDeviceDescriptor); void GetSelectedInputDevice([out] sharedptr audioDeviceDescriptor); void ClearSelectedInputDevice(); - void PreferBluetoothAndNearlinkRecord([in] boolean isPreferred); - void GetPreferBluetoothAndNearlinkRecord([out] boolean isPreferred); + void PreferBluetoothAndNearlinkRecord([in] unsigned int category); + void GetPreferBluetoothAndNearlinkRecord([out] unsigned int category); void RestoreOutputDevice([in] sptr audioRendererFilter); } diff --git a/services/audio_policy/server/domain/device/include/audio_usr_select_manager.h b/services/audio_policy/server/domain/device/include/audio_usr_select_manager.h index 43f66e09e269b86b9cde71b73e8fef70284823d8..9a66160355c3a9eedfed3b3542db4fdd0e57c192 100644 --- a/services/audio_policy/server/domain/device/include/audio_usr_select_manager.h +++ b/services/audio_policy/server/domain/device/include/audio_usr_select_manager.h @@ -43,8 +43,8 @@ public: bool SelectInputDeviceByUid(const std::shared_ptr &deviceDescriptor, int32_t uid); std::shared_ptr GetSelectedInputDeviceByUid(int32_t uid); void ClearSelectedInputDeviceByUid(int32_t uid); - void PreferBluetoothAndNearlinkRecordByUid(int32_t uid, bool isPreferred); - bool GetPreferBluetoothAndNearlinkRecordByUid(int32_t uid); + void PreferBluetoothAndNearlinkRecordByUid(int32_t uid, BluetoothAndNearlinkPreferredRecordCategory category); + BluetoothAndNearlinkPreferredRecordCategory GetPreferBluetoothAndNearlinkRecordByUid(int32_t uid); void EnableSelectInputDevice(const std::vector> &inputStreamDescs); void DisableSelectInputDevice(); std::shared_ptr GetCapturerDevice(int32_t uid, SourceType sourceType); @@ -56,11 +56,12 @@ private: std::list>::iterator findDevice(int32_t uid); int32_t GetRealUid(const std::shared_ptr &streamDesc); std::shared_ptr JudgeFinalSelectDevice(const std::shared_ptr &desc, - SourceType sourceType); + SourceType sourceType, BluetoothAndNearlinkPreferredRecordCategory category); std::shared_ptr GetPreferDevice(); std::list> selectedDevices_; std::list isPreferredBluetoothAndNearlinkRecord_; + std::unordered_map categoryMap_; AudioDevicePtr capturerDevice_ = nullptr; bool isEnabled_ = false; std::mutex mutex_; diff --git a/services/audio_policy/server/domain/device/src/audio_usr_select_manager.cpp b/services/audio_policy/server/domain/device/src/audio_usr_select_manager.cpp index f67127fcacec5d7da4873f690eae282f1b787b3c..ad0507d54c0611dda8abf09032ae20553004f949 100644 --- a/services/audio_policy/server/domain/device/src/audio_usr_select_manager.cpp +++ b/services/audio_policy/server/domain/device/src/audio_usr_select_manager.cpp @@ -30,6 +30,7 @@ bool AudioUsrSelectManager::SelectInputDeviceByUid(const std::shared_ptr lock(mutex_); + AUDIO_INFO_LOG("select input device, uid: %{public}d, deviceId: %{public}d", uid, deviceDescriptor->deviceId_); auto desc = AudioDeviceManager::GetAudioDeviceManager().FindConnectedDeviceById(deviceDescriptor->deviceId_); if (desc == nullptr) { AUDIO_ERR_LOG("AudioUsrSelectManager::SelectInputDeviceByUid no device found, deviceId: %{public}d", @@ -40,6 +41,7 @@ bool AudioUsrSelectManager::SelectInputDeviceByUid(const std::shared_ptrdeviceId_); int32_t ret = AudioRecoveryDevice::GetInstance().ConnectVirtualDevice(desc); CHECK_AND_RETURN_RET_LOG(ret == SUCCESS, false, "Connect device [%{public}s] failed", GetEncryptStr(desc->macAddress_).c_str()); @@ -76,31 +78,36 @@ void AudioUsrSelectManager::ClearSelectedInputDeviceByUid(int32_t uid) } } -void AudioUsrSelectManager::PreferBluetoothAndNearlinkRecordByUid(int32_t uid, bool isPreferred) +void AudioUsrSelectManager::PreferBluetoothAndNearlinkRecordByUid(int32_t uid, + BluetoothAndNearlinkPreferredRecordCategory category) { std::lock_guard lock(mutex_); - + AUDIO_INFO_LOG("prefer to use bluetooth and nearlink to record, uid: %{public}d, category: %{public}d", + uid, category); auto it = std::find(isPreferredBluetoothAndNearlinkRecord_.begin(), isPreferredBluetoothAndNearlinkRecord_.end(), uid); if (it != isPreferredBluetoothAndNearlinkRecord_.end()) { isPreferredBluetoothAndNearlinkRecord_.erase(it); + categoryMap_.erase(uid); } - - if (isPreferred) { + + if (category != BluetoothAndNearlinkPreferredRecordCategory::PREFERRED_NONE) { isPreferredBluetoothAndNearlinkRecord_.push_front(uid); + categoryMap_[uid] = category; } } -bool AudioUsrSelectManager::GetPreferBluetoothAndNearlinkRecordByUid(int32_t uid) +BluetoothAndNearlinkPreferredRecordCategory AudioUsrSelectManager::GetPreferBluetoothAndNearlinkRecordByUid( + int32_t uid) { std::lock_guard lock(mutex_); auto it = std::find(isPreferredBluetoothAndNearlinkRecord_.begin(), isPreferredBluetoothAndNearlinkRecord_.end(), uid); if (it != isPreferredBluetoothAndNearlinkRecord_.end()) { - return true; + return categoryMap_[uid]; } - return false; + return BluetoothAndNearlinkPreferredRecordCategory::PREFERRED_NONE; } void AudioUsrSelectManager::EnableSelectInputDevice( @@ -119,6 +126,7 @@ void AudioUsrSelectManager::EnableSelectInputDevice( int32_t uid = GetRealUid(streamDesc); uidMap[uid] = i; } + AUDIO_INFO_LOG("running stream size: %{public}zu", uidMap.size()); // use selected rules first for (const auto &device : selectedDevices_) { @@ -127,10 +135,12 @@ void AudioUsrSelectManager::EnableSelectInputDevice( int32_t index = uidMap[device.first]; auto &streamDesc = inputStreamDescs[index]; - capturerDevice_ = JudgeFinalSelectDevice(desc, streamDesc->capturerInfo_.sourceType); + capturerDevice_ = JudgeFinalSelectDevice(desc, streamDesc->capturerInfo_.sourceType, + categoryMap_[device.first]); CHECK_AND_CONTINUE(capturerDevice_ != nullptr); return; } + AUDIO_WARNING_LOG("no select device, use prefer settings"); if (isPreferredBluetoothAndNearlinkRecord_.size() == 0) { AUDIO_WARNING_LOG("AudioUsrSelectManager::EnableSelectInputDevice no prefer settings"); @@ -142,11 +152,12 @@ void AudioUsrSelectManager::EnableSelectInputDevice( auto preferDevice = GetPreferDevice(); CHECK_AND_RETURN(preferDevice != nullptr); for (const int32_t uid : isPreferredBluetoothAndNearlinkRecord_) { - CHECK_AND_CONTINUE(uidMap.find(uid) != uidMap.end()); + CHECK_AND_CONTINUE_LOG(uidMap.find(uid) != uidMap.end(), "uid: %{public}d has no running stream", uid); + CHECK_AND_CONTINUE_LOG(categoryMap_[uid] != PREFERRED_NONE, "uid: %{public}d prefer setting 0", uid); int32_t index = uidMap[uid]; auto &streamDesc = inputStreamDescs[index]; - capturerDevice_ = JudgeFinalSelectDevice(preferDevice, streamDesc->capturerInfo_.sourceType); + capturerDevice_ = JudgeFinalSelectDevice(preferDevice, streamDesc->capturerInfo_.sourceType, categoryMap_[uid]); CHECK_AND_CONTINUE(capturerDevice_ != nullptr); break; } @@ -163,28 +174,34 @@ std::shared_ptr AudioUsrSelectManager::GetCapturerDevice( { std::lock_guard lock(mutex_); // If marked, directly return the selection result. - CHECK_AND_RETURN_RET(!isEnabled_, capturerDevice_); + CHECK_AND_RETURN_RET_LOG(!isEnabled_, capturerDevice_, "select enabled, return capturerDevice_"); + AUDIO_INFO_LOG("select disabled, search selected device. uid: %{public}d, sourceType: %{public}d", + uid, sourceType); std::shared_ptr capturerDevice = nullptr; // If not marked, first find the selection of the current UID auto deviceIt = findDevice(uid); if (deviceIt != selectedDevices_.end()) { // Based on the sourceType, determine the final input device - auto desc = JudgeFinalSelectDevice(deviceIt->second, sourceType); + auto desc = JudgeFinalSelectDevice(deviceIt->second, sourceType, categoryMap_[uid]); CHECK_AND_RETURN_RET_LOG(desc == nullptr, desc, "AudioUsrSelectManager::GetCapturerDevice has selected device."); + AUDIO_WARNING_LOG("selected device no longer available"); } + AUDIO_WARNING_LOG("no selected device, use prefer settings"); // If the current UID has no selection, then apply the preference setting auto it = std::find(isPreferredBluetoothAndNearlinkRecord_.begin(), isPreferredBluetoothAndNearlinkRecord_.end(), uid); // If the current UID has no preference setting CHECK_AND_RETURN_RET_LOG(it != isPreferredBluetoothAndNearlinkRecord_.end(), nullptr, "AudioUsrSelectManager::GetCapturerDevice no prefer data"); + CHECK_AND_RETURN_RET_LOG(categoryMap_[uid] != PREFERRED_NONE, nullptr, + "AudioUsrSelectManager::GetCapturerDevice prefer setting 0"); // According to the device connection time, obtain the most recently connected Bluetooth/Nearlink device auto preferDevice = GetPreferDevice(); CHECK_AND_RETURN_RET(preferDevice != nullptr, nullptr); - return JudgeFinalSelectDevice(preferDevice, sourceType); + return JudgeFinalSelectDevice(preferDevice, sourceType, categoryMap_[uid]); } std::list>::iterator AudioUsrSelectManager::findDevice(int32_t uid) @@ -204,19 +221,24 @@ int32_t AudioUsrSelectManager::GetRealUid(const std::shared_ptr AudioUsrSelectManager::JudgeFinalSelectDevice( - const std::shared_ptr &desc, SourceType sourceType) + const std::shared_ptr &desc, SourceType sourceType, + BluetoothAndNearlinkPreferredRecordCategory category) { + // 判断设备是不是存在且处于连接状态 + bool isConnected = AudioDeviceManager::GetAudioDeviceManager().IsConnectedDevices(desc); + + if (desc->deviceType_ != DEVICE_TYPE_BLUETOOTH_SCO || category == PREFERRED_LOW_LATENCY) { + return isConnected ? desc : nullptr; + } + // 如果是直播或录像且设备为sco,需要判断是否存在可用的高清设备 - if ((sourceType == SOURCE_TYPE_CAMCORDER || sourceType == SOURCE_TYPE_LIVE) && - desc->deviceType_ == DEVICE_TYPE_BLUETOOTH_SCO) { + if (sourceType == SOURCE_TYPE_CAMCORDER || sourceType == SOURCE_TYPE_LIVE || category == PREFERRED_HIGH_QUALITY) { auto a2dpin = std::make_shared(desc); a2dpin->deviceType_ = DEVICE_TYPE_BLUETOOTH_A2DP_IN; bool isA2dpinConnected = AudioDeviceManager::GetAudioDeviceManager().IsConnectedDevices(a2dpin); CHECK_AND_RETURN_RET(!isA2dpinConnected, a2dpin); } - // 判断设备是不是存在且处于连接状态 - bool isConnected = AudioDeviceManager::GetAudioDeviceManager().IsConnectedDevices(desc); return isConnected ? desc : nullptr; } diff --git a/services/audio_policy/server/service/service_main/include/audio_core_service.h b/services/audio_policy/server/service/service_main/include/audio_core_service.h index 5aee838b5070432a640ed5190ba9f92e6e0fc5e2..f97db9d7115dd2ed27241040bd331bbea8501d54 100644 --- a/services/audio_policy/server/service/service_main/include/audio_core_service.h +++ b/services/audio_policy/server/service/service_main/include/audio_core_service.h @@ -137,8 +137,9 @@ public: int32_t uid); std::shared_ptr GetSelectedInputDeviceByUid(int32_t uid); int32_t ClearSelectedInputDeviceByUid(int32_t uid); - int32_t PreferBluetoothAndNearlinkRecordByUid(int32_t uid, bool isPreferred); - bool GetPreferBluetoothAndNearlinkRecordByUid(int32_t uid); + int32_t PreferBluetoothAndNearlinkRecordByUid(int32_t uid, + BluetoothAndNearlinkPreferredRecordCategory category); + BluetoothAndNearlinkPreferredRecordCategory GetPreferBluetoothAndNearlinkRecordByUid(int32_t uid); void NotifyRemoteRenderState(std::string networkId, std::string condition, std::string value); int32_t OnCapturerSessionAdded(uint64_t sessionID, SessionInfo sessionInfo, AudioStreamInfo streamInfo); void CloseWakeUpAudioCapturer(); @@ -257,8 +258,8 @@ private: int32_t SelectInputDeviceByUid(const std::shared_ptr &selectedDesc, int32_t uid); std::shared_ptr GetSelectedInputDeviceByUid(int32_t uid); int32_t ClearSelectedInputDeviceByUid(int32_t uid); - int32_t PreferBluetoothAndNearlinkRecordByUid(int32_t uid, bool isPreferred); - bool GetPreferBluetoothAndNearlinkRecordByUid(int32_t uid); + int32_t PreferBluetoothAndNearlinkRecordByUid(int32_t uid, BluetoothAndNearlinkPreferredRecordCategory category); + BluetoothAndNearlinkPreferredRecordCategory GetPreferBluetoothAndNearlinkRecordByUid(int32_t uid); void NotifyRemoteRenderState(std::string networkId, std::string condition, std::string value); int32_t OnCapturerSessionAdded(uint64_t sessionID, SessionInfo sessionInfo, AudioStreamInfo streamInfo); void CloseWakeUpAudioCapturer(); diff --git a/services/audio_policy/server/service/service_main/include/audio_policy_server.h b/services/audio_policy/server/service/service_main/include/audio_policy_server.h index acb0f7cfbcdfdf88da59d925a266bc34908b5572..17ebcf3e2310ffcab4f275f702aab88d6f51e344 100644 --- a/services/audio_policy/server/service/service_main/include/audio_policy_server.h +++ b/services/audio_policy/server/service/service_main/include/audio_policy_server.h @@ -172,9 +172,9 @@ public: int32_t ClearSelectedInputDevice() override; - int32_t PreferBluetoothAndNearlinkRecord(bool isPreferred) override; + int32_t PreferBluetoothAndNearlinkRecord(uint32_t category) override; - int32_t GetPreferBluetoothAndNearlinkRecord(bool &isPreferred) override; + int32_t GetPreferBluetoothAndNearlinkRecord(uint32_t &category) override; int32_t ExcludeOutputDevices(int32_t audioDevUsage, const std::vector> &audioDeviceDescriptors) override; diff --git a/services/audio_policy/server/service/service_main/src/audio_core_service.cpp b/services/audio_policy/server/service/service_main/src/audio_core_service.cpp index 9515f906c209fc7f220d681b896fa77b4a678227..971a2f25260fdfedc39e95d6555aec6b65feba05 100644 --- a/services/audio_policy/server/service/service_main/src/audio_core_service.cpp +++ b/services/audio_policy/server/service/service_main/src/audio_core_service.cpp @@ -1119,9 +1119,9 @@ int32_t AudioCoreService::SelectInputDeviceByUid(const std::shared_ptrClearSelectedInputDeviceByUid(uid); } -int32_t AudioCoreService::EventEntry::PreferBluetoothAndNearlinkRecordByUid(int32_t uid, bool isPreferred) +int32_t AudioCoreService::EventEntry::PreferBluetoothAndNearlinkRecordByUid(int32_t uid, + BluetoothAndNearlinkPreferredRecordCategory category) { Trace trace("KeyAction AudioCoreService::PreferBluetoothAndNearlinkRecordByUid"); std::lock_guard lock(eventMutex_); - return coreService_->PreferBluetoothAndNearlinkRecordByUid(uid, isPreferred); + return coreService_->PreferBluetoothAndNearlinkRecordByUid(uid, category); } -bool AudioCoreService::EventEntry::GetPreferBluetoothAndNearlinkRecordByUid(int32_t uid) +BluetoothAndNearlinkPreferredRecordCategory AudioCoreService::EventEntry::GetPreferBluetoothAndNearlinkRecordByUid( + int32_t uid) { Trace trace("KeyAction AudioCoreService::GetPreferBluetoothAndNearlinkRecordByUid"); std::lock_guard lock(eventMutex_); diff --git a/services/audio_policy/server/service/service_main/src/audio_policy_server.cpp b/services/audio_policy/server/service/service_main/src/audio_policy_server.cpp index 9e98bd9f0c9eeef4eec08a91b7140b29d1913a35..9b8a360d2f4fe5dab74b187d8b147b4de94b6863 100644 --- a/services/audio_policy/server/service/service_main/src/audio_policy_server.cpp +++ b/services/audio_policy/server/service/service_main/src/audio_policy_server.cpp @@ -3393,7 +3393,8 @@ void AudioPolicyServer::RegisteredTrackerClientDied(pid_t pid, pid_t uid) std::lock_guard lock(clientDiedListenerStateMutex_); eventEntry_->RegisteredTrackerClientDied(uid, pid); eventEntry_->ClearSelectedInputDeviceByUid(uid); - eventEntry_->PreferBluetoothAndNearlinkRecordByUid(uid, false); + eventEntry_->PreferBluetoothAndNearlinkRecordByUid(uid, + BluetoothAndNearlinkPreferredRecordCategory::PREFERRED_NONE); auto filter = [&pid](int val) { return pid == val; @@ -3425,6 +3426,9 @@ void AudioPolicyServer::RegisteredStreamListenerClientDied(pid_t pid, pid_t uid) AudioZoneService::GetInstance().UnRegisterAudioZoneClient(pid); AudioZoneService::GetInstance().ReleaseAudioZoneByClientPid(pid); + eventEntry_->ClearSelectedInputDeviceByUid(uid); + eventEntry_->PreferBluetoothAndNearlinkRecordByUid(uid, + BluetoothAndNearlinkPreferredRecordCategory::PREFERRED_NONE); } int32_t AudioPolicyServer::ResumeStreamState() @@ -3861,6 +3865,7 @@ int32_t AudioPolicyServer::GetSelectedInputDevice(std::shared_ptrGetSelectedInputDeviceByUid(callerUid); + audioPolicyUtils_.UpdateDisplayName(audioDeviceDescriptor); return SUCCESS; } @@ -3871,16 +3876,18 @@ int32_t AudioPolicyServer::ClearSelectedInputDevice() return SUCCESS; } -int32_t AudioPolicyServer::PreferBluetoothAndNearlinkRecord(bool isPreferred) +int32_t AudioPolicyServer::PreferBluetoothAndNearlinkRecord(uint32_t category) { auto callerUid = IPCSkeleton::GetCallingUid(); - return eventEntry_->PreferBluetoothAndNearlinkRecordByUid(callerUid, isPreferred); + return eventEntry_->PreferBluetoothAndNearlinkRecordByUid(callerUid, + static_cast(category)); } -int32_t AudioPolicyServer::GetPreferBluetoothAndNearlinkRecord(bool &isPreferred) +int32_t AudioPolicyServer::GetPreferBluetoothAndNearlinkRecord(uint32_t &category) { auto callerUid = IPCSkeleton::GetCallingUid(); - isPreferred = eventEntry_->GetPreferBluetoothAndNearlinkRecordByUid(callerUid); + auto preferCategory = eventEntry_->GetPreferBluetoothAndNearlinkRecordByUid(callerUid); + category = static_cast(preferCategory); return SUCCESS; } diff --git a/services/audio_policy/test/unittest/audio_usr_select_manager_unit_test/src/audio_usr_select_manager_unit_test.cpp b/services/audio_policy/test/unittest/audio_usr_select_manager_unit_test/src/audio_usr_select_manager_unit_test.cpp index 9a1cde4d7e59c31f6ff2e543f9496228d0df148e..9f961eeb5c871e857706ee6c708f75d9b2fce1ff 100644 --- a/services/audio_policy/test/unittest/audio_usr_select_manager_unit_test/src/audio_usr_select_manager_unit_test.cpp +++ b/services/audio_policy/test/unittest/audio_usr_select_manager_unit_test/src/audio_usr_select_manager_unit_test.cpp @@ -149,10 +149,10 @@ HWTEST_F(AudioUsrSelectManagerUnitTest, AudioUsrSelectManager_PreferBluetoothAnd TestSize.Level1) { AudioUsrSelectManager &audioUsrSelectManager = AudioUsrSelectManager::GetAudioUsrSelectManager(); - audioUsrSelectManager.PreferBluetoothAndNearlinkRecordByUid(123, true); + audioUsrSelectManager.PreferBluetoothAndNearlinkRecordByUid(123, PREFERRED_DEFAULT); EXPECT_EQ(audioUsrSelectManager.isPreferredBluetoothAndNearlinkRecord_.size(), 1); - audioUsrSelectManager.PreferBluetoothAndNearlinkRecordByUid(123, false); + audioUsrSelectManager.PreferBluetoothAndNearlinkRecordByUid(123, PREFERRED_NONE); EXPECT_EQ(audioUsrSelectManager.isPreferredBluetoothAndNearlinkRecord_.size(), 0); } @@ -165,8 +165,10 @@ HWTEST_F(AudioUsrSelectManagerUnitTest, AudioUsrSelectManager_GetPreferBluetooth TestSize.Level1) { AudioUsrSelectManager &audioUsrSelectManager = AudioUsrSelectManager::GetAudioUsrSelectManager(); - EXPECT_EQ(audioUsrSelectManager.GetPreferBluetoothAndNearlinkRecordByUid(123), true); - EXPECT_EQ(audioUsrSelectManager.GetPreferBluetoothAndNearlinkRecordByUid(321), false); + audioUsrSelectManager.PreferBluetoothAndNearlinkRecordByUid(123, PREFERRED_DEFAULT); + + EXPECT_EQ(audioUsrSelectManager.GetPreferBluetoothAndNearlinkRecordByUid(123), PREFERRED_DEFAULT); + EXPECT_EQ(audioUsrSelectManager.GetPreferBluetoothAndNearlinkRecordByUid(321), PREFERRED_NONE); } /** @@ -202,13 +204,20 @@ HWTEST_F(AudioUsrSelectManagerUnitTest, AudioUsrSelectManager_JudgeFinalSelectDe desc->deviceId_ = DEVICE_ID1; desc->macAddress_ = "00:11:22:33:44:55"; desc->connectState_ = VIRTUAL_CONNECTED; - auto judge = audioUsrSelectManager.JudgeFinalSelectDevice(desc, SOURCE_TYPE_CAMCORDER); + auto judge = audioUsrSelectManager.JudgeFinalSelectDevice(desc, SOURCE_TYPE_CAMCORDER, PREFERRED_DEFAULT); + EXPECT_NE(judge, nullptr); + EXPECT_EQ(judge->deviceId_, 2); + + judge = audioUsrSelectManager.JudgeFinalSelectDevice(desc, SOURCE_TYPE_LIVE, PREFERRED_DEFAULT); EXPECT_NE(judge, nullptr); EXPECT_EQ(judge->deviceId_, 2); - judge = audioUsrSelectManager.JudgeFinalSelectDevice(desc, SOURCE_TYPE_LIVE); + judge = audioUsrSelectManager.JudgeFinalSelectDevice(desc, SOURCE_TYPE_EC, PREFERRED_HIGH_QUALITY); EXPECT_NE(judge, nullptr); EXPECT_EQ(judge->deviceId_, 2); + + judge = audioUsrSelectManager.JudgeFinalSelectDevice(desc, SOURCE_TYPE_EC, PREFERRED_DEFAULT); + EXPECT_EQ(judge, nullptr); } /** @@ -226,13 +235,7 @@ HWTEST_F(AudioUsrSelectManagerUnitTest, AudioUsrSelectManager_JudgeFinalSelectDe desc->macAddress_ = "00:11:22:33:44:55"; desc->connectState_ = CONNECTED; - auto judge = audioUsrSelectManager.JudgeFinalSelectDevice(desc, SOURCE_TYPE_CAMCORDER); - EXPECT_NE(judge, nullptr); - - judge = audioUsrSelectManager.JudgeFinalSelectDevice(desc, SOURCE_TYPE_LIVE); - EXPECT_NE(judge, nullptr); - - judge = audioUsrSelectManager.JudgeFinalSelectDevice(desc, SOURCE_TYPE_VOICE_CALL); + auto judge = audioUsrSelectManager.JudgeFinalSelectDevice(desc, SOURCE_TYPE_CAMCORDER, PREFERRED_DEFAULT); EXPECT_NE(judge, nullptr); } } // namespace AudioStandard diff --git a/services/audio_service/client/src/audio_session_manager.cpp b/services/audio_service/client/src/audio_session_manager.cpp index c49b7f0b32b5f03b8b368fff127668507571ba9a..bbcb0705ee8e622a8603bc391b8dc99f06c8e0ab 100644 --- a/services/audio_service/client/src/audio_session_manager.cpp +++ b/services/audio_service/client/src/audio_session_manager.cpp @@ -132,12 +132,12 @@ int32_t AudioSessionManager::ClearSelectedInputDevice() return AudioPolicyManager::GetInstance().ClearSelectedInputDevice(); } -int32_t AudioSessionManager::PreferBluetoothAndNearlinkRecord(bool isPreferred) +int32_t AudioSessionManager::PreferBluetoothAndNearlinkRecord(BluetoothAndNearlinkPreferredRecordCategory category) { - return AudioPolicyManager::GetInstance().PreferBluetoothAndNearlinkRecord(isPreferred); + return AudioPolicyManager::GetInstance().PreferBluetoothAndNearlinkRecord(category); } -bool AudioSessionManager::GetPreferBluetoothAndNearlinkRecord() +BluetoothAndNearlinkPreferredRecordCategory AudioSessionManager::GetPreferBluetoothAndNearlinkRecord() { return AudioPolicyManager::GetInstance().GetPreferBluetoothAndNearlinkRecord(); }