diff --git a/frameworks/cj/include/multimedia_audio_volume_manager_callback.h b/frameworks/cj/include/multimedia_audio_volume_manager_callback.h index 7cd7576c605776eb042326cd2d23eaebe355b855..38a8bddf65010ae951f64997258f02512df556fc 100644 --- a/frameworks/cj/include/multimedia_audio_volume_manager_callback.h +++ b/frameworks/cj/include/multimedia_audio_volume_manager_callback.h @@ -29,7 +29,6 @@ public: void RegisterFunc(std::function cjCallback); void OnVolumeKeyEvent(VolumeEvent volumeEvent) override; - void OnVolumeDegreeEvent(VolumeEvent volumeEvent) override {} private: std::function func_ {}; diff --git a/frameworks/native/audiopolicy/include/audio_policy_manager.h b/frameworks/native/audiopolicy/include/audio_policy_manager.h index fd046754df4b1eec6fa33df7f8980c34843fd83b..ba2b3dce37b4e1493ee88ec3408c40fec9f78949 100644 --- a/frameworks/native/audiopolicy/include/audio_policy_manager.h +++ b/frameworks/native/audiopolicy/include/audio_policy_manager.h @@ -694,14 +694,6 @@ public: const std::shared_ptr &selectedAudioDevice); int32_t ForceVolumeKeyControlType(AudioVolumeType volumeType, int32_t duration); - int32_t SetVolumeDegreeCallback(const int32_t clientPid, - const std::shared_ptr &callback); - int32_t UnsetVolumeDegreeCallback(const std::shared_ptr &callback); - int32_t SetSystemVolumeDegree(AudioVolumeType volumeType, int32_t volumeDegree, - int32_t volumeFlag, int32_t uid); - int32_t GetSystemVolumeDegree(AudioVolumeType volumeType, int32_t uid); - int32_t GetMinVolumeDegree(AudioVolumeType volumeType); - private: AudioPolicyManager() {} ~AudioPolicyManager() {} diff --git a/frameworks/native/audiopolicy/test/unittest/group_manager_test/src/audio_group_manager_unit_test.cpp b/frameworks/native/audiopolicy/test/unittest/group_manager_test/src/audio_group_manager_unit_test.cpp index a7f2be5f7592923733590f817b053b2c978c720e..cb2c30e8011998e23d12a2e3a26831ccf88f5514 100644 --- a/frameworks/native/audiopolicy/test/unittest/group_manager_test/src/audio_group_manager_unit_test.cpp +++ b/frameworks/native/audiopolicy/test/unittest/group_manager_test/src/audio_group_manager_unit_test.cpp @@ -880,94 +880,5 @@ HWTEST(AudioGroupManagerUnitTest, Audio_Group_Manager_GetPersistentMicMuteState_ EXPECT_EQ(isMutePersistent, true); } } - -/** - * @tc.name : Test SetVolumeDegree API - * @tc.number: Audio_Group_Manager_SetVolumeDegree_001 - * @tc.desc : SetVolumeDegree - * @tc.require: - */ -HWTEST(AudioGroupManagerUnitTest, Audio_Group_Manager_SetVolumeDegree_001, TestSize.Level0) -{ - int32_t ret = -1; - std::vector> infos; - AudioSystemManager::GetInstance()->GetVolumeGroups(networkId, infos); - if (infos.size() > 0) { - int32_t groupId = infos[0]->volumeGroupId_; - auto audioGroupMngr_ = AudioSystemManager::GetInstance()->GetGroupManager(groupId); - - int32_t degree = 44; - AudioStreamType streamType = STREAM_MUSIC; - ret = audioGroupMngr_->SetVolumeDegree(streamType, degree); - EXPECT_EQ(SUCCESS, ret); - - AudioStreamType streamType2 = STREAM_ULTRASONIC; - ret = audioGroupMngr_->SetVolumeDegree(streamType2, degree); - EXPECT_EQ(SUCCESS, ret); - - AudioStreamType streamType3 = STREAM_APP; - ret = audioGroupMngr_->SetVolumeDegree(streamType3, degree); - EXPECT_EQ(ERR_NOT_SUPPORTED, ret); - } -} - -/** - * @tc.name : Test GetVolumeDegree API - * @tc.number: Audio_Group_Manager_GetVolumeDegree_001 - * @tc.desc : GetVolumeDegree - * @tc.require: - */ -HWTEST(AudioGroupManagerUnitTest, Audio_Group_Manager_GetVolumeDegree_001, TestSize.Level0) -{ - int32_t ret = -1; - std::vector> infos; - AudioSystemManager::GetInstance()->GetVolumeGroups(networkId, infos); - if (infos.size() > 0) { - int32_t groupId = infos[0]->volumeGroupId_; - auto audioGroupMngr_ = AudioSystemManager::GetInstance()->GetGroupManager(groupId); - - int32_t degree = 44; - AudioStreamType streamType = STREAM_MUSIC; - ret = audioGroupMngr_->SetVolumeDegree(streamType, degree); - EXPECT_EQ(SUCCESS, ret); - - ret = audioGroupMngr_->GetVolumeDegree(streamType); - EXPECT_EQ(ret, degree); - - AudioStreamType streamType3 = STREAM_APP; - ret = audioGroupMngr_->GetVolumeDegree(streamType3); - EXPECT_EQ(ERR_NOT_SUPPORTED, ret); - } -} - -/** - * @tc.name : Test GetMinVolumeDegree API - * @tc.number: Audio_Group_Manager_GetMinVolumeDegree_001 - * @tc.desc : GetMinVolumeDegree - * @tc.require: - */ -HWTEST(AudioGroupManagerUnitTest, Audio_Group_Manager_GetMinVolumeDegree_001, TestSize.Level0) -{ - int32_t ret = -1; - std::vector> infos; - AudioSystemManager::GetInstance()->GetVolumeGroups(networkId, infos); - if (infos.size() > 0) { - int32_t groupId = infos[0]->volumeGroupId_; - auto audioGroupMngr_ = AudioSystemManager::GetInstance()->GetGroupManager(groupId); - - AudioVolumeType streamType = STREAM_ALL; - ret = audioGroupMngr_->GetMinVolumeDegree(streamType); - EXPECT_EQ(SUCCESS, ret); - - AudioVolumeType streamType2 = STREAM_ULTRASONIC; - ret = audioGroupMngr_->GetMinVolumeDegree(streamType2); - EXPECT_EQ(SUCCESS, ret); - - AudioVolumeType streamType3 = STREAM_MUSIC; - ret = audioGroupMngr_->GetMinVolumeDegree(streamType3); - EXPECT_EQ(SUCCESS, ret); - } -} - } // namespace AudioStandard } // namespace OHOS diff --git a/frameworks/native/audiopolicy/test/unittest/volume_change_test/include/audio_volume_change_unit_test.h b/frameworks/native/audiopolicy/test/unittest/volume_change_test/include/audio_volume_change_unit_test.h index 5d56143bf5a4210656299e666a11c5c22714dcb8..3092bdb65e15d39499a989ba2cad8c7277ad03f7 100644 --- a/frameworks/native/audiopolicy/test/unittest/volume_change_test/include/audio_volume_change_unit_test.h +++ b/frameworks/native/audiopolicy/test/unittest/volume_change_test/include/audio_volume_change_unit_test.h @@ -35,7 +35,7 @@ public: ~ApplicationCallback() = default; void OnVolumeKeyEvent(VolumeEvent volumeEvent) override; - void OnVolumeDegreeEvent(VolumeEvent volumeEvent) override; + private: std::string testCaseName_; }; diff --git a/frameworks/native/audiopolicy/test/unittest/volume_change_test/src/audio_volume_change_unit_test.cpp b/frameworks/native/audiopolicy/test/unittest/volume_change_test/src/audio_volume_change_unit_test.cpp index 59da9d5edfdedb49d11bc3d09aaab641e22d5e8f..df4e2b187f8a647532cb5688b176cf6668cdf067 100644 --- a/frameworks/native/audiopolicy/test/unittest/volume_change_test/src/audio_volume_change_unit_test.cpp +++ b/frameworks/native/audiopolicy/test/unittest/volume_change_test/src/audio_volume_change_unit_test.cpp @@ -35,7 +35,6 @@ namespace { int32_t g_streamType(0); int32_t g_volumeLevel(0); - int32_t g_volumeDegree(0); bool g_isUpdateUi(false); int32_t g_volumeGroupId(0); std::string g_networkId(LOCAL_NETWORK_ID); @@ -60,18 +59,6 @@ void ApplicationCallback::OnVolumeKeyEvent(VolumeEvent volumeEvent) g_condVar.notify_all(); } -void ApplicationCallback::OnVolumeDegreeEvent(VolumeEvent volumeEvent) -{ - g_isCallbackReceived = true; - g_streamType = volumeEvent.volumeType; - g_volumeDegree = volumeEvent.volume; - g_callbackName = testCaseName_; - g_isUpdateUi = volumeEvent.updateUi; - g_volumeGroupId = volumeEvent.volumeGroupId; - g_networkId = volumeEvent.networkId; - g_condVar.notify_all(); -} - void AudioVolumeChangeUnitTest::WaitForCallback() { std::unique_lock lock(g_mutex); @@ -204,47 +191,5 @@ HWTEST_F(AudioVolumeChangeUnitTest, volumeChange_test_003, TestSize.Level1) } g_audioManagerInstance->UnregisterVolumeKeyEventCallback(getpid()); } - -/* - * Feature: AudioVolumeChangeUnitTest - * Function: Set volume degree for AudioStreamType::STREAM_VOICE_CALL - * SubFunction: NA - * FunctionPoints: NA - * EnvConditions: NA - * CaseDescription: - */ -HWTEST_F(AudioVolumeChangeUnitTest, volumeDegreeChange_test_001, TestSize.Level1) -{ - int32_t result; - int32_t callBackSetResult; - std::string testCaseName("volumeDegreeChange_test_001"); - g_isCallbackReceived = false; - AudioStreamType streamType = AudioStreamType::STREAM_VOICE_CALL; - AudioVolumeType volumeType = static_cast(streamType); - int32_t volumeDegree = 50; - g_callbackName = testCaseName; - bool isUpdateUi = false; - auto appCallback = make_shared(testCaseName); - - std::vector> infos; - g_audioManagerInstance->GetVolumeGroups(LOCAL_NETWORK_ID, infos); - EXPECT_GE(infos.size(), 0); - int32_t groupId = infos[0]->volumeGroupId_; - auto audioGroupMngr_ = AudioSystemManager::GetInstance()->GetGroupManager(groupId); - - callBackSetResult = g_audioManagerInstance->RegisterVolumeDegreeCallback(getpid(), appCallback); - result = audioGroupMngr_->SetVolumeDegree(volumeType, volumeDegree); - EXPECT_EQ(result, SUCCESS); - EXPECT_EQ(callBackSetResult, SUCCESS); - if (result == SUCCESS) { - // Wait here for callback. If not callback for 2 mintues, will skip this step - AudioVolumeChangeUnitTest::WaitForCallback(); - EXPECT_EQ(streamType, g_streamType); - EXPECT_EQ(volumeDegree, g_volumeDegree); - EXPECT_EQ(isUpdateUi, g_isUpdateUi); - EXPECT_STREQ(g_callbackName.c_str(), testCaseName.c_str()); - } - g_audioManagerInstance->UnregisterVolumeDegreeCallback(getpid()); -} } // namespace AudioStandard } // namespace OHOS diff --git a/frameworks/native/audioutils/src/audio_utils.cpp b/frameworks/native/audioutils/src/audio_utils.cpp index c9cb8cca2286f0460c4eac4157e3bddcdd3477ff..f9e6e6d357340ed22fe221931b5e61b4b9bc7577 100644 --- a/frameworks/native/audioutils/src/audio_utils.cpp +++ b/frameworks/native/audioutils/src/audio_utils.cpp @@ -88,10 +88,6 @@ const int32_t DATA_INDEX_4 = 4; const int32_t DATA_INDEX_5 = 5; const int32_t STEREO_CHANNEL_COUNT = 2; const int BUNDLE_MGR_SERVICE_SYS_ABILITY_ID = 401; -const int32_t MAX_VOLUME_DEGREE = 100; -const int32_t NUM_DEGREES_PER_LEVEL = 7; -const int32_t MAX_VOLUME_LEVEL = 15; -const int32_t MIN_VOLUME_LEVEL = 0; const char* DUMP_PULSE_DIR = "/data/data/.pulse_dir/"; const char* DUMP_SERVICE_DIR = "/data/local/tmp/"; @@ -1944,58 +1940,6 @@ std::set& VolumeUtils::GetStreamUsageSetForVolumeType(AudioVolumeTy } } -int32_t VolumeUtils::VolumeDegreeToLevel(int32_t degree) -{ - if (degree < MIN_VOLUME_LEVEL || degree > MAX_VOLUME_DEGREE) { - return MIN_VOLUME_LEVEL; - } - - if (degree == MIN_VOLUME_LEVEL) { - return MIN_VOLUME_LEVEL; - } - - if (degree == MAX_VOLUME_DEGREE) { - return MAX_VOLUME_LEVEL; - } - - int32_t level = (degree - 1) / NUM_DEGREES_PER_LEVEL + 1; - return level; -} - -int32_t VolumeUtils::VolumeLevelToDegree(int32_t level) -{ - if (level < MIN_VOLUME_LEVEL || level > MAX_VOLUME_LEVEL) { - return MIN_VOLUME_LEVEL; - } - - if (level == MIN_VOLUME_LEVEL) { - return MIN_VOLUME_LEVEL; - } - - const int32_t base = 6; - const int32_t period = 3; - int32_t cycles = (level - 1) / period; - int32_t remainder = (level - 1) % period; - const int32_t REMAINDER_1 = 1; - const int32_t REMAINDER_2 = 2; - const int32_t REMAINDER_OFF = 7; - const int32_t NUM_DEGREES_PER_CYCLE = 20; - - int32_t degree = base + cycles * NUM_DEGREES_PER_CYCLE; - switch (remainder) { - case REMAINDER_1: - degree += REMAINDER_1 * REMAINDER_OFF; - break; - case REMAINDER_2: - degree += REMAINDER_2 * REMAINDER_OFF; - break; - default: - break; - } - - return degree; -} - std::string GetEncryptStr(const std::string &src) { if (src.empty()) { diff --git a/interfaces/inner_api/native/audiocommon/include/audio_common_utils.h b/interfaces/inner_api/native/audiocommon/include/audio_common_utils.h index 0684e3d75b1413c782177b8bb8328596025f6562..c7f420419bc4c84c02cfa8e89d623c4955516027 100644 --- a/interfaces/inner_api/native/audiocommon/include/audio_common_utils.h +++ b/interfaces/inner_api/native/audiocommon/include/audio_common_utils.h @@ -32,8 +32,7 @@ public: AudioVolumeType volumeType); static std::vector GetSupportedAudioVolumeTypes(); static std::vector GetStreamUsagesByVolumeType(AudioVolumeType audioVolumeType); - static int32_t VolumeDegreeToLevel(int32_t degree); - static int32_t VolumeLevelToDegree(int32_t level); + private: static std::set& GetStreamUsageSetForVolumeType(AudioVolumeType volumeType); diff --git a/interfaces/inner_api/native/audiocommon/include/audio_info.h b/interfaces/inner_api/native/audiocommon/include/audio_info.h index 98b66eb36d07c44a011fc220b6e9a2f2bca1c747..0a7332a6a17f3fbd558c3e7ac9b1ccd68744718d 100644 --- a/interfaces/inner_api/native/audiocommon/include/audio_info.h +++ b/interfaces/inner_api/native/audiocommon/include/audio_info.h @@ -343,7 +343,6 @@ enum CallbackChange : int32_t { CALLBACK_SYSTEM_VOLUME_CHANGE, CALLBACK_AUDIO_SESSION_STATE, CALLBACK_AUDIO_SESSION_DEVICE, - CALLBACK_SET_VOLUME_DEGREE_CHANGE, CALLBACK_MAX, }; @@ -400,7 +399,6 @@ constexpr CallbackChange CALLBACK_ENUMS[] = { CALLBACK_SYSTEM_VOLUME_CHANGE, CALLBACK_AUDIO_SESSION_STATE, CALLBACK_AUDIO_SESSION_DEVICE, - CALLBACK_SET_VOLUME_DEGREE_CHANGE, }; static_assert((sizeof(CALLBACK_ENUMS) / sizeof(CallbackChange)) == static_cast(CALLBACK_MAX), @@ -409,7 +407,6 @@ static_assert((sizeof(CALLBACK_ENUMS) / sizeof(CallbackChange)) == static_cast(volumeType)) && parcel.WriteInt32(volume) - && parcel.WriteInt32(volumeDegree) && parcel.WriteBool(updateUi) && parcel.WriteInt32(volumeGroupId) && parcel.WriteString(networkId) @@ -435,7 +431,6 @@ struct VolumeEvent : public Parcelable { { volumeType = static_cast(parcel.ReadInt32()); volume = parcel.ReadInt32(); - volumeDegree = parcel.ReadInt32(); updateUi = parcel.ReadBool(); volumeGroupId = parcel.ReadInt32(); networkId = parcel.ReadString(); @@ -1415,7 +1410,6 @@ struct Volume { bool isMute = false; float volumeFloat = 1.0f; uint32_t volumeInt = 0; - uint32_t volumeDegree = 0; }; enum AppIsBackState { diff --git a/interfaces/inner_api/native/audiomanager/include/audio_group_manager.h b/interfaces/inner_api/native/audiomanager/include/audio_group_manager.h index eae56a6ce17f709e99aab7efdfb3c0297392d288..67548823b8f28219839827db5695089b05df1c66 100644 --- a/interfaces/inner_api/native/audiomanager/include/audio_group_manager.h +++ b/interfaces/inner_api/native/audiomanager/include/audio_group_manager.h @@ -112,9 +112,6 @@ public: int32_t AdjustSystemVolumeByStep(AudioVolumeType volumeType, VolumeAdjustType adjustType); float GetSystemVolumeInDb(AudioVolumeType volumeType, int32_t volumeLevel, DeviceType deviceType); float GetMaxAmplitude(const int32_t deviceId); - int32_t SetVolumeDegree(AudioVolumeType volumeType, int32_t degree, int32_t flag = 0, int32_t uid = 0); - int32_t GetVolumeDegree(AudioVolumeType volumeType, int32_t uid = 0); - int32_t GetMinVolumeDegree(AudioVolumeType volumeType); private: int32_t groupId_; ConnectType connectType_ = CONNECT_TYPE_LOCAL; diff --git a/interfaces/inner_api/native/audiomanager/include/audio_policy_interface.h b/interfaces/inner_api/native/audiomanager/include/audio_policy_interface.h index 9e11ae84fcbc89de3fd5fd46f60a108677652fa4..7a04ab3fc26e4391d606ff8e61ecd151ec5f2ef4 100644 --- a/interfaces/inner_api/native/audiomanager/include/audio_policy_interface.h +++ b/interfaces/inner_api/native/audiomanager/include/audio_policy_interface.h @@ -185,12 +185,6 @@ public: * @since 8 */ virtual void OnVolumeKeyEvent(VolumeEvent volumeEvent) = 0; - /** - * @brief VolumeKeyEventCallback will be executed when volume degree is updated - * - * @param volumeEvent the volume event info. - */ - virtual void OnVolumeDegreeEvent(VolumeEvent volumeEvent) {} }; class StreamVolumeChangeCallback { diff --git a/interfaces/inner_api/native/audiomanager/include/audio_system_manager.h b/interfaces/inner_api/native/audiomanager/include/audio_system_manager.h index 678d9a3851c2da182ef623c7f8ea18728eb651ba..b4ac5d7a0b72dc701b0d2392e37bc96df1d6070f 100644 --- a/interfaces/inner_api/native/audiomanager/include/audio_system_manager.h +++ b/interfaces/inner_api/native/audiomanager/include/audio_system_manager.h @@ -731,24 +731,6 @@ public: int32_t UnregisterVolumeKeyEventCallback(const int32_t clientPid, const std::shared_ptr &callback = nullptr); - /** - * @brief registers the volume degree callback listener - * - * @return Returns {@link SUCCESS} if callback registration is successful; returns an error code - * defined in {@link audio_errors.h} otherwise. - */ - int32_t RegisterVolumeDegreeCallback(const int32_t clientPid, - const std::shared_ptr &callback); - - /** - * @brief Unregisters the volumeKeyEvent callback listener - * - * @return Returns {@link SUCCESS} if callback unregistration is successful; returns an error code - * defined in {@link audio_errors.h} otherwise. - */ - int32_t UnregisterVolumeDegreeCallback(const int32_t clientPid, - const std::shared_ptr &callback = nullptr); - /** * @brief registers the systemVolumeChange callback listener * 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 be089e4a9a33e2381d7aeae1f8163787b5154389..9168f10367f51c92bd0427d195db59670e16992b 100644 --- a/services/audio_policy/client/service/src/audio_policy_manager.cpp +++ b/services/audio_policy/client/service/src/audio_policy_manager.cpp @@ -3217,80 +3217,6 @@ int32_t AudioPolicyManager::ForceVolumeKeyControlType(AudioVolumeType volumeType return ret; } -int32_t AudioPolicyManager::SetVolumeDegreeCallback(const int32_t clientPid, - const std::shared_ptr &callback) -{ - AUDIO_INFO_LOG("client: %{public}d", clientPid); - if (!PermissionUtil::VerifySystemPermission()) { - AUDIO_ERR_LOG("No system permission"); - return ERR_PERMISSION_DENIED; - } - CHECK_AND_RETURN_RET_LOG(callback != nullptr, ERR_INVALID_PARAM, "volume back is nullptr"); - - if (!isAudioPolicyClientRegisted_) { - const sptr gsp = GetAudioPolicyManagerProxy(); - CHECK_AND_RETURN_RET_LOG(gsp != nullptr, ERROR, "audio policy manager proxy is NULL."); - int32_t ret = RegisterPolicyCallbackClientFunc(gsp); - if (ret != SUCCESS) { - return ret; - } - } - - std::lock_guard lockCbMap(callbackChangeInfos_[CALLBACK_SET_VOLUME_DEGREE_CHANGE].mutex); - if (audioPolicyClientStubCB_ != nullptr) { - audioPolicyClientStubCB_->AddVolumeDegreeCallback(callback); - size_t callbackSize = audioPolicyClientStubCB_->GetVolumeDegreeCallbackSize(); - if (callbackSize == 1) { - callbackChangeInfos_[CALLBACK_SET_VOLUME_DEGREE_CHANGE].isEnable = true; - SetClientCallbacksEnable(CALLBACK_SET_VOLUME_DEGREE_CHANGE, true); - } - } - return SUCCESS; -} - -int32_t AudioPolicyManager::UnsetVolumeDegreeCallback( - const std::shared_ptr &callback) -{ - AUDIO_DEBUG_LOG("Start to unregister"); - std::lock_guard lockCbMap(callbackChangeInfos_[CALLBACK_SET_VOLUME_DEGREE_CHANGE].mutex); - if (audioPolicyClientStubCB_ != nullptr) { - audioPolicyClientStubCB_->RemoveVolumeDegreeCallback(callback); - if (audioPolicyClientStubCB_->GetVolumeDegreeCallbackSize() == 0) { - callbackChangeInfos_[CALLBACK_SET_VOLUME_DEGREE_CHANGE].isEnable = false; - SetClientCallbacksEnable(CALLBACK_SET_VOLUME_DEGREE_CHANGE, false, false); - } - } - return SUCCESS; -} - -int32_t AudioPolicyManager::SetSystemVolumeDegree(AudioVolumeType volumeType, int32_t volumeDegree, - int32_t volumeFlag, int32_t uid) -{ - const sptr gsp = GetAudioPolicyManagerProxy(); - CHECK_AND_RETURN_RET_LOG(gsp != nullptr, ERROR, "audio policy manager proxy is NULL."); - return gsp->SetSystemVolumeDegree(volumeType, volumeDegree, volumeFlag, uid); -} - -int32_t AudioPolicyManager::GetSystemVolumeDegree(AudioVolumeType volumeType, int32_t uid) -{ - const sptr gsp = GetAudioPolicyManagerProxy(); - CHECK_AND_RETURN_RET_LOG(gsp != nullptr, 0, "audio policy manager proxy is NULL."); - - int32_t volumeDegree = 0; - gsp->GetSystemVolumeDegree(volumeType, uid, volumeDegree); - return volumeDegree; -} - -int32_t AudioPolicyManager::GetMinVolumeDegree(AudioVolumeType volumeType) -{ - const sptr gsp = GetAudioPolicyManagerProxy(); - CHECK_AND_RETURN_RET_LOG(gsp != nullptr, 0, "audio policy manager proxy is NULL."); - - int32_t volumeDegree = 0; - gsp->GetMinVolumeDegree(volumeType, volumeDegree); - return volumeDegree; -} - AudioPolicyManager& AudioPolicyManager::GetInstance() { static AudioPolicyManager policyManager; diff --git a/services/audio_policy/client/stub/include/audio_policy_client_stub_impl.h b/services/audio_policy/client/stub/include/audio_policy_client_stub_impl.h index 7100ed10f1d75d84a05fede55a4aa0034189c6ea..f2bc4d63774924ed41cfaaad7434755a0aa10ff1 100644 --- a/services/audio_policy/client/stub/include/audio_policy_client_stub_impl.h +++ b/services/audio_policy/client/stub/include/audio_policy_client_stub_impl.h @@ -35,9 +35,6 @@ public: int32_t AddVolumeKeyEventCallback(const std::shared_ptr &cb); int32_t RemoveVolumeKeyEventCallback(const std::shared_ptr &cb); size_t GetVolumeKeyEventCallbackSize() const; - int32_t AddVolumeDegreeCallback(const std::shared_ptr &cb); - int32_t RemoveVolumeDegreeCallback(const std::shared_ptr &cb); - size_t GetVolumeDegreeCallbackSize() const; int32_t AddSystemVolumeChangeCallback(const std::shared_ptr &cb); int32_t RemoveSystemVolumeChangeCallback(const std::shared_ptr &cb); size_t GetSystemVolumeChangeCallbackSize() const; @@ -148,7 +145,6 @@ public: int32_t OnRecreateCapturerStreamEvent(uint32_t sessionId, int32_t streamFlag, const AudioStreamDeviceChangeReasonExt &reason) override; int32_t OnVolumeKeyEvent(const VolumeEvent &volumeEvent) override; - int32_t OnVolumeDegreeEvent(const VolumeEvent &volumeEvent) override; int32_t OnAudioFocusInfoChange(const std::vector> &focusInfoList) override; int32_t OnAudioFocusRequested(const AudioInterrupt &requestFocus) override; int32_t OnAudioFocusAbandoned(const AudioInterrupt &abandonFocus) override; @@ -189,7 +185,6 @@ private: const std::vector>& desc); std::vector> volumeKeyEventCallbackList_; - std::vector> volumeDegreeCallbackList_; std::vector, std::weak_ptr>> streamVolumeChangeCallbackList_; std::vector> systemVolumeChangeCallbackList_; @@ -235,7 +230,6 @@ private: mutable std::mutex pOutputDeviceChangeMutex_; mutable std::mutex pInputDeviceChangeMutex_; mutable std::mutex volumeKeyEventMutex_; - mutable std::mutex volumeDegreeEventMutex_; mutable std::mutex deviceChangeMutex_; mutable std::mutex ringerModeMutex_; mutable std::mutex activeVolumeTypeChangeMutex_; diff --git a/services/audio_policy/client/stub/src/audio_policy_client_stub_impl.cpp b/services/audio_policy/client/stub/src/audio_policy_client_stub_impl.cpp index 9317ccc8209d620a49f034c14ae300fd56a83b1e..f5b715e0033fa9d819c14c2f01d404e4aa51a540 100644 --- a/services/audio_policy/client/stub/src/audio_policy_client_stub_impl.cpp +++ b/services/audio_policy/client/stub/src/audio_policy_client_stub_impl.cpp @@ -74,48 +74,6 @@ int32_t AudioPolicyClientStubImpl::OnVolumeKeyEvent(const VolumeEvent &volumeEve return SUCCESS; } -int32_t AudioPolicyClientStubImpl::AddVolumeDegreeCallback(const std::shared_ptr &cb) -{ - std::lock_guard lockCbMap(volumeDegreeEventMutex_); - volumeDegreeCallbackList_.push_back(cb); - return SUCCESS; -} - -int32_t AudioPolicyClientStubImpl::RemoveVolumeDegreeCallback(const std::shared_ptr &cb) -{ - std::lock_guard lockCbMap(volumeDegreeEventMutex_); - if (cb == nullptr) { - volumeDegreeCallbackList_.clear(); - return SUCCESS; - } - auto it = find_if(volumeDegreeCallbackList_.begin(), volumeDegreeCallbackList_.end(), - [&cb](const std::weak_ptr& elem) { - return elem.lock() == cb; - }); - if (it != volumeDegreeCallbackList_.end()) { - volumeDegreeCallbackList_.erase(it); - } - return SUCCESS; -} - -size_t AudioPolicyClientStubImpl::GetVolumeDegreeCallbackSize() const -{ - std::lock_guard lockCbMap(volumeDegreeEventMutex_); - return volumeDegreeCallbackList_.size(); -} - -int32_t AudioPolicyClientStubImpl::OnVolumeDegreeEvent(const VolumeEvent &volumeEvent) -{ - std::lock_guard lockCbMap(volumeDegreeEventMutex_); - for (auto it = volumeDegreeCallbackList_.begin(); it != volumeDegreeCallbackList_.end(); ++it) { - std::shared_ptr volumeKeyEventCallback = (*it).lock(); - if (volumeKeyEventCallback != nullptr) { - volumeKeyEventCallback->OnVolumeDegreeEvent(volumeEvent); - } - } - return SUCCESS; -} - int32_t AudioPolicyClientStubImpl::AddSystemVolumeChangeCallback(const std::shared_ptr &cb) { std::lock_guard lockCbMap(systemVolumeChangeMutex_); diff --git a/services/audio_policy/idl/IAudioPolicyClient.idl b/services/audio_policy/idl/IAudioPolicyClient.idl index c213d0feebc767956468b44aa4f37530337a6bc3..bccd1241daa57797aa81ef6d0c597b56d14c25dd 100644 --- a/services/audio_policy/idl/IAudioPolicyClient.idl +++ b/services/audio_policy/idl/IAudioPolicyClient.idl @@ -87,6 +87,4 @@ interface IAudioPolicyClient { void OnAudioSessionStateChanged([in] int stateChangeHint /* AudioSessionStateChangedEvent */); [customMsgOption flags=MessageOption::TF_ASYNC_WAKEUP_LATER | MessageOption::TF_ASYNC] void OnAudioSessionCurrentDeviceChanged([in] CurrentOutputDeviceChangedEvent deviceChangedEvent); - [customMsgOption flags=MessageOption::TF_ASYNC_WAKEUP_LATER | MessageOption::TF_ASYNC] - void OnVolumeDegreeEvent([in] VolumeEvent volumeEvent); } diff --git a/services/audio_policy/server/domain/pipe/src/audio_policy_config_manager.cpp b/services/audio_policy/server/domain/pipe/src/audio_policy_config_manager.cpp index 878004328ae225f915c1dd2ae6c1c2e37fefc616..bd80054dc97a82f6777b89b0242997de0ecbd4ed 100644 --- a/services/audio_policy/server/domain/pipe/src/audio_policy_config_manager.cpp +++ b/services/audio_policy/server/domain/pipe/src/audio_policy_config_manager.cpp @@ -20,7 +20,7 @@ #include "audio_policy_config_parser.h" #include "audio_source_strategy_parser.h" #include "audio_policy_utils.h" -#include "audio_policy_service.h" +#include "audio_core_service.h" #include "audio_ec_manager.h" namespace OHOS { @@ -166,7 +166,7 @@ void AudioPolicyConfigManager::OnVoipConfigParsed(bool enableFastVoip) void AudioPolicyConfigManager::OnUpdateAnahsSupport(std::string anahsShowType) { AUDIO_INFO_LOG("show type: %{public}s", anahsShowType.c_str()); - AudioPolicyService::GetAudioPolicyService().OnUpdateAnahsSupport(anahsShowType); + AudioCoreService::GetCoreService()->OnUpdateAnahsSupport(anahsShowType); } void AudioPolicyConfigManager::OnUpdateEac3Support(bool isSupported) diff --git a/services/audio_policy/server/domain/volume/include/audio_adapter_manager.h b/services/audio_policy/server/domain/volume/include/audio_adapter_manager.h index d2d9f8b63ab5caffc337a28635feb85f583058ae..e0457b3ca81ea2bed462054566aa704b60da8ff7 100644 --- a/services/audio_policy/server/domain/volume/include/audio_adapter_manager.h +++ b/services/audio_policy/server/domain/volume/include/audio_adapter_manager.h @@ -48,7 +48,6 @@ struct AppConfigVolume { }; const int32_t MAX_CACHE_AMOUNT = 10; -static constexpr int32_t MAX_VOLUME_DEGREE = 100; class AudioAdapterManager : public IAudioPolicyInterface { public: static constexpr std::string_view SPLIT_STREAM_SINK = "libmodule-split-stream-sink.z.so"; @@ -168,7 +167,7 @@ public: bool SetSinkMute(const std::string &sinkName, bool isMute, bool isSync = false); - float CalculateVolumeDb(int32_t volumeLevel, int32_t maxDegree = MAX_VOLUME_LEVEL); + float CalculateVolumeDb(int32_t volumeLevel); int32_t SetSystemSoundUri(const std::string &key, const std::string &uri); @@ -260,9 +259,6 @@ public: void HandleSaveVolume(DeviceType deviceType, AudioStreamType streamType, int32_t volumeLevel, std::string networkId); - void HandleSaveVolumeDegree(DeviceType deviceType, AudioStreamType streamType, - int32_t volumeDegree, std::string networkId); - void HandleStreamMuteStatus(AudioStreamType streamType, bool mute, StreamUsage streamUsage = STREAM_USAGE_UNKNOWN, const DeviceType &deviceType = DEVICE_TYPE_NONE, std::string networkId = LOCAL_NETWORK_ID); @@ -307,10 +303,6 @@ public: void HandleDistributedDeviceVolume(); void SetSleVoiceStatusFlag(bool isSleVoiceStatus); - int32_t SetSystemVolumeDegree(AudioStreamType streamType, int32_t volumeDegree); - int32_t GetSystemVolumeDegree(AudioStreamType streamType); - int32_t GetMinVolumeDegree(AudioVolumeType volumeType); - void SendLoudVolumeModeToDsp(FunctionHoldType funcHoldType, bool state); private: friend class PolicyCallbackImpl; diff --git a/services/audio_policy/server/domain/volume/include/audio_adapter_manager_handler.h b/services/audio_policy/server/domain/volume/include/audio_adapter_manager_handler.h index 467174db6ab6a2c416c11bb24366c406007ebd53..8fd66887f2bc8fe82bdb261a6212dc27f84374e3 100644 --- a/services/audio_policy/server/domain/volume/include/audio_adapter_manager_handler.h +++ b/services/audio_policy/server/domain/volume/include/audio_adapter_manager_handler.h @@ -40,7 +40,6 @@ public: VOLUME_DATABASE_SAVE, STREAM_MUTE_STATUS_UPDATE, RINGER_MODE_UPDATE, - VOLUME_DEGREE_DATABASE_SAVE, }; struct VolumeDataEvent { @@ -53,7 +52,6 @@ public: AudioStreamType streamType_; int32_t volumeLevel_; std::string networkId_; - int32_t volumeDegree_; }; struct StreamMuteStatusEvent { @@ -80,8 +78,6 @@ public: bool SendKvDataUpdate(const bool &isFirstBoot); bool SendSaveVolume(const DeviceType &deviceType, const AudioStreamType &streamType, const int32_t &volumeLevel, std::string networkId = "LocalDevice"); - bool SendSaveVolumeDegree(DeviceType deviceType, AudioStreamType streamType, int32_t volumeDegree, - std::string networkId = "LocalDevice"); bool SendStreamMuteStatusUpdate(const AudioStreamType &streamType, const bool &mute, const StreamUsage &streamUsage, const DeviceType &deviceType = DEVICE_TYPE_NONE, std::string networkId = LOCAL_NETWORK_ID); @@ -94,7 +90,6 @@ private: /* Handle Event*/ void HandleUpdateKvDataEvent(const AppExecFwk::InnerEvent::Pointer &event); void HandleVolumeDataBaseSave(const AppExecFwk::InnerEvent::Pointer &event); - void HandleVolumeDegreeDataBaseSave(const AppExecFwk::InnerEvent::Pointer &event); void HandleUpdateStreamMuteStatus(const AppExecFwk::InnerEvent::Pointer &event); void HandleUpdateRingerMode(const AppExecFwk::InnerEvent::Pointer &event); diff --git a/services/audio_policy/server/domain/volume/include/iaudio_policy_interface.h b/services/audio_policy/server/domain/volume/include/iaudio_policy_interface.h index d697e21806bdf59591ab3d78c540dcd3e0f86394..3feb37d56c7b3b43c023b3cf0d2abaaaef99ba32 100644 --- a/services/audio_policy/server/domain/volume/include/iaudio_policy_interface.h +++ b/services/audio_policy/server/domain/volume/include/iaudio_policy_interface.h @@ -129,7 +129,7 @@ public: virtual bool SetSinkMute(const std::string &sinkName, bool isMute, bool isSync = false) = 0; - virtual float CalculateVolumeDb(int32_t volumeLevel, int32_t maxDegree = 0) = 0; + virtual float CalculateVolumeDb(int32_t volumeLevel) = 0; virtual int32_t SetSystemSoundUri(const std::string &key, const std::string &uri) = 0; @@ -202,9 +202,6 @@ public: virtual void HandleSaveVolume(DeviceType deviceType, AudioStreamType streamType, int32_t volumeLevel, std::string networkId) = 0; - virtual void HandleSaveVolumeDegree(DeviceType deviceType, AudioStreamType streamType, int32_t volumeDegree, - std::string networkId) = 0; - virtual void HandleStreamMuteStatus(AudioStreamType streamType, bool mute, StreamUsage streamUsage = STREAM_USAGE_UNKNOWN, const DeviceType &deviceType = DEVICE_TYPE_NONE, diff --git a/services/audio_policy/server/domain/volume/include/volume_data_maintainer.h b/services/audio_policy/server/domain/volume/include/volume_data_maintainer.h index ba8364bc851c67748651ec9c70f36caf9967c3a4..23ae4352b7d21c95eb1fb0bfb5513525a6ba4e86 100644 --- a/services/audio_policy/server/domain/volume/include/volume_data_maintainer.h +++ b/services/audio_policy/server/domain/volume/include/volume_data_maintainer.h @@ -134,11 +134,6 @@ public: bool GetMicMuteState(bool &isMute); bool CheckOsAccountReady(); - void SetVolumeDegree(AudioStreamType streamType, int32_t volumeDegree); - int32_t GetVolumeDegree(AudioStreamType streamType); - bool SaveVolumeDegree(DeviceType type, AudioStreamType streamType, int32_t volumeDegree, - std::string networkId = LOCAL_NETWORK_ID); - bool GetVolumeDegree(DeviceType deviceType, AudioStreamType streamType, std::string networkId = LOCAL_NETWORK_ID); private: static std::string GetVolumeKeyForDataShare(DeviceType deviceType, AudioStreamType streamType, std::string networkId = LOCAL_NETWORK_ID); @@ -168,7 +163,6 @@ private: // Stores the mute status of audio streams used by the app. std::unordered_map> appStreamMuteMap_; - std::unordered_map volumeDegreeMap_; // save system volume degree map bool isSettingsCloneHaveStarted_ = false; }; } // namespace AudioStandard diff --git a/services/audio_policy/server/domain/volume/src/audio_adapter_manager.cpp b/services/audio_policy/server/domain/volume/src/audio_adapter_manager.cpp index a2fc2581c7f3dc856d5bde1897011d3a3698bc9a..f19545e6e6e695bd725648fe67aec24b8cf60078 100644 --- a/services/audio_policy/server/domain/volume/src/audio_adapter_manager.cpp +++ b/services/audio_policy/server/domain/volume/src/audio_adapter_manager.cpp @@ -653,12 +653,6 @@ void AudioAdapterManager::HandleSaveVolume(DeviceType deviceType, AudioStreamTyp volumeDataMaintainer_.SaveVolume(deviceType, streamType, volumeLevel, networkId); } -void AudioAdapterManager::HandleSaveVolumeDegree(DeviceType deviceType, AudioStreamType streamType, - int32_t volumeDegree, std::string networkId) -{ - volumeDataMaintainer_.SaveVolumeDegree(deviceType, streamType, volumeDegree, networkId); -} - void AudioAdapterManager::HandleStreamMuteStatus(AudioStreamType streamType, bool mute, StreamUsage streamUsage, const DeviceType &deviceType, std::string networkId) { @@ -2333,11 +2327,6 @@ void AudioAdapterManager::InitVolumeMap(bool isFirstBoot) auto ret = volumeDataMaintainer_.SaveVolume(deviceType, streamType, volumeLevel); resetFirstFlag = ret ? resetFirstFlag : true; } - - if (!volumeDataMaintainer_.GetVolumeDegree(deviceType, streamType)) { - int32_t defVolumeDegree = MIN_VOLUME_LEVEL; - volumeDataMaintainer_.SaveVolumeDegree(deviceType, streamType, defVolumeDegree); - } } } if (resetFirstFlag) { @@ -2506,12 +2495,9 @@ bool AudioAdapterManager::LoadVolumeMap(void) for (auto &streamType: defaultVolumeTypeList_) { if (Util::IsDualToneStreamType(streamType) && currentActiveDevice_.deviceType_ != DEVICE_TYPE_REMOTE_CAST) { result = volumeDataMaintainer_.GetVolume(DEVICE_TYPE_SPEAKER, streamType, currentActiveDevice_.networkId_); - volumeDataMaintainer_.GetVolumeDegree(DEVICE_TYPE_SPEAKER, streamType, currentActiveDevice_.networkId_); } else { result = volumeDataMaintainer_.GetVolume(currentActiveDevice_.deviceType_, streamType, currentActiveDevice_.networkId_); - volumeDataMaintainer_.GetVolumeDegree(currentActiveDevice_.deviceType_, streamType, - currentActiveDevice_.networkId_); } if (!result) { AUDIO_ERR_LOG("LoadVolumeMap: Could not load volume for streamType[%{public}d] from kvStore", streamType); @@ -2896,13 +2882,9 @@ std::string AudioAdapterManager::GetMuteKeyForDeviceType(DeviceType deviceType, return type; } -float AudioAdapterManager::CalculateVolumeDb(int32_t volumeLevel, int32_t maxDegree) +float AudioAdapterManager::CalculateVolumeDb(int32_t volumeLevel) { - if (maxDegree == 0) { - maxDegree = MAX_VOLUME_LEVEL; - } - - float value = static_cast(volumeLevel) / maxDegree; + float value = static_cast(volumeLevel) / MAX_VOLUME_LEVEL; float roundValue = static_cast(value * CONST_FACTOR); return static_cast(roundValue) / CONST_FACTOR; @@ -3397,69 +3379,6 @@ void AudioAdapterManager::HandleHearingAidVolume(AudioStreamType streamType) } } -int32_t AudioAdapterManager::SetSystemVolumeDegree(AudioStreamType streamType, int32_t volumeDegree) -{ - Trace trace("streamType:" + std::to_string(streamType) + ", volumeDegree:" + std::to_string(volumeDegree)); - AUDIO_INFO_LOG("streamType: %{public}d, deviceType: %{public}d, volumeDegree:%{public}d", - streamType, currentActiveDevice_.deviceType_, volumeDegree); - if (GetSystemVolumeDegree(streamType) == volumeDegree && - currentActiveDevice_.deviceType_ != DEVICE_TYPE_BLUETOOTH_SCO && - currentActiveDevice_.deviceType_ != DEVICE_TYPE_BLUETOOTH_A2DP && !VolumeUtils::IsPCVolumeEnable()) { - AUDIO_INFO_LOG("The volume is the same as before."); - return SUCCESS; - } - - if (volumeDegree == 0 && !VolumeUtils::IsPCVolumeEnable() && - (streamType == STREAM_VOICE_CALL || - streamType == STREAM_ALARM || streamType == STREAM_ACCESSIBILITY || - streamType == STREAM_VOICE_COMMUNICATION)) { - // these types can not set to mute, but don't return error - AUDIO_ERR_LOG("this type can not set mute"); - return SUCCESS; - } - - int32_t minRet = GetMinVolumeDegree(streamType); - CHECK_AND_RETURN_RET_LOG(volumeDegree >= minRet && volumeDegree <= MAX_VOLUME_DEGREE, ERR_OPERATION_FAILED, - "volume not in scope, mimRet:%{public}d", minRet); - - volumeDataMaintainer_.SetVolumeDegree(streamType, volumeDegree); - - if (handler_ != nullptr) { - if (Util::IsDualToneStreamType(streamType) && currentActiveDevice_.deviceType_ != DEVICE_TYPE_REMOTE_CAST) { - AUDIO_INFO_LOG("DualToneStreamType. Save volume for speaker."); - handler_->SendSaveVolumeDegree(DEVICE_TYPE_SPEAKER, streamType, volumeDegree, "LocalDevice"); - } else { - handler_->SendSaveVolumeDegree(currentActiveDevice_.deviceType_, streamType, volumeDegree, - currentActiveDevice_.networkId_); - } - } - - float volumeDb = CalculateVolumeDb(volumeDegree, MAX_VOLUME_DEGREE); - if (streamType == STREAM_VOICE_CALL_ASSISTANT) { - volumeDb = 1.0f; - } - AUDIO_INFO_LOG("streamType:%{public}d volumeDb:%{public}f volumeDegree:%{public}d devicetype:%{public}d", - streamType, volumeDb, volumeDegree, currentActiveDevice_.deviceType_); - SetAudioVolume(streamType, volumeDb); - return SUCCESS; -} - -int32_t AudioAdapterManager::GetSystemVolumeDegree(AudioStreamType streamType) -{ - if (GetStreamMuteInternal(streamType)) { - return MIN_VOLUME_LEVEL; - } - - return volumeDataMaintainer_.GetVolumeDegree(streamType); -} - -int32_t AudioAdapterManager::GetMinVolumeDegree(AudioVolumeType volumeType) -{ - CHECK_AND_RETURN_RET_LOG(volumeType >= STREAM_VOICE_CALL && volumeType <= STREAM_TYPE_MAX, - MIN_VOLUME_LEVEL, "Invalid stream type"); - return MIN_VOLUME_LEVEL; -} - // LCOV_EXCL_STOP } // namespace AudioStandard } // namespace OHOS diff --git a/services/audio_policy/server/domain/volume/src/audio_adapter_manager_handler.cpp b/services/audio_policy/server/domain/volume/src/audio_adapter_manager_handler.cpp index b0058114fb0d2d331627117fbcd7db5a915a484e..7d538c407476b91b706ed462954fc645af109111 100644 --- a/services/audio_policy/server/domain/volume/src/audio_adapter_manager_handler.cpp +++ b/services/audio_policy/server/domain/volume/src/audio_adapter_manager_handler.cpp @@ -63,19 +63,6 @@ bool AudioAdapterManagerHandler::SendSaveVolume(const DeviceType &deviceType, return ret; } -bool AudioAdapterManagerHandler::SendSaveVolumeDegree(DeviceType deviceType, AudioStreamType streamType, - int32_t volumeDegree, std::string networkId) -{ - auto eventContextObj = std::make_shared(deviceType, streamType, 0, networkId); - CHECK_AND_RETURN_RET_LOG(eventContextObj != nullptr, false, "EventContextObj get nullptr"); - eventContextObj->volumeDegree_ = volumeDegree; - lock_guard runnerlock(runnerMutex_); - bool ret = SendEvent(AppExecFwk::InnerEvent::Get( - EventAdapterManagerServerCmd::VOLUME_DEGREE_DATABASE_SAVE, eventContextObj)); - CHECK_AND_RETURN_RET_LOG(ret, ret, "send event failed"); - return ret; -} - bool AudioAdapterManagerHandler::SendStreamMuteStatusUpdate(const AudioStreamType &streamType, const bool &mute, const StreamUsage &streamUsage, const DeviceType &deviceType, std::string networkId) { @@ -117,14 +104,6 @@ void AudioAdapterManagerHandler::HandleVolumeDataBaseSave(const AppExecFwk::Inne eventContextObj->streamType_, eventContextObj->volumeLevel_, eventContextObj->networkId_); } -void AudioAdapterManagerHandler::HandleVolumeDegreeDataBaseSave(const AppExecFwk::InnerEvent::Pointer &event) -{ - std::shared_ptr eventContextObj = event->GetSharedObject(); - CHECK_AND_RETURN_LOG(eventContextObj != nullptr, "EventContextObj get nullptr"); - AudioPolicyManagerFactory::GetAudioPolicyManager().HandleSaveVolumeDegree(eventContextObj->deviceType_, - eventContextObj->streamType_, eventContextObj->volumeDegree_, eventContextObj->networkId_); -} - void AudioAdapterManagerHandler::HandleUpdateStreamMuteStatus(const AppExecFwk::InnerEvent::Pointer &event) { std::shared_ptr eventContextObj = event->GetSharedObject(); @@ -165,9 +144,6 @@ void AudioAdapterManagerHandler::ProcessEvent(const AppExecFwk::InnerEvent::Poin case RINGER_MODE_UPDATE: HandleUpdateRingerMode(event); break; - case VOLUME_DEGREE_DATABASE_SAVE: - HandleVolumeDegreeDataBaseSave(event); - break; default: break; } diff --git a/services/audio_policy/server/domain/volume/src/audio_volume_manager.cpp b/services/audio_policy/server/domain/volume/src/audio_volume_manager.cpp index 4eeb01cd89179ec94fb0ff27cfd4dfa3136e9eab..1b52e1b0465d01bb7d3ef72f4db2f3c241ac4fbc 100644 --- a/services/audio_policy/server/domain/volume/src/audio_volume_manager.cpp +++ b/services/audio_policy/server/domain/volume/src/audio_volume_manager.cpp @@ -153,10 +153,8 @@ bool AudioVolumeManager::SetSharedVolume(AudioVolumeType streamType, DeviceType volumeVector_[index].isMute = vol.isMute; volumeVector_[index].volumeFloat = vol.volumeFloat; volumeVector_[index].volumeInt = vol.volumeInt; - volumeVector_[index].volumeDegree = vol.volumeDegree; - AUDIO_INFO_LOG("Success Set Shared Volume with StreamType:%{public}d, DeviceType:%{public}d, \ - volume:%{public}d, volumeDegree:%{public}d", - streamType, deviceType, vol.volumeInt, vol.volumeDegree); + AUDIO_INFO_LOG("Success Set Shared Volume with StreamType:%{public}d, DeviceType:%{public}d, volume:%{public}d", + streamType, deviceType, vol.volumeInt); AudioServerProxy::GetInstance().NotifyStreamVolumeChangedProxy(streamType, vol.volumeFloat); return true; @@ -1481,41 +1479,5 @@ void ForceControlVolumeTypeMonitor::SetTimer(int32_t duration, duration_ = (duration > MAX_DURATION_TIME_S ? MAX_DURATION_TIME_S : duration); StartMonitor(duration_, cb); } - -int32_t AudioVolumeManager::SetSystemVolumeDegree(AudioStreamType streamType, int32_t volumeDegree, - int32_t zoneId) -{ - int32_t volumeLevel = VolumeUtils::VolumeDegreeToLevel(volumeDegree); - int32_t currentVolumeDegree = GetSystemVolumeDegree(streamType); - int32_t currentVolumeLevel = VolumeUtils::VolumeDegreeToLevel(currentVolumeDegree); - if (volumeLevel == currentVolumeLevel) { - volumeDegree = currentVolumeDegree; - AUDIO_WARNING_LOG("volume level dont change, keep volume degree=%{public}d", volumeDegree); - } - - Volume vol{}; - vol.isMute = volumeDegree == 0; - vol.volumeInt = volumeLevel; - vol.volumeDegree = static_cast(volumeDegree); - vol.volumeFloat = audioPolicyManager_.CalculateVolumeDb(volumeDegree, MAX_VOLUME_DEGREE); - DeviceType curOutputDeviceType = audioActiveDevice_.GetCurrentOutputDeviceType(); - SetSharedVolume(streamType, curOutputDeviceType, vol); - - return audioPolicyManager_.SetSystemVolumeDegree(VolumeUtils::GetVolumeTypeFromStreamType(streamType), - volumeDegree); -} - -int32_t AudioVolumeManager::GetSystemVolumeDegree(AudioStreamType streamType) -{ - return audioPolicyManager_.GetSystemVolumeDegree(streamType); -} - -int32_t AudioVolumeManager::GetMinVolumeDegree(AudioVolumeType volumeType) const -{ - if (volumeType == STREAM_ALL) { - volumeType = STREAM_MUSIC; - } - return audioPolicyManager_.GetMinVolumeDegree(volumeType); -} } } diff --git a/services/audio_policy/server/domain/volume/src/volume_data_maintainer.cpp b/services/audio_policy/server/domain/volume/src/volume_data_maintainer.cpp index 5fdfb68aa66c7ce192f8f433da563fd74c33207c..65359209b982e754176707f12f9baa6dd6a9d139 100644 --- a/services/audio_policy/server/domain/volume/src/volume_data_maintainer.cpp +++ b/services/audio_policy/server/domain/volume/src/volume_data_maintainer.cpp @@ -116,29 +116,6 @@ bool VolumeDataMaintainer::SaveVolume(DeviceType type, AudioStreamType streamTyp return SaveVolumeInternal(type, streamForVolumeMap, volumeLevel, networkId); } -bool VolumeDataMaintainer::SaveVolumeDegree(DeviceType type, AudioStreamType streamTypeIn, - int32_t volumeDegree, std::string networkId) -{ - std::lock_guard lock(volumeForDbMutex_); - AudioStreamType streamType = VolumeUtils::GetVolumeTypeFromStreamType(streamTypeIn); - - std::string volumeKey = GetVolumeKeyForDataShare(type, streamType, networkId); - if (!volumeKey.compare("")) { - AUDIO_ERR_LOG("[device %{public}d, streamType %{public}d] is not supported for datashare", - type, streamType); - return false; - } - volumeKey += "_degree"; - - AudioSettingProvider& audioSettingProvider = AudioSettingProvider::GetInstance(AUDIO_POLICY_SERVICE_ID); - ErrCode ret = audioSettingProvider.PutIntValue(volumeKey, volumeDegree, "system"); - if (ret != SUCCESS) { - AUDIO_ERR_LOG("Save Volume To DataBase volumeMap failed"); - return false; - } - return true; -} - bool VolumeDataMaintainer::SaveVolumeInternal(DeviceType type, AudioStreamType streamType, int32_t volumeLevel, std::string networkId) { @@ -169,38 +146,6 @@ bool VolumeDataMaintainer::GetVolume(DeviceType deviceType, AudioStreamType stre return GetVolumeInternal(deviceType, streamForVolumeMap, networkId); } -bool VolumeDataMaintainer::GetVolumeDegree(DeviceType deviceType, AudioStreamType streamTypeIn, std::string networkId) -{ - std::lock_guard lock(volumeForDbMutex_); - AudioStreamType streamType = VolumeUtils::GetVolumeTypeFromStreamType(streamTypeIn); - // Voice call assistant stream is full volume by default - if (streamType == STREAM_VOICE_CALL_ASSISTANT) { - return true; - } - std::string volumeKey = GetVolumeKeyForDataShare(deviceType, streamType, networkId); - if (!volumeKey.compare("")) { - AUDIO_ERR_LOG("[device %{public}d, streamType %{public}d] is not supported for datashare", - deviceType, streamType); - return false; - } - volumeKey += "_degree"; - - AudioSettingProvider& audioSettingProvider = AudioSettingProvider::GetInstance(AUDIO_POLICY_SERVICE_ID); - int32_t volumeValue = 0; - ErrCode ret = audioSettingProvider.GetIntValue(volumeKey, volumeValue, "system"); - if (ret != SUCCESS) { - AUDIO_ERR_LOG("Get streamType %{public}d, deviceType %{public}d, Volume FromDataBase volumeMap failed.", - streamType, deviceType); - return false; - } else { - volumeDegreeMap_[streamType] = volumeValue; - AUDIO_PRERELEASE_LOGI("Get streamType %{public}d, deviceType %{public}d, "\ - "Volume FromDataBase volumeMap from datashare %{public}d.", streamType, deviceType, volumeValue); - } - - return true; -} - bool VolumeDataMaintainer::GetVolumeInternal(DeviceType deviceType, AudioStreamType streamType, std::string networkId) { // Voice call assistant stream is full volume by default @@ -1100,19 +1045,5 @@ std::string VolumeDataMaintainer::GetMuteKeyForDataShare(DeviceType deviceType, return type + deviceTypeName; } -void VolumeDataMaintainer::SetVolumeDegree(AudioStreamType streamType, int32_t volumeDegree) -{ - std::lock_guard lock(volumeMutex_); - AudioStreamType streamForVolumeMap = VolumeUtils::GetVolumeTypeFromStreamType(streamType); - volumeDegreeMap_[streamForVolumeMap] = volumeDegree; -} - -int32_t VolumeDataMaintainer::GetVolumeDegree(AudioStreamType streamType) -{ - std::lock_guard lock(volumeMutex_); - AudioStreamType streamForVolumeMap = VolumeUtils::GetVolumeTypeFromStreamType(streamType); - return volumeDegreeMap_[streamForVolumeMap]; -} - } // namespace AudioStandard } // namespace OHOS diff --git a/services/audio_policy/server/infra/async_action_handler/src/audio_policy_server_handler.cpp b/services/audio_policy/server/infra/async_action_handler/src/audio_policy_server_handler.cpp index a188951ab3398e5d47791c8cffee26ffd0073c92..89fd8e02e0899eab27305d9a014ecaf0a56fa900 100644 --- a/services/audio_policy/server/infra/async_action_handler/src/audio_policy_server_handler.cpp +++ b/services/audio_policy/server/infra/async_action_handler/src/audio_policy_server_handler.cpp @@ -793,11 +793,6 @@ void AudioPolicyServerHandler::HandleVolumeKeyEvent(const AppExecFwk::InnerEvent clientCallbacksMap_[it->first][CALLBACK_SYSTEM_VOLUME_CHANGE]) { volumeChangeCb->OnSystemVolumeChange(eventContextObj->volumeEvent); } - if (clientCallbacksMap_.count(it->first) > 0 && - clientCallbacksMap_[it->first].count(CALLBACK_SET_VOLUME_DEGREE_CHANGE) > 0 && - clientCallbacksMap_[it->first][CALLBACK_SET_VOLUME_DEGREE_CHANGE]) { - volumeChangeCb->OnVolumeDegreeEvent(eventContextObj->volumeEvent); - } HandleVolumeChangeCallback(it->first, volumeChangeCb, eventContextObj->volumeEvent); } } diff --git a/services/audio_policy/server/infra/ipc_proxy/include/audio_policy_client_holder.h b/services/audio_policy/server/infra/ipc_proxy/include/audio_policy_client_holder.h index d76aebf5fc61acf8d8406a096dee309281344a3d..541d2516f93c0f37c21784860e32e67342cba330 100644 --- a/services/audio_policy/server/infra/ipc_proxy/include/audio_policy_client_holder.h +++ b/services/audio_policy/server/infra/ipc_proxy/include/audio_policy_client_holder.h @@ -66,7 +66,6 @@ public: void OnSystemVolumeChange(VolumeEvent volumeEvent); void OnAudioSessionStateChanged(const AudioSessionStateChangedEvent &stateChangedEvent); void OnAudioSessionCurrentDeviceChanged(const CurrentOutputDeviceChangedEvent &deviceChangedEvent); - void OnVolumeDegreeEvent(VolumeEvent volumeEvent); public: bool hasBTPermission_ = true; diff --git a/services/audio_policy/server/infra/ipc_proxy/src/audio_policy_client_holder.cpp b/services/audio_policy/server/infra/ipc_proxy/src/audio_policy_client_holder.cpp index 784110eaf166a43490c6891b72386b2d4ea72653..3224783be2ba14a1fe03eabbc02e8ababb252250 100644 --- a/services/audio_policy/server/infra/ipc_proxy/src/audio_policy_client_holder.cpp +++ b/services/audio_policy/server/infra/ipc_proxy/src/audio_policy_client_holder.cpp @@ -280,13 +280,5 @@ void AudioPolicyClientHolder::OnAudioSessionCurrentDeviceChanged( audioPolicyClient_->OnAudioSessionCurrentDeviceChanged(deviceChangedEvent); } -void AudioPolicyClientHolder::OnVolumeDegreeEvent(VolumeEvent volumeEventIn) -{ - CHECK_AND_RETURN_LOG(audioPolicyClient_ != nullptr, "audioPolicyClient_ is nullptr."); - VolumeEvent volumeEvent = volumeEventIn; - volumeEvent.volumeDegree = VolumeUtils::VolumeLevelToDegree(volumeEvent.volume); - audioPolicyClient_->OnVolumeDegreeEvent(volumeEvent); -} - } // namespace AudioStandard } // namespace OHOS \ No newline at end of file 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 63a104f1f397c72e48f9181de0ca8f00112d46f3..b7b072a3b56aeebb328fa1dae9e4101fd27c7c0a 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 @@ -698,9 +698,6 @@ protected: int32_t GetApiTargetVersion(); private: - int32_t SetSystemVolumeDegreeInner(AudioStreamType streamType, int32_t volumeDegree, - bool isUpdateUi, int32_t uid); - friend class AudioInterruptService; static constexpr int32_t MAX_VOLUME_LEVEL = 15; 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 b15172aada60d96158222e6bb48ed18d6e748806..88027b6c6cab0e29e09f024b162f345f22e6cdf9 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 @@ -36,6 +36,8 @@ static const char* CHECK_FAST_BLOCK_PREFIX = "Is_Fast_Blocked_For_AppName#"; static const int32_t BLUETOOTH_FETCH_RESULT_DEFAULT = 0; static const int32_t BLUETOOTH_FETCH_RESULT_CONTINUE = 1; static const int32_t BLUETOOTH_FETCH_RESULT_ERROR = 2; +static constexpr int32_t MAX_TRY = 100; +static constexpr int32_t DELAY_MS = 100; } static bool IsRemoteOffloadActive(uint32_t remoteOffloadStreamPropSize, int32_t streamUsage) @@ -101,6 +103,7 @@ void AudioCoreService::Init() { serviceFlag_.reset(); eventEntry_ = std::make_shared(shared_from_this()); + deviceStatusListener_ = std::make_shared(*eventEntry_); // shared_ptr.get() -> * audioA2dpOffloadManager_ = std::make_shared(); if (audioA2dpOffloadManager_ != nullptr) { @@ -113,7 +116,6 @@ void AudioCoreService::Init() audioDeviceStatus_.Init(audioA2dpOffloadManager_, audioPolicyServerHandler_); audioCapturerSession_.Init(audioA2dpOffloadManager_); - deviceStatusListener_ = std::make_shared(*eventEntry_); // shared_ptr.get() -> * isFastControlled_ = GetFastControlParam(); // Register device status listener int32_t status = deviceStatusListener_->RegisterDeviceStatusListener(); @@ -211,7 +213,7 @@ int32_t AudioCoreService::CreateCapturerClient( std::shared_ptr streamDesc, uint32_t &audioFlag, uint32_t &sessionId) { CHECK_AND_RETURN_RET_LOG(streamDesc != nullptr, ERR_INVALID_PARAM, "streamDesc is nullptr"); - + AUDIO_INFO_LOG("[DeviceFetchStart] for stream %{public}d", sessionId); streamDesc->oldDeviceDescs_ = streamDesc->newDeviceDescs_; std::shared_ptr inputDeviceDesc = @@ -302,7 +304,7 @@ bool AudioCoreService::IsForcedNormal(std::shared_ptr &st void AudioCoreService::UpdatePlaybackStreamFlag(std::shared_ptr &streamDesc, bool isCreateProcess) { CHECK_AND_RETURN_LOG(streamDesc, "Input param error"); - + if (isCreateProcess && streamDesc->rendererInfo_.forceToNormal) { AUDIO_INFO_LOG("client force create normal"); streamDesc->audioFlag_ = AUDIO_OUTPUT_FLAG_NORMAL; @@ -559,7 +561,7 @@ int32_t AudioCoreService::SetAudioScene(AudioScene audioScene, const int32_t uid if (!isSameScene) { OnAudioSceneChange(audioScene); } - + if (audioScene == AUDIO_SCENE_PHONE_CALL) { // Make sure the STREAM_VOICE_CALL volume is set before the calling starts. audioVolumeManager_.SetVoiceCallVolume(audioVolumeManager_.GetSystemVolumeLevel(STREAM_VOICE_CALL)); @@ -1185,7 +1187,20 @@ int32_t AudioCoreService::UnsetAudioDeviceAnahsCallback() void AudioCoreService::OnUpdateAnahsSupport(std::string anahsShowType) { AUDIO_INFO_LOG("OnUpdateAnahsSupport show type: %{public}s", anahsShowType.c_str()); - deviceStatusListener_->UpdateAnahsPlatformType(anahsShowType); + thread th([this](string &&anahsShowType) { + for (int32_t i = 0; i < MAX_TRY; ++i) { + if (i > 0) { + this_thread::sleep_for(std::chrono::milliseconds(DELAY_MS)); + } + if (deviceStatusListener_) { + deviceStatusListener_->UpdateAnahsPlatformType(anahsShowType); + return; + } + } + AUDIO_ERR_LOG("Try UpdateAnahsPlatformType over %{public}d times, failed", MAX_TRY); + }, move(anahsShowType)); + pthread_setname_np(th.native_handle(), "OS_ANAHS_TYP"); + th.detach(); } void AudioCoreService::RegisterBluetoothListener() @@ -1430,7 +1445,7 @@ int32_t AudioCoreService::CaptureConcurrentCheck(uint32_t sessionId) if (streamDesc->audioMode_ != AUDIO_MODE_RECORD) { return ERR_NOT_SUPPORTED; } - + auto dfxResult = std::make_unique(); if (!WriteCapturerConcurrentMsg(streamDesc, dfxResult)) { return ERR_INVALID_HANDLE; 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 4d3490acb85eb7d2b1f18163ad07f683ef87aee2..080f7f44053ca1c7add87c4430c8263d204076e9 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 @@ -5358,58 +5358,5 @@ int32_t AudioPolicyServer::CallRingtoneLibrary() dataShareHelper->Release(); return SUCCESS; } - -int32_t AudioPolicyServer::SetSystemVolumeDegree(int32_t streamTypeIn, int32_t volumeDegree, int32_t volumeFlag, - int32_t uid) -{ - AudioStreamType streamType = static_cast(streamTypeIn); - if (!PermissionUtil::VerifySystemPermission()) { - AUDIO_ERR_LOG("No system permission"); - return ERR_PERMISSION_DENIED; - } - - if (!IsVolumeTypeValid(streamType)) { - return ERR_NOT_SUPPORTED; - } - - bool adjustable = false; - IsVolumeUnadjustable(adjustable); - if (adjustable) { - AUDIO_ERR_LOG("Unadjustable device, not allow set degree"); - return ERR_OPERATION_FAILED; - } - std::lock_guard lock(systemVolumeMutex_); - bool flag = volumeFlag == VolumeFlag::FLAG_SHOW_SYSTEM_UI; - int32_t volumeLevel = VolumeUtils::VolumeDegreeToLevel(volumeDegree); - int32_t callingUid = uid != 0 ? uid : IPCSkeleton::GetCallingUid(); - int32_t zoneId = AudioZoneService::GetInstance().FindAudioZoneByUid(callingUid); - SetSystemVolumeLevelInternal(streamType, volumeLevel, flag, zoneId); - - return SetSystemVolumeDegreeInner(streamType, volumeDegree, flag, uid); -} - -int32_t AudioPolicyServer::SetSystemVolumeDegreeInner(AudioStreamType streamType, int32_t volumeDegree, - bool volumeFlag, int32_t uid) -{ - int32_t ret = audioVolumeManager_.SetSystemVolumeDegree(streamType, volumeDegree, volumeFlag); - if (ret != SUCCESS) { - AUDIO_ERR_LOG("Update volume degree failed, err:%{public}d", ret); - } - return ret; -} - -int32_t AudioPolicyServer::GetSystemVolumeDegree(int32_t streamType, int32_t uid, int32_t &volumeDegree) -{ - std::lock_guard lock(systemVolumeMutex_); - AudioStreamType newStreamType = static_cast(streamType); - volumeDegree = audioVolumeManager_.GetSystemVolumeDegree(newStreamType); - return SUCCESS; -} - -int32_t AudioPolicyServer::GetMinVolumeDegree(int32_t volumeType, int32_t &volumeDegree) -{ - volumeDegree = audioVolumeManager_.GetMinVolumeDegree(static_cast(volumeType)); - return SUCCESS; -} } // namespace AudioStandard } // namespace OHOS diff --git a/services/audio_policy/test/unittest/audio_adapter_manager_unit_test/src/audio_adapter_manager_unit_test.cpp b/services/audio_policy/test/unittest/audio_adapter_manager_unit_test/src/audio_adapter_manager_unit_test.cpp index 35363a0baed0137fba85875e985a6bbd6fb683f1..0e0803091044954a923f8b20f2fae3623a6f67a9 100644 --- a/services/audio_policy/test/unittest/audio_adapter_manager_unit_test/src/audio_adapter_manager_unit_test.cpp +++ b/services/audio_policy/test/unittest/audio_adapter_manager_unit_test/src/audio_adapter_manager_unit_test.cpp @@ -503,31 +503,6 @@ HWTEST_F(AudioAdapterManagerUnitTest, SetInnerStreamMute_002, TestSize.Level4) EXPECT_EQ(audioAdapterManager->GetStreamMute(streamType), mute); } -/** - * @tc.name: Test SetSystemVolumeDegree - * @tc.desc: SetSystemVolumeDegree_001 - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(AudioAdapterManagerUnitTest, SetSystemVolumeDegree_001, TestSize.Level4) -{ - auto audioAdapterManager = std::make_shared(); - ASSERT_NE(audioAdapterManager, nullptr); - AudioStreamType streamType = STREAM_MUSIC; - int32_t volumeDegree = 44; - auto ret = audioAdapterManager->SetSystemVolumeDegree(streamType, volumeDegree); - EXPECT_EQ(ret, SUCCESS); - - ret = audioAdapterManager->SetSystemVolumeDegree(streamType, volumeDegree); - EXPECT_EQ(ret, SUCCESS); - - ret = audioAdapterManager->GetSystemVolumeDegree(streamType); - EXPECT_EQ(ret, volumeDegree); - - ret = audioAdapterManager->GetMinVolumeDegree(streamType); - EXPECT_EQ(ret, 0); -} - /** * @tc.name: Test SetSleVoliceStatusFlag * @tc.desc: SetSleVoliceStatusFlag_001 diff --git a/services/audio_policy/test/unittest/audio_policy_client_stub_impl_test/include/audio_policy_client_stub_impl_test.h b/services/audio_policy/test/unittest/audio_policy_client_stub_impl_test/include/audio_policy_client_stub_impl_test.h index 9d27debeb4cf1096bd2fd39453b2ce7b29149876..09d2f715799d3c61852e0cdb93ad16f9eaadd65a 100644 --- a/services/audio_policy/test/unittest/audio_policy_client_stub_impl_test/include/audio_policy_client_stub_impl_test.h +++ b/services/audio_policy/test/unittest/audio_policy_client_stub_impl_test/include/audio_policy_client_stub_impl_test.h @@ -38,7 +38,6 @@ class ConcreteVolumeKeyEventCallback : public VolumeKeyEventCallback { public: ConcreteVolumeKeyEventCallback() {} void OnVolumeKeyEvent(VolumeEvent volumeEvent) override {} - void OnVolumeDegreeEvent(VolumeEvent volumeEvent) override {} }; class ConcreteAudioFocusInfoChangeCallback : public AudioFocusInfoChangeCallback { diff --git a/services/audio_policy/test/unittest/audio_policy_manager_unit_test/src/audio_policy_manager_unit_test.cpp b/services/audio_policy/test/unittest/audio_policy_manager_unit_test/src/audio_policy_manager_unit_test.cpp index b8447a02733c75ab9f4eb896d1ba3261f61480f5..cffbf5f4b411e6bb1232b28b2c55ab11f989e3fd 100644 --- a/services/audio_policy/test/unittest/audio_policy_manager_unit_test/src/audio_policy_manager_unit_test.cpp +++ b/services/audio_policy/test/unittest/audio_policy_manager_unit_test/src/audio_policy_manager_unit_test.cpp @@ -728,28 +728,6 @@ HWTEST(AudioPolicyManager, CreateCapturerClient_002, TestSize.Level1) EXPECT_EQ(oldSessionId, originalSessionId); } -/** -* @tc.name : Test AudioPolicyManager. -* @tc.number: SetSystemVolumeDegree_001. -* @tc.desc : Test SetSystemVolumeDegree. -*/ -HWTEST(AudioPolicyManager, SetSystemVolumeDegree_001, TestSize.Level1) -{ - auto audioPolicyManager_ = std::make_shared(); - ASSERT_TRUE(audioPolicyManager_ != nullptr); - - AudioVolumeType volumeType = AudioVolumeType::STREAM_MUSIC; - int32_t volumeDegree = 4; - auto result = audioPolicyManager_->SetSystemVolumeDegree(volumeType, volumeDegree, 0, 0); - EXPECT_EQ(result, SUCCESS); - - result = audioPolicyManager_->GetSystemVolumeDegree(volumeType, 0); - EXPECT_EQ(result, volumeDegree); - - result = audioPolicyManager_->GetMinVolumeDegree(volumeType); - EXPECT_EQ(result, 0); -} - /** * @tc.name : Test AudioPolicyManager. * @tc.number: GetDirectPlaybackSupport_001. diff --git a/services/audio_policy/test/unittest/audio_policy_service_unit_test/src/audio_policy_service_second_unit_test.cpp b/services/audio_policy/test/unittest/audio_policy_service_unit_test/src/audio_policy_service_second_unit_test.cpp index 709685ac6f7f97fae31ba425b6ebc33d5f4ce581..c03d329d9f0a19f2746baf9a3517cc10da3d6e0f 100644 --- a/services/audio_policy/test/unittest/audio_policy_service_unit_test/src/audio_policy_service_second_unit_test.cpp +++ b/services/audio_policy/test/unittest/audio_policy_service_unit_test/src/audio_policy_service_second_unit_test.cpp @@ -1186,36 +1186,5 @@ HWTEST_F(AudioPolicyServiceExtUnitTest, GetSinkPortName_004, TestSize.Level1) EXPECT_EQ(HEARING_AID_SPEAKER, retPortName); } -/** -* @tc.name : Test SetSystemVolumeDegree -* @tc.number: SetSystemVolumeDegree_001 -* @tc.desc : Test AudioPolicyService interfaces. -*/ -HWTEST_F(AudioPolicyServiceExtUnitTest, SetSystemVolumeDegree_001, TestSize.Level1) -{ - auto server = GetServerUtil::GetServerPtr(); - ASSERT_TRUE(server != nullptr); - int32_t streamType = static_cast(STREAM_MUSIC); - int32_t volumeDegree = 44; - int32_t ret = server->SetSystemVolumeDegree(streamType, volumeDegree, 0, 0); - EXPECT_EQ(ret, SUCCESS); - - int32_t streamType2 = static_cast(STREAM_APP); - ret = server->SetSystemVolumeDegree(streamType2, volumeDegree, 0, 0); - EXPECT_EQ(ret, ERR_NOT_SUPPORTED); - - auto &manager = static_cast(server->audioPolicyManager_); - manager.isVolumeUnadjustable_ = true; - ret = server->SetSystemVolumeDegree(streamType, volumeDegree, 0, 0); - EXPECT_EQ(ret, ERR_OPERATION_FAILED); - manager.isVolumeUnadjustable_ = false; - - server->GetSystemVolumeDegree(streamType, 0, ret); - EXPECT_EQ(ret, volumeDegree); - - server->GetMinVolumeDegree(streamType, ret); - EXPECT_EQ(ret, 0); -} - } // namespace AudioStandard } // namespace OHOS diff --git a/services/audio_policy/test/unittest/audio_policy_service_unit_test/src/audio_policy_service_third_unit_test.cpp b/services/audio_policy/test/unittest/audio_policy_service_unit_test/src/audio_policy_service_third_unit_test.cpp index 843c8bd2376bc0231046943836e7a153d366d44c..c9608d2737323b089a53fc33ee5697780f68c715 100644 --- a/services/audio_policy/test/unittest/audio_policy_service_unit_test/src/audio_policy_service_third_unit_test.cpp +++ b/services/audio_policy/test/unittest/audio_policy_service_unit_test/src/audio_policy_service_third_unit_test.cpp @@ -1066,6 +1066,28 @@ HWTEST_F(AudioPolicyServiceThirdUnitTest, OnUpdateAnahsSupport_001, TestSize.Lev EXPECT_NE(server->audioPolicyService_.deviceStatusListener_, nullptr); } +/** + * @tc.name : Test OnUpdateAnahsSupport. + * @tc.number: OnUpdateAnahsSupport_002 + * @tc.desc : Test AudioPolicyService interfaces. + */ +HWTEST_F(AudioPolicyServiceThirdUnitTest, OnUpdateAnahsSupport_002, TestSize.Level1) +{ + auto server = GetServerPtr(); + ASSERT_NE(nullptr, server); + + std::string anahsShowType = "anahsShowType"; + + auto coreSvc = AudioCoreService::GetCoreService(); + auto bakUp = coreSvc->deviceStatusListener_; + CHECK_AND_RETURN(bakUp); + coreSvc->deviceStatusListener_ = nullptr; + coreSvc->OnUpdateAnahsSupport(anahsShowType); + coreSvc->deviceStatusListener_ = bakUp; + coreSvc->OnUpdateAnahsSupport(anahsShowType); + EXPECT_NE(coreSvc->deviceStatusListener_, nullptr); +} + /** * @tc.name : Test OnDeviceStatusUpdated. * @tc.number: OnDeviceStatusUpdated_001 diff --git a/services/audio_policy/test/unittest/audio_volume_manager_unit_test/src/audio_volume_manager_unit_test.cpp b/services/audio_policy/test/unittest/audio_volume_manager_unit_test/src/audio_volume_manager_unit_test.cpp index 7acc518340e7f766aa1a5d34a5b93e48124dba22..cf7a888b90227fdd179b5afc37c43b47fda349d0 100644 --- a/services/audio_policy/test/unittest/audio_volume_manager_unit_test/src/audio_volume_manager_unit_test.cpp +++ b/services/audio_policy/test/unittest/audio_volume_manager_unit_test/src/audio_volume_manager_unit_test.cpp @@ -1354,33 +1354,6 @@ HWTEST_F(AudioVolumeManagerUnitTest, AudioVolumeManager_062, TestSize.Level1) EXPECT_EQ(ret, SUCCESS); } -/** -* @tc.name : Test AudioVolumeManager. -* @tc.number: AudioVolumeManagerDegree_001 -* @tc.desc : Test SetSystemVolumeDegree interface. -*/ -HWTEST_F(AudioVolumeManagerUnitTest, AudioVolumeManagerDegree_001, TestSize.Level1) -{ - AudioVolumeManager& audioVolumeManager(AudioVolumeManager::GetInstance()); - int32_t zoneId = 0; - int32_t ret = audioVolumeManager.SetAdjustVolumeForZone(zoneId); - EXPECT_EQ(ret, SUCCESS); - zoneId = 1; - ret = audioVolumeManager.SetAdjustVolumeForZone(zoneId); - EXPECT_NE(ret, SUCCESS); - - AudioStreamType streamType = STREAM_MUSIC; - int32_t volumeDegree = 44; - ret = audioVolumeManager.SetSystemVolumeDegree(streamType, volumeDegree, 0); - EXPECT_EQ(ret, SUCCESS); - - ret = audioVolumeManager.GetSystemVolumeDegree(streamType); - EXPECT_EQ(ret, volumeDegree); - - ret = audioVolumeManager.GetMinVolumeDegree(streamType); - EXPECT_EQ(ret, 0); -} - /** * @tc.name : Test AudioVolumeManager. * @tc.number: AudioVolumeManager_063 diff --git a/services/audio_service/client/src/audio_group_manager.cpp b/services/audio_service/client/src/audio_group_manager.cpp index 73fa9d719256267b83b510bce400e2185fe976c7..1046ca719e02d5410c76f5a1dbadb282a8ee8852 100644 --- a/services/audio_service/client/src/audio_group_manager.cpp +++ b/services/audio_service/client/src/audio_group_manager.cpp @@ -437,79 +437,5 @@ float AudioGroupManager::GetMaxAmplitude(const int32_t deviceId) { return AudioPolicyManager::GetInstance().GetMaxAmplitude(deviceId); } - -int32_t AudioGroupManager::SetVolumeDegree(AudioVolumeType volumeType, int32_t degree, int32_t volumeFlag, int32_t uid) -{ - AUDIO_INFO_LOG("volumeType[%{public}d], degree[%{public}d], flag[%{public}d]", - volumeType, degree, volumeFlag); - - /* Validate volume type and return INVALID_PARAMS error */ - switch (volumeType) { - case STREAM_VOICE_CALL: - case STREAM_VOICE_COMMUNICATION: - case STREAM_RING: - case STREAM_MUSIC: - case STREAM_ALARM: - case STREAM_SYSTEM: - case STREAM_ACCESSIBILITY: - case STREAM_VOICE_ASSISTANT: - break; - case STREAM_ULTRASONIC: - case STREAM_ALL:{ - bool ret = PermissionUtil::VerifySelfPermission(); - CHECK_AND_RETURN_RET_LOG(ret, ERR_PERMISSION_DENIED, "No system permission"); - break; - } - default: - AUDIO_ERR_LOG("volumeType[%{public}d] is not supported", volumeType); - return ERR_NOT_SUPPORTED; - } - - return AudioPolicyManager::GetInstance().SetSystemVolumeDegree(volumeType, degree, volumeFlag, uid); -} - -int32_t AudioGroupManager::GetVolumeDegree(AudioVolumeType volumeType, int32_t uid) -{ - switch (volumeType) { - case STREAM_MUSIC: - case STREAM_RING: - case STREAM_NOTIFICATION: - case STREAM_VOICE_CALL: - case STREAM_VOICE_COMMUNICATION: - case STREAM_VOICE_ASSISTANT: - case STREAM_ALARM: - case STREAM_SYSTEM: - case STREAM_ACCESSIBILITY: - break; - case STREAM_ULTRASONIC: - case STREAM_ALL:{ - bool ret = PermissionUtil::VerifySelfPermission(); - CHECK_AND_RETURN_RET_LOG(ret, ERR_PERMISSION_DENIED, - "No system permission"); - break; - } - default: - AUDIO_ERR_LOG("volumeType=%{public}d not supported", volumeType); - return ERR_NOT_SUPPORTED; - } - - return AudioPolicyManager::GetInstance().GetSystemVolumeDegree(volumeType, uid); -} - -int32_t AudioGroupManager::GetMinVolumeDegree(AudioVolumeType volumeType) -{ - if (volumeType == STREAM_ALL) { - bool ret = PermissionUtil::VerifySelfPermission(); - CHECK_AND_RETURN_RET_LOG(ret, ERR_PERMISSION_DENIED, - "No system permission"); - } - - if (volumeType == STREAM_ULTRASONIC) { - bool ret = PermissionUtil::VerifySelfPermission(); - CHECK_AND_RETURN_RET_LOG(ret, ERR_PERMISSION_DENIED, - "STREAM_ULTRASONIC No system permission"); - } - return AudioPolicyManager::GetInstance().GetMinVolumeDegree(volumeType); -} } // namespace AudioStandard } // namespace OHOS diff --git a/services/audio_service/client/src/audio_system_manager.cpp b/services/audio_service/client/src/audio_system_manager.cpp index 7c8c48a9a71dc360934f4c587392a840c3e58a87..cded253e5a2f72e9e3d0147011a30e488c3e2c52 100644 --- a/services/audio_service/client/src/audio_system_manager.cpp +++ b/services/audio_service/client/src/audio_system_manager.cpp @@ -1262,29 +1262,6 @@ int32_t AudioSystemManager::UnregisterVolumeKeyEventCallback(const int32_t clien return ret; } -int32_t AudioSystemManager::RegisterVolumeDegreeCallback(const int32_t clientPid, - const std::shared_ptr &callback) -{ - AUDIO_DEBUG_LOG("register"); - - CHECK_AND_RETURN_RET_LOG(callback != nullptr, ERR_INVALID_PARAM, - "nullptr"); - volumeChangeClientPid_ = clientPid; - - return AudioPolicyManager::GetInstance().SetVolumeDegreeCallback(clientPid, callback); -} - -int32_t AudioSystemManager::UnregisterVolumeDegreeCallback(const int32_t clientPid, - const std::shared_ptr &callback) -{ - AUDIO_DEBUG_LOG("unregister"); - int32_t ret = AudioPolicyManager::GetInstance().UnsetVolumeDegreeCallback(callback); - if (!ret) { - AUDIO_DEBUG_LOG("success"); - } - return ret; -} - int32_t AudioSystemManager::RegisterSystemVolumeChangeCallback(const int32_t clientPid, const std::shared_ptr &callback) { diff --git a/test/fuzztest/audiopolicymanager_fuzzer/audio_policy_manager_fuzzer.cpp b/test/fuzztest/audiopolicymanager_fuzzer/audio_policy_manager_fuzzer.cpp index 712e7c1a740a9ca568fb26e9c987ce434b5a724f..c0bcd220bf55c6da14c4de6ef58db902ab8a4f10 100644 --- a/test/fuzztest/audiopolicymanager_fuzzer/audio_policy_manager_fuzzer.cpp +++ b/test/fuzztest/audiopolicymanager_fuzzer/audio_policy_manager_fuzzer.cpp @@ -487,10 +487,6 @@ void AudioPolicyManagerNiNeFuzzTest() vector> audioCapturerChangeInfos; StreamUsage streamUsage = GetData(); std::string address = "address"; - int32_t volumeDegree = GetData(); - AudioVolumeType volumeType = GetData(); - int32_t volumeFlag = GetData(); - uid_t uid = GetData(); AudioPolicyManager::GetInstance().SetMicrophoneMutePersistent(isMute, type); AudioPolicyManager::GetInstance().GetPersistentMicMuteState(); @@ -504,9 +500,6 @@ void AudioPolicyManagerNiNeFuzzTest() AudioPolicyManager::GetInstance().GetSpatializationState(streamUsage); AudioPolicyManager::GetInstance().IsSpatializationSupported(); AudioPolicyManager::GetInstance().IsSpatializationSupportedForDevice(address); - AudioPolicyManager::GetInstance().SetSystemVolumeDegree(volumeType, volumeDegree, volumeFlag, uid); - AudioPolicyManager::GetInstance().GetSystemVolumeDegree(volumeType, uid); - AudioPolicyManager::GetInstance().GetMinVolumeDegree(volumeType); } void AudioPolicyManagerDeviceOneFuzzTest()