diff --git a/services/samgr/native/include/collect/common_event_collect.h b/services/samgr/native/include/collect/common_event_collect.h index 69e026b62db34932e03390168d8eda961a51ab67..c1f8f0e45a131166bae5eda313f833501c7eb133 100644 --- a/services/samgr/native/include/collect/common_event_collect.h +++ b/services/samgr/native/include/collect/common_event_collect.h @@ -58,11 +58,13 @@ public: int GetSaExtraDataIdList(int32_t saId, std::vector& extraDataIdList, const std::string& eventName = "") override; void RemoveWhiteCommonEvent() override; + void StartReclaimIpcThreadWork(const EventFwk::CommonEventData& data); private: int64_t GenerateExtraDataIdLocked(); bool AddCommonEventName(const std::string& eventName); void AddSkillsEvent(EventFwk::MatchingSkills& skill); void CleanFailedEventLocked(const std::string& eventName); + void SendKernalReclaimIpcThread(); std::mutex commomEventLock_; std::mutex commonEventSubscriberLock_; sptr commonEventDeath_; @@ -80,6 +82,8 @@ private: std::map> extraDataKey_; std::mutex saExtraDataIdLock_; std::map> saExtraDataIdMap_; + std::atomic isTriggerTaskStart_ {false}; + std::atomic isCancel_{false}; }; class CommonEventListener : public SystemAbilityStatusChangeStub { diff --git a/services/samgr/native/source/collect/common_event_collect.cpp b/services/samgr/native/source/collect/common_event_collect.cpp index c1998b91c7746b5faecc11f570305cd1c9e5d8fa..1c510035701098d9f1e8d7290ead88c3ab00bc5e 100644 --- a/services/samgr/native/source/collect/common_event_collect.cpp +++ b/services/samgr/native/source/collect/common_event_collect.cpp @@ -21,6 +21,7 @@ #include "system_ability_manager_util.h" #include "common_event_manager.h" #include "common_event_support.h" +#include "ipc_skeleton.h" #include "matching_skills.h" #include "parse_util.h" #include "want.h" @@ -39,10 +40,14 @@ constexpr uint32_t REMOVE_EXTRA_DATA_DELAY_TIME = 300000; constexpr uint32_t UNSUB_DELAY_TIME = 10 * 1000; constexpr int64_t MAX_EXTRA_DATA_ID = 1000000000; constexpr int32_t COMMON_EVENT_SERVICE_ID = 3299; +constexpr int32_t TRIGGER_THREAD_RECLAIM_DELAY_TIME = 130; +constexpr int32_t TRIGGER_THREAD_RECLAIM_DURATION_TIME = 2; constexpr const char* UID = "uid"; constexpr const char* NET_TYPE = "NetType"; constexpr const char* BUNDLE_NAME = "bundleName"; constexpr const char* COMMON_EVENT_ACTION_NAME = "common_event_action_name"; +constexpr const char* COMMON_RECENT_EVENT = "RECENT_EVENT"; +constexpr const char* COMMON_RECENT_CLEAR_ALL = "RECENT_CLEAR_ALL"; } CommonEventCollect::CommonEventCollect(const sptr& report) @@ -534,6 +539,47 @@ int32_t CommonEventCollect::RemoveUnusedEvent(const OnDemandEvent& event) return ERR_OK; } +void CommonEventCollect::StartReclaimIpcThreadWork(const EventFwk::CommonEventData& data) +{ + bool isTrigger = false; + std::string eventName = data.GetWant().GetAction(); + std::string eventType = data.GetData(); + + if (eventName == EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_OFF) { + isTrigger = true; + isCancel_ = false; + } else if (eventName == EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_ON) { + isCancel_ = true; + } else if (eventName == COMMON_RECENT_EVENT && eventType == COMMON_RECENT_CLEAR_ALL) { + isTrigger = true; + isCancel_ = true; + HILOGI("TriggerSystemIPCThreadReclaim"); + IPCSkeleton::TriggerSystemIPCThreadReclaim(); + } + + if (isTrigger && !isTriggerTaskStart_.exchange(true)) { + SendKernalReclaimIpcThread(); + } +} + +void CommonEventCollect::SendKernalReclaimIpcThread() +{ + auto task = [this]() { + for (int i = 0; i < TRIGGER_THREAD_RECLAIM_DELAY_TIME; i+= TRIGGER_THREAD_RECLAIM_DURATION_TIME) { + if (isCancel_) { + isTriggerTaskStart_ = false; + return; + } + std::this_thread::sleep_for(std::chrono::seconds(TRIGGER_THREAD_RECLAIM_DURATION_TIME)); + } + HILOGI("TriggerSystemIPCThreadReclaim"); + IPCSkeleton::TriggerSystemIPCThreadReclaim(); + isTriggerTaskStart_ = false; + }; + std::thread reclaimThread(task); + reclaimThread.detach(); +} + bool CommonHandler::PostTask(std::function func, uint64_t delayTime) { if (handler_ == nullptr) { @@ -625,5 +671,6 @@ void CommonEventSubscriber::OnReceiveEvent(const EventFwk::CommonEventData& data collect->SaveOnDemandConditionExtraData(data); OnDemandEvent event = {COMMON_EVENT, action, std::to_string(code), extraDataId}; collect->ReportEvent(event); + collect->StartReclaimIpcThreadWork(data); } } // namespace OHOS