diff --git a/services/samgr/native/include/system_ability_manager.h b/services/samgr/native/include/system_ability_manager.h index b18a6001d612b323b060f4be7dc1e63b98628e9b..52db01e58be42d042d66afe9d236f4e6e3c02461 100644 --- a/services/samgr/native/include/system_ability_manager.h +++ b/services/samgr/native/include/system_ability_manager.h @@ -210,6 +210,7 @@ private: void CheckListenerNotify(int32_t systemAbilityId, const sptr& listener); void NotifySystemAbilityChanged(int32_t systemAbilityId, const std::string& deviceId, int32_t code, const sptr& listener); + void NotifySystemAbilityAddedByAsync(int32_t systemAbilityId, const sptr& listener); void UnSubscribeSystemAbilityLocked(std::list& listenerList, const sptr& listener); diff --git a/services/samgr/native/source/schedule/system_ability_state_scheduler.cpp b/services/samgr/native/source/schedule/system_ability_state_scheduler.cpp index 4cce71da6a888ef6a20019ec9bd6836aae26cef9..f5dc4cb7527dfde6a270e430e713d8afa1468d8c 100644 --- a/services/samgr/native/source/schedule/system_ability_state_scheduler.cpp +++ b/services/samgr/native/source/schedule/system_ability_state_scheduler.cpp @@ -181,10 +181,10 @@ void SystemAbilityStateScheduler::UpdateLimitDelayUnloadTime(int32_t systemAbili HILOGE("UpdateLimitDelayUnloadTime process handler not init"); return; } - auto UpdateDelayUnloadTimeTask = [systemAbilityId, this]() { + auto updateDelayUnloadTimeTask = [systemAbilityId, this]() { UpdateLimitDelayUnloadTimeTask(systemAbilityId); }; - bool ret = processHandler_->PostTask(UpdateDelayUnloadTimeTask); + bool ret = processHandler_->PostTask(updateDelayUnloadTimeTask); if (!ret) { HILOGW("UpdateLimitDelayUnloadTime PostTask fail"); } diff --git a/services/samgr/native/source/system_ability_manager.cpp b/services/samgr/native/source/system_ability_manager.cpp index 1f5de27de92284e17f694633e297ffa711115b2b..667323dca3a5fae5592783b0b665fea892eaf0c5 100644 --- a/services/samgr/native/source/system_ability_manager.cpp +++ b/services/samgr/native/source/system_ability_manager.cpp @@ -906,6 +906,23 @@ vector SystemAbilityManager::ListSystemAbilities(uint32_t dumpFlags) return list; } +void SystemAbilityManager::NotifySystemAbilityAddedByAsync(int32_t systemAbilityId, + const sptr& listener) +{ + if (workHandler_ == nullptr) { + HILOGE("NotifySystemAbilityAddedByAsync workHandler is nullptr"); + return; + } else { + auto listenerNotifyTask = [systemAbilityId, listener, this]() { + NotifySystemAbilityChanged(systemAbilityId, "", + static_cast(SamgrInterfaceCode::ADD_SYSTEM_ABILITY_TRANSACTION), listener); + }; + if (!workHandler_->PostTask(listenerNotifyTask)) { + HILOGE("NotifySystemAbilityAddedByAsync PostTask fail SA:%{public}d", systemAbilityId); + } + } +} + void SystemAbilityManager::CheckListenerNotify(int32_t systemAbilityId, const sptr& listener) { @@ -921,8 +938,7 @@ void SystemAbilityManager::CheckListenerNotify(int32_t systemAbilityId, if (itemListener.state == ListenerState::INIT) { HILOGI("NotifyAddSA:%{public}d,%{public}d_%{public}d", systemAbilityId, callingPid, subscribeCountMap_[callingPid]); - NotifySystemAbilityChanged(systemAbilityId, "", - static_cast(SamgrInterfaceCode::ADD_SYSTEM_ABILITY_TRANSACTION), listener); + NotifySystemAbilityAddedByAsync(systemAbilityId, listener); itemListener.state = ListenerState::NOTIFIED; } else { HILOGI("Subscribe Listener has been notified,SA:%{public}d,callpid:%{public}d", @@ -1384,7 +1400,16 @@ void SystemAbilityManager::CleanCallbackForLoadFailed(int32_t systemAbilityId, c auto& abilityItem = iter->second; for (auto& callbackItem : abilityItem.callbackMap[srcDeviceId]) { if (callback->AsObject() == callbackItem.first->AsObject()) { - NotifySystemAbilityLoadFail(systemAbilityId, callbackItem.first); + if (workHandler_ == nullptr) { + HILOGE("CleanCallbackForLoadFailed workHandler is nullptr"); + return; + } + auto listenerNotifyTask = [systemAbilityId, callbackItem, this]() { + NotifySystemAbilityLoadFail(systemAbilityId, callbackItem.first); + }; + if (!workHandler_->PostTask(listenerNotifyTask)) { + HILOGE("Send NotifySaLoadFailMsg PostTask fail"); + } RemoveStartingAbilityCallbackLocked(callbackItem); abilityItem.callbackMap[srcDeviceId].remove(callbackItem); break; @@ -1600,7 +1625,7 @@ int32_t SystemAbilityManager::DoLoadSystemAbility(int32_t systemAbilityId, const return ERR_OK; } HILOGI("DoLoadSA SA:%{public}d notify callpid:%{public}d!", systemAbilityId, callingPid); - NotifySystemAbilityLoaded(systemAbilityId, targetObject, callback); + SendLoadedSystemAbilityMsg(systemAbilityId, targetObject, callback); return ERR_OK; } int32_t result = ERR_INVALID_VALUE; diff --git a/services/samgr/native/source/system_ability_manager_stub.cpp b/services/samgr/native/source/system_ability_manager_stub.cpp index dab914f33b1a18a8b710f92ee7d9bf2d0184c3f7..597a0591b07f29d7d49d59edcbeb5ff9a70beb69 100644 --- a/services/samgr/native/source/system_ability_manager_stub.cpp +++ b/services/samgr/native/source/system_ability_manager_stub.cpp @@ -1085,7 +1085,7 @@ bool SystemAbilityManagerStub::CanRequest() { auto tid = IPCSkeleton::GetCallingTokenID(); AccessToken::ATokenTypeEnum tokenType = AccessToken::AccessTokenKit::GetTokenTypeFlag(tid); - HILOGD("CanRequest tid:%{private}u, tokenType:%{public}d", + HILOGD("CanRequest callingTkid:%{private}u, tokenType:%{public}d", tid, tokenType); return (tokenType == AccessToken::ATokenTypeEnum::TOKEN_NATIVE); } diff --git a/services/samgr/native/test/unittest/src/device_switch_collect_test.cpp b/services/samgr/native/test/unittest/src/device_switch_collect_test.cpp index ded0be5ad77b0cc15596901d4c0b574d6a7bd4e2..986e9bcc66440060cac10e5608018141c9ce151a 100644 --- a/services/samgr/native/test/unittest/src/device_switch_collect_test.cpp +++ b/services/samgr/native/test/unittest/src/device_switch_collect_test.cpp @@ -205,6 +205,8 @@ HWTEST_F(DeviceSwitchCollectTest, OnStart001, TestSize.Level3) sptr collect = new DeviceStatusCollectManager(); sptr deviceSwitchCollect = new DeviceSwitchCollect(collect); + sptr saMgr = SystemAbilityManager::GetInstance(); + saMgr->workHandler_ = make_shared("workHandler"); deviceSwitchCollect->needListenSwitchEvent_ = false; int32_t ret = deviceSwitchCollect->OnStart(); EXPECT_EQ(ret, ERR_OK); @@ -224,7 +226,9 @@ HWTEST_F(DeviceSwitchCollectTest, OnStart002, TestSize.Level3) new DeviceSwitchCollect(collect); deviceSwitchCollect->InitCommonEventSubscriber(); deviceSwitchCollect->needListenSwitchEvent_ = true; - SystemAbilityManager::GetInstance()->subscribeCountMap_.clear(); + sptr saMgr = SystemAbilityManager::GetInstance(); + saMgr->workHandler_ = make_shared("workHandler"); + saMgr->subscribeCountMap_.clear(); int32_t ret = deviceSwitchCollect->OnStart(); EXPECT_EQ(ret, ERR_OK); } diff --git a/services/samgr/native/test/unittest/src/system_ability_mgr_stub_test.cpp b/services/samgr/native/test/unittest/src/system_ability_mgr_stub_test.cpp index 058035c20277db71f61536d7b8bea600251e7593..011b29115f37b88c338c7b86152aa28520971654 100644 --- a/services/samgr/native/test/unittest/src/system_ability_mgr_stub_test.cpp +++ b/services/samgr/native/test/unittest/src/system_ability_mgr_stub_test.cpp @@ -494,6 +494,7 @@ HWTEST_F(SystemAbilityMgrStubTest, SubsSystemAbilityInner004, TestSize.Level1) sptr testAbility(new SaStatusChangeMock()); SAInfo saInfo; saMgr->abilityMap_[SAID] = saInfo; + saMgr->workHandler_ = make_shared("workHandler"); EXPECT_TRUE(saMgr != nullptr); MessageParcel data; MessageParcel reply; @@ -1937,6 +1938,7 @@ HWTEST_F(SystemAbilityMgrStubTest, AddSystemAbility004, TestSize.Level3) HWTEST_F(SystemAbilityMgrStubTest, AddSystemAbility005, TestSize.Level3) { sptr saMgr = SystemAbilityManager::GetInstance(); + saMgr->workHandler_ = make_shared("workHandler"); sptr testAbility(new SaStatusChangeMock()); SystemAbilityManager::SAExtraProp extraProp; saMgr->dBinderService_ = nullptr; @@ -1960,6 +1962,7 @@ HWTEST_F(SystemAbilityMgrStubTest, AddSystemAbility005, TestSize.Level3) HWTEST_F(SystemAbilityMgrStubTest, AddSystemAbility006, TestSize.Level3) { sptr saMgr = SystemAbilityManager::GetInstance(); + saMgr->workHandler_ = make_shared("workHandler"); sptr testAbility(new SaStatusChangeMock()); SystemAbilityManager::SAExtraProp extraProp; saMgr->rpcCallbackImp_ = nullptr; @@ -1984,6 +1987,7 @@ HWTEST_F(SystemAbilityMgrStubTest, AddSystemAbility006, TestSize.Level3) HWTEST_F(SystemAbilityMgrStubTest, AddSystemProcess001, TestSize.Level1) { sptr saMgr = SystemAbilityManager::GetInstance(); + saMgr->workHandler_ = make_shared("workHandler"); sptr testAbility(new SaStatusChangeMock()); u16string procName = u""; int32_t res = saMgr->AddSystemProcess(procName, testAbility); @@ -2008,6 +2012,7 @@ HWTEST_F(SystemAbilityMgrStubTest, AddSystemProcess001, TestSize.Level1) HWTEST_F(SystemAbilityMgrStubTest, AddSystemProcess002, TestSize.Level1) { sptr saMgr = SystemAbilityManager::GetInstance(); + saMgr->workHandler_ = make_shared("workHandler"); sptr testAbility(nullptr); u16string procName = u"proname"; int32_t res = saMgr->AddSystemProcess(procName, testAbility); @@ -2034,6 +2039,7 @@ HWTEST_F(SystemAbilityMgrStubTest, AddSystemProcess002, TestSize.Level1) HWTEST_F(SystemAbilityMgrStubTest, RemoveSystemProcess001, TestSize.Level1) { sptr saMgr = SystemAbilityManager::GetInstance(); + saMgr->workHandler_ = make_shared("workHandler"); sptr testAbility(nullptr); int32_t res = saMgr->RemoveSystemProcess(testAbility); saMgr->NotifySystemAbilityLoadFail(SAID, nullptr);