diff --git a/services/dataobsmgr/include/data_ability_observer_proxy.h b/services/dataobsmgr/include/data_ability_observer_proxy.h index 244a829e6dd44008573430d92d98aed9856c348c..fa67707413b1395e21e6822bd0d3db2fdee6d825 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 678e4893bdb8c9f076fce5b13abf1990e60ffe0b..041f2829438b3e610ce912bcca52cc7e134c383d 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");