diff --git a/frameworks/js/napi/audiomanager/napi_audio_stream_manager.cpp b/frameworks/js/napi/audiomanager/napi_audio_stream_manager.cpp index da44dd66f0bd4940777d96e8367589e0e55d637a..c4707d2790f88f238fd4b7b33defb00c16dc3252 100644 --- a/frameworks/js/napi/audiomanager/napi_audio_stream_manager.cpp +++ b/frameworks/js/napi/audiomanager/napi_audio_stream_manager.cpp @@ -107,6 +107,8 @@ napi_value NapiAudioStreamMgr::Init(napi_env env, napi_value exports) DECLARE_NAPI_FUNCTION("isAcousticEchoCancelerSupported", IsAcousticEchoCancelerSupported), DECLARE_NAPI_FUNCTION("isRecordingAvailable", IsRecordingAvailable), DECLARE_NAPI_FUNCTION("isAudioLoopbackSupported", IsAudioLoopbackSupported), + DECLARE_NAPI_FUNCTION("isCurrentDeviceEnableIntelligentNoiseReduction", + IsCurrentDeviceEnableIntelligentNoiseReduction), }; status = napi_define_class(env, AUDIO_STREAM_MGR_NAPI_CLASS_NAME.c_str(), NAPI_AUTO_LENGTH, Construct, nullptr, @@ -909,5 +911,32 @@ napi_value NapiAudioStreamMgr::IsAudioLoopbackSupported(napi_env env, napi_callb NapiParamUtils::SetValueBoolean(env, isSupported, result); return result; } + +napi_value NapiAudioStreamMgr::IsCurrentDeviceEnableIntelligentNoiseReduction(napi_env env, napi_callback_info info) +{ + napi_value result = nullptr; + size_t argc = ARGS_ONE; + napi_value args[ARGS_ONE] = {}; + auto *napiStreamMgr = GetParamWithSync(env, info, argc, args); + CHECK_AND_RETURN_RET_LOG(argc == ARGS_ONE && napiStreamMgr != nullptr && + napiStreamMgr->audioStreamMngr_ != nullptr, NapiAudioError::ThrowErrorAndReturn(env, + NAPI_ERR_INPUT_INVALID, + "parameter verification failed: mandatory parameters are left unspecified"), "argcCount invalid"); + napi_valuetype valueType = napi_undefined; + napi_typeof(env, args[PARAM0], &valueType); + CHECK_AND_RETURN_RET_LOG(valueType == napi_number, NapiAudioError::ThrowErrorAndReturn(env, + NAPI_ERR_INPUT_INVALID, "incorrect parameter types: The type of options must be number"), + "invaild valueType"); + int32_t sourceType = 0; + NapiParamUtils::GetValueInt32(env, sourceType, args[PARAM0]); + CHECK_AND_RETURN_RET_LOG(NapiAudioEnum::IsValidSourceType(sourceType), + NapiAudioError::ThrowErrorAndReturn(env, NAPI_ERR_INVALID_PARAM, + "parameter verification failed: The param of sourceType must be enum SourceType"), "get sourceType failed"); + + bool isSupported = napiStreamMgr->audioStreamMngr_->IsCurrentDeviceEnableIntelligentNoiseReduction( + static_cast(sourceType)); + NapiParamUtils::SetValueBoolean(env, isSupported, result); + return result; +} } // namespace AudioStandard } // namespace OHOS diff --git a/frameworks/js/napi/audiomanager/napi_audio_stream_manager.h b/frameworks/js/napi/audiomanager/napi_audio_stream_manager.h index 6ae77296c939e0d6368bfc96ef084a8e2caf7ff7..8a62f45519786679b4b727781dbed71fc9f477cb 100644 --- a/frameworks/js/napi/audiomanager/napi_audio_stream_manager.h +++ b/frameworks/js/napi/audiomanager/napi_audio_stream_manager.h @@ -83,6 +83,7 @@ private: static napi_value IsAcousticEchoCancelerSupported(napi_env env, napi_callback_info info); static napi_value IsRecordingAvailable(napi_env env, napi_callback_info info); static napi_value IsAudioLoopbackSupported(napi_env env, napi_callback_info info); + static napi_value IsCurrentDeviceEnableIntelligentNoiseReduction(napi_env env, napi_callback_info info); static void RegisterCallback(napi_env env, napi_value jsThis, napi_value *args, const std::string &cbName); static void RegisterCapturerStateChangeCallback(napi_env env, napi_value *args, diff --git a/frameworks/native/audiopolicy/include/audio_policy_manager.h b/frameworks/native/audiopolicy/include/audio_policy_manager.h index e7ed0c67730d907be41eef9c354c8eca5d86f9dd..77478a438efba7547cd7a030d0748da9646ac3f9 100644 --- a/frameworks/native/audiopolicy/include/audio_policy_manager.h +++ b/frameworks/native/audiopolicy/include/audio_policy_manager.h @@ -620,6 +620,7 @@ public: int32_t GetAudioEnhanceProperty(AudioEnhancePropertyArray &propertyArray); bool IsAcousticEchoCancelerSupported(SourceType sourceType); bool IsAudioLoopbackSupported(AudioLoopbackMode mode); + bool IsCurrentDeviceEnableIntelligentNoiseReduction(SourceType sourceType); bool SetKaraokeParameters(const std::string ¶meters); int32_t SetAudioRouteCallback(uint32_t sessionId, std::shared_ptr callback, uint32_t clientUid); int32_t UnsetAudioRouteCallback(uint32_t sessionId); diff --git a/frameworks/native/ohaudio/OHAudioStreamManager.cpp b/frameworks/native/ohaudio/OHAudioStreamManager.cpp index 7af92bf68be2b932a6a5ce84f00a30ae5937bf90..0c8c8912bb2be405e13658e8527eda4ad4ac38b6 100644 --- a/frameworks/native/ohaudio/OHAudioStreamManager.cpp +++ b/frameworks/native/ohaudio/OHAudioStreamManager.cpp @@ -157,6 +157,18 @@ bool OH_AudioStreamManager_IsFastRecordingSupported( return ohAudioStreamManager->IsFastRecordingSupported(audioStreamInfo, sourceType); } +bool OH_AudioStreamManager_IsCurrentDeviceEnableIntelligentNoiseReduction( + OH_AudioStreamManager *streamManager, OH_AudioStream_SourceType source) +{ + OHAudioStreamManager *ohAudioStreamManager = convertManager(streamManager); + CHECK_AND_RETURN_RET_LOG(ohAudioStreamManager != nullptr, + false, "ohAudioStreamManager is nullptr"); + CHECK_AND_RETURN_RET_LOG(VALID_OH_SOURCE_TYPES.count(source) != 0, + false, "sourceType is invalid"); + SourceType sourceType = static_cast(source); + return ohAudioStreamManager->IsCurrentDeviceEnableIntelligentNoiseReduction(sourceType); +} + namespace OHOS { namespace AudioStandard { @@ -196,5 +208,11 @@ bool OHAudioStreamManager::IsFastRecordingSupported(AudioStreamInfo &streamInfo, CHECK_AND_RETURN_RET_LOG(audioStreamManager_ != nullptr, false, "failed, audioStreamManager_ is null"); return audioStreamManager_->IsFastRecordingSupported(streamInfo, source); } + +bool OHAudioStreamManager::IsCurrentDeviceEnableIntelligentNoiseReduction(SourceType sourceType) +{ + CHECK_AND_RETURN_RET_LOG(audioStreamManager_ != nullptr, false, "failed, audioStreamManager_ is null"); + return audioStreamManager_->IsCurrentDeviceEnableIntelligentNoiseReduction(sourceType); +} } // namespace AudioStandard } // namespace OHOS diff --git a/frameworks/native/ohaudio/OHAudioStreamManager.h b/frameworks/native/ohaudio/OHAudioStreamManager.h index f6090258de9814e94ed257cd130a2e608bd2e17d..dc055a15f6cbb44258d602f9caf6abe9b0e8e7d7 100644 --- a/frameworks/native/ohaudio/OHAudioStreamManager.h +++ b/frameworks/native/ohaudio/OHAudioStreamManager.h @@ -43,6 +43,7 @@ public: bool IsFastPlaybackSupported(AudioStreamInfo &streamInfo, StreamUsage usage); bool IsFastRecordingSupported(AudioStreamInfo &streamInfo, SourceType source); + bool IsCurrentDeviceEnableIntelligentNoiseReduction(SourceType sourceType); private: OHAudioStreamManager(); static OHAudioStreamManager *ohAudioStreamManager_; diff --git a/frameworks/native/ohaudio/test/unittest/oh_audio_stream_manager_test/src/oh_audio_stream_manager_unit_test.cpp b/frameworks/native/ohaudio/test/unittest/oh_audio_stream_manager_test/src/oh_audio_stream_manager_unit_test.cpp index c5a9be7bbc804c089eaec9329d008478195c3ed9..4798016251b8f4df5f5ed3569a4604b82b835090 100644 --- a/frameworks/native/ohaudio/test/unittest/oh_audio_stream_manager_test/src/oh_audio_stream_manager_unit_test.cpp +++ b/frameworks/native/ohaudio/test/unittest/oh_audio_stream_manager_test/src/oh_audio_stream_manager_unit_test.cpp @@ -205,5 +205,22 @@ HWTEST(OHAudioStreamManagerUnitTest, OH_AudioStreamManager_IsFastRecordingSuppor auto result = OH_AudioStreamManager_IsFastRecordingSupported(audioStreamManager, streamInfo, sourceType); EXPECT_EQ(result, true); } + +/** + * @tc.name : Test OH_AudioStreamManager_IsCurrentDeviceEnableIntelligentNoiseReduction. + * @tc.number: OH_AudioStreamManager_IsCurrentDeviceEnableIntelligentNoiseReduction_001 + * @tc.desc : Test OH_AudioStreamManager_IsCurrentDeviceEnableIntelligentNoiseReduction. + */ +HWTEST(OHAudioStreamManagerUnitTest, OH_AudioStreamManager_IsCurrentDeviceEnableIntelligentNoiseReduction_001, + TestSize.Level0) +{ + OH_AudioStreamManager *audioStreamManager = nullptr; + auto ret = OH_AudioManager_GetAudioStreamManager(&audioStreamManager); + EXPECT_EQ(ret, AUDIOCOMMON_RESULT_SUCCESS); + + OH_AudioStream_SourceType sourceType = AUDIOSTREAM_SOURCE_TYPE_MIC; + auto result = OH_AudioStreamManager_IsCurrentDeviceEnableIntelligentNoiseReduction(audioStreamManager, sourceType); + EXPECT_EQ(result, false); +} } // namespace AudioStandard } // namespace OHOS diff --git a/interfaces/inner_api/native/audiomanager/include/audio_stream_manager.h b/interfaces/inner_api/native/audiomanager/include/audio_stream_manager.h index 9bed47d7db17c5b576d8473550117f3bc55bdccc..618079f99e3194d74be0e384f0ffb377b15a79d3 100644 --- a/interfaces/inner_api/native/audiomanager/include/audio_stream_manager.h +++ b/interfaces/inner_api/native/audiomanager/include/audio_stream_manager.h @@ -390,6 +390,14 @@ public: * @since 20 */ bool IsAudioLoopbackSupported(AudioLoopbackMode mode); + + /** + * @brief Return if the system recording supports intelligent noise reduction for current device. + * @param SourceType sourceType used to decide the audio device and pipe type selection result. + * @return {@code true} if the system recording supports intelligent noise reduction for current device. + * @since 21 + */ + bool IsCurrentDeviceEnableIntelligentNoiseReduction(SourceType sourceType); private: std::mutex rendererStateChangeCallbacksMutex_; std::vector> rendererStateChangeCallbacks_; diff --git a/interfaces/kits/c/audio_manager/native_audio_stream_manager.h b/interfaces/kits/c/audio_manager/native_audio_stream_manager.h index 2241d4f404161842ad61cd94d966c93d47fbebe2..6b60df28f95af965470ba384afd3ad672b7f8902 100644 --- a/interfaces/kits/c/audio_manager/native_audio_stream_manager.h +++ b/interfaces/kits/c/audio_manager/native_audio_stream_manager.h @@ -136,6 +136,18 @@ bool OH_AudioStreamManager_IsFastPlaybackSupported( bool OH_AudioStreamManager_IsFastRecordingSupported( OH_AudioStreamManager *streamManager, OH_AudioStreamInfo *streamInfo, OH_AudioStream_SourceType source); +/** + * @brief Return if the system recording supports intelligent noise reduction for current device. + * + * @param streamManager {@link OH_AudioStreamManager} handle + * provided by {@link OH_AudioManager_GetAudioStreamManager}. + * @param source stream source type used to decide the audio device and pipe type selection result. + * @return {@code true} if the system recording supports intelligent noise reduction for current device. + * @since 21 + */ +bool OH_AudioStreamManager_IsCurrentDeviceEnableIntelligentNoiseReduction( + OH_AudioStreamManager *streamManager, OH_AudioStream_SourceType source); + #ifdef __cplusplus } #endif diff --git a/services/audio_policy/client/service/src/audio_policy_manager.cpp b/services/audio_policy/client/service/src/audio_policy_manager.cpp index ac9bdab7e62db8e187cb645fbb14a8d209b86949..74169562e1cc3a071b5f635ce75b4bbf74eeaa1b 100644 --- a/services/audio_policy/client/service/src/audio_policy_manager.cpp +++ b/services/audio_policy/client/service/src/audio_policy_manager.cpp @@ -3291,6 +3291,16 @@ int32_t AudioPolicyManager::GetMinVolumeDegree(AudioVolumeType volumeType) return volumeDegree; } +bool AudioPolicyManager::IsCurrentDeviceEnableIntelligentNoiseReduction(SourceType sourceType) +{ + const sptr gsp = GetAudioPolicyManagerProxy(); + CHECK_AND_RETURN_RET_LOG(gsp != nullptr, false, "audio policy manager proxy is NULL."); + + bool isSupport = false; + gsp->IsCurrentDeviceEnableIntelligentNoiseReduction(sourceType, isSupport); + return isSupport; +} + AudioPolicyManager& AudioPolicyManager::GetInstance() { static AudioPolicyManager policyManager; diff --git a/services/audio_policy/common/include/audio_policy_ipc_interface_code.h b/services/audio_policy/common/include/audio_policy_ipc_interface_code.h index e92dbc1eb359e79cfe89ca23b09ca81200e4480b..36ed5076af5e62972d6a007fb15ff0139a5a0449 100644 --- a/services/audio_policy/common/include/audio_policy_ipc_interface_code.h +++ b/services/audio_policy/common/include/audio_policy_ipc_interface_code.h @@ -248,7 +248,8 @@ enum class AudioPolicyInterfaceCode { GET_SESSION_DEFAULT_OUTPUT_DEVICE, SET_SESSION_DEFAULT_OUTPUT_DEVICE, SET_QUERY_DEVICE_VOLUME_BEHAVIOR_CALLBACK, - AUDIO_POLICY_MANAGER_CODE_MAX = SET_QUERY_DEVICE_VOLUME_BEHAVIOR_CALLBACK, + IS_CURRENT_DEVICE_ENABLE_INTELLIGENT_NOISE_REDUCTION, + AUDIO_POLICY_MANAGER_CODE_MAX = IS_CURRENT_DEVICE_ENABLE_INTELLIGENT_NOISE_REDUCTION, }; } // namespace AudioStandard } // namespace OHOS diff --git a/services/audio_policy/idl/IAudioPolicy.idl b/services/audio_policy/idl/IAudioPolicy.idl index 62b3c23018eb9ba89cac21d24f5bc75efa4539c4..4fda6f7781d7feccfee9ec823f06fa80c2440be4 100644 --- a/services/audio_policy/idl/IAudioPolicy.idl +++ b/services/audio_policy/idl/IAudioPolicy.idl @@ -294,6 +294,7 @@ interface IAudioPolicy { void SetSystemVolumeDegree([in] int volumeType, [in] int volumeDegree, [in] int volumeFlag, [in] int uid); void GetSystemVolumeDegree([in] int volumeType, [in] int uid, [out] int volumeDegree); void GetMinVolumeDegree([in] int volumeType, [out] int volumeDegree); + void IsCurrentDeviceEnableIntelligentNoiseReduction([in] int sourceType, [out] boolean ret); // WARNING: above functions correspond with AudioPolicyInterfaceCode void GetAudioZoneByName([in] String name, [out] int zoneId); 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 73b8147036197aaa4fa4c917394a89fd88f88cd9..c1d2d9543fe786afa1fdb4b69715a9b547b53137 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 @@ -329,6 +329,7 @@ public: int32_t IsAcousticEchoCancelerSupported(int32_t sourceType, bool &ret) override; int32_t IsAudioLoopbackSupported(int32_t mode, bool &ret) override; + int32_t IsCurrentDeviceEnableIntelligentNoiseReduction(int32_t sourceType, bool &ret) override; int32_t SetKaraokeParameters(const std::string ¶meters, bool &ret) override; int32_t GetNetworkIdByGroupId(int32_t groupId, std::string &networkId) override; diff --git a/services/audio_policy/server/service/service_main/include/audio_policy_service.h b/services/audio_policy/server/service/service_main/include/audio_policy_service.h index b634e93d3e7dac7c3f9a11120e1cd020752cfb3a..e5a3d140d462bb6a83bb90443bca89bbc3f2f262 100644 --- a/services/audio_policy/server/service/service_main/include/audio_policy_service.h +++ b/services/audio_policy/server/service/service_main/include/audio_policy_service.h @@ -230,6 +230,7 @@ public: int32_t GetSupportedAudioEnhanceProperty(AudioEnhancePropertyArray &propertyArray); int32_t SetAudioEnhanceProperty(const AudioEnhancePropertyArray &propertyArray); int32_t GetAudioEnhanceProperty(AudioEnhancePropertyArray &propertyArray); + bool IsCurrentDeviceEnableIntelligentNoiseReduction(SourceType sourceType); bool getFastControlParam(); void OnReceiveEvent(const EventFwk::CommonEventData &eventData); @@ -318,6 +319,7 @@ private: BluetoothOffloadState GetA2dpOffloadFlag(); void SetDefaultAdapterEnable(bool isEnable); bool IsDevicePlaybackSupported(const AudioProcessConfig &config, const AudioDeviceDescriptor &deviceInfo); + bool CheckVoipAnrOn(std::vector &property); private: static bool isBtListenerRegistered; 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 2153facd0940ca1e77e0a0d4e9adb6fc02bae0b3..06723a13518a673cb715dc1017e12fc2b86cb9e6 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 @@ -5375,5 +5375,12 @@ int32_t AudioPolicyServer::GetMinVolumeDegree(int32_t volumeType, int32_t &volum volumeDegree = audioVolumeManager_.GetMinVolumeDegree(static_cast(volumeType)); return SUCCESS; } + +int32_t AudioPolicyServer::IsCurrentDeviceEnableIntelligentNoiseReduction(int32_t sourceType, bool &ret) +{ + ret = audioPolicyService_.IsCurrentDeviceEnableIntelligentNoiseReduction( + static_cast(sourceType)); + return SUCCESS; +} } // namespace AudioStandard } // namespace OHOS diff --git a/services/audio_policy/server/service/service_main/src/audio_policy_service.cpp b/services/audio_policy/server/service/service_main/src/audio_policy_service.cpp index 5fc0f49e59ffd5ed8946e8a88117dbbb81fc2528..f9aaa39bae566545e4f82770bc15e9410c6dc528 100644 --- a/services/audio_policy/server/service/service_main/src/audio_policy_service.cpp +++ b/services/audio_policy/server/service/service_main/src/audio_policy_service.cpp @@ -63,6 +63,13 @@ const int32_t UID_AUDIO = 1041; mutex g_dataShareHelperMutex; bool AudioPolicyService::isBtListenerRegistered = false; bool AudioPolicyService::isBtCrashed = false; +const std::string AINR_FLAG = "ai_voice_noise_suppression_flag"; +const std::string AUDIO_SETTING_TABLE_TYPE = "global"; +const std::string LIVE_EFFECT_KEY = "live_effect_enable"; +const std::string LIVE_EFFECT_TABLE_TYPE = "system"; +const std::string LIVE_EFFECT_ON = "NRON"; +const int32_t INVALID_VALUE = -1; +static const std::unordered_set ANRCategories = {"AINR", "PNR"}; AudioPolicyService::~AudioPolicyService() { @@ -1180,5 +1187,56 @@ int32_t AudioPolicyService::CaptureConcurrentCheck(const uint32_t &sessionID) { return AudioCoreService::GetCoreService()->CaptureConcurrentCheck(sessionID); } + +bool AudioPolicyService::CheckVoipAnrOn(std::vector &property) +{ + bool ret = false; + for (const auto &item : property) { + if (item.name != "voip_up") continue; + if (ANRCategories.find(item.category) != ANRCategories.end()) { + ret = true; + break; + } + } + return ret; +} + +bool AudioPolicyService::IsCurrentDeviceEnableIntelligentNoiseReduction(SourceType sourceType) +{ + if (sourceType != SOURCE_TYPE_LIVE && sourceType != SOURCE_TYPE_VOICE_COMMUNICATION) { + AUDIO_INFO_LOG("SourceType %{public}d IsCurrentDeviceEnableIntelligentNoiseReduction 0", sourceType); + return false; + } + + bool ret = false; + if (sourceType == SOURCE_TYPE_LIVE) { + std::string paramKey = LIVE_EFFECT_KEY; + std::string paramValue = ""; + AudioSettingProvider &settingProvider = AudioSettingProvider::GetInstance(AUDIO_POLICY_SERVICE_ID); + CHECK_AND_RETURN_RET_LOG(settingProvider.CheckOsAccountReady(), false, "os account not ready"); + settingProvider.GetStringValue(paramKey, paramValue, LIVE_EFFECT_TABLE_TYPE); + ret = (paramValue == LIVE_EFFECT_ON); + AUDIO_INFO_LOG("SourceType %{public}d IsCurrentDeviceEnableIntelligentNoiseReduction %{public}d", + sourceType, ret); + return ret; + } + + bool isEcFeatureEnable = audioEcManager_.GetEcFeatureEnable(); + if (isEcFeatureEnable) { // is configed according to the product + AudioEffectPropertyArrayV3 propertyArray = {}; + int32_t getPropRet = GetAudioEnhanceProperty(propertyArray); + CHECK_AND_RETURN_RET_LOG(getPropRet == SUCCESS, false, "get audio enhance property failed, return false"); + ret = CheckVoipAnrOn(propertyArray.property); + } else { + AudioSettingProvider &settingProvider = AudioSettingProvider::GetInstance(AUDIO_POLICY_SERVICE_ID); + CHECK_AND_RETURN_RET_LOG(settingProvider.CheckOsAccountReady(), false, "os account not ready"); + int32_t flagValue = INVALID_VALUE; + settingProvider.GetIntValue(AINR_FLAG, flagValue, AUDIO_SETTING_TABLE_TYPE); + ret = (flagValue == 1); + } + AUDIO_INFO_LOG("SourceType %{public}d IsCurrentDeviceEnableIntelligentNoiseReduction %{public}d", + sourceType, ret); + return ret; +} } // namespace AudioStandard } // namespace OHOS diff --git a/services/audio_policy/test/unittest/audio_interrupt_service_test/src/audio_policy_server_unit_test.cpp b/services/audio_policy/test/unittest/audio_interrupt_service_test/src/audio_policy_server_unit_test.cpp index 0394347d628317fecd0a726e000a1b3200bdbbb5..c1c720b6d6b2323e8f2b83a31bca05a120e059ea 100644 --- a/services/audio_policy/test/unittest/audio_interrupt_service_test/src/audio_policy_server_unit_test.cpp +++ b/services/audio_policy/test/unittest/audio_interrupt_service_test/src/audio_policy_server_unit_test.cpp @@ -3716,5 +3716,21 @@ HWTEST(AudioPolicyUnitTest, GetDeviceVolumeBehavior_001, TestSize.Level1) VolumeBehavior volumeBehavior = server->audioDeviceManager_.GetDeviceVolumeBehavior(networkId, deviceType); EXPECT_EQ(volumeBehavior.isReady, false); } + +/** +* @tc.name : Test AudioPolicyServer. +* @tc.number: IsCurrentDeviceEnableIntelligentNoiseReduction_001 +* @tc.desc : Test IsCurrentDeviceEnableIntelligentNoiseReduction. +*/ +HWTEST(AudioPolicyUnitTest, IsCurrentDeviceEnableIntelligentNoiseReduction_001, TestSize.Level1) +{ + sptr server = GetPolicyServerUnitTest(); + ASSERT_TRUE(server != nullptr); + + SourceType sourceType = SourceType::SOURCE_TYPE_MIC; + bool isSupport = false; + int32_t ret = server->IsCurrentDeviceEnableIntelligentNoiseReduction(sourceType, isSupport); + EXPECT_EQ(ret, SUCCESS); +} } // AudioStandard } // OHOS diff --git a/services/audio_policy/test/unittest/audio_policy_service_unit_test/src/audio_policy_service_thirdext_unit_test.cpp b/services/audio_policy/test/unittest/audio_policy_service_unit_test/src/audio_policy_service_thirdext_unit_test.cpp index adb0bf4a432d3dd607e400e1a9ad493eb3f66ce4..300669a8ee2bbf86f124aaa54473a69e7829ee78 100644 --- a/services/audio_policy/test/unittest/audio_policy_service_unit_test/src/audio_policy_service_thirdext_unit_test.cpp +++ b/services/audio_policy/test/unittest/audio_policy_service_unit_test/src/audio_policy_service_thirdext_unit_test.cpp @@ -1687,5 +1687,131 @@ HWTEST_F(AudioPolicyServiceFourthUnitTest, GetMinVolumeLevel_002, TestSize.Level EXPECT_EQ(ret, SUCCESS); EXPECT_EQ(volumeLevel, MIN_VOLUME_LEVEL); } + +/** +* @tc.name : Test IsCurrentDeviceEnableIntelligentNoiseReduction. +* @tc.number: IsCurrentDeviceEnableIntelligentNoiseReduction_001 +* @tc.desc : Test IsCurrentDeviceEnableIntelligentNoiseReduction interfaces. +*/ +HWTEST_F(AudioPolicyServiceFourthUnitTest, IsCurrentDeviceEnableIntelligentNoiseReduction_001, TestSize.Level1) +{ + auto server = GetServerUtil::GetServerPtr(); + EXPECT_NE(nullptr, server); + + SourceType sourceType = SourceType::SOURCE_TYPE_MIC; + bool ret = server->audioPolicyService_.IsCurrentDeviceEnableIntelligentNoiseReduction(sourceType); + EXPECT_EQ(ret, false); +} + +/** +* @tc.name : Test IsCurrentDeviceEnableIntelligentNoiseReduction. +* @tc.number: IsCurrentDeviceEnableIntelligentNoiseReduction_002 +* @tc.desc : Test IsCurrentDeviceEnableIntelligentNoiseReduction interfaces. +*/ +HWTEST_F(AudioPolicyServiceFourthUnitTest, IsCurrentDeviceEnableIntelligentNoiseReduction_002, TestSize.Level1) +{ + auto server = GetServerUtil::GetServerPtr(); + EXPECT_NE(nullptr, server); + + SourceType sourceType = SourceType::SOURCE_TYPE_LIVE; + bool ret = server->audioPolicyService_.IsCurrentDeviceEnableIntelligentNoiseReduction(sourceType); + EXPECT_EQ(ret, true); +} + +/** +* @tc.name : Test IsCurrentDeviceEnableIntelligentNoiseReduction. +* @tc.number: IsCurrentDeviceEnableIntelligentNoiseReduction_003 +* @tc.desc : Test IsCurrentDeviceEnableIntelligentNoiseReduction interfaces. +*/ +HWTEST_F(AudioPolicyServiceFourthUnitTest, IsCurrentDeviceEnableIntelligentNoiseReduction_003, TestSize.Level1) +{ + auto server = GetServerUtil::GetServerPtr(); + EXPECT_NE(nullptr, server); + + SourceType sourceType = SourceType::SOURCE_TYPE_VOICE_COMMUNICATION; + server->audioPolicyService_.audioEcManager_.isEcFeatureEnable_ = 1; + bool ret = server->audioPolicyService_.IsCurrentDeviceEnableIntelligentNoiseReduction(sourceType); + EXPECT_EQ(ret, false); +} + +/** +* @tc.name : Test IsCurrentDeviceEnableIntelligentNoiseReduction. +* @tc.number: IsCurrentDeviceEnableIntelligentNoiseReduction_004 +* @tc.desc : Test IsCurrentDeviceEnableIntelligentNoiseReduction interfaces. +*/ +HWTEST_F(AudioPolicyServiceFourthUnitTest, IsCurrentDeviceEnableIntelligentNoiseReduction_004, TestSize.Level1) +{ + auto server = GetServerUtil::GetServerPtr(); + EXPECT_NE(nullptr, server); + + SourceType sourceType = SourceType::SOURCE_TYPE_VOICE_COMMUNICATION; + server->audioPolicyService_.audioEcManager_.isEcFeatureEnable_ = 0; + bool ret = server->audioPolicyService_.IsCurrentDeviceEnableIntelligentNoiseReduction(sourceType); + EXPECT_EQ(ret, false); +} + +/** +* @tc.name : Test CheckVoipAnrOn. +* @tc.number: CheckVoipAnrOn_001 +* @tc.desc : Test CheckVoipAnrOn interfaces. +*/ +HWTEST_F(AudioPolicyServiceFourthUnitTest, CheckVoipAnrOn_001, TestSize.Level1) +{ + auto server = GetServerUtil::GetServerPtr(); + EXPECT_NE(nullptr, server); + + AudioEffectPropertyArrayV3 propertyArray = {}; + propertyArray.property.push_back({"record", "NROFF"}); + bool ret = server->audioPolicyService_.CheckVoipAnrOn(propertyArray.property); + EXPECT_EQ(ret, false); +} + +/** +* @tc.name : Test CheckVoipAnrOn. +* @tc.number: CheckVoipAnrOn_002 +* @tc.desc : Test CheckVoipAnrOn interfaces. +*/ +HWTEST_F(AudioPolicyServiceFourthUnitTest, CheckVoipAnrOn_002, TestSize.Level1) +{ + auto server = GetServerUtil::GetServerPtr(); + EXPECT_NE(nullptr, server); + + AudioEffectPropertyArrayV3 propertyArray = {}; + propertyArray.property.push_back({"voip_up", "NROFF"}); + bool ret = server->audioPolicyService_.CheckVoipAnrOn(propertyArray.property); + EXPECT_EQ(ret, false); +} + +/** +* @tc.name : Test CheckVoipAnrOn. +* @tc.number: CheckVoipAnrOn_003 +* @tc.desc : Test CheckVoipAnrOn interfaces. +*/ +HWTEST_F(AudioPolicyServiceFourthUnitTest, CheckVoipAnrOn_003, TestSize.Level1) +{ + auto server = GetServerUtil::GetServerPtr(); + EXPECT_NE(nullptr, server); + + AudioEffectPropertyArrayV3 propertyArray = {}; + propertyArray.property.push_back({"record", "AINR"}); + bool ret = server->audioPolicyService_.CheckVoipAnrOn(propertyArray.property); + EXPECT_EQ(ret, false); +} + +/** +* @tc.name : Test CheckVoipAnrOn. +* @tc.number: CheckVoipAnrOn_004 +* @tc.desc : Test CheckVoipAnrOn interfaces. +*/ +HWTEST_F(AudioPolicyServiceFourthUnitTest, CheckVoipAnrOn_004, TestSize.Level1) +{ + auto server = GetServerUtil::GetServerPtr(); + EXPECT_NE(nullptr, server); + + AudioEffectPropertyArrayV3 propertyArray = {}; + propertyArray.property.push_back({"voip_up", "AINR"}); + bool ret = server->audioPolicyService_.CheckVoipAnrOn(propertyArray.property); + EXPECT_EQ(ret, true); +} } // namespace AudioStandard } // namespace OHOS diff --git a/services/audio_service/client/src/audio_stream_manager.cpp b/services/audio_service/client/src/audio_stream_manager.cpp index 01818ec90da8b59f8a41a852dfe39184b762dcb3..398162f01daec9af78ea9a279ed2daa27fd4e506 100644 --- a/services/audio_service/client/src/audio_stream_manager.cpp +++ b/services/audio_service/client/src/audio_stream_manager.cpp @@ -327,5 +327,10 @@ bool AudioStreamManager::IsAudioLoopbackSupported(AudioLoopbackMode mode) { return AudioPolicyManager::GetInstance().IsAudioLoopbackSupported(mode); } + +bool AudioStreamManager::IsCurrentDeviceEnableIntelligentNoiseReduction(SourceType sourceType) +{ + return AudioPolicyManager::GetInstance().IsCurrentDeviceEnableIntelligentNoiseReduction(sourceType); +} } // namespace AudioStandard } // namespace OHOS diff --git a/services/audio_service/test/unittest/client/audio_stream_manager_unit_test.cpp b/services/audio_service/test/unittest/client/audio_stream_manager_unit_test.cpp index 90957c4796eb58fcb7054a4b3678a43f1c1c510f..6926614be718dae35b5654bef37618aa830e024f 100644 --- a/services/audio_service/test/unittest/client/audio_stream_manager_unit_test.cpp +++ b/services/audio_service/test/unittest/client/audio_stream_manager_unit_test.cpp @@ -311,5 +311,19 @@ HWTEST(AudioStreamManagerUnitTest, IsCapturerFocusAvailable_001, TestSize.Level1 int32_t result = AudioStreamManager::GetInstance()->IsCapturerFocusAvailable(capturerInfo); EXPECT_NE(result, 0); } + +/** + * @tc.name : Test IsCurrentDeviceEnableIntelligentNoiseReduction API + * @tc.type : FUNC + * @tc.number: IsCurrentDeviceEnableIntelligentNoiseReduction_001 + * @tc.desc : Test IsCurrentDeviceEnableIntelligentNoiseReduction interface. + */ +HWTEST(AudioStreamManagerUnitTest, IsCurrentDeviceEnableIntelligentNoiseReduction_001, TestSize.Level1) +{ + SourceType sourceType = SourceType::SOURCE_TYPE_MIC; + bool result = AudioStreamManager::GetInstance()->IsCurrentDeviceEnableIntelligentNoiseReduction(sourceType); + + EXPECT_EQ(result, false); +} } // namespace AudioStandard } // namespace OHOS \ No newline at end of file