diff --git a/services/samgr/native/source/collect/common_event_collect.cpp b/services/samgr/native/source/collect/common_event_collect.cpp index 305f9d5958d3ac75b29bf6e0b47b0fdb90659811..41594bccae53b56e9cc6d04887af64bb0327c0a6 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; }