From 43e9b988f426676daddc3cf0a63407df9763d497 Mon Sep 17 00:00:00 2001 From: h60047265 Date: Sat, 14 Dec 2024 17:16:55 +0800 Subject: [PATCH] =?UTF-8?q?cherry=20pick=202ecfcf2=20from=20https://gitee.?= =?UTF-8?q?com/hongll/systemabilitymgr=5Fsam=E2=80=A6=20=EF=BC=88cherry=20?= =?UTF-8?q?picked=20commit=20from=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../source/collect/common_event_collect.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/services/samgr/native/source/collect/common_event_collect.cpp b/services/samgr/native/source/collect/common_event_collect.cpp index 305f9d59..41594bcc 100644 --- a/services/samgr/native/source/collect/common_event_collect.cpp +++ b/services/samgr/native/source/collect/common_event_collect.cpp @@ -178,24 +178,25 @@ bool CommonEventCollect::CreateCommonEventSubscriber() bool CommonEventCollect::CreateCommonEventSubscriberLocked() { int64_t begin = GetTickCount(); - if (commonEventSubscriber_ != nullptr) { + EventFwk::MatchingSkills skill = EventFwk::MatchingSkills(); + AddSkillsEvent(skill); + EventFwk::CommonEventSubscribeInfo info(skill); + std::shared_ptr comEvtScrb = commonEventSubscriber_; + commonEventSubscriber_ = std::make_shared(info, this); + bool ret = EventFwk::CommonEventManager::SubscribeCommonEvent(commonEventSubscriber_); + HILOGI("SubsComEvt %{public}" PRId64 "ms %{public}s", (GetTickCount() - begin), ret ? "suc" : "fail"); + if (comEvtScrb != nullptr) { HILOGI("UnSubsComEvt start"); { SamgrXCollie samgrXCollie("samgr--UnSubscribeCommonEvent"); - bool isUnsubscribe = EventFwk::CommonEventManager::UnSubscribeCommonEvent(commonEventSubscriber_); + bool isUnsubscribe = EventFwk::CommonEventManager::UnSubscribeCommonEvent(comEvtScrb); if (!isUnsubscribe) { HILOGE("CreateCommonEventSubscriberLocked isUnsubscribe failed!"); return false; } } - commonEventSubscriber_.reset(); + comEvtScrb.reset(); } - EventFwk::MatchingSkills skill = EventFwk::MatchingSkills(); - AddSkillsEvent(skill); - EventFwk::CommonEventSubscribeInfo info(skill); - commonEventSubscriber_ = std::make_shared(info, this); - bool ret = EventFwk::CommonEventManager::SubscribeCommonEvent(commonEventSubscriber_); - HILOGI("SubsComEvt %{public}" PRId64 "ms %{public}s", (GetTickCount() - begin), ret ? "suc" : "fail"); return ret; } -- Gitee