From 2ff03686d22f7bb51b2572e161d2e1ea015ee072 Mon Sep 17 00:00:00 2001 From: dy_study Date: Thu, 17 Nov 2022 17:32:41 +0800 Subject: [PATCH] =?UTF-8?q?IssueNo:#I61QHA=20Description:=E6=96=B0?= =?UTF-8?q?=E5=A2=9EAppMgrServiceInner=20TDD=20Sig:SIG=5FApplicationFramew?= =?UTF-8?q?ork=20Feature=20or=20Bugfix:Bugfix=20Binary=20Source:=20No?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: dy_study Change-Id: I3853aeef2d14f6b7540413308ddcf28d40ef3b97 --- services/appmgr/src/app_mgr_service_inner.cpp | 43 + services/appmgr/src/app_running_record.cpp | 6 + .../appmgr/src/app_state_observer_manager.cpp | 35 + .../app_mgr_service_inner_test/BUILD.gn | 7 +- .../app_mgr_service_inner_test.cpp | 1146 ++++++++++++++++- 5 files changed, 1235 insertions(+), 2 deletions(-) diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index 058a052bf6..024fcf4667 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -855,10 +855,12 @@ std::shared_ptr AppMgrServiceInner::CreateAppRunningRecord(con { HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__); if (!appRunningManager_) { + HILOG_ERROR("appRunningManager nullptr!"); return nullptr; } auto appRecord = appRunningManager_->CreateAppRunningRecord(appInfo, processName, bundleInfo); if (!appRecord) { + HILOG_ERROR("get app record failed"); return nullptr; } @@ -971,12 +973,22 @@ void AppMgrServiceInner::UpdateExtensionState(const sptr &token, void AppMgrServiceInner::OnStop() { + if (!appRunningManager_) { + HILOG_ERROR("appRunningManager nullptr!"); + return; + } + appRunningManager_->ClearAppRunningRecordMap(); CloseAppSpawnConnection(); } ErrCode AppMgrServiceInner::OpenAppSpawnConnection() { + if (remoteClientManager_ == nullptr) { + HILOG_ERROR("remoteClientManager_ is null"); + return ERR_INVALID_VALUE; + } + if (remoteClientManager_->GetSpawnClient()) { return remoteClientManager_->GetSpawnClient()->OpenConnection(); } @@ -985,6 +997,11 @@ ErrCode AppMgrServiceInner::OpenAppSpawnConnection() void AppMgrServiceInner::CloseAppSpawnConnection() const { + if (remoteClientManager_ == nullptr) { + HILOG_ERROR("remoteClientManager_ is null"); + return; + } + if (remoteClientManager_->GetSpawnClient()) { remoteClientManager_->GetSpawnClient()->CloseConnection(); } @@ -992,6 +1009,11 @@ void AppMgrServiceInner::CloseAppSpawnConnection() const SpawnConnectionState AppMgrServiceInner::QueryAppSpawnConnectionState() const { + if (remoteClientManager_ == nullptr) { + HILOG_ERROR("remoteClientManager_ is null"); + return SpawnConnectionState::STATE_NOT_CONNECT; + } + if (remoteClientManager_->GetSpawnClient()) { return remoteClientManager_->GetSpawnClient()->QueryConnectionState(); } @@ -1000,16 +1022,32 @@ SpawnConnectionState AppMgrServiceInner::QueryAppSpawnConnectionState() const std::map> AppMgrServiceInner::GetRecordMap() const { + if (!appRunningManager_) { + HILOG_ERROR("appRunningManager nullptr!"); + std::map> appRunningRecordMap; + return appRunningRecordMap; + } + return appRunningManager_->GetAppRunningRecordMap(); } void AppMgrServiceInner::SetAppSpawnClient(std::shared_ptr spawnClient) { + if (remoteClientManager_ == nullptr) { + HILOG_ERROR("remoteClientManager_ is null"); + return; + } + remoteClientManager_->SetSpawnClient(std::move(spawnClient)); } void AppMgrServiceInner::SetBundleManager(sptr bundleManager) { + if (remoteClientManager_ == nullptr) { + HILOG_ERROR("remoteClientManager_ is null"); + return; + } + remoteClientManager_->SetBundleManager(bundleManager); } @@ -1179,6 +1217,11 @@ void AppMgrServiceInner::StartAbility(const sptr &token, const sp std::shared_ptr AppMgrServiceInner::GetAppRunningRecordByAbilityToken( const sptr &abilityToken) const { + if (!appRunningManager_) { + HILOG_ERROR("appRunningManager_ is nullptr"); + return nullptr; + } + return appRunningManager_->GetAppRunningRecordByAbilityToken(abilityToken); } diff --git a/services/appmgr/src/app_running_record.cpp b/services/appmgr/src/app_running_record.cpp index 2c638ca1b3..60145fd00a 100644 --- a/services/appmgr/src/app_running_record.cpp +++ b/services/appmgr/src/app_running_record.cpp @@ -409,6 +409,12 @@ void AppRunningRecord::AddAbilityStageDone() { HILOG_INFO("Add ability stage done. bundle %{public}s and eventId %{public}d", mainBundleName_.c_str(), static_cast(eventId_)); + + if (!eventHandler_) { + HILOG_ERROR("eventHandler_ is nullptr"); + return; + } + if (eventHandler_->HasInnerEvent(AMSEventHandler::START_PROCESS_SPECIFIED_ABILITY_TIMEOUT_MSG)) { eventHandler_->RemoveEvent(AMSEventHandler::START_PROCESS_SPECIFIED_ABILITY_TIMEOUT_MSG); } diff --git a/services/appmgr/src/app_state_observer_manager.cpp b/services/appmgr/src/app_state_observer_manager.cpp index eac69507ac..2a58e0eae6 100644 --- a/services/appmgr/src/app_state_observer_manager.cpp +++ b/services/appmgr/src/app_state_observer_manager.cpp @@ -95,6 +95,11 @@ int32_t AppStateObserverManager::UnregisterApplicationStateObserver(const sptr &appRecord, const ApplicationState state, bool needNotifyApp) { + if (handler_ == nullptr) { + HILOG_ERROR("handler is nullptr, OnAppStateChanged failed."); + return; + } + auto task = [weak = weak_from_this(), appRecord, state, needNotifyApp]() { auto self = weak.lock(); if (self == nullptr) { @@ -109,6 +114,11 @@ void AppStateObserverManager::OnAppStateChanged( void AppStateObserverManager::OnProcessDied(const std::shared_ptr &appRecord) { + if (handler_ == nullptr) { + HILOG_ERROR("handler is nullptr, OnProcessDied failed."); + return; + } + auto task = [weak = weak_from_this(), appRecord]() { auto self = weak.lock(); if (self == nullptr) { @@ -123,6 +133,11 @@ void AppStateObserverManager::OnProcessDied(const std::shared_ptr &renderRecord) { + if (handler_ == nullptr) { + HILOG_ERROR("handler is nullptr, OnRenderProcessDied failed."); + return; + } + auto task = [weak = weak_from_this(), renderRecord]() { auto self = weak.lock(); if (self == nullptr) { @@ -137,6 +152,11 @@ void AppStateObserverManager::OnRenderProcessDied(const std::shared_ptr &appRecord) { + if (handler_ == nullptr) { + HILOG_ERROR("handler is nullptr, OnProcessStateChanged failed."); + return; + } + auto task = [weak = weak_from_this(), appRecord]() { auto self = weak.lock(); if (self == nullptr) { @@ -151,6 +171,11 @@ void AppStateObserverManager::OnProcessStateChanged(const std::shared_ptr &appRecord) { + if (handler_ == nullptr) { + HILOG_ERROR("handler is nullptr, OnProcessCreated failed."); + return; + } + auto task = [weak = weak_from_this(), appRecord]() { auto self = weak.lock(); if (self == nullptr) { @@ -165,6 +190,11 @@ void AppStateObserverManager::OnProcessCreated(const std::shared_ptr &renderRecord) { + if (handler_ == nullptr) { + HILOG_ERROR("handler is nullptr, OnRenderProcessCreated failed."); + return; + } + auto task = [weak = weak_from_this(), renderRecord]() { auto self = weak.lock(); if (self == nullptr) { @@ -179,6 +209,11 @@ void AppStateObserverManager::OnRenderProcessCreated(const std::shared_ptr abilityInfo_; + std::shared_ptr applicationInfo_; }; +void AppMgrServiceInnerTest::InitAppInfo(const std::string &deviceName, + const std::string &abilityName, const std::string &appName, const std::string &bundleName, + const std::string &moduleName) +{ + ApplicationInfo applicationInfo; + applicationInfo.name = appName; + applicationInfo.bundleName = bundleName; + applicationInfo_ = std::make_shared(applicationInfo); + + AbilityInfo abilityInfo; + abilityInfo.visible = true; + abilityInfo.applicationName = appName; + abilityInfo.type = AbilityType::EXTENSION; + abilityInfo.name = abilityName; + abilityInfo.bundleName = bundleName; + abilityInfo.moduleName = moduleName; + abilityInfo.deviceId = deviceName; + abilityInfo_ = std::make_shared(abilityInfo); +} + void AppMgrServiceInnerTest::SetUpTestCase(void) { MockNativeToken::SetNativeToken(); @@ -44,7 +74,15 @@ void AppMgrServiceInnerTest::TearDownTestCase(void) {} void AppMgrServiceInnerTest::SetUp() -{} +{ + // init test app info + std::string deviceName = "device"; + std::string abilityName = "ServiceAbility"; + std::string appName = "hiservcie"; + std::string bundleName = "com.ix.hiservcie"; + std::string moduleName = "entry"; + InitAppInfo(deviceName, abilityName, appName, bundleName, moduleName); +} void AppMgrServiceInnerTest::TearDown() {} @@ -209,5 +247,1111 @@ HWTEST_F(AppMgrServiceInnerTest, PreStartNWebSpawnProcess_002, TestSize.Level0) int ret = appMgrServiceInner->PreStartNWebSpawnProcess(callingPid); EXPECT_EQ(ret, ERR_INVALID_VALUE); } + +/** + * @tc.name: LoadAbility_001 + * @tc.desc: load ability. + * @tc.type: FUNC + * @tc.require: issueI5W4S7 + */ +HWTEST_F(AppMgrServiceInnerTest, LoadAbility_001, TestSize.Level0) +{ + HILOG_INFO("LoadAbility_001 start"); + OHOS::sptr token = sptr(new (std::nothrow) MockAbilityToken()); + auto appMgrServiceInner = std::make_shared(); + EXPECT_NE(appMgrServiceInner, nullptr); + + appMgrServiceInner->appRunningManager_ = nullptr; + appMgrServiceInner->LoadAbility(token, nullptr, abilityInfo_, applicationInfo_, nullptr); + + auto appMgrServiceInner1 = std::make_shared(); + EXPECT_NE(appMgrServiceInner1, nullptr); + + appMgrServiceInner1->remoteClientManager_->SetBundleManager(nullptr); + appMgrServiceInner1->LoadAbility(token, nullptr, abilityInfo_, applicationInfo_, nullptr); + + auto appMgrServiceInner2 = std::make_shared(); + EXPECT_NE(appMgrServiceInner2, nullptr); + + appMgrServiceInner2->LoadAbility(token, nullptr, abilityInfo_, applicationInfo_, nullptr); + HILOG_INFO("LoadAbility_001 end"); +} + +/** + * @tc.name: CheckLoadAbilityConditions_001 + * @tc.desc: check load ability conditions. + * @tc.type: FUNC + * @tc.require: issueI5W4S7 + */ +HWTEST_F(AppMgrServiceInnerTest, CheckLoadAbilityConditions_001, TestSize.Level0) +{ + HILOG_INFO("CheckLoadAbilityConditions_001 start"); + auto appMgrServiceInner = std::make_shared(); + EXPECT_NE(appMgrServiceInner, nullptr); + + OHOS::sptr token = sptr(new (std::nothrow) MockAbilityToken()); + + appMgrServiceInner->CheckLoadAbilityConditions(nullptr, nullptr, nullptr); + + appMgrServiceInner->CheckLoadAbilityConditions(nullptr, abilityInfo_, nullptr); + + appMgrServiceInner->CheckLoadAbilityConditions(nullptr, nullptr, applicationInfo_); + + appMgrServiceInner->CheckLoadAbilityConditions(token, nullptr, nullptr); + + appMgrServiceInner->CheckLoadAbilityConditions(token, abilityInfo_, nullptr); + + appMgrServiceInner->CheckLoadAbilityConditions(nullptr, abilityInfo_, applicationInfo_); + + appMgrServiceInner->CheckLoadAbilityConditions(token, nullptr, applicationInfo_); + + appMgrServiceInner->CheckLoadAbilityConditions(token, abilityInfo_, applicationInfo_); + + EXPECT_NE(appMgrServiceInner, nullptr); + HILOG_INFO("CheckLoadAbilityConditions_001 end"); +} + +/** + * @tc.name: MakeProcessName_001 + * @tc.desc: make process name. + * @tc.type: FUNC + * @tc.require: issueI5W4S7 + */ +HWTEST_F(AppMgrServiceInnerTest, MakeProcessName_001, TestSize.Level0) +{ + HILOG_INFO("MakeProcessName_001 start"); + auto appMgrServiceInner = std::make_shared(); + EXPECT_NE(appMgrServiceInner, nullptr); + + HapModuleInfo hapModuleInfo; + hapModuleInfo.moduleName = "module789"; + std::string processName = "test_processName"; + appMgrServiceInner->MakeProcessName(nullptr, nullptr, hapModuleInfo, 1, processName); + appMgrServiceInner->MakeProcessName(nullptr, applicationInfo_, hapModuleInfo, 1, processName); + appMgrServiceInner->MakeProcessName(abilityInfo_, nullptr, hapModuleInfo, 1, processName); + appMgrServiceInner->MakeProcessName(abilityInfo_, applicationInfo_, hapModuleInfo, 1, processName); + + EXPECT_NE(appMgrServiceInner, nullptr); + HILOG_INFO("MakeProcessName_001 end"); +} + +/** + * @tc.name: MakeProcessName_002 + * @tc.desc: make process name. + * @tc.type: FUNC + * @tc.require: issueI5W4S7 + */ +HWTEST_F(AppMgrServiceInnerTest, MakeProcessName_002, TestSize.Level0) +{ + HILOG_INFO("MakeProcessName_002 start"); + auto appMgrServiceInner = std::make_shared(); + EXPECT_NE(appMgrServiceInner, nullptr); + + HapModuleInfo hapModuleInfo; + hapModuleInfo.moduleName = "module789"; + std::string processName = "test_processName"; + appMgrServiceInner->MakeProcessName(nullptr, hapModuleInfo, processName); + appMgrServiceInner->MakeProcessName(applicationInfo_, hapModuleInfo, processName); + hapModuleInfo.isStageBasedModel = false; + hapModuleInfo.process = ""; + appMgrServiceInner->MakeProcessName(applicationInfo_, hapModuleInfo, processName); + + hapModuleInfo.isStageBasedModel = true; + hapModuleInfo.process = ""; + appMgrServiceInner->MakeProcessName(applicationInfo_, hapModuleInfo, processName); + + hapModuleInfo.isStageBasedModel = false; + hapModuleInfo.process = "test_process"; + appMgrServiceInner->MakeProcessName(applicationInfo_, hapModuleInfo, processName); + + hapModuleInfo.isStageBasedModel = true; + hapModuleInfo.process = "test_process"; + appMgrServiceInner->MakeProcessName(applicationInfo_, hapModuleInfo, processName); + + hapModuleInfo.isStageBasedModel = false; + applicationInfo_->process = ""; + appMgrServiceInner->MakeProcessName(applicationInfo_, hapModuleInfo, processName); + + hapModuleInfo.isStageBasedModel = false; + applicationInfo_->process = "test_process"; + appMgrServiceInner->MakeProcessName(applicationInfo_, hapModuleInfo, processName); + + EXPECT_NE(appMgrServiceInner, nullptr); + HILOG_INFO("MakeProcessName_002 end"); +} + +/** + * @tc.name: GetBundleAndHapInfo_001 + * @tc.desc: get bundle and hapInfo. + * @tc.type: FUNC + * @tc.require: issueI5W4S7 + */ +HWTEST_F(AppMgrServiceInnerTest, GetBundleAndHapInfo_001, TestSize.Level0) +{ + HILOG_INFO("GetBundleAndHapInfo_001 start"); + auto appMgrServiceInner = std::make_shared(); + EXPECT_NE(appMgrServiceInner, nullptr); + + BundleInfo bundleInfo; + HapModuleInfo hapModuleInfo; + appMgrServiceInner->GetBundleAndHapInfo(*abilityInfo_, applicationInfo_, bundleInfo, hapModuleInfo, 1); + + appMgrServiceInner->remoteClientManager_->SetBundleManager(nullptr); + appMgrServiceInner->GetBundleAndHapInfo(*abilityInfo_, applicationInfo_, bundleInfo, hapModuleInfo, 1); + HILOG_INFO("GetBundleAndHapInfo_001 end"); +} + +/** + * @tc.name: AttachApplication_001 + * @tc.desc: attach application. + * @tc.type: FUNC + * @tc.require: issueI5W4S7 + */ +HWTEST_F(AppMgrServiceInnerTest, AttachApplication_001, TestSize.Level0) +{ + HILOG_INFO("AttachApplication_001 start"); + auto appMgrServiceInner = std::make_shared(); + EXPECT_NE(appMgrServiceInner, nullptr); + + appMgrServiceInner->AttachApplication(0, nullptr); + + appMgrServiceInner->AttachApplication(1, nullptr); + + sptr mockAppScheduler = new (std::nothrow) MockAppScheduler(); + sptr client = iface_cast(mockAppScheduler.GetRefPtr()); + appMgrServiceInner->AttachApplication(1, client); + HILOG_INFO("AttachApplication_001 end"); +} + +/** + * @tc.name: LaunchApplication_001 + * @tc.desc: launch application. + * @tc.type: FUNC + * @tc.require: issueI5W4S7 + */ +HWTEST_F(AppMgrServiceInnerTest, LaunchApplication_001, TestSize.Level0) +{ + HILOG_INFO("LaunchApplication_001 start"); + auto appMgrServiceInner = std::make_shared(); + EXPECT_NE(appMgrServiceInner, nullptr); + + appMgrServiceInner->LaunchApplication(nullptr); + + BundleInfo info; + std::string processName = "test_processName"; + std::shared_ptr appRecord = + appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info); + recordId_ += 1; + appMgrServiceInner->LaunchApplication(appRecord); + + appRecord->SetState(ApplicationState::APP_STATE_FOREGROUND); + appMgrServiceInner->LaunchApplication(appRecord); + + appRecord->SetState(ApplicationState::APP_STATE_CREATE); + appMgrServiceInner->LaunchApplication(appRecord); + + appRecord->SetKeepAliveAppState(false, true); + appMgrServiceInner->LaunchApplication(appRecord); + + appRecord->SetKeepAliveAppState(true, false); + appMgrServiceInner->LaunchApplication(appRecord); + + appRecord->SetKeepAliveAppState(true, true); + appMgrServiceInner->LaunchApplication(appRecord); + + appRecord->SetKeepAliveAppState(false, false); + appMgrServiceInner->LaunchApplication(appRecord); + + Want want; + appRecord->SetSpecifiedAbilityFlagAndWant(false, want, ""); + appMgrServiceInner->LaunchApplication(appRecord); + + appRecord->SetSpecifiedAbilityFlagAndWant(true, want, ""); + appMgrServiceInner->LaunchApplication(appRecord); + + appMgrServiceInner->configuration_ = nullptr; + appMgrServiceInner->LaunchApplication(appRecord); + HILOG_INFO("LaunchApplication_001 end"); +} + +/** + * @tc.name: AddAbilityStageDone_001 + * @tc.desc: add ability stage done. + * @tc.type: FUNC + * @tc.require: issueI5W4S7 + */ +HWTEST_F(AppMgrServiceInnerTest, AddAbilityStageDone_001, TestSize.Level0) +{ + HILOG_INFO("AddAbilityStageDone_001 start"); + auto appMgrServiceInner = std::make_shared(); + EXPECT_NE(appMgrServiceInner, nullptr); + + appMgrServiceInner->AddAbilityStageDone(99); + + BundleInfo info; + std::string processName = "test_processName"; + appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info); + recordId_ += 1; + + appMgrServiceInner->AddAbilityStageDone(recordId_); + HILOG_INFO("AddAbilityStageDone_001 end"); +} + +/** + * @tc.name: AddAbilityStageDone_001 + * @tc.desc: application foregrounded. + * @tc.type: FUNC + * @tc.require: issueI5W4S7 + */ +HWTEST_F(AppMgrServiceInnerTest, ApplicationForegrounded_001, TestSize.Level0) +{ + HILOG_INFO("ApplicationForegrounded_001 start"); + auto appMgrServiceInner = std::make_shared(); + EXPECT_NE(appMgrServiceInner, nullptr); + + appMgrServiceInner->ApplicationForegrounded(99); + + BundleInfo info; + std::string processName = "test_processName"; + appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info); + recordId_ += 1; + + appMgrServiceInner->ApplicationForegrounded(recordId_); + HILOG_INFO("ApplicationForegrounded_001 end"); +} + +/** + * @tc.name: ApplicationBackgrounded_001 + * @tc.desc: application backgrounded. + * @tc.type: FUNC + * @tc.require: issueI5W4S7 + */ +HWTEST_F(AppMgrServiceInnerTest, ApplicationBackgrounded_001, TestSize.Level0) +{ + HILOG_INFO("ApplicationBackgrounded_001 start"); + auto appMgrServiceInner = std::make_shared(); + EXPECT_NE(appMgrServiceInner, nullptr); + appMgrServiceInner->Init(); + + appMgrServiceInner->ApplicationBackgrounded(99); + + BundleInfo info; + std::string processName = "test_processName"; + auto appRecord = + appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info); + EXPECT_NE(appRecord, nullptr); + recordId_ += 1; + + appMgrServiceInner->ApplicationBackgrounded(recordId_); + + appRecord->SetState(ApplicationState::APP_STATE_FOREGROUND); + appMgrServiceInner->ApplicationBackgrounded(recordId_); + + HILOG_INFO("ApplicationBackgrounded_001 end"); +} + +/** + * @tc.name: ApplicationTerminated_001 + * @tc.desc: application terminated. + * @tc.type: FUNC + * @tc.require: issueI5W4S7 + */ +HWTEST_F(AppMgrServiceInnerTest, ApplicationTerminated_001, TestSize.Level0) +{ + HILOG_INFO("ApplicationTerminated_001 start"); + auto appMgrServiceInner = std::make_shared(); + EXPECT_NE(appMgrServiceInner, nullptr); + + appMgrServiceInner->ApplicationTerminated(99); + + BundleInfo info; + std::string processName = "test_processName"; + auto appRecord = + appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info); + EXPECT_NE(appRecord, nullptr); + recordId_ += 1; + + appMgrServiceInner->ApplicationTerminated(recordId_); + + appRecord->SetKeepAliveAppState(false, true); + appMgrServiceInner->ApplicationTerminated(recordId_); + + appRecord->SetKeepAliveAppState(true, false); + appMgrServiceInner->ApplicationTerminated(recordId_); + + appRecord->SetKeepAliveAppState(true, true); + appMgrServiceInner->ApplicationTerminated(recordId_); + + appRecord->SetKeepAliveAppState(false, false); + appMgrServiceInner->ApplicationTerminated(recordId_); + + appRecord->SetState(ApplicationState::APP_STATE_FOREGROUND); + appMgrServiceInner->ApplicationTerminated(recordId_); + + appRecord->SetState(ApplicationState::APP_STATE_BACKGROUND); + appMgrServiceInner->ApplicationTerminated(recordId_); + + appMgrServiceInner->appRunningManager_ = nullptr; + appMgrServiceInner->ApplicationTerminated(recordId_); + + HILOG_INFO("ApplicationTerminated_001 end"); +} + +/** + * @tc.name: KillApplication_001 + * @tc.desc: kill application. + * @tc.type: FUNC + * @tc.require: issueI5W4S7 + */ +HWTEST_F(AppMgrServiceInnerTest, KillApplication_001, TestSize.Level0) +{ + HILOG_INFO("KillApplication_001 start"); + auto appMgrServiceInner = std::make_shared(); + EXPECT_NE(appMgrServiceInner, nullptr); + + std::string bundleName = "test_bundleName"; + appMgrServiceInner->KillApplication(bundleName); + + appMgrServiceInner->appRunningManager_ = nullptr; + appMgrServiceInner->KillApplication(bundleName); + + HILOG_INFO("KillApplication_001 end"); +} + +/** + * @tc.name: KillApplicationByUid_001 + * @tc.desc: kill application by uid. + * @tc.type: FUNC + * @tc.require: issueI5W4S7 + */ +HWTEST_F(AppMgrServiceInnerTest, KillApplicationByUid_001, TestSize.Level0) +{ + HILOG_INFO("KillApplicationByUid_001 start"); + auto appMgrServiceInner = std::make_shared(); + EXPECT_NE(appMgrServiceInner, nullptr); + + std::string bundleName = "test_bundleName"; + appMgrServiceInner->KillApplicationByUid(bundleName, 0); + + appMgrServiceInner->remoteClientManager_->SetBundleManager(nullptr); + appMgrServiceInner->KillApplicationByUid(bundleName, 0); + + appMgrServiceInner->remoteClientManager_ = nullptr; + appMgrServiceInner->KillApplicationByUid(bundleName, 0); + + appMgrServiceInner->appRunningManager_ = nullptr; + appMgrServiceInner->KillApplicationByUid(bundleName, 0); + + HILOG_INFO("KillApplicationByUid_001 end"); +} + +/** + * @tc.name: KillApplicationSelf_001 + * @tc.desc: kill application self. + * @tc.type: FUNC + * @tc.require: issueI5W4S7 + */ +HWTEST_F(AppMgrServiceInnerTest, KillApplicationSelf_001, TestSize.Level0) +{ + HILOG_INFO("KillApplicationSelf_001 start"); + auto appMgrServiceInner = std::make_shared(); + EXPECT_NE(appMgrServiceInner, nullptr); + + appMgrServiceInner->KillApplicationSelf(); + + appMgrServiceInner->appRunningManager_ = nullptr; + appMgrServiceInner->KillApplicationSelf(); + + HILOG_INFO("KillApplicationSelf_001 end"); +} + +/** + * @tc.name: KillApplicationByUserId_001 + * @tc.desc: kill application by user id. + * @tc.type: FUNC + * @tc.require: issueI5W4S7 + */ +HWTEST_F(AppMgrServiceInnerTest, KillApplicationByUserId_001, TestSize.Level0) +{ + HILOG_INFO("KillApplicationByUserId_001 start"); + auto appMgrServiceInner = std::make_shared(); + EXPECT_NE(appMgrServiceInner, nullptr); + + std::string bundleName = "test_bundleName"; + int result = appMgrServiceInner->KillApplicationByUserId(bundleName, 0); + EXPECT_EQ(result, 0); + + appMgrServiceInner->remoteClientManager_->SetBundleManager(nullptr); + appMgrServiceInner->KillApplicationByUserId(bundleName, 0); + EXPECT_EQ(result, 0); + + appMgrServiceInner->remoteClientManager_ = nullptr; + appMgrServiceInner->KillApplicationByUserId(bundleName, 0); + EXPECT_EQ(result, 0); + + appMgrServiceInner->appRunningManager_ = nullptr; + appMgrServiceInner->KillApplicationByUserId(bundleName, 0); + EXPECT_EQ(result, 0); + + HILOG_INFO("KillApplicationByUserId_001 end"); +} + +/** + * @tc.name: KillApplicationByUserIdLocked_001 + * @tc.desc: kill application by user id locked. + * @tc.type: FUNC + * @tc.require: issueI5W4S7 + */ +HWTEST_F(AppMgrServiceInnerTest, KillApplicationByUserIdLocked_001, TestSize.Level0) +{ + HILOG_INFO("KillApplicationByUserIdLocked_001 start"); + auto appMgrServiceInner = std::make_shared(); + EXPECT_NE(appMgrServiceInner, nullptr); + + std::string bundleName = "test_bundleName"; + int result = appMgrServiceInner->KillApplicationByUserIdLocked(bundleName, 0); + EXPECT_EQ(result, 0); + + appMgrServiceInner->remoteClientManager_->SetBundleManager(nullptr); + appMgrServiceInner->KillApplicationByUserIdLocked(bundleName, 0); + EXPECT_EQ(result, 0); + + appMgrServiceInner->remoteClientManager_ = nullptr; + appMgrServiceInner->KillApplicationByUserIdLocked(bundleName, 0); + EXPECT_EQ(result, 0); + + appMgrServiceInner->appRunningManager_ = nullptr; + appMgrServiceInner->KillApplicationByUserIdLocked(bundleName, 0); + EXPECT_EQ(result, 0); + + HILOG_INFO("KillApplicationByUserIdLocked_001 end"); +} + +/** + * @tc.name: ClearUpApplicationData_001 + * @tc.desc: clear up application data. + * @tc.type: FUNC + * @tc.require: issueI5W4S7 + */ +HWTEST_F(AppMgrServiceInnerTest, ClearUpApplicationData_001, TestSize.Level0) +{ + HILOG_INFO("ClearUpApplicationData_001 start"); + auto appMgrServiceInner = std::make_shared(); + EXPECT_NE(appMgrServiceInner, nullptr); + + std::string bundleName = "test_bundleName"; + appMgrServiceInner->ClearUpApplicationData(bundleName, 0, 0); + + HILOG_INFO("ClearUpApplicationData_001 end"); +} + +/** + * @tc.name: ClearUpApplicationDataByUserId_001 + * @tc.desc: clear up application data by user id. + * @tc.type: FUNC + * @tc.require: issueI5W4S7 + */ +HWTEST_F(AppMgrServiceInnerTest, ClearUpApplicationDataByUserId_001, TestSize.Level0) +{ + HILOG_INFO("ClearUpApplicationDataByUserId_001 start"); + auto appMgrServiceInner = std::make_shared(); + EXPECT_NE(appMgrServiceInner, nullptr); + + std::string bundleName = "test_bundleName"; + appMgrServiceInner->ClearUpApplicationDataByUserId(bundleName, 0, 0, 0); + appMgrServiceInner->ClearUpApplicationDataByUserId(bundleName, 1, 0, 0); + appMgrServiceInner->ClearUpApplicationDataByUserId(bundleName, 1, 1, 0); + + appMgrServiceInner->appRunningManager_ = nullptr; + appMgrServiceInner->ClearUpApplicationDataByUserId(bundleName, 1, 1, 0); + + appMgrServiceInner->remoteClientManager_->SetBundleManager(nullptr); + appMgrServiceInner->ClearUpApplicationDataByUserId(bundleName, 1, 1, 0); + + HILOG_INFO("ClearUpApplicationDataByUserId_001 end"); +} + +/** + * @tc.name: GetAllRunningProcesses_001 + * @tc.desc: get all running processes. + * @tc.type: FUNC + * @tc.require: issueI5W4S7 + */ +HWTEST_F(AppMgrServiceInnerTest, GetAllRunningProcesses_001, TestSize.Level0) +{ + HILOG_INFO("GetAllRunningProcesses_001 start"); + auto appMgrServiceInner = std::make_shared(); + EXPECT_NE(appMgrServiceInner, nullptr); + + std::vector info; + appMgrServiceInner->GetAllRunningProcesses(info); + + HILOG_INFO("GetAllRunningProcesses_001 end"); +} + +/** + * @tc.name: GetProcessRunningInfosByUserId_001 + * @tc.desc: get process running infos by user id. + * @tc.type: FUNC + * @tc.require: issueI5W4S7 + */ +HWTEST_F(AppMgrServiceInnerTest, GetProcessRunningInfosByUserId_001, TestSize.Level0) +{ + HILOG_INFO("GetProcessRunningInfosByUserId_001 start"); + auto appMgrServiceInner = std::make_shared(); + EXPECT_NE(appMgrServiceInner, nullptr); + + std::vector info; + appMgrServiceInner->GetProcessRunningInfosByUserId(info, 0); + + HILOG_INFO("GetProcessRunningInfosByUserId_001 end"); +} + +/** + * @tc.name: NotifyMemoryLevel_001 + * @tc.desc: notify memory level. + * @tc.type: FUNC + * @tc.require: issueI5W4S7 + */ +HWTEST_F(AppMgrServiceInnerTest, NotifyMemoryLevel_001, TestSize.Level0) +{ + HILOG_INFO("NotifyMemoryLevel_001 start"); + auto appMgrServiceInner = std::make_shared(); + EXPECT_NE(appMgrServiceInner, nullptr); + + std::vector info; + int result = appMgrServiceInner->NotifyMemoryLevel(0); + EXPECT_EQ(result, 0); + + result = appMgrServiceInner->NotifyMemoryLevel(1); + EXPECT_EQ(result, 0); + + result = appMgrServiceInner->NotifyMemoryLevel(2); + EXPECT_EQ(result, 0); + + result = appMgrServiceInner->NotifyMemoryLevel(3); + EXPECT_EQ(result, 22); + + appMgrServiceInner->appRunningManager_ = nullptr; + result = appMgrServiceInner->NotifyMemoryLevel(3); + EXPECT_EQ(result, ERR_INVALID_VALUE); + + HILOG_INFO("NotifyMemoryLevel_001 end"); +} + +/** + * @tc.name: KillProcessByPid_001 + * @tc.desc: kill process by pid. + * @tc.type: FUNC + * @tc.require: issueI5W4S7 + */ +HWTEST_F(AppMgrServiceInnerTest, KillProcessByPid_001, TestSize.Level0) +{ + HILOG_INFO("KillProcessByPid_001 start"); + auto appMgrServiceInner = std::make_shared(); + EXPECT_NE(appMgrServiceInner, nullptr); + + int result = appMgrServiceInner->KillProcessByPid(0); + EXPECT_EQ(result, -1); + + result = appMgrServiceInner->KillProcessByPid(1); + EXPECT_EQ(result, 0); + + HILOG_INFO("KillProcessByPid_001 end"); +} + +/** + * @tc.name: GetAllPids_001 + * @tc.desc: get all pids. + * @tc.type: FUNC + * @tc.require: issueI5W4S7 + */ +HWTEST_F(AppMgrServiceInnerTest, GetAllPids_001, TestSize.Level0) +{ + HILOG_INFO("GetAllPids_001 start"); + auto appMgrServiceInner = std::make_shared(); + EXPECT_NE(appMgrServiceInner, nullptr); + + std::list pids; + bool result = appMgrServiceInner->GetAllPids(pids); + EXPECT_FALSE(result); + + pids.push_back(1); + result = appMgrServiceInner->GetAllPids(pids); + EXPECT_TRUE(result); + + std::string appName = "test_appName"; + std::string processName = "test_processName"; + appMgrServiceInner->appProcessManager_->AddAppToRecentList(appName, processName, 0, 0); + result = appMgrServiceInner->GetAllPids(pids); + EXPECT_TRUE(result); + + HILOG_INFO("GetAllPids_001 end"); +} + +/** + * @tc.name: ProcessExist_001 + * @tc.desc: process exist. + * @tc.type: FUNC + * @tc.require: issueI5W4S7 + */ +HWTEST_F(AppMgrServiceInnerTest, ProcessExist_001, TestSize.Level0) +{ + HILOG_INFO("ProcessExist_001 start"); + auto appMgrServiceInner = std::make_shared(); + EXPECT_NE(appMgrServiceInner, nullptr); + + pid_t pid = 0; + bool result = appMgrServiceInner->ProcessExist(pid); + EXPECT_FALSE(result); + + HILOG_INFO("ProcessExist_001 end"); +} + +/** + * @tc.name: CreateAppRunningRecord_001 + * @tc.desc: create app running record. + * @tc.type: FUNC + * @tc.require: issueI5W4S7 + */ +HWTEST_F(AppMgrServiceInnerTest, CreateAppRunningRecord_001, TestSize.Level0) +{ + HILOG_INFO("CreateAppRunningRecord_001 start"); + OHOS::sptr token = sptr(new (std::nothrow) MockAbilityToken()); + auto appMgrServiceInner = std::make_shared(); + EXPECT_NE(appMgrServiceInner, nullptr); + + BundleInfo bundleInfo; + HapModuleInfo hapModuleInfo; + std::shared_ptr want; + std::string processName = "test_processName"; + + std::shared_ptr appRecord = appMgrServiceInner->CreateAppRunningRecord(nullptr, nullptr, + nullptr, nullptr, "", bundleInfo, hapModuleInfo, nullptr); + EXPECT_EQ(appRecord, nullptr); + + appRecord = appMgrServiceInner->CreateAppRunningRecord(token, nullptr, + nullptr, nullptr, "", bundleInfo, hapModuleInfo, nullptr); + EXPECT_EQ(appRecord, nullptr); + + appRecord = appMgrServiceInner->CreateAppRunningRecord(token, nullptr, + applicationInfo_, nullptr, "", bundleInfo, hapModuleInfo, nullptr); + EXPECT_EQ(appRecord, nullptr); + + appRecord = appMgrServiceInner->CreateAppRunningRecord(token, nullptr, + applicationInfo_, abilityInfo_, "", bundleInfo, hapModuleInfo, nullptr); + EXPECT_EQ(appRecord, nullptr); + + appRecord = appMgrServiceInner->CreateAppRunningRecord(token, nullptr, + applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, nullptr); + EXPECT_NE(appRecord, nullptr); + + appRecord = appMgrServiceInner->CreateAppRunningRecord(token, nullptr, + applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, nullptr); + EXPECT_NE(appRecord, nullptr); + + appRecord = appMgrServiceInner->CreateAppRunningRecord(token, nullptr, + applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, nullptr); + EXPECT_NE(appRecord, nullptr); + + std::shared_ptr appRecord1 = appMgrServiceInner->CreateAppRunningRecord(token, nullptr, + nullptr, abilityInfo_, processName, bundleInfo, hapModuleInfo, want); + EXPECT_EQ(appRecord1, nullptr); + + std::shared_ptr appRecord2 = appMgrServiceInner->CreateAppRunningRecord(token, nullptr, + applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want); + EXPECT_NE(appRecord2, nullptr); + + want = std::make_shared(); + const std::string COLD_START = "coldStart"; + want->SetParam(COLD_START, true); + std::shared_ptr appRecord3 = appMgrServiceInner->CreateAppRunningRecord(token, nullptr, + applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want); + EXPECT_NE(appRecord3, nullptr); + + want->SetParam(COLD_START, false); + std::shared_ptr appRecord4 = appMgrServiceInner->CreateAppRunningRecord(token, nullptr, + applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want); + EXPECT_NE(appRecord4, nullptr); + + appMgrServiceInner->appRunningManager_ = nullptr; + std::shared_ptr appRecord5 = appMgrServiceInner->CreateAppRunningRecord(token, nullptr, + applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want); + EXPECT_EQ(appRecord5, nullptr); + + HILOG_INFO("CreateAppRunningRecord_001 end"); +} + +/** + * @tc.name: TerminateAbility_001 + * @tc.desc: terminate ability. + * @tc.type: FUNC + * @tc.require: issueI5W4S7 + */ +HWTEST_F(AppMgrServiceInnerTest, TerminateAbility_001, TestSize.Level0) +{ + HILOG_INFO("TerminateAbility_001 start"); + auto appMgrServiceInner = std::make_shared(); + EXPECT_NE(appMgrServiceInner, nullptr); + + appMgrServiceInner->TerminateAbility(nullptr, true); + appMgrServiceInner->TerminateAbility(nullptr, false); + + OHOS::sptr token = sptr(new (std::nothrow) MockAbilityToken()); + appMgrServiceInner->TerminateAbility(token, true); + appMgrServiceInner->TerminateAbility(token, false); + + appMgrServiceInner->appRunningManager_ = nullptr; + appMgrServiceInner->TerminateAbility(token, true); + + HILOG_INFO("TerminateAbility_001 end"); +} + +/** + * @tc.name: UpdateAbilityState_001 + * @tc.desc: update ability state. + * @tc.type: FUNC + * @tc.require: issueI5W4S7 + */ +HWTEST_F(AppMgrServiceInnerTest, UpdateAbilityState_001, TestSize.Level0) +{ + HILOG_INFO("UpdateAbilityState_001 start"); + auto appMgrServiceInner = std::make_shared(); + EXPECT_NE(appMgrServiceInner, nullptr); + + appMgrServiceInner->UpdateAbilityState(nullptr, AbilityState::ABILITY_STATE_CREATE); + + OHOS::sptr token = sptr(new (std::nothrow) MockAbilityToken()); + appMgrServiceInner->UpdateAbilityState(token, AbilityState::ABILITY_STATE_CREATE); + + BundleInfo bundleInfo; + HapModuleInfo hapModuleInfo; + std::shared_ptr want; + std::string processName = "test_processName"; + std::shared_ptr appRecord = appMgrServiceInner->CreateAppRunningRecord(token, nullptr, + applicationInfo_, nullptr, processName, bundleInfo, hapModuleInfo, want); + EXPECT_NE(appRecord, nullptr); + appMgrServiceInner->UpdateAbilityState(token, AbilityState::ABILITY_STATE_CREATE); + + OHOS::sptr token1 = sptr(new (std::nothrow) MockAbilityToken()); + std::shared_ptr appRecord1 = appMgrServiceInner->CreateAppRunningRecord(token1, nullptr, + applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want); + EXPECT_NE(appRecord1, nullptr); + + appMgrServiceInner->UpdateAbilityState(token1, AbilityState::ABILITY_STATE_READY); + appMgrServiceInner->UpdateAbilityState(token1, AbilityState::ABILITY_STATE_CREATE); + + auto abilityRecord1 = + appMgrServiceInner->GetAppRunningRecordByAbilityToken(token1)->GetAbilityRunningRecordByToken(token1); + abilityRecord1->SetState(AbilityState::ABILITY_STATE_TERMINATED); + appMgrServiceInner->UpdateAbilityState(token1, AbilityState::ABILITY_STATE_TERMINATED); + + abilityRecord1->SetState(AbilityState::ABILITY_STATE_CONNECTED); + appMgrServiceInner->UpdateAbilityState(token1, AbilityState::ABILITY_STATE_CONNECTED); + + abilityRecord1->SetState(AbilityState::ABILITY_STATE_DISCONNECTED); + appMgrServiceInner->UpdateAbilityState(token1, AbilityState::ABILITY_STATE_DISCONNECTED); + + abilityRecord1->SetState(AbilityState::ABILITY_STATE_END); + appMgrServiceInner->UpdateAbilityState(token1, AbilityState::ABILITY_STATE_END); + + abilityRecord1->SetState(AbilityState::ABILITY_STATE_BACKGROUND); + appMgrServiceInner->UpdateAbilityState(token1, AbilityState::ABILITY_STATE_BACKGROUND); + + OHOS::sptr token2 = sptr(new (std::nothrow) MockAbilityToken()); + abilityInfo_->type = AbilityType::SERVICE; + std::shared_ptr appRecord2 = appMgrServiceInner->CreateAppRunningRecord(token2, nullptr, + applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want); + EXPECT_NE(appRecord2, nullptr); + appMgrServiceInner->UpdateAbilityState(token2, AbilityState::ABILITY_STATE_CREATE); + + auto abilityRecord2 = + appMgrServiceInner->GetAppRunningRecordByAbilityToken(token2)->GetAbilityRunningRecordByToken(token2); + abilityRecord2->SetState(AbilityState::ABILITY_STATE_TERMINATED); + appMgrServiceInner->UpdateAbilityState(token2, AbilityState::ABILITY_STATE_TERMINATED); + + abilityRecord2->SetState(AbilityState::ABILITY_STATE_CONNECTED); + appMgrServiceInner->UpdateAbilityState(token2, AbilityState::ABILITY_STATE_CONNECTED); + + abilityRecord2->SetState(AbilityState::ABILITY_STATE_DISCONNECTED); + appMgrServiceInner->UpdateAbilityState(token2, AbilityState::ABILITY_STATE_DISCONNECTED); + + abilityRecord2->SetState(AbilityState::ABILITY_STATE_END); + appMgrServiceInner->UpdateAbilityState(token2, AbilityState::ABILITY_STATE_END); + + abilityRecord2->SetState(AbilityState::ABILITY_STATE_BACKGROUND); + appMgrServiceInner->UpdateAbilityState(token2, AbilityState::ABILITY_STATE_BACKGROUND); + + HILOG_INFO("UpdateAbilityState_001 end"); +} + +/** + * @tc.name: UpdateExtensionState_001 + * @tc.desc: update extension state. + * @tc.type: FUNC + * @tc.require: issueI5W4S7 + */ +HWTEST_F(AppMgrServiceInnerTest, UpdateExtensionState_001, TestSize.Level0) +{ + HILOG_INFO("UpdateExtensionState_001 start"); + auto appMgrServiceInner = std::make_shared(); + EXPECT_NE(appMgrServiceInner, nullptr); + + appMgrServiceInner->UpdateExtensionState(nullptr, ExtensionState::EXTENSION_STATE_CREATE); + + OHOS::sptr token = sptr(new (std::nothrow) MockAbilityToken()); + appMgrServiceInner->UpdateExtensionState(token, ExtensionState::EXTENSION_STATE_CREATE); + + BundleInfo bundleInfo; + HapModuleInfo hapModuleInfo; + std::shared_ptr want; + std::string processName = "test_processName"; + std::shared_ptr appRecord = appMgrServiceInner->CreateAppRunningRecord(token, nullptr, + applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want); + EXPECT_NE(appRecord, nullptr); + appMgrServiceInner->UpdateExtensionState(token, ExtensionState::EXTENSION_STATE_CREATE); + + HILOG_INFO("UpdateExtensionState_001 end"); +} + +/** + * @tc.name: OpenAppSpawnConnection_001 + * @tc.desc: open app spawn connection. + * @tc.type: FUNC + * @tc.require: issueI5W4S7 + */ +HWTEST_F(AppMgrServiceInnerTest, OpenAppSpawnConnection_001, TestSize.Level0) +{ + HILOG_INFO("OpenAppSpawnConnection_001 start"); + auto appMgrServiceInner = std::make_shared(); + EXPECT_NE(appMgrServiceInner, nullptr); + + appMgrServiceInner->remoteClientManager_->SetSpawnClient(nullptr); + auto errorCode = appMgrServiceInner->OpenAppSpawnConnection(); + EXPECT_EQ(errorCode, ERR_APPEXECFWK_BAD_APPSPAWN_CLIENT); + + appMgrServiceInner->remoteClientManager_ = nullptr; + auto errorCode1 = appMgrServiceInner->OpenAppSpawnConnection(); + EXPECT_EQ(errorCode1, ERR_INVALID_VALUE); + + HILOG_INFO("OpenAppSpawnConnection_001 end"); +} + +/** + * @tc.name: CloseAppSpawnConnection_001 + * @tc.desc: close app spawn connection. + * @tc.type: FUNC + * @tc.require: issueI5W4S7 + */ +HWTEST_F(AppMgrServiceInnerTest, CloseAppSpawnConnection_001, TestSize.Level0) +{ + HILOG_INFO("CloseAppSpawnConnection_001 start"); + auto appMgrServiceInner = std::make_shared(); + EXPECT_NE(appMgrServiceInner, nullptr); + + appMgrServiceInner->CloseAppSpawnConnection(); + + appMgrServiceInner->remoteClientManager_ = nullptr; + appMgrServiceInner->CloseAppSpawnConnection(); + + HILOG_INFO("CloseAppSpawnConnection_001 end"); +} + +/** + * @tc.name: QueryAppSpawnConnectionState_001 + * @tc.desc: query app spawn connection. + * @tc.type: FUNC + * @tc.require: issueI5W4S7 + */ +HWTEST_F(AppMgrServiceInnerTest, QueryAppSpawnConnectionState_001, TestSize.Level0) +{ + HILOG_INFO("QueryAppSpawnConnectionState_001 start"); + auto appMgrServiceInner = std::make_shared(); + EXPECT_NE(appMgrServiceInner, nullptr); + + auto connectionState = appMgrServiceInner->QueryAppSpawnConnectionState(); + EXPECT_EQ(connectionState, SpawnConnectionState::STATE_NOT_CONNECT); + + appMgrServiceInner->remoteClientManager_->SetSpawnClient(nullptr); + connectionState = appMgrServiceInner->QueryAppSpawnConnectionState(); + EXPECT_EQ(connectionState, SpawnConnectionState::STATE_NOT_CONNECT); + + + appMgrServiceInner->remoteClientManager_ = nullptr; + connectionState = appMgrServiceInner->QueryAppSpawnConnectionState(); + EXPECT_EQ(connectionState, SpawnConnectionState::STATE_NOT_CONNECT); + + HILOG_INFO("QueryAppSpawnConnectionState_001 end"); +} + +/** + * @tc.name: GetRecordMap_001 + * @tc.desc: get record map. + * @tc.type: FUNC + * @tc.require: issueI5W4S7 + */ +HWTEST_F(AppMgrServiceInnerTest, GetRecordMap_001, TestSize.Level0) +{ + HILOG_INFO("GetRecordMap_001 start"); + auto appMgrServiceInner = std::make_shared(); + EXPECT_NE(appMgrServiceInner, nullptr); + + std::map> appRunningRecordMap; + + auto appRunningRecordMap1 = appMgrServiceInner->GetRecordMap(); + EXPECT_EQ(appRunningRecordMap1, appRunningRecordMap); + + appMgrServiceInner->appRunningManager_ = nullptr; + auto appRunningRecordMap2 = appMgrServiceInner->GetRecordMap(); + EXPECT_EQ(appRunningRecordMap2, appRunningRecordMap); + + HILOG_INFO("GetRecordMap_001 end"); +} + +/** + * @tc.name: SetAppSpawnClient_001 + * @tc.desc: set app spawn client. + * @tc.type: FUNC + * @tc.require: issueI5W4S7 + */ +HWTEST_F(AppMgrServiceInnerTest, SetAppSpawnClient_001, TestSize.Level0) +{ + HILOG_INFO("SetAppSpawnClient_001 start"); + auto appMgrServiceInner = std::make_shared(); + EXPECT_NE(appMgrServiceInner, nullptr); + + std::shared_ptr spawnClient; + appMgrServiceInner->SetAppSpawnClient(spawnClient); + + appMgrServiceInner->remoteClientManager_ = nullptr; + appMgrServiceInner->SetAppSpawnClient(spawnClient); + + HILOG_INFO("SetAppSpawnClient_001 end"); +} + +/** + * @tc.name: SetBundleManager_001 + * @tc.desc: set bundle manager. + * @tc.type: FUNC + * @tc.require: issueI5W4S7 + */ +HWTEST_F(AppMgrServiceInnerTest, SetBundleManager_001, TestSize.Level0) +{ + HILOG_INFO("SetBundleManager_001 start"); + auto appMgrServiceInner = std::make_shared(); + EXPECT_NE(appMgrServiceInner, nullptr); + + sptr bundleManager; + appMgrServiceInner->SetBundleManager(bundleManager); + + appMgrServiceInner->remoteClientManager_ = nullptr; + appMgrServiceInner->SetBundleManager(bundleManager); + + HILOG_INFO("SetBundleManager_001 end"); +} + +/** + * @tc.name: RegisterAppStateCallback_001 + * @tc.desc: register app state call back. + * @tc.type: FUNC + * @tc.require: issueI5W4S7 + */ +HWTEST_F(AppMgrServiceInnerTest, RegisterAppStateCallback_001, TestSize.Level0) +{ + HILOG_INFO("RegisterAppStateCallback_001 start"); + auto appMgrServiceInner = std::make_shared(); + EXPECT_NE(appMgrServiceInner, nullptr); + + appMgrServiceInner->RegisterAppStateCallback(nullptr); + + sptr callback; + appMgrServiceInner->RegisterAppStateCallback(callback); + + HILOG_INFO("RegisterAppStateCallback_001 end"); +} + +/** + * @tc.name: AbilityBehaviorAnalysis_001 + * @tc.desc: ability behavior analysis. + * @tc.type: FUNC + * @tc.require: issueI5W4S7 + */ +HWTEST_F(AppMgrServiceInnerTest, AbilityBehaviorAnalysis_001, TestSize.Level0) +{ + HILOG_INFO("AbilityBehaviorAnalysis_001 start"); + auto appMgrServiceInner = std::make_shared(); + EXPECT_NE(appMgrServiceInner, nullptr); + + appMgrServiceInner->AbilityBehaviorAnalysis(nullptr, nullptr, 0, 0, 0); + + OHOS::sptr token = sptr(new (std::nothrow) MockAbilityToken()); + appMgrServiceInner->AbilityBehaviorAnalysis(token, nullptr, 0, 0, 0); + + BundleInfo bundleInfo; + HapModuleInfo hapModuleInfo; + std::shared_ptr want; + std::string processName = "test_processName"; + std::shared_ptr appRecord = appMgrServiceInner->CreateAppRunningRecord(token, nullptr, + applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want); + EXPECT_NE(appRecord, nullptr); + appMgrServiceInner->AbilityBehaviorAnalysis(token, nullptr, 0, 0, 0); + + OHOS::sptr preToken = sptr(new (std::nothrow) MockAbilityToken()); + appMgrServiceInner->AbilityBehaviorAnalysis(token, preToken, 0, 0, 0); + + HILOG_INFO("AbilityBehaviorAnalysis_001 end"); +} + +/** + * @tc.name: KillProcessByAbilityToken_001 + * @tc.desc: kill process by ability token. + * @tc.type: FUNC + * @tc.require: issueI5W4S7 + */ +HWTEST_F(AppMgrServiceInnerTest, KillProcessByAbilityToken_001, TestSize.Level0) +{ + HILOG_INFO("KillProcessByAbilityToken_001 start"); + auto appMgrServiceInner = std::make_shared(); + EXPECT_NE(appMgrServiceInner, nullptr); + + appMgrServiceInner->KillProcessByAbilityToken(nullptr); + + OHOS::sptr token = sptr(new (std::nothrow) MockAbilityToken()); + appMgrServiceInner->KillProcessByAbilityToken(token); + + BundleInfo bundleInfo; + HapModuleInfo hapModuleInfo; + std::shared_ptr want; + std::string processName = "test_processName"; + std::shared_ptr appRecord = appMgrServiceInner->CreateAppRunningRecord(token, nullptr, + applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want); + EXPECT_NE(appRecord, nullptr); + appMgrServiceInner->KillProcessByAbilityToken(token); + + appRecord->SetKeepAliveAppState(true, true); + appMgrServiceInner->KillProcessByAbilityToken(token); + + HILOG_INFO("KillProcessByAbilityToken_001 end"); +} + +/** + * @tc.name: KillProcessesByUserId_001 + * @tc.desc: kill process by user id. + * @tc.type: FUNC + * @tc.require: issueI5W4S7 + */ +HWTEST_F(AppMgrServiceInnerTest, KillProcessesByUserId_001, TestSize.Level0) +{ + HILOG_INFO("KillProcessesByUserId_001 start"); + auto appMgrServiceInner = std::make_shared(); + EXPECT_NE(appMgrServiceInner, nullptr); + + appMgrServiceInner->KillProcessesByUserId(0); + + appMgrServiceInner->appRunningManager_ = nullptr; + appMgrServiceInner->KillProcessesByUserId(0); + + HILOG_INFO("KillProcessesByUserId_001 end"); +} } // namespace AppExecFwk } // namespace OHOS