From ad6b8b2a3e4363d9f6fbf51520dc825b6e3944cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=B6=E6=98=A5=E9=BE=99?= Date: Tue, 9 Sep 2025 21:08:04 +0800 Subject: [PATCH 1/8] =?UTF-8?q?=E8=AE=BE=E5=A4=87=E5=BC=BA=E9=80=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 陶春龙 --- .../napi_audio_session_manager.cpp | 33 +++++++---- .../audiomanager/napi_audio_session_manager.h | 1 + frameworks/js/napi/common/napi_audio_enum.cpp | 17 ++++++ frameworks/js/napi/common/napi_audio_enum.h | 1 + .../include/audio_policy_manager.h | 4 +- .../native/ohaudio/OHAudioSessionManager.cpp | 30 ++++++---- .../native/ohaudio/OHAudioSessionManager.h | 4 +- .../native/audiocommon/include/audio_info.h | 24 ++++++++ .../include/audio_session_manager.h | 4 +- .../native_audio_session_manager.h | 30 ++++++++++ .../src/audio_policy_manager_device.cpp | 18 +++--- services/audio_policy/idl/IAudioPolicy.idl | 4 +- .../device/include/audio_usr_select_manager.h | 7 ++- .../device/src/audio_usr_select_manager.cpp | 59 ++++++++++++------- .../service_main/include/audio_core_service.h | 8 +-- .../include/audio_policy_server.h | 4 +- .../service_main/src/audio_core_service.cpp | 10 ++-- .../src/audio_core_service_entry.cpp | 8 ++- .../service_main/src/audio_policy_server.cpp | 17 ++++-- .../audio_usr_select_manager_unit_test.cpp | 30 ++++++---- .../client/src/audio_session_manager.cpp | 6 +- 21 files changed, 225 insertions(+), 94 deletions(-) diff --git a/frameworks/js/napi/audiomanager/napi_audio_session_manager.cpp b/frameworks/js/napi/audiomanager/napi_audio_session_manager.cpp index 3e9e49fea2..c05af5b7ac 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 f6c910709a..6e318f91b6 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 a478696166..30c9dd204c 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 3d44de7041..1c167b421b 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 c02ab69db6..72d4dba35a 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 a0f996192d..7abe6895bc 100644 --- a/frameworks/native/ohaudio/OHAudioSessionManager.cpp +++ b/frameworks/native/ohaudio/OHAudioSessionManager.cpp @@ -178,8 +178,9 @@ OH_AudioCommon_Result OH_AudioSessionManager_ClearSelectedMediaInputDevice(OH_Au 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 +189,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,7 +206,7 @@ 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(); + *category = ohAudioSessionManager->GetPreferredBluetoothAndNearlinkRecord(); if (*enable == true) { AUDIO_INFO_LOG("is preferred Bluetooth and Nearlink"); @@ -529,19 +534,24 @@ 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() +OH_AudioSession_BluetoothAndNearlinkPreferredRecordCategory + OHAudioSessionManager::GetPreferredBluetoothAndNearlinkRecord() { CHECK_AND_RETURN_RET_LOG(audioSessionManager_ != nullptr, false, "failed, audioSessionManager_ is null"); - return audioSessionManager_->GetPreferBluetoothAndNearlinkRecord(); + auto category = audioSessionManager_->GetPreferBluetoothAndNearlinkRecord(); + OH_AudioSession_BluetoothAndNearlinkPreferredRecordCategory preferCategory = + static_cast(category); + return preferCategory; } bool OHAudioSessionManager::IsAudioSessionActivated() diff --git a/frameworks/native/ohaudio/OHAudioSessionManager.h b/frameworks/native/ohaudio/OHAudioSessionManager.h index 2ca130f79f..4b2ed4d381 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); + OH_AudioSession_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 6ab761a85c..b7e7777a3b 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 6a4cb5e80a..ed48d45b30 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 aa69628ac3..105a9600b9 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 c5ce3bad28..5e6a23a399 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 c4d922a041..f4bb8cad92 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 43f66e09e2..9a66160355 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 f67127fcac..e44ae3bac5 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,33 @@ 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); } - - if (isPreferred) { - isPreferredBluetoothAndNearlinkRecord_.push_front(uid); - } + + 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; + categoryMap_[uid]; } - return false; + return BluetoothAndNearlinkPreferredRecordCategory::PREFERRED_NONE; } void AudioUsrSelectManager::EnableSelectInputDevice( @@ -119,6 +123,7 @@ void AudioUsrSelectManager::EnableSelectInputDevice( int32_t uid = GetRealUid(streamDesc); uidMap[uid] = i; } + AUDIO_INFO_LOG("running stream size: %{public}ld", uidMap.size()); // use selected rules first for (const auto &device : selectedDevices_) { @@ -127,10 +132,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 +149,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 +171,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 +218,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 5aee838b50..a096bd8b30 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,8 @@ 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 +257,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 acb0f7cfbc..17ebcf3e23 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 9515f906c2..a3000ab81f 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 9e98bd9f0c..9b8a360d2f 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 9a1cde4d7e..ba7296fbdb 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,21 @@ 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); + judge = audioUsrSelectManager.JudgeFinalSelectDevice(desc, SOURCE_TYPE_LIVE, PREFERRED_DEFAULT); EXPECT_NE(judge, nullptr); EXPECT_EQ(judge->deviceId_, 2); + + 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_NE(judge, nullptr); + EXPECT_EQ(judge->deviceId_, 1); } /** @@ -226,13 +236,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 c49b7f0b32..bbcb0705ee 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(); } -- Gitee From a0dafa7ff452542fbf17035efabaf23d30a16d1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=B6=E6=98=A5=E9=BE=99?= Date: Tue, 9 Sep 2025 21:15:56 +0800 Subject: [PATCH 2/8] fix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 陶春龙 --- .../native/ohaudio/OHAudioSessionManager.cpp | 27 +++++++++++++++---- .../device/src/audio_usr_select_manager.cpp | 2 +- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/frameworks/native/ohaudio/OHAudioSessionManager.cpp b/frameworks/native/ohaudio/OHAudioSessionManager.cpp index 7abe6895bc..19f74bf9fe 100644 --- a/frameworks/native/ohaudio/OHAudioSessionManager.cpp +++ b/frameworks/native/ohaudio/OHAudioSessionManager.cpp @@ -150,18 +150,18 @@ 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; } @@ -309,6 +309,23 @@ 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; + } +} + OH_AudioCommon_Result OH_AudioSessionManager_RegisterCurrentOutputDeviceChangeCallback( OH_AudioSessionManager *audioSessionManager, OH_AudioSession_CurrentOutputDeviceChangedCallback callback) 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 e44ae3bac5..66b0f128c8 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 @@ -102,7 +102,7 @@ BluetoothAndNearlinkPreferredRecordCategory AudioUsrSelectManager::GetPreferBlue auto it = std::find(isPreferredBluetoothAndNearlinkRecord_.begin(), isPreferredBluetoothAndNearlinkRecord_.end(), uid); if (it != isPreferredBluetoothAndNearlinkRecord_.end()) { - categoryMap_[uid]; + return categoryMap_[uid]; } return BluetoothAndNearlinkPreferredRecordCategory::PREFERRED_NONE; } -- Gitee From 0cbb48a449b44422f4c8d97e5f5d1f08248e0ca3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=B6=E6=98=A5=E9=BE=99?= Date: Tue, 9 Sep 2025 22:23:41 +0800 Subject: [PATCH 3/8] fix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 陶春龙 --- .../native/ohaudio/OHAudioSessionManager.cpp | 44 ++++++++++--------- .../native/ohaudio/OHAudioSessionManager.h | 3 +- .../device/src/audio_usr_select_manager.cpp | 7 ++- .../service_main/include/audio_core_service.h | 3 +- .../service_main/src/audio_core_service.cpp | 3 +- .../src/audio_core_service_entry.cpp | 4 +- 6 files changed, 37 insertions(+), 27 deletions(-) diff --git a/frameworks/native/ohaudio/OHAudioSessionManager.cpp b/frameworks/native/ohaudio/OHAudioSessionManager.cpp index 19f74bf9fe..118aff6846 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(desc); + } + OHAudioDeviceDescriptor* ohDeviceDescriptor = convertDeviceDescriptor(deviceDescriptor); CHECK_AND_RETURN_RET_LOG(ohDeviceDescriptor != nullptr, AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM, "ohDeviceDescriptor is nullptr"); @@ -150,7 +153,7 @@ OH_AudioCommon_Result OH_AudioSessionManager_SelectMediaInputDevice( } OH_AudioCommon_Result OH_AudioSessionManager_GetSelectedMediaInputDevice( - OH_AudioSessionManager *audioSessionManager, OH_AudioDeviceDescriptor **audioDeviceDescriptor); + OH_AudioSessionManager *audioSessionManager, OH_AudioDeviceDescriptor **audioDeviceDescriptor) { if (audioSessionManager == nullptr || audioDeviceDescriptor == nullptr) { AUDIO_ERR_LOG("Invalid params!"); @@ -180,7 +183,7 @@ OH_AudioCommon_Result OH_AudioSessionManager_ClearSelectedMediaInputDevice(OH_Au OH_AudioCommon_Result OH_AudioSessionManager_SetBluetoothAndNearlinkPreferredRecordCategory( OH_AudioSessionManager *audioSessionManager, - OH_AudioSession_BluetoothAndNearlinkPreferredRecordCategory category); + OH_AudioSession_BluetoothAndNearlinkPreferredRecordCategory category) { if (audioSessionManager == nullptr) { AUDIO_ERR_LOG("Invalid params!"); @@ -197,7 +200,7 @@ OH_AudioCommon_Result OH_AudioSessionManager_SetBluetoothAndNearlinkPreferredRec OH_AudioCommon_Result OH_AudioSessionManager_GetBluetoothAndNearlinkPreferredRecordCategory( OH_AudioSessionManager *audioSessionManager, - OH_AudioSession_BluetoothAndNearlinkPreferredRecordCategory *category); + OH_AudioSession_BluetoothAndNearlinkPreferredRecordCategory *category) { if (audioSessionManager == nullptr) { AUDIO_ERR_LOG("Invalid params!"); @@ -206,13 +209,9 @@ OH_AudioCommon_Result OH_AudioSessionManager_GetBluetoothAndNearlinkPreferredRec OHAudioSessionManager *ohAudioSessionManager = convertManager(audioSessionManager); CHECK_AND_RETURN_RET_LOG(ohAudioSessionManager != nullptr, AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM, "ohAudioSessionManager is nullptr"); - *category = ohAudioSessionManager->GetPreferredBluetoothAndNearlinkRecord(); + 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; } @@ -535,6 +534,14 @@ OH_AudioCommon_Result OHAudioSessionManager::SelectMediaInputDevice( return result == 0 ? AUDIOCOMMON_RESULT_SUCCESS : AUDIOCOMMON_RESULT_ERROR_ILLEGAL_STATE; } +OH_AudioCommon_Result OHAudioSessionManager::ClearSelectedMediaInputDevice() +{ + CHECK_AND_RETURN_RET_LOG(audioSessionManager_ != nullptr, + AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM, "failed, audioSessionManager_ is null"); + int32_t result = audioSessionManager_->ClearSelectedInputDevice(); + return result == 0 ? AUDIOCOMMON_RESULT_SUCCESS : AUDIOCOMMON_RESULT_ERROR_ILLEGAL_STATE; +} + OH_AudioDeviceDescriptor *OHAudioSessionManager::GetSelectedMediaInputDevice() { CHECK_AND_RETURN_RET_LOG(audioSessionManager_ != nullptr, @@ -560,15 +567,12 @@ OH_AudioCommon_Result OHAudioSessionManager::PreferBluetoothAndNearlinkRecord( return result == 0 ? AUDIOCOMMON_RESULT_SUCCESS : AUDIOCOMMON_RESULT_ERROR_ILLEGAL_STATE; } -OH_AudioSession_BluetoothAndNearlinkPreferredRecordCategory - OHAudioSessionManager::GetPreferredBluetoothAndNearlinkRecord() +BluetoothAndNearlinkPreferredRecordCategory OHAudioSessionManager::GetPreferredBluetoothAndNearlinkRecord() { CHECK_AND_RETURN_RET_LOG(audioSessionManager_ != nullptr, - false, "failed, audioSessionManager_ is null"); - auto category = audioSessionManager_->GetPreferBluetoothAndNearlinkRecord(); - OH_AudioSession_BluetoothAndNearlinkPreferredRecordCategory preferCategory = - static_cast(category); - return preferCategory; + BluetoothAndNearlinkPreferredRecordCategory::PREFERRED_NONE, + "failed, audioSessionManager_ is null"); + return audioSessionManager_->GetPreferBluetoothAndNearlinkRecord(); } bool OHAudioSessionManager::IsAudioSessionActivated() diff --git a/frameworks/native/ohaudio/OHAudioSessionManager.h b/frameworks/native/ohaudio/OHAudioSessionManager.h index 4b2ed4d381..ba0ee04ef1 100644 --- a/frameworks/native/ohaudio/OHAudioSessionManager.h +++ b/frameworks/native/ohaudio/OHAudioSessionManager.h @@ -165,11 +165,12 @@ public: bool IsAudioSessionActivated(); OH_AudioDeviceDescriptorArray *GetAvailableDevices(AudioDeviceUsage deviceUsage); + OH_AudioCommon_Result OHAudioSessionManager::ClearSelectedMediaInputDevice(); OH_AudioCommon_Result SelectMediaInputDevice(const std::shared_ptr &deviceDescriptor); OH_AudioDeviceDescriptor *GetSelectedMediaInputDevice(); OH_AudioCommon_Result ClearSelectedMediaInputDevice(); OH_AudioCommon_Result PreferBluetoothAndNearlinkRecord(BluetoothAndNearlinkPreferredRecordCategory category); - OH_AudioSession_BluetoothAndNearlinkPreferredRecordCategory GetPreferredBluetoothAndNearlinkRecord(); + BluetoothAndNearlinkPreferredRecordCategory GetPreferredBluetoothAndNearlinkRecord(); OH_AudioCommon_Result SetAvailableDeviceChangeCallback( AudioDeviceUsage deviceUsage, OH_AudioSession_AvailableDeviceChangedCallback callback); 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 66b0f128c8..904b30ef2f 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 @@ -88,10 +88,13 @@ void AudioUsrSelectManager::PreferBluetoothAndNearlinkRecordByUid(int32_t uid, std::find(isPreferredBluetoothAndNearlinkRecord_.begin(), isPreferredBluetoothAndNearlinkRecord_.end(), uid); if (it != isPreferredBluetoothAndNearlinkRecord_.end()) { isPreferredBluetoothAndNearlinkRecord_.erase(it); + categoryMap_.erase(uid); } - isPreferredBluetoothAndNearlinkRecord_.push_front(uid); - categoryMap_[uid] = category; + if (category != BluetoothAndNearlinkPreferredRecordCategory::PREFERRED_NONE) { + isPreferredBluetoothAndNearlinkRecord_.push_front(uid); + categoryMap_[uid] = category; + } } BluetoothAndNearlinkPreferredRecordCategory AudioUsrSelectManager::GetPreferBluetoothAndNearlinkRecordByUid( 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 a096bd8b30..f97db9d711 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,7 +137,8 @@ public: int32_t uid); std::shared_ptr GetSelectedInputDeviceByUid(int32_t uid); int32_t ClearSelectedInputDeviceByUid(int32_t uid); - int32_t PreferBluetoothAndNearlinkRecordByUid(int32_t uid, BluetoothAndNearlinkPreferredRecordCategory category); + 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); 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 a3000ab81f..971a2f2526 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 @@ -1137,7 +1137,8 @@ int32_t AudioCoreService::ClearSelectedInputDeviceByUid(int32_t uid) return SUCCESS; } -int32_t AudioCoreService::PreferBluetoothAndNearlinkRecordByUid(int32_t uid, BluetoothAndNearlinkPreferredRecordCategory category) +int32_t AudioCoreService::PreferBluetoothAndNearlinkRecordByUid(int32_t uid, + BluetoothAndNearlinkPreferredRecordCategory category) { int32_t result = SUCCESS; audioUsrSelectManager_.PreferBluetoothAndNearlinkRecordByUid(uid, category); diff --git a/services/audio_policy/server/service/service_main/src/audio_core_service_entry.cpp b/services/audio_policy/server/service/service_main/src/audio_core_service_entry.cpp index c16e9016c6..3107192f69 100644 --- a/services/audio_policy/server/service/service_main/src/audio_core_service_entry.cpp +++ b/services/audio_policy/server/service/service_main/src/audio_core_service_entry.cpp @@ -442,8 +442,8 @@ int32_t AudioCoreService::EventEntry::PreferBluetoothAndNearlinkRecordByUid(int3 return coreService_->PreferBluetoothAndNearlinkRecordByUid(uid, category); } -BluetoothAndNearlinkPreferredRecordCategory AudioCoreService::EventEntry:: - GetPreferBluetoothAndNearlinkRecordByUid(int32_t uid) +BluetoothAndNearlinkPreferredRecordCategory AudioCoreService::EventEntry::GetPreferBluetoothAndNearlinkRecordByUid( + int32_t uid) { Trace trace("KeyAction AudioCoreService::GetPreferBluetoothAndNearlinkRecordByUid"); std::lock_guard lock(eventMutex_); -- Gitee From 28b77046922321eebf1c2495e748305d1d234dc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=B6=E6=98=A5=E9=BE=99?= Date: Tue, 9 Sep 2025 22:42:37 +0800 Subject: [PATCH 4/8] fix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 陶春龙 --- .../native/ohaudio/OHAudioSessionManager.cpp | 20 ------------------- .../native/ohaudio/OHAudioSessionManager.h | 1 - 2 files changed, 21 deletions(-) diff --git a/frameworks/native/ohaudio/OHAudioSessionManager.cpp b/frameworks/native/ohaudio/OHAudioSessionManager.cpp index 118aff6846..103476c60f 100644 --- a/frameworks/native/ohaudio/OHAudioSessionManager.cpp +++ b/frameworks/native/ohaudio/OHAudioSessionManager.cpp @@ -169,18 +169,6 @@ OH_AudioCommon_Result OH_AudioSessionManager_GetSelectedMediaInputDevice( 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_SetBluetoothAndNearlinkPreferredRecordCategory( OH_AudioSessionManager *audioSessionManager, OH_AudioSession_BluetoothAndNearlinkPreferredRecordCategory category) @@ -534,14 +522,6 @@ OH_AudioCommon_Result OHAudioSessionManager::SelectMediaInputDevice( return result == 0 ? AUDIOCOMMON_RESULT_SUCCESS : AUDIOCOMMON_RESULT_ERROR_ILLEGAL_STATE; } -OH_AudioCommon_Result OHAudioSessionManager::ClearSelectedMediaInputDevice() -{ - CHECK_AND_RETURN_RET_LOG(audioSessionManager_ != nullptr, - AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM, "failed, audioSessionManager_ is null"); - int32_t result = audioSessionManager_->ClearSelectedInputDevice(); - return result == 0 ? AUDIOCOMMON_RESULT_SUCCESS : AUDIOCOMMON_RESULT_ERROR_ILLEGAL_STATE; -} - OH_AudioDeviceDescriptor *OHAudioSessionManager::GetSelectedMediaInputDevice() { CHECK_AND_RETURN_RET_LOG(audioSessionManager_ != nullptr, diff --git a/frameworks/native/ohaudio/OHAudioSessionManager.h b/frameworks/native/ohaudio/OHAudioSessionManager.h index ba0ee04ef1..8fef4993b6 100644 --- a/frameworks/native/ohaudio/OHAudioSessionManager.h +++ b/frameworks/native/ohaudio/OHAudioSessionManager.h @@ -165,7 +165,6 @@ public: bool IsAudioSessionActivated(); OH_AudioDeviceDescriptorArray *GetAvailableDevices(AudioDeviceUsage deviceUsage); - OH_AudioCommon_Result OHAudioSessionManager::ClearSelectedMediaInputDevice(); OH_AudioCommon_Result SelectMediaInputDevice(const std::shared_ptr &deviceDescriptor); OH_AudioDeviceDescriptor *GetSelectedMediaInputDevice(); OH_AudioCommon_Result ClearSelectedMediaInputDevice(); -- Gitee From e9b079809fa2c7544480b62e692b7a0b2ba109c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=B6=E6=98=A5=E9=BE=99?= Date: Tue, 9 Sep 2025 23:04:24 +0800 Subject: [PATCH 5/8] fix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 陶春龙 --- frameworks/native/ohaudio/OHAudioSessionManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/native/ohaudio/OHAudioSessionManager.cpp b/frameworks/native/ohaudio/OHAudioSessionManager.cpp index 103476c60f..1f97c83393 100644 --- a/frameworks/native/ohaudio/OHAudioSessionManager.cpp +++ b/frameworks/native/ohaudio/OHAudioSessionManager.cpp @@ -140,7 +140,7 @@ OH_AudioCommon_Result OH_AudioSessionManager_SelectMediaInputDevice( AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM, "ohAudioSessionManager is nullptr"); if (deviceDescriptor == nullptr) { - return ohAudioSessionManager->ClearSelectedMediaInputDevice(desc); + return ohAudioSessionManager->ClearSelectedMediaInputDevice(); } OHAudioDeviceDescriptor* ohDeviceDescriptor = convertDeviceDescriptor(deviceDescriptor); -- Gitee From 26522ef142504a4d4899f636f249138fe2c9d145 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=B6=E6=98=A5=E9=BE=99?= Date: Tue, 9 Sep 2025 23:19:06 +0800 Subject: [PATCH 6/8] fix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 陶春龙 --- frameworks/native/ohaudio/OHAudioSessionManager.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/frameworks/native/ohaudio/OHAudioSessionManager.cpp b/frameworks/native/ohaudio/OHAudioSessionManager.cpp index 1f97c83393..4d98f7c3e2 100644 --- a/frameworks/native/ohaudio/OHAudioSessionManager.cpp +++ b/frameworks/native/ohaudio/OHAudioSessionManager.cpp @@ -311,6 +311,7 @@ OH_AudioCommon_Result OH_AudioSessionManager_ReleaseDevice( if (ohAudioDeviceDescriptor != nullptr) { delete ohAudioDeviceDescriptor; } + return AUDIOCOMMON_RESULT_SUCCESS; } OH_AudioCommon_Result OH_AudioSessionManager_RegisterCurrentOutputDeviceChangeCallback( -- Gitee From b62086c903ce1abaf1862d265368c7164d381779 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=B6=E6=98=A5=E9=BE=99?= Date: Tue, 9 Sep 2025 23:53:16 +0800 Subject: [PATCH 7/8] fix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 陶春龙 --- .../server/domain/device/src/audio_usr_select_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 904b30ef2f..a6d633bb58 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 @@ -126,7 +126,7 @@ void AudioUsrSelectManager::EnableSelectInputDevice( int32_t uid = GetRealUid(streamDesc); uidMap[uid] = i; } - AUDIO_INFO_LOG("running stream size: %{public}ld", uidMap.size()); + AUDIO_INFO_LOG("running stream size: %{public}" PRIu64, uidMap.size()); // use selected rules first for (const auto &device : selectedDevices_) { -- Gitee From 22851a018f59b63fd8fcc8c148322736a4cfaf4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=B6=E6=98=A5=E9=BE=99?= Date: Wed, 10 Sep 2025 00:14:14 +0800 Subject: [PATCH 8/8] fix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 陶春龙 --- .../server/domain/device/src/audio_usr_select_manager.cpp | 2 +- .../src/audio_usr_select_manager_unit_test.cpp | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) 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 a6d633bb58..ad0507d54c 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 @@ -126,7 +126,7 @@ void AudioUsrSelectManager::EnableSelectInputDevice( int32_t uid = GetRealUid(streamDesc); uidMap[uid] = i; } - AUDIO_INFO_LOG("running stream size: %{public}" PRIu64, uidMap.size()); + AUDIO_INFO_LOG("running stream size: %{public}zu", uidMap.size()); // use selected rules first for (const auto &device : selectedDevices_) { 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 ba7296fbdb..9f961eeb5c 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 @@ -217,8 +217,7 @@ HWTEST_F(AudioUsrSelectManagerUnitTest, AudioUsrSelectManager_JudgeFinalSelectDe EXPECT_EQ(judge->deviceId_, 2); judge = audioUsrSelectManager.JudgeFinalSelectDevice(desc, SOURCE_TYPE_EC, PREFERRED_DEFAULT); - EXPECT_NE(judge, nullptr); - EXPECT_EQ(judge->deviceId_, 1); + EXPECT_EQ(judge, nullptr); } /** -- Gitee