From 972ea9038fb8b37adf087b0f2cd4d197865dd1e1 Mon Sep 17 00:00:00 2001 From: Axi_Beft Date: Fri, 9 May 2025 19:28:40 +0800 Subject: [PATCH] data_share IPC message option change Signed-off-by: Axi_Beft --- .../include/data_ability_observer_proxy.h | 3 ++ .../src/data_ability_observer_proxy.cpp | 29 +++++++++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/services/dataobsmgr/include/data_ability_observer_proxy.h b/services/dataobsmgr/include/data_ability_observer_proxy.h index 244a829e6dd..fa67707413b 100644 --- a/services/dataobsmgr/include/data_ability_observer_proxy.h +++ b/services/dataobsmgr/include/data_ability_observer_proxy.h @@ -50,6 +50,9 @@ public: private: static inline BrokerDelegator delegator_; int32_t SendTransactCmd(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option); + void SetMessageOption(MessageOption &option); + uint32_t messageCount_ = 0; + std::mutex countMutex_; }; } // namespace AAFwk } // namespace OHOS diff --git a/services/dataobsmgr/src/data_ability_observer_proxy.cpp b/services/dataobsmgr/src/data_ability_observer_proxy.cpp index 678e4893bdb..041f2829438 100644 --- a/services/dataobsmgr/src/data_ability_observer_proxy.cpp +++ b/services/dataobsmgr/src/data_ability_observer_proxy.cpp @@ -19,11 +19,31 @@ namespace OHOS { namespace AAFwk { +static constexpr uint32_t MESSAGE_MAX_COUNT = 50; DataAbilityObserverProxy::DataAbilityObserverProxy(const sptr &remote) : IRemoteProxy(remote) {} DataAbilityObserverProxy::~DataAbilityObserverProxy() {} + +/** + * @brief Set the message option. + * + * @param option Indicates the option of message. + */ + void DataAbilityObserverProxy::SetMessageOption(MessageOption &option) + { + std::lock_guard lock(countMutex_); + // Send a wakeup IPC every 50 times. Otherwise, send a non-wakeup IPC. + if (messageCount_ >= MESSAGE_MAX_COUNT) { + option = MessageOption(MessageOption::TF_ASYNC); + messageCount_ = 0; + } else { + option = MessageOption(MessageOption::TF_ASYNC | MessageOption::TF_ASYNC_WAKEUP_LATER); + messageCount_++; + } + } + /** * @brief Called back to notify that the data being observed has changed. * @@ -33,7 +53,8 @@ void DataAbilityObserverProxy::OnChange() { OHOS::MessageParcel data; OHOS::MessageParcel reply; - MessageOption option(MessageOption::TF_ASYNC); + MessageOption option; + SetMessageOption(option); if (!data.WriteInterfaceToken(DataAbilityObserverProxy::GetDescriptor())) { TAG_LOGE(AAFwkTag::DBOBSMGR, "write token false"); @@ -55,7 +76,8 @@ void DataAbilityObserverProxy::OnChangeExt(const ChangeInfo &changeInfo) { OHOS::MessageParcel data; OHOS::MessageParcel reply; - MessageOption option(MessageOption::TF_ASYNC); + MessageOption option; + SetMessageOption(option); if (!data.WriteInterfaceToken(DataAbilityObserverProxy::GetDescriptor())) { TAG_LOGE(AAFwkTag::DBOBSMGR, "write token false"); @@ -82,7 +104,8 @@ void DataAbilityObserverProxy::OnChangePreferences(const std::string &key) { OHOS::MessageParcel data; OHOS::MessageParcel reply; - MessageOption option(MessageOption::TF_ASYNC); + MessageOption option; + SetMessageOption(option); if (!data.WriteInterfaceToken(DataAbilityObserverProxy::GetDescriptor())) { TAG_LOGE(AAFwkTag::DBOBSMGR, "write token false"); -- Gitee