• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <gtest/gtest.h>
17 
18 #define private public
19 #include "app_mgr_service_inner.h"
20 #include "app_running_record.h"
21 #include "remote_client_manager.h"
22 #undef private
23 #include "app_scheduler.h"
24 #include "event_handler.h"
25 #include "hilog_wrapper.h"
26 #include "ipc_skeleton.h"
27 #include "mock_ability_token.h"
28 #include "mock_app_scheduler.h"
29 #include "mock_bundle_manager.h"
30 #include "mock_configuration_observer.h"
31 #include "mock_iapp_state_callback.h"
32 #include "mock_native_token.h"
33 #include "mock_render_scheduler.h"
34 #include "parameters.h"
35 #include "window_manager.h"
36 
37 using namespace testing;
38 using namespace testing::ext;
39 
40 namespace OHOS {
41 namespace AppExecFwk {
42 static int recordId_ = 0;
43 class AppMgrServiceInnerTest : public testing::Test {
44 public:
45     static void SetUpTestCase();
46     static void TearDownTestCase();
47     void SetUp() override;
48     void TearDown() override;
49 
50     void InitAppInfo(const std::string& deviceName, const std::string& abilityName,
51         const std::string& appName, const std::string& bundleName, const std::string& moduleName);
52 
53 public:
54     std::shared_ptr<AbilityInfo> abilityInfo_;
55     std::shared_ptr<ApplicationInfo> applicationInfo_;
56 };
57 
InitAppInfo(const std::string & deviceName,const std::string & abilityName,const std::string & appName,const std::string & bundleName,const std::string & moduleName)58 void AppMgrServiceInnerTest::InitAppInfo(const std::string& deviceName,
59     const std::string& abilityName, const std::string& appName, const std::string& bundleName,
60     const std::string& moduleName)
61 {
62     ApplicationInfo applicationInfo;
63     applicationInfo.name = appName;
64     applicationInfo.bundleName = bundleName;
65     applicationInfo_ = std::make_shared<ApplicationInfo>(applicationInfo);
66 
67     AbilityInfo abilityInfo;
68     abilityInfo.visible = true;
69     abilityInfo.applicationName = appName;
70     abilityInfo.type = AbilityType::EXTENSION;
71     abilityInfo.name = abilityName;
72     abilityInfo.bundleName = bundleName;
73     abilityInfo.moduleName = moduleName;
74     abilityInfo.deviceId = deviceName;
75     abilityInfo_ = std::make_shared<AbilityInfo>(abilityInfo);
76 }
77 
SetUpTestCase(void)78 void AppMgrServiceInnerTest::SetUpTestCase(void)
79 {
80     MockNativeToken::SetNativeToken();
81 }
82 
TearDownTestCase(void)83 void AppMgrServiceInnerTest::TearDownTestCase(void)
84 {}
85 
SetUp()86 void AppMgrServiceInnerTest::SetUp()
87 {
88     // init test app info
89     std::string deviceName = "device";
90     std::string abilityName = "ServiceAbility";
91     std::string appName = "hiservcie";
92     std::string bundleName = "com.ix.hiservcie";
93     std::string moduleName = "entry";
94     InitAppInfo(deviceName, abilityName, appName, bundleName, moduleName);
95 }
96 
TearDown()97 void AppMgrServiceInnerTest::TearDown()
98 {}
99 
100 /**
101  * @tc.name: PointerDeviceCallback_0100
102  * @tc.desc: set parameter, expect config update
103  * @tc.type: FUNC
104  * @tc.require: I581UL
105  */
106 HWTEST_F(AppMgrServiceInnerTest, PointerDeviceCallback_0100, TestSize.Level1)
107 {
108     HILOG_INFO("PointerDeviceCallback_0100 start");
109 
110     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
111     EXPECT_NE(appMgrServiceInner, nullptr);
112     std::string key = AAFwk::GlobalConfigurationKey::INPUT_POINTER_DEVICE;
113     auto context = new (std::nothrow) std::weak_ptr<AppMgrServiceInner>(appMgrServiceInner);
114     std::shared_ptr<AppExecFwk::Configuration> config = nullptr;
115     std::string value;
116 
117     // invalid parameter value
118     appMgrServiceInner->PointerDeviceEventCallback(key.c_str(), "false", nullptr);
119     appMgrServiceInner->PointerDeviceEventCallback("invalid_key", "false", context);
120     appMgrServiceInner->PointerDeviceEventCallback(key.c_str(), "invalid", context);
121 
122     // set "input.pointer.device" to false
123     appMgrServiceInner->PointerDeviceEventCallback(key.c_str(), "false", context);
124     config = appMgrServiceInner->GetConfiguration();
125     EXPECT_NE(config, nullptr);
126     value = config->GetItem(AAFwk::GlobalConfigurationKey::INPUT_POINTER_DEVICE);
127     EXPECT_EQ(value, "false");
128 
129     // set "input.pointer.device" to true
130     appMgrServiceInner->PointerDeviceEventCallback(key.c_str(), "true", context);
131     config = appMgrServiceInner->GetConfiguration();
132     EXPECT_NE(config, nullptr);
133     value = config->GetItem(AAFwk::GlobalConfigurationKey::INPUT_POINTER_DEVICE);
134     EXPECT_EQ(value, "true");
135 
136     HILOG_INFO("PointerDeviceCallback_0100 end");
137 }
138 
139 /**
140  * @tc.name: PointerDeviceWatchParameter_0100
141  * @tc.desc: set parameter, expect config update
142  * @tc.type: FUNC
143  * @tc.require: I581UL
144  */
145 HWTEST_F(AppMgrServiceInnerTest, PointerDeviceWatchParameter_0100, TestSize.Level1)
146 {
147     HILOG_INFO("PointerDeviceWatchParameter_0100 start");
148 
149     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
150     EXPECT_NE(appMgrServiceInner, nullptr);
151     std::string key = AAFwk::GlobalConfigurationKey::INPUT_POINTER_DEVICE;
152     std::shared_ptr<AppExecFwk::Configuration> config = nullptr;
153     std::string value;
154 
155     appMgrServiceInner->AddWatchParameter();
156     sleep(1);
157 
158     // invalid parameter value
159     system::SetParameter(key.c_str(), "invalid");
160     sleep(1);
161 
162     // set "input.pointer.device" to false
163     system::SetParameter(key.c_str(), "false");
164     sleep(2); // sleep 2s, wait until UpdateConfiguration finished.
165     config = appMgrServiceInner->GetConfiguration();
166     EXPECT_NE(config, nullptr);
167     value = config->GetItem(AAFwk::GlobalConfigurationKey::INPUT_POINTER_DEVICE);
168     EXPECT_EQ(value, "false");
169 
170     // set "input.pointer.device" to true
171     system::SetParameter(key.c_str(), "true");
172     sleep(2); // sleep 2s, wait until UpdateConfiguration finished.
173     config = appMgrServiceInner->GetConfiguration();
174     EXPECT_NE(config, nullptr);
175     value = config->GetItem(AAFwk::GlobalConfigurationKey::INPUT_POINTER_DEVICE);
176     EXPECT_EQ(value, "true");
177 
178     HILOG_INFO("PointerDeviceWatchParameter_0100 end");
179 }
180 
181 /**
182  * @tc.name: PointerDeviceUpdateConfig_0100
183  * @tc.desc: set parameter, expect config update
184  * @tc.type: FUNC
185  * @tc.require: I581UL
186  */
187 HWTEST_F(AppMgrServiceInnerTest, PointerDeviceUpdateConfig_0100, TestSize.Level1)
188 {
189     HILOG_INFO("PointerDeviceUpdateConfig_0100 start");
190 
191     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
192     EXPECT_NE(appMgrServiceInner, nullptr);
193     std::shared_ptr<AppExecFwk::Configuration> config;
194     std::string value;
195     int32_t result;
196 
197     appMgrServiceInner->InitGlobalConfiguration();
198     config = appMgrServiceInner->GetConfiguration();
199     EXPECT_NE(config, nullptr);
200     value = config->GetItem(AAFwk::GlobalConfigurationKey::INPUT_POINTER_DEVICE);
201     EXPECT_TRUE((value == "true") || (value == "false"));
202 
203     // config didn't change
204     result = appMgrServiceInner->UpdateConfiguration(*config);
205     EXPECT_EQ(result, ERR_INVALID_VALUE);
206 
207     Configuration changeConfig;
208     if (value == "true") {
209         changeConfig.AddItem(AAFwk::GlobalConfigurationKey::INPUT_POINTER_DEVICE, "false");
210         result = appMgrServiceInner->UpdateConfiguration(changeConfig);
211         EXPECT_EQ(result, 0);
212         config = appMgrServiceInner->GetConfiguration();
213         EXPECT_NE(config, nullptr);
214         value = config->GetItem(AAFwk::GlobalConfigurationKey::INPUT_POINTER_DEVICE);
215         EXPECT_EQ(value, "false");
216     } else {
217         changeConfig.AddItem(AAFwk::GlobalConfigurationKey::INPUT_POINTER_DEVICE, "true");
218         result = appMgrServiceInner->UpdateConfiguration(changeConfig);
219         EXPECT_EQ(result, 0);
220         config = appMgrServiceInner->GetConfiguration();
221         EXPECT_NE(config, nullptr);
222         value = config->GetItem(AAFwk::GlobalConfigurationKey::INPUT_POINTER_DEVICE);
223         EXPECT_EQ(value, "true");
224     }
225 
226     HILOG_INFO("PointerDeviceUpdateConfig_0100 end");
227 }
228 
229 /**
230  * @tc.name: PreStartNWebSpawnProcess_001
231  * @tc.desc: prestart nwebspawn process.
232  * @tc.type: FUNC
233  * @tc.require: issueI5W4S7
234  */
235 HWTEST_F(AppMgrServiceInnerTest, PreStartNWebSpawnProcess_001, TestSize.Level0)
236 {
237     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
238     EXPECT_NE(appMgrServiceInner, nullptr);
239 
240     int callingPid = IPCSkeleton::GetCallingPid();
241     int ret = appMgrServiceInner->PreStartNWebSpawnProcess(callingPid);
242     EXPECT_NE(ret, ERR_OK);
243 }
244 
245 /**
246  * @tc.name: PreStartNWebSpawnProcess_002
247  * @tc.desc: prestart nwebspawn process.
248  * @tc.type: FUNC
249  * @tc.require: issueI5W4S7
250  */
251 HWTEST_F(AppMgrServiceInnerTest, PreStartNWebSpawnProcess_002, TestSize.Level0)
252 {
253     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
254     EXPECT_NE(appMgrServiceInner, nullptr);
255 
256     int callingPid = 0;
257     int ret = appMgrServiceInner->PreStartNWebSpawnProcess(callingPid);
258     EXPECT_EQ(ret, ERR_INVALID_VALUE);
259 }
260 
261 /**
262  * @tc.name: LoadAbility_001
263  * @tc.desc: load ability.
264  * @tc.type: FUNC
265  * @tc.require: issueI5W4S7
266  */
267 HWTEST_F(AppMgrServiceInnerTest, LoadAbility_001, TestSize.Level0)
268 {
269     HILOG_INFO("LoadAbility_001 start");
270     OHOS::sptr<IRemoteObject> token = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
271     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
272     EXPECT_NE(appMgrServiceInner, nullptr);
273 
274     appMgrServiceInner->appRunningManager_ = nullptr;
275     appMgrServiceInner->LoadAbility(token, nullptr, abilityInfo_, applicationInfo_, nullptr);
276 
277     auto appMgrServiceInner1 = std::make_shared<AppMgrServiceInner>();
278     EXPECT_NE(appMgrServiceInner1, nullptr);
279 
280     appMgrServiceInner1->remoteClientManager_->SetBundleManager(nullptr);
281     appMgrServiceInner1->LoadAbility(token, nullptr, abilityInfo_, applicationInfo_, nullptr);
282 
283     auto appMgrServiceInner2 = std::make_shared<AppMgrServiceInner>();
284     EXPECT_NE(appMgrServiceInner2, nullptr);
285 
286     appMgrServiceInner2->LoadAbility(token, nullptr, abilityInfo_, applicationInfo_, nullptr);
287     HILOG_INFO("LoadAbility_001 end");
288 }
289 
290 /**
291  * @tc.name: CheckLoadAbilityConditions_001
292  * @tc.desc: check load ability conditions.
293  * @tc.type: FUNC
294  * @tc.require: issueI5W4S7
295  */
296 HWTEST_F(AppMgrServiceInnerTest, CheckLoadAbilityConditions_001, TestSize.Level0)
297 {
298     HILOG_INFO("CheckLoadAbilityConditions_001 start");
299     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
300     EXPECT_NE(appMgrServiceInner, nullptr);
301 
302     OHOS::sptr<IRemoteObject> token = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
303 
304     appMgrServiceInner->CheckLoadAbilityConditions(nullptr, nullptr, nullptr);
305 
306     appMgrServiceInner->CheckLoadAbilityConditions(nullptr, abilityInfo_, nullptr);
307 
308     appMgrServiceInner->CheckLoadAbilityConditions(nullptr, nullptr, applicationInfo_);
309 
310     appMgrServiceInner->CheckLoadAbilityConditions(token, nullptr, nullptr);
311 
312     appMgrServiceInner->CheckLoadAbilityConditions(token, abilityInfo_, nullptr);
313 
314     appMgrServiceInner->CheckLoadAbilityConditions(nullptr, abilityInfo_, applicationInfo_);
315 
316     appMgrServiceInner->CheckLoadAbilityConditions(token, nullptr, applicationInfo_);
317 
318     appMgrServiceInner->CheckLoadAbilityConditions(token, abilityInfo_, applicationInfo_);
319 
320     EXPECT_NE(appMgrServiceInner, nullptr);
321     HILOG_INFO("CheckLoadAbilityConditions_001 end");
322 }
323 
324 /**
325  * @tc.name: MakeProcessName_001
326  * @tc.desc: make process name.
327  * @tc.type: FUNC
328  * @tc.require: issueI5W4S7
329  */
330 HWTEST_F(AppMgrServiceInnerTest, MakeProcessName_001, TestSize.Level0)
331 {
332     HILOG_INFO("MakeProcessName_001 start");
333     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
334     EXPECT_NE(appMgrServiceInner, nullptr);
335 
336     HapModuleInfo hapModuleInfo;
337     hapModuleInfo.moduleName = "module789";
338     std::string processName = "test_processName";
339     appMgrServiceInner->MakeProcessName(nullptr, nullptr, hapModuleInfo, 1, processName);
340     appMgrServiceInner->MakeProcessName(nullptr, applicationInfo_, hapModuleInfo, 1, processName);
341     appMgrServiceInner->MakeProcessName(abilityInfo_, nullptr, hapModuleInfo, 1, processName);
342     appMgrServiceInner->MakeProcessName(abilityInfo_, applicationInfo_, hapModuleInfo, 1, processName);
343 
344     EXPECT_NE(appMgrServiceInner, nullptr);
345     HILOG_INFO("MakeProcessName_001 end");
346 }
347 
348 /**
349  * @tc.name: MakeProcessName_002
350  * @tc.desc: make process name.
351  * @tc.type: FUNC
352  * @tc.require: issueI5W4S7
353  */
354 HWTEST_F(AppMgrServiceInnerTest, MakeProcessName_002, TestSize.Level0)
355 {
356     HILOG_INFO("MakeProcessName_002 start");
357     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
358     EXPECT_NE(appMgrServiceInner, nullptr);
359 
360     HapModuleInfo hapModuleInfo;
361     hapModuleInfo.moduleName = "module789";
362     std::string processName = "test_processName";
363     appMgrServiceInner->MakeProcessName(nullptr, hapModuleInfo, processName);
364     appMgrServiceInner->MakeProcessName(applicationInfo_, hapModuleInfo, processName);
365     hapModuleInfo.isStageBasedModel = false;
366     hapModuleInfo.process = "";
367     appMgrServiceInner->MakeProcessName(applicationInfo_, hapModuleInfo, processName);
368 
369     hapModuleInfo.isStageBasedModel = true;
370     hapModuleInfo.process = "";
371     appMgrServiceInner->MakeProcessName(applicationInfo_, hapModuleInfo, processName);
372 
373     hapModuleInfo.isStageBasedModel = false;
374     hapModuleInfo.process = "test_process";
375     appMgrServiceInner->MakeProcessName(applicationInfo_, hapModuleInfo, processName);
376 
377     hapModuleInfo.isStageBasedModel = true;
378     hapModuleInfo.process = "test_process";
379     appMgrServiceInner->MakeProcessName(applicationInfo_, hapModuleInfo, processName);
380 
381     hapModuleInfo.isStageBasedModel = false;
382     applicationInfo_->process = "";
383     appMgrServiceInner->MakeProcessName(applicationInfo_, hapModuleInfo, processName);
384 
385     hapModuleInfo.isStageBasedModel = false;
386     applicationInfo_->process = "test_process";
387     appMgrServiceInner->MakeProcessName(applicationInfo_, hapModuleInfo, processName);
388 
389     EXPECT_NE(appMgrServiceInner, nullptr);
390     HILOG_INFO("MakeProcessName_002 end");
391 }
392 
393 /**
394  * @tc.name: GetBundleAndHapInfo_001
395  * @tc.desc: get bundle and hapInfo.
396  * @tc.type: FUNC
397  * @tc.require: issueI5W4S7
398  */
399 HWTEST_F(AppMgrServiceInnerTest, GetBundleAndHapInfo_001, TestSize.Level0)
400 {
401     HILOG_INFO("GetBundleAndHapInfo_001 start");
402     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
403     EXPECT_NE(appMgrServiceInner, nullptr);
404 
405     BundleInfo bundleInfo;
406     HapModuleInfo hapModuleInfo;
407     appMgrServiceInner->GetBundleAndHapInfo(*abilityInfo_, applicationInfo_, bundleInfo, hapModuleInfo, 1);
408 
409     appMgrServiceInner->remoteClientManager_->SetBundleManager(nullptr);
410     appMgrServiceInner->GetBundleAndHapInfo(*abilityInfo_, applicationInfo_, bundleInfo, hapModuleInfo, 1);
411     HILOG_INFO("GetBundleAndHapInfo_001 end");
412 }
413 
414 /**
415  * @tc.name: AttachApplication_001
416  * @tc.desc: attach application.
417  * @tc.type: FUNC
418  * @tc.require: issueI5W4S7
419  */
420 HWTEST_F(AppMgrServiceInnerTest, AttachApplication_001, TestSize.Level0)
421 {
422     HILOG_INFO("AttachApplication_001 start");
423     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
424     EXPECT_NE(appMgrServiceInner, nullptr);
425 
426     appMgrServiceInner->AttachApplication(0, nullptr);
427 
428     appMgrServiceInner->AttachApplication(1, nullptr);
429 
430     sptr<MockAppScheduler> mockAppScheduler = new (std::nothrow) MockAppScheduler();
431     sptr<IAppScheduler> client = iface_cast<IAppScheduler>(mockAppScheduler.GetRefPtr());
432     appMgrServiceInner->AttachApplication(1, client);
433     HILOG_INFO("AttachApplication_001 end");
434 }
435 
436 /**
437  * @tc.name: LaunchApplication_001
438  * @tc.desc: launch application.
439  * @tc.type: FUNC
440  * @tc.require: issueI5W4S7
441  */
442 HWTEST_F(AppMgrServiceInnerTest, LaunchApplication_001, TestSize.Level0)
443 {
444     HILOG_INFO("LaunchApplication_001 start");
445     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
446     EXPECT_NE(appMgrServiceInner, nullptr);
447 
448     appMgrServiceInner->LaunchApplication(nullptr);
449 
450     BundleInfo info;
451     std::string processName = "test_processName";
452     std::shared_ptr<AppRunningRecord> appRecord =
453         appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info);
454     recordId_ += 1;
455     appMgrServiceInner->LaunchApplication(appRecord);
456 
457     appRecord->SetState(ApplicationState::APP_STATE_FOREGROUND);
458     appMgrServiceInner->LaunchApplication(appRecord);
459 
460     appRecord->SetState(ApplicationState::APP_STATE_CREATE);
461     appMgrServiceInner->LaunchApplication(appRecord);
462 
463     appRecord->SetKeepAliveAppState(false, true);
464     appMgrServiceInner->LaunchApplication(appRecord);
465 
466     appRecord->SetKeepAliveAppState(true, false);
467     appMgrServiceInner->LaunchApplication(appRecord);
468 
469     appRecord->SetKeepAliveAppState(true, true);
470     appMgrServiceInner->LaunchApplication(appRecord);
471 
472     appRecord->SetKeepAliveAppState(false, false);
473     appMgrServiceInner->LaunchApplication(appRecord);
474 
475     Want want;
476     appRecord->SetSpecifiedAbilityFlagAndWant(false, want, "");
477     appMgrServiceInner->LaunchApplication(appRecord);
478 
479     appRecord->SetSpecifiedAbilityFlagAndWant(true, want, "");
480     appMgrServiceInner->LaunchApplication(appRecord);
481 
482     appMgrServiceInner->configuration_ = nullptr;
483     appMgrServiceInner->LaunchApplication(appRecord);
484     HILOG_INFO("LaunchApplication_001 end");
485 }
486 
487 /**
488  * @tc.name: AddAbilityStageDone_001
489  * @tc.desc: add ability stage done.
490  * @tc.type: FUNC
491  * @tc.require: issueI5W4S7
492  */
493 HWTEST_F(AppMgrServiceInnerTest, AddAbilityStageDone_001, TestSize.Level0)
494 {
495     HILOG_INFO("AddAbilityStageDone_001 start");
496     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
497     EXPECT_NE(appMgrServiceInner, nullptr);
498 
499     appMgrServiceInner->AddAbilityStageDone(99);
500 
501     BundleInfo info;
502     std::string processName = "test_processName";
503     appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info);
504     recordId_ += 1;
505 
506     appMgrServiceInner->AddAbilityStageDone(recordId_);
507     HILOG_INFO("AddAbilityStageDone_001 end");
508 }
509 
510 /**
511  * @tc.name: ApplicationForegrounded_001
512  * @tc.desc: application foregrounded.
513  * @tc.type: FUNC
514  * @tc.require: issueI5W4S7
515  */
516 HWTEST_F(AppMgrServiceInnerTest, ApplicationForegrounded_001, TestSize.Level0)
517 {
518     HILOG_INFO("ApplicationForegrounded_001 start");
519     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
520     EXPECT_NE(appMgrServiceInner, nullptr);
521 
522     appMgrServiceInner->ApplicationForegrounded(99);
523 
524     BundleInfo info;
525     std::string processName = "test_processName";
526     appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info);
527     recordId_ += 1;
528 
529     appMgrServiceInner->ApplicationForegrounded(recordId_);
530     HILOG_INFO("ApplicationForegrounded_001 end");
531 }
532 
533 /**
534  * @tc.name: ApplicationForegrounded_002
535  * @tc.desc: application foregrounded.
536  * @tc.type: FUNC
537  * @tc.require: issueI5W4S7
538  */
539 HWTEST_F(AppMgrServiceInnerTest, ApplicationForegrounded_002, TestSize.Level0)
540 {
541     HILOG_INFO("ApplicationForegrounded_002 start");
542     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
543     EXPECT_NE(appMgrServiceInner, nullptr);
544 
545     BundleInfo info;
546     std::string processName = "test_processName";
547     auto record = appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info);
548     record->SetUpdateStateFromService(true);
549     recordId_ += 1;
550 
551     appMgrServiceInner->ApplicationForegrounded(recordId_);
552     HILOG_INFO("ApplicationForegrounded_002 end");
553 }
554 
555 /**
556  * @tc.name: ApplicationForegrounded_003
557  * @tc.desc: application foregrounded.
558  * @tc.type: FUNC
559  * @tc.require: issueI5W4S7
560  */
561 HWTEST_F(AppMgrServiceInnerTest, ApplicationForegrounded_003, TestSize.Level0)
562 {
563     HILOG_INFO("ApplicationForegrounded_003 start");
564     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
565     EXPECT_NE(appMgrServiceInner, nullptr);
566 
567     BundleInfo info;
568     std::string processName = "test_processName";
569     auto record = appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info);
570     recordId_ += 1;
571     record->SetUpdateStateFromService(true);
572     auto record2 = appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info);
573     recordId_ += 1;
574     std::shared_ptr<PriorityObject> priorityObject = std::make_shared<PriorityObject>();
575     std::string callerBundleName = "callerBundleName";
576     priorityObject->SetPid(1);
577     record2->priorityObject_ = priorityObject;
578     record2->mainBundleName_ = callerBundleName;
579     record->SetCallerPid(1);
580 
581     appMgrServiceInner->ApplicationForegrounded(--recordId_);
582     HILOG_INFO("ApplicationForegrounded_003 end");
583 }
584 
585 /**
586  * @tc.name: ApplicationBackgrounded_001
587  * @tc.desc: application backgrounded.
588  * @tc.type: FUNC
589  * @tc.require: issueI5W4S7
590  */
591 HWTEST_F(AppMgrServiceInnerTest, ApplicationBackgrounded_001, TestSize.Level0)
592 {
593     HILOG_INFO("ApplicationBackgrounded_001 start");
594     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
595     EXPECT_NE(appMgrServiceInner, nullptr);
596     appMgrServiceInner->Init();
597 
598     appMgrServiceInner->ApplicationBackgrounded(99);
599 
600     BundleInfo info;
601     std::string processName = "test_processName";
602     auto appRecord =
603         appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info);
604     EXPECT_NE(appRecord, nullptr);
605     recordId_ += 1;
606 
607     appMgrServiceInner->ApplicationBackgrounded(recordId_);
608 
609     appRecord->SetState(ApplicationState::APP_STATE_FOREGROUND);
610     appMgrServiceInner->ApplicationBackgrounded(recordId_);
611 
612     HILOG_INFO("ApplicationBackgrounded_001 end");
613 }
614 
615 /**
616  * @tc.name: ApplicationTerminated_001
617  * @tc.desc: application terminated.
618  * @tc.type: FUNC
619  * @tc.require: issueI5W4S7
620  */
621 HWTEST_F(AppMgrServiceInnerTest, ApplicationTerminated_001, TestSize.Level0)
622 {
623     HILOG_INFO("ApplicationTerminated_001 start");
624     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
625     EXPECT_NE(appMgrServiceInner, nullptr);
626 
627     appMgrServiceInner->ApplicationTerminated(99);
628 
629     BundleInfo info;
630     std::string processName = "test_processName";
631     auto appRecord =
632         appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info);
633     EXPECT_NE(appRecord, nullptr);
634     recordId_ += 1;
635 
636     appMgrServiceInner->ApplicationTerminated(recordId_);
637 
638     appRecord->SetKeepAliveAppState(false, true);
639     appMgrServiceInner->ApplicationTerminated(recordId_);
640 
641     appRecord->SetKeepAliveAppState(true, false);
642     appMgrServiceInner->ApplicationTerminated(recordId_);
643 
644     appRecord->SetKeepAliveAppState(true, true);
645     appMgrServiceInner->ApplicationTerminated(recordId_);
646 
647     appRecord->SetKeepAliveAppState(false, false);
648     appMgrServiceInner->ApplicationTerminated(recordId_);
649 
650     appRecord->SetState(ApplicationState::APP_STATE_FOREGROUND);
651     appMgrServiceInner->ApplicationTerminated(recordId_);
652 
653     appRecord->SetState(ApplicationState::APP_STATE_BACKGROUND);
654     appMgrServiceInner->ApplicationTerminated(recordId_);
655 
656     appMgrServiceInner->appRunningManager_ = nullptr;
657     appMgrServiceInner->ApplicationTerminated(recordId_);
658 
659     HILOG_INFO("ApplicationTerminated_001 end");
660 }
661 
662 /**
663  * @tc.name: KillApplication_001
664  * @tc.desc: kill application.
665  * @tc.type: FUNC
666  * @tc.require: issueI5W4S7
667  */
668 HWTEST_F(AppMgrServiceInnerTest, KillApplication_001, TestSize.Level0)
669 {
670     HILOG_INFO("KillApplication_001 start");
671     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
672     EXPECT_NE(appMgrServiceInner, nullptr);
673 
674     std::string bundleName = "test_bundleName";
675     appMgrServiceInner->KillApplication(bundleName);
676 
677     appMgrServiceInner->appRunningManager_ = nullptr;
678     appMgrServiceInner->KillApplication(bundleName);
679 
680     HILOG_INFO("KillApplication_001 end");
681 }
682 
683 /**
684  * @tc.name: KillApplicationByUid_001
685  * @tc.desc: kill application by uid.
686  * @tc.type: FUNC
687  * @tc.require: issueI5W4S7
688  */
689 HWTEST_F(AppMgrServiceInnerTest, KillApplicationByUid_001, TestSize.Level0)
690 {
691     HILOG_INFO("KillApplicationByUid_001 start");
692     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
693     EXPECT_NE(appMgrServiceInner, nullptr);
694 
695     std::string bundleName = "test_bundleName";
696     appMgrServiceInner->KillApplicationByUid(bundleName, 0);
697 
698     appMgrServiceInner->remoteClientManager_->SetBundleManager(nullptr);
699     appMgrServiceInner->KillApplicationByUid(bundleName, 0);
700 
701     appMgrServiceInner->remoteClientManager_ = nullptr;
702     appMgrServiceInner->KillApplicationByUid(bundleName, 0);
703 
704     appMgrServiceInner->appRunningManager_ = nullptr;
705     appMgrServiceInner->KillApplicationByUid(bundleName, 0);
706 
707     HILOG_INFO("KillApplicationByUid_001 end");
708 }
709 
710 /**
711  * @tc.name: KillApplicationSelf_001
712  * @tc.desc: kill application self.
713  * @tc.type: FUNC
714  * @tc.require: issueI5W4S7
715  */
716 HWTEST_F(AppMgrServiceInnerTest, KillApplicationSelf_001, TestSize.Level0)
717 {
718     HILOG_INFO("KillApplicationSelf_001 start");
719     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
720     EXPECT_NE(appMgrServiceInner, nullptr);
721 
722     EXPECT_EQ(appMgrServiceInner->KillApplicationSelf(), ERR_INVALID_VALUE);
723 
724     appMgrServiceInner->appRunningManager_ = nullptr;
725     EXPECT_EQ(appMgrServiceInner->KillApplicationSelf(), ERR_NO_INIT);
726 
727     HILOG_INFO("KillApplicationSelf_001 end");
728 }
729 
730 /**
731  * @tc.name: KillApplicationByUserId_001
732  * @tc.desc: kill application by user id.
733  * @tc.type: FUNC
734  * @tc.require: issueI5W4S7
735  */
736 HWTEST_F(AppMgrServiceInnerTest, KillApplicationByUserId_001, TestSize.Level0)
737 {
738     HILOG_INFO("KillApplicationByUserId_001 start");
739     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
740     EXPECT_NE(appMgrServiceInner, nullptr);
741 
742     std::string bundleName = "test_bundleName";
743     int result = appMgrServiceInner->KillApplicationByUserId(bundleName, 0);
744     EXPECT_EQ(result, 0);
745 
746     appMgrServiceInner->remoteClientManager_->SetBundleManager(nullptr);
747     appMgrServiceInner->KillApplicationByUserId(bundleName, 0);
748     EXPECT_EQ(result, 0);
749 
750     appMgrServiceInner->remoteClientManager_ = nullptr;
751     appMgrServiceInner->KillApplicationByUserId(bundleName, 0);
752     EXPECT_EQ(result, 0);
753 
754     appMgrServiceInner->appRunningManager_ = nullptr;
755     appMgrServiceInner->KillApplicationByUserId(bundleName, 0);
756     EXPECT_EQ(result, 0);
757 
758     HILOG_INFO("KillApplicationByUserId_001 end");
759 }
760 
761 /**
762  * @tc.name: KillApplicationByUserIdLocked_001
763  * @tc.desc: kill application by user id locked.
764  * @tc.type: FUNC
765  * @tc.require: issueI5W4S7
766  */
767 HWTEST_F(AppMgrServiceInnerTest, KillApplicationByUserIdLocked_001, TestSize.Level0)
768 {
769     HILOG_INFO("KillApplicationByUserIdLocked_001 start");
770     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
771     EXPECT_NE(appMgrServiceInner, nullptr);
772 
773     std::string bundleName = "test_bundleName";
774     int result = appMgrServiceInner->KillApplicationByUserIdLocked(bundleName, 0);
775     EXPECT_EQ(result, 0);
776 
777     appMgrServiceInner->remoteClientManager_->SetBundleManager(nullptr);
778     appMgrServiceInner->KillApplicationByUserIdLocked(bundleName, 0);
779     EXPECT_EQ(result, 0);
780 
781     appMgrServiceInner->remoteClientManager_ = nullptr;
782     appMgrServiceInner->KillApplicationByUserIdLocked(bundleName, 0);
783     EXPECT_EQ(result, 0);
784 
785     appMgrServiceInner->appRunningManager_ = nullptr;
786     appMgrServiceInner->KillApplicationByUserIdLocked(bundleName, 0);
787     EXPECT_EQ(result, 0);
788 
789     HILOG_INFO("KillApplicationByUserIdLocked_001 end");
790 }
791 
792 /**
793  * @tc.name: ClearUpApplicationData_001
794  * @tc.desc: clear up application data.
795  * @tc.type: FUNC
796  * @tc.require: issueI5W4S7
797  */
798 HWTEST_F(AppMgrServiceInnerTest, ClearUpApplicationData_001, TestSize.Level0)
799 {
800     HILOG_INFO("ClearUpApplicationData_001 start");
801     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
802     EXPECT_NE(appMgrServiceInner, nullptr);
803 
804     std::string bundleName = "test_bundleName";
805     appMgrServiceInner->ClearUpApplicationData(bundleName, 0, 0);
806 
807     HILOG_INFO("ClearUpApplicationData_001 end");
808 }
809 
810 /**
811  * @tc.name: ClearUpApplicationDataByUserId_001
812  * @tc.desc: clear up application data by user id.
813  * @tc.type: FUNC
814  * @tc.require: issueI5W4S7
815  */
816 HWTEST_F(AppMgrServiceInnerTest, ClearUpApplicationDataByUserId_001, TestSize.Level0)
817 {
818     HILOG_INFO("ClearUpApplicationDataByUserId_001 start");
819     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
820     EXPECT_NE(appMgrServiceInner, nullptr);
821 
822     std::string bundleName = "test_bundleName";
823     appMgrServiceInner->ClearUpApplicationDataByUserId(bundleName, 0, 0, 0);
824     appMgrServiceInner->ClearUpApplicationDataByUserId(bundleName, 1, 0, 0);
825     appMgrServiceInner->ClearUpApplicationDataByUserId(bundleName, 1, 1, 0);
826 
827     appMgrServiceInner->appRunningManager_ = nullptr;
828     appMgrServiceInner->ClearUpApplicationDataByUserId(bundleName, 1, 1, 0);
829 
830     appMgrServiceInner->remoteClientManager_->SetBundleManager(nullptr);
831     appMgrServiceInner->ClearUpApplicationDataByUserId(bundleName, 1, 1, 0);
832 
833     HILOG_INFO("ClearUpApplicationDataByUserId_001 end");
834 }
835 
836 /**
837  * @tc.name: GetAllRunningProcesses_001
838  * @tc.desc: get all running processes.
839  * @tc.type: FUNC
840  * @tc.require: issueI5W4S7
841  */
842 HWTEST_F(AppMgrServiceInnerTest, GetAllRunningProcesses_001, TestSize.Level0)
843 {
844     HILOG_INFO("GetAllRunningProcesses_001 start");
845     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
846     EXPECT_NE(appMgrServiceInner, nullptr);
847 
848     std::vector<RunningProcessInfo> info;
849     appMgrServiceInner->GetAllRunningProcesses(info);
850 
851     HILOG_INFO("GetAllRunningProcesses_001 end");
852 }
853 
854 /**
855  * @tc.name: GetProcessRunningInfosByUserId_001
856  * @tc.desc: get process running infos by user id.
857  * @tc.type: FUNC
858  * @tc.require: issueI5W4S7
859  */
860 HWTEST_F(AppMgrServiceInnerTest, GetProcessRunningInfosByUserId_001, TestSize.Level0)
861 {
862     HILOG_INFO("GetProcessRunningInfosByUserId_001 start");
863     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
864     EXPECT_NE(appMgrServiceInner, nullptr);
865 
866     std::vector<RunningProcessInfo> info;
867     appMgrServiceInner->GetProcessRunningInfosByUserId(info, 0);
868 
869     HILOG_INFO("GetProcessRunningInfosByUserId_001 end");
870 }
871 
872 /**
873  * @tc.name: GetAllRenderProcesses_001
874  * @tc.desc: get all render processes.
875  * @tc.type: FUNC
876  */
877 HWTEST_F(AppMgrServiceInnerTest, GetAllRenderProcesses_001, TestSize.Level0)
878 {
879     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
880     EXPECT_NE(appMgrServiceInner, nullptr);
881 
882     std::vector<RenderProcessInfo> info;
883     appMgrServiceInner->GetAllRenderProcesses(info);
884 }
885 
886 /**
887  * @tc.name: NotifyMemoryLevel_001
888  * @tc.desc: notify memory level.
889  * @tc.type: FUNC
890  * @tc.require: issueI5W4S7
891  */
892 HWTEST_F(AppMgrServiceInnerTest, NotifyMemoryLevel_001, TestSize.Level0)
893 {
894     HILOG_INFO("NotifyMemoryLevel_001 start");
895     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
896     EXPECT_NE(appMgrServiceInner, nullptr);
897 
898     std::vector<RunningProcessInfo> info;
899     int result = appMgrServiceInner->NotifyMemoryLevel(0);
900     EXPECT_EQ(result, 0);
901 
902     result = appMgrServiceInner->NotifyMemoryLevel(1);
903     EXPECT_EQ(result, 0);
904 
905     result = appMgrServiceInner->NotifyMemoryLevel(2);
906     EXPECT_EQ(result, 0);
907 
908     result = appMgrServiceInner->NotifyMemoryLevel(3);
909     EXPECT_EQ(result, 22);
910 
911     appMgrServiceInner->appRunningManager_ = nullptr;
912     result = appMgrServiceInner->NotifyMemoryLevel(3);
913     EXPECT_EQ(result, ERR_INVALID_VALUE);
914 
915     HILOG_INFO("NotifyMemoryLevel_001 end");
916 }
917 
918 /**
919  * @tc.name: KillProcessByPid_001
920  * @tc.desc: kill process by pid.
921  * @tc.type: FUNC
922  * @tc.require: issueI5W4S7
923  */
924 HWTEST_F(AppMgrServiceInnerTest, KillProcessByPid_001, TestSize.Level0)
925 {
926     HILOG_INFO("KillProcessByPid_001 start");
927     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
928     EXPECT_NE(appMgrServiceInner, nullptr);
929 
930     int result = appMgrServiceInner->KillProcessByPid(0);
931     EXPECT_EQ(result, -1);
932 
933     result = appMgrServiceInner->KillProcessByPid(1);
934     EXPECT_EQ(result, 0);
935 
936     HILOG_INFO("KillProcessByPid_001 end");
937 }
938 
939 /**
940  * @tc.name: GetAllPids_001
941  * @tc.desc: get all pids.
942  * @tc.type: FUNC
943  * @tc.require: issueI5W4S7
944  */
945 HWTEST_F(AppMgrServiceInnerTest, GetAllPids_001, TestSize.Level0)
946 {
947     HILOG_INFO("GetAllPids_001 start");
948     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
949     EXPECT_NE(appMgrServiceInner, nullptr);
950 
951     std::list<pid_t> pids;
952     bool result = appMgrServiceInner->GetAllPids(pids);
953     EXPECT_FALSE(result);
954 
955     pids.push_back(1);
956     result = appMgrServiceInner->GetAllPids(pids);
957     EXPECT_TRUE(result);
958 
959     std::string appName = "test_appName";
960     std::string processName = "test_processName";
961     appMgrServiceInner->appProcessManager_->AddAppToRecentList(appName, processName, 0, 0);
962     result = appMgrServiceInner->GetAllPids(pids);
963     EXPECT_TRUE(result);
964 
965     HILOG_INFO("GetAllPids_001 end");
966 }
967 
968 /**
969  * @tc.name: ProcessExist_001
970  * @tc.desc: process exist.
971  * @tc.type: FUNC
972  * @tc.require: issueI5W4S7
973  */
974 HWTEST_F(AppMgrServiceInnerTest, ProcessExist_001, TestSize.Level0)
975 {
976     HILOG_INFO("ProcessExist_001 start");
977     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
978     EXPECT_NE(appMgrServiceInner, nullptr);
979 
980     pid_t pid = 0;
981     bool result = appMgrServiceInner->ProcessExist(pid);
982     EXPECT_FALSE(result);
983 
984     HILOG_INFO("ProcessExist_001 end");
985 }
986 
987 /**
988  * @tc.name: CreateAppRunningRecord_001
989  * @tc.desc: create app running record.
990  * @tc.type: FUNC
991  * @tc.require: issueI5W4S7
992  */
993 HWTEST_F(AppMgrServiceInnerTest, CreateAppRunningRecord_001, TestSize.Level0)
994 {
995     HILOG_INFO("CreateAppRunningRecord_001 start");
996     OHOS::sptr<IRemoteObject> token = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
997     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
998     EXPECT_NE(appMgrServiceInner, nullptr);
999 
1000     BundleInfo bundleInfo;
1001     HapModuleInfo hapModuleInfo;
1002     std::shared_ptr<AAFwk::Want> want;
1003     std::string processName = "test_processName";
1004 
1005     std::shared_ptr<AppRunningRecord> appRecord = appMgrServiceInner->CreateAppRunningRecord(nullptr, nullptr,
1006         nullptr, nullptr, "", bundleInfo, hapModuleInfo, nullptr);
1007     EXPECT_EQ(appRecord, nullptr);
1008 
1009     appRecord = appMgrServiceInner->CreateAppRunningRecord(token, nullptr,
1010         nullptr, nullptr, "", bundleInfo, hapModuleInfo, nullptr);
1011     EXPECT_EQ(appRecord, nullptr);
1012 
1013     appRecord = appMgrServiceInner->CreateAppRunningRecord(token, nullptr,
1014         applicationInfo_, nullptr, "", bundleInfo, hapModuleInfo, nullptr);
1015     EXPECT_EQ(appRecord, nullptr);
1016 
1017     appRecord = appMgrServiceInner->CreateAppRunningRecord(token, nullptr,
1018         applicationInfo_, abilityInfo_, "", bundleInfo, hapModuleInfo, nullptr);
1019     EXPECT_EQ(appRecord, nullptr);
1020 
1021     appRecord = appMgrServiceInner->CreateAppRunningRecord(token, nullptr,
1022         applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, nullptr);
1023     EXPECT_NE(appRecord, nullptr);
1024 
1025     appRecord = appMgrServiceInner->CreateAppRunningRecord(token, nullptr,
1026         applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, nullptr);
1027     EXPECT_NE(appRecord, nullptr);
1028 
1029     appRecord = appMgrServiceInner->CreateAppRunningRecord(token, nullptr,
1030         applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, nullptr);
1031     EXPECT_NE(appRecord, nullptr);
1032 
1033     std::shared_ptr<AppRunningRecord> appRecord1 = appMgrServiceInner->CreateAppRunningRecord(token, nullptr,
1034         nullptr, abilityInfo_, processName, bundleInfo, hapModuleInfo, want);
1035     EXPECT_EQ(appRecord1, nullptr);
1036 
1037     std::shared_ptr<AppRunningRecord> appRecord2 = appMgrServiceInner->CreateAppRunningRecord(token, nullptr,
1038         applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want);
1039     EXPECT_NE(appRecord2, nullptr);
1040 
1041     want = std::make_shared<Want>();
1042     const std::string COLD_START = "coldStart";
1043     want->SetParam(COLD_START, true);
1044     std::shared_ptr<AppRunningRecord> appRecord3 = appMgrServiceInner->CreateAppRunningRecord(token, nullptr,
1045         applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want);
1046     EXPECT_NE(appRecord3, nullptr);
1047 
1048     want->SetParam(COLD_START, false);
1049     std::shared_ptr<AppRunningRecord> appRecord4 = appMgrServiceInner->CreateAppRunningRecord(token, nullptr,
1050         applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want);
1051     EXPECT_NE(appRecord4, nullptr);
1052 
1053     appMgrServiceInner->appRunningManager_ = nullptr;
1054     std::shared_ptr<AppRunningRecord> appRecord5 = appMgrServiceInner->CreateAppRunningRecord(token, nullptr,
1055         applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want);
1056     EXPECT_EQ(appRecord5, nullptr);
1057 
1058     HILOG_INFO("CreateAppRunningRecord_001 end");
1059 }
1060 
1061 /**
1062  * @tc.name: TerminateAbility_001
1063  * @tc.desc: terminate ability.
1064  * @tc.type: FUNC
1065  * @tc.require: issueI5W4S7
1066  */
1067 HWTEST_F(AppMgrServiceInnerTest, TerminateAbility_001, TestSize.Level0)
1068 {
1069     HILOG_INFO("TerminateAbility_001 start");
1070     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1071     EXPECT_NE(appMgrServiceInner, nullptr);
1072 
1073     appMgrServiceInner->TerminateAbility(nullptr, true);
1074     appMgrServiceInner->TerminateAbility(nullptr, false);
1075 
1076     OHOS::sptr<IRemoteObject> token = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
1077     appMgrServiceInner->TerminateAbility(token, true);
1078     appMgrServiceInner->TerminateAbility(token, false);
1079 
1080     appMgrServiceInner->appRunningManager_ = nullptr;
1081     appMgrServiceInner->TerminateAbility(token, true);
1082 
1083     HILOG_INFO("TerminateAbility_001 end");
1084 }
1085 
1086 /**
1087  * @tc.name: UpdateAbilityState_001
1088  * @tc.desc: update ability state.
1089  * @tc.type: FUNC
1090  * @tc.require: issueI5W4S7
1091  */
1092 HWTEST_F(AppMgrServiceInnerTest, UpdateAbilityState_001, TestSize.Level0)
1093 {
1094     HILOG_INFO("UpdateAbilityState_001 start");
1095     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1096     EXPECT_NE(appMgrServiceInner, nullptr);
1097 
1098     appMgrServiceInner->UpdateAbilityState(nullptr, AbilityState::ABILITY_STATE_CREATE);
1099 
1100     OHOS::sptr<IRemoteObject> token = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
1101     appMgrServiceInner->UpdateAbilityState(token, AbilityState::ABILITY_STATE_CREATE);
1102 
1103     BundleInfo bundleInfo;
1104     HapModuleInfo hapModuleInfo;
1105     std::shared_ptr<AAFwk::Want> want;
1106     std::string processName = "test_processName";
1107     std::shared_ptr<AppRunningRecord> appRecord = appMgrServiceInner->CreateAppRunningRecord(token, nullptr,
1108         applicationInfo_, nullptr, processName, bundleInfo, hapModuleInfo, want);
1109     EXPECT_NE(appRecord, nullptr);
1110     appMgrServiceInner->UpdateAbilityState(token, AbilityState::ABILITY_STATE_CREATE);
1111 
1112     OHOS::sptr<IRemoteObject> token1 = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
1113     std::shared_ptr<AppRunningRecord> appRecord1 = appMgrServiceInner->CreateAppRunningRecord(token1, nullptr,
1114         applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want);
1115     EXPECT_NE(appRecord1, nullptr);
1116 
1117     appMgrServiceInner->UpdateAbilityState(token1, AbilityState::ABILITY_STATE_READY);
1118     appMgrServiceInner->UpdateAbilityState(token1, AbilityState::ABILITY_STATE_CREATE);
1119 
1120     auto abilityRecord1 =
1121         appMgrServiceInner->GetAppRunningRecordByAbilityToken(token1)->GetAbilityRunningRecordByToken(token1);
1122     abilityRecord1->SetState(AbilityState::ABILITY_STATE_TERMINATED);
1123     appMgrServiceInner->UpdateAbilityState(token1, AbilityState::ABILITY_STATE_TERMINATED);
1124 
1125     abilityRecord1->SetState(AbilityState::ABILITY_STATE_CONNECTED);
1126     appMgrServiceInner->UpdateAbilityState(token1, AbilityState::ABILITY_STATE_CONNECTED);
1127 
1128     abilityRecord1->SetState(AbilityState::ABILITY_STATE_DISCONNECTED);
1129     appMgrServiceInner->UpdateAbilityState(token1, AbilityState::ABILITY_STATE_DISCONNECTED);
1130 
1131     abilityRecord1->SetState(AbilityState::ABILITY_STATE_END);
1132     appMgrServiceInner->UpdateAbilityState(token1, AbilityState::ABILITY_STATE_END);
1133 
1134     abilityRecord1->SetState(AbilityState::ABILITY_STATE_BACKGROUND);
1135     appMgrServiceInner->UpdateAbilityState(token1, AbilityState::ABILITY_STATE_BACKGROUND);
1136 
1137     OHOS::sptr<IRemoteObject> token2 = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
1138     abilityInfo_->type = AbilityType::SERVICE;
1139     std::shared_ptr<AppRunningRecord> appRecord2 = appMgrServiceInner->CreateAppRunningRecord(token2, nullptr,
1140         applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want);
1141     EXPECT_NE(appRecord2, nullptr);
1142     appMgrServiceInner->UpdateAbilityState(token2, AbilityState::ABILITY_STATE_CREATE);
1143 
1144     auto abilityRecord2 =
1145         appMgrServiceInner->GetAppRunningRecordByAbilityToken(token2)->GetAbilityRunningRecordByToken(token2);
1146     abilityRecord2->SetState(AbilityState::ABILITY_STATE_TERMINATED);
1147     appMgrServiceInner->UpdateAbilityState(token2, AbilityState::ABILITY_STATE_TERMINATED);
1148 
1149     abilityRecord2->SetState(AbilityState::ABILITY_STATE_CONNECTED);
1150     appMgrServiceInner->UpdateAbilityState(token2, AbilityState::ABILITY_STATE_CONNECTED);
1151 
1152     abilityRecord2->SetState(AbilityState::ABILITY_STATE_DISCONNECTED);
1153     appMgrServiceInner->UpdateAbilityState(token2, AbilityState::ABILITY_STATE_DISCONNECTED);
1154 
1155     abilityRecord2->SetState(AbilityState::ABILITY_STATE_END);
1156     appMgrServiceInner->UpdateAbilityState(token2, AbilityState::ABILITY_STATE_END);
1157 
1158     abilityRecord2->SetState(AbilityState::ABILITY_STATE_BACKGROUND);
1159     appMgrServiceInner->UpdateAbilityState(token2, AbilityState::ABILITY_STATE_BACKGROUND);
1160 
1161     HILOG_INFO("UpdateAbilityState_001 end");
1162 }
1163 
1164 /**
1165  * @tc.name: UpdateExtensionState_001
1166  * @tc.desc: update extension state.
1167  * @tc.type: FUNC
1168  * @tc.require: issueI5W4S7
1169  */
1170 HWTEST_F(AppMgrServiceInnerTest, UpdateExtensionState_001, TestSize.Level0)
1171 {
1172     HILOG_INFO("UpdateExtensionState_001 start");
1173     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1174     EXPECT_NE(appMgrServiceInner, nullptr);
1175 
1176     appMgrServiceInner->UpdateExtensionState(nullptr, ExtensionState::EXTENSION_STATE_CREATE);
1177 
1178     OHOS::sptr<IRemoteObject> token = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
1179     appMgrServiceInner->UpdateExtensionState(token, ExtensionState::EXTENSION_STATE_CREATE);
1180 
1181     BundleInfo bundleInfo;
1182     HapModuleInfo hapModuleInfo;
1183     std::shared_ptr<AAFwk::Want> want;
1184     std::string processName = "test_processName";
1185     std::shared_ptr<AppRunningRecord> appRecord = appMgrServiceInner->CreateAppRunningRecord(token, nullptr,
1186         applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want);
1187     EXPECT_NE(appRecord, nullptr);
1188     appMgrServiceInner->UpdateExtensionState(token, ExtensionState::EXTENSION_STATE_CREATE);
1189 
1190     HILOG_INFO("UpdateExtensionState_001 end");
1191 }
1192 
1193 /**
1194  * @tc.name: OpenAppSpawnConnection_001
1195  * @tc.desc: open app spawn connection.
1196  * @tc.type: FUNC
1197  * @tc.require: issueI5W4S7
1198  */
1199 HWTEST_F(AppMgrServiceInnerTest, OpenAppSpawnConnection_001, TestSize.Level0)
1200 {
1201     HILOG_INFO("OpenAppSpawnConnection_001 start");
1202     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1203     EXPECT_NE(appMgrServiceInner, nullptr);
1204 
1205     appMgrServiceInner->remoteClientManager_->SetSpawnClient(nullptr);
1206     auto errorCode = appMgrServiceInner->OpenAppSpawnConnection();
1207     EXPECT_EQ(errorCode, ERR_APPEXECFWK_BAD_APPSPAWN_CLIENT);
1208 
1209     appMgrServiceInner->remoteClientManager_ = nullptr;
1210     auto errorCode1 = appMgrServiceInner->OpenAppSpawnConnection();
1211     EXPECT_EQ(errorCode1, ERR_INVALID_VALUE);
1212 
1213     HILOG_INFO("OpenAppSpawnConnection_001 end");
1214 }
1215 
1216 /**
1217  * @tc.name: CloseAppSpawnConnection_001
1218  * @tc.desc: close app spawn connection.
1219  * @tc.type: FUNC
1220  * @tc.require: issueI5W4S7
1221  */
1222 HWTEST_F(AppMgrServiceInnerTest, CloseAppSpawnConnection_001, TestSize.Level0)
1223 {
1224     HILOG_INFO("CloseAppSpawnConnection_001 start");
1225     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1226     EXPECT_NE(appMgrServiceInner, nullptr);
1227 
1228     appMgrServiceInner->CloseAppSpawnConnection();
1229 
1230     appMgrServiceInner->remoteClientManager_ = nullptr;
1231     appMgrServiceInner->CloseAppSpawnConnection();
1232 
1233     HILOG_INFO("CloseAppSpawnConnection_001 end");
1234 }
1235 
1236 /**
1237  * @tc.name: QueryAppSpawnConnectionState_001
1238  * @tc.desc: query app spawn connection.
1239  * @tc.type: FUNC
1240  * @tc.require: issueI5W4S7
1241  */
1242 HWTEST_F(AppMgrServiceInnerTest, QueryAppSpawnConnectionState_001, TestSize.Level0)
1243 {
1244     HILOG_INFO("QueryAppSpawnConnectionState_001 start");
1245     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1246     EXPECT_NE(appMgrServiceInner, nullptr);
1247 
1248     auto connectionState = appMgrServiceInner->QueryAppSpawnConnectionState();
1249     EXPECT_EQ(connectionState, SpawnConnectionState::STATE_NOT_CONNECT);
1250 
1251     appMgrServiceInner->remoteClientManager_->SetSpawnClient(nullptr);
1252     connectionState = appMgrServiceInner->QueryAppSpawnConnectionState();
1253     EXPECT_EQ(connectionState, SpawnConnectionState::STATE_NOT_CONNECT);
1254 
1255 
1256     appMgrServiceInner->remoteClientManager_ = nullptr;
1257     connectionState = appMgrServiceInner->QueryAppSpawnConnectionState();
1258     EXPECT_EQ(connectionState, SpawnConnectionState::STATE_NOT_CONNECT);
1259 
1260     HILOG_INFO("QueryAppSpawnConnectionState_001 end");
1261 }
1262 
1263 /**
1264  * @tc.name: SetAppSpawnClient_001
1265  * @tc.desc: set app spawn client.
1266  * @tc.type: FUNC
1267  * @tc.require: issueI5W4S7
1268  */
1269 HWTEST_F(AppMgrServiceInnerTest, SetAppSpawnClient_001, TestSize.Level0)
1270 {
1271     HILOG_INFO("SetAppSpawnClient_001 start");
1272     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1273     EXPECT_NE(appMgrServiceInner, nullptr);
1274 
1275     std::shared_ptr<AppSpawnClient> spawnClient;
1276     appMgrServiceInner->SetAppSpawnClient(spawnClient);
1277 
1278     appMgrServiceInner->remoteClientManager_ = nullptr;
1279     appMgrServiceInner->SetAppSpawnClient(spawnClient);
1280 
1281     HILOG_INFO("SetAppSpawnClient_001 end");
1282 }
1283 
1284 /**
1285  * @tc.name: SetBundleManager_001
1286  * @tc.desc: set bundle manager.
1287  * @tc.type: FUNC
1288  * @tc.require: issueI5W4S7
1289  */
1290 HWTEST_F(AppMgrServiceInnerTest, SetBundleManager_001, TestSize.Level0)
1291 {
1292     HILOG_INFO("SetBundleManager_001 start");
1293     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1294     EXPECT_NE(appMgrServiceInner, nullptr);
1295 
1296     sptr<IBundleMgr> bundleManager;
1297     appMgrServiceInner->SetBundleManager(bundleManager);
1298 
1299     appMgrServiceInner->remoteClientManager_ = nullptr;
1300     appMgrServiceInner->SetBundleManager(bundleManager);
1301 
1302     HILOG_INFO("SetBundleManager_001 end");
1303 }
1304 
1305 /**
1306  * @tc.name: RegisterAppStateCallback_001
1307  * @tc.desc: register app state call back.
1308  * @tc.type: FUNC
1309  * @tc.require: issueI5W4S7
1310  */
1311 HWTEST_F(AppMgrServiceInnerTest, RegisterAppStateCallback_001, TestSize.Level0)
1312 {
1313     HILOG_INFO("RegisterAppStateCallback_001 start");
1314     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1315     EXPECT_NE(appMgrServiceInner, nullptr);
1316 
1317     appMgrServiceInner->RegisterAppStateCallback(nullptr);
1318 
1319     sptr<IAppStateCallback> callback;
1320     appMgrServiceInner->RegisterAppStateCallback(callback);
1321 
1322     HILOG_INFO("RegisterAppStateCallback_001 end");
1323 }
1324 
1325 /**
1326  * @tc.name: AbilityBehaviorAnalysis_001
1327  * @tc.desc: ability behavior analysis.
1328  * @tc.type: FUNC
1329  * @tc.require: issueI5W4S7
1330  */
1331 HWTEST_F(AppMgrServiceInnerTest, AbilityBehaviorAnalysis_001, TestSize.Level0)
1332 {
1333     HILOG_INFO("AbilityBehaviorAnalysis_001 start");
1334     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1335     EXPECT_NE(appMgrServiceInner, nullptr);
1336 
1337     appMgrServiceInner->AbilityBehaviorAnalysis(nullptr, nullptr, 0, 0, 0);
1338 
1339     OHOS::sptr<IRemoteObject> token = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
1340     appMgrServiceInner->AbilityBehaviorAnalysis(token, nullptr, 0, 0, 0);
1341 
1342     BundleInfo bundleInfo;
1343     HapModuleInfo hapModuleInfo;
1344     std::shared_ptr<AAFwk::Want> want;
1345     std::string processName = "test_processName";
1346     std::shared_ptr<AppRunningRecord> appRecord = appMgrServiceInner->CreateAppRunningRecord(token, nullptr,
1347         applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want);
1348     EXPECT_NE(appRecord, nullptr);
1349     appMgrServiceInner->AbilityBehaviorAnalysis(token, nullptr, 0, 0, 0);
1350 
1351     OHOS::sptr<IRemoteObject> preToken = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
1352     appMgrServiceInner->AbilityBehaviorAnalysis(token, preToken, 0, 0, 0);
1353 
1354     HILOG_INFO("AbilityBehaviorAnalysis_001 end");
1355 }
1356 
1357 /**
1358  * @tc.name: KillProcessByAbilityToken_001
1359  * @tc.desc: kill process by ability token.
1360  * @tc.type: FUNC
1361  * @tc.require: issueI5W4S7
1362  */
1363 HWTEST_F(AppMgrServiceInnerTest, KillProcessByAbilityToken_001, TestSize.Level0)
1364 {
1365     HILOG_INFO("KillProcessByAbilityToken_001 start");
1366     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1367     EXPECT_NE(appMgrServiceInner, nullptr);
1368 
1369     appMgrServiceInner->KillProcessByAbilityToken(nullptr);
1370 
1371     OHOS::sptr<IRemoteObject> token = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
1372     appMgrServiceInner->KillProcessByAbilityToken(token);
1373 
1374     BundleInfo bundleInfo;
1375     HapModuleInfo hapModuleInfo;
1376     std::shared_ptr<AAFwk::Want> want;
1377     std::string processName = "test_processName";
1378     std::shared_ptr<AppRunningRecord> appRecord = appMgrServiceInner->CreateAppRunningRecord(token, nullptr,
1379         applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want);
1380     EXPECT_NE(appRecord, nullptr);
1381     appMgrServiceInner->KillProcessByAbilityToken(token);
1382 
1383     appRecord->SetKeepAliveAppState(true, true);
1384     appMgrServiceInner->KillProcessByAbilityToken(token);
1385 
1386     HILOG_INFO("KillProcessByAbilityToken_001 end");
1387 }
1388 
1389 /**
1390  * @tc.name: KillProcessesByUserId_001
1391  * @tc.desc: kill process by user id.
1392  * @tc.type: FUNC
1393  * @tc.require: issueI5W4S7
1394  */
1395 HWTEST_F(AppMgrServiceInnerTest, KillProcessesByUserId_001, TestSize.Level0)
1396 {
1397     HILOG_INFO("KillProcessesByUserId_001 start");
1398     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1399     EXPECT_NE(appMgrServiceInner, nullptr);
1400 
1401     appMgrServiceInner->KillProcessesByUserId(0);
1402 
1403     appMgrServiceInner->appRunningManager_ = nullptr;
1404     appMgrServiceInner->KillProcessesByUserId(0);
1405 
1406     HILOG_INFO("KillProcessesByUserId_001 end");
1407 }
1408 
1409 /**
1410  * @tc.name: StartAbility_001
1411  * @tc.desc: start ability.
1412  * @tc.type: FUNC
1413  * @tc.require: issueI5W4S7
1414  */
1415 HWTEST_F(AppMgrServiceInnerTest, StartAbility_001, TestSize.Level0)
1416 {
1417     HILOG_INFO("StartAbility_001 start");
1418     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1419     EXPECT_NE(appMgrServiceInner, nullptr);
1420 
1421     HapModuleInfo hapModuleInfo;
1422     std::shared_ptr<AAFwk::Want> want;
1423     std::shared_ptr<AppRunningRecord> appRecord;
1424     appMgrServiceInner->StartAbility(nullptr, nullptr, abilityInfo_, nullptr, hapModuleInfo, nullptr);
1425     appMgrServiceInner->StartAbility(nullptr, nullptr, abilityInfo_, appRecord, hapModuleInfo, nullptr);
1426     appMgrServiceInner->StartAbility(nullptr, nullptr, abilityInfo_, appRecord, hapModuleInfo, want);
1427 
1428     OHOS::sptr<IRemoteObject> token = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
1429     OHOS::sptr<IRemoteObject> preToken = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
1430     appMgrServiceInner->StartAbility(token, nullptr, abilityInfo_, appRecord, hapModuleInfo, want);
1431     appMgrServiceInner->StartAbility(nullptr, preToken, abilityInfo_, appRecord, hapModuleInfo, want);
1432     appMgrServiceInner->StartAbility(token, preToken, abilityInfo_, appRecord, hapModuleInfo, want);
1433 
1434     BundleInfo bundleInfo;
1435     std::string processName = "test_processName";
1436     appRecord = appMgrServiceInner->CreateAppRunningRecord(token, nullptr,
1437         applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want);
1438     EXPECT_NE(appRecord, nullptr);
1439     appMgrServiceInner->StartAbility(token, nullptr, abilityInfo_, appRecord, hapModuleInfo, want);
1440     appMgrServiceInner->StartAbility(token, preToken, abilityInfo_, appRecord, hapModuleInfo, want);
1441 
1442     abilityInfo_->applicationInfo.name = "hiservcie";
1443     abilityInfo_->applicationInfo.bundleName = "com.ix.hiservcie";
1444     appMgrServiceInner->StartAbility(token, preToken, abilityInfo_, appRecord, hapModuleInfo, want);
1445 
1446     HILOG_INFO("StartAbility_001 end");
1447 }
1448 
1449 /**
1450  * @tc.name: GetAppRunningRecordByAbilityToken_001
1451  * @tc.desc: get app running record by ability token.
1452  * @tc.type: FUNC
1453  * @tc.require: issueI5W4S7
1454  */
1455 HWTEST_F(AppMgrServiceInnerTest, GetAppRunningRecordByAbilityToken_001, TestSize.Level0)
1456 {
1457     HILOG_INFO("GetAppRunningRecordByAbilityToken_001 start");
1458     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1459     EXPECT_NE(appMgrServiceInner, nullptr);
1460 
1461     OHOS::sptr<IRemoteObject> token = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
1462     appMgrServiceInner->GetAppRunningRecordByAbilityToken(token);
1463 
1464     appMgrServiceInner->appRunningManager_ = nullptr;
1465     appMgrServiceInner->GetAppRunningRecordByAbilityToken(token);
1466 
1467     HILOG_INFO("GetAppRunningRecordByAbilityToken_001 end");
1468 }
1469 
1470 /**
1471  * @tc.name: AbilityTerminated_001
1472  * @tc.desc: ability terminated.
1473  * @tc.type: FUNC
1474  * @tc.require: issueI5W4S7
1475  */
1476 HWTEST_F(AppMgrServiceInnerTest, AbilityTerminated_001, TestSize.Level0)
1477 {
1478     HILOG_INFO("AbilityTerminated_001 start");
1479     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1480     EXPECT_NE(appMgrServiceInner, nullptr);
1481 
1482     appMgrServiceInner->AbilityTerminated(nullptr);
1483 
1484     OHOS::sptr<IRemoteObject> token = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
1485     appMgrServiceInner->AbilityTerminated(token);
1486 
1487     BundleInfo bundleInfo;
1488     HapModuleInfo hapModuleInfo;
1489     std::shared_ptr<AAFwk::Want> want;
1490     std::string processName = "test_processName";
1491     std::shared_ptr<AppRunningRecord> appRecord = appMgrServiceInner->CreateAppRunningRecord(token, nullptr,
1492         applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want);
1493     EXPECT_NE(appRecord, nullptr);
1494     appMgrServiceInner->AbilityTerminated(token);
1495 
1496     HILOG_INFO("AbilityTerminated_001 end");
1497 }
1498 
1499 /**
1500  * @tc.name: GetAppRunningRecordByAppRecordId_001
1501  * @tc.desc: get app running record by app record id.
1502  * @tc.type: FUNC
1503  * @tc.require: issueI5W4S7
1504  */
1505 HWTEST_F(AppMgrServiceInnerTest, GetAppRunningRecordByAppRecordId_001, TestSize.Level0)
1506 {
1507     HILOG_INFO("GetAppRunningRecordByAppRecordId_001 start");
1508     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1509     EXPECT_NE(appMgrServiceInner, nullptr);
1510 
1511     appMgrServiceInner->GetAppRunningRecordByAppRecordId(0);
1512 
1513     appMgrServiceInner->appRunningManager_ = nullptr;
1514     appMgrServiceInner->GetAppRunningRecordByAppRecordId(0);
1515 
1516     HILOG_INFO("GetAppRunningRecordByAppRecordId_001 end");
1517 }
1518 
1519 /**
1520  * @tc.name: OnAppStateChanged_001
1521  * @tc.desc: on app state changed.
1522  * @tc.type: FUNC
1523  * @tc.require: issueI5W4S7
1524  */
1525 HWTEST_F(AppMgrServiceInnerTest, OnAppStateChanged_001, TestSize.Level0)
1526 {
1527     HILOG_INFO("OnAppStateChanged_001 start");
1528     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1529     EXPECT_NE(appMgrServiceInner, nullptr);
1530 
1531     appMgrServiceInner->OnAppStateChanged(nullptr, ApplicationState::APP_STATE_CREATE, true);
1532     appMgrServiceInner->OnAppStateChanged(nullptr, ApplicationState::APP_STATE_CREATE, false);
1533 
1534     BundleInfo bundleInfo;
1535     std::string processName = "test_processName";
1536     std::shared_ptr<AppRunningRecord> appRecord =
1537         appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo);
1538     EXPECT_NE(appRecord, nullptr);
1539     appMgrServiceInner->OnAppStateChanged(appRecord, ApplicationState::APP_STATE_CREATE, true);
1540 
1541     sptr<MockAppStateCallback> mockCallback(new MockAppStateCallback());
1542     EXPECT_CALL(*mockCallback, OnAppStateChanged(_)).Times(2);
1543     sptr<IAppStateCallback> callback1 = iface_cast<IAppStateCallback>(mockCallback);
1544     appMgrServiceInner->appStateCallbacks_.push_back(callback1);
1545     appMgrServiceInner->OnAppStateChanged(appRecord, ApplicationState::APP_STATE_CREATE, true);
1546 
1547     sptr<IAppStateCallback> callback;
1548     appMgrServiceInner->appStateCallbacks_.push_back(callback);
1549     appMgrServiceInner->OnAppStateChanged(appRecord, ApplicationState::APP_STATE_CREATE, true);
1550 
1551     HILOG_INFO("OnAppStateChanged_001 end");
1552 }
1553 
1554 /**
1555  * @tc.name: OnAbilityStateChanged_001
1556  * @tc.desc: on ability state changed.
1557  * @tc.type: FUNC
1558  * @tc.require: issueI5W4S7
1559  */
1560 HWTEST_F(AppMgrServiceInnerTest, OnAbilityStateChanged_001, TestSize.Level0)
1561 {
1562     HILOG_INFO("OnAbilityStateChanged_001 start");
1563     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1564     EXPECT_NE(appMgrServiceInner, nullptr);
1565 
1566     appMgrServiceInner->OnAbilityStateChanged(nullptr, AbilityState::ABILITY_STATE_CREATE);
1567 
1568     sptr<IRemoteObject> token = new MockAbilityToken();
1569     std::shared_ptr<AbilityRunningRecord> abilityRunningRecord =
1570         std::make_shared<AbilityRunningRecord>(abilityInfo_, token);
1571     appMgrServiceInner->OnAbilityStateChanged(abilityRunningRecord, AbilityState::ABILITY_STATE_CREATE);
1572 
1573     sptr<MockAppStateCallback> mockCallback(new MockAppStateCallback());
1574     EXPECT_CALL(*mockCallback, OnAbilityRequestDone(_, _)).Times(2);
1575     sptr<IAppStateCallback> callback1 = iface_cast<IAppStateCallback>(mockCallback);
1576     appMgrServiceInner->appStateCallbacks_.push_back(callback1);
1577     appMgrServiceInner->OnAbilityStateChanged(abilityRunningRecord, AbilityState::ABILITY_STATE_CREATE);
1578 
1579     sptr<IAppStateCallback> callback;
1580     appMgrServiceInner->appStateCallbacks_.push_back(callback);
1581     appMgrServiceInner->OnAbilityStateChanged(abilityRunningRecord, AbilityState::ABILITY_STATE_CREATE);
1582 
1583     HILOG_INFO("OnAbilityStateChanged_001 end");
1584 }
1585 
1586 /**
1587  * @tc.name: StartProcess_001
1588  * @tc.desc: start process.
1589  * @tc.type: FUNC
1590  * @tc.require: issueI5W4S7
1591  */
1592 HWTEST_F(AppMgrServiceInnerTest, StartProcess_001, TestSize.Level0)
1593 {
1594     HILOG_INFO("StartProcess_001 start");
1595     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1596     EXPECT_NE(appMgrServiceInner, nullptr);
1597 
1598     BundleInfo bundleInfo;
1599     std::string appName = "test_appName";
1600     std::string processName = "test_processName";
1601     std::string bundleName = "test_bundleName";
1602     sptr<IRemoteObject> token = new MockAbilityToken();
1603     std::shared_ptr<AppRunningRecord> appRecord =
1604         appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo);
1605     EXPECT_NE(appRecord, nullptr);
1606     appMgrServiceInner->StartProcess(appName, processName, 0, nullptr, 0, bundleName, 0);
1607     appMgrServiceInner->StartProcess(appName, processName, 0, appRecord, 0, bundleName, 0);
1608     appMgrServiceInner->StartProcess(appName, processName, 0, appRecord, 0, bundleName, 1);
1609     appMgrServiceInner->StartProcess(appName, processName, 0, appRecord, 0, bundleName, 0, false);
1610     appMgrServiceInner->StartProcess(appName, processName, 0, appRecord, 0, bundleName, 1, false);
1611 
1612     appMgrServiceInner->SetBundleManager(nullptr);
1613     appMgrServiceInner->StartProcess(appName, processName, 0, appRecord, 0, bundleName, 0);
1614 
1615     appMgrServiceInner->SetAppSpawnClient(nullptr);
1616     appMgrServiceInner->StartProcess(appName, processName, 0, nullptr, 0, bundleName, 0);
1617     appMgrServiceInner->StartProcess(appName, processName, 0, appRecord, 0, bundleName, 0);
1618 
1619     HILOG_INFO("StartProcess_001 end");
1620 }
1621 
1622 /**
1623  * @tc.name: RemoveAppFromRecentList_001
1624  * @tc.desc: remove app from recent list.
1625  * @tc.type: FUNC
1626  * @tc.require: issueI5W4S7
1627  */
1628 HWTEST_F(AppMgrServiceInnerTest, RemoveAppFromRecentList_001, TestSize.Level0)
1629 {
1630     HILOG_INFO("RemoveAppFromRecentList_001 start");
1631     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1632     EXPECT_NE(appMgrServiceInner, nullptr);
1633 
1634     std::string appName = "test_appName";
1635     std::string processName = "test_processName";
1636     appMgrServiceInner->RemoveAppFromRecentList(appName, processName);
1637 
1638     appMgrServiceInner->AddAppToRecentList(appName, processName, 0, 0);
1639     appMgrServiceInner->RemoveAppFromRecentList(appName, processName);
1640 
1641     appMgrServiceInner->ClearRecentAppList();
1642     BundleInfo bundleInfo;
1643     std::string appName1 = "hiservcie";
1644     std::string processName1 = "hiservcie_processName";
1645     std::shared_ptr<AppRunningRecord> appRecord =
1646         appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName1, bundleInfo);
1647     HILOG_INFO("RemoveAppFromRecentList_001 start 22");
1648 
1649     pid_t pid = 123;
1650     std::string renderParam = "test_renderParam";
1651     std::shared_ptr<RenderRecord> renderRecord =
1652         RenderRecord::CreateRenderRecord(pid, renderParam, 1, 1, 1, appRecord);
1653     appRecord->AddRenderRecord(renderRecord);
1654     appMgrServiceInner->AddAppToRecentList(appName1, processName1, pid, 0);
1655     appRecord->SetKeepAliveAppState(true, true);
1656     appMgrServiceInner->RemoveAppFromRecentList(appName1, processName1);
1657     appRecord->SetKeepAliveAppState(false, false);
1658     appMgrServiceInner->RemoveAppFromRecentList(appName1, processName1);
1659 
1660     HILOG_INFO("RemoveAppFromRecentList_001 end");
1661 }
1662 
1663 /**
1664  * @tc.name: ClearRecentAppList_001
1665  * @tc.desc: clear recent list.
1666  * @tc.type: FUNC
1667  * @tc.require: issueI5W4S7
1668  */
1669 HWTEST_F(AppMgrServiceInnerTest, ClearRecentAppList_001, TestSize.Level0)
1670 {
1671     HILOG_INFO("ClearRecentAppList_001 start");
1672     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1673     EXPECT_NE(appMgrServiceInner, nullptr);
1674 
1675     appMgrServiceInner->ClearRecentAppList();
1676     std::list<const std::shared_ptr<AppTaskInfo>> list = appMgrServiceInner->GetRecentAppList();
1677     EXPECT_EQ(list.size(), 0);
1678 
1679     HILOG_INFO("ClearRecentAppList_001 end");
1680 }
1681 
1682 /**
1683  * @tc.name: OnRemoteDied_001
1684  * @tc.desc: on remote died.
1685  * @tc.type: FUNC
1686  * @tc.require: issueI5W4S7
1687  */
1688 HWTEST_F(AppMgrServiceInnerTest, OnRemoteDied_001, TestSize.Level0)
1689 {
1690     HILOG_INFO("OnRemoteDied_001 start");
1691     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1692     EXPECT_NE(appMgrServiceInner, nullptr);
1693 
1694     sptr<IRemoteObject> remoteObject;
1695     appMgrServiceInner->OnRemoteDied(remoteObject, true);
1696     appMgrServiceInner->OnRemoteDied(remoteObject, false);
1697 
1698     HILOG_INFO("OnRemoteDied_001 end");
1699 }
1700 
1701 /**
1702  * @tc.name: ClearAppRunningData_001
1703  * @tc.desc: clear app running data.
1704  * @tc.type: FUNC
1705  * @tc.require: issueI5W4S7
1706  */
1707 HWTEST_F(AppMgrServiceInnerTest, ClearAppRunningData_001, TestSize.Level0)
1708 {
1709     HILOG_INFO("ClearAppRunningData_001 start");
1710     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1711     EXPECT_NE(appMgrServiceInner, nullptr);
1712 
1713     appMgrServiceInner->ClearAppRunningData(nullptr, true);
1714 
1715     BundleInfo info;
1716     std::string processName = "test_processName";
1717     std::shared_ptr<AppRunningRecord> appRecord =
1718         appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info);
1719     appMgrServiceInner->ClearAppRunningData(appRecord, true);
1720     appMgrServiceInner->ClearAppRunningData(appRecord, false);
1721 
1722     std::shared_ptr<RenderRecord> renderRecord;
1723     appRecord->AddRenderRecord(renderRecord);
1724     appMgrServiceInner->ClearAppRunningData(appRecord, false);
1725 
1726     pid_t pid = 123;
1727     std::string renderParam = "test_renderParam";
1728     std::shared_ptr<RenderRecord> renderRecord1 =
1729         RenderRecord::CreateRenderRecord(pid, renderParam, 1, 1, 1, appRecord);
1730     appRecord->AddRenderRecord(renderRecord1);
1731     appMgrServiceInner->ClearAppRunningData(appRecord, false);
1732 
1733     appRecord->SetKeepAliveAppState(true, true);
1734     appMgrServiceInner->ClearAppRunningData(appRecord, false);
1735 
1736     appMgrServiceInner->taskHandler_ = nullptr;
1737     appMgrServiceInner->ClearAppRunningData(appRecord, false);
1738 
1739     appRecord->restartResidentProcCount_ = 0;
1740     appMgrServiceInner->ClearAppRunningData(appRecord, false);
1741 
1742     appRecord->appInfo_ = nullptr;
1743     appMgrServiceInner->ClearAppRunningData(appRecord, false);
1744 
1745     HILOG_INFO("ClearAppRunningData_001 end");
1746 }
1747 
1748 /**
1749  * @tc.name: AddAppDeathRecipient_001
1750  * @tc.desc: add app death recipient.
1751  * @tc.type: FUNC
1752  * @tc.require: issueI5W4S7
1753  */
1754 HWTEST_F(AppMgrServiceInnerTest, AddAppDeathRecipient_001, TestSize.Level0)
1755 {
1756     HILOG_INFO("AddAppDeathRecipient_001 start");
1757     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1758     EXPECT_NE(appMgrServiceInner, nullptr);
1759 
1760     BundleInfo bundleInfo;
1761     std::string appName = "test_appName";
1762     std::string processName = "test_processName";
1763     std::string bundleName = "test_bundleName";
1764     sptr<IRemoteObject> token = new MockAbilityToken();
1765     std::shared_ptr<AppRunningRecord> appRecord =
1766         appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo);
1767     EXPECT_NE(appRecord, nullptr);
1768     sptr<AppDeathRecipient> appDeathRecipient;
1769     pid_t pid = 999;
1770     appMgrServiceInner->AddAppDeathRecipient(pid, appDeathRecipient);
1771 
1772     pid_t pid1 = 123;
1773     appMgrServiceInner->AddAppDeathRecipient(pid1, appDeathRecipient);
1774 
1775     HILOG_INFO("AddAppDeathRecipient_001 end");
1776 }
1777 
1778 /**
1779  * @tc.name: HandleTimeOut_001
1780  * @tc.desc: handle time out.
1781  * @tc.type: FUNC
1782  * @tc.require: issueI5W4S7
1783  */
1784 HWTEST_F(AppMgrServiceInnerTest, HandleTimeOut_001, TestSize.Level0)
1785 {
1786     HILOG_INFO("HandleTimeOut_001 start");
1787     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1788     EXPECT_NE(appMgrServiceInner, nullptr);
1789 
1790     AAFwk::EventWrap innerEvent(0);
1791     appMgrServiceInner->HandleTimeOut(innerEvent);
1792 
1793     appMgrServiceInner->appRunningManager_ = nullptr;
1794     appMgrServiceInner->HandleTimeOut(innerEvent);
1795 
1796     HILOG_INFO("HandleTimeOut_001 end");
1797 }
1798 
1799 /**
1800  * @tc.name: HandleAbilityAttachTimeOut_001
1801  * @tc.desc: handle ability attach time out.
1802  * @tc.type: FUNC
1803  * @tc.require: issueI5W4S7
1804  */
1805 HWTEST_F(AppMgrServiceInnerTest, HandleAbilityAttachTimeOut_001, TestSize.Level0)
1806 {
1807     HILOG_INFO("HandleAbilityAttachTimeOut_001 start");
1808     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1809     EXPECT_NE(appMgrServiceInner, nullptr);
1810 
1811     appMgrServiceInner->HandleAbilityAttachTimeOut(nullptr);
1812 
1813     appMgrServiceInner->appRunningManager_ = nullptr;
1814     appMgrServiceInner->HandleAbilityAttachTimeOut(nullptr);
1815 
1816     HILOG_INFO("HandleAbilityAttachTimeOut_001 end");
1817 }
1818 
1819 /**
1820  * @tc.name: PrepareTerminate_001
1821  * @tc.desc: prepare terminate.
1822  * @tc.type: FUNC
1823  * @tc.require: issueI5W4S7
1824  */
1825 HWTEST_F(AppMgrServiceInnerTest, PrepareTerminate_001, TestSize.Level0)
1826 {
1827     HILOG_INFO("PrepareTerminate_001 start");
1828     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1829     EXPECT_NE(appMgrServiceInner, nullptr);
1830 
1831     appMgrServiceInner->PrepareTerminate(nullptr);
1832 
1833     appMgrServiceInner->appRunningManager_ = nullptr;
1834     appMgrServiceInner->PrepareTerminate(nullptr);
1835 
1836     HILOG_INFO("PrepareTerminate_001 end");
1837 }
1838 
1839 /**
1840  * @tc.name: HandleTerminateApplicationTimeOut_001
1841  * @tc.desc: handle terminate application time out.
1842  * @tc.type: FUNC
1843  * @tc.require: issueI5W4S7
1844  */
1845 HWTEST_F(AppMgrServiceInnerTest, HandleTerminateApplicationTimeOut_001, TestSize.Level0)
1846 {
1847     HILOG_INFO("HandleTerminateApplicationTimeOut_001 start");
1848     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1849     EXPECT_NE(appMgrServiceInner, nullptr);
1850 
1851     appMgrServiceInner->HandleTerminateApplicationTimeOut(0);
1852 
1853     BundleInfo bundleInfo;
1854     std::string appName = "test_appName";
1855     std::string processName = "test_processName";
1856     std::string bundleName = "test_bundleName";
1857     sptr<IRemoteObject> token = new MockAbilityToken();
1858     std::shared_ptr<AppRunningRecord> appRecord =
1859         appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo);
1860     EXPECT_NE(appRecord, nullptr);
1861     appRecord->eventId_ = 0;
1862     appMgrServiceInner->HandleTerminateApplicationTimeOut(0);
1863 
1864     pid_t pid = 1;
1865     appRecord->GetPriorityObject()->SetPid(pid);
1866     appMgrServiceInner->HandleTerminateApplicationTimeOut(0);
1867 
1868     appMgrServiceInner->taskHandler_ = nullptr;
1869     appMgrServiceInner->HandleTerminateApplicationTimeOut(0);
1870 
1871     appMgrServiceInner->appRunningManager_ = nullptr;
1872     appMgrServiceInner->HandleTerminateApplicationTimeOut(0);
1873 
1874     HILOG_INFO("HandleTerminateApplicationTimeOut_001 end");
1875 }
1876 
1877 /**
1878  * @tc.name: HandleAddAbilityStageTimeOut_001
1879  * @tc.desc: handle add ability stage time out.
1880  * @tc.type: FUNC
1881  * @tc.require: issueI5W4S7
1882  */
1883 HWTEST_F(AppMgrServiceInnerTest, HandleAddAbilityStageTimeOut_001, TestSize.Level0)
1884 {
1885     HILOG_INFO("HandleAddAbilityStageTimeOut_001 start");
1886     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1887     EXPECT_NE(appMgrServiceInner, nullptr);
1888 
1889     appMgrServiceInner->HandleAddAbilityStageTimeOut(0);
1890 
1891     BundleInfo bundleInfo;
1892     std::string appName = "test_appName";
1893     std::string processName = "test_processName";
1894     std::string bundleName = "test_bundleName";
1895     sptr<IRemoteObject> token = new MockAbilityToken();
1896     std::shared_ptr<AppRunningRecord> appRecord =
1897         appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo);
1898     EXPECT_NE(appRecord, nullptr);
1899     appRecord->eventId_ = 0;
1900     appMgrServiceInner->HandleAddAbilityStageTimeOut(0);
1901 
1902     appRecord->isSpecifiedAbility_ = true;
1903     appMgrServiceInner->HandleAddAbilityStageTimeOut(0);
1904 
1905     sptr<IStartSpecifiedAbilityResponse> response;
1906     appMgrServiceInner->startSpecifiedAbilityResponse_ = response;
1907     appMgrServiceInner->HandleAddAbilityStageTimeOut(0);
1908 
1909     appMgrServiceInner->appRunningManager_ = nullptr;
1910     appMgrServiceInner->HandleAddAbilityStageTimeOut(0);
1911 
1912     HILOG_INFO("HandleAddAbilityStageTimeOut_001 end");
1913 }
1914 
1915 /**
1916  * @tc.name: GetRunningProcessInfoByToken_001
1917  * @tc.desc: get running process info by token.
1918  * @tc.type: FUNC
1919  * @tc.require: issueI5W4S7
1920  */
1921 HWTEST_F(AppMgrServiceInnerTest, GetRunningProcessInfoByToken_001, TestSize.Level0)
1922 {
1923     HILOG_INFO("GetRunningProcessInfoByToken_001 start");
1924     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1925     EXPECT_NE(appMgrServiceInner, nullptr);
1926 
1927     AppExecFwk::RunningProcessInfo info;
1928     appMgrServiceInner->GetRunningProcessInfoByToken(nullptr, info);
1929 
1930     appMgrServiceInner->appRunningManager_ = nullptr;
1931     appMgrServiceInner->GetRunningProcessInfoByToken(nullptr, info);
1932 
1933     HILOG_INFO("GetRunningProcessInfoByToken_001 end");
1934 }
1935 
1936 /**
1937  * @tc.name: GetRunningProcessInfoByPid_001
1938  * @tc.desc: get running process info by pid.
1939  * @tc.type: FUNC
1940  * @tc.require: issueI5W4S7
1941  */
1942 HWTEST_F(AppMgrServiceInnerTest, GetRunningProcessInfoByPid_001, TestSize.Level0)
1943 {
1944     HILOG_INFO("GetRunningProcessInfoByPid_001 start");
1945     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1946     EXPECT_NE(appMgrServiceInner, nullptr);
1947 
1948     AppExecFwk::RunningProcessInfo info;
1949     appMgrServiceInner->GetRunningProcessInfoByPid(0, info);
1950 
1951     appMgrServiceInner->appRunningManager_ = nullptr;
1952     appMgrServiceInner->GetRunningProcessInfoByPid(0, info);
1953 
1954     HILOG_INFO("GetRunningProcessInfoByPid_001 end");
1955 }
1956 
1957 /**
1958  * @tc.name: CheckGetRunningInfoPermission_001
1959  * @tc.desc: check get running info permission.
1960  * @tc.type: FUNC
1961  * @tc.require: issueI5W4S7
1962  */
1963 HWTEST_F(AppMgrServiceInnerTest, CheckGetRunningInfoPermission_001, TestSize.Level0)
1964 {
1965     HILOG_INFO("CheckGetRunningInfoPermission_001 start");
1966     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1967     EXPECT_NE(appMgrServiceInner, nullptr);
1968 
1969     appMgrServiceInner->CheckGetRunningInfoPermission();
1970 
1971     appMgrServiceInner->appRunningManager_ = nullptr;
1972     appMgrServiceInner->CheckGetRunningInfoPermission();
1973 
1974     HILOG_INFO("CheckGetRunningInfoPermission_001 end");
1975 }
1976 
1977 /**
1978  * @tc.name: LoadResidentProcess_001
1979  * @tc.desc: load resident process.
1980  * @tc.type: FUNC
1981  * @tc.require: issueI5W4S7
1982  */
1983 HWTEST_F(AppMgrServiceInnerTest, LoadResidentProcess_001, TestSize.Level0)
1984 {
1985     HILOG_INFO("LoadResidentProcess_001 start");
1986     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1987     EXPECT_NE(appMgrServiceInner, nullptr);
1988 
1989     std::vector<BundleInfo> infos;
1990     appMgrServiceInner->LoadResidentProcess(infos);
1991 
1992     HILOG_INFO("LoadResidentProcess_001 end");
1993 }
1994 
1995 /**
1996  * @tc.name: StartResidentProcess_001
1997  * @tc.desc: start resident process.
1998  * @tc.type: FUNC
1999  * @tc.require: issueI5W4S7
2000  */
2001 HWTEST_F(AppMgrServiceInnerTest, StartResidentProcess_001, TestSize.Level0)
2002 {
2003     HILOG_INFO("StartResidentProcess_001 start");
2004     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2005     EXPECT_NE(appMgrServiceInner, nullptr);
2006 
2007     std::vector<BundleInfo> infos;
2008     appMgrServiceInner->StartResidentProcess(infos, 0, true);
2009 
2010     BundleInfo info;
2011     infos.push_back(info);
2012 
2013     BundleInfo info1;
2014     info1.applicationInfo.process = "";
2015     infos.push_back(info1);
2016 
2017     BundleInfo info2;
2018     info2.applicationInfo.process = "test_process";
2019     infos.push_back(info2);
2020     appMgrServiceInner->StartResidentProcess(infos, 0, true);
2021 
2022     appMgrServiceInner->appRunningManager_ = nullptr;
2023     appMgrServiceInner->StartResidentProcess(infos, 0, true);
2024 
2025     HILOG_INFO("StartResidentProcess_001 end");
2026 }
2027 
2028 /**
2029  * @tc.name: StartEmptyResidentProcess_001
2030  * @tc.desc: start empty resident process.
2031  * @tc.type: FUNC
2032  * @tc.require: issueI5W4S7
2033  */
2034 HWTEST_F(AppMgrServiceInnerTest, StartEmptyResidentProcess_001, TestSize.Level0)
2035 {
2036     HILOG_INFO("StartEmptyResidentProcess_001 start");
2037     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2038     EXPECT_NE(appMgrServiceInner, nullptr);
2039 
2040     BundleInfo info;
2041     info.applicationInfo = *applicationInfo_;
2042     std::string processName = "test_process";
2043     appMgrServiceInner->StartEmptyResidentProcess(info, processName, 0, true);
2044 
2045     appMgrServiceInner->StartEmptyResidentProcess(info, processName, 1, true);
2046 
2047     appMgrServiceInner->StartEmptyResidentProcess(info, "", 0, true);
2048 
2049     appMgrServiceInner->appRunningManager_ = nullptr;
2050     appMgrServiceInner->StartEmptyResidentProcess(info, processName, 0, true);
2051 
2052     appMgrServiceInner->remoteClientManager_ = nullptr;
2053     appMgrServiceInner->StartEmptyResidentProcess(info, processName, 0, true);
2054 
2055     HILOG_INFO("StartEmptyResidentProcess_001 end");
2056 }
2057 
2058 /**
2059  * @tc.name: CheckRemoteClient_001
2060  * @tc.desc: check remote client.
2061  * @tc.type: FUNC
2062  * @tc.require: issueI5W4S7
2063  */
2064 HWTEST_F(AppMgrServiceInnerTest, CheckRemoteClient_001, TestSize.Level0)
2065 {
2066     HILOG_INFO("CheckRemoteClient_001 start");
2067     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2068     EXPECT_NE(appMgrServiceInner, nullptr);
2069 
2070     appMgrServiceInner->CheckRemoteClient();
2071 
2072     appMgrServiceInner->remoteClientManager_->SetSpawnClient(nullptr);
2073     appMgrServiceInner->CheckRemoteClient();
2074 
2075     appMgrServiceInner->remoteClientManager_->SetBundleManager(nullptr);
2076     appMgrServiceInner->CheckRemoteClient();
2077 
2078     appMgrServiceInner->remoteClientManager_ = nullptr;
2079     appMgrServiceInner->CheckRemoteClient();
2080 
2081     HILOG_INFO("CheckRemoteClient_001 end");
2082 }
2083 
2084 /**
2085  * @tc.name: RestartResidentProcess_001
2086  * @tc.desc: restart resident process.
2087  * @tc.type: FUNC
2088  * @tc.require: issueI5W4S7
2089  */
2090 HWTEST_F(AppMgrServiceInnerTest, RestartResidentProcess_001, TestSize.Level0)
2091 {
2092     HILOG_INFO("RestartResidentProcess_001 start");
2093     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2094     EXPECT_NE(appMgrServiceInner, nullptr);
2095 
2096     appMgrServiceInner->RestartResidentProcess(nullptr);
2097 
2098     std::shared_ptr<AppRunningRecord> appRecord;
2099     appMgrServiceInner->RestartResidentProcess(appRecord);
2100 
2101     BundleInfo bundleInfo;
2102     std::string processName = "test_processName";
2103     appRecord =
2104         appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo);
2105     EXPECT_NE(appRecord, nullptr);
2106     appRecord->mainBundleName_ = "com.ohos.settings";
2107     appMgrServiceInner->RestartResidentProcess(appRecord);
2108 
2109     appMgrServiceInner->appRunningManager_ = nullptr;
2110     appMgrServiceInner->RestartResidentProcess(appRecord);
2111 
2112     appMgrServiceInner->remoteClientManager_ = nullptr;
2113     appMgrServiceInner->RestartResidentProcess(appRecord);
2114 
2115     HILOG_INFO("RestartResidentProcess_001 end");
2116 }
2117 
2118 /**
2119  * @tc.name: NotifyAppStatusByCallerUid_001
2120  * @tc.desc: notify app status by caller uid.
2121  * @tc.type: FUNC
2122  * @tc.require: issueI5W4S7
2123  */
2124 HWTEST_F(AppMgrServiceInnerTest, NotifyAppStatusByCallerUid_001, TestSize.Level0)
2125 {
2126     HILOG_INFO("NotifyAppStatusByCallerUid_001 start");
2127     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2128     EXPECT_NE(appMgrServiceInner, nullptr);
2129 
2130     std::string bundleName = "test_bundle_name";
2131     std::string eventData = "test_event_data";
2132     appMgrServiceInner->NotifyAppStatusByCallerUid(bundleName, 0, 0, eventData);
2133 
2134     HILOG_INFO("NotifyAppStatusByCallerUid_001 end");
2135 }
2136 
2137 /**
2138  * @tc.name: RegisterApplicationStateObserver_001
2139  * @tc.desc: register application state observer.
2140  * @tc.type: FUNC
2141  * @tc.require: issueI5W4S7
2142  */
2143 HWTEST_F(AppMgrServiceInnerTest, RegisterApplicationStateObserver_001, TestSize.Level0)
2144 {
2145     HILOG_INFO("RegisterApplicationStateObserver_001 start");
2146     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2147     EXPECT_NE(appMgrServiceInner, nullptr);
2148 
2149     sptr<IApplicationStateObserver> observer;
2150     std::vector<std::string> bundleNameList;
2151     appMgrServiceInner->RegisterApplicationStateObserver(observer, bundleNameList);
2152 
2153     HILOG_INFO("RegisterApplicationStateObserver_001 end");
2154 }
2155 
2156 /**
2157  * @tc.name: UnregisterApplicationStateObserver_001
2158  * @tc.desc: unregister application state observer.
2159  * @tc.type: FUNC
2160  * @tc.require: issueI5W4S7
2161  */
2162 HWTEST_F(AppMgrServiceInnerTest, UnregisterApplicationStateObserver_001, TestSize.Level0)
2163 {
2164     HILOG_INFO("UnregisterApplicationStateObserver_001 start");
2165     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2166     EXPECT_NE(appMgrServiceInner, nullptr);
2167 
2168     sptr<IApplicationStateObserver> observer;
2169     appMgrServiceInner->UnregisterApplicationStateObserver(observer);
2170 
2171     HILOG_INFO("UnregisterApplicationStateObserver_001 end");
2172 }
2173 
2174 /**
2175  * @tc.name: GetForegroundApplications_001
2176  * @tc.desc: get foreground applications.
2177  * @tc.type: FUNC
2178  * @tc.require: issueI5W4S7
2179  */
2180 HWTEST_F(AppMgrServiceInnerTest, GetForegroundApplications_001, TestSize.Level0)
2181 {
2182     HILOG_INFO("GetForegroundApplications_001 start");
2183     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2184     EXPECT_NE(appMgrServiceInner, nullptr);
2185 
2186     std::vector<AppStateData> list;
2187     appMgrServiceInner->GetForegroundApplications(list);
2188 
2189     HILOG_INFO("GetForegroundApplications_001 end");
2190 }
2191 
2192 /**
2193  * @tc.name: StartUserTestProcess_001
2194  * @tc.desc: start user test process.
2195  * @tc.type: FUNC
2196  * @tc.require: issueI5W4S7
2197  */
2198 HWTEST_F(AppMgrServiceInnerTest, StartUserTestProcess_001, TestSize.Level0)
2199 {
2200     HILOG_INFO("StartUserTestProcess_001 start");
2201     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2202     EXPECT_NE(appMgrServiceInner, nullptr);
2203 
2204     AAFwk::Want want;
2205     sptr<IRemoteObject> observer;
2206     BundleInfo bundleInfo;
2207     appMgrServiceInner->StartUserTestProcess(want, nullptr, bundleInfo, 0);
2208 
2209     appMgrServiceInner->StartUserTestProcess(want, observer, bundleInfo, 0);
2210 
2211     std::string bundle_name = "test_bundle_name";
2212     want.SetParam("-b", bundle_name);
2213     appMgrServiceInner->StartUserTestProcess(want, observer, bundleInfo, 0);
2214 
2215     std::string moduleName = "test_module_name";
2216     want.SetParam("-m", moduleName);
2217     HapModuleInfo hapModuleInfo;
2218     hapModuleInfo.moduleName = moduleName;
2219     bundleInfo.hapModuleInfos.push_back(hapModuleInfo);
2220     appMgrServiceInner->StartUserTestProcess(want, observer, bundleInfo, 0);
2221 
2222     appMgrServiceInner->remoteClientManager_ = nullptr;
2223     appMgrServiceInner->StartUserTestProcess(want, observer, bundleInfo, 0);
2224 
2225     appMgrServiceInner->appRunningManager_ = nullptr;
2226     appMgrServiceInner->StartUserTestProcess(want, observer, bundleInfo, 0);
2227 
2228     HILOG_INFO("StartUserTestProcess_001 end");
2229 }
2230 
2231 /**
2232  * @tc.name: GetHapModuleInfoForTestRunner_001
2233  * @tc.desc: get hap module info for test runner.
2234  * @tc.type: FUNC
2235  * @tc.require: issueI5W4S7
2236  */
2237 HWTEST_F(AppMgrServiceInnerTest, GetHapModuleInfoForTestRunner_001, TestSize.Level0)
2238 {
2239     HILOG_INFO("GetHapModuleInfoForTestRunner_001 start");
2240     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2241     EXPECT_NE(appMgrServiceInner, nullptr);
2242 
2243     AAFwk::Want want;
2244     sptr<IRemoteObject> observer;
2245     BundleInfo bundleInfo;
2246     HapModuleInfo hapModuleInfo;
2247     appMgrServiceInner->GetHapModuleInfoForTestRunner(want, nullptr, bundleInfo, hapModuleInfo);
2248 
2249     appMgrServiceInner->GetHapModuleInfoForTestRunner(want, observer, bundleInfo, hapModuleInfo);
2250 
2251     hapModuleInfo.moduleName = "test_module_name";
2252     bundleInfo.hapModuleInfos.push_back(hapModuleInfo);
2253     appMgrServiceInner->GetHapModuleInfoForTestRunner(want, observer, bundleInfo, hapModuleInfo);
2254 
2255     bundleInfo.hapModuleInfos.back().isModuleJson = true;
2256     appMgrServiceInner->GetHapModuleInfoForTestRunner(want, observer, bundleInfo, hapModuleInfo);
2257 
2258     std::string testmoduleName = "test_XXX";
2259     want.SetParam("-m", testmoduleName);
2260     appMgrServiceInner->GetHapModuleInfoForTestRunner(want, observer, bundleInfo, hapModuleInfo);
2261 
2262     std::string moduleName = "test_module_name";
2263     want.SetParam("-m", moduleName);
2264     appMgrServiceInner->GetHapModuleInfoForTestRunner(want, observer, bundleInfo, hapModuleInfo);
2265 
2266     HILOG_INFO("GetHapModuleInfoForTestRunner_001 end");
2267 }
2268 
2269 /**
2270  * @tc.name: UserTestAbnormalFinish_001
2271  * @tc.desc: user test abnormal finish.
2272  * @tc.type: FUNC
2273  * @tc.require: issueI5W4S7
2274  */
2275 HWTEST_F(AppMgrServiceInnerTest, UserTestAbnormalFinish_001, TestSize.Level0)
2276 {
2277     HILOG_INFO("UserTestAbnormalFinish_001 start");
2278     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2279     EXPECT_NE(appMgrServiceInner, nullptr);
2280 
2281     sptr<IRemoteObject> observer;
2282     std::string msg = "testmsg";
2283     appMgrServiceInner->UserTestAbnormalFinish(nullptr, "");
2284     appMgrServiceInner->UserTestAbnormalFinish(nullptr, msg);
2285     appMgrServiceInner->UserTestAbnormalFinish(observer, "");
2286     appMgrServiceInner->UserTestAbnormalFinish(observer, msg);
2287 
2288     HILOG_INFO("UserTestAbnormalFinish_001 end");
2289 }
2290 
2291 /**
2292  * @tc.name: StartEmptyProcess_001
2293  * @tc.desc: start empty process.
2294  * @tc.type: FUNC
2295  * @tc.require: issueI5W4S7
2296  */
2297 HWTEST_F(AppMgrServiceInnerTest, StartEmptyProcess_001, TestSize.Level0)
2298 {
2299     HILOG_INFO("StartEmptyProcess_001 start");
2300     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2301     EXPECT_NE(appMgrServiceInner, nullptr);
2302 
2303     AAFwk::Want want;
2304     sptr<IRemoteObject> observer;
2305     BundleInfo info;
2306     HapModuleInfo hapModuleInfo;
2307     std::string processName = "test_processName";
2308     appMgrServiceInner->StartEmptyProcess(want, nullptr, info, "", 0);
2309     appMgrServiceInner->StartEmptyProcess(want, observer, info, "", 0);
2310     appMgrServiceInner->StartEmptyProcess(want, observer, info, processName, 0);
2311 
2312     info.applicationInfo = *applicationInfo_;
2313     appMgrServiceInner->StartEmptyProcess(want, observer, info, processName, 0);
2314 
2315     want.SetParam("coldStart", true);
2316     appMgrServiceInner->StartEmptyProcess(want, observer, info, processName, 0);
2317 
2318     appMgrServiceInner->remoteClientManager_ = nullptr;
2319     appMgrServiceInner->StartEmptyProcess(want, observer, info, processName, 0);
2320 
2321     appMgrServiceInner->appRunningManager_ = nullptr;
2322     appMgrServiceInner->StartEmptyProcess(want, observer, info, processName, 0);
2323 
2324     HILOG_INFO("StartEmptyProcess_001 end");
2325 }
2326 
2327 /**
2328  * @tc.name: FinishUserTest_001
2329  * @tc.desc: finish user test.
2330  * @tc.type: FUNC
2331  * @tc.require: issueI5W4S7
2332  */
2333 HWTEST_F(AppMgrServiceInnerTest, FinishUserTest_001, TestSize.Level0)
2334 {
2335     HILOG_INFO("FinishUserTest_001 start");
2336     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2337     EXPECT_NE(appMgrServiceInner, nullptr);
2338 
2339     pid_t pid = 0;
2340     appMgrServiceInner->FinishUserTest("", 0, "", pid);
2341 
2342     std::string msg = "testmsg";
2343     std::string bundleName = "test_bundle_name";
2344     appMgrServiceInner->FinishUserTest("", 0, bundleName, pid);
2345     appMgrServiceInner->FinishUserTest(msg, 0, "", pid);
2346     appMgrServiceInner->FinishUserTest(msg, 0, bundleName, pid);
2347 
2348     BundleInfo bundleInfo;
2349     HapModuleInfo hapModuleInfo;
2350     std::shared_ptr<AAFwk::Want> want;
2351     sptr<IRemoteObject> token = new MockAbilityToken();
2352     std::string processName = "test_processName";
2353     std::shared_ptr<AppRunningRecord> appRecord = appMgrServiceInner->CreateAppRunningRecord(token, nullptr,
2354         applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want);
2355     EXPECT_NE(appRecord, nullptr);
2356     pid = appRecord->GetPriorityObject()->GetPid();
2357     appMgrServiceInner->FinishUserTest(msg, 0, bundleName, pid);
2358 
2359     std::shared_ptr<UserTestRecord> record = std::make_shared<UserTestRecord>();
2360     appRecord->SetUserTestInfo(record);
2361     appMgrServiceInner->FinishUserTest(msg, 0, bundleName, pid);
2362 
2363     appMgrServiceInner->appRunningManager_ = nullptr;
2364     appMgrServiceInner->FinishUserTest(msg, 0, bundleName, pid);
2365 
2366     HILOG_INFO("FinishUserTest_001 end");
2367 }
2368 
2369 /**
2370  * @tc.name: FinishUserTestLocked_001
2371  * @tc.desc: finish user test locked.
2372  * @tc.type: FUNC
2373  * @tc.require: issueI5W4S7
2374  */
2375 HWTEST_F(AppMgrServiceInnerTest, FinishUserTestLocked_001, TestSize.Level0)
2376 {
2377     HILOG_INFO("FinishUserTestLocked_001 start");
2378     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2379     EXPECT_NE(appMgrServiceInner, nullptr);
2380 
2381     appMgrServiceInner->FinishUserTestLocked("", 0, nullptr);
2382 
2383     std::shared_ptr<AppRunningRecord> appRecord;
2384     appMgrServiceInner->FinishUserTestLocked("", 0, appRecord);
2385 
2386     std::string msg = "testmsg";
2387     appMgrServiceInner->FinishUserTestLocked(msg, 0, nullptr);
2388     appMgrServiceInner->FinishUserTestLocked(msg, 0, appRecord);
2389 
2390     BundleInfo bundleInfo;
2391     std::string processName = "test_processName";
2392     appRecord =
2393         appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo);
2394     EXPECT_NE(appRecord, nullptr);
2395     std::shared_ptr<UserTestRecord> record = std::make_shared<UserTestRecord>();
2396     appRecord->SetUserTestInfo(record);
2397     appMgrServiceInner->FinishUserTestLocked(msg, 0, appRecord);
2398 
2399     record->isFinished = true;
2400     appRecord->SetUserTestInfo(record);
2401     appMgrServiceInner->FinishUserTestLocked(msg, 0, appRecord);
2402 
2403     record->observer = nullptr;
2404     appRecord->SetUserTestInfo(record);
2405     appMgrServiceInner->FinishUserTestLocked(msg, 0, appRecord);
2406 
2407     HILOG_INFO("FinishUserTestLocked_001 end");
2408 }
2409 
2410 /**
2411  * @tc.name: StartSpecifiedAbility_001
2412  * @tc.desc: start specified ability.
2413  * @tc.type: FUNC
2414  * @tc.require: issueI5W4S7
2415  */
2416 HWTEST_F(AppMgrServiceInnerTest, StartSpecifiedAbility_001, TestSize.Level0)
2417 {
2418     HILOG_INFO("StartSpecifiedAbility_001 start");
2419     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2420     EXPECT_NE(appMgrServiceInner, nullptr);
2421 
2422     AAFwk::Want want;
2423     AbilityInfo abilityInfo;
2424     appMgrServiceInner->StartSpecifiedAbility(want, abilityInfo);
2425 
2426     appMgrServiceInner->StartSpecifiedAbility(want, *abilityInfo_);
2427 
2428     abilityInfo_->applicationInfo = *applicationInfo_;
2429     appMgrServiceInner->StartSpecifiedAbility(want, *abilityInfo_);
2430 
2431     appMgrServiceInner->remoteClientManager_->SetBundleManager(nullptr);
2432     appMgrServiceInner->StartSpecifiedAbility(want, *abilityInfo_);
2433 
2434     appMgrServiceInner->remoteClientManager_ = nullptr;
2435     appMgrServiceInner->StartSpecifiedAbility(want, *abilityInfo_);
2436 
2437     HILOG_INFO("StartSpecifiedAbility_001 end");
2438 }
2439 
2440 /**
2441  * @tc.name: RegisterStartSpecifiedAbilityResponse_001
2442  * @tc.desc: register start specified ability response.
2443  * @tc.type: FUNC
2444  * @tc.require: issueI5W4S7
2445  */
2446 HWTEST_F(AppMgrServiceInnerTest, RegisterStartSpecifiedAbilityResponse_001, TestSize.Level0)
2447 {
2448     HILOG_INFO("RegisterStartSpecifiedAbilityResponse_001 start");
2449     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2450     EXPECT_NE(appMgrServiceInner, nullptr);
2451 
2452     appMgrServiceInner->RegisterStartSpecifiedAbilityResponse(nullptr);
2453 
2454     sptr<IStartSpecifiedAbilityResponse> response;
2455     appMgrServiceInner->RegisterStartSpecifiedAbilityResponse(response);
2456 
2457     HILOG_INFO("RegisterStartSpecifiedAbilityResponse_001 end");
2458 }
2459 
2460 /**
2461  * @tc.name: ScheduleAcceptWantDone_001
2462  * @tc.desc: schedule accept want done.
2463  * @tc.type: FUNC
2464  * @tc.require: issueI5W4S7
2465  */
2466 HWTEST_F(AppMgrServiceInnerTest, ScheduleAcceptWantDone_001, TestSize.Level0)
2467 {
2468     HILOG_INFO("ScheduleAcceptWantDone_001 start");
2469     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2470     EXPECT_NE(appMgrServiceInner, nullptr);
2471 
2472     AAFwk::Want want;
2473     std::string flag = "test_flag";
2474     appMgrServiceInner->ScheduleAcceptWantDone(0, want, flag);
2475 
2476     BundleInfo bundleInfo;
2477     std::string processName = "test_processName";
2478     std::shared_ptr<AppRunningRecord> appRecord =
2479         appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo);
2480     appMgrServiceInner->ScheduleAcceptWantDone(appRecord->GetRecordId(), want, flag);
2481 
2482     sptr<IStartSpecifiedAbilityResponse> response;
2483     appMgrServiceInner->RegisterStartSpecifiedAbilityResponse(response);
2484     appMgrServiceInner->ScheduleAcceptWantDone(appRecord->GetRecordId(), want, flag);
2485 
2486     HILOG_INFO("ScheduleAcceptWantDone_001 end");
2487 }
2488 
2489 /**
2490  * @tc.name: HandleStartSpecifiedAbilityTimeOut_001
2491  * @tc.desc: handle start specified ability time out.
2492  * @tc.type: FUNC
2493  * @tc.require: issueI5W4S7
2494  */
2495 HWTEST_F(AppMgrServiceInnerTest, HandleStartSpecifiedAbilityTimeOut_001, TestSize.Level0)
2496 {
2497     HILOG_INFO("HandleStartSpecifiedAbilityTimeOut_001 start");
2498     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2499     EXPECT_NE(appMgrServiceInner, nullptr);
2500 
2501     appMgrServiceInner->HandleStartSpecifiedAbilityTimeOut(0);
2502 
2503     BundleInfo bundleInfo;
2504     std::string appName = "test_appName";
2505     std::string processName = "test_processName";
2506     std::string bundleName = "test_bundleName";
2507     sptr<IRemoteObject> token = new MockAbilityToken();
2508     std::shared_ptr<AppRunningRecord> appRecord =
2509         appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo);
2510     EXPECT_NE(appRecord, nullptr);
2511     appRecord->eventId_ = 0;
2512     appMgrServiceInner->HandleStartSpecifiedAbilityTimeOut(0);
2513 
2514     appRecord->isSpecifiedAbility_ = true;
2515     appMgrServiceInner->HandleStartSpecifiedAbilityTimeOut(0);
2516 
2517     sptr<IStartSpecifiedAbilityResponse> response;
2518     appMgrServiceInner->startSpecifiedAbilityResponse_ = response;
2519     appMgrServiceInner->HandleStartSpecifiedAbilityTimeOut(0);
2520 
2521     appRecord->isSpecifiedAbility_ = false;
2522     appMgrServiceInner->HandleStartSpecifiedAbilityTimeOut(0);
2523 
2524     appMgrServiceInner->appRunningManager_ = nullptr;
2525     appMgrServiceInner->HandleStartSpecifiedAbilityTimeOut(0);
2526 
2527     HILOG_INFO("HandleStartSpecifiedAbilityTimeOut_001 end");
2528 }
2529 
2530 /**
2531  * @tc.name: UpdateConfiguration_001
2532  * @tc.desc: update configuration.
2533  * @tc.type: FUNC
2534  * @tc.require: issueI5W4S7
2535  */
2536 HWTEST_F(AppMgrServiceInnerTest, UpdateConfiguration_001, TestSize.Level0)
2537 {
2538     HILOG_INFO("UpdateConfiguration_001 start");
2539     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2540     EXPECT_NE(appMgrServiceInner, nullptr);
2541 
2542     Configuration config;
2543     appMgrServiceInner->UpdateConfiguration(config);
2544 
2545     auto testLanguge = "ch-zh";
2546     config.AddItem(AAFwk::GlobalConfigurationKey::SYSTEM_LANGUAGE, testLanguge);
2547     appMgrServiceInner->UpdateConfiguration(config);
2548 
2549     auto appRunningRecordMap = appMgrServiceInner->appRunningManager_->appRunningRecordMap_;
2550     for (const auto& item : appRunningRecordMap) {
2551         const auto& appRecord = item.second;
2552         if (appRecord) {
2553             appRecord->appLifeCycleDeal_ = nullptr;
2554         }
2555     }
2556     appMgrServiceInner->UpdateConfiguration(config);
2557 
2558     sptr<MockConfigurationObserver> observer(new (std::nothrow) MockConfigurationObserver());
2559     appMgrServiceInner->configurationObservers_.push_back(observer);
2560     sptr<IConfigurationObserver> observer1;
2561     appMgrServiceInner->configurationObservers_.push_back(observer1);
2562     appMgrServiceInner->configurationObservers_.push_back(nullptr);
2563     appMgrServiceInner->UpdateConfiguration(config);
2564 
2565     appMgrServiceInner->appRunningManager_ = nullptr;
2566     appMgrServiceInner->UpdateConfiguration(config);
2567 
2568     HILOG_INFO("UpdateConfiguration_001 end");
2569 }
2570 
2571 /**
2572  * @tc.name: RegisterConfigurationObserver_001
2573  * @tc.desc: register configuration observer.
2574  * @tc.type: FUNC
2575  * @tc.require: issueI5W4S7
2576  */
2577 HWTEST_F(AppMgrServiceInnerTest, RegisterConfigurationObserver_001, TestSize.Level0)
2578 {
2579     HILOG_INFO("RegisterConfigurationObserver_001 start");
2580     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2581     EXPECT_NE(appMgrServiceInner, nullptr);
2582 
2583     appMgrServiceInner->configurationObservers_.clear();
2584 
2585     appMgrServiceInner->RegisterConfigurationObserver(nullptr);
2586 
2587     sptr<MockConfigurationObserver> observer(new (std::nothrow) MockConfigurationObserver());
2588     appMgrServiceInner->RegisterConfigurationObserver(observer);
2589     appMgrServiceInner->RegisterConfigurationObserver(observer);
2590 
2591     HILOG_INFO("RegisterConfigurationObserver_001 end");
2592 }
2593 
2594 /**
2595  * @tc.name: UnregisterConfigurationObserver_001
2596  * @tc.desc: unregister configuration observer.
2597  * @tc.type: FUNC
2598  * @tc.require: issueI5W4S7
2599  */
2600 HWTEST_F(AppMgrServiceInnerTest, UnregisterConfigurationObserver_001, TestSize.Level0)
2601 {
2602     HILOG_INFO("UnregisterConfigurationObserver_001 start");
2603     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2604     EXPECT_NE(appMgrServiceInner, nullptr);
2605 
2606     appMgrServiceInner->configurationObservers_.clear();
2607 
2608     appMgrServiceInner->UnregisterConfigurationObserver(nullptr);
2609 
2610     sptr<MockConfigurationObserver> observer(new (std::nothrow) MockConfigurationObserver());
2611     appMgrServiceInner->UnregisterConfigurationObserver(observer);
2612 
2613     appMgrServiceInner->RegisterConfigurationObserver(observer);
2614     appMgrServiceInner->UnregisterConfigurationObserver(observer);
2615 
2616     HILOG_INFO("UnregisterConfigurationObserver_001 end");
2617 }
2618 
2619 /**
2620  * @tc.name: InitGlobalConfiguration_001
2621  * @tc.desc: init global configuration.
2622  * @tc.type: FUNC
2623  * @tc.require: issueI5W4S7
2624  */
2625 HWTEST_F(AppMgrServiceInnerTest, InitGlobalConfiguration_001, TestSize.Level0)
2626 {
2627     HILOG_INFO("InitGlobalConfiguration_001 start");
2628     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2629     EXPECT_NE(appMgrServiceInner, nullptr);
2630 
2631     appMgrServiceInner->InitGlobalConfiguration();
2632 
2633     appMgrServiceInner->configuration_ = nullptr;
2634     appMgrServiceInner->InitGlobalConfiguration();
2635 
2636     HILOG_INFO("InitGlobalConfiguration_001 end");
2637 }
2638 
2639 /**
2640  * @tc.name: KillApplicationByRecord_001
2641  * @tc.desc: kill application by record.
2642  * @tc.type: FUNC
2643  * @tc.require: issueI5W4S7
2644  */
2645 HWTEST_F(AppMgrServiceInnerTest, KillApplicationByRecord_001, TestSize.Level0)
2646 {
2647     HILOG_INFO("KillApplicationByRecord_001 start");
2648     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2649     EXPECT_NE(appMgrServiceInner, nullptr);
2650 
2651     std::shared_ptr<AppRunningRecord> appRecord = nullptr;
2652     BundleInfo bundleInfo;
2653     std::string processName = "test_processName";
2654     std::shared_ptr<AppRunningRecord> appRecord1 =
2655         appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo);
2656     EXPECT_NE(appRecord1, nullptr);
2657     appMgrServiceInner->KillApplicationByRecord(appRecord);
2658     appMgrServiceInner->KillApplicationByRecord(appRecord1);
2659 
2660     appMgrServiceInner->taskHandler_ = nullptr;
2661     appMgrServiceInner->KillApplicationByRecord(appRecord);
2662     appMgrServiceInner->KillApplicationByRecord(appRecord1);
2663 
2664     HILOG_INFO("KillApplicationByRecord_001 end");
2665 }
2666 
2667 /**
2668  * @tc.name: SendHiSysEvent_001
2669  * @tc.desc: send hi sys event.
2670  * @tc.type: FUNC
2671  * @tc.require: issueI5W4S7
2672  */
2673 HWTEST_F(AppMgrServiceInnerTest, SendHiSysEvent_001, TestSize.Level0)
2674 {
2675     HILOG_INFO("SendHiSysEvent_001 start");
2676     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2677     EXPECT_NE(appMgrServiceInner, nullptr);
2678 
2679     appMgrServiceInner->SendHiSysEvent(0, 0);
2680 
2681     BundleInfo bundleInfo;
2682     std::string processName = "test_processName";
2683     std::shared_ptr<AppRunningRecord> appRecord =
2684         appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo);
2685     EXPECT_NE(appRecord, nullptr);
2686     appRecord->eventId_ = 0;
2687     appMgrServiceInner->SendHiSysEvent(0, 0);
2688     appMgrServiceInner->SendHiSysEvent(1, 0);
2689     appMgrServiceInner->SendHiSysEvent(2, 0);
2690     appMgrServiceInner->SendHiSysEvent(3, 0);
2691     appMgrServiceInner->SendHiSysEvent(4, 0);
2692 
2693     appMgrServiceInner->appRunningManager_ = nullptr;
2694     appMgrServiceInner->SendHiSysEvent(0, 0);
2695 
2696     HILOG_INFO("SendHiSysEvent_001 end");
2697 }
2698 
2699 /**
2700  * @tc.name: GetAbilityRecordsByProcessID_001
2701  * @tc.desc: get ability records by process id.
2702  * @tc.type: FUNC
2703  * @tc.require: issueI5W4S7
2704  */
2705 HWTEST_F(AppMgrServiceInnerTest, GetAbilityRecordsByProcessID_001, TestSize.Level0)
2706 {
2707     HILOG_INFO("GetAbilityRecordsByProcessID_001 start");
2708     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2709     EXPECT_NE(appMgrServiceInner, nullptr);
2710 
2711     std::vector<sptr<IRemoteObject>> tokens;
2712     appMgrServiceInner->GetAbilityRecordsByProcessID(0, tokens);
2713 
2714     BundleInfo bundleInfo;
2715     std::string processName = "test_processName";
2716     std::shared_ptr<AppRunningRecord> appRecord =
2717         appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo);
2718     EXPECT_NE(appRecord, nullptr);
2719     int pid = appRecord->GetPriorityObject()->GetPid();
2720     appMgrServiceInner->GetAbilityRecordsByProcessID(pid, tokens);
2721 
2722     HILOG_INFO("GetAbilityRecordsByProcessID_001 end");
2723 }
2724 
2725 /**
2726  * @tc.name: GetApplicationInfoByProcessID_001
2727  * @tc.desc: get applicationInfo by process id.
2728  * @tc.type: FUNC
2729  * @tc.require: issueI5W4S7
2730  */
2731 HWTEST_F(AppMgrServiceInnerTest, GetApplicationInfoByProcessID_001, TestSize.Level0)
2732 {
2733     HILOG_INFO("GetApplicationInfoByProcessID_001 start");
2734     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2735     EXPECT_NE(appMgrServiceInner, nullptr);
2736 
2737     ApplicationInfo application;
2738     bool debug = false;
2739     appMgrServiceInner->GetApplicationInfoByProcessID(0, application, debug);
2740 
2741     BundleInfo bundleInfo;
2742     std::string processName = "test_processName";
2743     std::shared_ptr<AppRunningRecord> appRecord =
2744         appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo);
2745     EXPECT_NE(appRecord, nullptr);
2746     int pid = appRecord->GetPriorityObject()->GetPid();
2747     appMgrServiceInner->GetApplicationInfoByProcessID(pid, application, debug);
2748 
2749     appRecord->appInfo_ = nullptr;
2750     appMgrServiceInner->GetApplicationInfoByProcessID(pid, application, debug);
2751 
2752     HILOG_INFO("GetApplicationInfoByProcessID_001 end");
2753 }
2754 
2755 /**
2756  * @tc.name: VerifyProcessPermission_001
2757  * @tc.desc: verify process permission.
2758  * @tc.type: FUNC
2759  * @tc.require: issueI5W4S7
2760  */
2761 HWTEST_F(AppMgrServiceInnerTest, VerifyProcessPermission_001, TestSize.Level0)
2762 {
2763     HILOG_INFO("VerifyProcessPermission_001 start");
2764     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2765     EXPECT_NE(appMgrServiceInner, nullptr);
2766 
2767     appMgrServiceInner->VerifyProcessPermission("");
2768 
2769     appMgrServiceInner->appRunningManager_ = nullptr;
2770     appMgrServiceInner->VerifyProcessPermission("");
2771 
2772     HILOG_INFO("VerifyProcessPermission_001 end");
2773 }
2774 
2775 /**
2776  * @tc.name: VerifyAPL_001
2777  * @tc.desc: verify APL.
2778  * @tc.type: FUNC
2779  * @tc.require: issueI5W4S7
2780  */
2781 HWTEST_F(AppMgrServiceInnerTest, VerifyAPL_001, TestSize.Level0)
2782 {
2783     HILOG_INFO("VerifyAPL_001 start");
2784     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2785     EXPECT_NE(appMgrServiceInner, nullptr);
2786 
2787     appMgrServiceInner->VerifyAPL();
2788 
2789     appMgrServiceInner->appRunningManager_ = nullptr;
2790     appMgrServiceInner->VerifyAPL();
2791 
2792     HILOG_INFO("VerifyAPL_001 end");
2793 }
2794 
2795 /**
2796  * @tc.name: VerifyAccountPermission_001
2797  * @tc.desc: verify account permission.
2798  * @tc.type: FUNC
2799  * @tc.require: issueI5W4S7
2800  */
2801 HWTEST_F(AppMgrServiceInnerTest, VerifyAccountPermission_001, TestSize.Level0)
2802 {
2803     HILOG_INFO("VerifyAccountPermission_001 start");
2804     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2805     EXPECT_NE(appMgrServiceInner, nullptr);
2806 
2807     std::string permissionName = "test_permissionName";
2808     appMgrServiceInner->VerifyAccountPermission(permissionName, 0);
2809 
2810     HILOG_INFO("VerifyAccountPermission_001 end");
2811 }
2812 
2813 /**
2814  * @tc.name: PreStartNWebSpawnProcess_003
2815  * @tc.desc: prestart nwebspawn process.
2816  * @tc.type: FUNC
2817  * @tc.require: issueI5W4S7
2818  */
2819 HWTEST_F(AppMgrServiceInnerTest, PreStartNWebSpawnProcess_003, TestSize.Level0)
2820 {
2821     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2822     EXPECT_NE(appMgrServiceInner, nullptr);
2823 
2824     int callingPid = 1;
2825     appMgrServiceInner->remoteClientManager_->nwebSpawnClient_ = nullptr;
2826     int ret = appMgrServiceInner->PreStartNWebSpawnProcess(callingPid);
2827     EXPECT_EQ(ret, ERR_INVALID_VALUE);
2828 }
2829 
2830 /**
2831  * @tc.name: StartRenderProcess_001
2832  * @tc.desc: start render process.
2833  * @tc.type: FUNC
2834  * @tc.require: issueI5W4S7
2835  */
2836 HWTEST_F(AppMgrServiceInnerTest, StartRenderProcess_001, TestSize.Level0)
2837 {
2838     HILOG_INFO("StartRenderProcess_001 start");
2839     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2840     EXPECT_NE(appMgrServiceInner, nullptr);
2841 
2842     pid_t hostPid = 0;
2843     std::string renderParam = "test_renderParam";
2844     pid_t renderPid = 0;
2845     int ret = appMgrServiceInner->StartRenderProcess(hostPid, "", 0, 0, 0, renderPid);
2846     EXPECT_EQ(ret, ERR_INVALID_VALUE);
2847     ret = appMgrServiceInner->StartRenderProcess(hostPid, "", 0, 0, 1, renderPid);
2848     EXPECT_EQ(ret, ERR_INVALID_VALUE);
2849     ret = appMgrServiceInner->StartRenderProcess(hostPid, "", 0, 1, 0, renderPid);
2850     EXPECT_EQ(ret, ERR_INVALID_VALUE);
2851     ret = appMgrServiceInner->StartRenderProcess(hostPid, "", 0, 1, 1, renderPid);
2852     EXPECT_EQ(ret, ERR_INVALID_VALUE);
2853     ret = appMgrServiceInner->StartRenderProcess(hostPid, "", 1, 0, 0, renderPid);
2854     EXPECT_EQ(ret, ERR_INVALID_VALUE);
2855     ret = appMgrServiceInner->StartRenderProcess(hostPid, "", 1, 0, 1, renderPid);
2856     EXPECT_EQ(ret, ERR_INVALID_VALUE);
2857     ret = appMgrServiceInner->StartRenderProcess(hostPid, "", 1, 1, 0, renderPid);
2858     EXPECT_EQ(ret, ERR_INVALID_VALUE);
2859     ret = appMgrServiceInner->StartRenderProcess(hostPid, "", 1, 1, 1, renderPid);
2860     EXPECT_EQ(ret, ERR_INVALID_VALUE);
2861     ret = appMgrServiceInner->StartRenderProcess(hostPid, renderParam, 0, 0, 0, renderPid);
2862     EXPECT_EQ(ret, ERR_INVALID_VALUE);
2863     ret = appMgrServiceInner->StartRenderProcess(hostPid, renderParam, 0, 0, 1, renderPid);
2864     EXPECT_EQ(ret, ERR_INVALID_VALUE);
2865     ret = appMgrServiceInner->StartRenderProcess(hostPid, renderParam, 0, 1, 0, renderPid);
2866     EXPECT_EQ(ret, ERR_INVALID_VALUE);
2867     ret = appMgrServiceInner->StartRenderProcess(hostPid, renderParam, 0, 1, 1, renderPid);
2868     EXPECT_EQ(ret, ERR_INVALID_VALUE);
2869     ret = appMgrServiceInner->StartRenderProcess(hostPid, renderParam, 1, 0, 0, renderPid);
2870     EXPECT_EQ(ret, ERR_INVALID_VALUE);
2871     ret = appMgrServiceInner->StartRenderProcess(hostPid, renderParam, 1, 0, 1, renderPid);
2872     EXPECT_EQ(ret, ERR_INVALID_VALUE);
2873     ret = appMgrServiceInner->StartRenderProcess(hostPid, renderParam, 1, 1, 0, renderPid);
2874     EXPECT_EQ(ret, ERR_INVALID_VALUE);
2875     ret = appMgrServiceInner->StartRenderProcess(hostPid, renderParam, 1, 1, 1, renderPid);
2876     EXPECT_EQ(ret, ERR_INVALID_VALUE);
2877 
2878     HILOG_INFO("StartRenderProcess_001 end");
2879 }
2880 
2881 /**
2882  * @tc.name: StartRenderProcess_002
2883  * @tc.desc: start render process.
2884  * @tc.type: FUNC
2885  * @tc.require: issueI5W4S7
2886  */
2887 HWTEST_F(AppMgrServiceInnerTest, StartRenderProcess_002, TestSize.Level0)
2888 {
2889     HILOG_INFO("StartRenderProcess_002 start");
2890     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2891     EXPECT_NE(appMgrServiceInner, nullptr);
2892 
2893     pid_t hostPid1 = 1;
2894     std::string renderParam = "test_renderParam";
2895     pid_t renderPid = 0;
2896 
2897     BundleInfo bundleInfo;
2898     std::string processName = "test_processName";
2899     std::shared_ptr<AppRunningRecord> appRecord =
2900         appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo);
2901     EXPECT_NE(appRecord, nullptr);
2902     appRecord->GetPriorityObject()->SetPid(hostPid1);
2903     int ret = appMgrServiceInner->StartRenderProcess(hostPid1, renderParam, 1, 1, 1, renderPid);
2904     EXPECT_EQ(ret, ERR_INVALID_VALUE);
2905 
2906     std::shared_ptr<RenderRecord> renderRecord =
2907         RenderRecord::CreateRenderRecord(hostPid1, renderParam, 1, 1, 1, appRecord);
2908     appRecord->AddRenderRecord(renderRecord);
2909     ret = appMgrServiceInner->StartRenderProcess(hostPid1, renderParam, 1, 1, 1, renderPid);
2910     EXPECT_EQ(ret, ERR_INVALID_VALUE);
2911 
2912     appMgrServiceInner->appRunningManager_ = nullptr;
2913     ret = appMgrServiceInner->StartRenderProcess(hostPid1, renderParam, 1, 1, 1, renderPid);
2914     EXPECT_EQ(ret, ERR_INVALID_VALUE);
2915 
2916     HILOG_INFO("StartRenderProcess_002 end");
2917 }
2918 
2919 /**
2920  * @tc.name: StartRenderProcess_003
2921  * @tc.desc: start render process.
2922  * @tc.type: FUNC
2923  * @tc.require: issueI5W4S7
2924  */
2925 HWTEST_F(AppMgrServiceInnerTest, StartRenderProcess_003, TestSize.Level0)
2926 {
2927     HILOG_INFO("StartRenderProcess_003 start");
2928     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2929     EXPECT_NE(appMgrServiceInner, nullptr);
2930 
2931     pid_t hostPid1 = 1;
2932     std::string renderParam = "test_renderParam";
2933     pid_t renderPid = 0;
2934     int ret = appMgrServiceInner->StartRenderProcess(hostPid1, "", 0, 0, 0, renderPid);
2935     EXPECT_EQ(ret, ERR_INVALID_VALUE);
2936     ret = appMgrServiceInner->StartRenderProcess(hostPid1, "", 0, 0, 1, renderPid);
2937     EXPECT_EQ(ret, ERR_INVALID_VALUE);
2938     ret = appMgrServiceInner->StartRenderProcess(hostPid1, "", 0, 1, 0, renderPid);
2939     EXPECT_EQ(ret, ERR_INVALID_VALUE);
2940     ret = appMgrServiceInner->StartRenderProcess(hostPid1, "", 0, 1, 1, renderPid);
2941     EXPECT_EQ(ret, ERR_INVALID_VALUE);
2942     ret = appMgrServiceInner->StartRenderProcess(hostPid1, "", 1, 0, 0, renderPid);
2943     EXPECT_EQ(ret, ERR_INVALID_VALUE);
2944     ret = appMgrServiceInner->StartRenderProcess(hostPid1, "", 1, 0, 1, renderPid);
2945     EXPECT_EQ(ret, ERR_INVALID_VALUE);
2946     ret = appMgrServiceInner->StartRenderProcess(hostPid1, "", 1, 1, 0, renderPid);
2947     EXPECT_EQ(ret, ERR_INVALID_VALUE);
2948     ret = appMgrServiceInner->StartRenderProcess(hostPid1, "", 1, 1, 1, renderPid);
2949     EXPECT_EQ(ret, ERR_INVALID_VALUE);
2950     ret = appMgrServiceInner->StartRenderProcess(hostPid1, renderParam, 0, 0, 0, renderPid);
2951     EXPECT_EQ(ret, ERR_INVALID_VALUE);
2952     ret = appMgrServiceInner->StartRenderProcess(hostPid1, renderParam, 0, 0, 1, renderPid);
2953     EXPECT_EQ(ret, ERR_INVALID_VALUE);
2954     ret = appMgrServiceInner->StartRenderProcess(hostPid1, renderParam, 0, 1, 0, renderPid);
2955     EXPECT_EQ(ret, ERR_INVALID_VALUE);
2956 
2957     ret = appMgrServiceInner->StartRenderProcess(hostPid1, renderParam, 0, 1, 1, renderPid);
2958     EXPECT_EQ(ret, ERR_INVALID_VALUE);
2959 
2960     ret = appMgrServiceInner->StartRenderProcess(hostPid1, renderParam, 1, 0, 0, renderPid);
2961     EXPECT_EQ(ret, ERR_INVALID_VALUE);
2962     ret = appMgrServiceInner->StartRenderProcess(hostPid1, renderParam, 1, 0, 1, renderPid);
2963     EXPECT_EQ(ret, ERR_INVALID_VALUE);
2964     ret = appMgrServiceInner->StartRenderProcess(hostPid1, renderParam, 1, 1, 0, renderPid);
2965     EXPECT_EQ(ret, ERR_INVALID_VALUE);
2966 
2967     ret = appMgrServiceInner->StartRenderProcess(hostPid1, renderParam, 1, 1, 1, renderPid);
2968     EXPECT_EQ(ret, ERR_INVALID_VALUE);
2969     HILOG_INFO("StartRenderProcess_003 end");
2970 }
2971 
2972 /**
2973  * @tc.name: AttachRenderProcess_001
2974  * @tc.desc: attach render process.
2975  * @tc.type: FUNC
2976  * @tc.require: issueI5W4S7
2977  */
2978 HWTEST_F(AppMgrServiceInnerTest, AttachRenderProcess_001, TestSize.Level0)
2979 {
2980     HILOG_INFO("AttachRenderProcess_001 start");
2981     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2982     EXPECT_NE(appMgrServiceInner, nullptr);
2983 
2984     pid_t pid = 0;
2985     sptr<IRenderScheduler> scheduler;
2986     appMgrServiceInner->AttachRenderProcess(pid, scheduler);
2987 
2988     pid = 1;
2989     appMgrServiceInner->AttachRenderProcess(pid, scheduler);
2990 
2991     sptr<MockRenderScheduler> mockRenderScheduler = new (std::nothrow) MockRenderScheduler();
2992     EXPECT_CALL(*mockRenderScheduler, AsObject()).Times(1);
2993     EXPECT_CALL(*mockRenderScheduler, NotifyBrowserFd(1, 1, 1)).Times(1);
2994     appMgrServiceInner->AttachRenderProcess(pid, mockRenderScheduler);
2995 
2996     BundleInfo bundleInfo;
2997     std::string processName = "test_processName";
2998     std::shared_ptr<AppRunningRecord> appRecord =
2999         appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo);
3000     EXPECT_NE(appRecord, nullptr);
3001     appRecord->GetPriorityObject()->SetPid(pid);
3002     std::string renderParam = "test_renderParam";
3003     std::shared_ptr<RenderRecord> renderRecord =
3004         RenderRecord::CreateRenderRecord(pid, renderParam, 1, 1, 1, appRecord);
3005     EXPECT_NE(renderRecord, nullptr);
3006     renderRecord->SetPid(pid);
3007     appRecord->AddRenderRecord(renderRecord);
3008     appMgrServiceInner->AttachRenderProcess(pid, mockRenderScheduler);
3009 
3010     appMgrServiceInner->appRunningManager_ = nullptr;
3011     appMgrServiceInner->AttachRenderProcess(pid, mockRenderScheduler);
3012 
3013     HILOG_INFO("AttachRenderProcess_001 end");
3014 }
3015 
3016 /**
3017  * @tc.name: BuildStartFlags_001
3018  * @tc.desc: build start flags.
3019  * @tc.type: FUNC
3020  * @tc.require: issueI5W4S7
3021  */
3022 HWTEST_F(AppMgrServiceInnerTest, BuildStartFlags_001, TestSize.Level0)
3023 {
3024     HILOG_INFO("BuildStartFlags_001 start");
3025     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
3026     EXPECT_NE(appMgrServiceInner, nullptr);
3027 
3028     AAFwk::Want want;
3029     AbilityInfo abilityInfo;
3030     appMgrServiceInner->BuildStartFlags(want, abilityInfo);
3031 
3032     want.SetParam("coldStart", true);
3033     want.SetParam("ohos.dlp.params.index", 1);
3034     abilityInfo.extensionAbilityType = ExtensionAbilityType::BACKUP;
3035     appMgrServiceInner->BuildStartFlags(want, abilityInfo);
3036 
3037     HILOG_INFO("BuildStartFlags_001 end");
3038 }
3039 
3040 /**
3041  * @tc.name: RegisterFocusListener_001
3042  * @tc.desc: register focus listener.
3043  * @tc.type: FUNC
3044  * @tc.require: issueI5W4S7
3045  */
3046 HWTEST_F(AppMgrServiceInnerTest, RegisterFocusListener_001, TestSize.Level0)
3047 {
3048     HILOG_INFO("RegisterFocusListener_001 start");
3049     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
3050     EXPECT_NE(appMgrServiceInner, nullptr);
3051 
3052     appMgrServiceInner->RegisterFocusListener();
3053 
3054     appMgrServiceInner->focusListener_ = nullptr;
3055     appMgrServiceInner->RegisterFocusListener();
3056 
3057     HILOG_INFO("RegisterFocusListener_001 end");
3058 }
3059 
3060 /**
3061  * @tc.name: HandleFocused_001
3062  * @tc.desc: handle focused.
3063  * @tc.type: FUNC
3064  * @tc.require: issueI5W4S7
3065  */
3066 HWTEST_F(AppMgrServiceInnerTest, HandleFocused_001, TestSize.Level0)
3067 {
3068     HILOG_INFO("HandleFocused_001 start");
3069     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
3070     EXPECT_NE(appMgrServiceInner, nullptr);
3071 
3072     sptr<Rosen::FocusChangeInfo> focusChangeInfo;
3073     appMgrServiceInner->HandleFocused(focusChangeInfo);
3074 
3075     pid_t pid = 1;
3076     focusChangeInfo = new Rosen::FocusChangeInfo();
3077     appMgrServiceInner->HandleFocused(focusChangeInfo);
3078 
3079     focusChangeInfo->pid_ = pid;
3080     appMgrServiceInner->HandleFocused(focusChangeInfo);
3081 
3082     BundleInfo bundleInfo;
3083     std::string processName = "test_processName";
3084     std::shared_ptr<AppRunningRecord> appRecord =
3085         appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo);
3086     EXPECT_NE(appRecord, nullptr);
3087     appRecord->GetPriorityObject()->SetPid(pid);
3088     appMgrServiceInner->HandleFocused(focusChangeInfo);
3089 
3090     HILOG_INFO("HandleFocused_001 end");
3091 }
3092 
3093 /**
3094  * @tc.name: HandleUnfocused_001
3095  * @tc.desc: handle unfocused.
3096  * @tc.type: FUNC
3097  * @tc.require: issueI5W4S7
3098  */
3099 HWTEST_F(AppMgrServiceInnerTest, HandleUnfocused_001, TestSize.Level0)
3100 {
3101     HILOG_INFO("HandleUnfocused_001 start");
3102     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
3103     EXPECT_NE(appMgrServiceInner, nullptr);
3104 
3105     sptr<Rosen::FocusChangeInfo> focusChangeInfo;
3106     appMgrServiceInner->HandleUnfocused(focusChangeInfo);
3107 
3108     pid_t pid = 1;
3109     focusChangeInfo = new Rosen::FocusChangeInfo();
3110     appMgrServiceInner->HandleUnfocused(focusChangeInfo);
3111 
3112     focusChangeInfo->pid_ = pid;
3113     appMgrServiceInner->HandleUnfocused(focusChangeInfo);
3114 
3115     BundleInfo bundleInfo;
3116     std::string processName = "test_processName";
3117     std::shared_ptr<AppRunningRecord> appRecord =
3118         appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo);
3119     EXPECT_NE(appRecord, nullptr);
3120     appRecord->GetPriorityObject()->SetPid(pid);
3121     appMgrServiceInner->HandleUnfocused(focusChangeInfo);
3122 
3123     HILOG_INFO("HandleUnfocused_001 end");
3124 }
3125 
3126 /**
3127  * @tc.name: GetAppRunningStateByBundleName_001
3128  * @tc.desc: get app running state by bundle name.
3129  * @tc.type: FUNC
3130  * @tc.require: issueI5W4S7
3131  */
3132 HWTEST_F(AppMgrServiceInnerTest, GetAppRunningStateByBundleName_001, TestSize.Level0)
3133 {
3134     HILOG_INFO("GetAppRunningStateByBundleName_001 start");
3135     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
3136     EXPECT_NE(appMgrServiceInner, nullptr);
3137 
3138     std::string bundleName = "test_bundleName";
3139     appMgrServiceInner->GetAppRunningStateByBundleName(bundleName);
3140 
3141     appMgrServiceInner->appRunningManager_ = nullptr;
3142     appMgrServiceInner->GetAppRunningStateByBundleName(bundleName);
3143 
3144     HILOG_INFO("GetAppRunningStateByBundleName_001 end");
3145 }
3146 
3147 /**
3148  * @tc.name: NotifyLoadRepairPatch_001
3149  * @tc.desc: notify load repair patch.
3150  * @tc.type: FUNC
3151  * @tc.require: issueI5W4S7
3152  */
3153 HWTEST_F(AppMgrServiceInnerTest, NotifyLoadRepairPatch_001, TestSize.Level0)
3154 {
3155     HILOG_INFO("NotifyLoadRepairPatch_001 start");
3156     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
3157     EXPECT_NE(appMgrServiceInner, nullptr);
3158 
3159     std::string bundleName = "test_bundleName";
3160     sptr<IQuickFixCallback> callback;
3161     appMgrServiceInner->NotifyLoadRepairPatch(bundleName, callback);
3162 
3163     appMgrServiceInner->appRunningManager_ = nullptr;
3164     appMgrServiceInner->NotifyLoadRepairPatch(bundleName, callback);
3165 
3166     HILOG_INFO("NotifyLoadRepairPatch_001 end");
3167 }
3168 
3169 /**
3170  * @tc.name: NotifyHotReloadPage_001
3171  * @tc.desc: notify hot reload page.
3172  * @tc.type: FUNC
3173  * @tc.require: issueI5W4S7
3174  */
3175 HWTEST_F(AppMgrServiceInnerTest, NotifyHotReloadPage_001, TestSize.Level0)
3176 {
3177     HILOG_INFO("NotifyHotReloadPage_001 start");
3178     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
3179     EXPECT_NE(appMgrServiceInner, nullptr);
3180 
3181     std::string bundleName = "test_bundleName";
3182     sptr<IQuickFixCallback> callback;
3183     appMgrServiceInner->NotifyHotReloadPage(bundleName, callback);
3184 
3185     appMgrServiceInner->appRunningManager_ = nullptr;
3186     appMgrServiceInner->NotifyHotReloadPage(bundleName, callback);
3187 
3188     HILOG_INFO("NotifyHotReloadPage_001 end");
3189 }
3190 
3191 /**
3192  * @tc.name: SetContinuousTaskProcess_001
3193  * @tc.desc: set continuous task process.
3194  * @tc.type: FUNC
3195  * @tc.require: issueI5W4S7
3196  */
3197 #ifdef BGTASKMGR_CONTINUOUS_TASK_ENABLE
3198 HWTEST_F(AppMgrServiceInnerTest, SetContinuousTaskProcess_001, TestSize.Level0)
3199 {
3200     HILOG_INFO("SetContinuousTaskProcess_001 start");
3201     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
3202     EXPECT_NE(appMgrServiceInner, nullptr);
3203 
3204     int32_t ret = appMgrServiceInner->SetContinuousTaskProcess(0, true);
3205     EXPECT_EQ(ret, 0);
3206 
3207     BundleInfo bundleInfo;
3208     std::string processName = "test_processName";
3209     std::shared_ptr<AppRunningRecord> appRecord =
3210         appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo);
3211     EXPECT_NE(appRecord, nullptr);
3212     appRecord->GetPriorityObject()->SetPid(0);
3213     ret = appMgrServiceInner->SetContinuousTaskProcess(0, true);
3214     EXPECT_EQ(ret, 0);
3215 
3216     appMgrServiceInner->appRunningManager_ = nullptr;
3217     ret = appMgrServiceInner->SetContinuousTaskProcess(0, true);
3218     EXPECT_EQ(ret, ERR_INVALID_OPERATION);
3219 
3220     HILOG_INFO("SetContinuousTaskProcess_001 end");
3221 }
3222 #endif
3223 
3224 /**
3225  * @tc.name: NotifyUnLoadRepairPatch_001
3226  * @tc.desc: notify unload repair patch.
3227  * @tc.type: FUNC
3228  * @tc.require: issueI5W4S7
3229  */
3230 HWTEST_F(AppMgrServiceInnerTest, NotifyUnLoadRepairPatch_001, TestSize.Level0)
3231 {
3232     HILOG_INFO("NotifyUnLoadRepairPatch_001 start");
3233     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
3234     EXPECT_NE(appMgrServiceInner, nullptr);
3235 
3236     std::string bundleName = "test_bundleName";
3237     sptr<IQuickFixCallback> callback;
3238     appMgrServiceInner->NotifyUnLoadRepairPatch(bundleName, callback);
3239 
3240     appMgrServiceInner->appRunningManager_ = nullptr;
3241     appMgrServiceInner->NotifyUnLoadRepairPatch(bundleName, callback);
3242 
3243     HILOG_INFO("NotifyUnLoadRepairPatch_001 end");
3244 }
3245 
3246 /**
3247  * @tc.name: SetCurrentUserId_001
3248  * @tc.desc: set current userId.
3249  * @tc.type: FUNC
3250  */
3251 HWTEST_F(AppMgrServiceInnerTest, SetCurrentUserId_001, TestSize.Level0)
3252 {
3253     HILOG_INFO("SetCurrentUserId_001 start");
3254     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
3255     EXPECT_NE(appMgrServiceInner, nullptr);
3256 
3257     int userId = 0;
3258     appMgrServiceInner->SetCurrentUserId(userId);
3259     EXPECT_EQ(appMgrServiceInner->currentUserId_, userId);
3260 
3261     HILOG_INFO("SetCurrentUserId_001 end");
3262 }
3263 
3264 /**
3265  * @tc.name: GetProcessMemoryByPid_001
3266  * @tc.desc: Get memorySize by pid.
3267  * @tc.type: FUNC
3268  * @tc.require: issueI76JBF
3269  */
3270 HWTEST_F(AppMgrServiceInnerTest, GetProcessMemoryByPid_001, TestSize.Level0)
3271 {
3272     HILOG_INFO("GetProcessMemoryByPid_001 start");
3273     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
3274     EXPECT_NE(appMgrServiceInner, nullptr);
3275 
3276     int32_t pid = 0;
3277     int32_t memorySize = 0;
3278     int32_t ret = appMgrServiceInner->GetProcessMemoryByPid(pid, memorySize);
3279     EXPECT_EQ(ret, ERR_OK);
3280 
3281     HILOG_INFO("GetProcessMemoryByPid_001 end");
3282 }
3283 
3284 /**
3285  * @tc.name: GetRunningProcessInformation_001
3286  * @tc.desc: Get application processes information list by bundleName.
3287  * @tc.type: FUNC
3288  * @tc.require: issueI76JBF
3289  */
3290 HWTEST_F(AppMgrServiceInnerTest, GetRunningProcessInformation_001, TestSize.Level0)
3291 {
3292     HILOG_INFO("GetRunningProcessInformation_001 start");
3293     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
3294     EXPECT_NE(appMgrServiceInner, nullptr);
3295 
3296     std::string bundleName = "testBundleName";
3297     int32_t userId = 100;
3298     std::vector<RunningProcessInfo> info;
3299     int32_t ret = appMgrServiceInner->GetRunningProcessInformation(bundleName, userId, info);
3300     EXPECT_EQ(ret, ERR_OK);
3301 
3302     appMgrServiceInner->remoteClientManager_ = nullptr;
3303     ret = appMgrServiceInner->GetRunningProcessInformation(bundleName, userId, info);
3304     EXPECT_EQ(ret, ERR_NO_INIT);
3305 
3306     appMgrServiceInner->appRunningManager_ = nullptr;
3307     ret = appMgrServiceInner->GetRunningProcessInformation(bundleName, userId, info);
3308     EXPECT_EQ(ret, ERR_NO_INIT);
3309 
3310     HILOG_INFO("GetRunningProcessInformation_001 end");
3311 }
3312 
3313 /**
3314  * @tc.name: GetBundleNameByPid_001
3315  * @tc.desc: get bundle name by Pid.
3316  * @tc.type: FUNC
3317  */
3318 HWTEST_F(AppMgrServiceInnerTest, GetBundleNameByPid_001, TestSize.Level1)
3319 {
3320     HILOG_INFO("GetBundleNameByPid_001 start");
3321 
3322     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
3323     EXPECT_NE(appMgrServiceInner, nullptr);
3324     int32_t pid = 0;
3325     std::string name = "test_name";
3326     int32_t uid = 0;
3327     auto ret  = appMgrServiceInner->GetBundleNameByPid(pid, name, uid);
3328     EXPECT_EQ(ret, ERR_INVALID_OPERATION);
3329 
3330     HILOG_INFO("GetBundleNameByPid_001 end");
3331 }
3332 
3333 /**
3334  * @tc.name: GetBundleNameByPid_002
3335  * @tc.desc: get bundle name by Pid.
3336  * @tc.type: FUNC
3337  */
3338 HWTEST_F(AppMgrServiceInnerTest, GetBundleNameByPid_002, TestSize.Level1)
3339 {
3340     HILOG_INFO("GetBundleNameByPid_002 start");
3341 
3342     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
3343     EXPECT_NE(appMgrServiceInner, nullptr);
3344     BundleInfo info;
3345     std::string processName = "test_processName";
3346     appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info);
3347     int32_t pid = 0;
3348     std::string name = "test_name";
3349     int32_t uid = 0;
3350     auto ret  = appMgrServiceInner->GetBundleNameByPid(pid, name, uid);
3351     EXPECT_EQ(ret, ERR_OK);
3352 
3353     HILOG_INFO("GetBundleNameByPid_002 end");
3354 }
3355 } // namespace AppExecFwk
3356 } // namespace OHOS
3357