diff --git a/frameworks/native/audiopolicy/include/audio_policy_manager.h b/frameworks/native/audiopolicy/include/audio_policy_manager.h index 94eca65fd905e7f7a9567f7b825e13a88b0d75a2..783dd29a389b3a20dc98d130d303f87815169b10 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 7db5dcbd492045029525e5d25999257bc2403518..ac26f89e6c3b0856b1f2a47621b0608ace880700 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 faad35af8e831890223a6a048da9844d961d2b85..fc594b91f6d358e917b0fb72785b7e2f3dad63c8 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 52619c66c9c7a182d3e0ee97faa7ac0bbd4d384e..aba2494125edf1caec8bf8e6e6102da312341994 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 007daa827788c2cde65297fdc6911d6664291d5b..be27b1f7c305ced5af04344c835e6493404f03af 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 cd03395d0e5cad89e426e4aaf10aae3dca88b77b..958bbc957d161703f0a142fa78b9299b311543f0 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 5b9ae7f2bf868d21a7c399aa52df77d5b5a9afaf..828b5eed729bd87214f45ba6752475ca9a578532 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 b38933176ebe10f59bbca2b0f2eff6cd9907d799..65593090603ee34e8bc7ef31c6616af49d7ea62d 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 6ec4900b1f2d8ea4cbe9b175a532b2a8cf816ab7..1e770f3ec5ce0caa28879aa660c7d8bc7edaec9a 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 26eef5d5a1be1180d977b71f20a45e8b31f714da..955fc4114400db6649264a516eb4b443af3cbcbe 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 e1a7f2130dccef41875c711f4cc4ea25fd282606..2d25e69371bd6fe750992d5e56214778b0747083 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 6437d1ab74d3fe0a7d7adb11bc9cd9dca64cdae8..cc613dae2e1d6d66f6a2a2ee4caede17681d2080 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 5089eaa7319955079f80aac42c79334f52a0a5c8..c3689cfcd8e62ba73375be6fce8831380417e200 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)