diff --git a/services/samgr/native/include/collect/device_networking_collect.h b/services/samgr/native/include/collect/device_networking_collect.h index 3538ed96ff19ca10edbaddbbb61540b6bb3a1d3b..3836e4ec8f4c44faceb0397c7921a88db3cfc5cb 100644 --- a/services/samgr/native/include/collect/device_networking_collect.h +++ b/services/samgr/native/include/collect/device_networking_collect.h @@ -74,7 +74,7 @@ private: bool ReportMissedEvents(); }; -class WorkHandler { +class WorkHandler : public std::enable_shared_from_this { public: WorkHandler(const sptr& collect) : collect_(collect) { diff --git a/services/samgr/native/include/collect/device_param_collect.h b/services/samgr/native/include/collect/device_param_collect.h index 3441f4df6748537070c3a93198ccd3b484da4001..0ddf8cecd2faabc5b9c2864ae35298f5a5a7dc23 100644 --- a/services/samgr/native/include/collect/device_param_collect.h +++ b/services/samgr/native/include/collect/device_param_collect.h @@ -39,7 +39,8 @@ private: std::set params_; }; -class SystemAbilityStatusChange : public SystemAbilityStatusChangeStub { +class SystemAbilityStatusChange : public SystemAbilityStatusChangeStub, +public std::enable_shared_from_this { public: void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; diff --git a/services/samgr/native/include/collect/device_switch_collect.h b/services/samgr/native/include/collect/device_switch_collect.h index 5798d549753b18c7031660ec76edddf8361e71e7..c635ab47e9be3a665a950e0181ffd79ef0946be3 100644 --- a/services/samgr/native/include/collect/device_switch_collect.h +++ b/services/samgr/native/include/collect/device_switch_collect.h @@ -44,7 +44,8 @@ private: wptr deviceSwitchCollect_; }; -class CesStateListener : public SystemAbilityStatusChangeStub { +class CesStateListener : public SystemAbilityStatusChangeStub, +public std::enable_shared_from_this { public: CesStateListener(const sptr& deviceSwitchCollect) : deviceSwitchCollect_(deviceSwitchCollect) {}; diff --git a/services/samgr/native/source/collect/device_networking_collect.cpp b/services/samgr/native/source/collect/device_networking_collect.cpp index 97ad65b0f3c1f962189b8569faef50171ee29235..a49a592034dd6184497f133b2df6e4798b5c590c 100644 --- a/services/samgr/native/source/collect/device_networking_collect.cpp +++ b/services/samgr/native/source/collect/device_networking_collect.cpp @@ -293,7 +293,15 @@ void WorkHandler::ProcessEvent(uint32_t eventId) } if (!collect_->AddDeviceChangeListener()) { HILOGW("AddDeviceChangeListener retry"); - auto task = [this] {this->ProcessEvent(INIT_EVENT);}; + auto weak = weak_from_this(); + auto task = [weak] { + auto strong = weak.lock(); + if (!strong) { + HILOGE("WorkHandler ProcessEvent is null!"); + return; + } + strong->ProcessEvent(INIT_EVENT); + }; if (handler_ == nullptr) { HILOGE("NetworkingCollect ProcessEvent handler is null!"); return; @@ -308,7 +316,15 @@ bool WorkHandler::SendEvent(uint32_t eventId) HILOGE("NetworkingCollect SendEvent handler is null!"); return false; } - auto task = [this, eventId] {this->ProcessEvent(eventId);}; + auto weak = weak_from_this(); + auto task = [weak, eventId] { + auto strong = weak.lock(); + if (!strong) { + HILOGE("WorkHandler SendEvent is null!"); + return; + }; + strong->ProcessEvent(eventId); + }; return handler_->PostTask(task); } @@ -318,7 +334,15 @@ bool WorkHandler::SendEvent(uint32_t eventId, uint64_t delayTime) HILOGE("NetworkingCollect SendEvent handler is null!"); return false; } - auto task = [this, eventId] {this->ProcessEvent(eventId);}; + auto weak = weak_from_this(); + auto task = [weak, eventId] { + auto strong = weak.lock(); + if (!strong) { + HILOGE("WorkHandler SendEvent delay is null!"); + return; + }; + strong->ProcessEvent(eventId); + }; return handler_->PostTask(task, delayTime); } } // namespace OHOS diff --git a/services/samgr/native/source/collect/device_param_collect.cpp b/services/samgr/native/source/collect/device_param_collect.cpp index 1a89f822e65fb2ef860f27394a7c68852951d51c..fbe3bc59e1b75cebeda0d3a5711d8a11cb565da5 100644 --- a/services/samgr/native/source/collect/device_param_collect.cpp +++ b/services/samgr/native/source/collect/device_param_collect.cpp @@ -138,8 +138,13 @@ void SystemAbilityStatusChange::OnAddSystemAbility(int32_t systemAbilityId, cons HILOGE("DeviceParamCollect is nullptr"); return; } - auto task = [this] () { - deviceParamCollect_->WatchParameters(); + auto weak = weak_from_this(); + auto task = [weak] () { + auto strong = weak.lock(); + if (!strong) { + HILOGE("SystemAbilityStatusChange is null"); + } + strong->deviceParamCollect_->WatchParameters(); }; deviceParamCollect_->PostDelayTask(task, 0); break; diff --git a/services/samgr/native/source/collect/device_switch_collect.cpp b/services/samgr/native/source/collect/device_switch_collect.cpp index 69909ed6a979ecd1757553f4fddd2504e1e9fb77..7cbeb7ce522f9b9e28917e5cd620ee3db3b16707 100644 --- a/services/samgr/native/source/collect/device_switch_collect.cpp +++ b/services/samgr/native/source/collect/device_switch_collect.cpp @@ -131,8 +131,13 @@ void CesStateListener::OnAddSystemAbility(int32_t systemAbilityId, const std::st HILOGE("DeviceSwitchCollect switchEventSubscriber is nullptr"); return; } - auto task = [this] () { - auto deviceSwitchCollect = deviceSwitchCollect_.promote(); + auto weak = weak_from_this(); + auto task = [weak] () { + auto strong = weak.lock(); + if (!strong) { + HILOGE("CesStateListener is null"); + } + auto deviceSwitchCollect = strong->deviceSwitchCollect_.promote(); if (deviceSwitchCollect == nullptr) { HILOGE("DeviceSwitchCollect switchEventSubscriber is nullptr"); return; diff --git a/services/samgr/native/test/unittest/include/device_status_collect_manager_test.h b/services/samgr/native/test/unittest/include/device_status_collect_manager_test.h index b73f6b8e753e9a35776c14cbc4516208e23117fa..9807c41a5610231a48689cfaa770b81f7d2f5aed 100644 --- a/services/samgr/native/test/unittest/include/device_status_collect_manager_test.h +++ b/services/samgr/native/test/unittest/include/device_status_collect_manager_test.h @@ -24,7 +24,8 @@ #include "icollect_plugin.h" namespace OHOS { -class DeviceStatusCollectManagerTest : public testing::Test { +class DeviceStatusCollectManagerTest : public testing::Test, +public std::enable_shared_from_this { public: static void SetUpTestCase(); static void TearDownTestCase(); diff --git a/services/samgr/native/test/unittest/src/common_event_collect_test.cpp b/services/samgr/native/test/unittest/src/common_event_collect_test.cpp index e00077d593c9df04d941889ae86ecec0680b448e..481eafdffac6608ea3aa732f5754660477194cf3 100644 --- a/services/samgr/native/test/unittest/src/common_event_collect_test.cpp +++ b/services/samgr/native/test/unittest/src/common_event_collect_test.cpp @@ -68,6 +68,7 @@ HWTEST_F(CommonEventCollectTest, OnStart001, TestSize.Level3) sptr commonEventCollect = new CommonEventCollect(nullptr); int32_t ret = commonEventCollect->OnStart(); EXPECT_EQ(ERR_OK, ret); + DTEST_LOG << " OnStart001 END" << std::endl; } /** @@ -77,11 +78,12 @@ HWTEST_F(CommonEventCollectTest, OnStart001, TestSize.Level3) */ HWTEST_F(CommonEventCollectTest, OnStart002, TestSize.Level3) { - DTEST_LOG << " OnStart001 BEGIN" << std::endl; + DTEST_LOG << " OnStart002 BEGIN" << std::endl; sptr commonEventCollect = new CommonEventCollect(nullptr); commonEventCollect->commonEventNames_.insert("test"); int32_t ret = commonEventCollect->OnStart(); EXPECT_EQ(ERR_OK, ret); + DTEST_LOG << " OnStart002 END" << std::endl; } /** @@ -96,6 +98,7 @@ HWTEST_F(CommonEventCollectTest, OnStop001, TestSize.Level3) commonEventCollect->workHandler_ = std::make_shared(commonEventCollect); int32_t ret = commonEventCollect->OnStop(); EXPECT_EQ(ERR_OK, ret); + DTEST_LOG << " OnStop001 END" << std::endl; } /** @@ -110,6 +113,7 @@ HWTEST_F(CommonEventCollectTest, OnStop002, TestSize.Level3) commonEventCollect->workHandler_ = nullptr; int32_t ret = commonEventCollect->OnStop(); EXPECT_EQ(ERR_OK, ret); + DTEST_LOG << " OnStop002 END" << std::endl; } /** @@ -130,6 +134,7 @@ HWTEST_F(CommonEventCollectTest, init001, TestSize.Level3) commonEventCollect->workHandler_ = nullptr; int32_t ret = commonEventCollect->OnStop(); EXPECT_EQ(ERR_OK, ret); + DTEST_LOG << " init001 END" << std::endl; } /** @@ -255,6 +260,7 @@ HWTEST_F(CommonEventCollectTest, OnReceiveEvent001, TestSize.Level3) commonEventCollect->workHandler_ = nullptr; int32_t ret = commonEventCollect->OnStop(); EXPECT_EQ(ERR_OK, ret); + DTEST_LOG << " OnReceiveEvent001 END" << std::endl; } /** @@ -283,6 +289,7 @@ HWTEST_F(CommonEventCollectTest, AddCollectEvent001, TestSize.Level3) */ HWTEST_F(CommonEventCollectTest, RemoveUnusedEvent001, TestSize.Level3) { + DTEST_LOG << "RemoveUnusedEvent001 begin" << std::endl; sptr commonEventCollect = new CommonEventCollect(nullptr); OnDemandEvent event = {COMMON_EVENT, "", ""}; OnDemandEvent event1 = {COMMON_EVENT, "", ""}; @@ -291,6 +298,7 @@ HWTEST_F(CommonEventCollectTest, RemoveUnusedEvent001, TestSize.Level3) EXPECT_EQ(event1 == event2, false); int32_t ret = commonEventCollect->RemoveUnusedEvent(event); EXPECT_EQ(ret, ERR_OK); + DTEST_LOG << "RemoveUnusedEvent001 end" << std::endl; } /** @@ -301,11 +309,13 @@ HWTEST_F(CommonEventCollectTest, RemoveUnusedEvent001, TestSize.Level3) */ HWTEST_F(CommonEventCollectTest, RemoveUnusedEvent002, TestSize.Level3) { + DTEST_LOG << "RemoveUnusedEvent002 begin" << std::endl; sptr commonEventCollect = new CommonEventCollect(nullptr); commonEventCollect->commonEventNames_.insert("usual.event.SCREEN_ON"); OnDemandEvent event = {COMMON_EVENT, "usual.event.SCREEN_ON", ""}; commonEventCollect->RemoveUnusedEvent(event); EXPECT_EQ(commonEventCollect->commonEventNames_.size(), 0); + DTEST_LOG << "RemoveUnusedEvent002 end" << std::endl; } /** @@ -316,12 +326,14 @@ HWTEST_F(CommonEventCollectTest, RemoveUnusedEvent002, TestSize.Level3) */ HWTEST_F(CommonEventCollectTest, SaveOnDemandReasonExtraData001, TestSize.Level3) { + DTEST_LOG << "SaveOnDemandReasonExtraData001 begin" << std::endl; sptr collect = new DeviceStatusCollectManager(); sptr commonEventCollect = new CommonEventCollect(collect); commonEventCollect->workHandler_ = std::make_shared(commonEventCollect); EventFwk::CommonEventData eventData; int64_t ret = commonEventCollect->SaveOnDemandReasonExtraData(eventData); EXPECT_EQ(ret, 1); + DTEST_LOG << "SaveOnDemandReasonExtraData001 end" << std::endl; } /** @@ -374,6 +386,7 @@ HWTEST_F(CommonEventCollectTest, SaveOnDemandReasonExtraData002, TestSize.Level3 */ HWTEST_F(CommonEventCollectTest, RemoveOnDemandReasonExtraData001, TestSize.Level3) { + DTEST_LOG << "RemoveOnDemandReasonExtraData001 begin" << std::endl; sptr collect = new DeviceStatusCollectManager(); sptr commonEventCollect = new CommonEventCollect(collect); commonEventCollect->workHandler_ = std::make_shared(commonEventCollect); @@ -382,6 +395,7 @@ HWTEST_F(CommonEventCollectTest, RemoveOnDemandReasonExtraData001, TestSize.Leve commonEventCollect->SaveOnDemandReasonExtraData(eventData); commonEventCollect->RemoveOnDemandReasonExtraData(1); EXPECT_TRUE(commonEventCollect->extraDatas_.empty()); + DTEST_LOG << "RemoveOnDemandReasonExtraData001 end" << std::endl; } /** @@ -392,6 +406,7 @@ HWTEST_F(CommonEventCollectTest, RemoveOnDemandReasonExtraData001, TestSize.Leve */ HWTEST_F(CommonEventCollectTest, GetOnDemandReasonExtraData001, TestSize.Level3) { + DTEST_LOG << "GetOnDemandReasonExtraData001 begin" << std::endl; sptr collect = new DeviceStatusCollectManager(); sptr commonEventCollect = new CommonEventCollect(collect); commonEventCollect->workHandler_ = std::make_shared(commonEventCollect); @@ -399,6 +414,7 @@ HWTEST_F(CommonEventCollectTest, GetOnDemandReasonExtraData001, TestSize.Level3) OnDemandReasonExtraData onDemandReasonExtraData; bool ret = commonEventCollect->GetOnDemandReasonExtraData(1, onDemandReasonExtraData); EXPECT_FALSE(ret); + DTEST_LOG << "GetOnDemandReasonExtraData001 end" << std::endl; } /** @@ -409,6 +425,7 @@ HWTEST_F(CommonEventCollectTest, GetOnDemandReasonExtraData001, TestSize.Level3) */ HWTEST_F(CommonEventCollectTest, GetOnDemandReasonExtraData002, TestSize.Level3) { + DTEST_LOG << "GetOnDemandReasonExtraData002 begin" << std::endl; sptr collect = new DeviceStatusCollectManager(); sptr commonEventCollect = new CommonEventCollect(collect); commonEventCollect->workHandler_ = std::make_shared(commonEventCollect); @@ -418,6 +435,7 @@ HWTEST_F(CommonEventCollectTest, GetOnDemandReasonExtraData002, TestSize.Level3) commonEventCollect->SaveOnDemandReasonExtraData(eventData); bool ret = commonEventCollect->GetOnDemandReasonExtraData(1, onDemandReasonExtraData); EXPECT_TRUE(ret); + DTEST_LOG << "GetOnDemandReasonExtraData002 end" << std::endl; } /** @@ -427,6 +445,7 @@ HWTEST_F(CommonEventCollectTest, GetOnDemandReasonExtraData002, TestSize.Level3) */ HWTEST_F(CommonEventCollectTest, InitCommonEventState001, TestSize.Level3) { + DTEST_LOG << "InitCommonEventState001 begin" << std::endl; sptr collect = new DeviceStatusCollectManager(); sptr commonEventCollect = new CommonEventCollect(collect); commonEventCollect->workHandler_ = std::make_shared(commonEventCollect); @@ -438,6 +457,7 @@ HWTEST_F(CommonEventCollectTest, InitCommonEventState001, TestSize.Level3) OnDemandEvent event = {COMMON_EVENT, "1", "", -1, false, conditions, false, 3, extraMessages}; commonEventCollect->InitCommonEventState(event); EXPECT_EQ(commonEventCollect->commonEventNames_.size(), 1); + DTEST_LOG << "InitCommonEventState001 end" << std::endl; } /** @@ -447,6 +467,7 @@ HWTEST_F(CommonEventCollectTest, InitCommonEventState001, TestSize.Level3) */ HWTEST_F(CommonEventCollectTest, InitCommonEventState002, TestSize.Level3) { + DTEST_LOG << "InitCommonEventState002 begin" << std::endl; sptr collect = new DeviceStatusCollectManager(); sptr commonEventCollect = new CommonEventCollect(collect); commonEventCollect->workHandler_ = std::make_shared(commonEventCollect); @@ -465,6 +486,7 @@ HWTEST_F(CommonEventCollectTest, InitCommonEventState002, TestSize.Level3) commonEventCollect->InitCommonEventState(event); EXPECT_EQ(commonEventCollect->commonEventNames_.size(), 2); EXPECT_EQ(commonEventCollect->commonEventConditionExtraData_["1"].size(), 1); + DTEST_LOG << "InitCommonEventState002 end" << std::endl; } /** @@ -474,6 +496,7 @@ HWTEST_F(CommonEventCollectTest, InitCommonEventState002, TestSize.Level3) */ HWTEST_F(CommonEventCollectTest, GetParamFromWant001, TestSize.Level3) { + DTEST_LOG << "GetParamFromWant001 begin" << std::endl; sptr collect = new DeviceStatusCollectManager(); sptr commonEventCollect = new CommonEventCollect(collect); commonEventCollect->workHandler_ = std::make_shared(commonEventCollect); @@ -488,6 +511,7 @@ HWTEST_F(CommonEventCollectTest, GetParamFromWant001, TestSize.Level3) EXPECT_EQ(commonEventCollect->GetParamFromWant("2", want), "2"); EXPECT_EQ(commonEventCollect->GetParamFromWant("3", want), "3"); EXPECT_EQ(commonEventCollect->GetParamFromWant("4", want), ""); + DTEST_LOG << "GetParamFromWant001 end" << std::endl; } /** @@ -498,6 +522,7 @@ HWTEST_F(CommonEventCollectTest, GetParamFromWant001, TestSize.Level3) */ HWTEST_F(CommonEventCollectTest, GetExtraDataIdlist001, TestSize.Level3) { + DTEST_LOG << "GetExtraDataIdlist001 begin" << std::endl; sptr collect = new DeviceStatusCollectManager(); sptr commonEventCollect = new CommonEventCollect(collect); commonEventCollect->workHandler_ = std::make_shared(commonEventCollect); @@ -536,6 +561,7 @@ HWTEST_F(CommonEventCollectTest, GetExtraDataIdlist001, TestSize.Level3) EXPECT_EQ(extraDataIdList.size(), 1); commonEventCollect->extraDatas_.clear(); commonEventCollect->saExtraDataIdMap_.clear(); + DTEST_LOG << "GetExtraDataIdlist001 end" << std::endl; } /** @@ -546,6 +572,7 @@ HWTEST_F(CommonEventCollectTest, GetExtraDataIdlist001, TestSize.Level3) */ HWTEST_F(CommonEventCollectTest, GetExtraDataIdlist002, TestSize.Level3) { + DTEST_LOG << "GetExtraDataIdlist002 begin" << std::endl; sptr collect = new DeviceStatusCollectManager(); sptr commonEventCollect = new CommonEventCollect(collect); commonEventCollect->workHandler_ = std::make_shared(commonEventCollect); @@ -590,6 +617,7 @@ HWTEST_F(CommonEventCollectTest, GetExtraDataIdlist002, TestSize.Level3) EXPECT_EQ(extraDataIdList.size(), 1); commonEventCollect->extraDatas_.clear(); commonEventCollect->saExtraDataIdMap_.clear(); + DTEST_LOG << "GetExtraDataIdlist002 end" << std::endl; } /** @@ -599,6 +627,7 @@ HWTEST_F(CommonEventCollectTest, GetExtraDataIdlist002, TestSize.Level3) */ HWTEST_F(CommonEventCollectTest, CheckCondition001, TestSize.Level3) { + DTEST_LOG << " CheckCondition001 BEGIN" << std::endl; sptr collect = new DeviceStatusCollectManager(); sptr commonEventCollect = new CommonEventCollect(collect); commonEventCollect->workHandler_ = std::make_shared(commonEventCollect); @@ -620,6 +649,7 @@ HWTEST_F(CommonEventCollectTest, CheckCondition001, TestSize.Level3) */ HWTEST_F(CommonEventCollectTest, CheckCondition002, TestSize.Level3) { + DTEST_LOG << " CheckCondition002 BEGIN" << std::endl; sptr collect = new DeviceStatusCollectManager(); sptr commonEventCollect = new CommonEventCollect(collect); commonEventCollect->workHandler_ = std::make_shared(commonEventCollect); @@ -642,6 +672,7 @@ HWTEST_F(CommonEventCollectTest, CheckCondition002, TestSize.Level3) */ HWTEST_F(CommonEventCollectTest, CheckCondition003, TestSize.Level3) { + DTEST_LOG << " CheckCondition003 BEGIN" << std::endl; sptr collect = new DeviceStatusCollectManager(); sptr commonEventCollect = new CommonEventCollect(collect); commonEventCollect->workHandler_ = std::make_shared(commonEventCollect); @@ -664,6 +695,7 @@ HWTEST_F(CommonEventCollectTest, CheckCondition003, TestSize.Level3) */ HWTEST_F(CommonEventCollectTest, CheckCondition004, TestSize.Level3) { + DTEST_LOG << " CheckCondition004 BEGIN" << std::endl; sptr collect = new DeviceStatusCollectManager(); sptr commonEventCollect = new CommonEventCollect(collect); commonEventCollect->workHandler_ = std::make_shared(commonEventCollect); @@ -685,6 +717,7 @@ HWTEST_F(CommonEventCollectTest, CheckCondition004, TestSize.Level3) */ HWTEST_F(CommonEventCollectTest, CheckExtraMessage001, TestSize.Level3) { + DTEST_LOG << " CheckExtraMessages001 BEGIN" << std::endl; sptr collect = new DeviceStatusCollectManager(); sptr commonEventCollect = new CommonEventCollect(collect); commonEventCollect->workHandler_ = std::make_shared(commonEventCollect); @@ -710,6 +743,7 @@ HWTEST_F(CommonEventCollectTest, CheckExtraMessage001, TestSize.Level3) */ HWTEST_F(CommonEventCollectTest, CheckExtraMessage002, TestSize.Level3) { + DTEST_LOG << " CheckExtraMessages002 BEGIN" << std::endl; sptr collect = new DeviceStatusCollectManager(); sptr commonEventCollect = new CommonEventCollect(collect); commonEventCollect->workHandler_ = std::make_shared(commonEventCollect); @@ -735,6 +769,7 @@ HWTEST_F(CommonEventCollectTest, CheckExtraMessage002, TestSize.Level3) */ HWTEST_F(CommonEventCollectTest, CheckExtraMessage003, TestSize.Level3) { + DTEST_LOG << " CheckExtraMessages003 BEGIN" << std::endl; sptr collect = new DeviceStatusCollectManager(); sptr commonEventCollect = new CommonEventCollect(collect); commonEventCollect->workHandler_ = std::make_shared(commonEventCollect); @@ -760,6 +795,7 @@ HWTEST_F(CommonEventCollectTest, CheckExtraMessage003, TestSize.Level3) */ HWTEST_F(CommonEventCollectTest, SaveOnDemandConditionExtraData001, TestSize.Level3) { + DTEST_LOG << " SaveOnDemandConditionExtraData001 BEGIN" << std::endl; sptr collect = new DeviceStatusCollectManager(); sptr commonEventCollect = new CommonEventCollect(collect); commonEventCollect->workHandler_ = std::make_shared(commonEventCollect); @@ -784,6 +820,7 @@ HWTEST_F(CommonEventCollectTest, SaveOnDemandConditionExtraData001, TestSize.Lev */ HWTEST_F(CommonEventCollectTest, RemoveWhiteCommonEvent001, TestSize.Level3) { + DTEST_LOG << " RemoveWhiteCommonEvent001 BEGIN" << std::endl; sptr collect = new DeviceStatusCollectManager(); sptr commonEventCollect = new CommonEventCollect(collect); commonEventCollect->RemoveWhiteCommonEvent(); @@ -798,6 +835,7 @@ HWTEST_F(CommonEventCollectTest, RemoveWhiteCommonEvent001, TestSize.Level3) */ HWTEST_F(CommonEventCollectTest, CleanFailedEventLocked001, TestSize.Level3) { + DTEST_LOG << " CleanFailedEventLocked001 BEGIN" << std::endl; sptr collect = new DeviceStatusCollectManager(); sptr commonEventCollect = new CommonEventCollect(collect); EventFwk::MatchingSkills skill = EventFwk::MatchingSkills(); @@ -819,6 +857,7 @@ HWTEST_F(CommonEventCollectTest, CleanFailedEventLocked001, TestSize.Level3) */ HWTEST_F(CommonEventCollectTest, OnRemoveSystemAbility001, TestSize.Level3) { + DTEST_LOG << " OnRemoveSystemAbility001 BEGIN" << std::endl; sptr collect = new DeviceStatusCollectManager(); sptr commonEventCollect = new CommonEventCollect(collect); sptr commonEventListener = new CommonEventListener(commonEventCollect); diff --git a/services/samgr/native/test/unittest/src/device_status_collect_manager_test.cpp b/services/samgr/native/test/unittest/src/device_status_collect_manager_test.cpp index c24703ec4710ec36e0978385defda9c8a0701871..bf6e771afb5b18683f48726913f7f4fd21a3f99e 100644 --- a/services/samgr/native/test/unittest/src/device_status_collect_manager_test.cpp +++ b/services/samgr/native/test/unittest/src/device_status_collect_manager_test.cpp @@ -77,10 +77,16 @@ void DeviceStatusCollectManagerTest::PostTask( std::shared_ptr& collectHandler) { isCaseDone = false; - auto caseDoneNotifyTask = [this]() { - std::lock_guard autoLock(caseDoneLock_); - isCaseDone = true; - caseDoneCondition_.notify_one(); + auto weak = weak_from_this(); + auto caseDoneNotifyTask = [weak]() { + auto strong = weak.lock(); + std::lock_guard autoLock(strong->caseDoneLock_); + if (!strong) { + DTEST_LOG << "DeviceStatusCollectManagerTest is null!" << std::endl; + return; + }; + strong->isCaseDone = true; + strong->caseDoneCondition_.notify_one(); }; if (collectHandler != nullptr) { collectHandler->PostTask(caseDoneNotifyTask);