• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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: AddAbilityStageDone_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: ApplicationBackgrounded_001
535  * @tc.desc: application backgrounded.
536  * @tc.type: FUNC
537  * @tc.require: issueI5W4S7
538  */
539 HWTEST_F(AppMgrServiceInnerTest, ApplicationBackgrounded_001, TestSize.Level0)
540 {
541     HILOG_INFO("ApplicationBackgrounded_001 start");
542     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
543     EXPECT_NE(appMgrServiceInner, nullptr);
544     appMgrServiceInner->Init();
545 
546     appMgrServiceInner->ApplicationBackgrounded(99);
547 
548     BundleInfo info;
549     std::string processName = "test_processName";
550     auto appRecord =
551         appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info);
552     EXPECT_NE(appRecord, nullptr);
553     recordId_ += 1;
554 
555     appMgrServiceInner->ApplicationBackgrounded(recordId_);
556 
557     appRecord->SetState(ApplicationState::APP_STATE_FOREGROUND);
558     appMgrServiceInner->ApplicationBackgrounded(recordId_);
559 
560     HILOG_INFO("ApplicationBackgrounded_001 end");
561 }
562 
563 /**
564  * @tc.name: ApplicationTerminated_001
565  * @tc.desc: application terminated.
566  * @tc.type: FUNC
567  * @tc.require: issueI5W4S7
568  */
569 HWTEST_F(AppMgrServiceInnerTest, ApplicationTerminated_001, TestSize.Level0)
570 {
571     HILOG_INFO("ApplicationTerminated_001 start");
572     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
573     EXPECT_NE(appMgrServiceInner, nullptr);
574 
575     appMgrServiceInner->ApplicationTerminated(99);
576 
577     BundleInfo info;
578     std::string processName = "test_processName";
579     auto appRecord =
580         appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info);
581     EXPECT_NE(appRecord, nullptr);
582     recordId_ += 1;
583 
584     appMgrServiceInner->ApplicationTerminated(recordId_);
585 
586     appRecord->SetKeepAliveAppState(false, true);
587     appMgrServiceInner->ApplicationTerminated(recordId_);
588 
589     appRecord->SetKeepAliveAppState(true, false);
590     appMgrServiceInner->ApplicationTerminated(recordId_);
591 
592     appRecord->SetKeepAliveAppState(true, true);
593     appMgrServiceInner->ApplicationTerminated(recordId_);
594 
595     appRecord->SetKeepAliveAppState(false, false);
596     appMgrServiceInner->ApplicationTerminated(recordId_);
597 
598     appRecord->SetState(ApplicationState::APP_STATE_FOREGROUND);
599     appMgrServiceInner->ApplicationTerminated(recordId_);
600 
601     appRecord->SetState(ApplicationState::APP_STATE_BACKGROUND);
602     appMgrServiceInner->ApplicationTerminated(recordId_);
603 
604     appMgrServiceInner->appRunningManager_ = nullptr;
605     appMgrServiceInner->ApplicationTerminated(recordId_);
606 
607     HILOG_INFO("ApplicationTerminated_001 end");
608 }
609 
610 /**
611  * @tc.name: KillApplication_001
612  * @tc.desc: kill application.
613  * @tc.type: FUNC
614  * @tc.require: issueI5W4S7
615  */
616 HWTEST_F(AppMgrServiceInnerTest, KillApplication_001, TestSize.Level0)
617 {
618     HILOG_INFO("KillApplication_001 start");
619     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
620     EXPECT_NE(appMgrServiceInner, nullptr);
621 
622     std::string bundleName = "test_bundleName";
623     appMgrServiceInner->KillApplication(bundleName);
624 
625     appMgrServiceInner->appRunningManager_ = nullptr;
626     appMgrServiceInner->KillApplication(bundleName);
627 
628     HILOG_INFO("KillApplication_001 end");
629 }
630 
631 /**
632  * @tc.name: KillApplicationByUid_001
633  * @tc.desc: kill application by uid.
634  * @tc.type: FUNC
635  * @tc.require: issueI5W4S7
636  */
637 HWTEST_F(AppMgrServiceInnerTest, KillApplicationByUid_001, TestSize.Level0)
638 {
639     HILOG_INFO("KillApplicationByUid_001 start");
640     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
641     EXPECT_NE(appMgrServiceInner, nullptr);
642 
643     std::string bundleName = "test_bundleName";
644     appMgrServiceInner->KillApplicationByUid(bundleName, 0);
645 
646     appMgrServiceInner->remoteClientManager_->SetBundleManager(nullptr);
647     appMgrServiceInner->KillApplicationByUid(bundleName, 0);
648 
649     appMgrServiceInner->remoteClientManager_ = nullptr;
650     appMgrServiceInner->KillApplicationByUid(bundleName, 0);
651 
652     appMgrServiceInner->appRunningManager_ = nullptr;
653     appMgrServiceInner->KillApplicationByUid(bundleName, 0);
654 
655     HILOG_INFO("KillApplicationByUid_001 end");
656 }
657 
658 /**
659  * @tc.name: KillApplicationSelf_001
660  * @tc.desc: kill application self.
661  * @tc.type: FUNC
662  * @tc.require: issueI5W4S7
663  */
664 HWTEST_F(AppMgrServiceInnerTest, KillApplicationSelf_001, TestSize.Level0)
665 {
666     HILOG_INFO("KillApplicationSelf_001 start");
667     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
668     EXPECT_NE(appMgrServiceInner, nullptr);
669 
670     EXPECT_EQ(appMgrServiceInner->KillApplicationSelf(), ERR_INVALID_VALUE);
671 
672     appMgrServiceInner->appRunningManager_ = nullptr;
673     EXPECT_EQ(appMgrServiceInner->KillApplicationSelf(), ERR_NO_INIT);
674 
675     HILOG_INFO("KillApplicationSelf_001 end");
676 }
677 
678 /**
679  * @tc.name: KillApplicationByUserId_001
680  * @tc.desc: kill application by user id.
681  * @tc.type: FUNC
682  * @tc.require: issueI5W4S7
683  */
684 HWTEST_F(AppMgrServiceInnerTest, KillApplicationByUserId_001, TestSize.Level0)
685 {
686     HILOG_INFO("KillApplicationByUserId_001 start");
687     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
688     EXPECT_NE(appMgrServiceInner, nullptr);
689 
690     std::string bundleName = "test_bundleName";
691     int result = appMgrServiceInner->KillApplicationByUserId(bundleName, 0);
692     EXPECT_EQ(result, 0);
693 
694     appMgrServiceInner->remoteClientManager_->SetBundleManager(nullptr);
695     appMgrServiceInner->KillApplicationByUserId(bundleName, 0);
696     EXPECT_EQ(result, 0);
697 
698     appMgrServiceInner->remoteClientManager_ = nullptr;
699     appMgrServiceInner->KillApplicationByUserId(bundleName, 0);
700     EXPECT_EQ(result, 0);
701 
702     appMgrServiceInner->appRunningManager_ = nullptr;
703     appMgrServiceInner->KillApplicationByUserId(bundleName, 0);
704     EXPECT_EQ(result, 0);
705 
706     HILOG_INFO("KillApplicationByUserId_001 end");
707 }
708 
709 /**
710  * @tc.name: KillApplicationByUserIdLocked_001
711  * @tc.desc: kill application by user id locked.
712  * @tc.type: FUNC
713  * @tc.require: issueI5W4S7
714  */
715 HWTEST_F(AppMgrServiceInnerTest, KillApplicationByUserIdLocked_001, TestSize.Level0)
716 {
717     HILOG_INFO("KillApplicationByUserIdLocked_001 start");
718     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
719     EXPECT_NE(appMgrServiceInner, nullptr);
720 
721     std::string bundleName = "test_bundleName";
722     int result = appMgrServiceInner->KillApplicationByUserIdLocked(bundleName, 0);
723     EXPECT_EQ(result, 0);
724 
725     appMgrServiceInner->remoteClientManager_->SetBundleManager(nullptr);
726     appMgrServiceInner->KillApplicationByUserIdLocked(bundleName, 0);
727     EXPECT_EQ(result, 0);
728 
729     appMgrServiceInner->remoteClientManager_ = nullptr;
730     appMgrServiceInner->KillApplicationByUserIdLocked(bundleName, 0);
731     EXPECT_EQ(result, 0);
732 
733     appMgrServiceInner->appRunningManager_ = nullptr;
734     appMgrServiceInner->KillApplicationByUserIdLocked(bundleName, 0);
735     EXPECT_EQ(result, 0);
736 
737     HILOG_INFO("KillApplicationByUserIdLocked_001 end");
738 }
739 
740 /**
741  * @tc.name: ClearUpApplicationData_001
742  * @tc.desc: clear up application data.
743  * @tc.type: FUNC
744  * @tc.require: issueI5W4S7
745  */
746 HWTEST_F(AppMgrServiceInnerTest, ClearUpApplicationData_001, TestSize.Level0)
747 {
748     HILOG_INFO("ClearUpApplicationData_001 start");
749     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
750     EXPECT_NE(appMgrServiceInner, nullptr);
751 
752     std::string bundleName = "test_bundleName";
753     appMgrServiceInner->ClearUpApplicationData(bundleName, 0, 0);
754 
755     HILOG_INFO("ClearUpApplicationData_001 end");
756 }
757 
758 /**
759  * @tc.name: ClearUpApplicationDataByUserId_001
760  * @tc.desc: clear up application data by user id.
761  * @tc.type: FUNC
762  * @tc.require: issueI5W4S7
763  */
764 HWTEST_F(AppMgrServiceInnerTest, ClearUpApplicationDataByUserId_001, TestSize.Level0)
765 {
766     HILOG_INFO("ClearUpApplicationDataByUserId_001 start");
767     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
768     EXPECT_NE(appMgrServiceInner, nullptr);
769 
770     std::string bundleName = "test_bundleName";
771     appMgrServiceInner->ClearUpApplicationDataByUserId(bundleName, 0, 0, 0);
772     appMgrServiceInner->ClearUpApplicationDataByUserId(bundleName, 1, 0, 0);
773     appMgrServiceInner->ClearUpApplicationDataByUserId(bundleName, 1, 1, 0);
774 
775     appMgrServiceInner->appRunningManager_ = nullptr;
776     appMgrServiceInner->ClearUpApplicationDataByUserId(bundleName, 1, 1, 0);
777 
778     appMgrServiceInner->remoteClientManager_->SetBundleManager(nullptr);
779     appMgrServiceInner->ClearUpApplicationDataByUserId(bundleName, 1, 1, 0);
780 
781     HILOG_INFO("ClearUpApplicationDataByUserId_001 end");
782 }
783 
784 /**
785  * @tc.name: GetAllRunningProcesses_001
786  * @tc.desc: get all running processes.
787  * @tc.type: FUNC
788  * @tc.require: issueI5W4S7
789  */
790 HWTEST_F(AppMgrServiceInnerTest, GetAllRunningProcesses_001, TestSize.Level0)
791 {
792     HILOG_INFO("GetAllRunningProcesses_001 start");
793     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
794     EXPECT_NE(appMgrServiceInner, nullptr);
795 
796     std::vector<RunningProcessInfo> info;
797     appMgrServiceInner->GetAllRunningProcesses(info);
798 
799     HILOG_INFO("GetAllRunningProcesses_001 end");
800 }
801 
802 /**
803  * @tc.name: GetProcessRunningInfosByUserId_001
804  * @tc.desc: get process running infos by user id.
805  * @tc.type: FUNC
806  * @tc.require: issueI5W4S7
807  */
808 HWTEST_F(AppMgrServiceInnerTest, GetProcessRunningInfosByUserId_001, TestSize.Level0)
809 {
810     HILOG_INFO("GetProcessRunningInfosByUserId_001 start");
811     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
812     EXPECT_NE(appMgrServiceInner, nullptr);
813 
814     std::vector<RunningProcessInfo> info;
815     appMgrServiceInner->GetProcessRunningInfosByUserId(info, 0);
816 
817     HILOG_INFO("GetProcessRunningInfosByUserId_001 end");
818 }
819 
820 /**
821  * @tc.name: NotifyMemoryLevel_001
822  * @tc.desc: notify memory level.
823  * @tc.type: FUNC
824  * @tc.require: issueI5W4S7
825  */
826 HWTEST_F(AppMgrServiceInnerTest, NotifyMemoryLevel_001, TestSize.Level0)
827 {
828     HILOG_INFO("NotifyMemoryLevel_001 start");
829     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
830     EXPECT_NE(appMgrServiceInner, nullptr);
831 
832     std::vector<RunningProcessInfo> info;
833     int result = appMgrServiceInner->NotifyMemoryLevel(0);
834     EXPECT_EQ(result, 0);
835 
836     result = appMgrServiceInner->NotifyMemoryLevel(1);
837     EXPECT_EQ(result, 0);
838 
839     result = appMgrServiceInner->NotifyMemoryLevel(2);
840     EXPECT_EQ(result, 0);
841 
842     result = appMgrServiceInner->NotifyMemoryLevel(3);
843     EXPECT_EQ(result, 22);
844 
845     appMgrServiceInner->appRunningManager_ = nullptr;
846     result = appMgrServiceInner->NotifyMemoryLevel(3);
847     EXPECT_EQ(result, ERR_INVALID_VALUE);
848 
849     HILOG_INFO("NotifyMemoryLevel_001 end");
850 }
851 
852 /**
853  * @tc.name: KillProcessByPid_001
854  * @tc.desc: kill process by pid.
855  * @tc.type: FUNC
856  * @tc.require: issueI5W4S7
857  */
858 HWTEST_F(AppMgrServiceInnerTest, KillProcessByPid_001, TestSize.Level0)
859 {
860     HILOG_INFO("KillProcessByPid_001 start");
861     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
862     EXPECT_NE(appMgrServiceInner, nullptr);
863 
864     int result = appMgrServiceInner->KillProcessByPid(0);
865     EXPECT_EQ(result, -1);
866 
867     result = appMgrServiceInner->KillProcessByPid(1);
868     EXPECT_EQ(result, 0);
869 
870     HILOG_INFO("KillProcessByPid_001 end");
871 }
872 
873 /**
874  * @tc.name: GetAllPids_001
875  * @tc.desc: get all pids.
876  * @tc.type: FUNC
877  * @tc.require: issueI5W4S7
878  */
879 HWTEST_F(AppMgrServiceInnerTest, GetAllPids_001, TestSize.Level0)
880 {
881     HILOG_INFO("GetAllPids_001 start");
882     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
883     EXPECT_NE(appMgrServiceInner, nullptr);
884 
885     std::list<pid_t> pids;
886     bool result = appMgrServiceInner->GetAllPids(pids);
887     EXPECT_FALSE(result);
888 
889     pids.push_back(1);
890     result = appMgrServiceInner->GetAllPids(pids);
891     EXPECT_TRUE(result);
892 
893     std::string appName = "test_appName";
894     std::string processName = "test_processName";
895     appMgrServiceInner->appProcessManager_->AddAppToRecentList(appName, processName, 0, 0);
896     result = appMgrServiceInner->GetAllPids(pids);
897     EXPECT_TRUE(result);
898 
899     HILOG_INFO("GetAllPids_001 end");
900 }
901 
902 /**
903  * @tc.name: ProcessExist_001
904  * @tc.desc: process exist.
905  * @tc.type: FUNC
906  * @tc.require: issueI5W4S7
907  */
908 HWTEST_F(AppMgrServiceInnerTest, ProcessExist_001, TestSize.Level0)
909 {
910     HILOG_INFO("ProcessExist_001 start");
911     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
912     EXPECT_NE(appMgrServiceInner, nullptr);
913 
914     pid_t pid = 0;
915     bool result = appMgrServiceInner->ProcessExist(pid);
916     EXPECT_FALSE(result);
917 
918     HILOG_INFO("ProcessExist_001 end");
919 }
920 
921 /**
922  * @tc.name: CreateAppRunningRecord_001
923  * @tc.desc: create app running record.
924  * @tc.type: FUNC
925  * @tc.require: issueI5W4S7
926  */
927 HWTEST_F(AppMgrServiceInnerTest, CreateAppRunningRecord_001, TestSize.Level0)
928 {
929     HILOG_INFO("CreateAppRunningRecord_001 start");
930     OHOS::sptr<IRemoteObject> token = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
931     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
932     EXPECT_NE(appMgrServiceInner, nullptr);
933 
934     BundleInfo bundleInfo;
935     HapModuleInfo hapModuleInfo;
936     std::shared_ptr<AAFwk::Want> want;
937     std::string processName = "test_processName";
938 
939     std::shared_ptr<AppRunningRecord> appRecord = appMgrServiceInner->CreateAppRunningRecord(nullptr, nullptr,
940         nullptr, nullptr, "", bundleInfo, hapModuleInfo, nullptr);
941     EXPECT_EQ(appRecord, nullptr);
942 
943     appRecord = appMgrServiceInner->CreateAppRunningRecord(token, nullptr,
944         nullptr, nullptr, "", bundleInfo, hapModuleInfo, nullptr);
945     EXPECT_EQ(appRecord, nullptr);
946 
947     appRecord = appMgrServiceInner->CreateAppRunningRecord(token, nullptr,
948         applicationInfo_, nullptr, "", bundleInfo, hapModuleInfo, nullptr);
949     EXPECT_EQ(appRecord, nullptr);
950 
951     appRecord = appMgrServiceInner->CreateAppRunningRecord(token, nullptr,
952         applicationInfo_, abilityInfo_, "", bundleInfo, hapModuleInfo, nullptr);
953     EXPECT_EQ(appRecord, nullptr);
954 
955     appRecord = appMgrServiceInner->CreateAppRunningRecord(token, nullptr,
956         applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, nullptr);
957     EXPECT_NE(appRecord, nullptr);
958 
959     appRecord = appMgrServiceInner->CreateAppRunningRecord(token, nullptr,
960         applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, nullptr);
961     EXPECT_NE(appRecord, nullptr);
962 
963     appRecord = appMgrServiceInner->CreateAppRunningRecord(token, nullptr,
964         applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, nullptr);
965     EXPECT_NE(appRecord, nullptr);
966 
967     std::shared_ptr<AppRunningRecord> appRecord1 = appMgrServiceInner->CreateAppRunningRecord(token, nullptr,
968         nullptr, abilityInfo_, processName, bundleInfo, hapModuleInfo, want);
969     EXPECT_EQ(appRecord1, nullptr);
970 
971     std::shared_ptr<AppRunningRecord> appRecord2 = appMgrServiceInner->CreateAppRunningRecord(token, nullptr,
972         applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want);
973     EXPECT_NE(appRecord2, nullptr);
974 
975     want = std::make_shared<Want>();
976     const std::string COLD_START = "coldStart";
977     want->SetParam(COLD_START, true);
978     std::shared_ptr<AppRunningRecord> appRecord3 = appMgrServiceInner->CreateAppRunningRecord(token, nullptr,
979         applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want);
980     EXPECT_NE(appRecord3, nullptr);
981 
982     want->SetParam(COLD_START, false);
983     std::shared_ptr<AppRunningRecord> appRecord4 = appMgrServiceInner->CreateAppRunningRecord(token, nullptr,
984         applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want);
985     EXPECT_NE(appRecord4, nullptr);
986 
987     appMgrServiceInner->appRunningManager_ = nullptr;
988     std::shared_ptr<AppRunningRecord> appRecord5 = appMgrServiceInner->CreateAppRunningRecord(token, nullptr,
989         applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want);
990     EXPECT_EQ(appRecord5, nullptr);
991 
992     HILOG_INFO("CreateAppRunningRecord_001 end");
993 }
994 
995 /**
996  * @tc.name: TerminateAbility_001
997  * @tc.desc: terminate ability.
998  * @tc.type: FUNC
999  * @tc.require: issueI5W4S7
1000  */
1001 HWTEST_F(AppMgrServiceInnerTest, TerminateAbility_001, TestSize.Level0)
1002 {
1003     HILOG_INFO("TerminateAbility_001 start");
1004     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1005     EXPECT_NE(appMgrServiceInner, nullptr);
1006 
1007     appMgrServiceInner->TerminateAbility(nullptr, true);
1008     appMgrServiceInner->TerminateAbility(nullptr, false);
1009 
1010     OHOS::sptr<IRemoteObject> token = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
1011     appMgrServiceInner->TerminateAbility(token, true);
1012     appMgrServiceInner->TerminateAbility(token, false);
1013 
1014     appMgrServiceInner->appRunningManager_ = nullptr;
1015     appMgrServiceInner->TerminateAbility(token, true);
1016 
1017     HILOG_INFO("TerminateAbility_001 end");
1018 }
1019 
1020 /**
1021  * @tc.name: UpdateAbilityState_001
1022  * @tc.desc: update ability state.
1023  * @tc.type: FUNC
1024  * @tc.require: issueI5W4S7
1025  */
1026 HWTEST_F(AppMgrServiceInnerTest, UpdateAbilityState_001, TestSize.Level0)
1027 {
1028     HILOG_INFO("UpdateAbilityState_001 start");
1029     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1030     EXPECT_NE(appMgrServiceInner, nullptr);
1031 
1032     appMgrServiceInner->UpdateAbilityState(nullptr, AbilityState::ABILITY_STATE_CREATE);
1033 
1034     OHOS::sptr<IRemoteObject> token = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
1035     appMgrServiceInner->UpdateAbilityState(token, AbilityState::ABILITY_STATE_CREATE);
1036 
1037     BundleInfo bundleInfo;
1038     HapModuleInfo hapModuleInfo;
1039     std::shared_ptr<AAFwk::Want> want;
1040     std::string processName = "test_processName";
1041     std::shared_ptr<AppRunningRecord> appRecord = appMgrServiceInner->CreateAppRunningRecord(token, nullptr,
1042         applicationInfo_, nullptr, processName, bundleInfo, hapModuleInfo, want);
1043     EXPECT_NE(appRecord, nullptr);
1044     appMgrServiceInner->UpdateAbilityState(token, AbilityState::ABILITY_STATE_CREATE);
1045 
1046     OHOS::sptr<IRemoteObject> token1 = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
1047     std::shared_ptr<AppRunningRecord> appRecord1 = appMgrServiceInner->CreateAppRunningRecord(token1, nullptr,
1048         applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want);
1049     EXPECT_NE(appRecord1, nullptr);
1050 
1051     appMgrServiceInner->UpdateAbilityState(token1, AbilityState::ABILITY_STATE_READY);
1052     appMgrServiceInner->UpdateAbilityState(token1, AbilityState::ABILITY_STATE_CREATE);
1053 
1054     auto abilityRecord1 =
1055         appMgrServiceInner->GetAppRunningRecordByAbilityToken(token1)->GetAbilityRunningRecordByToken(token1);
1056     abilityRecord1->SetState(AbilityState::ABILITY_STATE_TERMINATED);
1057     appMgrServiceInner->UpdateAbilityState(token1, AbilityState::ABILITY_STATE_TERMINATED);
1058 
1059     abilityRecord1->SetState(AbilityState::ABILITY_STATE_CONNECTED);
1060     appMgrServiceInner->UpdateAbilityState(token1, AbilityState::ABILITY_STATE_CONNECTED);
1061 
1062     abilityRecord1->SetState(AbilityState::ABILITY_STATE_DISCONNECTED);
1063     appMgrServiceInner->UpdateAbilityState(token1, AbilityState::ABILITY_STATE_DISCONNECTED);
1064 
1065     abilityRecord1->SetState(AbilityState::ABILITY_STATE_END);
1066     appMgrServiceInner->UpdateAbilityState(token1, AbilityState::ABILITY_STATE_END);
1067 
1068     abilityRecord1->SetState(AbilityState::ABILITY_STATE_BACKGROUND);
1069     appMgrServiceInner->UpdateAbilityState(token1, AbilityState::ABILITY_STATE_BACKGROUND);
1070 
1071     OHOS::sptr<IRemoteObject> token2 = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
1072     abilityInfo_->type = AbilityType::SERVICE;
1073     std::shared_ptr<AppRunningRecord> appRecord2 = appMgrServiceInner->CreateAppRunningRecord(token2, nullptr,
1074         applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want);
1075     EXPECT_NE(appRecord2, nullptr);
1076     appMgrServiceInner->UpdateAbilityState(token2, AbilityState::ABILITY_STATE_CREATE);
1077 
1078     auto abilityRecord2 =
1079         appMgrServiceInner->GetAppRunningRecordByAbilityToken(token2)->GetAbilityRunningRecordByToken(token2);
1080     abilityRecord2->SetState(AbilityState::ABILITY_STATE_TERMINATED);
1081     appMgrServiceInner->UpdateAbilityState(token2, AbilityState::ABILITY_STATE_TERMINATED);
1082 
1083     abilityRecord2->SetState(AbilityState::ABILITY_STATE_CONNECTED);
1084     appMgrServiceInner->UpdateAbilityState(token2, AbilityState::ABILITY_STATE_CONNECTED);
1085 
1086     abilityRecord2->SetState(AbilityState::ABILITY_STATE_DISCONNECTED);
1087     appMgrServiceInner->UpdateAbilityState(token2, AbilityState::ABILITY_STATE_DISCONNECTED);
1088 
1089     abilityRecord2->SetState(AbilityState::ABILITY_STATE_END);
1090     appMgrServiceInner->UpdateAbilityState(token2, AbilityState::ABILITY_STATE_END);
1091 
1092     abilityRecord2->SetState(AbilityState::ABILITY_STATE_BACKGROUND);
1093     appMgrServiceInner->UpdateAbilityState(token2, AbilityState::ABILITY_STATE_BACKGROUND);
1094 
1095     HILOG_INFO("UpdateAbilityState_001 end");
1096 }
1097 
1098 /**
1099  * @tc.name: UpdateExtensionState_001
1100  * @tc.desc: update extension state.
1101  * @tc.type: FUNC
1102  * @tc.require: issueI5W4S7
1103  */
1104 HWTEST_F(AppMgrServiceInnerTest, UpdateExtensionState_001, TestSize.Level0)
1105 {
1106     HILOG_INFO("UpdateExtensionState_001 start");
1107     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1108     EXPECT_NE(appMgrServiceInner, nullptr);
1109 
1110     appMgrServiceInner->UpdateExtensionState(nullptr, ExtensionState::EXTENSION_STATE_CREATE);
1111 
1112     OHOS::sptr<IRemoteObject> token = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
1113     appMgrServiceInner->UpdateExtensionState(token, ExtensionState::EXTENSION_STATE_CREATE);
1114 
1115     BundleInfo bundleInfo;
1116     HapModuleInfo hapModuleInfo;
1117     std::shared_ptr<AAFwk::Want> want;
1118     std::string processName = "test_processName";
1119     std::shared_ptr<AppRunningRecord> appRecord = appMgrServiceInner->CreateAppRunningRecord(token, nullptr,
1120         applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want);
1121     EXPECT_NE(appRecord, nullptr);
1122     appMgrServiceInner->UpdateExtensionState(token, ExtensionState::EXTENSION_STATE_CREATE);
1123 
1124     HILOG_INFO("UpdateExtensionState_001 end");
1125 }
1126 
1127 /**
1128  * @tc.name: OpenAppSpawnConnection_001
1129  * @tc.desc: open app spawn connection.
1130  * @tc.type: FUNC
1131  * @tc.require: issueI5W4S7
1132  */
1133 HWTEST_F(AppMgrServiceInnerTest, OpenAppSpawnConnection_001, TestSize.Level0)
1134 {
1135     HILOG_INFO("OpenAppSpawnConnection_001 start");
1136     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1137     EXPECT_NE(appMgrServiceInner, nullptr);
1138 
1139     appMgrServiceInner->remoteClientManager_->SetSpawnClient(nullptr);
1140     auto errorCode = appMgrServiceInner->OpenAppSpawnConnection();
1141     EXPECT_EQ(errorCode, ERR_APPEXECFWK_BAD_APPSPAWN_CLIENT);
1142 
1143     appMgrServiceInner->remoteClientManager_ = nullptr;
1144     auto errorCode1 = appMgrServiceInner->OpenAppSpawnConnection();
1145     EXPECT_EQ(errorCode1, ERR_INVALID_VALUE);
1146 
1147     HILOG_INFO("OpenAppSpawnConnection_001 end");
1148 }
1149 
1150 /**
1151  * @tc.name: CloseAppSpawnConnection_001
1152  * @tc.desc: close app spawn connection.
1153  * @tc.type: FUNC
1154  * @tc.require: issueI5W4S7
1155  */
1156 HWTEST_F(AppMgrServiceInnerTest, CloseAppSpawnConnection_001, TestSize.Level0)
1157 {
1158     HILOG_INFO("CloseAppSpawnConnection_001 start");
1159     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1160     EXPECT_NE(appMgrServiceInner, nullptr);
1161 
1162     appMgrServiceInner->CloseAppSpawnConnection();
1163 
1164     appMgrServiceInner->remoteClientManager_ = nullptr;
1165     appMgrServiceInner->CloseAppSpawnConnection();
1166 
1167     HILOG_INFO("CloseAppSpawnConnection_001 end");
1168 }
1169 
1170 /**
1171  * @tc.name: QueryAppSpawnConnectionState_001
1172  * @tc.desc: query app spawn connection.
1173  * @tc.type: FUNC
1174  * @tc.require: issueI5W4S7
1175  */
1176 HWTEST_F(AppMgrServiceInnerTest, QueryAppSpawnConnectionState_001, TestSize.Level0)
1177 {
1178     HILOG_INFO("QueryAppSpawnConnectionState_001 start");
1179     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1180     EXPECT_NE(appMgrServiceInner, nullptr);
1181 
1182     auto connectionState = appMgrServiceInner->QueryAppSpawnConnectionState();
1183     EXPECT_EQ(connectionState, SpawnConnectionState::STATE_NOT_CONNECT);
1184 
1185     appMgrServiceInner->remoteClientManager_->SetSpawnClient(nullptr);
1186     connectionState = appMgrServiceInner->QueryAppSpawnConnectionState();
1187     EXPECT_EQ(connectionState, SpawnConnectionState::STATE_NOT_CONNECT);
1188 
1189 
1190     appMgrServiceInner->remoteClientManager_ = nullptr;
1191     connectionState = appMgrServiceInner->QueryAppSpawnConnectionState();
1192     EXPECT_EQ(connectionState, SpawnConnectionState::STATE_NOT_CONNECT);
1193 
1194     HILOG_INFO("QueryAppSpawnConnectionState_001 end");
1195 }
1196 
1197 /**
1198  * @tc.name: SetAppSpawnClient_001
1199  * @tc.desc: set app spawn client.
1200  * @tc.type: FUNC
1201  * @tc.require: issueI5W4S7
1202  */
1203 HWTEST_F(AppMgrServiceInnerTest, SetAppSpawnClient_001, TestSize.Level0)
1204 {
1205     HILOG_INFO("SetAppSpawnClient_001 start");
1206     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1207     EXPECT_NE(appMgrServiceInner, nullptr);
1208 
1209     std::shared_ptr<AppSpawnClient> spawnClient;
1210     appMgrServiceInner->SetAppSpawnClient(spawnClient);
1211 
1212     appMgrServiceInner->remoteClientManager_ = nullptr;
1213     appMgrServiceInner->SetAppSpawnClient(spawnClient);
1214 
1215     HILOG_INFO("SetAppSpawnClient_001 end");
1216 }
1217 
1218 /**
1219  * @tc.name: SetBundleManager_001
1220  * @tc.desc: set bundle manager.
1221  * @tc.type: FUNC
1222  * @tc.require: issueI5W4S7
1223  */
1224 HWTEST_F(AppMgrServiceInnerTest, SetBundleManager_001, TestSize.Level0)
1225 {
1226     HILOG_INFO("SetBundleManager_001 start");
1227     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1228     EXPECT_NE(appMgrServiceInner, nullptr);
1229 
1230     sptr<IBundleMgr> bundleManager;
1231     appMgrServiceInner->SetBundleManager(bundleManager);
1232 
1233     appMgrServiceInner->remoteClientManager_ = nullptr;
1234     appMgrServiceInner->SetBundleManager(bundleManager);
1235 
1236     HILOG_INFO("SetBundleManager_001 end");
1237 }
1238 
1239 /**
1240  * @tc.name: RegisterAppStateCallback_001
1241  * @tc.desc: register app state call back.
1242  * @tc.type: FUNC
1243  * @tc.require: issueI5W4S7
1244  */
1245 HWTEST_F(AppMgrServiceInnerTest, RegisterAppStateCallback_001, TestSize.Level0)
1246 {
1247     HILOG_INFO("RegisterAppStateCallback_001 start");
1248     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1249     EXPECT_NE(appMgrServiceInner, nullptr);
1250 
1251     appMgrServiceInner->RegisterAppStateCallback(nullptr);
1252 
1253     sptr<IAppStateCallback> callback;
1254     appMgrServiceInner->RegisterAppStateCallback(callback);
1255 
1256     HILOG_INFO("RegisterAppStateCallback_001 end");
1257 }
1258 
1259 /**
1260  * @tc.name: AbilityBehaviorAnalysis_001
1261  * @tc.desc: ability behavior analysis.
1262  * @tc.type: FUNC
1263  * @tc.require: issueI5W4S7
1264  */
1265 HWTEST_F(AppMgrServiceInnerTest, AbilityBehaviorAnalysis_001, TestSize.Level0)
1266 {
1267     HILOG_INFO("AbilityBehaviorAnalysis_001 start");
1268     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1269     EXPECT_NE(appMgrServiceInner, nullptr);
1270 
1271     appMgrServiceInner->AbilityBehaviorAnalysis(nullptr, nullptr, 0, 0, 0);
1272 
1273     OHOS::sptr<IRemoteObject> token = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
1274     appMgrServiceInner->AbilityBehaviorAnalysis(token, nullptr, 0, 0, 0);
1275 
1276     BundleInfo bundleInfo;
1277     HapModuleInfo hapModuleInfo;
1278     std::shared_ptr<AAFwk::Want> want;
1279     std::string processName = "test_processName";
1280     std::shared_ptr<AppRunningRecord> appRecord = appMgrServiceInner->CreateAppRunningRecord(token, nullptr,
1281         applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want);
1282     EXPECT_NE(appRecord, nullptr);
1283     appMgrServiceInner->AbilityBehaviorAnalysis(token, nullptr, 0, 0, 0);
1284 
1285     OHOS::sptr<IRemoteObject> preToken = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
1286     appMgrServiceInner->AbilityBehaviorAnalysis(token, preToken, 0, 0, 0);
1287 
1288     HILOG_INFO("AbilityBehaviorAnalysis_001 end");
1289 }
1290 
1291 /**
1292  * @tc.name: KillProcessByAbilityToken_001
1293  * @tc.desc: kill process by ability token.
1294  * @tc.type: FUNC
1295  * @tc.require: issueI5W4S7
1296  */
1297 HWTEST_F(AppMgrServiceInnerTest, KillProcessByAbilityToken_001, TestSize.Level0)
1298 {
1299     HILOG_INFO("KillProcessByAbilityToken_001 start");
1300     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1301     EXPECT_NE(appMgrServiceInner, nullptr);
1302 
1303     appMgrServiceInner->KillProcessByAbilityToken(nullptr);
1304 
1305     OHOS::sptr<IRemoteObject> token = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
1306     appMgrServiceInner->KillProcessByAbilityToken(token);
1307 
1308     BundleInfo bundleInfo;
1309     HapModuleInfo hapModuleInfo;
1310     std::shared_ptr<AAFwk::Want> want;
1311     std::string processName = "test_processName";
1312     std::shared_ptr<AppRunningRecord> appRecord = appMgrServiceInner->CreateAppRunningRecord(token, nullptr,
1313         applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want);
1314     EXPECT_NE(appRecord, nullptr);
1315     appMgrServiceInner->KillProcessByAbilityToken(token);
1316 
1317     appRecord->SetKeepAliveAppState(true, true);
1318     appMgrServiceInner->KillProcessByAbilityToken(token);
1319 
1320     HILOG_INFO("KillProcessByAbilityToken_001 end");
1321 }
1322 
1323 /**
1324  * @tc.name: KillProcessesByUserId_001
1325  * @tc.desc: kill process by user id.
1326  * @tc.type: FUNC
1327  * @tc.require: issueI5W4S7
1328  */
1329 HWTEST_F(AppMgrServiceInnerTest, KillProcessesByUserId_001, TestSize.Level0)
1330 {
1331     HILOG_INFO("KillProcessesByUserId_001 start");
1332     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1333     EXPECT_NE(appMgrServiceInner, nullptr);
1334 
1335     appMgrServiceInner->KillProcessesByUserId(0);
1336 
1337     appMgrServiceInner->appRunningManager_ = nullptr;
1338     appMgrServiceInner->KillProcessesByUserId(0);
1339 
1340     HILOG_INFO("KillProcessesByUserId_001 end");
1341 }
1342 
1343 /**
1344  * @tc.name: StartAbility_001
1345  * @tc.desc: start ability.
1346  * @tc.type: FUNC
1347  * @tc.require: issueI5W4S7
1348  */
1349 HWTEST_F(AppMgrServiceInnerTest, StartAbility_001, TestSize.Level0)
1350 {
1351     HILOG_INFO("StartAbility_001 start");
1352     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1353     EXPECT_NE(appMgrServiceInner, nullptr);
1354 
1355     HapModuleInfo hapModuleInfo;
1356     std::shared_ptr<AAFwk::Want> want;
1357     std::shared_ptr<AppRunningRecord> appRecord;
1358     appMgrServiceInner->StartAbility(nullptr, nullptr, abilityInfo_, nullptr, hapModuleInfo, nullptr);
1359     appMgrServiceInner->StartAbility(nullptr, nullptr, abilityInfo_, appRecord, hapModuleInfo, nullptr);
1360     appMgrServiceInner->StartAbility(nullptr, nullptr, abilityInfo_, appRecord, hapModuleInfo, want);
1361 
1362     OHOS::sptr<IRemoteObject> token = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
1363     OHOS::sptr<IRemoteObject> preToken = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
1364     appMgrServiceInner->StartAbility(token, nullptr, abilityInfo_, appRecord, hapModuleInfo, want);
1365     appMgrServiceInner->StartAbility(nullptr, preToken, abilityInfo_, appRecord, hapModuleInfo, want);
1366     appMgrServiceInner->StartAbility(token, preToken, abilityInfo_, appRecord, hapModuleInfo, want);
1367 
1368     BundleInfo bundleInfo;
1369     std::string processName = "test_processName";
1370     appRecord = appMgrServiceInner->CreateAppRunningRecord(token, nullptr,
1371         applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want);
1372     EXPECT_NE(appRecord, nullptr);
1373     appMgrServiceInner->StartAbility(token, nullptr, abilityInfo_, appRecord, hapModuleInfo, want);
1374     appMgrServiceInner->StartAbility(token, preToken, abilityInfo_, appRecord, hapModuleInfo, want);
1375 
1376     abilityInfo_->applicationInfo.name = "hiservcie";
1377     abilityInfo_->applicationInfo.bundleName = "com.ix.hiservcie";
1378     appMgrServiceInner->StartAbility(token, preToken, abilityInfo_, appRecord, hapModuleInfo, want);
1379 
1380     HILOG_INFO("StartAbility_001 end");
1381 }
1382 
1383 /**
1384  * @tc.name: GetAppRunningRecordByAbilityToken_001
1385  * @tc.desc: get app running record by ability token.
1386  * @tc.type: FUNC
1387  * @tc.require: issueI5W4S7
1388  */
1389 HWTEST_F(AppMgrServiceInnerTest, GetAppRunningRecordByAbilityToken_001, TestSize.Level0)
1390 {
1391     HILOG_INFO("GetAppRunningRecordByAbilityToken_001 start");
1392     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1393     EXPECT_NE(appMgrServiceInner, nullptr);
1394 
1395     OHOS::sptr<IRemoteObject> token = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
1396     appMgrServiceInner->GetAppRunningRecordByAbilityToken(token);
1397 
1398     appMgrServiceInner->appRunningManager_ = nullptr;
1399     appMgrServiceInner->GetAppRunningRecordByAbilityToken(token);
1400 
1401     HILOG_INFO("GetAppRunningRecordByAbilityToken_001 end");
1402 }
1403 
1404 /**
1405  * @tc.name: AbilityTerminated_001
1406  * @tc.desc: ability terminated.
1407  * @tc.type: FUNC
1408  * @tc.require: issueI5W4S7
1409  */
1410 HWTEST_F(AppMgrServiceInnerTest, AbilityTerminated_001, TestSize.Level0)
1411 {
1412     HILOG_INFO("AbilityTerminated_001 start");
1413     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1414     EXPECT_NE(appMgrServiceInner, nullptr);
1415 
1416     appMgrServiceInner->AbilityTerminated(nullptr);
1417 
1418     OHOS::sptr<IRemoteObject> token = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
1419     appMgrServiceInner->AbilityTerminated(token);
1420 
1421     BundleInfo bundleInfo;
1422     HapModuleInfo hapModuleInfo;
1423     std::shared_ptr<AAFwk::Want> want;
1424     std::string processName = "test_processName";
1425     std::shared_ptr<AppRunningRecord> appRecord = appMgrServiceInner->CreateAppRunningRecord(token, nullptr,
1426         applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want);
1427     EXPECT_NE(appRecord, nullptr);
1428     appMgrServiceInner->AbilityTerminated(token);
1429 
1430     HILOG_INFO("AbilityTerminated_001 end");
1431 }
1432 
1433 /**
1434  * @tc.name: GetAppRunningRecordByAppRecordId_001
1435  * @tc.desc: get app running record by app record id.
1436  * @tc.type: FUNC
1437  * @tc.require: issueI5W4S7
1438  */
1439 HWTEST_F(AppMgrServiceInnerTest, GetAppRunningRecordByAppRecordId_001, TestSize.Level0)
1440 {
1441     HILOG_INFO("GetAppRunningRecordByAppRecordId_001 start");
1442     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1443     EXPECT_NE(appMgrServiceInner, nullptr);
1444 
1445     appMgrServiceInner->GetAppRunningRecordByAppRecordId(0);
1446 
1447     appMgrServiceInner->appRunningManager_ = nullptr;
1448     appMgrServiceInner->GetAppRunningRecordByAppRecordId(0);
1449 
1450     HILOG_INFO("GetAppRunningRecordByAppRecordId_001 end");
1451 }
1452 
1453 /**
1454  * @tc.name: OnAppStateChanged_001
1455  * @tc.desc: on app state changed.
1456  * @tc.type: FUNC
1457  * @tc.require: issueI5W4S7
1458  */
1459 HWTEST_F(AppMgrServiceInnerTest, OnAppStateChanged_001, TestSize.Level0)
1460 {
1461     HILOG_INFO("OnAppStateChanged_001 start");
1462     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1463     EXPECT_NE(appMgrServiceInner, nullptr);
1464 
1465     appMgrServiceInner->OnAppStateChanged(nullptr, ApplicationState::APP_STATE_CREATE, true);
1466     appMgrServiceInner->OnAppStateChanged(nullptr, ApplicationState::APP_STATE_CREATE, false);
1467 
1468     BundleInfo bundleInfo;
1469     std::string processName = "test_processName";
1470     std::shared_ptr<AppRunningRecord> appRecord =
1471         appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo);
1472     EXPECT_NE(appRecord, nullptr);
1473     appMgrServiceInner->OnAppStateChanged(appRecord, ApplicationState::APP_STATE_CREATE, true);
1474 
1475     sptr<MockAppStateCallback> mockCallback(new MockAppStateCallback());
1476     EXPECT_CALL(*mockCallback, OnAppStateChanged(_)).Times(2);
1477     sptr<IAppStateCallback> callback1 = iface_cast<IAppStateCallback>(mockCallback);
1478     appMgrServiceInner->appStateCallbacks_.push_back(callback1);
1479     appMgrServiceInner->OnAppStateChanged(appRecord, ApplicationState::APP_STATE_CREATE, true);
1480 
1481     sptr<IAppStateCallback> callback;
1482     appMgrServiceInner->appStateCallbacks_.push_back(callback);
1483     appMgrServiceInner->OnAppStateChanged(appRecord, ApplicationState::APP_STATE_CREATE, true);
1484 
1485     HILOG_INFO("OnAppStateChanged_001 end");
1486 }
1487 
1488 /**
1489  * @tc.name: OnAbilityStateChanged_001
1490  * @tc.desc: on ability state changed.
1491  * @tc.type: FUNC
1492  * @tc.require: issueI5W4S7
1493  */
1494 HWTEST_F(AppMgrServiceInnerTest, OnAbilityStateChanged_001, TestSize.Level0)
1495 {
1496     HILOG_INFO("OnAbilityStateChanged_001 start");
1497     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1498     EXPECT_NE(appMgrServiceInner, nullptr);
1499 
1500     appMgrServiceInner->OnAbilityStateChanged(nullptr, AbilityState::ABILITY_STATE_CREATE);
1501 
1502     sptr<IRemoteObject> token = new MockAbilityToken();
1503     std::shared_ptr<AbilityRunningRecord> abilityRunningRecord =
1504         std::make_shared<AbilityRunningRecord>(abilityInfo_, token);
1505     appMgrServiceInner->OnAbilityStateChanged(abilityRunningRecord, AbilityState::ABILITY_STATE_CREATE);
1506 
1507     sptr<MockAppStateCallback> mockCallback(new MockAppStateCallback());
1508     EXPECT_CALL(*mockCallback, OnAbilityRequestDone(_, _)).Times(2);
1509     sptr<IAppStateCallback> callback1 = iface_cast<IAppStateCallback>(mockCallback);
1510     appMgrServiceInner->appStateCallbacks_.push_back(callback1);
1511     appMgrServiceInner->OnAbilityStateChanged(abilityRunningRecord, AbilityState::ABILITY_STATE_CREATE);
1512 
1513     sptr<IAppStateCallback> callback;
1514     appMgrServiceInner->appStateCallbacks_.push_back(callback);
1515     appMgrServiceInner->OnAbilityStateChanged(abilityRunningRecord, AbilityState::ABILITY_STATE_CREATE);
1516 
1517     HILOG_INFO("OnAbilityStateChanged_001 end");
1518 }
1519 
1520 /**
1521  * @tc.name: StartProcess_001
1522  * @tc.desc: start process.
1523  * @tc.type: FUNC
1524  * @tc.require: issueI5W4S7
1525  */
1526 HWTEST_F(AppMgrServiceInnerTest, StartProcess_001, TestSize.Level0)
1527 {
1528     HILOG_INFO("StartProcess_001 start");
1529     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1530     EXPECT_NE(appMgrServiceInner, nullptr);
1531 
1532     BundleInfo bundleInfo;
1533     std::string appName = "test_appName";
1534     std::string processName = "test_processName";
1535     std::string bundleName = "test_bundleName";
1536     sptr<IRemoteObject> token = new MockAbilityToken();
1537     std::shared_ptr<AppRunningRecord> appRecord =
1538         appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo);
1539     EXPECT_NE(appRecord, nullptr);
1540     appMgrServiceInner->StartProcess(appName, processName, 0, nullptr, 0, bundleName, 0);
1541     appMgrServiceInner->StartProcess(appName, processName, 0, appRecord, 0, bundleName, 0);
1542     appMgrServiceInner->StartProcess(appName, processName, 0, appRecord, 0, bundleName, 1);
1543 
1544     appMgrServiceInner->SetBundleManager(nullptr);
1545     appMgrServiceInner->StartProcess(appName, processName, 0, appRecord, 0, bundleName, 0);
1546 
1547     appMgrServiceInner->SetAppSpawnClient(nullptr);
1548     appMgrServiceInner->StartProcess(appName, processName, 0, nullptr, 0, bundleName, 0);
1549     appMgrServiceInner->StartProcess(appName, processName, 0, appRecord, 0, bundleName, 0);
1550 
1551     HILOG_INFO("StartProcess_001 end");
1552 }
1553 
1554 /**
1555  * @tc.name: RemoveAppFromRecentList_001
1556  * @tc.desc: remove app from recent list.
1557  * @tc.type: FUNC
1558  * @tc.require: issueI5W4S7
1559  */
1560 HWTEST_F(AppMgrServiceInnerTest, RemoveAppFromRecentList_001, TestSize.Level0)
1561 {
1562     HILOG_INFO("RemoveAppFromRecentList_001 start");
1563     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1564     EXPECT_NE(appMgrServiceInner, nullptr);
1565 
1566     std::string appName = "test_appName";
1567     std::string processName = "test_processName";
1568     appMgrServiceInner->RemoveAppFromRecentList(appName, processName);
1569 
1570     appMgrServiceInner->AddAppToRecentList(appName, processName, 0, 0);
1571     appMgrServiceInner->RemoveAppFromRecentList(appName, processName);
1572 
1573     appMgrServiceInner->ClearRecentAppList();
1574     BundleInfo bundleInfo;
1575     std::string appName1 = "hiservcie";
1576     std::string processName1 = "hiservcie_processName";
1577     std::shared_ptr<AppRunningRecord> appRecord =
1578         appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName1, bundleInfo);
1579     HILOG_INFO("RemoveAppFromRecentList_001 start 22");
1580 
1581     pid_t pid = 123;
1582     std::string renderParam = "test_renderParam";
1583     std::shared_ptr<RenderRecord> renderRecord = RenderRecord::CreateRenderRecord(pid, renderParam, 1, 1, appRecord);
1584     appRecord->SetRenderRecord(renderRecord);
1585     appMgrServiceInner->AddAppToRecentList(appName1, processName1, pid, 0);
1586     appRecord->SetKeepAliveAppState(true, true);
1587     appMgrServiceInner->RemoveAppFromRecentList(appName1, processName1);
1588     appRecord->SetKeepAliveAppState(false, false);
1589     appMgrServiceInner->RemoveAppFromRecentList(appName1, processName1);
1590 
1591     HILOG_INFO("RemoveAppFromRecentList_001 end");
1592 }
1593 
1594 /**
1595  * @tc.name: ClearRecentAppList_001
1596  * @tc.desc: clear recent list.
1597  * @tc.type: FUNC
1598  * @tc.require: issueI5W4S7
1599  */
1600 HWTEST_F(AppMgrServiceInnerTest, ClearRecentAppList_001, TestSize.Level0)
1601 {
1602     HILOG_INFO("ClearRecentAppList_001 start");
1603     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1604     EXPECT_NE(appMgrServiceInner, nullptr);
1605 
1606     appMgrServiceInner->ClearRecentAppList();
1607     std::list<const std::shared_ptr<AppTaskInfo>> list = appMgrServiceInner->GetRecentAppList();
1608     EXPECT_EQ(list.size(), 0);
1609 
1610     HILOG_INFO("ClearRecentAppList_001 end");
1611 }
1612 
1613 /**
1614  * @tc.name: OnRemoteDied_001
1615  * @tc.desc: on remote died.
1616  * @tc.type: FUNC
1617  * @tc.require: issueI5W4S7
1618  */
1619 HWTEST_F(AppMgrServiceInnerTest, OnRemoteDied_001, TestSize.Level0)
1620 {
1621     HILOG_INFO("OnRemoteDied_001 start");
1622     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1623     EXPECT_NE(appMgrServiceInner, nullptr);
1624 
1625     sptr<IRemoteObject> remoteObject;
1626     appMgrServiceInner->OnRemoteDied(remoteObject, true);
1627     appMgrServiceInner->OnRemoteDied(remoteObject, false);
1628 
1629     HILOG_INFO("OnRemoteDied_001 end");
1630 }
1631 
1632 /**
1633  * @tc.name: ClearAppRunningData_001
1634  * @tc.desc: clear app running data.
1635  * @tc.type: FUNC
1636  * @tc.require: issueI5W4S7
1637  */
1638 HWTEST_F(AppMgrServiceInnerTest, ClearAppRunningData_001, TestSize.Level0)
1639 {
1640     HILOG_INFO("ClearAppRunningData_001 start");
1641     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1642     EXPECT_NE(appMgrServiceInner, nullptr);
1643 
1644     appMgrServiceInner->ClearAppRunningData(nullptr, true);
1645 
1646     BundleInfo info;
1647     std::string processName = "test_processName";
1648     std::shared_ptr<AppRunningRecord> appRecord =
1649         appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info);
1650     appMgrServiceInner->ClearAppRunningData(appRecord, true);
1651     appMgrServiceInner->ClearAppRunningData(appRecord, false);
1652 
1653     std::shared_ptr<RenderRecord> renderRecord;
1654     appRecord->SetRenderRecord(renderRecord);
1655     appMgrServiceInner->ClearAppRunningData(appRecord, false);
1656 
1657     pid_t pid = 123;
1658     std::string renderParam = "test_renderParam";
1659     std::shared_ptr<RenderRecord> renderRecord1 = RenderRecord::CreateRenderRecord(pid, renderParam, 1, 1, appRecord);
1660     appRecord->SetRenderRecord(renderRecord1);
1661     appMgrServiceInner->ClearAppRunningData(appRecord, false);
1662 
1663     appRecord->SetKeepAliveAppState(true, true);
1664     appMgrServiceInner->ClearAppRunningData(appRecord, false);
1665 
1666     appMgrServiceInner->eventHandler_ = nullptr;
1667     appMgrServiceInner->ClearAppRunningData(appRecord, false);
1668 
1669     appRecord->restartResidentProcCount_ = 0;
1670     appMgrServiceInner->ClearAppRunningData(appRecord, false);
1671 
1672     appRecord->appInfo_ = nullptr;
1673     appMgrServiceInner->ClearAppRunningData(appRecord, false);
1674 
1675     HILOG_INFO("ClearAppRunningData_001 end");
1676 }
1677 
1678 /**
1679  * @tc.name: AddAppDeathRecipient_001
1680  * @tc.desc: add app death recipient.
1681  * @tc.type: FUNC
1682  * @tc.require: issueI5W4S7
1683  */
1684 HWTEST_F(AppMgrServiceInnerTest, AddAppDeathRecipient_001, TestSize.Level0)
1685 {
1686     HILOG_INFO("AddAppDeathRecipient_001 start");
1687     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1688     EXPECT_NE(appMgrServiceInner, nullptr);
1689 
1690     BundleInfo bundleInfo;
1691     std::string appName = "test_appName";
1692     std::string processName = "test_processName";
1693     std::string bundleName = "test_bundleName";
1694     sptr<IRemoteObject> token = new MockAbilityToken();
1695     std::shared_ptr<AppRunningRecord> appRecord =
1696         appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo);
1697     EXPECT_NE(appRecord, nullptr);
1698     sptr<AppDeathRecipient> appDeathRecipient;
1699     pid_t pid = 999;
1700     appMgrServiceInner->AddAppDeathRecipient(pid, appDeathRecipient);
1701 
1702     pid_t pid1 = 123;
1703     appMgrServiceInner->AddAppDeathRecipient(pid1, appDeathRecipient);
1704 
1705     HILOG_INFO("AddAppDeathRecipient_001 end");
1706 }
1707 
1708 /**
1709  * @tc.name: HandleTimeOut_001
1710  * @tc.desc: handle time out.
1711  * @tc.type: FUNC
1712  * @tc.require: issueI5W4S7
1713  */
1714 HWTEST_F(AppMgrServiceInnerTest, HandleTimeOut_001, TestSize.Level0)
1715 {
1716     HILOG_INFO("HandleTimeOut_001 start");
1717     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1718     EXPECT_NE(appMgrServiceInner, nullptr);
1719 
1720     InnerEvent::Pointer innerEvent = InnerEvent::Pointer(nullptr, nullptr);
1721     appMgrServiceInner->HandleTimeOut(innerEvent);
1722 
1723     appMgrServiceInner->appRunningManager_ = nullptr;
1724     appMgrServiceInner->HandleTimeOut(innerEvent);
1725 
1726     HILOG_INFO("HandleTimeOut_001 end");
1727 }
1728 
1729 /**
1730  * @tc.name: HandleAbilityAttachTimeOut_001
1731  * @tc.desc: handle ability attach time out.
1732  * @tc.type: FUNC
1733  * @tc.require: issueI5W4S7
1734  */
1735 HWTEST_F(AppMgrServiceInnerTest, HandleAbilityAttachTimeOut_001, TestSize.Level0)
1736 {
1737     HILOG_INFO("HandleAbilityAttachTimeOut_001 start");
1738     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1739     EXPECT_NE(appMgrServiceInner, nullptr);
1740 
1741     appMgrServiceInner->HandleAbilityAttachTimeOut(nullptr);
1742 
1743     appMgrServiceInner->appRunningManager_ = nullptr;
1744     appMgrServiceInner->HandleAbilityAttachTimeOut(nullptr);
1745 
1746     HILOG_INFO("HandleAbilityAttachTimeOut_001 end");
1747 }
1748 
1749 /**
1750  * @tc.name: PrepareTerminate_001
1751  * @tc.desc: prepare terminate.
1752  * @tc.type: FUNC
1753  * @tc.require: issueI5W4S7
1754  */
1755 HWTEST_F(AppMgrServiceInnerTest, PrepareTerminate_001, TestSize.Level0)
1756 {
1757     HILOG_INFO("PrepareTerminate_001 start");
1758     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1759     EXPECT_NE(appMgrServiceInner, nullptr);
1760 
1761     appMgrServiceInner->PrepareTerminate(nullptr);
1762 
1763     appMgrServiceInner->appRunningManager_ = nullptr;
1764     appMgrServiceInner->PrepareTerminate(nullptr);
1765 
1766     HILOG_INFO("PrepareTerminate_001 end");
1767 }
1768 
1769 /**
1770  * @tc.name: HandleTerminateApplicationTimeOut_001
1771  * @tc.desc: handle terminate application time out.
1772  * @tc.type: FUNC
1773  * @tc.require: issueI5W4S7
1774  */
1775 HWTEST_F(AppMgrServiceInnerTest, HandleTerminateApplicationTimeOut_001, TestSize.Level0)
1776 {
1777     HILOG_INFO("HandleTerminateApplicationTimeOut_001 start");
1778     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1779     EXPECT_NE(appMgrServiceInner, nullptr);
1780 
1781     appMgrServiceInner->HandleTerminateApplicationTimeOut(0);
1782 
1783     BundleInfo bundleInfo;
1784     std::string appName = "test_appName";
1785     std::string processName = "test_processName";
1786     std::string bundleName = "test_bundleName";
1787     sptr<IRemoteObject> token = new MockAbilityToken();
1788     std::shared_ptr<AppRunningRecord> appRecord =
1789         appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo);
1790     EXPECT_NE(appRecord, nullptr);
1791     appRecord->eventId_ = 0;
1792     appMgrServiceInner->HandleTerminateApplicationTimeOut(0);
1793 
1794     pid_t pid = 1;
1795     appRecord->GetPriorityObject()->SetPid(pid);
1796     appMgrServiceInner->HandleTerminateApplicationTimeOut(0);
1797 
1798     appMgrServiceInner->eventHandler_ = nullptr;
1799     appMgrServiceInner->HandleTerminateApplicationTimeOut(0);
1800 
1801     appMgrServiceInner->appRunningManager_ = nullptr;
1802     appMgrServiceInner->HandleTerminateApplicationTimeOut(0);
1803 
1804     HILOG_INFO("HandleTerminateApplicationTimeOut_001 end");
1805 }
1806 
1807 /**
1808  * @tc.name: HandleAddAbilityStageTimeOut_001
1809  * @tc.desc: handle add ability stage time out.
1810  * @tc.type: FUNC
1811  * @tc.require: issueI5W4S7
1812  */
1813 HWTEST_F(AppMgrServiceInnerTest, HandleAddAbilityStageTimeOut_001, TestSize.Level0)
1814 {
1815     HILOG_INFO("HandleAddAbilityStageTimeOut_001 start");
1816     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1817     EXPECT_NE(appMgrServiceInner, nullptr);
1818 
1819     appMgrServiceInner->HandleAddAbilityStageTimeOut(0);
1820 
1821     BundleInfo bundleInfo;
1822     std::string appName = "test_appName";
1823     std::string processName = "test_processName";
1824     std::string bundleName = "test_bundleName";
1825     sptr<IRemoteObject> token = new MockAbilityToken();
1826     std::shared_ptr<AppRunningRecord> appRecord =
1827         appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo);
1828     EXPECT_NE(appRecord, nullptr);
1829     appRecord->eventId_ = 0;
1830     appMgrServiceInner->HandleAddAbilityStageTimeOut(0);
1831 
1832     appRecord->isSpecifiedAbility_ = true;
1833     appMgrServiceInner->HandleAddAbilityStageTimeOut(0);
1834 
1835     sptr<IStartSpecifiedAbilityResponse> response;
1836     appMgrServiceInner->startSpecifiedAbilityResponse_ = response;
1837     appMgrServiceInner->HandleAddAbilityStageTimeOut(0);
1838 
1839     appMgrServiceInner->appRunningManager_ = nullptr;
1840     appMgrServiceInner->HandleAddAbilityStageTimeOut(0);
1841 
1842     HILOG_INFO("HandleAddAbilityStageTimeOut_001 end");
1843 }
1844 
1845 /**
1846  * @tc.name: GetRunningProcessInfoByToken_001
1847  * @tc.desc: get running process info by token.
1848  * @tc.type: FUNC
1849  * @tc.require: issueI5W4S7
1850  */
1851 HWTEST_F(AppMgrServiceInnerTest, GetRunningProcessInfoByToken_001, TestSize.Level0)
1852 {
1853     HILOG_INFO("GetRunningProcessInfoByToken_001 start");
1854     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1855     EXPECT_NE(appMgrServiceInner, nullptr);
1856 
1857     AppExecFwk::RunningProcessInfo info;
1858     appMgrServiceInner->GetRunningProcessInfoByToken(nullptr, info);
1859 
1860     appMgrServiceInner->appRunningManager_ = nullptr;
1861     appMgrServiceInner->GetRunningProcessInfoByToken(nullptr, info);
1862 
1863     HILOG_INFO("GetRunningProcessInfoByToken_001 end");
1864 }
1865 
1866 /**
1867  * @tc.name: GetRunningProcessInfoByPid_001
1868  * @tc.desc: get running process info by pid.
1869  * @tc.type: FUNC
1870  * @tc.require: issueI5W4S7
1871  */
1872 HWTEST_F(AppMgrServiceInnerTest, GetRunningProcessInfoByPid_001, TestSize.Level0)
1873 {
1874     HILOG_INFO("GetRunningProcessInfoByPid_001 start");
1875     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1876     EXPECT_NE(appMgrServiceInner, nullptr);
1877 
1878     AppExecFwk::RunningProcessInfo info;
1879     appMgrServiceInner->GetRunningProcessInfoByPid(0, info);
1880 
1881     appMgrServiceInner->appRunningManager_ = nullptr;
1882     appMgrServiceInner->GetRunningProcessInfoByPid(0, info);
1883 
1884     HILOG_INFO("GetRunningProcessInfoByPid_001 end");
1885 }
1886 
1887 /**
1888  * @tc.name: CheckGetRunningInfoPermission_001
1889  * @tc.desc: check get running info permission.
1890  * @tc.type: FUNC
1891  * @tc.require: issueI5W4S7
1892  */
1893 HWTEST_F(AppMgrServiceInnerTest, CheckGetRunningInfoPermission_001, TestSize.Level0)
1894 {
1895     HILOG_INFO("CheckGetRunningInfoPermission_001 start");
1896     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1897     EXPECT_NE(appMgrServiceInner, nullptr);
1898 
1899     appMgrServiceInner->CheckGetRunningInfoPermission();
1900 
1901     appMgrServiceInner->appRunningManager_ = nullptr;
1902     appMgrServiceInner->CheckGetRunningInfoPermission();
1903 
1904     HILOG_INFO("CheckGetRunningInfoPermission_001 end");
1905 }
1906 
1907 /**
1908  * @tc.name: LoadResidentProcess_001
1909  * @tc.desc: load resident process.
1910  * @tc.type: FUNC
1911  * @tc.require: issueI5W4S7
1912  */
1913 HWTEST_F(AppMgrServiceInnerTest, LoadResidentProcess_001, TestSize.Level0)
1914 {
1915     HILOG_INFO("LoadResidentProcess_001 start");
1916     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1917     EXPECT_NE(appMgrServiceInner, nullptr);
1918 
1919     std::vector<BundleInfo> infos;
1920     appMgrServiceInner->LoadResidentProcess(infos);
1921 
1922     HILOG_INFO("LoadResidentProcess_001 end");
1923 }
1924 
1925 /**
1926  * @tc.name: StartResidentProcess_001
1927  * @tc.desc: start resident process.
1928  * @tc.type: FUNC
1929  * @tc.require: issueI5W4S7
1930  */
1931 HWTEST_F(AppMgrServiceInnerTest, StartResidentProcess_001, TestSize.Level0)
1932 {
1933     HILOG_INFO("StartResidentProcess_001 start");
1934     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1935     EXPECT_NE(appMgrServiceInner, nullptr);
1936 
1937     std::vector<BundleInfo> infos;
1938     appMgrServiceInner->StartResidentProcess(infos, 0, true);
1939 
1940     BundleInfo info;
1941     infos.push_back(info);
1942 
1943     BundleInfo info1;
1944     info1.applicationInfo.process = "";
1945     infos.push_back(info1);
1946 
1947     BundleInfo info2;
1948     info2.applicationInfo.process = "test_process";
1949     infos.push_back(info2);
1950     appMgrServiceInner->StartResidentProcess(infos, 0, true);
1951 
1952     appMgrServiceInner->appRunningManager_ = nullptr;
1953     appMgrServiceInner->StartResidentProcess(infos, 0, true);
1954 
1955     HILOG_INFO("StartResidentProcess_001 end");
1956 }
1957 
1958 /**
1959  * @tc.name: StartEmptyResidentProcess_001
1960  * @tc.desc: start empty resident process.
1961  * @tc.type: FUNC
1962  * @tc.require: issueI5W4S7
1963  */
1964 HWTEST_F(AppMgrServiceInnerTest, StartEmptyResidentProcess_001, TestSize.Level0)
1965 {
1966     HILOG_INFO("StartEmptyResidentProcess_001 start");
1967     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1968     EXPECT_NE(appMgrServiceInner, nullptr);
1969 
1970     BundleInfo info;
1971     info.applicationInfo = *applicationInfo_;
1972     std::string processName = "test_process";
1973     appMgrServiceInner->StartEmptyResidentProcess(info, processName, 0, true);
1974 
1975     appMgrServiceInner->StartEmptyResidentProcess(info, processName, 1, true);
1976 
1977     appMgrServiceInner->StartEmptyResidentProcess(info, "", 0, true);
1978 
1979     appMgrServiceInner->appRunningManager_ = nullptr;
1980     appMgrServiceInner->StartEmptyResidentProcess(info, processName, 0, true);
1981 
1982     appMgrServiceInner->remoteClientManager_ = nullptr;
1983     appMgrServiceInner->StartEmptyResidentProcess(info, processName, 0, true);
1984 
1985     HILOG_INFO("StartEmptyResidentProcess_001 end");
1986 }
1987 
1988 /**
1989  * @tc.name: CheckRemoteClient_001
1990  * @tc.desc: check remote client.
1991  * @tc.type: FUNC
1992  * @tc.require: issueI5W4S7
1993  */
1994 HWTEST_F(AppMgrServiceInnerTest, CheckRemoteClient_001, TestSize.Level0)
1995 {
1996     HILOG_INFO("CheckRemoteClient_001 start");
1997     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1998     EXPECT_NE(appMgrServiceInner, nullptr);
1999 
2000     appMgrServiceInner->CheckRemoteClient();
2001 
2002     appMgrServiceInner->remoteClientManager_->SetSpawnClient(nullptr);
2003     appMgrServiceInner->CheckRemoteClient();
2004 
2005     appMgrServiceInner->remoteClientManager_->SetBundleManager(nullptr);
2006     appMgrServiceInner->CheckRemoteClient();
2007 
2008     appMgrServiceInner->remoteClientManager_ = nullptr;
2009     appMgrServiceInner->CheckRemoteClient();
2010 
2011     HILOG_INFO("CheckRemoteClient_001 end");
2012 }
2013 
2014 /**
2015  * @tc.name: RestartResidentProcess_001
2016  * @tc.desc: restart resident process.
2017  * @tc.type: FUNC
2018  * @tc.require: issueI5W4S7
2019  */
2020 HWTEST_F(AppMgrServiceInnerTest, RestartResidentProcess_001, TestSize.Level0)
2021 {
2022     HILOG_INFO("RestartResidentProcess_001 start");
2023     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2024     EXPECT_NE(appMgrServiceInner, nullptr);
2025 
2026     appMgrServiceInner->RestartResidentProcess(nullptr);
2027 
2028     std::shared_ptr<AppRunningRecord> appRecord;
2029     appMgrServiceInner->RestartResidentProcess(appRecord);
2030 
2031     BundleInfo bundleInfo;
2032     std::string processName = "test_processName";
2033     appRecord =
2034         appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo);
2035     EXPECT_NE(appRecord, nullptr);
2036     appRecord->mainBundleName_ = "com.ohos.settings";
2037     appMgrServiceInner->RestartResidentProcess(appRecord);
2038 
2039     appMgrServiceInner->appRunningManager_ = nullptr;
2040     appMgrServiceInner->RestartResidentProcess(appRecord);
2041 
2042     appMgrServiceInner->remoteClientManager_ = nullptr;
2043     appMgrServiceInner->RestartResidentProcess(appRecord);
2044 
2045     HILOG_INFO("RestartResidentProcess_001 end");
2046 }
2047 
2048 /**
2049  * @tc.name: NotifyAppStatusByCallerUid_001
2050  * @tc.desc: notify app status by caller uid.
2051  * @tc.type: FUNC
2052  * @tc.require: issueI5W4S7
2053  */
2054 HWTEST_F(AppMgrServiceInnerTest, NotifyAppStatusByCallerUid_001, TestSize.Level0)
2055 {
2056     HILOG_INFO("NotifyAppStatusByCallerUid_001 start");
2057     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2058     EXPECT_NE(appMgrServiceInner, nullptr);
2059 
2060     std::string bundleName = "test_bundle_name";
2061     std::string eventData = "test_event_data";
2062     appMgrServiceInner->NotifyAppStatusByCallerUid(bundleName, 0, 0, eventData);
2063 
2064     HILOG_INFO("NotifyAppStatusByCallerUid_001 end");
2065 }
2066 
2067 /**
2068  * @tc.name: RegisterApplicationStateObserver_001
2069  * @tc.desc: register application state observer.
2070  * @tc.type: FUNC
2071  * @tc.require: issueI5W4S7
2072  */
2073 HWTEST_F(AppMgrServiceInnerTest, RegisterApplicationStateObserver_001, TestSize.Level0)
2074 {
2075     HILOG_INFO("RegisterApplicationStateObserver_001 start");
2076     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2077     EXPECT_NE(appMgrServiceInner, nullptr);
2078 
2079     sptr<IApplicationStateObserver> observer;
2080     std::vector<std::string> bundleNameList;
2081     appMgrServiceInner->RegisterApplicationStateObserver(observer, bundleNameList);
2082 
2083     HILOG_INFO("RegisterApplicationStateObserver_001 end");
2084 }
2085 
2086 /**
2087  * @tc.name: UnregisterApplicationStateObserver_001
2088  * @tc.desc: unregister application state observer.
2089  * @tc.type: FUNC
2090  * @tc.require: issueI5W4S7
2091  */
2092 HWTEST_F(AppMgrServiceInnerTest, UnregisterApplicationStateObserver_001, TestSize.Level0)
2093 {
2094     HILOG_INFO("UnregisterApplicationStateObserver_001 start");
2095     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2096     EXPECT_NE(appMgrServiceInner, nullptr);
2097 
2098     sptr<IApplicationStateObserver> observer;
2099     appMgrServiceInner->UnregisterApplicationStateObserver(observer);
2100 
2101     HILOG_INFO("UnregisterApplicationStateObserver_001 end");
2102 }
2103 
2104 /**
2105  * @tc.name: GetForegroundApplications_001
2106  * @tc.desc: get foreground applications.
2107  * @tc.type: FUNC
2108  * @tc.require: issueI5W4S7
2109  */
2110 HWTEST_F(AppMgrServiceInnerTest, GetForegroundApplications_001, TestSize.Level0)
2111 {
2112     HILOG_INFO("GetForegroundApplications_001 start");
2113     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2114     EXPECT_NE(appMgrServiceInner, nullptr);
2115 
2116     std::vector<AppStateData> list;
2117     appMgrServiceInner->GetForegroundApplications(list);
2118 
2119     HILOG_INFO("GetForegroundApplications_001 end");
2120 }
2121 
2122 /**
2123  * @tc.name: StartUserTestProcess_001
2124  * @tc.desc: start user test process.
2125  * @tc.type: FUNC
2126  * @tc.require: issueI5W4S7
2127  */
2128 HWTEST_F(AppMgrServiceInnerTest, StartUserTestProcess_001, TestSize.Level0)
2129 {
2130     HILOG_INFO("StartUserTestProcess_001 start");
2131     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2132     EXPECT_NE(appMgrServiceInner, nullptr);
2133 
2134     AAFwk::Want want;
2135     sptr<IRemoteObject> observer;
2136     BundleInfo bundleInfo;
2137     appMgrServiceInner->StartUserTestProcess(want, nullptr, bundleInfo, 0);
2138 
2139     appMgrServiceInner->StartUserTestProcess(want, observer, bundleInfo, 0);
2140 
2141     std::string bundle_name = "test_bundle_name";
2142     want.SetParam("-b", bundle_name);
2143     appMgrServiceInner->StartUserTestProcess(want, observer, bundleInfo, 0);
2144 
2145     std::string moduleName = "test_module_name";
2146     want.SetParam("-m", moduleName);
2147     HapModuleInfo hapModuleInfo;
2148     hapModuleInfo.moduleName = moduleName;
2149     bundleInfo.hapModuleInfos.push_back(hapModuleInfo);
2150     appMgrServiceInner->StartUserTestProcess(want, observer, bundleInfo, 0);
2151 
2152     appMgrServiceInner->remoteClientManager_ = nullptr;
2153     appMgrServiceInner->StartUserTestProcess(want, observer, bundleInfo, 0);
2154 
2155     appMgrServiceInner->appRunningManager_ = nullptr;
2156     appMgrServiceInner->StartUserTestProcess(want, observer, bundleInfo, 0);
2157 
2158     HILOG_INFO("StartUserTestProcess_001 end");
2159 }
2160 
2161 /**
2162  * @tc.name: GetHapModuleInfoForTestRunner_001
2163  * @tc.desc: get hap module info for test runner.
2164  * @tc.type: FUNC
2165  * @tc.require: issueI5W4S7
2166  */
2167 HWTEST_F(AppMgrServiceInnerTest, GetHapModuleInfoForTestRunner_001, TestSize.Level0)
2168 {
2169     HILOG_INFO("GetHapModuleInfoForTestRunner_001 start");
2170     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2171     EXPECT_NE(appMgrServiceInner, nullptr);
2172 
2173     AAFwk::Want want;
2174     sptr<IRemoteObject> observer;
2175     BundleInfo bundleInfo;
2176     HapModuleInfo hapModuleInfo;
2177     appMgrServiceInner->GetHapModuleInfoForTestRunner(want, nullptr, bundleInfo, hapModuleInfo);
2178 
2179     appMgrServiceInner->GetHapModuleInfoForTestRunner(want, observer, bundleInfo, hapModuleInfo);
2180 
2181     hapModuleInfo.moduleName = "test_module_name";
2182     bundleInfo.hapModuleInfos.push_back(hapModuleInfo);
2183     appMgrServiceInner->GetHapModuleInfoForTestRunner(want, observer, bundleInfo, hapModuleInfo);
2184 
2185     bundleInfo.hapModuleInfos.back().isModuleJson = true;
2186     appMgrServiceInner->GetHapModuleInfoForTestRunner(want, observer, bundleInfo, hapModuleInfo);
2187 
2188     std::string testmoduleName = "test_XXX";
2189     want.SetParam("-m", testmoduleName);
2190     appMgrServiceInner->GetHapModuleInfoForTestRunner(want, observer, bundleInfo, hapModuleInfo);
2191 
2192     std::string moduleName = "test_module_name";
2193     want.SetParam("-m", moduleName);
2194     appMgrServiceInner->GetHapModuleInfoForTestRunner(want, observer, bundleInfo, hapModuleInfo);
2195 
2196     HILOG_INFO("GetHapModuleInfoForTestRunner_001 end");
2197 }
2198 
2199 /**
2200  * @tc.name: UserTestAbnormalFinish_001
2201  * @tc.desc: user test abnormal finish.
2202  * @tc.type: FUNC
2203  * @tc.require: issueI5W4S7
2204  */
2205 HWTEST_F(AppMgrServiceInnerTest, UserTestAbnormalFinish_001, TestSize.Level0)
2206 {
2207     HILOG_INFO("UserTestAbnormalFinish_001 start");
2208     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2209     EXPECT_NE(appMgrServiceInner, nullptr);
2210 
2211     sptr<IRemoteObject> observer;
2212     std::string msg = "testmsg";
2213     appMgrServiceInner->UserTestAbnormalFinish(nullptr, "");
2214     appMgrServiceInner->UserTestAbnormalFinish(nullptr, msg);
2215     appMgrServiceInner->UserTestAbnormalFinish(observer, "");
2216     appMgrServiceInner->UserTestAbnormalFinish(observer, msg);
2217 
2218     HILOG_INFO("UserTestAbnormalFinish_001 end");
2219 }
2220 
2221 /**
2222  * @tc.name: StartEmptyProcess_001
2223  * @tc.desc: start empty process.
2224  * @tc.type: FUNC
2225  * @tc.require: issueI5W4S7
2226  */
2227 HWTEST_F(AppMgrServiceInnerTest, StartEmptyProcess_001, TestSize.Level0)
2228 {
2229     HILOG_INFO("StartEmptyProcess_001 start");
2230     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2231     EXPECT_NE(appMgrServiceInner, nullptr);
2232 
2233     AAFwk::Want want;
2234     sptr<IRemoteObject> observer;
2235     BundleInfo info;
2236     HapModuleInfo hapModuleInfo;
2237     std::string processName = "test_processName";
2238     appMgrServiceInner->StartEmptyProcess(want, nullptr, info, "", 0);
2239     appMgrServiceInner->StartEmptyProcess(want, observer, info, "", 0);
2240     appMgrServiceInner->StartEmptyProcess(want, observer, info, processName, 0);
2241 
2242     info.applicationInfo = *applicationInfo_;
2243     appMgrServiceInner->StartEmptyProcess(want, observer, info, processName, 0);
2244 
2245     want.SetParam("coldStart", true);
2246     appMgrServiceInner->StartEmptyProcess(want, observer, info, processName, 0);
2247 
2248     appMgrServiceInner->remoteClientManager_ = nullptr;
2249     appMgrServiceInner->StartEmptyProcess(want, observer, info, processName, 0);
2250 
2251     appMgrServiceInner->appRunningManager_ = nullptr;
2252     appMgrServiceInner->StartEmptyProcess(want, observer, info, processName, 0);
2253 
2254     HILOG_INFO("StartEmptyProcess_001 end");
2255 }
2256 
2257 /**
2258  * @tc.name: FinishUserTest_001
2259  * @tc.desc: finish user test.
2260  * @tc.type: FUNC
2261  * @tc.require: issueI5W4S7
2262  */
2263 HWTEST_F(AppMgrServiceInnerTest, FinishUserTest_001, TestSize.Level0)
2264 {
2265     HILOG_INFO("FinishUserTest_001 start");
2266     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2267     EXPECT_NE(appMgrServiceInner, nullptr);
2268 
2269     pid_t pid = 0;
2270     appMgrServiceInner->FinishUserTest("", 0, "", pid);
2271 
2272     std::string msg = "testmsg";
2273     std::string bundleName = "test_bundle_name";
2274     appMgrServiceInner->FinishUserTest("", 0, bundleName, pid);
2275     appMgrServiceInner->FinishUserTest(msg, 0, "", pid);
2276     appMgrServiceInner->FinishUserTest(msg, 0, bundleName, pid);
2277 
2278     BundleInfo bundleInfo;
2279     HapModuleInfo hapModuleInfo;
2280     std::shared_ptr<AAFwk::Want> want;
2281     sptr<IRemoteObject> token = new MockAbilityToken();
2282     std::string processName = "test_processName";
2283     std::shared_ptr<AppRunningRecord> appRecord = appMgrServiceInner->CreateAppRunningRecord(token, nullptr,
2284         applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want);
2285     EXPECT_NE(appRecord, nullptr);
2286     pid = appRecord->GetPriorityObject()->GetPid();
2287     appMgrServiceInner->FinishUserTest(msg, 0, bundleName, pid);
2288 
2289     std::shared_ptr<UserTestRecord> record = std::make_shared<UserTestRecord>();
2290     appRecord->SetUserTestInfo(record);
2291     appMgrServiceInner->FinishUserTest(msg, 0, bundleName, pid);
2292 
2293     appMgrServiceInner->appRunningManager_ = nullptr;
2294     appMgrServiceInner->FinishUserTest(msg, 0, bundleName, pid);
2295 
2296     HILOG_INFO("FinishUserTest_001 end");
2297 }
2298 
2299 /**
2300  * @tc.name: FinishUserTestLocked_001
2301  * @tc.desc: finish user test locked.
2302  * @tc.type: FUNC
2303  * @tc.require: issueI5W4S7
2304  */
2305 HWTEST_F(AppMgrServiceInnerTest, FinishUserTestLocked_001, TestSize.Level0)
2306 {
2307     HILOG_INFO("FinishUserTestLocked_001 start");
2308     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2309     EXPECT_NE(appMgrServiceInner, nullptr);
2310 
2311     appMgrServiceInner->FinishUserTestLocked("", 0, nullptr);
2312 
2313     std::shared_ptr<AppRunningRecord> appRecord;
2314     appMgrServiceInner->FinishUserTestLocked("", 0, appRecord);
2315 
2316     std::string msg = "testmsg";
2317     appMgrServiceInner->FinishUserTestLocked(msg, 0, nullptr);
2318     appMgrServiceInner->FinishUserTestLocked(msg, 0, appRecord);
2319 
2320     BundleInfo bundleInfo;
2321     std::string processName = "test_processName";
2322     appRecord =
2323         appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo);
2324     EXPECT_NE(appRecord, nullptr);
2325     std::shared_ptr<UserTestRecord> record = std::make_shared<UserTestRecord>();
2326     appRecord->SetUserTestInfo(record);
2327     appMgrServiceInner->FinishUserTestLocked(msg, 0, appRecord);
2328 
2329     record->isFinished = true;
2330     appRecord->SetUserTestInfo(record);
2331     appMgrServiceInner->FinishUserTestLocked(msg, 0, appRecord);
2332 
2333     record->observer = nullptr;
2334     appRecord->SetUserTestInfo(record);
2335     appMgrServiceInner->FinishUserTestLocked(msg, 0, appRecord);
2336 
2337     HILOG_INFO("FinishUserTestLocked_001 end");
2338 }
2339 
2340 /**
2341  * @tc.name: StartSpecifiedAbility_001
2342  * @tc.desc: start specified ability.
2343  * @tc.type: FUNC
2344  * @tc.require: issueI5W4S7
2345  */
2346 HWTEST_F(AppMgrServiceInnerTest, StartSpecifiedAbility_001, TestSize.Level0)
2347 {
2348     HILOG_INFO("StartSpecifiedAbility_001 start");
2349     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2350     EXPECT_NE(appMgrServiceInner, nullptr);
2351 
2352     AAFwk::Want want;
2353     AbilityInfo abilityInfo;
2354     appMgrServiceInner->StartSpecifiedAbility(want, abilityInfo);
2355 
2356     appMgrServiceInner->StartSpecifiedAbility(want, *abilityInfo_);
2357 
2358     abilityInfo_->applicationInfo = *applicationInfo_;
2359     appMgrServiceInner->StartSpecifiedAbility(want, *abilityInfo_);
2360 
2361     appMgrServiceInner->remoteClientManager_->SetBundleManager(nullptr);
2362     appMgrServiceInner->StartSpecifiedAbility(want, *abilityInfo_);
2363 
2364     appMgrServiceInner->remoteClientManager_ = nullptr;
2365     appMgrServiceInner->StartSpecifiedAbility(want, *abilityInfo_);
2366 
2367     HILOG_INFO("StartSpecifiedAbility_001 end");
2368 }
2369 
2370 /**
2371  * @tc.name: RegisterStartSpecifiedAbilityResponse_001
2372  * @tc.desc: register start specified ability response.
2373  * @tc.type: FUNC
2374  * @tc.require: issueI5W4S7
2375  */
2376 HWTEST_F(AppMgrServiceInnerTest, RegisterStartSpecifiedAbilityResponse_001, TestSize.Level0)
2377 {
2378     HILOG_INFO("RegisterStartSpecifiedAbilityResponse_001 start");
2379     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2380     EXPECT_NE(appMgrServiceInner, nullptr);
2381 
2382     appMgrServiceInner->RegisterStartSpecifiedAbilityResponse(nullptr);
2383 
2384     sptr<IStartSpecifiedAbilityResponse> response;
2385     appMgrServiceInner->RegisterStartSpecifiedAbilityResponse(response);
2386 
2387     HILOG_INFO("RegisterStartSpecifiedAbilityResponse_001 end");
2388 }
2389 
2390 /**
2391  * @tc.name: ScheduleAcceptWantDone_001
2392  * @tc.desc: schedule accept want done.
2393  * @tc.type: FUNC
2394  * @tc.require: issueI5W4S7
2395  */
2396 HWTEST_F(AppMgrServiceInnerTest, ScheduleAcceptWantDone_001, TestSize.Level0)
2397 {
2398     HILOG_INFO("ScheduleAcceptWantDone_001 start");
2399     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2400     EXPECT_NE(appMgrServiceInner, nullptr);
2401 
2402     AAFwk::Want want;
2403     std::string flag = "test_flag";
2404     appMgrServiceInner->ScheduleAcceptWantDone(0, want, flag);
2405 
2406     BundleInfo bundleInfo;
2407     std::string processName = "test_processName";
2408     std::shared_ptr<AppRunningRecord> appRecord =
2409         appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo);
2410     appMgrServiceInner->ScheduleAcceptWantDone(appRecord->GetRecordId(), want, flag);
2411 
2412     sptr<IStartSpecifiedAbilityResponse> response;
2413     appMgrServiceInner->RegisterStartSpecifiedAbilityResponse(response);
2414     appMgrServiceInner->ScheduleAcceptWantDone(appRecord->GetRecordId(), want, flag);
2415 
2416     HILOG_INFO("ScheduleAcceptWantDone_001 end");
2417 }
2418 
2419 /**
2420  * @tc.name: HandleStartSpecifiedAbilityTimeOut_001
2421  * @tc.desc: handle start specified ability time out.
2422  * @tc.type: FUNC
2423  * @tc.require: issueI5W4S7
2424  */
2425 HWTEST_F(AppMgrServiceInnerTest, HandleStartSpecifiedAbilityTimeOut_001, TestSize.Level0)
2426 {
2427     HILOG_INFO("HandleStartSpecifiedAbilityTimeOut_001 start");
2428     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2429     EXPECT_NE(appMgrServiceInner, nullptr);
2430 
2431     appMgrServiceInner->HandleStartSpecifiedAbilityTimeOut(0);
2432 
2433     BundleInfo bundleInfo;
2434     std::string appName = "test_appName";
2435     std::string processName = "test_processName";
2436     std::string bundleName = "test_bundleName";
2437     sptr<IRemoteObject> token = new MockAbilityToken();
2438     std::shared_ptr<AppRunningRecord> appRecord =
2439         appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo);
2440     EXPECT_NE(appRecord, nullptr);
2441     appRecord->eventId_ = 0;
2442     appMgrServiceInner->HandleStartSpecifiedAbilityTimeOut(0);
2443 
2444     appRecord->isSpecifiedAbility_ = true;
2445     appMgrServiceInner->HandleStartSpecifiedAbilityTimeOut(0);
2446 
2447     sptr<IStartSpecifiedAbilityResponse> response;
2448     appMgrServiceInner->startSpecifiedAbilityResponse_ = response;
2449     appMgrServiceInner->HandleStartSpecifiedAbilityTimeOut(0);
2450 
2451     appRecord->isSpecifiedAbility_ = false;
2452     appMgrServiceInner->HandleStartSpecifiedAbilityTimeOut(0);
2453 
2454     appMgrServiceInner->appRunningManager_ = nullptr;
2455     appMgrServiceInner->HandleStartSpecifiedAbilityTimeOut(0);
2456 
2457     HILOG_INFO("HandleStartSpecifiedAbilityTimeOut_001 end");
2458 }
2459 
2460 /**
2461  * @tc.name: UpdateConfiguration_001
2462  * @tc.desc: update configuration.
2463  * @tc.type: FUNC
2464  * @tc.require: issueI5W4S7
2465  */
2466 HWTEST_F(AppMgrServiceInnerTest, UpdateConfiguration_001, TestSize.Level0)
2467 {
2468     HILOG_INFO("UpdateConfiguration_001 start");
2469     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2470     EXPECT_NE(appMgrServiceInner, nullptr);
2471 
2472     Configuration config;
2473     appMgrServiceInner->UpdateConfiguration(config);
2474 
2475     auto testLanguge = "ch-zh";
2476     config.AddItem(AAFwk::GlobalConfigurationKey::SYSTEM_LANGUAGE, testLanguge);
2477     appMgrServiceInner->UpdateConfiguration(config);
2478 
2479     auto appRunningRecordMap = appMgrServiceInner->appRunningManager_->appRunningRecordMap_;
2480     for (const auto &item : appRunningRecordMap) {
2481         const auto &appRecord = item.second;
2482         if (appRecord) {
2483             appRecord->appLifeCycleDeal_ = nullptr;
2484         }
2485     }
2486     appMgrServiceInner->UpdateConfiguration(config);
2487 
2488     sptr<MockConfigurationObserver> observer(new (std::nothrow) MockConfigurationObserver());
2489     appMgrServiceInner->configurationObservers_.push_back(observer);
2490     sptr<IConfigurationObserver> observer1;
2491     appMgrServiceInner->configurationObservers_.push_back(observer1);
2492     appMgrServiceInner->configurationObservers_.push_back(nullptr);
2493     appMgrServiceInner->UpdateConfiguration(config);
2494 
2495     appMgrServiceInner->appRunningManager_ = nullptr;
2496     appMgrServiceInner->UpdateConfiguration(config);
2497 
2498     HILOG_INFO("UpdateConfiguration_001 end");
2499 }
2500 
2501 /**
2502  * @tc.name: RegisterConfigurationObserver_001
2503  * @tc.desc: register configuration observer.
2504  * @tc.type: FUNC
2505  * @tc.require: issueI5W4S7
2506  */
2507 HWTEST_F(AppMgrServiceInnerTest, RegisterConfigurationObserver_001, TestSize.Level0)
2508 {
2509     HILOG_INFO("RegisterConfigurationObserver_001 start");
2510     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2511     EXPECT_NE(appMgrServiceInner, nullptr);
2512 
2513     appMgrServiceInner->configurationObservers_.clear();
2514 
2515     appMgrServiceInner->RegisterConfigurationObserver(nullptr);
2516 
2517     sptr<MockConfigurationObserver> observer(new (std::nothrow) MockConfigurationObserver());
2518     appMgrServiceInner->RegisterConfigurationObserver(observer);
2519     appMgrServiceInner->RegisterConfigurationObserver(observer);
2520 
2521     HILOG_INFO("RegisterConfigurationObserver_001 end");
2522 }
2523 
2524 /**
2525  * @tc.name: UnregisterConfigurationObserver_001
2526  * @tc.desc: unregister configuration observer.
2527  * @tc.type: FUNC
2528  * @tc.require: issueI5W4S7
2529  */
2530 HWTEST_F(AppMgrServiceInnerTest, UnregisterConfigurationObserver_001, TestSize.Level0)
2531 {
2532     HILOG_INFO("UnregisterConfigurationObserver_001 start");
2533     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2534     EXPECT_NE(appMgrServiceInner, nullptr);
2535 
2536     appMgrServiceInner->configurationObservers_.clear();
2537 
2538     appMgrServiceInner->UnregisterConfigurationObserver(nullptr);
2539 
2540     sptr<MockConfigurationObserver> observer(new (std::nothrow) MockConfigurationObserver());
2541     appMgrServiceInner->UnregisterConfigurationObserver(observer);
2542 
2543     appMgrServiceInner->RegisterConfigurationObserver(observer);
2544     appMgrServiceInner->UnregisterConfigurationObserver(observer);
2545 
2546     HILOG_INFO("UnregisterConfigurationObserver_001 end");
2547 }
2548 
2549 /**
2550  * @tc.name: InitGlobalConfiguration_001
2551  * @tc.desc: init global configuration.
2552  * @tc.type: FUNC
2553  * @tc.require: issueI5W4S7
2554  */
2555 HWTEST_F(AppMgrServiceInnerTest, InitGlobalConfiguration_001, TestSize.Level0)
2556 {
2557     HILOG_INFO("InitGlobalConfiguration_001 start");
2558     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2559     EXPECT_NE(appMgrServiceInner, nullptr);
2560 
2561     appMgrServiceInner->InitGlobalConfiguration();
2562 
2563     appMgrServiceInner->configuration_ = nullptr;
2564     appMgrServiceInner->InitGlobalConfiguration();
2565 
2566     HILOG_INFO("InitGlobalConfiguration_001 end");
2567 }
2568 
2569 /**
2570  * @tc.name: KillApplicationByRecord_001
2571  * @tc.desc: kill application by record.
2572  * @tc.type: FUNC
2573  * @tc.require: issueI5W4S7
2574  */
2575 HWTEST_F(AppMgrServiceInnerTest, KillApplicationByRecord_001, TestSize.Level0)
2576 {
2577     HILOG_INFO("KillApplicationByRecord_001 start");
2578     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2579     EXPECT_NE(appMgrServiceInner, nullptr);
2580 
2581     std::shared_ptr<AppRunningRecord> appRecord = nullptr;
2582     BundleInfo bundleInfo;
2583     std::string processName = "test_processName";
2584     std::shared_ptr<AppRunningRecord> appRecord1 =
2585         appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo);
2586     EXPECT_NE(appRecord1, nullptr);
2587     appMgrServiceInner->KillApplicationByRecord(appRecord);
2588     appMgrServiceInner->KillApplicationByRecord(appRecord1);
2589 
2590     appMgrServiceInner->eventHandler_ = nullptr;
2591     appMgrServiceInner->KillApplicationByRecord(appRecord);
2592     appMgrServiceInner->KillApplicationByRecord(appRecord1);
2593 
2594     HILOG_INFO("KillApplicationByRecord_001 end");
2595 }
2596 
2597 /**
2598  * @tc.name: SendHiSysEvent_001
2599  * @tc.desc: send hi sys event.
2600  * @tc.type: FUNC
2601  * @tc.require: issueI5W4S7
2602  */
2603 HWTEST_F(AppMgrServiceInnerTest, SendHiSysEvent_001, TestSize.Level0)
2604 {
2605     HILOG_INFO("SendHiSysEvent_001 start");
2606     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2607     EXPECT_NE(appMgrServiceInner, nullptr);
2608 
2609     appMgrServiceInner->SendHiSysEvent(0, 0);
2610 
2611     BundleInfo bundleInfo;
2612     std::string processName = "test_processName";
2613     std::shared_ptr<AppRunningRecord> appRecord =
2614         appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo);
2615     EXPECT_NE(appRecord, nullptr);
2616     appRecord->eventId_ = 0;
2617     appMgrServiceInner->SendHiSysEvent(0, 0);
2618     appMgrServiceInner->SendHiSysEvent(1, 0);
2619     appMgrServiceInner->SendHiSysEvent(2, 0);
2620     appMgrServiceInner->SendHiSysEvent(3, 0);
2621     appMgrServiceInner->SendHiSysEvent(4, 0);
2622 
2623     appMgrServiceInner->appRunningManager_ = nullptr;
2624     appMgrServiceInner->SendHiSysEvent(0, 0);
2625 
2626     HILOG_INFO("SendHiSysEvent_001 end");
2627 }
2628 
2629 /**
2630  * @tc.name: GetAbilityRecordsByProcessID_001
2631  * @tc.desc: get ability records by process id.
2632  * @tc.type: FUNC
2633  * @tc.require: issueI5W4S7
2634  */
2635 HWTEST_F(AppMgrServiceInnerTest, GetAbilityRecordsByProcessID_001, TestSize.Level0)
2636 {
2637     HILOG_INFO("GetAbilityRecordsByProcessID_001 start");
2638     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2639     EXPECT_NE(appMgrServiceInner, nullptr);
2640 
2641     std::vector<sptr<IRemoteObject>> tokens;
2642     appMgrServiceInner->GetAbilityRecordsByProcessID(0, tokens);
2643 
2644     BundleInfo bundleInfo;
2645     std::string processName = "test_processName";
2646     std::shared_ptr<AppRunningRecord> appRecord =
2647         appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo);
2648     EXPECT_NE(appRecord, nullptr);
2649     int pid = appRecord->GetPriorityObject()->GetPid();
2650     appMgrServiceInner->GetAbilityRecordsByProcessID(pid, tokens);
2651 
2652     HILOG_INFO("GetAbilityRecordsByProcessID_001 end");
2653 }
2654 
2655 /**
2656  * @tc.name: GetApplicationInfoByProcessID_001
2657  * @tc.desc: get applicationInfo by process id.
2658  * @tc.type: FUNC
2659  * @tc.require: issueI5W4S7
2660  */
2661 HWTEST_F(AppMgrServiceInnerTest, GetApplicationInfoByProcessID_001, TestSize.Level0)
2662 {
2663     HILOG_INFO("GetApplicationInfoByProcessID_001 start");
2664     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2665     EXPECT_NE(appMgrServiceInner, nullptr);
2666 
2667     ApplicationInfo application;
2668     bool debug = false;
2669     appMgrServiceInner->GetApplicationInfoByProcessID(0, application, debug);
2670 
2671     BundleInfo bundleInfo;
2672     std::string processName = "test_processName";
2673     std::shared_ptr<AppRunningRecord> appRecord =
2674         appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo);
2675     EXPECT_NE(appRecord, nullptr);
2676     int pid = appRecord->GetPriorityObject()->GetPid();
2677     appMgrServiceInner->GetApplicationInfoByProcessID(pid, application, debug);
2678 
2679     appRecord->appInfo_ = nullptr;
2680     appMgrServiceInner->GetApplicationInfoByProcessID(pid, application, debug);
2681 
2682     HILOG_INFO("GetApplicationInfoByProcessID_001 end");
2683 }
2684 
2685 /**
2686  * @tc.name: VerifyProcessPermission_001
2687  * @tc.desc: verify process permission.
2688  * @tc.type: FUNC
2689  * @tc.require: issueI5W4S7
2690  */
2691 HWTEST_F(AppMgrServiceInnerTest, VerifyProcessPermission_001, TestSize.Level0)
2692 {
2693     HILOG_INFO("VerifyProcessPermission_001 start");
2694     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2695     EXPECT_NE(appMgrServiceInner, nullptr);
2696 
2697     appMgrServiceInner->VerifyProcessPermission("");
2698 
2699     appMgrServiceInner->appRunningManager_ = nullptr;
2700     appMgrServiceInner->VerifyProcessPermission("");
2701 
2702     HILOG_INFO("VerifyProcessPermission_001 end");
2703 }
2704 
2705 /**
2706  * @tc.name: VerifyAPL_001
2707  * @tc.desc: verify APL.
2708  * @tc.type: FUNC
2709  * @tc.require: issueI5W4S7
2710  */
2711 HWTEST_F(AppMgrServiceInnerTest, VerifyAPL_001, TestSize.Level0)
2712 {
2713     HILOG_INFO("VerifyAPL_001 start");
2714     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2715     EXPECT_NE(appMgrServiceInner, nullptr);
2716 
2717     appMgrServiceInner->VerifyAPL();
2718 
2719     appMgrServiceInner->appRunningManager_ = nullptr;
2720     appMgrServiceInner->VerifyAPL();
2721 
2722     HILOG_INFO("VerifyAPL_001 end");
2723 }
2724 
2725 /**
2726  * @tc.name: VerifyAccountPermission_001
2727  * @tc.desc: verify account permission.
2728  * @tc.type: FUNC
2729  * @tc.require: issueI5W4S7
2730  */
2731 HWTEST_F(AppMgrServiceInnerTest, VerifyAccountPermission_001, TestSize.Level0)
2732 {
2733     HILOG_INFO("VerifyAccountPermission_001 start");
2734     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2735     EXPECT_NE(appMgrServiceInner, nullptr);
2736 
2737     std::string permissionName = "test_permissionName";
2738     appMgrServiceInner->VerifyAccountPermission(permissionName, 0);
2739 
2740     HILOG_INFO("VerifyAccountPermission_001 end");
2741 }
2742 
2743 /**
2744  * @tc.name: PreStartNWebSpawnProcess_003
2745  * @tc.desc: prestart nwebspawn process.
2746  * @tc.type: FUNC
2747  * @tc.require: issueI5W4S7
2748  */
2749 HWTEST_F(AppMgrServiceInnerTest, PreStartNWebSpawnProcess_003, TestSize.Level0)
2750 {
2751     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2752     EXPECT_NE(appMgrServiceInner, nullptr);
2753 
2754     int callingPid = 1;
2755     appMgrServiceInner->remoteClientManager_->nwebSpawnClient_ = nullptr;
2756     int ret = appMgrServiceInner->PreStartNWebSpawnProcess(callingPid);
2757     EXPECT_EQ(ret, ERR_INVALID_VALUE);
2758 }
2759 
2760 /**
2761  * @tc.name: StartRenderProcess_001
2762  * @tc.desc: start render process.
2763  * @tc.type: FUNC
2764  * @tc.require: issueI5W4S7
2765  */
2766 HWTEST_F(AppMgrServiceInnerTest, StartRenderProcess_001, TestSize.Level0)
2767 {
2768     HILOG_INFO("StartRenderProcess_001 start");
2769     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2770     EXPECT_NE(appMgrServiceInner, nullptr);
2771 
2772     pid_t hostPid = 0;
2773     pid_t hostPid1 = 1;
2774     std::string renderParam = "test_renderParam";
2775     pid_t renderPid = 0;
2776     int ret = appMgrServiceInner->StartRenderProcess(hostPid, "", 0, 0, renderPid);
2777     EXPECT_EQ(ret, ERR_INVALID_VALUE);
2778     ret = appMgrServiceInner->StartRenderProcess(hostPid, "", 0, 1, renderPid);
2779     EXPECT_EQ(ret, ERR_INVALID_VALUE);
2780     ret = appMgrServiceInner->StartRenderProcess(hostPid, "", 1, 0, renderPid);
2781     EXPECT_EQ(ret, ERR_INVALID_VALUE);
2782     ret = appMgrServiceInner->StartRenderProcess(hostPid, "", 1, 1, renderPid);
2783     EXPECT_EQ(ret, ERR_INVALID_VALUE);
2784     ret = appMgrServiceInner->StartRenderProcess(hostPid, renderParam, 0, 0, renderPid);
2785     EXPECT_EQ(ret, ERR_INVALID_VALUE);
2786     ret = appMgrServiceInner->StartRenderProcess(hostPid, renderParam, 0, 1, renderPid);
2787     EXPECT_EQ(ret, ERR_INVALID_VALUE);
2788     ret = appMgrServiceInner->StartRenderProcess(hostPid, renderParam, 1, 0, renderPid);
2789     EXPECT_EQ(ret, ERR_INVALID_VALUE);
2790     ret = appMgrServiceInner->StartRenderProcess(hostPid, renderParam, 1, 1, renderPid);
2791     EXPECT_EQ(ret, ERR_INVALID_VALUE);
2792     ret = appMgrServiceInner->StartRenderProcess(hostPid1, "", 0, 0, renderPid);
2793     EXPECT_EQ(ret, ERR_INVALID_VALUE);
2794     ret = appMgrServiceInner->StartRenderProcess(hostPid1, "", 0, 1, renderPid);
2795     EXPECT_EQ(ret, ERR_INVALID_VALUE);
2796     ret = appMgrServiceInner->StartRenderProcess(hostPid1, "", 1, 0, renderPid);
2797     EXPECT_EQ(ret, ERR_INVALID_VALUE);
2798     ret = appMgrServiceInner->StartRenderProcess(hostPid1, "", 1, 1, renderPid);
2799     EXPECT_EQ(ret, ERR_INVALID_VALUE);
2800     ret = appMgrServiceInner->StartRenderProcess(hostPid1, renderParam, 0, 0, renderPid);
2801     EXPECT_EQ(ret, ERR_INVALID_VALUE);
2802     ret = appMgrServiceInner->StartRenderProcess(hostPid1, renderParam, 0, 1, renderPid);
2803     EXPECT_EQ(ret, ERR_INVALID_VALUE);
2804     ret = appMgrServiceInner->StartRenderProcess(hostPid1, renderParam, 1, 0, renderPid);
2805     EXPECT_EQ(ret, ERR_INVALID_VALUE);
2806 
2807     ret = appMgrServiceInner->StartRenderProcess(hostPid1, renderParam, 1, 1, renderPid);
2808     EXPECT_EQ(ret, ERR_INVALID_VALUE);
2809 
2810     HILOG_INFO("StartRenderProcess_001 end");
2811 }
2812 
2813 /**
2814  * @tc.name: StartRenderProcess_002
2815  * @tc.desc: start render process.
2816  * @tc.type: FUNC
2817  * @tc.require: issueI5W4S7
2818  */
2819 HWTEST_F(AppMgrServiceInnerTest, StartRenderProcess_002, TestSize.Level0)
2820 {
2821     HILOG_INFO("StartRenderProcess_002 start");
2822     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2823     EXPECT_NE(appMgrServiceInner, nullptr);
2824 
2825     pid_t hostPid1 = 1;
2826     std::string renderParam = "test_renderParam";
2827     pid_t renderPid = 0;
2828 
2829     BundleInfo bundleInfo;
2830     std::string processName = "test_processName";
2831     std::shared_ptr<AppRunningRecord> appRecord =
2832         appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo);
2833     EXPECT_NE(appRecord, nullptr);
2834     appRecord->GetPriorityObject()->SetPid(hostPid1);
2835     int ret = appMgrServiceInner->StartRenderProcess(hostPid1, renderParam, 1, 1, renderPid);
2836     EXPECT_EQ(ret, ERR_INVALID_VALUE);
2837 
2838     std::shared_ptr<RenderRecord> renderRecord =
2839         RenderRecord::CreateRenderRecord(hostPid1, renderParam, 1, 1, appRecord);
2840     appRecord->SetRenderRecord(renderRecord);
2841     ret = appMgrServiceInner->StartRenderProcess(hostPid1, renderParam, 1, 1, renderPid);
2842     EXPECT_EQ(ret, 8454244);
2843 
2844     appMgrServiceInner->appRunningManager_ = nullptr;
2845     ret = appMgrServiceInner->StartRenderProcess(hostPid1, renderParam, 1, 1, renderPid);
2846     EXPECT_EQ(ret, ERR_INVALID_VALUE);
2847 
2848     HILOG_INFO("StartRenderProcess_002 end");
2849 }
2850 
2851 /**
2852  * @tc.name: AttachRenderProcess_001
2853  * @tc.desc: attach render process.
2854  * @tc.type: FUNC
2855  * @tc.require: issueI5W4S7
2856  */
2857 HWTEST_F(AppMgrServiceInnerTest, AttachRenderProcess_001, TestSize.Level0)
2858 {
2859     HILOG_INFO("AttachRenderProcess_001 start");
2860     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2861     EXPECT_NE(appMgrServiceInner, nullptr);
2862 
2863     pid_t pid = 0;
2864     sptr<IRenderScheduler> scheduler;
2865     appMgrServiceInner->AttachRenderProcess(pid, scheduler);
2866 
2867     pid = 1;
2868     appMgrServiceInner->AttachRenderProcess(pid, scheduler);
2869 
2870     sptr<MockRenderScheduler> mockRenderScheduler = new (std::nothrow) MockRenderScheduler();
2871     EXPECT_CALL(*mockRenderScheduler, AsObject()).Times(1);
2872     EXPECT_CALL(*mockRenderScheduler, NotifyBrowserFd(1, 1)).Times(1);
2873     appMgrServiceInner->AttachRenderProcess(pid, mockRenderScheduler);
2874 
2875     BundleInfo bundleInfo;
2876     std::string processName = "test_processName";
2877     std::shared_ptr<AppRunningRecord> appRecord =
2878         appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo);
2879     EXPECT_NE(appRecord, nullptr);
2880     appRecord->GetPriorityObject()->SetPid(pid);
2881     std::string renderParam = "test_renderParam";
2882     std::shared_ptr<RenderRecord> renderRecord = RenderRecord::CreateRenderRecord(pid, renderParam, 1, 1, appRecord);
2883     EXPECT_NE(renderRecord, nullptr);
2884     renderRecord->SetPid(pid);
2885     appRecord->SetRenderRecord(renderRecord);
2886     appMgrServiceInner->AttachRenderProcess(pid, mockRenderScheduler);
2887 
2888     appMgrServiceInner->appRunningManager_ = nullptr;
2889     appMgrServiceInner->AttachRenderProcess(pid, mockRenderScheduler);
2890 
2891     HILOG_INFO("AttachRenderProcess_001 end");
2892 }
2893 
2894 /**
2895  * @tc.name: BuildStartFlags_001
2896  * @tc.desc: build start flags.
2897  * @tc.type: FUNC
2898  * @tc.require: issueI5W4S7
2899  */
2900 HWTEST_F(AppMgrServiceInnerTest, BuildStartFlags_001, TestSize.Level0)
2901 {
2902     HILOG_INFO("BuildStartFlags_001 start");
2903     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2904     EXPECT_NE(appMgrServiceInner, nullptr);
2905 
2906     AAFwk::Want want;
2907     AbilityInfo abilityInfo;
2908     appMgrServiceInner->BuildStartFlags(want, abilityInfo);
2909 
2910     want.SetParam("coldStart", true);
2911     want.SetParam("ohos.dlp.params.index", 1);
2912     abilityInfo.extensionAbilityType = ExtensionAbilityType::BACKUP;
2913     appMgrServiceInner->BuildStartFlags(want, abilityInfo);
2914 
2915     HILOG_INFO("BuildStartFlags_001 end");
2916 }
2917 
2918 /**
2919  * @tc.name: RegisterFocusListener_001
2920  * @tc.desc: register focus listener.
2921  * @tc.type: FUNC
2922  * @tc.require: issueI5W4S7
2923  */
2924 HWTEST_F(AppMgrServiceInnerTest, RegisterFocusListener_001, TestSize.Level0)
2925 {
2926     HILOG_INFO("RegisterFocusListener_001 start");
2927     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2928     EXPECT_NE(appMgrServiceInner, nullptr);
2929 
2930     appMgrServiceInner->RegisterFocusListener();
2931 
2932     appMgrServiceInner->focusListener_ = nullptr;
2933     appMgrServiceInner->RegisterFocusListener();
2934 
2935     HILOG_INFO("RegisterFocusListener_001 end");
2936 }
2937 
2938 /**
2939  * @tc.name: HandleFocused_001
2940  * @tc.desc: handle focused.
2941  * @tc.type: FUNC
2942  * @tc.require: issueI5W4S7
2943  */
2944 HWTEST_F(AppMgrServiceInnerTest, HandleFocused_001, TestSize.Level0)
2945 {
2946     HILOG_INFO("HandleFocused_001 start");
2947     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2948     EXPECT_NE(appMgrServiceInner, nullptr);
2949 
2950     sptr<Rosen::FocusChangeInfo> focusChangeInfo;
2951     appMgrServiceInner->HandleFocused(focusChangeInfo);
2952 
2953     pid_t pid = 1;
2954     focusChangeInfo = new Rosen::FocusChangeInfo();
2955     appMgrServiceInner->HandleFocused(focusChangeInfo);
2956 
2957     focusChangeInfo->pid_ = pid;
2958     appMgrServiceInner->HandleFocused(focusChangeInfo);
2959 
2960     BundleInfo bundleInfo;
2961     std::string processName = "test_processName";
2962     std::shared_ptr<AppRunningRecord> appRecord =
2963         appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo);
2964     EXPECT_NE(appRecord, nullptr);
2965     appRecord->GetPriorityObject()->SetPid(pid);
2966     appMgrServiceInner->HandleFocused(focusChangeInfo);
2967 
2968     HILOG_INFO("HandleFocused_001 end");
2969 }
2970 
2971 /**
2972  * @tc.name: HandleUnfocused_001
2973  * @tc.desc: handle unfocused.
2974  * @tc.type: FUNC
2975  * @tc.require: issueI5W4S7
2976  */
2977 HWTEST_F(AppMgrServiceInnerTest, HandleUnfocused_001, TestSize.Level0)
2978 {
2979     HILOG_INFO("HandleUnfocused_001 start");
2980     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2981     EXPECT_NE(appMgrServiceInner, nullptr);
2982 
2983     sptr<Rosen::FocusChangeInfo> focusChangeInfo;
2984     appMgrServiceInner->HandleUnfocused(focusChangeInfo);
2985 
2986     pid_t pid = 1;
2987     focusChangeInfo = new Rosen::FocusChangeInfo();
2988     appMgrServiceInner->HandleUnfocused(focusChangeInfo);
2989 
2990     focusChangeInfo->pid_ = pid;
2991     appMgrServiceInner->HandleUnfocused(focusChangeInfo);
2992 
2993     BundleInfo bundleInfo;
2994     std::string processName = "test_processName";
2995     std::shared_ptr<AppRunningRecord> appRecord =
2996         appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo);
2997     EXPECT_NE(appRecord, nullptr);
2998     appRecord->GetPriorityObject()->SetPid(pid);
2999     appMgrServiceInner->HandleUnfocused(focusChangeInfo);
3000 
3001     HILOG_INFO("HandleUnfocused_001 end");
3002 }
3003 
3004 /**
3005  * @tc.name: GetAppRunningStateByBundleName_001
3006  * @tc.desc: get app running state by bundle name.
3007  * @tc.type: FUNC
3008  * @tc.require: issueI5W4S7
3009  */
3010 HWTEST_F(AppMgrServiceInnerTest, GetAppRunningStateByBundleName_001, TestSize.Level0)
3011 {
3012     HILOG_INFO("GetAppRunningStateByBundleName_001 start");
3013     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
3014     EXPECT_NE(appMgrServiceInner, nullptr);
3015 
3016     std::string bundleName = "test_bundleName";
3017     appMgrServiceInner->GetAppRunningStateByBundleName(bundleName);
3018 
3019     appMgrServiceInner->appRunningManager_ = nullptr;
3020     appMgrServiceInner->GetAppRunningStateByBundleName(bundleName);
3021 
3022     HILOG_INFO("GetAppRunningStateByBundleName_001 end");
3023 }
3024 
3025 /**
3026  * @tc.name: NotifyLoadRepairPatch_001
3027  * @tc.desc: notify load repair patch.
3028  * @tc.type: FUNC
3029  * @tc.require: issueI5W4S7
3030  */
3031 HWTEST_F(AppMgrServiceInnerTest, NotifyLoadRepairPatch_001, TestSize.Level0)
3032 {
3033     HILOG_INFO("NotifyLoadRepairPatch_001 start");
3034     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
3035     EXPECT_NE(appMgrServiceInner, nullptr);
3036 
3037     std::string bundleName = "test_bundleName";
3038     sptr<IQuickFixCallback> callback;
3039     appMgrServiceInner->NotifyLoadRepairPatch(bundleName, callback);
3040 
3041     appMgrServiceInner->appRunningManager_ = nullptr;
3042     appMgrServiceInner->NotifyLoadRepairPatch(bundleName, callback);
3043 
3044     HILOG_INFO("NotifyLoadRepairPatch_001 end");
3045 }
3046 
3047 /**
3048  * @tc.name: NotifyHotReloadPage_001
3049  * @tc.desc: notify hot reload page.
3050  * @tc.type: FUNC
3051  * @tc.require: issueI5W4S7
3052  */
3053 HWTEST_F(AppMgrServiceInnerTest, NotifyHotReloadPage_001, TestSize.Level0)
3054 {
3055     HILOG_INFO("NotifyHotReloadPage_001 start");
3056     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
3057     EXPECT_NE(appMgrServiceInner, nullptr);
3058 
3059     std::string bundleName = "test_bundleName";
3060     sptr<IQuickFixCallback> callback;
3061     appMgrServiceInner->NotifyHotReloadPage(bundleName, callback);
3062 
3063     appMgrServiceInner->appRunningManager_ = nullptr;
3064     appMgrServiceInner->NotifyHotReloadPage(bundleName, callback);
3065 
3066     HILOG_INFO("NotifyHotReloadPage_001 end");
3067 }
3068 
3069 /**
3070  * @tc.name: SetContinuousTaskProcess_001
3071  * @tc.desc: set continuous task process.
3072  * @tc.type: FUNC
3073  * @tc.require: issueI5W4S7
3074  */
3075 #ifdef BGTASKMGR_CONTINUOUS_TASK_ENABLE
3076 HWTEST_F(AppMgrServiceInnerTest, SetContinuousTaskProcess_001, TestSize.Level0)
3077 {
3078     HILOG_INFO("SetContinuousTaskProcess_001 start");
3079     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
3080     EXPECT_NE(appMgrServiceInner, nullptr);
3081 
3082     int32_t ret = appMgrServiceInner->SetContinuousTaskProcess(0, true);
3083     EXPECT_EQ(ret, 0);
3084 
3085     BundleInfo bundleInfo;
3086     std::string processName = "test_processName";
3087     std::shared_ptr<AppRunningRecord> appRecord =
3088         appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo);
3089     EXPECT_NE(appRecord, nullptr);
3090     appRecord->GetPriorityObject()->SetPid(0);
3091     ret = appMgrServiceInner->SetContinuousTaskProcess(0, true);
3092     EXPECT_EQ(ret, 0);
3093 
3094     appMgrServiceInner->appRunningManager_ = nullptr;
3095     ret = appMgrServiceInner->SetContinuousTaskProcess(0, true);
3096     EXPECT_EQ(ret, ERR_INVALID_OPERATION);
3097 
3098     HILOG_INFO("SetContinuousTaskProcess_001 end");
3099 }
3100 #endif
3101 
3102 /**
3103  * @tc.name: NotifyUnLoadRepairPatch_001
3104  * @tc.desc: notify unload repair patch.
3105  * @tc.type: FUNC
3106  * @tc.require: issueI5W4S7
3107  */
3108 HWTEST_F(AppMgrServiceInnerTest, NotifyUnLoadRepairPatch_001, TestSize.Level0)
3109 {
3110     HILOG_INFO("NotifyUnLoadRepairPatch_001 start");
3111     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
3112     EXPECT_NE(appMgrServiceInner, nullptr);
3113 
3114     std::string bundleName = "test_bundleName";
3115     sptr<IQuickFixCallback> callback;
3116     appMgrServiceInner->NotifyUnLoadRepairPatch(bundleName, callback);
3117 
3118     appMgrServiceInner->appRunningManager_ = nullptr;
3119     appMgrServiceInner->NotifyUnLoadRepairPatch(bundleName, callback);
3120 
3121     HILOG_INFO("NotifyUnLoadRepairPatch_001 end");
3122 }
3123 } // namespace AppExecFwk
3124 } // namespace OHOS
3125