From 813d206bad97210b778535e77863163c8846b5df Mon Sep 17 00:00:00 2001 From: huyue57 Date: Mon, 29 Jul 2024 04:05:11 +0000 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=84=A6=E7=82=B9=E6=B3=A8?= =?UTF-8?q?=E5=85=A5=E6=8E=A5=E5=8F=A3=EF=BC=8C=E8=A7=A3=E5=86=B3=E6=8A=95?= =?UTF-8?q?=E5=B1=8F=E5=9C=BA=E6=99=AFsink=E7=AB=AF=E7=84=A6=E7=82=B9?= =?UTF-8?q?=E4=BA=8B=E4=BB=B6=E6=97=A0=E6=B3=95=E5=8F=8D=E6=8E=A7source?= =?UTF-8?q?=E7=AB=AF=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: huyue57 Change-Id: Ifa4f34fdd9f53375de4a826f5a42b5cc84c21767 --- .../include/audio_policy_manager.h | 2 ++ .../include/audio_system_manager.h | 13 ++++++++++++ .../client/include/audio_policy_base.h | 3 +++ .../include/audio_policy_manager_stub.h | 2 ++ .../client/include/audio_policy_proxy.h | 3 +++ .../client/src/audio_policy_manager.cpp | 7 +++++++ .../client/src/audio_policy_proxy.cpp | 20 +++++++++++++++++++ .../include/audio_policy_ipc_interface_code.h | 3 ++- .../server/include/audio_policy_server.h | 2 ++ .../server/src/audio_policy_manager_stub.cpp | 13 ++++++++++++ .../server/src/audio_policy_server.cpp | 13 ++++++++++++ .../client/src/audio_system_manager.cpp | 5 +++++ .../audio_policy_another_fuzzer.cpp | 7 +++++++ 13 files changed, 92 insertions(+), 1 deletion(-) diff --git a/frameworks/native/audiopolicy/include/audio_policy_manager.h b/frameworks/native/audiopolicy/include/audio_policy_manager.h index 94eca65fd9..783dd29a38 100644 --- a/frameworks/native/audiopolicy/include/audio_policy_manager.h +++ b/frameworks/native/audiopolicy/include/audio_policy_manager.h @@ -392,6 +392,8 @@ public: int32_t ActivateAudioConcurrency(const AudioPipeType &pipeType); int32_t ResetRingerModeMute(); + + int32_t InjectInterruption(const std::string networkId, InterruptEvent &event); private: AudioPolicyManager() {} ~AudioPolicyManager() {} 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 7db5dcbd49..ac26f89e6c 100644 --- a/interfaces/inner_api/native/audiomanager/include/audio_system_manager.h +++ b/interfaces/inner_api/native/audiomanager/include/audio_system_manager.h @@ -1253,6 +1253,19 @@ public: static void AudioServerDied(pid_t pid); std::string GetSelfBundleName(int32_t uid); + + /** + * @brief inject interruption event. + * + * @param networkId networkId. + * @param event Indicates the InterruptEvent information needed by client. + * For details, refer InterruptEvent struct in audio_interrupt_info.h + * @return Returns {@link SUCCESS} if the setting is successful; returns an error code defined + * in {@link audio_errors.h} otherwise. + * @since 12 + */ + int32_t InjectInterruption(const std::string networkId, InterruptEvent &event); + private: class WakeUpCallbackImpl : public WakeUpSourceCallback { public: diff --git a/services/audio_policy/client/include/audio_policy_base.h b/services/audio_policy/client/include/audio_policy_base.h index faad35af8e..fc594b91f6 100644 --- a/services/audio_policy/client/include/audio_policy_base.h +++ b/services/audio_policy/client/include/audio_policy_base.h @@ -309,6 +309,9 @@ public: virtual int32_t MoveToNewPipe(const uint32_t sessionId, const AudioPipeType pipeType) = 0; virtual int32_t ResetRingerModeMute() = 0; + + virtual int32_t InjectInterruption(const std::string networkId, InterruptEvent &event) = 0; + public: DECLARE_INTERFACE_DESCRIPTOR(u"IAudioPolicy"); }; diff --git a/services/audio_policy/client/include/audio_policy_manager_stub.h b/services/audio_policy/client/include/audio_policy_manager_stub.h index 52619c66c9..aba2494125 100644 --- a/services/audio_policy/client/include/audio_policy_manager_stub.h +++ b/services/audio_policy/client/include/audio_policy_manager_stub.h @@ -156,6 +156,7 @@ private: void SetRingerStreamMuteInternal(MessageParcel &data, MessageParcel &reply); void SetMicrophoneMutePersistentInternal(MessageParcel &data, MessageParcel &reply); void GetMicrophoneMutePersistentInternal(MessageParcel &data, MessageParcel &reply); + void InjectInterruptionInternal(MessageParcel &data, MessageParcel &reply); using HandlerFunc = void(AudioPolicyManagerStub::*)(MessageParcel &data, MessageParcel &reply); static inline HandlerFunc handlers[] = { @@ -286,6 +287,7 @@ private: &AudioPolicyManagerStub::SetRingerStreamMuteInternal, &AudioPolicyManagerStub::SetMicrophoneMutePersistentInternal, &AudioPolicyManagerStub::GetMicrophoneMutePersistentInternal, + &AudioPolicyManagerStub::InjectInterruptionInternal, }; static constexpr size_t handlersNums = sizeof(handlers) / sizeof(HandlerFunc); static_assert(handlersNums == (static_cast (AudioPolicyInterfaceCode::AUDIO_POLICY_MANAGER_CODE_MAX) + 1), diff --git a/services/audio_policy/client/include/audio_policy_proxy.h b/services/audio_policy/client/include/audio_policy_proxy.h index 007daa8277..be27b1f7c3 100644 --- a/services/audio_policy/client/include/audio_policy_proxy.h +++ b/services/audio_policy/client/include/audio_policy_proxy.h @@ -296,6 +296,9 @@ public: int32_t ActivateAudioConcurrency(const AudioPipeType &pipeType) override; int32_t ResetRingerModeMute() override; + + int32_t InjectInterruption(const std::string networkId, InterruptEvent &event) override; + private: static inline BrokerDelegator mDdelegator; void WriteStreamChangeInfo(MessageParcel &data, const AudioMode &mode, diff --git a/services/audio_policy/client/src/audio_policy_manager.cpp b/services/audio_policy/client/src/audio_policy_manager.cpp index cd03395d0e..958bbc957d 100644 --- a/services/audio_policy/client/src/audio_policy_manager.cpp +++ b/services/audio_policy/client/src/audio_policy_manager.cpp @@ -1765,6 +1765,13 @@ int32_t AudioPolicyManager::ActivateAudioConcurrency(const AudioPipeType &pipeTy return gsp->ActivateAudioConcurrency(pipeType); } +int32_t AudioPolicyManager::InjectInterruption(const std::string networkId, InterruptEvent &event) +{ + const sptr gsp = GetAudioPolicyManagerProxy(); + CHECK_AND_RETURN_RET_LOG(gsp != nullptr, -1, "audio policy manager proxy is NULL."); + return gsp->InjectInterruption(networkId, event); +} + AudioPolicyManager& AudioPolicyManager::GetInstance() { static AudioPolicyManager policyManager; diff --git a/services/audio_policy/client/src/audio_policy_proxy.cpp b/services/audio_policy/client/src/audio_policy_proxy.cpp index 5b9ae7f2bf..828b5eed72 100644 --- a/services/audio_policy/client/src/audio_policy_proxy.cpp +++ b/services/audio_policy/client/src/audio_policy_proxy.cpp @@ -2317,5 +2317,25 @@ int32_t AudioPolicyProxy::ResetRingerModeMute() CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "activate concurrency failed, error: %{public}d", error); return reply.ReadInt32(); } + +int32_t AudioPolicyProxy::InjectInterruption(const std::string networkId, InterruptEvent &event) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + + bool ret = data.WriteInterfaceToken(GetDescriptor()); + CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); + data.WriteString(networkId); + data.WriteInt32(event.eventType); + data.WriteInt32(event.forceType); + data.WriteInt32(event.hintType); + + int error = Remote()->SendRequest( + static_cast(AudioPolicyInterfaceCode::INJECT_INTERRUPTION), data, reply, option); + CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "SendRequest failed, error: %{public}d", error); + return reply.ReadInt32(); +} + } // namespace AudioStandard } // namespace OHOS 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 b38933176e..6559309060 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 @@ -147,7 +147,8 @@ enum class AudioPolicyInterfaceCode { SET_RINGER_MODE_MUTE, SET_MICROPHONE_MUTE_PERSISTENT, GET_MICROPHONE_MUTE_PERSISTENT, - AUDIO_POLICY_MANAGER_CODE_MAX = GET_MICROPHONE_MUTE_PERSISTENT, + INJECT_INTERRUPTION, + AUDIO_POLICY_MANAGER_CODE_MAX = INJECT_INTERRUPTION, }; } // namespace AudioStandard } // namespace OHOS diff --git a/services/audio_policy/server/include/audio_policy_server.h b/services/audio_policy/server/include/audio_policy_server.h index 6ec4900b1f..1e770f3ec5 100644 --- a/services/audio_policy/server/include/audio_policy_server.h +++ b/services/audio_policy/server/include/audio_policy_server.h @@ -379,6 +379,8 @@ public: int32_t ResetRingerModeMute() override; + int32_t InjectInterruption(const std::string networkId, InterruptEvent &event) override; + class RemoteParameterCallback : public AudioParameterCallback { public: RemoteParameterCallback(sptr server); diff --git a/services/audio_policy/server/src/audio_policy_manager_stub.cpp b/services/audio_policy/server/src/audio_policy_manager_stub.cpp index 26eef5d5a1..955fc41144 100644 --- a/services/audio_policy/server/src/audio_policy_manager_stub.cpp +++ b/services/audio_policy/server/src/audio_policy_manager_stub.cpp @@ -154,6 +154,7 @@ const char *g_audioPolicyCodeStrs[] = { "SET_RINGER_MODE_MUTE", "SET_MICROPHONE_MUTE_PERSISTENT", "GET_MICROPHONE_MUTE_PERSISTENT", + "INJECT_INTERRUPTION", }; constexpr size_t codeNums = sizeof(g_audioPolicyCodeStrs) / sizeof(const char *); static_assert(codeNums == (static_cast (AudioPolicyInterfaceCode::AUDIO_POLICY_MANAGER_CODE_MAX) + 1), @@ -1370,5 +1371,17 @@ void AudioPolicyManagerStub::GetMicrophoneMutePersistentInternal(MessageParcel & bool result = GetPersistentMicMuteState(); reply.WriteBool(result); } + +void AudioPolicyManagerStub::InjectInterruptionInternal(MessageParcel &data, MessageParcel &reply) +{ + std::string networkId = data.ReadString(); + InterruptEvent event; + event.eventType = static_cast(data.ReadInt32()); + event.forceType = static_cast(data.ReadInt32()); + event.hintType = static_cast(data.ReadInt32()); + + int32_t result = InjectInterruption(networkId, event); + reply.WriteInt32(result); +} } // namespace audio_policy } // namespace OHOS diff --git a/services/audio_policy/server/src/audio_policy_server.cpp b/services/audio_policy/server/src/audio_policy_server.cpp index e1a7f2130d..2d25e69371 100644 --- a/services/audio_policy/server/src/audio_policy_server.cpp +++ b/services/audio_policy/server/src/audio_policy_server.cpp @@ -2759,5 +2759,18 @@ void AudioPolicyServer::UnregisterCommonEventReceiver() AUDIO_INFO_LOG("unregister bluetooth device name commonevent"); } } + +int32_t AudioPolicyServer::InjectInterruption(const std::string networkId, InterruptEvent &event) +{ + auto callerUid = IPCSkeleton::GetCallingUid(); + if (callerUid != UID_CAST_ENGINE_SA) { + AUDIO_ERR_LOG("InjectInterruption callerUid is Error: not cast_engine"); + return ERROR; + } + CHECK_AND_RETURN_RET_LOG(audioPolicyServerHandler_ != nullptr, ERROR, "audioPolicyServerHandler_ is nullptr"); + InterruptEventInternal interruptEvent { event.eventType, event.forceType, event.hintType, 0.2f}; + return audioPolicyServerHandler_->SendInterruptEventInternalCallback(interruptEvent); +} + } // 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 6437d1ab74..cc613dae2e 100644 --- a/services/audio_service/client/src/audio_system_manager.cpp +++ b/services/audio_service/client/src/audio_system_manager.cpp @@ -1536,5 +1536,10 @@ int32_t AudioSystemManager::DisableSafeMediaVolume() { return AudioPolicyManager::GetInstance().DisableSafeMediaVolume(); } + +int32_t AudioSystemManager::InjectInterruption(const std::string networkId, InterruptEvent &event) +{ + return AudioPolicyManager::GetInstance().InjectInterruption(networkId, event); +} } // namespace AudioStandard } // namespace OHOS diff --git a/test/fuzztest/audiopolicyanother_fuzzer/audio_policy_another_fuzzer.cpp b/test/fuzztest/audiopolicyanother_fuzzer/audio_policy_another_fuzzer.cpp index 5089eaa731..c3689cfcd8 100644 --- a/test/fuzztest/audiopolicyanother_fuzzer/audio_policy_another_fuzzer.cpp +++ b/test/fuzztest/audiopolicyanother_fuzzer/audio_policy_another_fuzzer.cpp @@ -252,6 +252,13 @@ void AudioPolicyOtherFuzzTest(const uint8_t *rawData, size_t size) GetServerPtr()->IsHighResolutionExist(); bool highResExist = *reinterpret_cast(rawData); GetServerPtr()->SetHighResolutionExist(highResExist); + + std::string networkId(reinterpret_cast(rawData), size - 1); + InterruptEvent event = {}; + event.eventType = *reinterpret_cast(rawData); + event.forceType = *reinterpret_cast(rawData); + event.hintType = *reinterpret_cast(rawData); + GetServerPtr()->InjectInterruption(networkId, event); } void AudioConcurrencyFuzzTest(const uint8_t *rawData, size_t size) -- Gitee