diff --git a/services/audio/include/ring.h b/services/audio/include/ring.h index 00e8d67cc611111394980028e24911771353163c..de579fdd9d569970a384034a04d4ebd9bbc5769f 100644 --- a/services/audio/include/ring.h +++ b/services/audio/include/ring.h @@ -19,6 +19,7 @@ #include #include "audio_renderer.h" +#include "ffrt.h" #include "audio_player.h" #include "audio_proxy.h" @@ -51,7 +52,7 @@ public: bool isMutedRing_ = false; private: - std::mutex mutex_; + ffrt::mutex mutex_; AudioPlayer *audioPlayer_ = nullptr; std::shared_ptr SystemSoundManager_ = nullptr; std::shared_ptr RingtonePlayer_ = nullptr; diff --git a/services/audio/src/ring.cpp b/services/audio/src/ring.cpp index 81742973d31e5d6ace15353df7e51ec8247bcfc4..64d436100d6b5e00c73f8681ea3cd57befb9d62f 100644 --- a/services/audio/src/ring.cpp +++ b/services/audio/src/ring.cpp @@ -32,6 +32,7 @@ Ring::Ring() : audioPlayer_(new (std::nothrow) AudioPlayer()) Ring::~Ring() { + std::lock_guard lock(mutex_); if (audioPlayer_ != nullptr) { delete audioPlayer_; audioPlayer_ = nullptr; @@ -49,6 +50,7 @@ void Ring::Init() int32_t Ring::Play(int32_t slotId, std::string ringtonePath, Media::HapticStartupMode mode) { + std::lock_guard lock(mutex_); if (SystemSoundManager_ == nullptr || audioPlayer_ == nullptr) { TELEPHONY_LOGE("SystemSoundManager_ or audioPlayer_ is nullptr"); return TELEPHONY_ERR_LOCAL_PTR_NULL; @@ -73,7 +75,7 @@ int32_t Ring::Play(int32_t slotId, std::string ringtonePath, Media::HapticStartu int32_t Ring::Stop() { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); if (audioPlayer_ == nullptr) { TELEPHONY_LOGE("audioPlayer_ is nullptr"); return TELEPHONY_ERR_LOCAL_PTR_NULL; diff --git a/test/unittest/call_manager_zero_gtest/src/zero_branch9_test.cpp b/test/unittest/call_manager_zero_gtest/src/zero_branch9_test.cpp index 30966e3cfb1b545218bf599c507ad3070d3d94bf..3f1e5d37e44552889c32645afcf5fe35c2e4686c 100644 --- a/test/unittest/call_manager_zero_gtest/src/zero_branch9_test.cpp +++ b/test/unittest/call_manager_zero_gtest/src/zero_branch9_test.cpp @@ -212,7 +212,7 @@ HWTEST_F(ZeroBranch9Test, Telephony_AudioControlManager_005, TestSize.Level0) audioControl->UnexcludeBluetoothSco(); AudioDeviceType deviceType = AudioDeviceType::DEVICE_BLUETOOTH_SCO; audioControl->UpdateDeviceTypeForCrs(deviceType); - EXPECT_FALSE(audioControl->IsRingingVibrateModeOn()); + EXPECT_TRUE(audioControl->IsRingingVibrateModeOn()); auto callControl = DelayedSingleton::GetInstance(); callControl->SetVoIPCallState(1); EXPECT_TRUE(audioControl->IsVoIPCallActived());