diff --git a/frameworks/native/audiopolicy/include/audio_policy_manager.h b/frameworks/native/audiopolicy/include/audio_policy_manager.h index 0877af17d44d69ba2b0dc7c14aa7d34dc972a593..3d564b8210bb2626d6b64cec7256b1f1382621fc 100644 --- a/frameworks/native/audiopolicy/include/audio_policy_manager.h +++ b/frameworks/native/audiopolicy/include/audio_policy_manager.h @@ -199,6 +199,8 @@ public: int32_t SetQueryClientTypeCallback(const std::shared_ptr &callback); + int32_t SetQueryBundleNameListCallback(const std::shared_ptr &callback); + int32_t SetAudioManagerInterruptCallback(const int32_t clientId, const std::shared_ptr &callback); 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 6935526828f207419c4ee3b13abc342d81bab9bb..f3740da019f87bb4fb5b8bda8d5ab205c3d50c27 100644 --- a/interfaces/inner_api/native/audiomanager/include/audio_system_manager.h +++ b/interfaces/inner_api/native/audiomanager/include/audio_system_manager.h @@ -189,6 +189,12 @@ private: std::shared_ptr cb_; }; +class AudioQueryBundleNameListCallback { +public: + virtual ~AudioQueryBundleNameListCallback() = default; + virtual bool OnQueryBundleNameIsInList(const std::string &bundleName) = 0; +}; + class AudioManagerAvailableDeviceChangeCallback { public: virtual ~AudioManagerAvailableDeviceChangeCallback() = default; @@ -1324,6 +1330,8 @@ public: int32_t SetAudioClientInfoMgrCallback(const std::shared_ptr &callback); int32_t SetQueryAllowedPlaybackCallback(const std::shared_ptr &callback); + int32_t SetQueryBundleNameListCallback(const std::shared_ptr &callback); + /** * @brief inject interruption event. * diff --git a/services/audio_policy/client/include/audio_policy_base.h b/services/audio_policy/client/include/audio_policy_base.h index edc6a26845853ff290e6813346382b1b56401f42..3c6bd1913490a985138eae894520170e98f86c07 100644 --- a/services/audio_policy/client/include/audio_policy_base.h +++ b/services/audio_policy/client/include/audio_policy_base.h @@ -151,6 +151,8 @@ public: virtual int32_t SetAudioClientInfoMgrCallback(const sptr &object) = 0; + virtual int32_t SetQueryBundleNameListCallback(const sptr &object) = 0; + virtual int32_t RequestAudioFocus(const int32_t clientId, const AudioInterrupt &audioInterrupt) = 0; virtual int32_t AbandonAudioFocus(const int32_t clientId, const AudioInterrupt &audioInterrupt) = 0; diff --git a/services/audio_policy/client/include/audio_policy_manager_listener_stub.h b/services/audio_policy/client/include/audio_policy_manager_listener_stub.h index 268188f7e6def66257e4aa8d90dbbae4c1b8cd43..184b485ab18539057569408650a2ab16034264e0 100644 --- a/services/audio_policy/client/include/audio_policy_manager_listener_stub.h +++ b/services/audio_policy/client/include/audio_policy_manager_listener_stub.h @@ -37,12 +37,14 @@ public: bool OnQueryClientType(const std::string &bundleName, uint32_t uid) override; bool OnCheckClientInfo(const std::string &bundleName, uint32_t uid, int32_t &pid) override; bool OnQueryAllowedPlayback(int32_t uid, int32_t pid) override; + bool OnQueryBundleNameIsInList(const std::string &bundleName) override; // AudioManagerListenerStub void SetInterruptCallback(const std::weak_ptr &callback); void SetAvailableDeviceChangeCallback(const std::weak_ptr &cb); void SetQueryClientTypeCallback(const std::weak_ptr &cb); void SetAudioClientInfoMgrCallback(const std::weak_ptr &cb); void SetQueryAllowedPlaybackCallback(const std::weak_ptr &callback); + void SetQueryBundleNameListCallback(const std::weak_ptr &cb); private: void ReadInterruptEventParams(MessageParcel &data, InterruptEventInternal &interruptEvent); void ReadAudioDeviceChangeData(MessageParcel &data, DeviceChangeAction &devChange); @@ -52,6 +54,7 @@ private: std::weak_ptr audioQueryClientTypeCallback_; std::weak_ptr audioQueryAllowedPlaybackCallback_; std::weak_ptr audioClientInfoMgrCallback_; + std::weak_ptr audioQueryBundleNameListCallback_; }; } // namespace AudioStandard } // namespace OHOS 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 1abbadca126a68993bfba6a13ed737b9c431433b..90f9ff44dbfe943b5789f4f0b086e9a5105a927e 100644 --- a/services/audio_policy/client/include/audio_policy_manager_stub.h +++ b/services/audio_policy/client/include/audio_policy_manager_stub.h @@ -198,7 +198,9 @@ private: void SetVirtualCallInternal(MessageParcel &data, MessageParcel &reply); void SetDeviceConnectionStatusInternal(MessageParcel &data, MessageParcel &reply); void SetQueryAllowedPlaybackCallbackInternal(MessageParcel &data, MessageParcel &reply); + void SetQueryBundleNameListCallbackInternal(MessageParcel &data, MessageParcel &reply); + void OnMiddleEleRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option); void OnMiddleTenRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option); void OnMiddleNinRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option); void OnMiddleEigRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option); diff --git a/services/audio_policy/client/include/audio_policy_proxy.h b/services/audio_policy/client/include/audio_policy_proxy.h index ca4a78fa1b38c51a357b7c9222d3d9eac6fac571..99ef4cd0a473d55fb19b0c6f4e5d6fe3be93ca73 100644 --- a/services/audio_policy/client/include/audio_policy_proxy.h +++ b/services/audio_policy/client/include/audio_policy_proxy.h @@ -160,6 +160,8 @@ public: int32_t SetAudioClientInfoMgrCallback(const sptr &object) override; + int32_t SetQueryBundleNameListCallback(const sptr &object) override; + int32_t RequestAudioFocus(const int32_t clientId, const AudioInterrupt &audioInterrupt) override; int32_t AbandonAudioFocus(const int32_t clientId, const AudioInterrupt &audioInterrupt) override; diff --git a/services/audio_policy/client/src/audio_policy_manager.cpp b/services/audio_policy/client/src/audio_policy_manager.cpp index 8957075dfa8790b4dbca690f6e18a6f971b0aba8..82be469c46bf74b2e9fabd1aacbdde82c0fb2ba4 100644 --- a/services/audio_policy/client/src/audio_policy_manager.cpp +++ b/services/audio_policy/client/src/audio_policy_manager.cpp @@ -891,6 +891,24 @@ int32_t AudioPolicyManager::SetQueryClientTypeCallback(const std::shared_ptrSetQueryClientTypeCallback(object); } +int32_t AudioPolicyManager::SetQueryBundleNameListCallback( + const std::shared_ptr &callback) +{ + AUDIO_INFO_LOG("In"); + const sptr gsp = GetAudioPolicyManagerProxy(); + CHECK_AND_RETURN_RET_LOG(gsp != nullptr, ERROR, "audio policy manager proxy is NULL."); + CHECK_AND_RETURN_RET_LOG(callback != nullptr, ERR_INVALID_PARAM, "callback is nullptr"); + + sptr listener = new(std::nothrow) AudioPolicyManagerListenerStub(); + CHECK_AND_RETURN_RET_LOG(listener != nullptr, ERROR, "object null"); + listener->SetQueryBundleNameListCallback(callback); + + sptr object = listener->AsObject(); + CHECK_AND_RETURN_RET_LOG(object != nullptr, ERROR, "listenerStub->AsObject is nullptr."); + + return gsp->SetQueryBundleNameListCallback(object); +} + int32_t AudioPolicyManager::ActivateAudioInterrupt( AudioInterrupt &audioInterrupt, const int32_t zoneID, const bool isUpdatedAudioStrategy) { diff --git a/services/audio_policy/client/src/audio_policy_manager_listener_stub.cpp b/services/audio_policy/client/src/audio_policy_manager_listener_stub.cpp index 62ff6b76fbe33f51981629072753dbe1cadd4a76..34547fa7ed7dec79fbdf687066cfc45973c0e4d5 100644 --- a/services/audio_policy/client/src/audio_policy_manager_listener_stub.cpp +++ b/services/audio_policy/client/src/audio_policy_manager_listener_stub.cpp @@ -103,6 +103,11 @@ int AudioPolicyManagerListenerStub::OnRemoteRequest( OnCheckClientInfo(bundleName, uid, pid); return AUDIO_OK; } + case ON_QUERY_BUNDLE_NAME_LIST: { + std::string bundleName = data.ReadString(); + OnQueryBundleNameIsInList(bundleName); + return AUDIO_OK; + } default: { AUDIO_ERR_LOG("default case, need check AudioListenerStub"); return IPCObjectStub::OnRemoteRequest(code, data, reply, option); @@ -163,6 +168,17 @@ bool AudioPolicyManagerListenerStub::OnQueryAllowedPlayback(int32_t uid, int32_t return audioQueryAllowedPlaybackCallback->OnQueryAllowedPlayback(uid, pid); } +bool AudioPolicyManagerListenerStub::OnQueryBundleNameIsInList(const std::string &bundleName) +{ + std::shared_ptr audioQueryBundleNameListCallback = + audioQueryBundleNameListCallback_.lock(); + + CHECK_AND_RETURN_RET_LOG(audioQueryBundleNameListCallback != nullptr, false, + "audioQueryBundleNameListCallback_ is nullptr"); + + return audioQueryBundleNameListCallback->OnQueryBundleNameIsInList(bundleName); +} + void AudioPolicyManagerListenerStub::SetInterruptCallback(const std::weak_ptr &callback) { callback_ = callback; @@ -189,5 +205,11 @@ void AudioPolicyManagerListenerStub::SetQueryAllowedPlaybackCallback( { audioQueryAllowedPlaybackCallback_ = cb; } + +void AudioPolicyManagerListenerStub::SetQueryBundleNameListCallback( + const std::weak_ptr &cb) +{ + audioQueryBundleNameListCallback_ = cb; +} } // namespace AudioStandard } // namespace OHOS diff --git a/services/audio_policy/client/src/proxy/audio_policy_callback_proxy.cpp b/services/audio_policy/client/src/proxy/audio_policy_callback_proxy.cpp index e9e1a34dcab75b7081d39d8e8550299a4d6ad0f0..e7ba3dc75b680ffe8a2b601d29467c3f23584c27 100644 --- a/services/audio_policy/client/src/proxy/audio_policy_callback_proxy.cpp +++ b/services/audio_policy/client/src/proxy/audio_policy_callback_proxy.cpp @@ -144,6 +144,25 @@ int32_t AudioPolicyProxy::SetAudioClientInfoMgrCallback(const sptr &object) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + + CHECK_AND_RETURN_RET_LOG(object != nullptr, ERR_NULL_OBJECT, + "SetQueryClientTypeCallback object is null"); + bool ret = data.WriteInterfaceToken(GetDescriptor()); + CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); + (void)data.WriteRemoteObject(object); + int error = Remote()->SendRequest( + static_cast(AudioPolicyInterfaceCode::SET_QUERY_BUNDLE_NAME_LIST_CALLBACK), data, reply, option); + CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, + "set callback failed, error: %{public}d", error); + + return reply.ReadInt32(); +} + int32_t AudioPolicyProxy::SetAvailableDeviceChangeCallback(const int32_t clientId, const AudioDeviceUsage usage, const sptr &object) { 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 050f97c42fa885e2421188bd5943e673d0346a16..921c36881c2e82177052d087c2abc008394f0679 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 @@ -53,6 +53,7 @@ enum class AudioPolicyInterfaceCode { UNSET_CALLBACK, SET_QUERY_CLIENT_TYPE_CALLBACK, SET_CLIENT_INFO_MGR_CALLBACK, + SET_QUERY_BUNDLE_NAME_LIST_CALLBACK, ACTIVATE_INTERRUPT, DEACTIVATE_INTERRUPT, SET_INTERRUPT_CALLBACK, diff --git a/services/audio_policy/common/include/i_standard_audio_policy_manager_listener.h b/services/audio_policy/common/include/i_standard_audio_policy_manager_listener.h index be8c2c06def2866f35ca8cd1b4d1d1517f7911f7..0e9c191b0593443faa8acb37034444e752c3d345 100644 --- a/services/audio_policy/common/include/i_standard_audio_policy_manager_listener.h +++ b/services/audio_policy/common/include/i_standard_audio_policy_manager_listener.h @@ -32,6 +32,7 @@ public: virtual bool OnQueryClientType(const std::string &bundleName, uint32_t uid) = 0; virtual bool OnCheckClientInfo(const std::string &bundleName, uint32_t uid, int32_t &pid) = 0; virtual bool OnQueryAllowedPlayback(int32_t uid, int32_t pid) = 0; + virtual bool OnQueryBundleNameIsInList(const std::string &bundleName) = 0; bool hasBTPermission_ = true; bool hasSystemPermission_ = true; @@ -43,6 +44,7 @@ public: ON_QUERY_CLIENT_TYPE, ON_CHECK_CLIENT_INFO, ON_QUERY_ALLOWED_PLAYBACK, + ON_QUERY_BUNDLE_NAME_LIST, }; DECLARE_INTERFACE_DESCRIPTOR(u"IStandardAudioManagerListener"); }; diff --git a/services/audio_policy/server/include/audio_policy_manager_listener_proxy.h b/services/audio_policy/server/include/audio_policy_manager_listener_proxy.h index 8628320135106272819bf702c080debc859bd932..443bc0fd2b38953eae53e55d1e2743097d4d6470 100644 --- a/services/audio_policy/server/include/audio_policy_manager_listener_proxy.h +++ b/services/audio_policy/server/include/audio_policy_manager_listener_proxy.h @@ -32,6 +32,7 @@ public: bool OnQueryClientType(const std::string &bundleName, uint32_t uid) override; bool OnCheckClientInfo(const std::string &bundleName, uint32_t uid, int32_t &pid) override; bool OnQueryAllowedPlayback(int32_t uid, int32_t pid) override; + bool OnQueryBundleNameIsInList(const std::string &bundleName) override; private: static inline BrokerDelegator delegator_; diff --git a/services/audio_policy/server/include/audio_policy_server.h b/services/audio_policy/server/include/audio_policy_server.h index 43df1329f26f3564a0c5e8a387675469edd83b00..05e19176b72ce52119e5db77877332fb5831a6e7 100644 --- a/services/audio_policy/server/include/audio_policy_server.h +++ b/services/audio_policy/server/include/audio_policy_server.h @@ -221,6 +221,8 @@ public: int32_t SetAudioClientInfoMgrCallback(const sptr &object) override; + int32_t SetQueryBundleNameListCallback(const sptr &object) override; + int32_t RequestAudioFocus(const int32_t clientId, const AudioInterrupt &audioInterrupt) override; int32_t AbandonAudioFocus(const int32_t clientId, const AudioInterrupt &audioInterrupt) override; @@ -701,6 +703,7 @@ private: AudioPolicyDump &audioPolicyDump_; int32_t sessionIdByRemote_ = -1; AudioActiveDevice& audioActiveDevice_; + sptr queryBundleNameListCallback_ = nullptr; }; class AudioOsAccountInfo : public AccountSA::OsAccountSubscriber { diff --git a/services/audio_policy/server/src/audio_policy_manager_listener_proxy.cpp b/services/audio_policy/server/src/audio_policy_manager_listener_proxy.cpp index 9b8382a9278a27accea2239fc85532a2568d2d7b..b3cfb4d81f004cb99f6b3afdda2e1ab9b7419632 100644 --- a/services/audio_policy/server/src/audio_policy_manager_listener_proxy.cpp +++ b/services/audio_policy/server/src/audio_policy_manager_listener_proxy.cpp @@ -158,5 +158,22 @@ bool AudioPolicyManagerListenerProxy::OnQueryAllowedPlayback(int32_t uid, int32_ CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, true, "OnQueryAllowedPlayback failed, error: %{public}d", error); return reply.ReadBool(); } + +bool AudioPolicyManagerListenerProxy::OnQueryBundleNameIsInList(const std::string &bundleName) +{ + AUDIO_DEBUG_LOG("In"); + + MessageParcel data; + MessageParcel reply; + MessageOption option; + + CHECK_AND_RETURN_RET_LOG(data.WriteInterfaceToken(GetDescriptor()), false, + "AudioPolicyManagerListenerProxy: WriteInterfaceToken failed"); + data.WriteString(bundleName); + + int error = Remote()->SendRequest(ON_QUERY_BUNDLE_NAME_LIST, data, reply, option); + CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, false, "OnQueryClientType failed, error: %{public}d", error); + return reply.ReadBool(); +} } // namespace AudioStandard } // namespace OHOS 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 f745968fe997d629f82b6bed4205af9e1ce11a84..610509f873e77f70cc59c72ebc29df0aa8c95a3c 100644 --- a/services/audio_policy/server/src/audio_policy_manager_stub.cpp +++ b/services/audio_policy/server/src/audio_policy_manager_stub.cpp @@ -62,6 +62,7 @@ const char *g_audioPolicyCodeStrs[] = { "UNSET_CALLBACK", "SET_QUERY_CLIENT_TYPE_CALLBACK", "SET_CLIENT_INFO_MGR_CALLBACK", + "SET_QUERY_BUNDLE_NAME_LIST_CALLBACK", "ACTIVATE_INTERRUPT", "DEACTIVATE_INTERRUPT", "SET_INTERRUPT_CALLBACK", @@ -1189,6 +1190,28 @@ void AudioPolicyManagerStub::SetAudioClientInfoMgrCallbackInternal(MessageParcel reply.WriteInt32(result); } +void AudioPolicyManagerStub::SetQueryBundleNameListCallbackInternal(MessageParcel &data, MessageParcel &reply) +{ + sptr object = data.ReadRemoteObject(); + CHECK_AND_RETURN_LOG(object != nullptr, "SetQueryBundleNameListCallback is null"); + int32_t result = SetQueryBundleNameListCallback(object); + reply.WriteInt32(result); +} + +void AudioPolicyManagerStub::OnMiddleEleRemoteRequest( + uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) +{ + switch (code) { + case static_cast(AudioPolicyInterfaceCode::SET_QUERY_BUNDLE_NAME_LIST_CALLBACK): + SetQueryBundleNameListCallbackInternal(data, reply); + break; + default: + AUDIO_ERR_LOG("default case, need check AudioPolicyManagerStub"); + IPCObjectStub::OnRemoteRequest(code, data, reply, option); + break; + } +} + void AudioPolicyManagerStub::OnMiddleTenRemoteRequest( uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { @@ -1236,8 +1259,7 @@ void AudioPolicyManagerStub::OnMiddleTenRemoteRequest( SetQueryAllowedPlaybackCallbackInternal(data, reply); break; default: - AUDIO_ERR_LOG("default case, need check AudioPolicyManagerStub"); - IPCObjectStub::OnRemoteRequest(code, data, reply, option); + OnMiddleEleRemoteRequest(code, data, reply, option); break; } } @@ -2034,8 +2056,7 @@ void AudioPolicyManagerStub::GetSupportedAudioEffectPropertyInternal(MessageParc AudioEffectPropertyArray propertyArray = {}; int32_t result = GetSupportedAudioEffectProperty(propertyArray); int32_t size = propertyArray.property.size(); - CHECK_AND_RETURN_LOG(size >= 0 && size <= AUDIO_EFFECT_COUNT_UPPER_LIMIT, - "get supported audio effect property size invalid."); + CHECK_AND_RETURN_LOG(size >= 0 && size <= AUDIO_EFFECT_COUNT_UPPER_LIMIT, "size invalid."); reply.WriteInt32(size); for (int i = 0; i < size; i++) { propertyArray.property[i].Marshalling(reply); @@ -2047,8 +2068,7 @@ void AudioPolicyManagerStub::GetSupportedAudioEffectPropertyInternal(MessageParc void AudioPolicyManagerStub::SetAudioEffectPropertyInternal(MessageParcel &data, MessageParcel &reply) { int32_t size = data.ReadInt32(); - CHECK_AND_RETURN_LOG(size > 0 && size <= AUDIO_EFFECT_COUNT_UPPER_LIMIT, - "set audio effect property size upper limit."); + CHECK_AND_RETURN_LOG(size > 0 && size <= AUDIO_EFFECT_COUNT_UPPER_LIMIT, "size upper limit."); AudioEffectPropertyArray propertyArray = {}; for (int i = 0; i < size; i++) { AudioEffectProperty prop = {}; @@ -2064,8 +2084,7 @@ void AudioPolicyManagerStub::GetAudioEffectPropertyInternal(MessageParcel &data, AudioEffectPropertyArray propertyArray = {}; int32_t result = GetAudioEffectProperty(propertyArray); int32_t size = propertyArray.property.size(); - CHECK_AND_RETURN_LOG(size >= 0 && size <= AUDIO_EFFECT_COUNT_UPPER_LIMIT, - "get audio effect property size invalid."); + CHECK_AND_RETURN_LOG(size >= 0 && size <= AUDIO_EFFECT_COUNT_UPPER_LIMIT, "size invalid."); reply.WriteInt32(size); for (int i = 0; i < size; i++) { propertyArray.property[i].Marshalling(reply); @@ -2077,8 +2096,7 @@ void AudioPolicyManagerStub::GetAudioEffectPropertyInternal(MessageParcel &data, void AudioPolicyManagerStub::SetAudioEnhancePropertyInternal(MessageParcel &data, MessageParcel &reply) { int32_t size = data.ReadInt32(); - CHECK_AND_RETURN_LOG(size > 0 && size <= AUDIO_EFFECT_COUNT_UPPER_LIMIT, - "set audio enhance property size upper limit."); + CHECK_AND_RETURN_LOG(size > 0 && size <= AUDIO_EFFECT_COUNT_UPPER_LIMIT, "size upper limit."); AudioEnhancePropertyArray propertyArray = {}; for (int i = 0; i < size; i++) { AudioEnhanceProperty prop = {}; diff --git a/services/audio_policy/server/src/audio_policy_server.cpp b/services/audio_policy/server/src/audio_policy_server.cpp index 640f078095f59e3fa972a8774067c70c33ac6787..09519c8417ef6d819c7a0c9110bb3a8fabe4010f 100644 --- a/services/audio_policy/server/src/audio_policy_server.cpp +++ b/services/audio_policy/server/src/audio_policy_server.cpp @@ -1910,6 +1910,19 @@ int32_t AudioPolicyServer::SetAudioClientInfoMgrCallback(const sptr &object) +{ + if (!PermissionUtil::VerifyIsAudio()) { + AUDIO_ERR_LOG("not audio calling!"); + return ERR_OPERATION_FAILED; + } + + if (interruptService_ != nullptr) { + return interruptService_->SetQueryBundleNameListCallback(object); + } + return ERR_UNKNOWN; +} + int32_t AudioPolicyServer::RequestAudioFocus(const int32_t clientId, const AudioInterrupt &audioInterrupt) { if (interruptService_ != nullptr) { diff --git a/services/audio_policy/server/src/service/interrupt/audio_interrupt_service.cpp b/services/audio_policy/server/src/service/interrupt/audio_interrupt_service.cpp index 67164793a777213673f0275533b756cc6c17f491..393a958938f43d1737a2ebfa50e842c080bb34ab 100644 --- a/services/audio_policy/server/src/service/interrupt/audio_interrupt_service.cpp +++ b/services/audio_policy/server/src/service/interrupt/audio_interrupt_service.cpp @@ -1173,6 +1173,7 @@ void AudioInterruptService::ProcessActiveInterrupt(const int32_t zoneId, const A for (auto iterActive = tmpFocusInfoList.begin(); iterActive != tmpFocusInfoList.end();) { AudioFocusEntry focusEntry = focusCfgMap_[std::make_pair((iterActive->first).audioFocusType, incomingInterrupt.audioFocusType)]; + UpdateAudioFocusStrategy((iterActive->first).audioFocusType, incomingInterrupt.audioFocusType, focusEntry); if (focusEntry.actionOn != CURRENT || IsSameAppInShareMode(incomingInterrupt, iterActive->first) || iterActive->second == PLACEHOLDER || CanMixForSession(incomingInterrupt, iterActive->first, focusEntry) || // incomming peeling should not stop/pause/duck other playing instances @@ -1362,6 +1363,61 @@ bool AudioInterruptService::IsAudioSourceConcurrency(const SourceType &existSour return false; } +bool AudioInterruptService::IsMediaStream(AudioStreamType audioStreamType) +{ + if (audioStreamType == STREAM_MUSIC || audioStreamType == STREAM_MOVIE || audioStreamType == STREAM_SPEECH) { + return true; + } + return false; +} + +int32_t AudioInterruptService::SetQueryBundleNameListCallback(const sptr &object) +{ + AUDIO_INFO_LOG("Set query bundle name list callback"); + queryBundleNameListCallback_ = iface_cast(object); + if (queryBundleNameListCallback_ == nullptr) { + AUDIO_ERR_LOG("Client type callback is null"); + return ERR_CALLBACK_NOT_REGISTERED; + } + return SUCCESS; +} + +void AudioInterruptService::UpdateAudioFocusStrategy(AudioFocusType existAudioFocusType, + AudioFocusType incomingAudioFocusType, AudioFocusEntry &focusEntry) +{ + CHECK_AND_RETURN_LOG(policyServer_ != nullptr, "policyServer nullptr"); + std::string bundleName = policyServer_->GetBundleName(); + AudioStreamType existStreamType = existAudioFocusType.streamType; + AudioStreamType incomingStreamType = incomingAudioFocusType.streamType; + if (IsMediaStream(existStreamType) && IsMediaStream(incomingStreamType) + && queryBundleNameListCallback_ != nullptr + && queryBundleNameListCallback_->OnQueryBundleNameIsInList(bundleName) + && focusEntry.hintType == INTERRUPT_HINT_STOP) { + focusEntry.hintType = INTERRUPT_HINT_PAUSE; + AUDIO_INFO_LOG("%{public}s update audio focus strategy", bundleName.c_str()); + } +} + +bool AudioInterruptService::FocusEntryContinue(std::list>::iterator + &iterActive, AudioFocusEntry &focusEntry, const AudioInterrupt &incomingInterrupt) +{ + bool continueFlag = false; + SourceType incomingSourceType = incomingInterrupt.audioFocusType.sourceType; + std::vector incomingConcurrentSources = incomingInterrupt.currencySources.sourcesTypes; + if (focusEntry.actionOn == CURRENT || iterActive->second == PLACEHOLDER || + CanMixForSession(incomingInterrupt, iterActive->first, focusEntry)) { + continueFlag = true; + } + if (((focusEntry.actionOn == INCOMING && focusEntry.hintType == INTERRUPT_HINT_PAUSE) || focusEntry.isReject) + && (IsAudioSourceConcurrency((iterActive->first).audioFocusType.sourceType, incomingSourceType, + (iterActive->first).currencySources.sourcesTypes, incomingConcurrentSources) + // if the rejection is caused by the existing peeling recording, just ignore it + || IsLowestPriorityRecording(iterActive->first))) { + continueFlag = true; + } + return continueFlag; +} + int32_t AudioInterruptService::ProcessFocusEntry(const int32_t zoneId, const AudioInterrupt &incomingInterrupt) { AudioFocuState incomingState = ACTIVE; @@ -1371,8 +1427,6 @@ int32_t AudioInterruptService::ProcessFocusEntry(const int32_t zoneId, const Aud std::list> audioFocusInfoList {}; if (itZone != zonesMap_.end()) { audioFocusInfoList = itZone->second->audioFocusInfoList; } - SourceType incomingSourceType = incomingInterrupt.audioFocusType.sourceType; - std::vector incomingConcurrentSources = incomingInterrupt.currencySources.sourcesTypes; for (auto iterActive = audioFocusInfoList.begin(); iterActive != audioFocusInfoList.end(); ++iterActive) { if (IsSameAppInShareMode(incomingInterrupt, iterActive->first)) { continue; } // if peeling is the incomming interrupt while at the momount there are already some existing recordings @@ -1387,16 +1441,9 @@ int32_t AudioInterruptService::ProcessFocusEntry(const int32_t zoneId, const Aud std::make_pair((iterActive->first).audioFocusType, incomingInterrupt.audioFocusType); CHECK_AND_RETURN_RET_LOG(focusCfgMap_.find(focusPair) != focusCfgMap_.end(), ERR_INVALID_PARAM, "no focus cfg"); AudioFocusEntry focusEntry = focusCfgMap_[focusPair]; - CheckIncommingFoucsValidity(focusEntry, incomingInterrupt, incomingConcurrentSources); - if (focusEntry.actionOn == CURRENT || iterActive->second == PLACEHOLDER || - CanMixForSession(incomingInterrupt, iterActive->first, focusEntry)) { continue; } - if (((focusEntry.actionOn == INCOMING && focusEntry.hintType == INTERRUPT_HINT_PAUSE) || focusEntry.isReject) - && (IsAudioSourceConcurrency((iterActive->first).audioFocusType.sourceType, incomingSourceType, - (iterActive->first).currencySources.sourcesTypes, incomingConcurrentSources) - // if the rejection is caused by the existing peeling recording, just ignore it - || IsLowestPriorityRecording(iterActive->first))) { - continue; - } + UpdateAudioFocusStrategy((iterActive->first).audioFocusType, incomingInterrupt.audioFocusType, focusEntry); + CheckIncommingFoucsValidity(focusEntry, incomingInterrupt, incomingInterrupt.currencySources.sourcesTypes); + if (FocusEntryContinue(iterActive, focusEntry, incomingInterrupt)) { continue; } if (focusEntry.isReject) { if (GetClientTypeByStreamId((iterActive->first).streamId) == CLIENT_TYPE_GAME) { incomingState = PAUSE; @@ -1667,6 +1714,7 @@ std::list> AudioInterruptService::Simu break; } AudioFocusEntry focusEntry = focusCfgMap_[audioFocusTypePair]; + UpdateAudioFocusStrategy(inprocessing.audioFocusType, incoming.audioFocusType, focusEntry); SourceType existSourceType = inprocessing.audioFocusType.sourceType; std::vector existConcurrentSources = inprocessing.currencySources.sourcesTypes; bool bConcurrency = IsAudioSourceConcurrency(existSourceType, incomingSourceType, diff --git a/services/audio_policy/server/src/service/interrupt/audio_interrupt_service.h b/services/audio_policy/server/src/service/interrupt/audio_interrupt_service.h index c344e343b785831aa10ac3fe9a5c1061a8d04b4e..3790a03b3334498ee36aa93fe99e7ecc712c90c1 100644 --- a/services/audio_policy/server/src/service/interrupt/audio_interrupt_service.h +++ b/services/audio_policy/server/src/service/interrupt/audio_interrupt_service.h @@ -100,6 +100,7 @@ public: AudioScene GetHighestPriorityAudioScene(const int32_t zoneId) const; ClientType GetClientTypeByStreamId(int32_t streamId); void ProcessRemoteInterrupt(std::set streamIds, InterruptEventInternal interruptEvent); + int32_t SetQueryBundleNameListCallback(const sptr &object); private: static constexpr int32_t ZONEID_DEFAULT = 0; @@ -163,6 +164,11 @@ private: bool IsAudioSourceConcurrency(const SourceType &existSourceType, const SourceType &incomingSourceType, const std::vector &existConcurrentSources, const std::vector &incomingConcurrentSources); + bool IsMediaStream(AudioStreamType audioStreamType); + void UpdateAudioFocusStrategy(AudioFocusType existAudioFocusType, AudioFocusType incomingAudioFocusType, + AudioFocusEntry &focusEntry); + bool FocusEntryContinue(std::list>::iterator &iterActive, + AudioFocusEntry &focusEntry, const AudioInterrupt &incomingInterrupt); int32_t ProcessFocusEntry(const int32_t zoneId, const AudioInterrupt &incomingInterrupt); void SendInterruptEventToIncomingStream(InterruptEventInternal &interruptEvent, const AudioInterrupt &incomingInterrupt); @@ -266,6 +272,7 @@ private: std::mutex mutex_; mutable int32_t ownerPid_ = 0; std::unique_ptr dfxCollector_; + sptr queryBundleNameListCallback_ = nullptr; }; } // 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 1b412dfedfd36c2dccff828f9fe80b96f2bdb1d3..4844e68e4987bc26d39eb0c776ea9eb8257116eb 100644 --- a/services/audio_service/client/src/audio_system_manager.cpp +++ b/services/audio_service/client/src/audio_system_manager.cpp @@ -776,6 +776,14 @@ int32_t AudioSystemManager::SetAudioClientInfoMgrCallback(const std::shared_ptr< return AudioPolicyManager::GetInstance().SetAudioClientInfoMgrCallback(callback); } +int32_t AudioSystemManager::SetQueryBundleNameListCallback( + const std::shared_ptr &callback) +{ + AUDIO_INFO_LOG("In"); + CHECK_AND_RETURN_RET_LOG(callback != nullptr, ERR_INVALID_PARAM, "callback is nullptr"); + return AudioPolicyManager::GetInstance().SetQueryBundleNameListCallback(callback); +} + int32_t AudioSystemManager::SetRingerModeCallback(const int32_t clientId, const std::shared_ptr &callback) {