1 /*
2  * Copyright (c) 2022-2024 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 "ability_manager_errors.h"
24 #include "app_scheduler.h"
25 #include "appspawn_util.h"
26 #include "event_handler.h"
27 #include "hilog_tag_wrapper.h"
28 #include "ipc_skeleton.h"
29 #include "mock_ability_token.h"
30 #include "mock_app_scheduler.h"
31 #include "mock_bundle_manager.h"
32 #include "mock_configuration_observer.h"
33 #include "mock_iapp_state_callback.h"
34 #include "mock_native_token.h"
35 #include "mock_render_scheduler.h"
36 #include "mock_sa_call.h"
37 #include "mock_task_handler_wrap.h"
38 #include "param.h"
39 #include "parameters.h"
40 #include "render_state_observer_stub.h"
41 #include "window_manager.h"
42 
43 using namespace testing;
44 using namespace testing::ext;
45 
46 namespace OHOS {
47 namespace AppExecFwk {
48 class WindowFocusChangedListener : public OHOS::Rosen::IFocusChangedListener {
49 public:
50     WindowFocusChangedListener(const std::shared_ptr<AppMgrServiceInner>& owner,
51         const std::shared_ptr<AAFwk::TaskHandlerWrap>& handler);
52     virtual ~WindowFocusChangedListener();
53 
54     void OnFocused(const sptr<OHOS::Rosen::FocusChangeInfo> &focusChangeInfo) override;
55     void OnUnfocused(const sptr<OHOS::Rosen::FocusChangeInfo> &focusChangeInfo) override;
56 
57 private:
58     std::weak_ptr<AppMgrServiceInner> owner_;
59     std::shared_ptr<AAFwk::TaskHandlerWrap> taskHandler_;
60 };
61 namespace {
62 constexpr int32_t RECORD_ID = 1;
63 constexpr int32_t APP_DEBUG_INFO_PID = 0;
64 constexpr int32_t APP_DEBUG_INFO_UID = 0;
65 }
66 static int recordId_ = 0;
67 class AppMgrServiceInnerTest : public testing::Test {
68 public:
69     static void SetUpTestCase();
70     static void TearDownTestCase();
71     void SetUp() override;
72     void TearDown() override;
73 
74     void InitAppInfo(const std::string& deviceName, const std::string& abilityName,
75         const std::string& appName, const std::string& bundleName, const std::string& moduleName);
76 
77 public:
78     std::shared_ptr<AbilityInfo> abilityInfo_;
79     std::shared_ptr<ApplicationInfo> applicationInfo_;
80 };
81 
82 class RenderStateObserverMock : public RenderStateObserverStub {
83 public:
84     RenderStateObserverMock() = default;
85     virtual ~RenderStateObserverMock() = default;
OnRenderStateChanged(const RenderStateData & renderStateData)86     void OnRenderStateChanged(const RenderStateData &renderStateData) override
87     {}
88 };
89 
InitAppInfo(const std::string & deviceName,const std::string & abilityName,const std::string & appName,const std::string & bundleName,const std::string & moduleName)90 void AppMgrServiceInnerTest::InitAppInfo(const std::string& deviceName,
91     const std::string& abilityName, const std::string& appName, const std::string& bundleName,
92     const std::string& moduleName)
93 {
94     ApplicationInfo applicationInfo;
95     applicationInfo.name = appName;
96     applicationInfo.bundleName = bundleName;
97     applicationInfo_ = std::make_shared<ApplicationInfo>(applicationInfo);
98 
99     AbilityInfo abilityInfo;
100     abilityInfo.visible = true;
101     abilityInfo.applicationName = appName;
102     abilityInfo.type = AbilityType::EXTENSION;
103     abilityInfo.name = abilityName;
104     abilityInfo.bundleName = bundleName;
105     abilityInfo.moduleName = moduleName;
106     abilityInfo.deviceId = deviceName;
107     abilityInfo_ = std::make_shared<AbilityInfo>(abilityInfo);
108 }
109 
SetUpTestCase(void)110 void AppMgrServiceInnerTest::SetUpTestCase(void)
111 {
112     MockNativeToken::SetNativeToken();
113 }
114 
TearDownTestCase(void)115 void AppMgrServiceInnerTest::TearDownTestCase(void)
116 {}
117 
SetUp()118 void AppMgrServiceInnerTest::SetUp()
119 {
120     // init test app info
121     std::string deviceName = "device";
122     std::string abilityName = "ServiceAbility";
123     std::string appName = "hiservcie";
124     std::string bundleName = "com.ix.hiservcie";
125     std::string moduleName = "entry";
126     InitAppInfo(deviceName, abilityName, appName, bundleName, moduleName);
127 }
128 
TearDown()129 void AppMgrServiceInnerTest::TearDown()
130 {}
131 
132 /**
133  * @tc.name: PointerDeviceCallback_0100
134  * @tc.desc: set parameter, expect config update
135  * @tc.type: FUNC
136  */
137 HWTEST_F(AppMgrServiceInnerTest, PointerDeviceCallback_0100, TestSize.Level1)
138 {
139     TAG_LOGI(AAFwkTag::TEST, "PointerDeviceCallback_0100 start");
140 
141     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
142     EXPECT_NE(appMgrServiceInner, nullptr);
143     std::string key = AAFwk::GlobalConfigurationKey::INPUT_POINTER_DEVICE;
144     auto context = new (std::nothrow) std::weak_ptr<AppMgrServiceInner>(appMgrServiceInner);
145     std::shared_ptr<AppExecFwk::Configuration> config = nullptr;
146     std::string value;
147 
148     // invalid parameter value
149     appMgrServiceInner->PointerDeviceEventCallback(key.c_str(), "false", context);
150     config = appMgrServiceInner->GetConfiguration();
151     EXPECT_NE(config, nullptr);
152 
153     TAG_LOGI(AAFwkTag::TEST, "PointerDeviceCallback_0100 end");
154 }
155 
156 /**
157  * @tc.name: PointerDeviceCallback_0200
158  * @tc.desc: set parameter, expect config update
159  * @tc.type: FUNC
160  */
161 HWTEST_F(AppMgrServiceInnerTest, PointerDeviceCallback_0200, TestSize.Level1)
162 {
163     TAG_LOGI(AAFwkTag::TEST, "PointerDeviceCallback_0200 start");
164 
165     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
166     EXPECT_NE(appMgrServiceInner, nullptr);
167     std::string key = AAFwk::GlobalConfigurationKey::INPUT_POINTER_DEVICE;
168     auto context = new (std::nothrow) std::weak_ptr<AppMgrServiceInner>(appMgrServiceInner);
169     std::shared_ptr<AppExecFwk::Configuration> config = nullptr;
170     std::string value;
171 
172     // invalid parameter value
173     appMgrServiceInner->PointerDeviceEventCallback(key.c_str(), "true", context);
174     config = appMgrServiceInner->GetConfiguration();
175     EXPECT_NE(config, nullptr);
176 
177     TAG_LOGI(AAFwkTag::TEST, "PointerDeviceCallback_0200 end");
178 }
179 
180 /**
181  * @tc.name: PointerDeviceCallback_0300
182  * @tc.desc: set parameter, expect config update
183  * @tc.type: FUNC
184  */
185 HWTEST_F(AppMgrServiceInnerTest, PointerDeviceCallback_0300, TestSize.Level1)
186 {
187     TAG_LOGI(AAFwkTag::TEST, "PointerDeviceCallback_0300 start");
188 
189     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
190     EXPECT_NE(appMgrServiceInner, nullptr);
191     std::string key = AAFwk::GlobalConfigurationKey::INPUT_POINTER_DEVICE;
192     auto context = new (std::nothrow) std::weak_ptr<AppMgrServiceInner>(appMgrServiceInner);
193     std::shared_ptr<AppExecFwk::Configuration> config = nullptr;
194     std::string value;
195 
196     // invalid parameter value
197     appMgrServiceInner->PointerDeviceEventCallback("invalid_key", "false", context);
198     config = appMgrServiceInner->GetConfiguration();
199     EXPECT_NE(config, nullptr);
200 
201     TAG_LOGI(AAFwkTag::TEST, "PointerDeviceCallback_0300 end");
202 }
203 
204 /**
205  * @tc.name: PointerDeviceCallback_0400
206  * @tc.desc: set parameter, expect config update
207  * @tc.type: FUNC
208  */
209 HWTEST_F(AppMgrServiceInnerTest, PointerDeviceCallback_0400, TestSize.Level1)
210 {
211     TAG_LOGI(AAFwkTag::TEST, "PointerDeviceCallback_0400 start");
212 
213     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
214     EXPECT_NE(appMgrServiceInner, nullptr);
215     std::string key = AAFwk::GlobalConfigurationKey::INPUT_POINTER_DEVICE;
216     auto context = new (std::nothrow) std::weak_ptr<AppMgrServiceInner>(appMgrServiceInner);
217     std::shared_ptr<AppExecFwk::Configuration> config = nullptr;
218     std::string value;
219 
220     // invalid parameter value
221     appMgrServiceInner->PointerDeviceEventCallback(key.c_str(), "invalid", context);
222     config = appMgrServiceInner->GetConfiguration();
223     EXPECT_NE(config, nullptr);
224 
225     TAG_LOGI(AAFwkTag::TEST, "PointerDeviceCallback_0400 end");
226 }
227 
228 /**
229  * @tc.name: PointerDeviceWatchParameter_0100
230  * @tc.desc: set parameter, expect config update
231  * @tc.type: FUNC
232  */
233 HWTEST_F(AppMgrServiceInnerTest, PointerDeviceWatchParameter_0100, TestSize.Level1)
234 {
235     TAG_LOGI(AAFwkTag::TEST, "PointerDeviceWatchParameter_0100 start");
236 
237     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
238     EXPECT_NE(appMgrServiceInner, nullptr);
239     std::string key = AAFwk::GlobalConfigurationKey::INPUT_POINTER_DEVICE;
240     std::shared_ptr<AppExecFwk::Configuration> config = nullptr;
241     std::string value;
242 
243     appMgrServiceInner->AddWatchParameter();
244     sleep(1);
245 
246     // invalid parameter value
247     system::SetParameter(key.c_str(), "invalid");
248     sleep(1);
249     config = appMgrServiceInner->GetConfiguration();
250     EXPECT_NE(config, nullptr);
251 
252     TAG_LOGI(AAFwkTag::TEST, "PointerDeviceWatchParameter_0100 end");
253 }
254 
255 /**
256  * @tc.name: PointerDeviceWatchParameter_0200
257  * @tc.desc: set parameter, expect config update
258  * @tc.type: FUNC
259  */
260 HWTEST_F(AppMgrServiceInnerTest, PointerDeviceWatchParameter_0200, TestSize.Level1)
261 {
262     TAG_LOGI(AAFwkTag::TEST, "PointerDeviceWatchParameter_0200 start");
263 
264     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
265     EXPECT_NE(appMgrServiceInner, nullptr);
266     std::string key = AAFwk::GlobalConfigurationKey::INPUT_POINTER_DEVICE;
267     std::shared_ptr<AppExecFwk::Configuration> config = nullptr;
268     std::string value;
269 
270     appMgrServiceInner->AddWatchParameter();
271     sleep(1);
272 
273     // set "input.pointer.device" to false
274     system::SetParameter(key.c_str(), "false");
275     sleep(1);
276     config = appMgrServiceInner->GetConfiguration();
277     EXPECT_NE(config, nullptr);
278 
279     TAG_LOGI(AAFwkTag::TEST, "PointerDeviceWatchParameter_0200 end");
280 }
281 
282 /**
283  * @tc.name: PointerDeviceWatchParameter_0300
284  * @tc.desc: set parameter, expect config update
285  * @tc.type: FUNC
286  */
287 HWTEST_F(AppMgrServiceInnerTest, PointerDeviceWatchParameter_0300, TestSize.Level1)
288 {
289     TAG_LOGI(AAFwkTag::TEST, "PointerDeviceWatchParameter_0300 start");
290 
291     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
292     EXPECT_NE(appMgrServiceInner, nullptr);
293     std::string key = AAFwk::GlobalConfigurationKey::INPUT_POINTER_DEVICE;
294     std::shared_ptr<AppExecFwk::Configuration> config = nullptr;
295     std::string value;
296 
297     appMgrServiceInner->AddWatchParameter();
298     sleep(1);
299 
300     // set "input.pointer.device" to true
301     system::SetParameter(key.c_str(), "true");
302     sleep(1);
303     config = appMgrServiceInner->GetConfiguration();
304     EXPECT_NE(config, nullptr);
305 
306     TAG_LOGI(AAFwkTag::TEST, "PointerDeviceWatchParameter_0300 end");
307 }
308 
309 /**
310  * @tc.name: PointerDeviceUpdateConfig_0100
311  * @tc.desc: set parameter, expect config update
312  * @tc.type: FUNC
313  * @tc.require: I581UL
314  */
315 HWTEST_F(AppMgrServiceInnerTest, PointerDeviceUpdateConfig_0100, TestSize.Level1)
316 {
317     TAG_LOGI(AAFwkTag::TEST, "PointerDeviceUpdateConfig_0100 start");
318 
319     AAFwk::IsMockSaCall::IsMockSaCallWithPermission();
320     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
321     EXPECT_NE(appMgrServiceInner, nullptr);
322     std::shared_ptr<AppExecFwk::Configuration> config;
323     std::string value;
324     int32_t result;
325 
326     appMgrServiceInner->InitGlobalConfiguration();
327     config = appMgrServiceInner->GetConfiguration();
328     EXPECT_NE(config, nullptr);
329     value = config->GetItem(AAFwk::GlobalConfigurationKey::INPUT_POINTER_DEVICE);
330     EXPECT_TRUE((value == "true") || (value == "false"));
331 
332     // config didn't change
333     result = appMgrServiceInner->UpdateConfiguration(*config);
334     EXPECT_EQ(result, ERR_INVALID_VALUE);
335 
336     Configuration changeConfig;
337     if (value == "true") {
338         changeConfig.AddItem(AAFwk::GlobalConfigurationKey::INPUT_POINTER_DEVICE, "false");
339         result = appMgrServiceInner->UpdateConfiguration(changeConfig);
340         EXPECT_EQ(result, ERR_OK);
341         config = appMgrServiceInner->GetConfiguration();
342         EXPECT_NE(config, nullptr);
343         value = config->GetItem(AAFwk::GlobalConfigurationKey::INPUT_POINTER_DEVICE);
344         EXPECT_EQ(value, "false");
345     } else {
346         changeConfig.AddItem(AAFwk::GlobalConfigurationKey::INPUT_POINTER_DEVICE, "true");
347         result = appMgrServiceInner->UpdateConfiguration(changeConfig);
348         EXPECT_EQ(result, ERR_PERMISSION_DENIED);
349         config = appMgrServiceInner->GetConfiguration();
350         EXPECT_NE(config, nullptr);
351         value = config->GetItem(AAFwk::GlobalConfigurationKey::INPUT_POINTER_DEVICE);
352         EXPECT_EQ(value, "true");
353     }
354 
355     TAG_LOGI(AAFwkTag::TEST, "PointerDeviceUpdateConfig_0100 end");
356 }
357 
358 /**
359  * @tc.name: PreStartNWebSpawnProcess_001
360  * @tc.desc: prestart nwebspawn process.
361  * @tc.type: FUNC
362  * @tc.require: issueI5W4S7
363  */
364 HWTEST_F(AppMgrServiceInnerTest, PreStartNWebSpawnProcess_001, TestSize.Level0)
365 {
366     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
367     EXPECT_NE(appMgrServiceInner, nullptr);
368 
369     int callingPid = IPCSkeleton::GetCallingPid();
370     int ret = appMgrServiceInner->PreStartNWebSpawnProcess(callingPid);
371     EXPECT_NE(ret, ERR_OK);
372 }
373 
374 /**
375  * @tc.name: PreStartNWebSpawnProcess_002
376  * @tc.desc: prestart nwebspawn process.
377  * @tc.type: FUNC
378  * @tc.require: issueI5W4S7
379  */
380 HWTEST_F(AppMgrServiceInnerTest, PreStartNWebSpawnProcess_002, TestSize.Level0)
381 {
382     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
383     EXPECT_NE(appMgrServiceInner, nullptr);
384 
385     int callingPid = 0;
386     int ret = appMgrServiceInner->PreStartNWebSpawnProcess(callingPid);
387     EXPECT_EQ(ret, ERR_INVALID_VALUE);
388 }
389 
390 /**
391  * @tc.name: LoadAbility_001
392  * @tc.desc: load ability.
393  * @tc.type: FUNC
394  * @tc.require: issueI5W4S7
395  */
396 HWTEST_F(AppMgrServiceInnerTest, LoadAbility_001, TestSize.Level0)
397 {
398     TAG_LOGI(AAFwkTag::TEST, "LoadAbility_001 start");
399     OHOS::sptr<IRemoteObject> token = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
400     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
401     EXPECT_NE(appMgrServiceInner, nullptr);
402 
403     appMgrServiceInner->appRunningManager_ = nullptr;
404     AbilityRuntime::LoadParam loadParam;
405     loadParam.token = token;
406     auto loadParamPtr = std::make_shared<AbilityRuntime::LoadParam>(loadParam);
407     appMgrServiceInner->LoadAbility(abilityInfo_, applicationInfo_, nullptr, loadParamPtr);
408 
409     auto appMgrServiceInner1 = std::make_shared<AppMgrServiceInner>();
410     EXPECT_NE(appMgrServiceInner1, nullptr);
411 
412     appMgrServiceInner1->remoteClientManager_->SetBundleManagerHelper(nullptr);
413     appMgrServiceInner1->LoadAbility(abilityInfo_, applicationInfo_, nullptr, loadParamPtr);
414 
415     auto appMgrServiceInner2 = std::make_shared<AppMgrServiceInner>();
416     EXPECT_NE(appMgrServiceInner2, nullptr);
417 
418     appMgrServiceInner2->LoadAbility(abilityInfo_, applicationInfo_, nullptr, loadParamPtr);
419     TAG_LOGI(AAFwkTag::TEST, "LoadAbility_001 end");
420 }
421 
422 /**
423  * @tc.name: CheckLoadAbilityConditions_001
424  * @tc.desc: check load ability conditions.
425  * @tc.type: FUNC
426  * @tc.require: issueI5W4S7
427  */
428 HWTEST_F(AppMgrServiceInnerTest, CheckLoadAbilityConditions_001, TestSize.Level0)
429 {
430     TAG_LOGI(AAFwkTag::TEST, "CheckLoadAbilityConditions_001 start");
431     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
432     EXPECT_NE(appMgrServiceInner, nullptr);
433 
434     OHOS::sptr<IRemoteObject> token = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
435 
436     appMgrServiceInner->CheckLoadAbilityConditions(nullptr, nullptr, nullptr);
437 
438     appMgrServiceInner->CheckLoadAbilityConditions(nullptr, abilityInfo_, nullptr);
439 
440     appMgrServiceInner->CheckLoadAbilityConditions(nullptr, nullptr, applicationInfo_);
441 
442     appMgrServiceInner->CheckLoadAbilityConditions(token, nullptr, nullptr);
443 
444     appMgrServiceInner->CheckLoadAbilityConditions(token, abilityInfo_, nullptr);
445 
446     appMgrServiceInner->CheckLoadAbilityConditions(nullptr, abilityInfo_, applicationInfo_);
447 
448     appMgrServiceInner->CheckLoadAbilityConditions(token, nullptr, applicationInfo_);
449 
450     appMgrServiceInner->CheckLoadAbilityConditions(token, abilityInfo_, applicationInfo_);
451 
452     EXPECT_NE(appMgrServiceInner, nullptr);
453     TAG_LOGI(AAFwkTag::TEST, "CheckLoadAbilityConditions_001 end");
454 }
455 
456 /**
457  * @tc.name: MakeProcessName_001
458  * @tc.desc: make process name.
459  * @tc.type: FUNC
460  * @tc.require: issueI5W4S7
461  */
462 HWTEST_F(AppMgrServiceInnerTest, MakeProcessName_001, TestSize.Level0)
463 {
464     TAG_LOGI(AAFwkTag::TEST, "MakeProcessName_001 start");
465     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
466     EXPECT_NE(appMgrServiceInner, nullptr);
467 
468     HapModuleInfo hapModuleInfo;
469     hapModuleInfo.moduleName = "module789";
470     std::string processName = "test_processName";
471     appMgrServiceInner->MakeProcessName(nullptr, nullptr, hapModuleInfo, 1, "", processName);
472     appMgrServiceInner->MakeProcessName(nullptr, applicationInfo_, hapModuleInfo, 1, "", processName);
473     appMgrServiceInner->MakeProcessName(abilityInfo_, nullptr, hapModuleInfo, 1, "", processName);
474     appMgrServiceInner->MakeProcessName(abilityInfo_, applicationInfo_, hapModuleInfo, 1, "", processName);
475 
476     EXPECT_NE(appMgrServiceInner, nullptr);
477     TAG_LOGI(AAFwkTag::TEST, "MakeProcessName_001 end");
478 }
479 
480 /**
481  * @tc.name: MakeProcessName_002
482  * @tc.desc: make process name.
483  * @tc.type: FUNC
484  * @tc.require: issueI5W4S7
485  */
486 HWTEST_F(AppMgrServiceInnerTest, MakeProcessName_002, TestSize.Level0)
487 {
488     TAG_LOGI(AAFwkTag::TEST, "MakeProcessName_002 start");
489     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
490     EXPECT_NE(appMgrServiceInner, nullptr);
491 
492     HapModuleInfo hapModuleInfo;
493     hapModuleInfo.moduleName = "module789";
494     std::string processName = "test_processName";
495     appMgrServiceInner->MakeProcessName(nullptr, hapModuleInfo, processName);
496     appMgrServiceInner->MakeProcessName(applicationInfo_, hapModuleInfo, processName);
497     hapModuleInfo.isStageBasedModel = false;
498     hapModuleInfo.process = "";
499     appMgrServiceInner->MakeProcessName(applicationInfo_, hapModuleInfo, processName);
500 
501     hapModuleInfo.isStageBasedModel = true;
502     hapModuleInfo.process = "";
503     appMgrServiceInner->MakeProcessName(applicationInfo_, hapModuleInfo, processName);
504 
505     hapModuleInfo.isStageBasedModel = false;
506     hapModuleInfo.process = "test_process";
507     appMgrServiceInner->MakeProcessName(applicationInfo_, hapModuleInfo, processName);
508 
509     hapModuleInfo.isStageBasedModel = true;
510     hapModuleInfo.process = "test_process";
511     appMgrServiceInner->MakeProcessName(applicationInfo_, hapModuleInfo, processName);
512 
513     hapModuleInfo.isStageBasedModel = false;
514     applicationInfo_->process = "";
515     appMgrServiceInner->MakeProcessName(applicationInfo_, hapModuleInfo, processName);
516 
517     hapModuleInfo.isStageBasedModel = false;
518     applicationInfo_->process = "test_process";
519     appMgrServiceInner->MakeProcessName(applicationInfo_, hapModuleInfo, processName);
520 
521     EXPECT_NE(appMgrServiceInner, nullptr);
522     TAG_LOGI(AAFwkTag::TEST, "MakeProcessName_002 end");
523 }
524 
525 /**
526  * @tc.name: GetBundleAndHapInfo_001
527  * @tc.desc: get bundle and hapInfo.
528  * @tc.type: FUNC
529  * @tc.require: issueI5W4S7
530  */
531 HWTEST_F(AppMgrServiceInnerTest, GetBundleAndHapInfo_001, TestSize.Level0)
532 {
533     TAG_LOGI(AAFwkTag::TEST, "GetBundleAndHapInfo_001 start");
534     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
535     EXPECT_NE(appMgrServiceInner, nullptr);
536 
537     BundleInfo bundleInfo;
538     HapModuleInfo hapModuleInfo;
539     appMgrServiceInner->GetBundleAndHapInfo(*abilityInfo_, applicationInfo_, bundleInfo, hapModuleInfo, 1);
540 
541     appMgrServiceInner->remoteClientManager_->SetBundleManagerHelper(nullptr);
542     appMgrServiceInner->GetBundleAndHapInfo(*abilityInfo_, applicationInfo_, bundleInfo, hapModuleInfo, 1);
543     TAG_LOGI(AAFwkTag::TEST, "GetBundleAndHapInfo_001 end");
544 }
545 
546 /**
547  * @tc.name: AttachApplication_001
548  * @tc.desc: attach application.
549  * @tc.type: FUNC
550  * @tc.require: issueI5W4S7
551  */
552 HWTEST_F(AppMgrServiceInnerTest, AttachApplication_001, TestSize.Level0)
553 {
554     TAG_LOGI(AAFwkTag::TEST, "AttachApplication_001 start");
555     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
556     EXPECT_NE(appMgrServiceInner, nullptr);
557 
558     appMgrServiceInner->AttachApplication(0, nullptr);
559 
560     appMgrServiceInner->AttachApplication(1, nullptr);
561 
562     sptr<MockAppScheduler> mockAppScheduler = new (std::nothrow) MockAppScheduler();
563     sptr<IAppScheduler> client = iface_cast<IAppScheduler>(mockAppScheduler.GetRefPtr());
564     appMgrServiceInner->AttachApplication(1, client);
565     TAG_LOGI(AAFwkTag::TEST, "AttachApplication_001 end");
566 }
567 
568 /**
569  * @tc.name: LaunchApplication_001
570  * @tc.desc: launch application.
571  * @tc.type: FUNC
572  * @tc.require: issueI5W4S7
573  */
574 HWTEST_F(AppMgrServiceInnerTest, LaunchApplication_001, TestSize.Level0)
575 {
576     TAG_LOGI(AAFwkTag::TEST, "LaunchApplication_001 start");
577     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
578     EXPECT_NE(appMgrServiceInner, nullptr);
579 
580     appMgrServiceInner->LaunchApplication(nullptr);
581 
582     BundleInfo info;
583     std::string processName = "test_processName";
584     std::shared_ptr<AppRunningRecord> appRecord =
585         appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info);
586     recordId_ += 1;
587     appMgrServiceInner->LaunchApplication(appRecord);
588 
589     appRecord->SetState(ApplicationState::APP_STATE_FOREGROUND);
590     appMgrServiceInner->LaunchApplication(appRecord);
591 
592     appRecord->SetState(ApplicationState::APP_STATE_CREATE);
593     appMgrServiceInner->LaunchApplication(appRecord);
594 
595     appRecord->SetEmptyKeepAliveAppState(true);
596     appRecord->SetKeepAliveEnableState(false);
597     appMgrServiceInner->LaunchApplication(appRecord);
598 
599     appRecord->SetKeepAliveEnableState(true);
600     appRecord->SetEmptyKeepAliveAppState(false);
601     appMgrServiceInner->LaunchApplication(appRecord);
602 
603     appRecord->SetKeepAliveEnableState(true);
604     appRecord->SetEmptyKeepAliveAppState(true);
605     appMgrServiceInner->LaunchApplication(appRecord);
606 
607     appRecord->SetKeepAliveEnableState(false);
608     appRecord->SetEmptyKeepAliveAppState(false);
609     appMgrServiceInner->LaunchApplication(appRecord);
610 
611     Want want;
612     appRecord->SetSpecifiedAbilityFlagAndWant(-1, want, "");
613     appMgrServiceInner->LaunchApplication(appRecord);
614 
615     appRecord->SetSpecifiedAbilityFlagAndWant(1, want, "");
616     appMgrServiceInner->LaunchApplication(appRecord);
617 
618     appMgrServiceInner->configuration_ = nullptr;
619     appMgrServiceInner->LaunchApplication(appRecord);
620     TAG_LOGI(AAFwkTag::TEST, "LaunchApplication_001 end");
621 }
622 
623 /**
624  * @tc.name: AddAbilityStageDone_001
625  * @tc.desc: add ability stage done.
626  * @tc.type: FUNC
627  * @tc.require: issueI5W4S7
628  */
629 HWTEST_F(AppMgrServiceInnerTest, AddAbilityStageDone_001, TestSize.Level0)
630 {
631     TAG_LOGI(AAFwkTag::TEST, "AddAbilityStageDone_001 start");
632     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
633     EXPECT_NE(appMgrServiceInner, nullptr);
634 
635     appMgrServiceInner->AddAbilityStageDone(99);
636 
637     BundleInfo info;
638     std::string processName = "test_processName";
639     appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info);
640     recordId_ += 1;
641 
642     appMgrServiceInner->AddAbilityStageDone(recordId_);
643     TAG_LOGI(AAFwkTag::TEST, "AddAbilityStageDone_001 end");
644 }
645 
646 /**
647  * @tc.name: ApplicationForegrounded_001
648  * @tc.desc: application foregrounded.
649  * @tc.type: FUNC
650  * @tc.require: issueI5W4S7
651  */
652 HWTEST_F(AppMgrServiceInnerTest, ApplicationForegrounded_001, TestSize.Level0)
653 {
654     TAG_LOGI(AAFwkTag::TEST, "ApplicationForegrounded_001 start");
655     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
656     EXPECT_NE(appMgrServiceInner, nullptr);
657 
658     appMgrServiceInner->ApplicationForegrounded(99);
659 
660     BundleInfo info;
661     std::string processName = "test_processName";
662     appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info);
663     recordId_ += 1;
664 
665     appMgrServiceInner->ApplicationForegrounded(recordId_);
666     TAG_LOGI(AAFwkTag::TEST, "ApplicationForegrounded_001 end");
667 }
668 
669 /**
670  * @tc.name: ApplicationForegrounded_002
671  * @tc.desc: application foregrounded.
672  * @tc.type: FUNC
673  * @tc.require: issueI5W4S7
674  */
675 HWTEST_F(AppMgrServiceInnerTest, ApplicationForegrounded_002, TestSize.Level0)
676 {
677     TAG_LOGI(AAFwkTag::TEST, "ApplicationForegrounded_002 start");
678     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
679     EXPECT_NE(appMgrServiceInner, nullptr);
680 
681     BundleInfo info;
682     std::string processName = "test_processName";
683     auto record = appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info);
684     recordId_ += 1;
685 
686     appMgrServiceInner->ApplicationForegrounded(recordId_);
687     TAG_LOGI(AAFwkTag::TEST, "ApplicationForegrounded_002 end");
688 }
689 
690 /**
691  * @tc.name: ApplicationForegrounded_003
692  * @tc.desc: application foregrounded.
693  * @tc.type: FUNC
694  * @tc.require: issueI5W4S7
695  */
696 HWTEST_F(AppMgrServiceInnerTest, ApplicationForegrounded_003, TestSize.Level0)
697 {
698     TAG_LOGI(AAFwkTag::TEST, "ApplicationForegrounded_003 start");
699     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
700     EXPECT_NE(appMgrServiceInner, nullptr);
701 
702     BundleInfo info;
703     std::string processName = "test_processName";
704     auto record = appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info);
705     recordId_ += 1;
706     auto record2 = appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info);
707     recordId_ += 1;
708     std::shared_ptr<PriorityObject> priorityObject = std::make_shared<PriorityObject>();
709     std::string callerBundleName = "callerBundleName";
710     priorityObject->SetPid(1);
711     record2->priorityObject_ = priorityObject;
712     record2->mainBundleName_ = callerBundleName;
713     record->SetCallerPid(1);
714 
715     appMgrServiceInner->ApplicationForegrounded(--recordId_);
716     TAG_LOGI(AAFwkTag::TEST, "ApplicationForegrounded_003 end");
717 }
718 
719 /**
720  * @tc.name: ApplicationBackgrounded_001
721  * @tc.desc: application backgrounded.
722  * @tc.type: FUNC
723  * @tc.require: issueI5W4S7
724  */
725 HWTEST_F(AppMgrServiceInnerTest, ApplicationBackgrounded_001, TestSize.Level0)
726 {
727     TAG_LOGI(AAFwkTag::TEST, "ApplicationBackgrounded_001 start");
728     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
729     EXPECT_NE(appMgrServiceInner, nullptr);
730     appMgrServiceInner->Init();
731 
732     appMgrServiceInner->ApplicationBackgrounded(99);
733 
734     BundleInfo info;
735     std::string processName = "test_processName";
736     auto appRecord =
737         appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info);
738     EXPECT_NE(appRecord, nullptr);
739     recordId_ += 1;
740 
741     appMgrServiceInner->ApplicationBackgrounded(recordId_);
742 
743     appRecord->SetState(ApplicationState::APP_STATE_FOREGROUND);
744     appMgrServiceInner->ApplicationBackgrounded(recordId_);
745 
746     TAG_LOGI(AAFwkTag::TEST, "ApplicationBackgrounded_001 end");
747 }
748 
749 /**
750  * @tc.name: ApplicationTerminated_001
751  * @tc.desc: application terminated.
752  * @tc.type: FUNC
753  * @tc.require: issueI5W4S7
754  */
755 HWTEST_F(AppMgrServiceInnerTest, ApplicationTerminated_001, TestSize.Level0)
756 {
757     TAG_LOGI(AAFwkTag::TEST, "ApplicationTerminated_001 start");
758     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
759     EXPECT_NE(appMgrServiceInner, nullptr);
760 
761     appMgrServiceInner->ApplicationTerminated(99);
762 
763     BundleInfo info;
764     std::string processName = "test_processName";
765     auto appRecord =
766         appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info);
767     EXPECT_NE(appRecord, nullptr);
768     recordId_ += 1;
769 
770     appMgrServiceInner->ApplicationTerminated(recordId_);
771 
772     appRecord->SetKeepAliveEnableState(false);
773     appRecord->SetEmptyKeepAliveAppState(true);
774     appMgrServiceInner->ApplicationTerminated(recordId_);
775 
776     appRecord->SetKeepAliveEnableState(true);
777     appRecord->SetEmptyKeepAliveAppState(false);
778     appMgrServiceInner->ApplicationTerminated(recordId_);
779 
780     appRecord->SetKeepAliveEnableState(true);
781     appRecord->SetEmptyKeepAliveAppState(true);
782     appMgrServiceInner->ApplicationTerminated(recordId_);
783 
784     appRecord->SetKeepAliveEnableState(false);
785     appRecord->SetEmptyKeepAliveAppState(false);
786     appMgrServiceInner->ApplicationTerminated(recordId_);
787 
788     appRecord->SetState(ApplicationState::APP_STATE_FOREGROUND);
789     appMgrServiceInner->ApplicationTerminated(recordId_);
790 
791     appRecord->SetState(ApplicationState::APP_STATE_BACKGROUND);
792     appMgrServiceInner->ApplicationTerminated(recordId_);
793 
794     appMgrServiceInner->appRunningManager_ = nullptr;
795     appMgrServiceInner->ApplicationTerminated(recordId_);
796 
797     TAG_LOGI(AAFwkTag::TEST, "ApplicationTerminated_001 end");
798 }
799 
800 /**
801  * @tc.name: KillApplication_001
802  * @tc.desc: kill application.
803  * @tc.type: FUNC
804  * @tc.require: issueI5W4S7
805  */
806 HWTEST_F(AppMgrServiceInnerTest, KillApplication_001, TestSize.Level0)
807 {
808     TAG_LOGI(AAFwkTag::TEST, "KillApplication_001 start");
809     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
810     EXPECT_NE(appMgrServiceInner, nullptr);
811 
812     std::string bundleName = "test_bundleName";
813     appMgrServiceInner->KillApplication(bundleName);
814 
815     appMgrServiceInner->appRunningManager_ = nullptr;
816     appMgrServiceInner->KillApplication(bundleName);
817 
818     TAG_LOGI(AAFwkTag::TEST, "KillApplication_001 end");
819 }
820 
821 /**
822  * @tc.name: KillApplicationByUid_001
823  * @tc.desc: kill application by uid.
824  * @tc.type: FUNC
825  * @tc.require: issueI5W4S7
826  */
827 HWTEST_F(AppMgrServiceInnerTest, KillApplicationByUid_001, TestSize.Level0)
828 {
829     TAG_LOGI(AAFwkTag::TEST, "KillApplicationByUid_001 start");
830     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
831     EXPECT_NE(appMgrServiceInner, nullptr);
832 
833     std::string bundleName = "test_bundleName";
834     appMgrServiceInner->KillApplicationByUid(bundleName, 0);
835 
836     appMgrServiceInner->remoteClientManager_->SetBundleManagerHelper(nullptr);
837     appMgrServiceInner->KillApplicationByUid(bundleName, 0);
838 
839     appMgrServiceInner->remoteClientManager_ = nullptr;
840     appMgrServiceInner->KillApplicationByUid(bundleName, 0);
841 
842     appMgrServiceInner->appRunningManager_ = nullptr;
843     appMgrServiceInner->KillApplicationByUid(bundleName, 0);
844 
845     TAG_LOGI(AAFwkTag::TEST, "KillApplicationByUid_001 end");
846 }
847 
848 /**
849  * @tc.name: KillApplicationSelf_001
850  * @tc.desc: kill application self.
851  * @tc.type: FUNC
852  * @tc.require: issueI5W4S7
853  */
854 HWTEST_F(AppMgrServiceInnerTest, KillApplicationSelf_001, TestSize.Level0)
855 {
856     TAG_LOGI(AAFwkTag::TEST, "KillApplicationSelf_001 start");
857     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
858     EXPECT_NE(appMgrServiceInner, nullptr);
859 
860     EXPECT_EQ(appMgrServiceInner->KillApplicationSelf(), ERR_INVALID_VALUE);
861 
862     appMgrServiceInner->appRunningManager_ = nullptr;
863     EXPECT_EQ(appMgrServiceInner->KillApplicationSelf(), ERR_NO_INIT);
864 
865     TAG_LOGI(AAFwkTag::TEST, "KillApplicationSelf_001 end");
866 }
867 
868 /**
869  * @tc.name: KillApplicationByUserId_001
870  * @tc.desc: kill application by user id.
871  * @tc.type: FUNC
872  * @tc.require: issueI5W4S7
873  */
874 HWTEST_F(AppMgrServiceInnerTest, KillApplicationByUserId_001, TestSize.Level0)
875 {
876     TAG_LOGI(AAFwkTag::TEST, "KillApplicationByUserId_001 start");
877     AAFwk::IsMockSaCall::IsMockSaCallWithPermission();
878     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
879     EXPECT_NE(appMgrServiceInner, nullptr);
880 
881     std::string bundleName = "test_bundleName";
882     int result = appMgrServiceInner->KillApplicationByUserId(bundleName, 0, 0);
883     EXPECT_EQ(result, 0);
884 
885     appMgrServiceInner->remoteClientManager_->SetBundleManagerHelper(nullptr);
886     appMgrServiceInner->KillApplicationByUserId(bundleName, 0, 0);
887     EXPECT_EQ(result, 0);
888 
889     appMgrServiceInner->remoteClientManager_ = nullptr;
890     appMgrServiceInner->KillApplicationByUserId(bundleName, 0, 0);
891     EXPECT_EQ(result, 0);
892 
893     appMgrServiceInner->appRunningManager_ = nullptr;
894     appMgrServiceInner->KillApplicationByUserId(bundleName, 0, 0);
895     EXPECT_EQ(result, 0);
896 
897     TAG_LOGI(AAFwkTag::TEST, "KillApplicationByUserId_001 end");
898 }
899 
900 /**
901  * @tc.name: KillApplicationByUserIdLocked_001
902  * @tc.desc: kill application by user id locked.
903  * @tc.type: FUNC
904  * @tc.require: issueI5W4S7
905  */
906 HWTEST_F(AppMgrServiceInnerTest, KillApplicationByUserIdLocked_001, TestSize.Level0)
907 {
908     TAG_LOGI(AAFwkTag::TEST, "KillApplicationByUserIdLocked_001 start");
909     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
910     EXPECT_NE(appMgrServiceInner, nullptr);
911 
912     std::string bundleName = "test_bundleName";
913     int result = appMgrServiceInner->KillApplicationByUserIdLocked(bundleName, 0, 0);
914     EXPECT_EQ(result, 0);
915 
916     appMgrServiceInner->remoteClientManager_->SetBundleManagerHelper(nullptr);
917     appMgrServiceInner->KillApplicationByUserIdLocked(bundleName, 0, 0);
918     EXPECT_EQ(result, 0);
919 
920     appMgrServiceInner->remoteClientManager_ = nullptr;
921     appMgrServiceInner->KillApplicationByUserIdLocked(bundleName, 0, 0);
922     EXPECT_EQ(result, 0);
923 
924     appMgrServiceInner->appRunningManager_ = nullptr;
925     appMgrServiceInner->KillApplicationByUserIdLocked(bundleName, 0, 0);
926     EXPECT_EQ(result, 0);
927 
928     TAG_LOGI(AAFwkTag::TEST, "KillApplicationByUserIdLocked_001 end");
929 }
930 
931 /**
932  * @tc.name: ClearUpApplicationData_001
933  * @tc.desc: clear up application data.
934  * @tc.type: FUNC
935  * @tc.require: issueI5W4S7
936  */
937 HWTEST_F(AppMgrServiceInnerTest, ClearUpApplicationData_001, TestSize.Level0)
938 {
939     TAG_LOGI(AAFwkTag::TEST, "ClearUpApplicationData_001 start");
940     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
941     EXPECT_NE(appMgrServiceInner, nullptr);
942 
943     std::string bundleName = "test_bundleName";
944     appMgrServiceInner->ClearUpApplicationData(bundleName, 0, 0, 0);
945 
946     TAG_LOGI(AAFwkTag::TEST, "ClearUpApplicationData_001 end");
947 }
948 
949 /**
950  * @tc.name: ClearUpApplicationDataByUserId_001
951  * @tc.desc: clear up application data by user id.
952  * @tc.type: FUNC
953  * @tc.require: issueI5W4S7
954  */
955 HWTEST_F(AppMgrServiceInnerTest, ClearUpApplicationDataByUserId_001, TestSize.Level0)
956 {
957     TAG_LOGI(AAFwkTag::TEST, "ClearUpApplicationDataByUserId_001 start");
958     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
959     EXPECT_NE(appMgrServiceInner, nullptr);
960 
961     std::string bundleName = "test_bundleName";
962     appMgrServiceInner->ClearUpApplicationDataByUserId(bundleName, 0, 0, 0, 0);
963     appMgrServiceInner->ClearUpApplicationDataByUserId(bundleName, 1, 0, 0, 0);
964     appMgrServiceInner->ClearUpApplicationDataByUserId(bundleName, 1, 1, 0, 0);
965 
966     appMgrServiceInner->appRunningManager_ = nullptr;
967     appMgrServiceInner->ClearUpApplicationDataByUserId(bundleName, 1, 1, 0, 0);
968 
969     appMgrServiceInner->remoteClientManager_->SetBundleManagerHelper(nullptr);
970     appMgrServiceInner->ClearUpApplicationDataByUserId(bundleName, 1, 1, 0, 0);
971 
972     TAG_LOGI(AAFwkTag::TEST, "ClearUpApplicationDataByUserId_001 end");
973 }
974 
975 /**
976  * @tc.name: GetAllRunningProcesses_001
977  * @tc.desc: get all running processes.
978  * @tc.type: FUNC
979  * @tc.require: issueI5W4S7
980  */
981 HWTEST_F(AppMgrServiceInnerTest, GetAllRunningProcesses_001, TestSize.Level0)
982 {
983     TAG_LOGI(AAFwkTag::TEST, "GetAllRunningProcesses_001 start");
984     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
985     EXPECT_NE(appMgrServiceInner, nullptr);
986 
987     std::vector<RunningProcessInfo> info;
988     appMgrServiceInner->GetAllRunningProcesses(info);
989 
990     TAG_LOGI(AAFwkTag::TEST, "GetAllRunningProcesses_001 end");
991 }
992 
993 /**
994  * @tc.name: GetProcessRunningInfosByUserId_001
995  * @tc.desc: get process running infos by user id.
996  * @tc.type: FUNC
997  * @tc.require: issueI5W4S7
998  */
999 HWTEST_F(AppMgrServiceInnerTest, GetProcessRunningInfosByUserId_001, TestSize.Level0)
1000 {
1001     TAG_LOGI(AAFwkTag::TEST, "GetProcessRunningInfosByUserId_001 start");
1002     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1003     EXPECT_NE(appMgrServiceInner, nullptr);
1004 
1005     std::vector<RunningProcessInfo> info;
1006     appMgrServiceInner->GetProcessRunningInfosByUserId(info, 0);
1007 
1008     TAG_LOGI(AAFwkTag::TEST, "GetProcessRunningInfosByUserId_001 end");
1009 }
1010 
1011 /**
1012  * @tc.name: GetAllRenderProcesses_001
1013  * @tc.desc: get all render processes.
1014  * @tc.type: FUNC
1015  */
1016 HWTEST_F(AppMgrServiceInnerTest, GetAllRenderProcesses_001, TestSize.Level0)
1017 {
1018     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1019     EXPECT_NE(appMgrServiceInner, nullptr);
1020 
1021     std::vector<RenderProcessInfo> info;
1022     appMgrServiceInner->GetAllRenderProcesses(info);
1023 }
1024 
1025 /**
1026  * @tc.name: GetAllChildrenProcesses_001
1027  * @tc.desc: get all children processes.
1028  * @tc.type: FUNC
1029  */
1030 HWTEST_F(AppMgrServiceInnerTest, GetAllChildrenProcesses_001, TestSize.Level0)
1031 {
1032     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1033     EXPECT_NE(appMgrServiceInner, nullptr);
1034 
1035     std::vector<ChildProcessInfo> info;
1036     auto result = appMgrServiceInner->GetAllChildrenProcesses(info);
1037     EXPECT_EQ(result, ERR_OK);
1038 }
1039 
1040 /**
1041  * @tc.name: NotifyMemoryLevel_001
1042  * @tc.desc: notify memory level.
1043  * @tc.type: FUNC
1044  * @tc.require: issueI5W4S7
1045  */
1046 HWTEST_F(AppMgrServiceInnerTest, NotifyMemoryLevel_001, TestSize.Level0)
1047 {
1048     TAG_LOGI(AAFwkTag::TEST, "NotifyMemoryLevel_001 start");
1049     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1050     EXPECT_NE(appMgrServiceInner, nullptr);
1051 
1052     std::vector<RunningProcessInfo> info;
1053     int result = appMgrServiceInner->NotifyMemoryLevel(0);
1054     EXPECT_EQ(result, ERR_INVALID_VALUE);
1055 
1056     result = appMgrServiceInner->NotifyMemoryLevel(1);
1057     EXPECT_EQ(result, ERR_INVALID_VALUE);
1058 
1059     result = appMgrServiceInner->NotifyMemoryLevel(2);
1060     EXPECT_EQ(result, ERR_INVALID_VALUE);
1061 
1062     result = appMgrServiceInner->NotifyMemoryLevel(3);
1063     EXPECT_EQ(result, ERR_INVALID_VALUE);
1064 
1065     appMgrServiceInner->appRunningManager_ = nullptr;
1066     result = appMgrServiceInner->NotifyMemoryLevel(3);
1067     EXPECT_EQ(result, ERR_INVALID_VALUE);
1068 
1069     TAG_LOGI(AAFwkTag::TEST, "NotifyMemoryLevel_001 end");
1070 }
1071 
1072 /**
1073  * @tc.name: KillProcessByPid_001
1074  * @tc.desc: kill process by pid.
1075  * @tc.type: FUNC
1076  * @tc.require: issueI5W4S7
1077  */
1078 HWTEST_F(AppMgrServiceInnerTest, KillProcessByPid_001, TestSize.Level0)
1079 {
1080     TAG_LOGI(AAFwkTag::TEST, "KillProcessByPid_001 start");
1081     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1082     EXPECT_NE(appMgrServiceInner, nullptr);
1083 
1084     int result = appMgrServiceInner->KillProcessByPid(0, "KillProcessByPid_001");
1085     EXPECT_EQ(result, AAFwk::ERR_KILL_PROCESS_NOT_EXIST);
1086 
1087     result = appMgrServiceInner->KillProcessByPid(1, "KillProcessByPid_001");
1088     EXPECT_EQ(result, 0);
1089 
1090     TAG_LOGI(AAFwkTag::TEST, "KillProcessByPid_001 end");
1091 }
1092 
1093 /**
1094  * @tc.name: KillProcessByPid_002
1095  * @tc.desc: kill process by pid.
1096  * @tc.type: FUNC
1097  * @tc.require: issueI5W4S7
1098  */
1099 HWTEST_F(AppMgrServiceInnerTest, KillProcessByPid_002, TestSize.Level0)
1100 {
1101     TAG_LOGI(AAFwkTag::TEST, "KillProcessByPid_002 start");
1102     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1103     EXPECT_NE(appMgrServiceInner, nullptr);
1104     int pid = 0;
1105     std::string processName = "test_processName";
1106     std::shared_ptr<AppRunningRecord> appRecord =
1107         std::make_shared<AppRunningRecord>(applicationInfo_, ++recordId_, processName);
1108     auto appRunningManager = std::make_shared<AppRunningManager>();
1109     auto priorityObject = std::make_shared<PriorityObject>();
1110     priorityObject->SetPid(0);
1111     appRecord->priorityObject_ = priorityObject;
1112     appRunningManager->appRunningRecordMap_.emplace(recordId_, appRecord);
1113 
1114     int result = appMgrServiceInner->KillProcessByPid(pid, "KillProcessByPid_002");
1115     EXPECT_EQ(result, AAFwk::ERR_KILL_PROCESS_NOT_EXIST);
1116 
1117     TAG_LOGI(AAFwkTag::TEST, "KillProcessByPid_002 end");
1118 }
1119 
1120 /**
1121  * @tc.name: ProcessExist_001
1122  * @tc.desc: process exist.
1123  * @tc.type: FUNC
1124  * @tc.require: issueI5W4S7
1125  */
1126 HWTEST_F(AppMgrServiceInnerTest, ProcessExist_001, TestSize.Level0)
1127 {
1128     TAG_LOGI(AAFwkTag::TEST, "ProcessExist_001 start");
1129     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1130     EXPECT_NE(appMgrServiceInner, nullptr);
1131 
1132     pid_t pid = 0;
1133     bool result = appMgrServiceInner->ProcessExist(pid);
1134     EXPECT_FALSE(result);
1135 
1136     TAG_LOGI(AAFwkTag::TEST, "ProcessExist_001 end");
1137 }
1138 
1139 /**
1140  * @tc.name: CreateAppRunningRecord_001
1141  * @tc.desc: create app running record.
1142  * @tc.type: FUNC
1143  * @tc.require: issueI5W4S7
1144  */
1145 HWTEST_F(AppMgrServiceInnerTest, CreateAppRunningRecord_001, TestSize.Level0)
1146 {
1147     TAG_LOGI(AAFwkTag::TEST, "CreateAppRunningRecord_001 start");
1148     OHOS::sptr<IRemoteObject> token = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
1149     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1150     EXPECT_NE(appMgrServiceInner, nullptr);
1151 
1152     BundleInfo bundleInfo;
1153     HapModuleInfo hapModuleInfo;
1154     std::shared_ptr<AAFwk::Want> want;
1155     std::string processName = "test_processName";
1156 
1157     std::shared_ptr<AppRunningRecord> appRecord = appMgrServiceInner->CreateAppRunningRecord(nullptr, nullptr,
1158         nullptr, nullptr, "", bundleInfo, hapModuleInfo, nullptr, 0);
1159     EXPECT_EQ(appRecord, nullptr);
1160 
1161     appRecord = appMgrServiceInner->CreateAppRunningRecord(token, nullptr,
1162         nullptr, nullptr, "", bundleInfo, hapModuleInfo, nullptr, 0);
1163     EXPECT_EQ(appRecord, nullptr);
1164 
1165     appRecord = appMgrServiceInner->CreateAppRunningRecord(token, nullptr,
1166         applicationInfo_, nullptr, "", bundleInfo, hapModuleInfo, nullptr, 0);
1167     EXPECT_EQ(appRecord, nullptr);
1168 
1169     appRecord = appMgrServiceInner->CreateAppRunningRecord(token, nullptr,
1170         applicationInfo_, abilityInfo_, "", bundleInfo, hapModuleInfo, nullptr, 0);
1171     EXPECT_EQ(appRecord, nullptr);
1172 
1173     appRecord = appMgrServiceInner->CreateAppRunningRecord(token, nullptr,
1174         applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, nullptr, 0);
1175     EXPECT_NE(appRecord, nullptr);
1176 
1177     appRecord = appMgrServiceInner->CreateAppRunningRecord(token, nullptr,
1178         applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, nullptr, 0);
1179     EXPECT_NE(appRecord, nullptr);
1180 
1181     appRecord = appMgrServiceInner->CreateAppRunningRecord(token, nullptr,
1182         applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, nullptr, 0);
1183     EXPECT_NE(appRecord, nullptr);
1184 
1185     std::shared_ptr<AppRunningRecord> appRecord1 = appMgrServiceInner->CreateAppRunningRecord(token, nullptr,
1186         nullptr, abilityInfo_, processName, bundleInfo, hapModuleInfo, want, 0);
1187     EXPECT_EQ(appRecord1, nullptr);
1188 
1189     std::shared_ptr<AppRunningRecord> appRecord2 = appMgrServiceInner->CreateAppRunningRecord(token, nullptr,
1190         applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want, 0);
1191     EXPECT_NE(appRecord2, nullptr);
1192 
1193     want = std::make_shared<Want>();
1194     const std::string COLD_START = "coldStart";
1195     want->SetParam(COLD_START, true);
1196     std::shared_ptr<AppRunningRecord> appRecord3 = appMgrServiceInner->CreateAppRunningRecord(token, nullptr,
1197         applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want, 0);
1198     EXPECT_NE(appRecord3, nullptr);
1199 
1200     want->SetParam(COLD_START, false);
1201     std::shared_ptr<AppRunningRecord> appRecord4 = appMgrServiceInner->CreateAppRunningRecord(token, nullptr,
1202         applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want, 0);
1203     EXPECT_NE(appRecord4, nullptr);
1204 
1205     appMgrServiceInner->appRunningManager_ = nullptr;
1206     std::shared_ptr<AppRunningRecord> appRecord5 = appMgrServiceInner->CreateAppRunningRecord(token, nullptr,
1207         applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want, 0);
1208     EXPECT_EQ(appRecord5, nullptr);
1209 
1210     appMgrServiceInner->appRunningManager_ = nullptr;
1211     want->SetParam("multiThread", false);
1212     std::shared_ptr<AppRunningRecord> appRecord6 = appMgrServiceInner->CreateAppRunningRecord(token, nullptr,
1213         applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want, 0);
1214     EXPECT_EQ(appRecord6, nullptr);
1215 
1216     TAG_LOGI(AAFwkTag::TEST, "CreateAppRunningRecord_001 end");
1217 }
1218 
1219 /**
1220  * @tc.name: TerminateAbility_001
1221  * @tc.desc: terminate ability.
1222  * @tc.type: FUNC
1223  * @tc.require: issueI5W4S7
1224  */
1225 HWTEST_F(AppMgrServiceInnerTest, TerminateAbility_001, TestSize.Level0)
1226 {
1227     TAG_LOGI(AAFwkTag::TEST, "TerminateAbility_001 start");
1228     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1229     EXPECT_NE(appMgrServiceInner, nullptr);
1230 
1231     appMgrServiceInner->TerminateAbility(nullptr, true);
1232     appMgrServiceInner->TerminateAbility(nullptr, false);
1233 
1234     OHOS::sptr<IRemoteObject> token = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
1235     appMgrServiceInner->TerminateAbility(token, true);
1236     appMgrServiceInner->TerminateAbility(token, false);
1237 
1238     appMgrServiceInner->appRunningManager_ = nullptr;
1239     appMgrServiceInner->TerminateAbility(token, true);
1240 
1241     TAG_LOGI(AAFwkTag::TEST, "TerminateAbility_001 end");
1242 }
1243 
1244 /**
1245  * @tc.name: UpdateAbilityState_001
1246  * @tc.desc: update ability state.
1247  * @tc.type: FUNC
1248  * @tc.require: issueI5W4S7
1249  */
1250 HWTEST_F(AppMgrServiceInnerTest, UpdateAbilityState_001, TestSize.Level0)
1251 {
1252     TAG_LOGI(AAFwkTag::TEST, "UpdateAbilityState_001 start");
1253     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1254     EXPECT_NE(appMgrServiceInner, nullptr);
1255 
1256     appMgrServiceInner->UpdateAbilityState(nullptr, AbilityState::ABILITY_STATE_CREATE);
1257 
1258     OHOS::sptr<IRemoteObject> token = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
1259     appMgrServiceInner->UpdateAbilityState(token, AbilityState::ABILITY_STATE_CREATE);
1260 
1261     BundleInfo bundleInfo;
1262     HapModuleInfo hapModuleInfo;
1263     std::shared_ptr<AAFwk::Want> want;
1264     std::string processName = "test_processName";
1265     std::shared_ptr<AppRunningRecord> appRecord = appMgrServiceInner->CreateAppRunningRecord(token, nullptr,
1266         applicationInfo_, nullptr, processName, bundleInfo, hapModuleInfo, want, 0);
1267     EXPECT_NE(appRecord, nullptr);
1268     appMgrServiceInner->UpdateAbilityState(token, AbilityState::ABILITY_STATE_CREATE);
1269 
1270     OHOS::sptr<IRemoteObject> token1 = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
1271     std::shared_ptr<AppRunningRecord> appRecord1 = appMgrServiceInner->CreateAppRunningRecord(token1, nullptr,
1272         applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want, 0);
1273     EXPECT_NE(appRecord1, nullptr);
1274 
1275     appMgrServiceInner->UpdateAbilityState(token1, AbilityState::ABILITY_STATE_READY);
1276     appMgrServiceInner->UpdateAbilityState(token1, AbilityState::ABILITY_STATE_CREATE);
1277 
1278     auto abilityRecord1 =
1279         appMgrServiceInner->GetAppRunningRecordByAbilityToken(token1)->GetAbilityRunningRecordByToken(token1);
1280     abilityRecord1->SetState(AbilityState::ABILITY_STATE_TERMINATED);
1281     appMgrServiceInner->UpdateAbilityState(token1, AbilityState::ABILITY_STATE_TERMINATED);
1282 
1283     abilityRecord1->SetState(AbilityState::ABILITY_STATE_CONNECTED);
1284     appMgrServiceInner->UpdateAbilityState(token1, AbilityState::ABILITY_STATE_CONNECTED);
1285 
1286     abilityRecord1->SetState(AbilityState::ABILITY_STATE_DISCONNECTED);
1287     appMgrServiceInner->UpdateAbilityState(token1, AbilityState::ABILITY_STATE_DISCONNECTED);
1288 
1289     abilityRecord1->SetState(AbilityState::ABILITY_STATE_END);
1290     appMgrServiceInner->UpdateAbilityState(token1, AbilityState::ABILITY_STATE_END);
1291 
1292     abilityRecord1->SetState(AbilityState::ABILITY_STATE_BACKGROUND);
1293     appMgrServiceInner->UpdateAbilityState(token1, AbilityState::ABILITY_STATE_BACKGROUND);
1294 
1295     OHOS::sptr<IRemoteObject> token2 = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
1296     abilityInfo_->type = AbilityType::SERVICE;
1297     std::shared_ptr<AppRunningRecord> appRecord2 = appMgrServiceInner->CreateAppRunningRecord(token2, nullptr,
1298         applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want, 0);
1299     EXPECT_NE(appRecord2, nullptr);
1300     appMgrServiceInner->UpdateAbilityState(token2, AbilityState::ABILITY_STATE_CREATE);
1301 
1302     auto abilityRecord2 =
1303         appMgrServiceInner->GetAppRunningRecordByAbilityToken(token2)->GetAbilityRunningRecordByToken(token2);
1304     abilityRecord2->SetState(AbilityState::ABILITY_STATE_TERMINATED);
1305     appMgrServiceInner->UpdateAbilityState(token2, AbilityState::ABILITY_STATE_TERMINATED);
1306 
1307     abilityRecord2->SetState(AbilityState::ABILITY_STATE_CONNECTED);
1308     appMgrServiceInner->UpdateAbilityState(token2, AbilityState::ABILITY_STATE_CONNECTED);
1309 
1310     abilityRecord2->SetState(AbilityState::ABILITY_STATE_DISCONNECTED);
1311     appMgrServiceInner->UpdateAbilityState(token2, AbilityState::ABILITY_STATE_DISCONNECTED);
1312 
1313     abilityRecord2->SetState(AbilityState::ABILITY_STATE_END);
1314     appMgrServiceInner->UpdateAbilityState(token2, AbilityState::ABILITY_STATE_END);
1315 
1316     abilityRecord2->SetState(AbilityState::ABILITY_STATE_BACKGROUND);
1317     appMgrServiceInner->UpdateAbilityState(token2, AbilityState::ABILITY_STATE_BACKGROUND);
1318 
1319     TAG_LOGI(AAFwkTag::TEST, "UpdateAbilityState_001 end");
1320 }
1321 
1322 /**
1323  * @tc.name: UpdateExtensionState_001
1324  * @tc.desc: update extension state.
1325  * @tc.type: FUNC
1326  * @tc.require: issueI5W4S7
1327  */
1328 HWTEST_F(AppMgrServiceInnerTest, UpdateExtensionState_001, TestSize.Level0)
1329 {
1330     TAG_LOGI(AAFwkTag::TEST, "UpdateExtensionState_001 start");
1331     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1332     EXPECT_NE(appMgrServiceInner, nullptr);
1333 
1334     appMgrServiceInner->UpdateExtensionState(nullptr, ExtensionState::EXTENSION_STATE_CREATE);
1335 
1336     OHOS::sptr<IRemoteObject> token = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
1337     appMgrServiceInner->UpdateExtensionState(token, ExtensionState::EXTENSION_STATE_CREATE);
1338 
1339     BundleInfo bundleInfo;
1340     HapModuleInfo hapModuleInfo;
1341     std::shared_ptr<AAFwk::Want> want;
1342     std::string processName = "test_processName";
1343     std::shared_ptr<AppRunningRecord> appRecord = appMgrServiceInner->CreateAppRunningRecord(token, nullptr,
1344         applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want, 0);
1345     EXPECT_NE(appRecord, nullptr);
1346     appMgrServiceInner->UpdateExtensionState(token, ExtensionState::EXTENSION_STATE_CREATE);
1347 
1348     TAG_LOGI(AAFwkTag::TEST, "UpdateExtensionState_001 end");
1349 }
1350 
1351 /**
1352  * @tc.name: OpenAppSpawnConnection_001
1353  * @tc.desc: open app spawn connection.
1354  * @tc.type: FUNC
1355  * @tc.require: issueI5W4S7
1356  */
1357 HWTEST_F(AppMgrServiceInnerTest, OpenAppSpawnConnection_001, TestSize.Level0)
1358 {
1359     TAG_LOGI(AAFwkTag::TEST, "OpenAppSpawnConnection_001 start");
1360     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1361     EXPECT_NE(appMgrServiceInner, nullptr);
1362 
1363     appMgrServiceInner->remoteClientManager_->SetSpawnClient(nullptr);
1364     auto errorCode = appMgrServiceInner->OpenAppSpawnConnection();
1365     EXPECT_EQ(errorCode, ERR_APPEXECFWK_BAD_APPSPAWN_CLIENT);
1366 
1367     appMgrServiceInner->remoteClientManager_ = nullptr;
1368     auto errorCode1 = appMgrServiceInner->OpenAppSpawnConnection();
1369     EXPECT_EQ(errorCode1, ERR_INVALID_VALUE);
1370 
1371     TAG_LOGI(AAFwkTag::TEST, "OpenAppSpawnConnection_001 end");
1372 }
1373 
1374 /**
1375  * @tc.name: CloseAppSpawnConnection_001
1376  * @tc.desc: close app spawn connection.
1377  * @tc.type: FUNC
1378  * @tc.require: issueI5W4S7
1379  */
1380 HWTEST_F(AppMgrServiceInnerTest, CloseAppSpawnConnection_001, TestSize.Level0)
1381 {
1382     TAG_LOGI(AAFwkTag::TEST, "CloseAppSpawnConnection_001 start");
1383     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1384     EXPECT_NE(appMgrServiceInner, nullptr);
1385 
1386     appMgrServiceInner->CloseAppSpawnConnection();
1387 
1388     appMgrServiceInner->remoteClientManager_ = nullptr;
1389     appMgrServiceInner->CloseAppSpawnConnection();
1390 
1391     TAG_LOGI(AAFwkTag::TEST, "CloseAppSpawnConnection_001 end");
1392 }
1393 
1394 /**
1395  * @tc.name: QueryAppSpawnConnectionState_001
1396  * @tc.desc: query app spawn connection.
1397  * @tc.type: FUNC
1398  * @tc.require: issueI5W4S7
1399  */
1400 HWTEST_F(AppMgrServiceInnerTest, QueryAppSpawnConnectionState_001, TestSize.Level0)
1401 {
1402     TAG_LOGI(AAFwkTag::TEST, "QueryAppSpawnConnectionState_001 start");
1403     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1404     EXPECT_NE(appMgrServiceInner, nullptr);
1405 
1406     auto connectionState = appMgrServiceInner->QueryAppSpawnConnectionState();
1407     EXPECT_EQ(connectionState, SpawnConnectionState::STATE_NOT_CONNECT);
1408 
1409     appMgrServiceInner->remoteClientManager_->SetSpawnClient(nullptr);
1410     connectionState = appMgrServiceInner->QueryAppSpawnConnectionState();
1411     EXPECT_EQ(connectionState, SpawnConnectionState::STATE_NOT_CONNECT);
1412 
1413 
1414     appMgrServiceInner->remoteClientManager_ = nullptr;
1415     connectionState = appMgrServiceInner->QueryAppSpawnConnectionState();
1416     EXPECT_EQ(connectionState, SpawnConnectionState::STATE_NOT_CONNECT);
1417 
1418     TAG_LOGI(AAFwkTag::TEST, "QueryAppSpawnConnectionState_001 end");
1419 }
1420 
1421 /**
1422  * @tc.name: SetAppSpawnClient_001
1423  * @tc.desc: set app spawn client.
1424  * @tc.type: FUNC
1425  * @tc.require: issueI5W4S7
1426  */
1427 HWTEST_F(AppMgrServiceInnerTest, SetAppSpawnClient_001, TestSize.Level0)
1428 {
1429     TAG_LOGI(AAFwkTag::TEST, "SetAppSpawnClient_001 start");
1430     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1431     EXPECT_NE(appMgrServiceInner, nullptr);
1432 
1433     std::shared_ptr<AppSpawnClient> spawnClient;
1434     appMgrServiceInner->SetAppSpawnClient(spawnClient);
1435 
1436     appMgrServiceInner->remoteClientManager_ = nullptr;
1437     appMgrServiceInner->SetAppSpawnClient(spawnClient);
1438 
1439     TAG_LOGI(AAFwkTag::TEST, "SetAppSpawnClient_001 end");
1440 }
1441 
1442 /**
1443  * @tc.name: SetBundleManager_001
1444  * @tc.desc: set bundle manager.
1445  * @tc.type: FUNC
1446  * @tc.require: issueI5W4S7
1447  */
1448 HWTEST_F(AppMgrServiceInnerTest, SetBundleManager_001, TestSize.Level0)
1449 {
1450     TAG_LOGI(AAFwkTag::TEST, "SetBundleManager_001 start");
1451     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1452     EXPECT_NE(appMgrServiceInner, nullptr);
1453 
1454     std::shared_ptr<BundleMgrHelper> bundleManager;
1455     appMgrServiceInner->SetBundleManagerHelper(bundleManager);
1456 
1457     appMgrServiceInner->remoteClientManager_ = nullptr;
1458     appMgrServiceInner->SetBundleManagerHelper(bundleManager);
1459 
1460     TAG_LOGI(AAFwkTag::TEST, "SetBundleManager_001 end");
1461 }
1462 
1463 /**
1464  * @tc.name: RegisterAppStateCallback_001
1465  * @tc.desc: register app state call back.
1466  * @tc.type: FUNC
1467  * @tc.require: issueI5W4S7
1468  */
1469 HWTEST_F(AppMgrServiceInnerTest, RegisterAppStateCallback_001, TestSize.Level0)
1470 {
1471     TAG_LOGI(AAFwkTag::TEST, "RegisterAppStateCallback_001 start");
1472     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1473     EXPECT_NE(appMgrServiceInner, nullptr);
1474 
1475     appMgrServiceInner->RegisterAppStateCallback(nullptr);
1476 
1477     sptr<IAppStateCallback> callback;
1478     appMgrServiceInner->RegisterAppStateCallback(callback);
1479 
1480     TAG_LOGI(AAFwkTag::TEST, "RegisterAppStateCallback_001 end");
1481 }
1482 
1483 /**
1484  * @tc.name: AbilityBehaviorAnalysis_001
1485  * @tc.desc: ability behavior analysis.
1486  * @tc.type: FUNC
1487  * @tc.require: issueI5W4S7
1488  */
1489 HWTEST_F(AppMgrServiceInnerTest, AbilityBehaviorAnalysis_001, TestSize.Level0)
1490 {
1491     TAG_LOGI(AAFwkTag::TEST, "AbilityBehaviorAnalysis_001 start");
1492     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1493     EXPECT_NE(appMgrServiceInner, nullptr);
1494 
1495     appMgrServiceInner->AbilityBehaviorAnalysis(nullptr, nullptr, 0, 0, 0);
1496 
1497     OHOS::sptr<IRemoteObject> token = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
1498     appMgrServiceInner->AbilityBehaviorAnalysis(token, nullptr, 0, 0, 0);
1499 
1500     BundleInfo bundleInfo;
1501     HapModuleInfo hapModuleInfo;
1502     std::shared_ptr<AAFwk::Want> want;
1503     std::string processName = "test_processName";
1504     std::shared_ptr<AppRunningRecord> appRecord = appMgrServiceInner->CreateAppRunningRecord(token, nullptr,
1505         applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want, 0);
1506     EXPECT_NE(appRecord, nullptr);
1507     appMgrServiceInner->AbilityBehaviorAnalysis(token, nullptr, 0, 0, 0);
1508 
1509     OHOS::sptr<IRemoteObject> preToken = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
1510     appMgrServiceInner->AbilityBehaviorAnalysis(token, preToken, 0, 0, 0);
1511 
1512     TAG_LOGI(AAFwkTag::TEST, "AbilityBehaviorAnalysis_001 end");
1513 }
1514 
1515 /**
1516  * @tc.name: KillProcessByAbilityToken_001
1517  * @tc.desc: kill process by ability token.
1518  * @tc.type: FUNC
1519  * @tc.require: issueI5W4S7
1520  */
1521 HWTEST_F(AppMgrServiceInnerTest, KillProcessByAbilityToken_001, TestSize.Level0)
1522 {
1523     TAG_LOGI(AAFwkTag::TEST, "KillProcessByAbilityToken_001 start");
1524     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1525     EXPECT_NE(appMgrServiceInner, nullptr);
1526 
1527     appMgrServiceInner->KillProcessByAbilityToken(nullptr);
1528 
1529     OHOS::sptr<IRemoteObject> token = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
1530     appMgrServiceInner->KillProcessByAbilityToken(token);
1531 
1532     BundleInfo bundleInfo;
1533     HapModuleInfo hapModuleInfo;
1534     std::shared_ptr<AAFwk::Want> want;
1535     std::string processName = "test_processName";
1536     std::shared_ptr<AppRunningRecord> appRecord = appMgrServiceInner->CreateAppRunningRecord(token, nullptr,
1537         applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want, 0);
1538     EXPECT_NE(appRecord, nullptr);
1539     appMgrServiceInner->KillProcessByAbilityToken(token);
1540 
1541     appRecord->SetKeepAliveEnableState(true);
1542     appRecord->SetEmptyKeepAliveAppState(true);
1543     appMgrServiceInner->KillProcessByAbilityToken(token);
1544 
1545     TAG_LOGI(AAFwkTag::TEST, "KillProcessByAbilityToken_001 end");
1546 }
1547 
1548 /**
1549  * @tc.name: KillProcessesByUserId_001
1550  * @tc.desc: kill process by user id.
1551  * @tc.type: FUNC
1552  * @tc.require: issueI5W4S7
1553  */
1554 HWTEST_F(AppMgrServiceInnerTest, KillProcessesByUserId_001, TestSize.Level0)
1555 {
1556     TAG_LOGI(AAFwkTag::TEST, "KillProcessesByUserId_001 start");
1557     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1558     EXPECT_NE(appMgrServiceInner, nullptr);
1559 
1560     appMgrServiceInner->KillProcessesByUserId(0);
1561 
1562     appMgrServiceInner->appRunningManager_ = nullptr;
1563     appMgrServiceInner->KillProcessesByUserId(0);
1564 
1565     TAG_LOGI(AAFwkTag::TEST, "KillProcessesByUserId_001 end");
1566 }
1567 
1568 /**
1569  * @tc.name: StartAbility_001
1570  * @tc.desc: start ability.
1571  * @tc.type: FUNC
1572  * @tc.require: issueI5W4S7
1573  */
1574 HWTEST_F(AppMgrServiceInnerTest, StartAbility_001, TestSize.Level0)
1575 {
1576     TAG_LOGI(AAFwkTag::TEST, "StartAbility_001 start");
1577     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1578     EXPECT_NE(appMgrServiceInner, nullptr);
1579 
1580     HapModuleInfo hapModuleInfo;
1581     std::shared_ptr<AAFwk::Want> want;
1582     std::shared_ptr<AppRunningRecord> appRecord;
1583     appMgrServiceInner->StartAbility(nullptr, nullptr, abilityInfo_, nullptr, hapModuleInfo, nullptr, 0);
1584     appMgrServiceInner->StartAbility(nullptr, nullptr, abilityInfo_, appRecord, hapModuleInfo, nullptr, 0);
1585     appMgrServiceInner->StartAbility(nullptr, nullptr, abilityInfo_, appRecord, hapModuleInfo, want, 0);
1586 
1587     OHOS::sptr<IRemoteObject> token = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
1588     OHOS::sptr<IRemoteObject> preToken = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
1589     appMgrServiceInner->StartAbility(token, nullptr, abilityInfo_, appRecord, hapModuleInfo, want, 0);
1590     appMgrServiceInner->StartAbility(nullptr, preToken, abilityInfo_, appRecord, hapModuleInfo, want, 0);
1591     appMgrServiceInner->StartAbility(token, preToken, abilityInfo_, appRecord, hapModuleInfo, want, 0);
1592 
1593     BundleInfo bundleInfo;
1594     std::string processName = "test_processName";
1595     appRecord = appMgrServiceInner->CreateAppRunningRecord(token, nullptr,
1596         applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want, 0);
1597     EXPECT_NE(appRecord, nullptr);
1598     appMgrServiceInner->StartAbility(token, nullptr, abilityInfo_, appRecord, hapModuleInfo, want, 0);
1599     appMgrServiceInner->StartAbility(token, preToken, abilityInfo_, appRecord, hapModuleInfo, want, 0);
1600 
1601     abilityInfo_->applicationInfo.name = "hiservcie";
1602     abilityInfo_->applicationInfo.bundleName = "com.ix.hiservcie";
1603     appMgrServiceInner->StartAbility(token, preToken, abilityInfo_, appRecord, hapModuleInfo, want, 0);
1604 
1605     TAG_LOGI(AAFwkTag::TEST, "StartAbility_001 end");
1606 }
1607 
1608 /**
1609  * @tc.name: GetAppRunningRecordByAbilityToken_001
1610  * @tc.desc: get app running record by ability token.
1611  * @tc.type: FUNC
1612  * @tc.require: issueI5W4S7
1613  */
1614 HWTEST_F(AppMgrServiceInnerTest, GetAppRunningRecordByAbilityToken_001, TestSize.Level0)
1615 {
1616     TAG_LOGI(AAFwkTag::TEST, "GetAppRunningRecordByAbilityToken_001 start");
1617     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1618     EXPECT_NE(appMgrServiceInner, nullptr);
1619 
1620     OHOS::sptr<IRemoteObject> token = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
1621     appMgrServiceInner->GetAppRunningRecordByAbilityToken(token);
1622 
1623     appMgrServiceInner->appRunningManager_ = nullptr;
1624     appMgrServiceInner->GetAppRunningRecordByAbilityToken(token);
1625 
1626     TAG_LOGI(AAFwkTag::TEST, "GetAppRunningRecordByAbilityToken_001 end");
1627 }
1628 
1629 /**
1630  * @tc.name: AbilityTerminated_001
1631  * @tc.desc: ability terminated.
1632  * @tc.type: FUNC
1633  * @tc.require: issueI5W4S7
1634  */
1635 HWTEST_F(AppMgrServiceInnerTest, AbilityTerminated_001, TestSize.Level0)
1636 {
1637     TAG_LOGI(AAFwkTag::TEST, "AbilityTerminated_001 start");
1638     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1639     EXPECT_NE(appMgrServiceInner, nullptr);
1640 
1641     appMgrServiceInner->AbilityTerminated(nullptr);
1642 
1643     OHOS::sptr<IRemoteObject> token = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
1644     appMgrServiceInner->AbilityTerminated(token);
1645 
1646     BundleInfo bundleInfo;
1647     HapModuleInfo hapModuleInfo;
1648     std::shared_ptr<AAFwk::Want> want;
1649     std::string processName = "test_processName";
1650     std::shared_ptr<AppRunningRecord> appRecord = appMgrServiceInner->CreateAppRunningRecord(token, nullptr,
1651         applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want, 0);
1652     EXPECT_NE(appRecord, nullptr);
1653     appMgrServiceInner->AbilityTerminated(token);
1654 
1655     TAG_LOGI(AAFwkTag::TEST, "AbilityTerminated_001 end");
1656 }
1657 
1658 /**
1659  * @tc.name: GetAppRunningRecordByAppRecordId_001
1660  * @tc.desc: get app running record by app record id.
1661  * @tc.type: FUNC
1662  * @tc.require: issueI5W4S7
1663  */
1664 HWTEST_F(AppMgrServiceInnerTest, GetAppRunningRecordByAppRecordId_001, TestSize.Level0)
1665 {
1666     TAG_LOGI(AAFwkTag::TEST, "GetAppRunningRecordByAppRecordId_001 start");
1667     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1668     EXPECT_NE(appMgrServiceInner, nullptr);
1669 
1670     appMgrServiceInner->GetAppRunningRecordByAppRecordId(0);
1671 
1672     appMgrServiceInner->appRunningManager_ = nullptr;
1673     appMgrServiceInner->GetAppRunningRecordByAppRecordId(0);
1674 
1675     TAG_LOGI(AAFwkTag::TEST, "GetAppRunningRecordByAppRecordId_001 end");
1676 }
1677 
1678 /**
1679  * @tc.name: OnAppStateChanged_001
1680  * @tc.desc: on app state changed.
1681  * @tc.type: FUNC
1682  * @tc.require: issueI5W4S7
1683  */
1684 HWTEST_F(AppMgrServiceInnerTest, OnAppStateChanged_001, TestSize.Level0)
1685 {
1686     TAG_LOGI(AAFwkTag::TEST, "OnAppStateChanged_001 start");
1687     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1688     EXPECT_NE(appMgrServiceInner, nullptr);
1689 
1690     appMgrServiceInner->OnAppStateChanged(nullptr, ApplicationState::APP_STATE_CREATE, true, false);
1691     appMgrServiceInner->OnAppStateChanged(nullptr, ApplicationState::APP_STATE_CREATE, false, false);
1692 
1693     BundleInfo bundleInfo;
1694     std::string processName = "test_processName";
1695     std::shared_ptr<AppRunningRecord> appRecord =
1696         appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo);
1697     EXPECT_NE(appRecord, nullptr);
1698     appMgrServiceInner->OnAppStateChanged(appRecord, ApplicationState::APP_STATE_CREATE, true, false);
1699 
1700     sptr<MockAppStateCallback> mockCallback(new MockAppStateCallback());
1701     EXPECT_CALL(*mockCallback, OnAppStateChanged(_)).Times(2);
1702     sptr<IAppStateCallback> callback1 = iface_cast<IAppStateCallback>(mockCallback);
1703     appMgrServiceInner->appStateCallbacks_.push_back({ callback1, 100 });
1704     appMgrServiceInner->OnAppStateChanged(appRecord, ApplicationState::APP_STATE_CREATE, true, false);
1705 
1706     sptr<IAppStateCallback> callback;
1707     appMgrServiceInner->appStateCallbacks_.push_back({ callback, 100 });
1708     appMgrServiceInner->OnAppStateChanged(appRecord, ApplicationState::APP_STATE_CREATE, true, false);
1709 
1710     TAG_LOGI(AAFwkTag::TEST, "OnAppStateChanged_001 end");
1711 }
1712 
1713 /**
1714  * @tc.name: OnAbilityStateChanged_001
1715  * @tc.desc: on ability state changed.
1716  * @tc.type: FUNC
1717  * @tc.require: issueI5W4S7
1718  */
1719 HWTEST_F(AppMgrServiceInnerTest, OnAbilityStateChanged_001, TestSize.Level0)
1720 {
1721     TAG_LOGI(AAFwkTag::TEST, "OnAbilityStateChanged_001 start");
1722     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1723     EXPECT_NE(appMgrServiceInner, nullptr);
1724 
1725     appMgrServiceInner->OnAbilityStateChanged(nullptr, AbilityState::ABILITY_STATE_CREATE);
1726 
1727     sptr<IRemoteObject> token = new MockAbilityToken();
1728     std::shared_ptr<AbilityRunningRecord> abilityRunningRecord =
1729         std::make_shared<AbilityRunningRecord>(abilityInfo_, token, 0);
1730     appMgrServiceInner->OnAbilityStateChanged(abilityRunningRecord, AbilityState::ABILITY_STATE_CREATE);
1731 
1732     sptr<MockAppStateCallback> mockCallback(new MockAppStateCallback());
1733     EXPECT_CALL(*mockCallback, OnAbilityRequestDone(_, _)).Times(2);
1734     sptr<IAppStateCallback> callback1 = iface_cast<IAppStateCallback>(mockCallback);
1735     appMgrServiceInner->appStateCallbacks_.push_back({ callback1, 100 });
1736     appMgrServiceInner->OnAbilityStateChanged(abilityRunningRecord, AbilityState::ABILITY_STATE_CREATE);
1737 
1738     sptr<IAppStateCallback> callback;
1739     appMgrServiceInner->appStateCallbacks_.push_back({ callback, 100 });
1740     appMgrServiceInner->OnAbilityStateChanged(abilityRunningRecord, AbilityState::ABILITY_STATE_CREATE);
1741 
1742     TAG_LOGI(AAFwkTag::TEST, "OnAbilityStateChanged_001 end");
1743 }
1744 
1745 /**
1746  * @tc.name: StartProcess_001
1747  * @tc.desc: start process.
1748  * @tc.type: FUNC
1749  * @tc.require: issueI5W4S7
1750  */
1751 HWTEST_F(AppMgrServiceInnerTest, StartProcess_001, TestSize.Level0)
1752 {
1753     TAG_LOGI(AAFwkTag::TEST, "StartProcess_001 start");
1754     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1755     EXPECT_NE(appMgrServiceInner, nullptr);
1756 
1757     BundleInfo bundleInfo;
1758     std::string appName = "test_appName";
1759     std::string processName = "test_processName";
1760     std::string bundleName = "test_bundleName";
1761     sptr<IRemoteObject> token = new MockAbilityToken();
1762     std::shared_ptr<AppRunningRecord> appRecord =
1763         appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo);
1764     EXPECT_NE(appRecord, nullptr);
1765     appMgrServiceInner->StartProcess(appName, processName, 0, nullptr, 0, bundleInfo, bundleName, 0);
1766     appMgrServiceInner->StartProcess(appName, processName, 0, appRecord, 0, bundleInfo, bundleName, 0);
1767 
1768     TAG_LOGI(AAFwkTag::TEST, "StartProcess_001 end");
1769 }
1770 
1771 /**
1772  * @tc.name: OnRemoteDied_001
1773  * @tc.desc: on remote died.
1774  * @tc.type: FUNC
1775  * @tc.require: issueI5W4S7
1776  */
1777 HWTEST_F(AppMgrServiceInnerTest, OnRemoteDied_001, TestSize.Level0)
1778 {
1779     TAG_LOGI(AAFwkTag::TEST, "OnRemoteDied_001 start");
1780     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1781     EXPECT_NE(appMgrServiceInner, nullptr);
1782 
1783     sptr<IRemoteObject> remoteObject;
1784     appMgrServiceInner->OnRemoteDied(remoteObject, true);
1785     appMgrServiceInner->OnRemoteDied(remoteObject, false);
1786 
1787     TAG_LOGI(AAFwkTag::TEST, "OnRemoteDied_001 end");
1788 }
1789 
1790 /**
1791  * @tc.name: ClearAppRunningData_001
1792  * @tc.desc: clear app running data.
1793  * @tc.type: FUNC
1794  */
1795 HWTEST_F(AppMgrServiceInnerTest, ClearAppRunningData_001, TestSize.Level0)
1796 {
1797     TAG_LOGI(AAFwkTag::TEST, "ClearAppRunningData_001 start");
1798     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1799     EXPECT_NE(appMgrServiceInner, nullptr);
1800 
1801     appMgrServiceInner->ClearAppRunningData(nullptr, true);
1802     TAG_LOGI(AAFwkTag::TEST, "ClearAppRunningData_001 end");
1803 }
1804 
1805 /**
1806  * @tc.name: ClearAppRunningData_002
1807  * @tc.desc: clear app running data.
1808  * @tc.type: FUNC
1809  */
1810 HWTEST_F(AppMgrServiceInnerTest, ClearAppRunningData_002, TestSize.Level0)
1811 {
1812     TAG_LOGI(AAFwkTag::TEST, "ClearAppRunningData_002 start");
1813     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1814     EXPECT_NE(appMgrServiceInner, nullptr);
1815     BundleInfo info;
1816     std::string processName = "test_processName";
1817     std::shared_ptr<AppRunningRecord> appRecord =
1818         appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info);
1819     appMgrServiceInner->ClearAppRunningData(appRecord, true);
1820     TAG_LOGI(AAFwkTag::TEST, "ClearAppRunningData_002 end");
1821 }
1822 
1823 /**
1824  * @tc.name: ClearAppRunningData_003
1825  * @tc.desc: clear app running data.
1826  * @tc.type: FUNC
1827  */
1828 HWTEST_F(AppMgrServiceInnerTest, ClearAppRunningData_003, TestSize.Level0)
1829 {
1830     TAG_LOGI(AAFwkTag::TEST, "ClearAppRunningData_003 start");
1831     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1832     EXPECT_NE(appMgrServiceInner, nullptr);
1833     BundleInfo info;
1834     std::string processName = "test_processName";
1835     std::shared_ptr<AppRunningRecord> appRecord =
1836         appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info);
1837     appMgrServiceInner->ClearAppRunningData(appRecord, false);
1838     TAG_LOGI(AAFwkTag::TEST, "ClearAppRunningData_003 end");
1839 }
1840 
1841 /**
1842  * @tc.name: ClearAppRunningData_004
1843  * @tc.desc: clear app running data.
1844  * @tc.type: FUNC
1845  */
1846 HWTEST_F(AppMgrServiceInnerTest, ClearAppRunningData_004, TestSize.Level0)
1847 {
1848     TAG_LOGI(AAFwkTag::TEST, "ClearAppRunningData_004 start");
1849     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1850     EXPECT_NE(appMgrServiceInner, nullptr);
1851 
1852     appMgrServiceInner->ClearAppRunningData(nullptr, false);
1853     TAG_LOGI(AAFwkTag::TEST, "ClearAppRunningData_004 end");
1854 }
1855 
1856 /**
1857  * @tc.name: HandleTimeOut_001
1858  * @tc.desc: handle time out.
1859  * @tc.type: FUNC
1860  * @tc.require: issueI5W4S7
1861  */
1862 HWTEST_F(AppMgrServiceInnerTest, HandleTimeOut_001, TestSize.Level0)
1863 {
1864     TAG_LOGI(AAFwkTag::TEST, "HandleTimeOut_001 start");
1865     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1866     EXPECT_NE(appMgrServiceInner, nullptr);
1867 
1868     AAFwk::EventWrap innerEvent(0);
1869     appMgrServiceInner->HandleTimeOut(innerEvent);
1870 
1871     appMgrServiceInner->appRunningManager_ = nullptr;
1872     appMgrServiceInner->HandleTimeOut(innerEvent);
1873 
1874     TAG_LOGI(AAFwkTag::TEST, "HandleTimeOut_001 end");
1875 }
1876 
1877 /**
1878  * @tc.name: HandleAbilityAttachTimeOut_001
1879  * @tc.desc: handle ability attach time out.
1880  * @tc.type: FUNC
1881  * @tc.require: issueI5W4S7
1882  */
1883 HWTEST_F(AppMgrServiceInnerTest, HandleAbilityAttachTimeOut_001, TestSize.Level0)
1884 {
1885     TAG_LOGI(AAFwkTag::TEST, "HandleAbilityAttachTimeOut_001 start");
1886     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1887     EXPECT_NE(appMgrServiceInner, nullptr);
1888 
1889     appMgrServiceInner->HandleAbilityAttachTimeOut(nullptr);
1890 
1891     appMgrServiceInner->appRunningManager_ = nullptr;
1892     appMgrServiceInner->HandleAbilityAttachTimeOut(nullptr);
1893 
1894     TAG_LOGI(AAFwkTag::TEST, "HandleAbilityAttachTimeOut_001 end");
1895 }
1896 
1897 /**
1898  * @tc.name: PrepareTerminate_001
1899  * @tc.desc: prepare terminate.
1900  * @tc.type: FUNC
1901  * @tc.require: issueI5W4S7
1902  */
1903 HWTEST_F(AppMgrServiceInnerTest, PrepareTerminate_001, TestSize.Level0)
1904 {
1905     TAG_LOGI(AAFwkTag::TEST, "PrepareTerminate_001 start");
1906     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1907     EXPECT_NE(appMgrServiceInner, nullptr);
1908 
1909     appMgrServiceInner->PrepareTerminate(nullptr);
1910 
1911     appMgrServiceInner->appRunningManager_ = nullptr;
1912     appMgrServiceInner->PrepareTerminate(nullptr);
1913 
1914     TAG_LOGI(AAFwkTag::TEST, "PrepareTerminate_001 end");
1915 }
1916 
1917 /**
1918  * @tc.name: HandleTerminateApplicationTimeOut_001
1919  * @tc.desc: handle terminate application time out.
1920  * @tc.type: FUNC
1921  * @tc.require: issueI5W4S7
1922  */
1923 HWTEST_F(AppMgrServiceInnerTest, HandleTerminateApplicationTimeOut_001, TestSize.Level0)
1924 {
1925     TAG_LOGI(AAFwkTag::TEST, "HandleTerminateApplicationTimeOut_001 start");
1926     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1927     EXPECT_NE(appMgrServiceInner, nullptr);
1928 
1929     appMgrServiceInner->HandleTerminateApplicationTimeOut(0);
1930 
1931     BundleInfo bundleInfo;
1932     std::string appName = "test_appName";
1933     std::string processName = "test_processName";
1934     std::string bundleName = "test_bundleName";
1935     sptr<IRemoteObject> token = new MockAbilityToken();
1936     std::shared_ptr<AppRunningRecord> appRecord =
1937         appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo);
1938     EXPECT_NE(appRecord, nullptr);
1939     appRecord->eventId_ = 0;
1940     appMgrServiceInner->HandleTerminateApplicationTimeOut(0);
1941 
1942     pid_t pid = 1;
1943     appRecord->GetPriorityObject()->SetPid(pid);
1944     appMgrServiceInner->HandleTerminateApplicationTimeOut(0);
1945 
1946     appMgrServiceInner->taskHandler_ = nullptr;
1947     appMgrServiceInner->HandleTerminateApplicationTimeOut(0);
1948 
1949     appMgrServiceInner->appRunningManager_ = nullptr;
1950     appMgrServiceInner->HandleTerminateApplicationTimeOut(0);
1951 
1952     TAG_LOGI(AAFwkTag::TEST, "HandleTerminateApplicationTimeOut_001 end");
1953 }
1954 
1955 /**
1956  * @tc.name: HandleAddAbilityStageTimeOut_001
1957  * @tc.desc: handle add ability stage time out.
1958  * @tc.type: FUNC
1959  * @tc.require: issueI5W4S7
1960  */
1961 HWTEST_F(AppMgrServiceInnerTest, HandleAddAbilityStageTimeOut_001, TestSize.Level0)
1962 {
1963     TAG_LOGI(AAFwkTag::TEST, "HandleAddAbilityStageTimeOut_001 start");
1964     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1965     EXPECT_NE(appMgrServiceInner, nullptr);
1966 
1967     appMgrServiceInner->HandleAddAbilityStageTimeOut(0);
1968 
1969     BundleInfo bundleInfo;
1970     std::string appName = "test_appName";
1971     std::string processName = "test_processName";
1972     std::string bundleName = "test_bundleName";
1973     sptr<IRemoteObject> token = new MockAbilityToken();
1974     std::shared_ptr<AppRunningRecord> appRecord =
1975         appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo);
1976     EXPECT_NE(appRecord, nullptr);
1977     appRecord->eventId_ = 0;
1978     appMgrServiceInner->HandleAddAbilityStageTimeOut(0);
1979 
1980     appRecord->specifiedRequestId_ = 1;
1981     appMgrServiceInner->HandleAddAbilityStageTimeOut(0);
1982 
1983     sptr<IStartSpecifiedAbilityResponse> response;
1984     appMgrServiceInner->startSpecifiedAbilityResponse_ = response;
1985     appMgrServiceInner->HandleAddAbilityStageTimeOut(0);
1986 
1987     appMgrServiceInner->appRunningManager_ = nullptr;
1988     appMgrServiceInner->HandleAddAbilityStageTimeOut(0);
1989 
1990     TAG_LOGI(AAFwkTag::TEST, "HandleAddAbilityStageTimeOut_001 end");
1991 }
1992 
1993 /**
1994  * @tc.name: GetRunningProcessInfoByToken_001
1995  * @tc.desc: get running process info by token.
1996  * @tc.type: FUNC
1997  * @tc.require: issueI5W4S7
1998  */
1999 HWTEST_F(AppMgrServiceInnerTest, GetRunningProcessInfoByToken_001, TestSize.Level0)
2000 {
2001     TAG_LOGI(AAFwkTag::TEST, "GetRunningProcessInfoByToken_001 start");
2002     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2003     EXPECT_NE(appMgrServiceInner, nullptr);
2004 
2005     AppExecFwk::RunningProcessInfo info;
2006     appMgrServiceInner->GetRunningProcessInfoByToken(nullptr, info);
2007 
2008     appMgrServiceInner->appRunningManager_ = nullptr;
2009     appMgrServiceInner->GetRunningProcessInfoByToken(nullptr, info);
2010 
2011     TAG_LOGI(AAFwkTag::TEST, "GetRunningProcessInfoByToken_001 end");
2012 }
2013 
2014 /**
2015  * @tc.name: GetRunningProcessInfoByPid_001
2016  * @tc.desc: get running process info by pid.
2017  * @tc.type: FUNC
2018  * @tc.require: issueI5W4S7
2019  */
2020 HWTEST_F(AppMgrServiceInnerTest, GetRunningProcessInfoByPid_001, TestSize.Level0)
2021 {
2022     TAG_LOGI(AAFwkTag::TEST, "GetRunningProcessInfoByPid_001 start");
2023     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2024     EXPECT_NE(appMgrServiceInner, nullptr);
2025 
2026     AppExecFwk::RunningProcessInfo info;
2027     appMgrServiceInner->GetRunningProcessInfoByPid(0, info);
2028 
2029     appMgrServiceInner->appRunningManager_ = nullptr;
2030     appMgrServiceInner->GetRunningProcessInfoByPid(0, info);
2031 
2032     TAG_LOGI(AAFwkTag::TEST, "GetRunningProcessInfoByPid_001 end");
2033 }
2034 
2035 /**
2036  * @tc.name: CheckGetRunningInfoPermission_001
2037  * @tc.desc: check get running info permission.
2038  * @tc.type: FUNC
2039  * @tc.require: issueI5W4S7
2040  */
2041 HWTEST_F(AppMgrServiceInnerTest, CheckGetRunningInfoPermission_001, TestSize.Level0)
2042 {
2043     TAG_LOGI(AAFwkTag::TEST, "CheckGetRunningInfoPermission_001 start");
2044     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2045     EXPECT_NE(appMgrServiceInner, nullptr);
2046 
2047     appMgrServiceInner->CheckGetRunningInfoPermission();
2048 
2049     appMgrServiceInner->appRunningManager_ = nullptr;
2050     appMgrServiceInner->CheckGetRunningInfoPermission();
2051 
2052     TAG_LOGI(AAFwkTag::TEST, "CheckGetRunningInfoPermission_001 end");
2053 }
2054 
2055 /**
2056  * @tc.name: IsMemorySizeSufficent_001
2057  * @tc.desc: check get running info permission.
2058  * @tc.type: FUNC
2059  * @tc.require: issueI5W4S7
2060  */
2061 HWTEST_F(AppMgrServiceInnerTest, IsMemorySizeSufficent_001, TestSize.Level0)
2062 {
2063     TAG_LOGI(AAFwkTag::TEST, "IsMemorySizeSufficent start");
2064     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2065     EXPECT_NE(appMgrServiceInner, nullptr);
2066 
2067     appMgrServiceInner->IsMemorySizeSufficent();
2068 
2069     appMgrServiceInner->appRunningManager_ = nullptr;
2070     appMgrServiceInner->IsMemorySizeSufficent();
2071 
2072     TAG_LOGI(AAFwkTag::TEST, "IsMemorySizeSufficent_001 end");
2073 }
2074 
2075 /**
2076  * @tc.name: LoadResidentProcess_001
2077  * @tc.desc: load resident process.
2078  * @tc.type: FUNC
2079  * @tc.require: issueI5W4S7
2080  */
2081 HWTEST_F(AppMgrServiceInnerTest, LoadResidentProcess_001, TestSize.Level0)
2082 {
2083     TAG_LOGI(AAFwkTag::TEST, "LoadResidentProcess_001 start");
2084     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2085     EXPECT_NE(appMgrServiceInner, nullptr);
2086 
2087     std::vector<BundleInfo> infos;
2088     appMgrServiceInner->LoadResidentProcess(infos);
2089 
2090     TAG_LOGI(AAFwkTag::TEST, "LoadResidentProcess_001 end");
2091 }
2092 
2093 /**
2094  * @tc.name: StartResidentProcess_001
2095  * @tc.desc: start resident process.
2096  * @tc.type: FUNC
2097  * @tc.require: issueI5W4S7
2098  */
2099 HWTEST_F(AppMgrServiceInnerTest, StartResidentProcess_001, TestSize.Level0)
2100 {
2101     TAG_LOGI(AAFwkTag::TEST, "StartResidentProcess_001 start");
2102     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2103     EXPECT_NE(appMgrServiceInner, nullptr);
2104 
2105     std::vector<BundleInfo> infos;
2106     appMgrServiceInner->StartResidentProcess(infos, 0, true);
2107 
2108     BundleInfo info;
2109     infos.push_back(info);
2110 
2111     BundleInfo info1;
2112     info1.applicationInfo.process = "";
2113     infos.push_back(info1);
2114 
2115     BundleInfo info2;
2116     info2.applicationInfo.process = "test_process";
2117     infos.push_back(info2);
2118     appMgrServiceInner->StartResidentProcess(infos, 0, true);
2119 
2120     appMgrServiceInner->appRunningManager_ = nullptr;
2121     appMgrServiceInner->StartResidentProcess(infos, 0, true);
2122 
2123     TAG_LOGI(AAFwkTag::TEST, "StartResidentProcess_001 end");
2124 }
2125 
2126 /**
2127  * @tc.name: StartEmptyResidentProcess_001
2128  * @tc.desc: start empty resident process.
2129  * @tc.type: FUNC
2130  * @tc.require: issueI5W4S7
2131  */
2132 HWTEST_F(AppMgrServiceInnerTest, StartEmptyResidentProcess_001, TestSize.Level0)
2133 {
2134     TAG_LOGI(AAFwkTag::TEST, "StartEmptyResidentProcess_001 start");
2135     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2136     EXPECT_NE(appMgrServiceInner, nullptr);
2137 
2138     BundleInfo info;
2139     info.applicationInfo = *applicationInfo_;
2140     std::string processName = "test_process";
2141     appMgrServiceInner->StartEmptyResidentProcess(info, processName, 0, true);
2142 
2143     appMgrServiceInner->StartEmptyResidentProcess(info, processName, 1, true);
2144 
2145     appMgrServiceInner->StartEmptyResidentProcess(info, "", 0, true);
2146 
2147     appMgrServiceInner->appRunningManager_ = nullptr;
2148     appMgrServiceInner->StartEmptyResidentProcess(info, processName, 0, true);
2149 
2150     appMgrServiceInner->remoteClientManager_ = nullptr;
2151     appMgrServiceInner->StartEmptyResidentProcess(info, processName, 0, true);
2152 
2153     TAG_LOGI(AAFwkTag::TEST, "StartEmptyResidentProcess_001 end");
2154 }
2155 
2156 /**
2157  * @tc.name: CheckRemoteClient_001
2158  * @tc.desc: check remote client.
2159  * @tc.type: FUNC
2160  * @tc.require: issueI5W4S7
2161  */
2162 HWTEST_F(AppMgrServiceInnerTest, CheckRemoteClient_001, TestSize.Level0)
2163 {
2164     TAG_LOGI(AAFwkTag::TEST, "CheckRemoteClient_001 start");
2165     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2166     EXPECT_NE(appMgrServiceInner, nullptr);
2167 
2168     appMgrServiceInner->CheckRemoteClient();
2169 
2170     appMgrServiceInner->remoteClientManager_->SetSpawnClient(nullptr);
2171     appMgrServiceInner->CheckRemoteClient();
2172 
2173     appMgrServiceInner->remoteClientManager_->SetBundleManagerHelper(nullptr);
2174     appMgrServiceInner->CheckRemoteClient();
2175 
2176     appMgrServiceInner->remoteClientManager_ = nullptr;
2177     appMgrServiceInner->CheckRemoteClient();
2178 
2179     TAG_LOGI(AAFwkTag::TEST, "CheckRemoteClient_001 end");
2180 }
2181 
2182 /**
2183  * @tc.name: RestartResidentProcess_001
2184  * @tc.desc: restart resident process.
2185  * @tc.type: FUNC
2186  * @tc.require: issueI5W4S7
2187  */
2188 HWTEST_F(AppMgrServiceInnerTest, RestartResidentProcess_001, TestSize.Level0)
2189 {
2190     TAG_LOGI(AAFwkTag::TEST, "RestartResidentProcess_001 start");
2191     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2192     EXPECT_NE(appMgrServiceInner, nullptr);
2193 
2194     appMgrServiceInner->RestartResidentProcess(nullptr);
2195 
2196     std::shared_ptr<AppRunningRecord> appRecord;
2197     appMgrServiceInner->RestartResidentProcess(appRecord);
2198 
2199     BundleInfo bundleInfo;
2200     std::string processName = "test_processName";
2201     appRecord =
2202         appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo);
2203     EXPECT_NE(appRecord, nullptr);
2204     appRecord->mainBundleName_ = "com.ohos.settings";
2205     appMgrServiceInner->RestartResidentProcess(appRecord);
2206 
2207     appMgrServiceInner->appRunningManager_ = nullptr;
2208     appMgrServiceInner->RestartResidentProcess(appRecord);
2209 
2210     appMgrServiceInner->remoteClientManager_ = nullptr;
2211     appMgrServiceInner->RestartResidentProcess(appRecord);
2212 
2213     TAG_LOGI(AAFwkTag::TEST, "RestartResidentProcess_001 end");
2214 }
2215 
2216 /**
2217  * @tc.name: NotifyAppStatusByCallerUid_001
2218  * @tc.desc: notify app status by caller uid.
2219  * @tc.type: FUNC
2220  * @tc.require: issueI5W4S7
2221  */
2222 HWTEST_F(AppMgrServiceInnerTest, NotifyAppStatusByCallerUid_001, TestSize.Level0)
2223 {
2224     TAG_LOGI(AAFwkTag::TEST, "NotifyAppStatusByCallerUid_001 start");
2225     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2226     EXPECT_NE(appMgrServiceInner, nullptr);
2227 
2228     std::string bundleName = "test_bundle_name";
2229     std::string eventData = "test_event_data";
2230     appMgrServiceInner->NotifyAppStatusByCallerUid(bundleName, 0, 0, 0, 0, eventData);
2231 
2232     TAG_LOGI(AAFwkTag::TEST, "NotifyAppStatusByCallerUid_001 end");
2233 }
2234 
2235 /**
2236  * @tc.name: RegisterApplicationStateObserver_001
2237  * @tc.desc: register application state observer.
2238  * @tc.type: FUNC
2239  * @tc.require: issueI5W4S7
2240  */
2241 HWTEST_F(AppMgrServiceInnerTest, RegisterApplicationStateObserver_001, TestSize.Level0)
2242 {
2243     TAG_LOGI(AAFwkTag::TEST, "RegisterApplicationStateObserver_001 start");
2244     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2245     EXPECT_NE(appMgrServiceInner, nullptr);
2246 
2247     sptr<IApplicationStateObserver> observer;
2248     std::vector<std::string> bundleNameList;
2249     appMgrServiceInner->RegisterApplicationStateObserver(observer, bundleNameList);
2250 
2251     TAG_LOGI(AAFwkTag::TEST, "RegisterApplicationStateObserver_001 end");
2252 }
2253 
2254 /**
2255  * @tc.name: UnregisterApplicationStateObserver_001
2256  * @tc.desc: unregister application state observer.
2257  * @tc.type: FUNC
2258  * @tc.require: issueI5W4S7
2259  */
2260 HWTEST_F(AppMgrServiceInnerTest, UnregisterApplicationStateObserver_001, TestSize.Level0)
2261 {
2262     TAG_LOGI(AAFwkTag::TEST, "UnregisterApplicationStateObserver_001 start");
2263     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2264     EXPECT_NE(appMgrServiceInner, nullptr);
2265 
2266     sptr<IApplicationStateObserver> observer;
2267     appMgrServiceInner->UnregisterApplicationStateObserver(observer);
2268 
2269     TAG_LOGI(AAFwkTag::TEST, "UnregisterApplicationStateObserver_001 end");
2270 }
2271 
2272 /**
2273  * @tc.name: GetForegroundApplications_001
2274  * @tc.desc: get foreground applications.
2275  * @tc.type: FUNC
2276  * @tc.require: issueI5W4S7
2277  */
2278 HWTEST_F(AppMgrServiceInnerTest, GetForegroundApplications_001, TestSize.Level0)
2279 {
2280     TAG_LOGI(AAFwkTag::TEST, "GetForegroundApplications_001 start");
2281     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2282     EXPECT_NE(appMgrServiceInner, nullptr);
2283 
2284     std::vector<AppStateData> list;
2285     appMgrServiceInner->GetForegroundApplications(list);
2286 
2287     TAG_LOGI(AAFwkTag::TEST, "GetForegroundApplications_001 end");
2288 }
2289 
2290 /**
2291  * @tc.name: StartUserTestProcess_001
2292  * @tc.desc: start user test process.
2293  * @tc.type: FUNC
2294  * @tc.require: issueI5W4S7
2295  */
2296 HWTEST_F(AppMgrServiceInnerTest, StartUserTestProcess_001, TestSize.Level0)
2297 {
2298     TAG_LOGI(AAFwkTag::TEST, "StartUserTestProcess_001 start");
2299     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2300     EXPECT_NE(appMgrServiceInner, nullptr);
2301 
2302     AAFwk::Want want;
2303     sptr<IRemoteObject> observer;
2304     BundleInfo bundleInfo;
2305     appMgrServiceInner->StartUserTestProcess(want, nullptr, bundleInfo, 0);
2306 
2307     appMgrServiceInner->StartUserTestProcess(want, observer, bundleInfo, 0);
2308 
2309     std::string bundle_name = "test_bundle_name";
2310     want.SetParam("-b", bundle_name);
2311     appMgrServiceInner->StartUserTestProcess(want, observer, bundleInfo, 0);
2312 
2313     std::string moduleName = "test_module_name";
2314     want.SetParam("-m", moduleName);
2315     HapModuleInfo hapModuleInfo;
2316     hapModuleInfo.moduleName = moduleName;
2317     bundleInfo.hapModuleInfos.push_back(hapModuleInfo);
2318     appMgrServiceInner->StartUserTestProcess(want, observer, bundleInfo, 0);
2319 
2320     appMgrServiceInner->remoteClientManager_ = nullptr;
2321     appMgrServiceInner->StartUserTestProcess(want, observer, bundleInfo, 0);
2322 
2323     appMgrServiceInner->appRunningManager_ = nullptr;
2324     appMgrServiceInner->StartUserTestProcess(want, observer, bundleInfo, 0);
2325 
2326     TAG_LOGI(AAFwkTag::TEST, "StartUserTestProcess_001 end");
2327 }
2328 
2329 /**
2330  * @tc.name: GetHapModuleInfoForTestRunner_001
2331  * @tc.desc: get hap module info for test runner.
2332  * @tc.type: FUNC
2333  * @tc.require: issueI5W4S7
2334  */
2335 HWTEST_F(AppMgrServiceInnerTest, GetHapModuleInfoForTestRunner_001, TestSize.Level0)
2336 {
2337     TAG_LOGI(AAFwkTag::TEST, "GetHapModuleInfoForTestRunner_001 start");
2338     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2339     EXPECT_NE(appMgrServiceInner, nullptr);
2340 
2341     AAFwk::Want want;
2342     sptr<IRemoteObject> observer;
2343     BundleInfo bundleInfo;
2344     HapModuleInfo hapModuleInfo;
2345     appMgrServiceInner->GetHapModuleInfoForTestRunner(want, nullptr, bundleInfo, hapModuleInfo);
2346 
2347     appMgrServiceInner->GetHapModuleInfoForTestRunner(want, observer, bundleInfo, hapModuleInfo);
2348 
2349     hapModuleInfo.moduleName = "test_module_name";
2350     bundleInfo.hapModuleInfos.push_back(hapModuleInfo);
2351     appMgrServiceInner->GetHapModuleInfoForTestRunner(want, observer, bundleInfo, hapModuleInfo);
2352 
2353     bundleInfo.hapModuleInfos.back().isModuleJson = true;
2354     appMgrServiceInner->GetHapModuleInfoForTestRunner(want, observer, bundleInfo, hapModuleInfo);
2355 
2356     std::string testmoduleName = "test_XXX";
2357     want.SetParam("-m", testmoduleName);
2358     appMgrServiceInner->GetHapModuleInfoForTestRunner(want, observer, bundleInfo, hapModuleInfo);
2359 
2360     std::string moduleName = "test_module_name";
2361     want.SetParam("-m", moduleName);
2362     appMgrServiceInner->GetHapModuleInfoForTestRunner(want, observer, bundleInfo, hapModuleInfo);
2363 
2364     TAG_LOGI(AAFwkTag::TEST, "GetHapModuleInfoForTestRunner_001 end");
2365 }
2366 
2367 /**
2368  * @tc.name: UserTestAbnormalFinish_001
2369  * @tc.desc: user test abnormal finish.
2370  * @tc.type: FUNC
2371  * @tc.require: issueI5W4S7
2372  */
2373 HWTEST_F(AppMgrServiceInnerTest, UserTestAbnormalFinish_001, TestSize.Level0)
2374 {
2375     TAG_LOGI(AAFwkTag::TEST, "UserTestAbnormalFinish_001 start");
2376     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2377     EXPECT_NE(appMgrServiceInner, nullptr);
2378 
2379     sptr<IRemoteObject> observer;
2380     std::string msg = "testmsg";
2381     appMgrServiceInner->UserTestAbnormalFinish(nullptr, "");
2382     appMgrServiceInner->UserTestAbnormalFinish(nullptr, msg);
2383     appMgrServiceInner->UserTestAbnormalFinish(observer, "");
2384     appMgrServiceInner->UserTestAbnormalFinish(observer, msg);
2385 
2386     TAG_LOGI(AAFwkTag::TEST, "UserTestAbnormalFinish_001 end");
2387 }
2388 
2389 /**
2390  * @tc.name: StartEmptyProcess_001
2391  * @tc.desc: start empty process.
2392  * @tc.type: FUNC
2393  * @tc.require: issueI5W4S7
2394  */
2395 HWTEST_F(AppMgrServiceInnerTest, StartEmptyProcess_001, TestSize.Level0)
2396 {
2397     TAG_LOGI(AAFwkTag::TEST, "StartEmptyProcess_001 start");
2398     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2399     EXPECT_NE(appMgrServiceInner, nullptr);
2400 
2401     AAFwk::Want want;
2402     sptr<IRemoteObject> observer;
2403     BundleInfo info;
2404     HapModuleInfo hapModuleInfo;
2405     std::string processName = "test_processName";
2406     appMgrServiceInner->StartEmptyProcess(want, nullptr, info, "", 0);
2407     appMgrServiceInner->StartEmptyProcess(want, observer, info, "", 0);
2408     appMgrServiceInner->StartEmptyProcess(want, observer, info, processName, 0);
2409 
2410     info.applicationInfo = *applicationInfo_;
2411     appMgrServiceInner->StartEmptyProcess(want, observer, info, processName, 0);
2412 
2413     want.SetParam("coldStart", true);
2414     appMgrServiceInner->StartEmptyProcess(want, observer, info, processName, 0);
2415 
2416     appMgrServiceInner->remoteClientManager_ = nullptr;
2417     appMgrServiceInner->StartEmptyProcess(want, observer, info, processName, 0);
2418 
2419     appMgrServiceInner->appRunningManager_ = nullptr;
2420     appMgrServiceInner->StartEmptyProcess(want, observer, info, processName, 0);
2421 
2422     TAG_LOGI(AAFwkTag::TEST, "StartEmptyProcess_001 end");
2423 }
2424 
2425 /**
2426  * @tc.name: FinishUserTest_001
2427  * @tc.desc: finish user test.
2428  * @tc.type: FUNC
2429  * @tc.require: issueI5W4S7
2430  */
2431 HWTEST_F(AppMgrServiceInnerTest, FinishUserTest_001, TestSize.Level0)
2432 {
2433     TAG_LOGI(AAFwkTag::TEST, "FinishUserTest_001 start");
2434     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2435     EXPECT_NE(appMgrServiceInner, nullptr);
2436 
2437     pid_t pid = 0;
2438     appMgrServiceInner->FinishUserTest("", 0, "", pid);
2439 
2440     std::string msg = "testmsg";
2441     std::string bundleName = "test_bundle_name";
2442     appMgrServiceInner->FinishUserTest("", 0, bundleName, pid);
2443     appMgrServiceInner->FinishUserTest(msg, 0, "", pid);
2444     appMgrServiceInner->FinishUserTest(msg, 0, bundleName, pid);
2445 
2446     BundleInfo bundleInfo;
2447     HapModuleInfo hapModuleInfo;
2448     std::shared_ptr<AAFwk::Want> want;
2449     sptr<IRemoteObject> token = new MockAbilityToken();
2450     std::string processName = "test_processName";
2451     std::shared_ptr<AppRunningRecord> appRecord = appMgrServiceInner->CreateAppRunningRecord(token, nullptr,
2452         applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want, 0);
2453     EXPECT_NE(appRecord, nullptr);
2454     pid = appRecord->GetPriorityObject()->GetPid();
2455     appMgrServiceInner->FinishUserTest(msg, 0, bundleName, pid);
2456 
2457     std::shared_ptr<UserTestRecord> record = std::make_shared<UserTestRecord>();
2458     appRecord->SetUserTestInfo(record);
2459     appMgrServiceInner->FinishUserTest(msg, 0, bundleName, pid);
2460 
2461     appMgrServiceInner->appRunningManager_ = nullptr;
2462     appMgrServiceInner->FinishUserTest(msg, 0, bundleName, pid);
2463 
2464     TAG_LOGI(AAFwkTag::TEST, "FinishUserTest_001 end");
2465 }
2466 
2467 /**
2468  * @tc.name: FinishUserTestLocked_001
2469  * @tc.desc: finish user test locked.
2470  * @tc.type: FUNC
2471  * @tc.require: issueI5W4S7
2472  */
2473 HWTEST_F(AppMgrServiceInnerTest, FinishUserTestLocked_001, TestSize.Level0)
2474 {
2475     TAG_LOGI(AAFwkTag::TEST, "FinishUserTestLocked_001 start");
2476     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2477     EXPECT_NE(appMgrServiceInner, nullptr);
2478 
2479     appMgrServiceInner->FinishUserTestLocked("", 0, nullptr);
2480 
2481     std::shared_ptr<AppRunningRecord> appRecord;
2482     appMgrServiceInner->FinishUserTestLocked("", 0, appRecord);
2483 
2484     std::string msg = "testmsg";
2485     appMgrServiceInner->FinishUserTestLocked(msg, 0, nullptr);
2486     appMgrServiceInner->FinishUserTestLocked(msg, 0, appRecord);
2487 
2488     BundleInfo bundleInfo;
2489     std::string processName = "test_processName";
2490     appRecord =
2491         appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo);
2492     EXPECT_NE(appRecord, nullptr);
2493     std::shared_ptr<UserTestRecord> record = std::make_shared<UserTestRecord>();
2494     appRecord->SetUserTestInfo(record);
2495     appMgrServiceInner->FinishUserTestLocked(msg, 0, appRecord);
2496 
2497     record->isFinished = true;
2498     appRecord->SetUserTestInfo(record);
2499     appMgrServiceInner->FinishUserTestLocked(msg, 0, appRecord);
2500 
2501     record->observer = nullptr;
2502     appRecord->SetUserTestInfo(record);
2503     appMgrServiceInner->FinishUserTestLocked(msg, 0, appRecord);
2504 
2505     TAG_LOGI(AAFwkTag::TEST, "FinishUserTestLocked_001 end");
2506 }
2507 
2508 /**
2509  * @tc.name: StartSpecifiedAbility_001
2510  * @tc.desc: start specified ability.
2511  * @tc.type: FUNC
2512  * @tc.require: issueI5W4S7
2513  */
2514 HWTEST_F(AppMgrServiceInnerTest, StartSpecifiedAbility_001, TestSize.Level0)
2515 {
2516     TAG_LOGI(AAFwkTag::TEST, "StartSpecifiedAbility_001 start");
2517     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2518     EXPECT_NE(appMgrServiceInner, nullptr);
2519 
2520     AAFwk::Want want;
2521     AbilityInfo abilityInfo;
2522     appMgrServiceInner->StartSpecifiedAbility(want, abilityInfo);
2523 
2524     appMgrServiceInner->StartSpecifiedAbility(want, *abilityInfo_);
2525 
2526     abilityInfo_->applicationInfo = *applicationInfo_;
2527     appMgrServiceInner->StartSpecifiedAbility(want, *abilityInfo_);
2528 
2529     appMgrServiceInner->remoteClientManager_->SetBundleManagerHelper(nullptr);
2530     appMgrServiceInner->StartSpecifiedAbility(want, *abilityInfo_);
2531 
2532     appMgrServiceInner->remoteClientManager_ = nullptr;
2533     appMgrServiceInner->StartSpecifiedAbility(want, *abilityInfo_);
2534 
2535     TAG_LOGI(AAFwkTag::TEST, "StartSpecifiedAbility_001 end");
2536 }
2537 
2538 /**
2539  * @tc.name: RegisterStartSpecifiedAbilityResponse_001
2540  * @tc.desc: register start specified ability response.
2541  * @tc.type: FUNC
2542  * @tc.require: issueI5W4S7
2543  */
2544 HWTEST_F(AppMgrServiceInnerTest, RegisterStartSpecifiedAbilityResponse_001, TestSize.Level0)
2545 {
2546     TAG_LOGI(AAFwkTag::TEST, "RegisterStartSpecifiedAbilityResponse_001 start");
2547     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2548     EXPECT_NE(appMgrServiceInner, nullptr);
2549 
2550     appMgrServiceInner->RegisterStartSpecifiedAbilityResponse(nullptr);
2551 
2552     sptr<IStartSpecifiedAbilityResponse> response;
2553     appMgrServiceInner->RegisterStartSpecifiedAbilityResponse(response);
2554 
2555     TAG_LOGI(AAFwkTag::TEST, "RegisterStartSpecifiedAbilityResponse_001 end");
2556 }
2557 
2558 /**
2559  * @tc.name: ScheduleAcceptWantDone_001
2560  * @tc.desc: schedule accept want done.
2561  * @tc.type: FUNC
2562  * @tc.require: issueI5W4S7
2563  */
2564 HWTEST_F(AppMgrServiceInnerTest, ScheduleAcceptWantDone_001, TestSize.Level0)
2565 {
2566     TAG_LOGI(AAFwkTag::TEST, "ScheduleAcceptWantDone_001 start");
2567     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2568     EXPECT_NE(appMgrServiceInner, nullptr);
2569 
2570     AAFwk::Want want;
2571     std::string flag = "test_flag";
2572     appMgrServiceInner->ScheduleAcceptWantDone(0, want, flag);
2573 
2574     BundleInfo bundleInfo;
2575     std::string processName = "test_processName";
2576     std::shared_ptr<AppRunningRecord> appRecord =
2577         appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo);
2578     appMgrServiceInner->ScheduleAcceptWantDone(appRecord->GetRecordId(), want, flag);
2579 
2580     sptr<IStartSpecifiedAbilityResponse> response;
2581     appMgrServiceInner->RegisterStartSpecifiedAbilityResponse(response);
2582     appMgrServiceInner->ScheduleAcceptWantDone(appRecord->GetRecordId(), want, flag);
2583 
2584     TAG_LOGI(AAFwkTag::TEST, "ScheduleAcceptWantDone_001 end");
2585 }
2586 
2587 /**
2588  * @tc.name: HandleStartSpecifiedAbilityTimeOut_001
2589  * @tc.desc: handle start specified ability time out.
2590  * @tc.type: FUNC
2591  * @tc.require: issueI5W4S7
2592  */
2593 HWTEST_F(AppMgrServiceInnerTest, HandleStartSpecifiedAbilityTimeOut_001, TestSize.Level0)
2594 {
2595     TAG_LOGI(AAFwkTag::TEST, "HandleStartSpecifiedAbilityTimeOut_001 start");
2596     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2597     EXPECT_NE(appMgrServiceInner, nullptr);
2598 
2599     appMgrServiceInner->HandleStartSpecifiedAbilityTimeOut(0);
2600 
2601     BundleInfo bundleInfo;
2602     std::string appName = "test_appName";
2603     std::string processName = "test_processName";
2604     std::string bundleName = "test_bundleName";
2605     sptr<IRemoteObject> token = new MockAbilityToken();
2606     std::shared_ptr<AppRunningRecord> appRecord =
2607         appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo);
2608     EXPECT_NE(appRecord, nullptr);
2609     appRecord->eventId_ = 0;
2610     appMgrServiceInner->HandleStartSpecifiedAbilityTimeOut(0);
2611 
2612     appRecord->specifiedRequestId_ = 1;
2613     appMgrServiceInner->HandleStartSpecifiedAbilityTimeOut(0);
2614 
2615     sptr<IStartSpecifiedAbilityResponse> response;
2616     appMgrServiceInner->startSpecifiedAbilityResponse_ = response;
2617     appMgrServiceInner->HandleStartSpecifiedAbilityTimeOut(0);
2618 
2619     appRecord->specifiedRequestId_ = -1;
2620     appMgrServiceInner->HandleStartSpecifiedAbilityTimeOut(0);
2621 
2622     appMgrServiceInner->appRunningManager_ = nullptr;
2623     appMgrServiceInner->HandleStartSpecifiedAbilityTimeOut(0);
2624 
2625     TAG_LOGI(AAFwkTag::TEST, "HandleStartSpecifiedAbilityTimeOut_001 end");
2626 }
2627 
2628 /**
2629  * @tc.name: UpdateConfiguration_001
2630  * @tc.desc: update configuration.
2631  * @tc.type: FUNC
2632  * @tc.require: issueI5W4S7
2633  */
2634 HWTEST_F(AppMgrServiceInnerTest, UpdateConfiguration_001, TestSize.Level0)
2635 {
2636     TAG_LOGI(AAFwkTag::TEST, "UpdateConfiguration_001 start");
2637     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2638     EXPECT_NE(appMgrServiceInner, nullptr);
2639 
2640     Configuration config;
2641     appMgrServiceInner->UpdateConfiguration(config);
2642 
2643     auto testLanguge = "ch-zh";
2644     config.AddItem(AAFwk::GlobalConfigurationKey::SYSTEM_LANGUAGE, testLanguge);
2645     appMgrServiceInner->UpdateConfiguration(config);
2646 
2647     auto appRunningRecordMap = appMgrServiceInner->appRunningManager_->appRunningRecordMap_;
2648     for (const auto& item : appRunningRecordMap) {
2649         const auto& appRecord = item.second;
2650         if (appRecord) {
2651             appRecord->appLifeCycleDeal_ = nullptr;
2652         }
2653     }
2654     appMgrServiceInner->UpdateConfiguration(config);
2655 
2656     sptr<MockConfigurationObserver> observer(new (std::nothrow) MockConfigurationObserver());
2657     appMgrServiceInner->configurationObservers_.push_back({ observer, 100 });
2658     sptr<IConfigurationObserver> observer1;
2659     appMgrServiceInner->configurationObservers_.push_back({ observer1, 100 });
2660     appMgrServiceInner->configurationObservers_.push_back({ nullptr, 100 });
2661     appMgrServiceInner->UpdateConfiguration(config);
2662 
2663     appMgrServiceInner->appRunningManager_ = nullptr;
2664     appMgrServiceInner->UpdateConfiguration(config);
2665 
2666     TAG_LOGI(AAFwkTag::TEST, "UpdateConfiguration_001 end");
2667 }
2668 
2669 /**
2670  * @tc.name: RegisterConfigurationObserver_001
2671  * @tc.desc: register configuration observer.
2672  * @tc.type: FUNC
2673  * @tc.require: issueI5W4S7
2674  */
2675 HWTEST_F(AppMgrServiceInnerTest, RegisterConfigurationObserver_001, TestSize.Level0)
2676 {
2677     TAG_LOGI(AAFwkTag::TEST, "RegisterConfigurationObserver_001 start");
2678     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2679     EXPECT_NE(appMgrServiceInner, nullptr);
2680 
2681     appMgrServiceInner->configurationObservers_.clear();
2682 
2683     appMgrServiceInner->RegisterConfigurationObserver(nullptr);
2684 
2685     sptr<MockConfigurationObserver> observer(new (std::nothrow) MockConfigurationObserver());
2686     appMgrServiceInner->RegisterConfigurationObserver(observer);
2687     appMgrServiceInner->RegisterConfigurationObserver(observer);
2688 
2689     TAG_LOGI(AAFwkTag::TEST, "RegisterConfigurationObserver_001 end");
2690 }
2691 
2692 /**
2693  * @tc.name: UnregisterConfigurationObserver_001
2694  * @tc.desc: unregister configuration observer.
2695  * @tc.type: FUNC
2696  * @tc.require: issueI5W4S7
2697  */
2698 HWTEST_F(AppMgrServiceInnerTest, UnregisterConfigurationObserver_001, TestSize.Level0)
2699 {
2700     TAG_LOGI(AAFwkTag::TEST, "UnregisterConfigurationObserver_001 start");
2701     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2702     EXPECT_NE(appMgrServiceInner, nullptr);
2703 
2704     appMgrServiceInner->configurationObservers_.clear();
2705 
2706     appMgrServiceInner->UnregisterConfigurationObserver(nullptr);
2707 
2708     sptr<MockConfigurationObserver> observer(new (std::nothrow) MockConfigurationObserver());
2709     appMgrServiceInner->UnregisterConfigurationObserver(observer);
2710 
2711     appMgrServiceInner->RegisterConfigurationObserver(observer);
2712     appMgrServiceInner->UnregisterConfigurationObserver(observer);
2713 
2714     TAG_LOGI(AAFwkTag::TEST, "UnregisterConfigurationObserver_001 end");
2715 }
2716 
2717 /**
2718  * @tc.name: InitGlobalConfiguration_001
2719  * @tc.desc: init global configuration.
2720  * @tc.type: FUNC
2721  * @tc.require: issueI5W4S7
2722  */
2723 HWTEST_F(AppMgrServiceInnerTest, InitGlobalConfiguration_001, TestSize.Level0)
2724 {
2725     TAG_LOGI(AAFwkTag::TEST, "InitGlobalConfiguration_001 start");
2726     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2727     EXPECT_NE(appMgrServiceInner, nullptr);
2728 
2729     appMgrServiceInner->InitGlobalConfiguration();
2730 
2731     appMgrServiceInner->configuration_ = nullptr;
2732     appMgrServiceInner->InitGlobalConfiguration();
2733 
2734     TAG_LOGI(AAFwkTag::TEST, "InitGlobalConfiguration_001 end");
2735 }
2736 
2737 /**
2738  * @tc.name: KillApplicationByRecord_001
2739  * @tc.desc: kill application by record.
2740  * @tc.type: FUNC
2741  * @tc.require: issueI5W4S7
2742  */
2743 HWTEST_F(AppMgrServiceInnerTest, KillApplicationByRecord_001, TestSize.Level0)
2744 {
2745     TAG_LOGI(AAFwkTag::TEST, "KillApplicationByRecord_001 start");
2746     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2747     EXPECT_NE(appMgrServiceInner, nullptr);
2748 
2749     std::shared_ptr<AppRunningRecord> appRecord = nullptr;
2750     BundleInfo bundleInfo;
2751     std::string processName = "test_processName";
2752     std::shared_ptr<AppRunningRecord> appRecord1 =
2753         appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo);
2754     EXPECT_NE(appRecord1, nullptr);
2755     appMgrServiceInner->KillApplicationByRecord(appRecord);
2756     appMgrServiceInner->KillApplicationByRecord(appRecord1);
2757 
2758     appMgrServiceInner->taskHandler_ = nullptr;
2759     appMgrServiceInner->KillApplicationByRecord(appRecord);
2760     appMgrServiceInner->KillApplicationByRecord(appRecord1);
2761 
2762     TAG_LOGI(AAFwkTag::TEST, "KillApplicationByRecord_001 end");
2763 }
2764 
2765 /**
2766  * @tc.name: SendHiSysEvent_001
2767  * @tc.desc: send hi sys event.
2768  * @tc.type: FUNC
2769  * @tc.require: issueI5W4S7
2770  */
2771 HWTEST_F(AppMgrServiceInnerTest, SendHiSysEvent_001, TestSize.Level0)
2772 {
2773     TAG_LOGI(AAFwkTag::TEST, "SendHiSysEvent_001 start");
2774     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2775     EXPECT_NE(appMgrServiceInner, nullptr);
2776 
2777     appMgrServiceInner->SendHiSysEvent(0, 0);
2778 
2779     BundleInfo bundleInfo;
2780     std::string processName = "test_processName";
2781     std::shared_ptr<AppRunningRecord> appRecord =
2782         appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo);
2783     EXPECT_NE(appRecord, nullptr);
2784     appRecord->eventId_ = 0;
2785     appMgrServiceInner->SendHiSysEvent(0, 0);
2786     appMgrServiceInner->SendHiSysEvent(1, 0);
2787     appMgrServiceInner->SendHiSysEvent(2, 0);
2788     appMgrServiceInner->SendHiSysEvent(3, 0);
2789     appMgrServiceInner->SendHiSysEvent(4, 0);
2790 
2791     appMgrServiceInner->appRunningManager_ = nullptr;
2792     appMgrServiceInner->SendHiSysEvent(0, 0);
2793 
2794     TAG_LOGI(AAFwkTag::TEST, "SendHiSysEvent_001 end");
2795 }
2796 
2797 /**
2798  * @tc.name: GetAbilityRecordsByProcessID_001
2799  * @tc.desc: get ability records by process id.
2800  * @tc.type: FUNC
2801  * @tc.require: issueI5W4S7
2802  */
2803 HWTEST_F(AppMgrServiceInnerTest, GetAbilityRecordsByProcessID_001, TestSize.Level0)
2804 {
2805     TAG_LOGI(AAFwkTag::TEST, "GetAbilityRecordsByProcessID_001 start");
2806     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2807     EXPECT_NE(appMgrServiceInner, nullptr);
2808 
2809     std::vector<sptr<IRemoteObject>> tokens;
2810     appMgrServiceInner->GetAbilityRecordsByProcessID(0, tokens);
2811 
2812     BundleInfo bundleInfo;
2813     std::string processName = "test_processName";
2814     std::shared_ptr<AppRunningRecord> appRecord =
2815         appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo);
2816     EXPECT_NE(appRecord, nullptr);
2817     int pid = appRecord->GetPriorityObject()->GetPid();
2818     appMgrServiceInner->GetAbilityRecordsByProcessID(pid, tokens);
2819 
2820     TAG_LOGI(AAFwkTag::TEST, "GetAbilityRecordsByProcessID_001 end");
2821 }
2822 
2823 /**
2824  * @tc.name: GetApplicationInfoByProcessID_001
2825  * @tc.desc: get applicationInfo by process id.
2826  * @tc.type: FUNC
2827  * @tc.require: issueI5W4S7
2828  */
2829 HWTEST_F(AppMgrServiceInnerTest, GetApplicationInfoByProcessID_001, TestSize.Level0)
2830 {
2831     TAG_LOGI(AAFwkTag::TEST, "GetApplicationInfoByProcessID_001 start");
2832     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2833     EXPECT_NE(appMgrServiceInner, nullptr);
2834 
2835     ApplicationInfo application;
2836     bool debug = false;
2837     appMgrServiceInner->GetApplicationInfoByProcessID(0, application, debug);
2838 
2839     BundleInfo bundleInfo;
2840     std::string processName = "test_processName";
2841     std::shared_ptr<AppRunningRecord> appRecord =
2842         appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo);
2843     EXPECT_NE(appRecord, nullptr);
2844     int pid = appRecord->GetPriorityObject()->GetPid();
2845     appMgrServiceInner->GetApplicationInfoByProcessID(pid, application, debug);
2846 
2847     appRecord->appInfo_ = nullptr;
2848     appMgrServiceInner->GetApplicationInfoByProcessID(pid, application, debug);
2849 
2850     TAG_LOGI(AAFwkTag::TEST, "GetApplicationInfoByProcessID_001 end");
2851 }
2852 
2853 /**
2854  * @tc.name: NotifyAppMgrRecordExitReason_001
2855  * @tc.desc: NotifyAppMgrRecordExitReason.
2856  * @tc.type: FUNC
2857  * @tc.require: issueI5W4S7
2858  */
2859 HWTEST_F(AppMgrServiceInnerTest, NotifyAppMgrRecordExitReason_001, TestSize.Level0)
2860 {
2861     TAG_LOGI(AAFwkTag::TEST, "NotifyAppMgrRecordExitReason_001 start");
2862     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2863     EXPECT_NE(appMgrServiceInner, nullptr);
2864 
2865     int32_t reason = 0;
2866     int32_t pid = 1;
2867     std::string exitMsg = "JsError";
2868     auto ret = appMgrServiceInner->NotifyAppMgrRecordExitReason(reason, pid, exitMsg);
2869     EXPECT_NE(ret, ERR_OK);
2870     TAG_LOGI(AAFwkTag::TEST, "NotifyAppMgrRecordExitReason_001 end");
2871 }
2872 
2873 /**
2874  * @tc.name: VerifyKillProcessPermission_001
2875  * @tc.desc: verify process permission.
2876  * @tc.type: FUNC
2877  * @tc.require: issueI5W4S7
2878  */
2879 HWTEST_F(AppMgrServiceInnerTest, VerifyKillProcessPermission_001, TestSize.Level0)
2880 {
2881     TAG_LOGI(AAFwkTag::TEST, "VerifyKillProcessPermission_001 start");
2882     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2883     EXPECT_NE(appMgrServiceInner, nullptr);
2884 
2885     appMgrServiceInner->VerifyKillProcessPermission("");
2886 
2887     appMgrServiceInner->appRunningManager_ = nullptr;
2888     appMgrServiceInner->VerifyKillProcessPermission("");
2889 
2890     TAG_LOGI(AAFwkTag::TEST, "VerifyKillProcessPermission_001 end");
2891 }
2892 
2893 /**
2894  * @tc.name: VerifyAPL_001
2895  * @tc.desc: verify APL.
2896  * @tc.type: FUNC
2897  * @tc.require: issueI5W4S7
2898  */
2899 HWTEST_F(AppMgrServiceInnerTest, VerifyAPL_001, TestSize.Level0)
2900 {
2901     TAG_LOGI(AAFwkTag::TEST, "VerifyAPL_001 start");
2902     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2903     EXPECT_NE(appMgrServiceInner, nullptr);
2904 
2905     appMgrServiceInner->VerifyAPL();
2906 
2907     appMgrServiceInner->appRunningManager_ = nullptr;
2908     appMgrServiceInner->VerifyAPL();
2909 
2910     TAG_LOGI(AAFwkTag::TEST, "VerifyAPL_001 end");
2911 }
2912 
2913 /**
2914  * @tc.name: VerifyAccountPermission_001
2915  * @tc.desc: verify account permission.
2916  * @tc.type: FUNC
2917  * @tc.require: issueI5W4S7
2918  */
2919 HWTEST_F(AppMgrServiceInnerTest, VerifyAccountPermission_001, TestSize.Level0)
2920 {
2921     TAG_LOGI(AAFwkTag::TEST, "VerifyAccountPermission_001 start");
2922     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2923     EXPECT_NE(appMgrServiceInner, nullptr);
2924 
2925     std::string permissionName = "test_permissionName";
2926     appMgrServiceInner->VerifyAccountPermission(permissionName, 0);
2927 
2928     TAG_LOGI(AAFwkTag::TEST, "VerifyAccountPermission_001 end");
2929 }
2930 
2931 /**
2932  * @tc.name: PreStartNWebSpawnProcess_003
2933  * @tc.desc: prestart nwebspawn process.
2934  * @tc.type: FUNC
2935  * @tc.require: issueI5W4S7
2936  */
2937 HWTEST_F(AppMgrServiceInnerTest, PreStartNWebSpawnProcess_003, TestSize.Level0)
2938 {
2939     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2940     EXPECT_NE(appMgrServiceInner, nullptr);
2941 
2942     int callingPid = 1;
2943     appMgrServiceInner->remoteClientManager_->nwebSpawnClient_ = nullptr;
2944     int ret = appMgrServiceInner->PreStartNWebSpawnProcess(callingPid);
2945     EXPECT_EQ(ret, ERR_INVALID_VALUE);
2946 }
2947 
2948 /**
2949  * @tc.name: StartRenderProcess_001
2950  * @tc.desc: start render process.
2951  * @tc.type: FUNC
2952  * @tc.require: issueI5W4S7
2953  */
2954 HWTEST_F(AppMgrServiceInnerTest, StartRenderProcess_001, TestSize.Level0)
2955 {
2956     TAG_LOGI(AAFwkTag::TEST, "StartRenderProcess_001 start");
2957     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2958     EXPECT_NE(appMgrServiceInner, nullptr);
2959 
2960     pid_t hostPid = 0;
2961     std::string renderParam = "test_renderParam";
2962     pid_t renderPid = 0;
2963     int ret = appMgrServiceInner->StartRenderProcess(hostPid, "", 0, 0, 0, renderPid);
2964     EXPECT_EQ(ret, ERR_INVALID_VALUE);
2965     ret = appMgrServiceInner->StartRenderProcess(hostPid, "", 0, 0, 1, renderPid);
2966     EXPECT_EQ(ret, ERR_INVALID_VALUE);
2967     ret = appMgrServiceInner->StartRenderProcess(hostPid, "", 0, 1, 0, renderPid);
2968     EXPECT_EQ(ret, ERR_INVALID_VALUE);
2969     ret = appMgrServiceInner->StartRenderProcess(hostPid, "", 0, 1, 1, renderPid);
2970     EXPECT_EQ(ret, ERR_INVALID_VALUE);
2971     ret = appMgrServiceInner->StartRenderProcess(hostPid, "", 1, 0, 0, renderPid);
2972     EXPECT_EQ(ret, ERR_INVALID_VALUE);
2973     ret = appMgrServiceInner->StartRenderProcess(hostPid, "", 1, 0, 1, renderPid);
2974     EXPECT_EQ(ret, ERR_INVALID_VALUE);
2975     ret = appMgrServiceInner->StartRenderProcess(hostPid, "", 1, 1, 0, renderPid);
2976     EXPECT_EQ(ret, ERR_INVALID_VALUE);
2977     ret = appMgrServiceInner->StartRenderProcess(hostPid, "", 1, 1, 1, renderPid);
2978     EXPECT_EQ(ret, ERR_INVALID_VALUE);
2979     ret = appMgrServiceInner->StartRenderProcess(hostPid, renderParam, 0, 0, 0, renderPid);
2980     EXPECT_EQ(ret, ERR_INVALID_VALUE);
2981     ret = appMgrServiceInner->StartRenderProcess(hostPid, renderParam, 0, 0, 1, renderPid);
2982     EXPECT_EQ(ret, ERR_INVALID_VALUE);
2983     ret = appMgrServiceInner->StartRenderProcess(hostPid, renderParam, 0, 1, 0, renderPid);
2984     EXPECT_EQ(ret, ERR_INVALID_VALUE);
2985     ret = appMgrServiceInner->StartRenderProcess(hostPid, renderParam, 0, 1, 1, renderPid);
2986     EXPECT_EQ(ret, ERR_INVALID_VALUE);
2987     ret = appMgrServiceInner->StartRenderProcess(hostPid, renderParam, 1, 0, 0, renderPid);
2988     EXPECT_EQ(ret, ERR_INVALID_VALUE);
2989     ret = appMgrServiceInner->StartRenderProcess(hostPid, renderParam, 1, 0, 1, renderPid);
2990     EXPECT_EQ(ret, ERR_INVALID_VALUE);
2991     ret = appMgrServiceInner->StartRenderProcess(hostPid, renderParam, 1, 1, 0, renderPid);
2992     EXPECT_EQ(ret, ERR_INVALID_VALUE);
2993     ret = appMgrServiceInner->StartRenderProcess(hostPid, renderParam, 1, 1, 1, renderPid);
2994     EXPECT_EQ(ret, ERR_INVALID_VALUE);
2995 
2996     TAG_LOGI(AAFwkTag::TEST, "StartRenderProcess_001 end");
2997 }
2998 
2999 /**
3000  * @tc.name: StartRenderProcess_002
3001  * @tc.desc: start render process.
3002  * @tc.type: FUNC
3003  * @tc.require: issueI5W4S7
3004  */
3005 HWTEST_F(AppMgrServiceInnerTest, StartRenderProcess_002, TestSize.Level0)
3006 {
3007     TAG_LOGI(AAFwkTag::TEST, "StartRenderProcess_002 start");
3008     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
3009     EXPECT_NE(appMgrServiceInner, nullptr);
3010 
3011     pid_t hostPid1 = 1;
3012     std::string renderParam = "test_renderParam";
3013     pid_t renderPid = 0;
3014     int ret = appMgrServiceInner->StartRenderProcess(hostPid1, "", 0, 0, 0, renderPid);
3015     EXPECT_EQ(ret, ERR_INVALID_VALUE);
3016     ret = appMgrServiceInner->StartRenderProcess(hostPid1, "", 0, 0, 1, renderPid);
3017     EXPECT_EQ(ret, ERR_INVALID_VALUE);
3018     ret = appMgrServiceInner->StartRenderProcess(hostPid1, "", 0, 1, 0, renderPid);
3019     EXPECT_EQ(ret, ERR_INVALID_VALUE);
3020     ret = appMgrServiceInner->StartRenderProcess(hostPid1, "", 0, 1, 1, renderPid);
3021     EXPECT_EQ(ret, ERR_INVALID_VALUE);
3022     ret = appMgrServiceInner->StartRenderProcess(hostPid1, "", 1, 0, 0, renderPid);
3023     EXPECT_EQ(ret, ERR_INVALID_VALUE);
3024     ret = appMgrServiceInner->StartRenderProcess(hostPid1, "", 1, 0, 1, renderPid);
3025     EXPECT_EQ(ret, ERR_INVALID_VALUE);
3026     ret = appMgrServiceInner->StartRenderProcess(hostPid1, "", 1, 1, 0, renderPid);
3027     EXPECT_EQ(ret, ERR_INVALID_VALUE);
3028     ret = appMgrServiceInner->StartRenderProcess(hostPid1, "", 1, 1, 1, renderPid);
3029     EXPECT_EQ(ret, ERR_INVALID_VALUE);
3030     ret = appMgrServiceInner->StartRenderProcess(hostPid1, renderParam, 0, 0, 0, renderPid);
3031     EXPECT_EQ(ret, ERR_INVALID_VALUE);
3032     ret = appMgrServiceInner->StartRenderProcess(hostPid1, renderParam, 0, 0, 1, renderPid);
3033     EXPECT_EQ(ret, ERR_INVALID_VALUE);
3034     ret = appMgrServiceInner->StartRenderProcess(hostPid1, renderParam, 0, 1, 0, renderPid);
3035     EXPECT_EQ(ret, ERR_INVALID_VALUE);
3036 
3037     ret = appMgrServiceInner->StartRenderProcess(hostPid1, renderParam, 0, 1, 1, renderPid);
3038     EXPECT_EQ(ret, ERR_INVALID_VALUE);
3039 
3040     ret = appMgrServiceInner->StartRenderProcess(hostPid1, renderParam, 1, 0, 0, renderPid);
3041     EXPECT_EQ(ret, ERR_INVALID_VALUE);
3042     ret = appMgrServiceInner->StartRenderProcess(hostPid1, renderParam, 1, 0, 1, renderPid);
3043     EXPECT_EQ(ret, ERR_INVALID_VALUE);
3044     ret = appMgrServiceInner->StartRenderProcess(hostPid1, renderParam, 1, 1, 0, renderPid);
3045     EXPECT_EQ(ret, ERR_INVALID_VALUE);
3046 
3047     ret = appMgrServiceInner->StartRenderProcess(hostPid1, renderParam, 1, 1, 1, renderPid);
3048     EXPECT_EQ(ret, ERR_INVALID_VALUE);
3049     TAG_LOGI(AAFwkTag::TEST, "StartRenderProcess_002 end");
3050 }
3051 
3052 /**
3053  * @tc.name: AttachRenderProcess_001
3054  * @tc.desc: attach render process.
3055  * @tc.type: FUNC
3056  */
3057 HWTEST_F(AppMgrServiceInnerTest, AttachRenderProcess_001, TestSize.Level0)
3058 {
3059     TAG_LOGI(AAFwkTag::TEST, "AttachRenderProcess_001 start");
3060     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
3061     EXPECT_NE(appMgrServiceInner, nullptr);
3062 
3063     pid_t pid = 0;
3064     sptr<IRenderScheduler> scheduler;
3065     appMgrServiceInner->AttachRenderProcess(pid, scheduler);
3066     TAG_LOGI(AAFwkTag::TEST, "AttachRenderProcess_001 end");
3067 }
3068 
3069 /**
3070  * @tc.name: AttachRenderProcess_002
3071  * @tc.desc: attach render process.
3072  * @tc.type: FUNC
3073  */
3074 HWTEST_F(AppMgrServiceInnerTest, AttachRenderProcess_002, TestSize.Level0)
3075 {
3076     TAG_LOGI(AAFwkTag::TEST, "AttachRenderProcess_002 start");
3077     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
3078     EXPECT_NE(appMgrServiceInner, nullptr);
3079 
3080     pid_t pid = 1;
3081     sptr<IRenderScheduler> scheduler;
3082     appMgrServiceInner->AttachRenderProcess(pid, scheduler);
3083     TAG_LOGI(AAFwkTag::TEST, "AttachRenderProcess_002 end");
3084 }
3085 
3086 #ifdef WITH_DLP
3087 /**
3088  * @tc.name: BuildStartFlags_001
3089  * @tc.desc: build start flags.
3090  * @tc.type: FUNC
3091  * @tc.require: issueI5W4S7
3092  */
3093 HWTEST_F(AppMgrServiceInnerTest, BuildStartFlags_001, TestSize.Level0)
3094 {
3095     TAG_LOGI(AAFwkTag::TEST, "BuildStartFlags_001 start");
3096 
3097     AAFwk::Want want;
3098     AbilityInfo abilityInfo;
3099     AppspawnUtil::BuildStartFlags(want, abilityInfo);
3100 
3101     want.SetParam("coldStart", true);
3102     want.SetParam("ohos.dlp.params.index", 1);
3103     abilityInfo.extensionAbilityType = ExtensionAbilityType::BACKUP;
3104     uint32_t result = AppspawnUtil::BuildStartFlags(want, abilityInfo);
3105     EXPECT_EQ(result, 7);
3106 
3107     TAG_LOGI(AAFwkTag::TEST, "BuildStartFlags_001 end");
3108 }
3109 #endif // WITH_DLP
3110 
3111 /**
3112  * @tc.name: RegisterFocusListener_001
3113  * @tc.desc: register focus listener.
3114  * @tc.type: FUNC
3115  * @tc.require: issueI5W4S7
3116  */
3117 HWTEST_F(AppMgrServiceInnerTest, RegisterFocusListener_001, TestSize.Level0)
3118 {
3119     TAG_LOGI(AAFwkTag::TEST, "RegisterFocusListener_001 start");
3120     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
3121     EXPECT_NE(appMgrServiceInner, nullptr);
3122 
3123     appMgrServiceInner->RegisterFocusListener();
3124 
3125     appMgrServiceInner->focusListener_ = nullptr;
3126     appMgrServiceInner->RegisterFocusListener();
3127 
3128     TAG_LOGI(AAFwkTag::TEST, "RegisterFocusListener_001 end");
3129 }
3130 
3131 /**
3132  * @tc.name: HandleFocused_001
3133  * @tc.desc: handle focused.
3134  * @tc.type: FUNC
3135  * @tc.require: issueI5W4S7
3136  */
3137 HWTEST_F(AppMgrServiceInnerTest, HandleFocused_001, TestSize.Level0)
3138 {
3139     TAG_LOGI(AAFwkTag::TEST, "HandleFocused_001 start");
3140     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
3141     EXPECT_NE(appMgrServiceInner, nullptr);
3142 
3143     sptr<Rosen::FocusChangeInfo> focusChangeInfo;
3144     appMgrServiceInner->HandleFocused(focusChangeInfo);
3145 
3146     pid_t pid = 1;
3147     focusChangeInfo = new Rosen::FocusChangeInfo();
3148     appMgrServiceInner->HandleFocused(focusChangeInfo);
3149 
3150     focusChangeInfo->pid_ = pid;
3151     appMgrServiceInner->HandleFocused(focusChangeInfo);
3152 
3153     BundleInfo bundleInfo;
3154     std::string processName = "test_processName";
3155     std::shared_ptr<AppRunningRecord> appRecord =
3156         appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo);
3157     EXPECT_NE(appRecord, nullptr);
3158     appRecord->GetPriorityObject()->SetPid(pid);
3159     appMgrServiceInner->HandleFocused(focusChangeInfo);
3160 
3161     TAG_LOGI(AAFwkTag::TEST, "HandleFocused_001 end");
3162 }
3163 
3164 /**
3165  * @tc.name: HandleUnfocused_001
3166  * @tc.desc: handle unfocused.
3167  * @tc.type: FUNC
3168  * @tc.require: issueI5W4S7
3169  */
3170 HWTEST_F(AppMgrServiceInnerTest, HandleUnfocused_001, TestSize.Level0)
3171 {
3172     TAG_LOGI(AAFwkTag::TEST, "HandleUnfocused_001 start");
3173     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
3174     EXPECT_NE(appMgrServiceInner, nullptr);
3175 
3176     sptr<Rosen::FocusChangeInfo> focusChangeInfo;
3177     appMgrServiceInner->HandleUnfocused(focusChangeInfo);
3178 
3179     pid_t pid = 1;
3180     focusChangeInfo = new Rosen::FocusChangeInfo();
3181     appMgrServiceInner->HandleUnfocused(focusChangeInfo);
3182 
3183     focusChangeInfo->pid_ = pid;
3184     appMgrServiceInner->HandleUnfocused(focusChangeInfo);
3185 
3186     BundleInfo bundleInfo;
3187     std::string processName = "test_processName";
3188     std::shared_ptr<AppRunningRecord> appRecord =
3189         appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo);
3190     EXPECT_NE(appRecord, nullptr);
3191     appRecord->GetPriorityObject()->SetPid(pid);
3192     appMgrServiceInner->HandleUnfocused(focusChangeInfo);
3193 
3194     TAG_LOGI(AAFwkTag::TEST, "HandleUnfocused_001 end");
3195 }
3196 
3197 /**
3198  * @tc.name: GetAppRunningStateByBundleName_001
3199  * @tc.desc: get app running state by bundle name.
3200  * @tc.type: FUNC
3201  * @tc.require: issueI5W4S7
3202  */
3203 HWTEST_F(AppMgrServiceInnerTest, GetAppRunningStateByBundleName_001, TestSize.Level0)
3204 {
3205     TAG_LOGI(AAFwkTag::TEST, "GetAppRunningStateByBundleName_001 start");
3206     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
3207     EXPECT_NE(appMgrServiceInner, nullptr);
3208 
3209     std::string bundleName = "test_bundleName";
3210     appMgrServiceInner->GetAppRunningStateByBundleName(bundleName);
3211 
3212     appMgrServiceInner->appRunningManager_ = nullptr;
3213     appMgrServiceInner->GetAppRunningStateByBundleName(bundleName);
3214 
3215     TAG_LOGI(AAFwkTag::TEST, "GetAppRunningStateByBundleName_001 end");
3216 }
3217 
3218 /**
3219  * @tc.name: NotifyLoadRepairPatch_001
3220  * @tc.desc: notify load repair patch.
3221  * @tc.type: FUNC
3222  * @tc.require: issueI5W4S7
3223  */
3224 HWTEST_F(AppMgrServiceInnerTest, NotifyLoadRepairPatch_001, TestSize.Level0)
3225 {
3226     TAG_LOGI(AAFwkTag::TEST, "NotifyLoadRepairPatch_001 start");
3227     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
3228     EXPECT_NE(appMgrServiceInner, nullptr);
3229 
3230     std::string bundleName = "test_bundleName";
3231     sptr<IQuickFixCallback> callback;
3232     appMgrServiceInner->NotifyLoadRepairPatch(bundleName, callback);
3233 
3234     appMgrServiceInner->appRunningManager_ = nullptr;
3235     appMgrServiceInner->NotifyLoadRepairPatch(bundleName, callback);
3236 
3237     TAG_LOGI(AAFwkTag::TEST, "NotifyLoadRepairPatch_001 end");
3238 }
3239 
3240 /**
3241  * @tc.name: NotifyHotReloadPage_001
3242  * @tc.desc: notify hot reload page.
3243  * @tc.type: FUNC
3244  * @tc.require: issueI5W4S7
3245  */
3246 HWTEST_F(AppMgrServiceInnerTest, NotifyHotReloadPage_001, TestSize.Level0)
3247 {
3248     TAG_LOGI(AAFwkTag::TEST, "NotifyHotReloadPage_001 start");
3249     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
3250     EXPECT_NE(appMgrServiceInner, nullptr);
3251 
3252     std::string bundleName = "test_bundleName";
3253     sptr<IQuickFixCallback> callback;
3254     appMgrServiceInner->NotifyHotReloadPage(bundleName, callback);
3255 
3256     appMgrServiceInner->appRunningManager_ = nullptr;
3257     appMgrServiceInner->NotifyHotReloadPage(bundleName, callback);
3258 
3259     TAG_LOGI(AAFwkTag::TEST, "NotifyHotReloadPage_001 end");
3260 }
3261 
3262 /**
3263  * @tc.name: SetContinuousTaskProcess_001
3264  * @tc.desc: set continuous task process.
3265  * @tc.type: FUNC
3266  * @tc.require: issueI5W4S7
3267  */
3268 #ifdef BGTASKMGR_CONTINUOUS_TASK_ENABLE
3269 HWTEST_F(AppMgrServiceInnerTest, SetContinuousTaskProcess_001, TestSize.Level0)
3270 {
3271     TAG_LOGI(AAFwkTag::TEST, "SetContinuousTaskProcess_001 start");
3272     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
3273     EXPECT_NE(appMgrServiceInner, nullptr);
3274 
3275     int32_t ret = appMgrServiceInner->SetContinuousTaskProcess(0, true);
3276     EXPECT_EQ(ret, ERR_INVALID_VALUE);
3277 
3278     BundleInfo bundleInfo;
3279     std::string processName = "test_processName";
3280     std::shared_ptr<AppRunningRecord> appRecord =
3281         appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo);
3282     EXPECT_NE(appRecord, nullptr);
3283     appRecord->GetPriorityObject()->SetPid(0);
3284     ret = appMgrServiceInner->SetContinuousTaskProcess(0, true);
3285     EXPECT_EQ(ret, 0);
3286 
3287     appMgrServiceInner->appRunningManager_ = nullptr;
3288     ret = appMgrServiceInner->SetContinuousTaskProcess(0, true);
3289     EXPECT_EQ(ret, ERR_INVALID_OPERATION);
3290 
3291     TAG_LOGI(AAFwkTag::TEST, "SetContinuousTaskProcess_001 end");
3292 }
3293 #endif
3294 
3295 /**
3296  * @tc.name: NotifyUnLoadRepairPatch_001
3297  * @tc.desc: notify unload repair patch.
3298  * @tc.type: FUNC
3299  * @tc.require: issueI5W4S7
3300  */
3301 HWTEST_F(AppMgrServiceInnerTest, NotifyUnLoadRepairPatch_001, TestSize.Level0)
3302 {
3303     TAG_LOGI(AAFwkTag::TEST, "NotifyUnLoadRepairPatch_001 start");
3304     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
3305     EXPECT_NE(appMgrServiceInner, nullptr);
3306 
3307     std::string bundleName = "test_bundleName";
3308     sptr<IQuickFixCallback> callback;
3309     appMgrServiceInner->NotifyUnLoadRepairPatch(bundleName, callback);
3310 
3311     appMgrServiceInner->appRunningManager_ = nullptr;
3312     appMgrServiceInner->NotifyUnLoadRepairPatch(bundleName, callback);
3313 
3314     TAG_LOGI(AAFwkTag::TEST, "NotifyUnLoadRepairPatch_001 end");
3315 }
3316 
3317 /**
3318  * @tc.name: SetCurrentUserId_001
3319  * @tc.desc: set current userId.
3320  * @tc.type: FUNC
3321  */
3322 HWTEST_F(AppMgrServiceInnerTest, SetCurrentUserId_001, TestSize.Level0)
3323 {
3324     TAG_LOGI(AAFwkTag::TEST, "SetCurrentUserId_001 start");
3325     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
3326     EXPECT_NE(appMgrServiceInner, nullptr);
3327 
3328     int userId = 0;
3329     appMgrServiceInner->SetCurrentUserId(userId);
3330     EXPECT_EQ(appMgrServiceInner->currentUserId_, userId);
3331 
3332     TAG_LOGI(AAFwkTag::TEST, "SetCurrentUserId_001 end");
3333 }
3334 
3335 /**
3336  * @tc.name: GetProcessMemoryByPid_001
3337  * @tc.desc: Get memorySize by pid.
3338  * @tc.type: FUNC
3339  * @tc.require: issueI76JBF
3340  */
3341 HWTEST_F(AppMgrServiceInnerTest, GetProcessMemoryByPid_001, TestSize.Level0)
3342 {
3343     TAG_LOGI(AAFwkTag::TEST, "GetProcessMemoryByPid_001 start");
3344     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
3345     EXPECT_NE(appMgrServiceInner, nullptr);
3346 
3347     int32_t pid = 0;
3348     int32_t memorySize = 0;
3349     int32_t ret = appMgrServiceInner->GetProcessMemoryByPid(pid, memorySize);
3350     EXPECT_EQ(ret, ERR_OK);
3351 
3352     TAG_LOGI(AAFwkTag::TEST, "GetProcessMemoryByPid_001 end");
3353 }
3354 
3355 /**
3356  * @tc.name: GetRunningProcessInformation_001
3357  * @tc.desc: Get application processes information list by bundleName.
3358  * @tc.type: FUNC
3359  * @tc.require: issueI76JBF
3360  */
3361 HWTEST_F(AppMgrServiceInnerTest, GetRunningProcessInformation_001, TestSize.Level0)
3362 {
3363     TAG_LOGI(AAFwkTag::TEST, "GetRunningProcessInformation_001 start");
3364     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
3365     EXPECT_NE(appMgrServiceInner, nullptr);
3366 
3367     std::string bundleName = "testBundleName";
3368     int32_t userId = 100;
3369     std::vector<RunningProcessInfo> info;
3370     int32_t ret = appMgrServiceInner->GetRunningProcessInformation(bundleName, userId, info);
3371     EXPECT_EQ(ret, ERR_OK);
3372 
3373     appMgrServiceInner->remoteClientManager_ = nullptr;
3374     ret = appMgrServiceInner->GetRunningProcessInformation(bundleName, userId, info);
3375     EXPECT_EQ(ret, ERR_NO_INIT);
3376 
3377     appMgrServiceInner->appRunningManager_ = nullptr;
3378     ret = appMgrServiceInner->GetRunningProcessInformation(bundleName, userId, info);
3379     EXPECT_EQ(ret, ERR_NO_INIT);
3380 
3381     TAG_LOGI(AAFwkTag::TEST, "GetRunningProcessInformation_001 end");
3382 }
3383 
3384 /**
3385  * @tc.name: GetBundleNameByPid_001
3386  * @tc.desc: get bundle name by Pid.
3387  * @tc.type: FUNC
3388  */
3389 HWTEST_F(AppMgrServiceInnerTest, GetBundleNameByPid_001, TestSize.Level1)
3390 {
3391     TAG_LOGI(AAFwkTag::TEST, "GetBundleNameByPid_001 start");
3392 
3393     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
3394     EXPECT_NE(appMgrServiceInner, nullptr);
3395     int32_t pid = 0;
3396     std::string name = "test_name";
3397     int32_t uid = 0;
3398     auto ret  = appMgrServiceInner->GetBundleNameByPid(pid, name, uid);
3399     EXPECT_EQ(ret, ERR_INVALID_OPERATION);
3400 
3401     TAG_LOGI(AAFwkTag::TEST, "GetBundleNameByPid_001 end");
3402 }
3403 
3404 /**
3405  * @tc.name: GetBundleNameByPid_002
3406  * @tc.desc: get bundle name by Pid.
3407  * @tc.type: FUNC
3408  */
3409 HWTEST_F(AppMgrServiceInnerTest, GetBundleNameByPid_002, TestSize.Level1)
3410 {
3411     TAG_LOGI(AAFwkTag::TEST, "GetBundleNameByPid_002 start");
3412 
3413     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
3414     EXPECT_NE(appMgrServiceInner, nullptr);
3415     BundleInfo info;
3416     std::string processName = "test_processName";
3417     appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info);
3418     int32_t pid = 0;
3419     std::string name = "test_name";
3420     int32_t uid = 0;
3421     auto ret  = appMgrServiceInner->GetBundleNameByPid(pid, name, uid);
3422     EXPECT_EQ(ret, ERR_OK);
3423 
3424     TAG_LOGI(AAFwkTag::TEST, "GetBundleNameByPid_002 end");
3425 }
3426 
3427 /**
3428  * @tc.name: AppRecoveryNotifyApp_001
3429  * @tc.desc: AppRecovery NotifyApp.
3430  * @tc.type: FUNC
3431  */
3432 HWTEST_F(AppMgrServiceInnerTest, AppRecoveryNotifyApp_001, TestSize.Level1)
3433 {
3434     TAG_LOGI(AAFwkTag::TEST, "AppRecoveryNotifyApp_001 start");
3435     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
3436     EXPECT_NE(appMgrServiceInner, nullptr);
3437     int32_t pid = 0;
3438     std::string bundleName = "com.is.hiserice";
3439     appMgrServiceInner->AppRecoveryNotifyApp(pid, bundleName, FaultDataType::RESOURCE_CONTROL, "appRecovery");
3440     appMgrServiceInner->AppRecoveryNotifyApp(pid, bundleName, FaultDataType::APP_FREEZE, "recovery");
3441     TAG_LOGI(AAFwkTag::TEST, "AppRecoveryNotifyApp_001 end");
3442 }
3443 
3444 /**
3445  * @tc.name: NotifyAppFault_001
3446  * @tc.desc: Notify AppFault.
3447  * @tc.type: FUNC
3448  */
3449 HWTEST_F(AppMgrServiceInnerTest, NotifyAppFault_001, TestSize.Level1)
3450 {
3451     TAG_LOGI(AAFwkTag::TEST, "NotifyAppFault_001 start");
3452     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
3453     EXPECT_NE(appMgrServiceInner, nullptr);
3454     FaultData faultData1;
3455     faultData1.errorObject.name = "1234";
3456     faultData1.timeoutMarkers = "456";
3457     int32_t ret1 = appMgrServiceInner->NotifyAppFault(faultData1);
3458     EXPECT_EQ(ret1, ERR_INVALID_VALUE);
3459 }
3460 
3461 /**
3462  * @tc.name: TimeoutNotifyApp_001
3463  * @tc.desc: Timeout Notify App.
3464  * @tc.type: FUNC
3465  */
3466 HWTEST_F(AppMgrServiceInnerTest, TimeoutNotifyApp_001, TestSize.Level1)
3467 {
3468     TAG_LOGI(AAFwkTag::TEST, "TimeoutNotifyApp_001 start");
3469     std::shared_ptr<AppMgrServiceInner> appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
3470     EXPECT_NE(appMgrServiceInner, nullptr);
3471     std::shared_ptr<MockTaskHandlerWrap> taskHandler = MockTaskHandlerWrap::CreateQueueHandler("app_mgr_task_queue");
3472     EXPECT_CALL(*taskHandler, SubmitTaskInner(_, _)).Times(AtLeast(1));
3473     appMgrServiceInner->SetTaskHandler(taskHandler);
3474 
3475     int32_t pid = 0;
3476     int32_t uid = 0;
3477     std::string bundleName = "test_processName";
3478     std::string processName = "test_processName";
3479     FaultData faultData;
3480     faultData.errorObject.name = "1234";
3481     faultData.faultType = FaultDataType::APP_FREEZE;
3482     appMgrServiceInner->TimeoutNotifyApp(pid, uid, bundleName, processName, faultData);
3483     EXPECT_NE(taskHandler, nullptr);
3484     TAG_LOGI(AAFwkTag::TEST, "TimeoutNotifyApp_001 end");
3485 }
3486 
3487 /**
3488  * @tc.name: NotifyAppFaultBySA_001
3489  * @tc.desc: Notify Fault Data By SA
3490  * @tc.type: FUNC
3491  */
3492 HWTEST_F(AppMgrServiceInnerTest, NotifyAppFaultBySA_001, TestSize.Level1)
3493 {
3494     TAG_LOGI(AAFwkTag::TEST, "NotifyAppFaultBySA_001 start");
3495     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
3496     EXPECT_NE(appMgrServiceInner, nullptr);
3497     AppFaultDataBySA faultData;
3498     faultData.pid = 8142;
3499     faultData.errorObject.name = "appRecovery";
3500     int32_t ret = appMgrServiceInner->NotifyAppFaultBySA(faultData);
3501     EXPECT_EQ(ret, ERR_INVALID_VALUE);
3502     TAG_LOGI(AAFwkTag::TEST, "NotifyAppFaultBySA_001 end");
3503 }
3504 
3505 /**
3506  * @tc.name: RegisterAppDebugListener_001
3507  * @tc.desc: Test the status of RegisterAppDebugListener.
3508  * @tc.type: FUNC
3509  */
3510 HWTEST_F(AppMgrServiceInnerTest, RegisterAppDebugListener_001, TestSize.Level0)
3511 {
3512     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
3513     EXPECT_NE(appMgrServiceInner, nullptr);
3514     sptr<IAppDebugListener> listener = nullptr;
3515     appMgrServiceInner->appDebugManager_ = std::make_shared<AppDebugManager>();
3516     auto result = appMgrServiceInner->RegisterAppDebugListener(listener);
3517     EXPECT_EQ(result, ERR_INVALID_DATA);
3518     appMgrServiceInner->appDebugManager_ = nullptr;
3519     result = appMgrServiceInner->RegisterAppDebugListener(listener);
3520     EXPECT_EQ(result, ERR_NO_INIT);
3521 }
3522 
3523 /**
3524  * @tc.name: UnregisterAppDebugListener_001
3525  * @tc.desc: Test the status of UnregisterAppDebugListener.
3526  * @tc.type: FUNC
3527  */
3528 HWTEST_F(AppMgrServiceInnerTest, UnregisterAppDebugListener_001, TestSize.Level0)
3529 {
3530     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
3531     EXPECT_NE(appMgrServiceInner, nullptr);
3532     sptr<IAppDebugListener> listener = nullptr;
3533     appMgrServiceInner->appDebugManager_ = std::make_shared<AppDebugManager>();
3534     auto result = appMgrServiceInner->UnregisterAppDebugListener(listener);
3535     EXPECT_EQ(result, ERR_INVALID_DATA);
3536     appMgrServiceInner->appDebugManager_ = nullptr;
3537     result = appMgrServiceInner->UnregisterAppDebugListener(listener);
3538     EXPECT_EQ(result, ERR_NO_INIT);
3539 }
3540 
3541 /**
3542  * @tc.name: AttachAppDebug_001
3543  * @tc.desc: Test the status of AttachAppDebug.
3544  * @tc.type: FUNC
3545  */
3546 HWTEST_F(AppMgrServiceInnerTest, AttachAppDebug_001, TestSize.Level0)
3547 {
3548     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
3549     EXPECT_NE(appMgrServiceInner, nullptr);
3550     std::string bundleName;
3551     appMgrServiceInner->appRunningManager_ = std::make_shared<AppRunningManager>();
3552     appMgrServiceInner->appDebugManager_ = std::make_shared<AppDebugManager>();
3553     auto result = appMgrServiceInner->AttachAppDebug(bundleName);
3554     EXPECT_EQ(result, ERR_OK);
3555 }
3556 
3557 /**
3558  * @tc.name: AttachAppDebug_002
3559  * @tc.desc: Test the status of AttachAppDebug, check nullptr AppRunningManager.
3560  * @tc.type: FUNC
3561  */
3562 HWTEST_F(AppMgrServiceInnerTest, AttachAppDebug_002, TestSize.Level0)
3563 {
3564     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
3565     EXPECT_NE(appMgrServiceInner, nullptr);
3566     std::string bundleName;
3567     appMgrServiceInner->appRunningManager_ = nullptr;
3568     appMgrServiceInner->appDebugManager_ = std::make_shared<AppDebugManager>();
3569     auto result = appMgrServiceInner->AttachAppDebug(bundleName);
3570     EXPECT_EQ(result, ERR_NO_INIT);
3571 }
3572 
3573 /**
3574  * @tc.name: DetachAppDebug_001
3575  * @tc.desc: Test the status of DetachAppDebug.
3576  * @tc.type: FUNC
3577  */
3578 HWTEST_F(AppMgrServiceInnerTest, DetachAppDebug_001, TestSize.Level0)
3579 {
3580     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
3581     EXPECT_NE(appMgrServiceInner, nullptr);
3582     std::string bundleName;
3583     appMgrServiceInner->appRunningManager_ = std::make_shared<AppRunningManager>();
3584     appMgrServiceInner->appDebugManager_ = std::make_shared<AppDebugManager>();
3585     auto result = appMgrServiceInner->DetachAppDebug(bundleName);
3586     EXPECT_EQ(result, ERR_OK);
3587 }
3588 
3589 /**
3590  * @tc.name: DetachAppDebug_002
3591  * @tc.desc: Test the status of DetachAppDebug, check nullptr AppRunningManager.
3592  * @tc.type: FUNC
3593  */
3594 HWTEST_F(AppMgrServiceInnerTest, DetachAppDebug_002, TestSize.Level0)
3595 {
3596     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
3597     EXPECT_NE(appMgrServiceInner, nullptr);
3598     std::string bundleName;
3599     appMgrServiceInner->appRunningManager_ = nullptr;
3600     appMgrServiceInner->appDebugManager_ = std::make_shared<AppDebugManager>();
3601     auto result = appMgrServiceInner->DetachAppDebug(bundleName);
3602     EXPECT_EQ(result, ERR_NO_INIT);
3603 }
3604 
3605 /**
3606  * @tc.name: SetAppWaitingDebug_001
3607  * @tc.desc: Test function SetAppWaitingDebug.
3608  * @tc.type: FUNC
3609  */
3610 HWTEST_F(AppMgrServiceInnerTest, SetAppWaitingDebug_001, TestSize.Level0)
3611 {
3612     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
3613     EXPECT_NE(appMgrServiceInner, nullptr);
3614     std::string bundleName("test");
3615     auto result = appMgrServiceInner->SetAppWaitingDebug(bundleName, false);
3616     EXPECT_EQ(result, ERR_PERMISSION_DENIED);
3617 }
3618 
3619 /**
3620  * @tc.name: CancelAppWaitingDebug_001
3621  * @tc.desc: Test function CancelAppWaitingDebug.
3622  * @tc.type: FUNC
3623  */
3624 HWTEST_F(AppMgrServiceInnerTest, CancelAppWaitingDebug_001, TestSize.Level0)
3625 {
3626     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
3627     EXPECT_NE(appMgrServiceInner, nullptr);
3628     auto result = appMgrServiceInner->CancelAppWaitingDebug();
3629     EXPECT_EQ(result, ERR_PERMISSION_DENIED);
3630 }
3631 
3632 /**
3633  * @tc.name: GetWaitingDebugApp_001
3634  * @tc.desc: Test function GetWaitingDebugApp.
3635  * @tc.type: FUNC
3636  */
3637 HWTEST_F(AppMgrServiceInnerTest, GetWaitingDebugApp_001, TestSize.Level0)
3638 {
3639     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
3640     EXPECT_NE(appMgrServiceInner, nullptr);
3641     std::vector<std::string> debugInfoList;
3642     auto result = appMgrServiceInner->GetWaitingDebugApp(debugInfoList);
3643     EXPECT_EQ(result, ERR_PERMISSION_DENIED);
3644 }
3645 
3646 /**
3647  * @tc.name: RegisterAbilityDebugResponse_001
3648  * @tc.desc: Test the status of RegisterAbilityDebugResponse.
3649  * @tc.type: FUNC
3650  */
3651 HWTEST_F(AppMgrServiceInnerTest, RegisterAbilityDebugResponse_001, TestSize.Level0)
3652 {
3653     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
3654     EXPECT_NE(appMgrServiceInner, nullptr);
3655     sptr<IAbilityDebugResponse> response = nullptr;
3656     appMgrServiceInner->RegisterAbilityDebugResponse(response);
3657     EXPECT_TRUE(appMgrServiceInner != nullptr);
3658 }
3659 
3660 /**
3661  * @tc.name: NotifyAbilitysDebugChange_001
3662  * @tc.desc: Test the status of NotifyAbilitysDebugChange.
3663  * @tc.type: FUNC
3664  */
3665 HWTEST_F(AppMgrServiceInnerTest, NotifyAbilitysDebugChange_001, TestSize.Level0)
3666 {
3667     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
3668     EXPECT_NE(appMgrServiceInner, nullptr);
3669     std::string bundleName;
3670     bool isAppDebug = true;
3671     appMgrServiceInner->appRunningManager_ = std::make_shared<AppRunningManager>();
3672     appMgrServiceInner->appDebugManager_ = std::make_shared<AppDebugManager>();
3673     auto result = appMgrServiceInner->NotifyAbilitysDebugChange(bundleName, isAppDebug);
3674     EXPECT_EQ(result, ERR_NO_INIT);
3675 }
3676 
3677 /**
3678  * @tc.name: ProcessAppDebug_001
3679  * @tc.desc: Test the status of ProcessAppDebug.
3680  * @tc.type: FUNC
3681  */
3682 HWTEST_F(AppMgrServiceInnerTest, ProcessAppDebug_001, TestSize.Level0)
3683 {
3684     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
3685     EXPECT_NE(appMgrServiceInner, nullptr);
3686     appMgrServiceInner->appRunningManager_ = std::make_shared<AppRunningManager>();
3687     std::shared_ptr<ApplicationInfo> info = std::make_shared<ApplicationInfo>();
3688     int32_t recordId = RECORD_ID;
3689     std::string processName = "processName";
3690     std::shared_ptr<AppRunningRecord> appRecord = std::make_shared<AppRunningRecord>(info, recordId, processName);
3691     bool isDebugStart = true;
3692     appRecord->SetDebugApp(false);
3693     appMgrServiceInner->ProcessAppDebug(appRecord, isDebugStart);
3694     EXPECT_EQ(appRecord->IsDebugApp(), true);
3695 }
3696 
3697 /**
3698  * @tc.name: MakeAppDebugInfo_001
3699  * @tc.desc: Test the status of MakeAppDebugInfo.
3700  * @tc.type: FUNC
3701  */
3702 HWTEST_F(AppMgrServiceInnerTest, MakeAppDebugInfo_001, TestSize.Level0)
3703 {
3704     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
3705     EXPECT_NE(appMgrServiceInner, nullptr);
3706     appMgrServiceInner->appRunningManager_ = std::make_shared<AppRunningManager>();
3707     std::shared_ptr<ApplicationInfo> info = std::make_shared<ApplicationInfo>();
3708     int32_t recordId = RECORD_ID;
3709     std::string processName = "processName";
3710     std::shared_ptr<AppRunningRecord> appRecord = std::make_shared<AppRunningRecord>(info, recordId, processName);
3711     bool isDebugStart = true;
3712     appRecord->SetDebugApp(false);
3713     auto appDebugInfo = appMgrServiceInner->MakeAppDebugInfo(appRecord, isDebugStart);
3714     EXPECT_EQ(appDebugInfo.bundleName, "");
3715     EXPECT_EQ(appDebugInfo.pid, APP_DEBUG_INFO_PID);
3716     EXPECT_EQ(appDebugInfo.isDebugStart, true);
3717 }
3718 
3719 /**
3720  * @tc.name: ChangeAppGcState_001
3721  * @tc.desc: Change app Gc state
3722  * @tc.type: FUNC
3723  */
3724 HWTEST_F(AppMgrServiceInnerTest, ChangeAppGcState_001, TestSize.Level1)
3725 {
3726     TAG_LOGI(AAFwkTag::TEST, "ChangeAppGcState_001 start");
3727     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
3728     EXPECT_NE(appMgrServiceInner, nullptr);
3729     int32_t pid = 0;
3730     int32_t state = 0;
3731     int32_t ret = appMgrServiceInner->ChangeAppGcState(pid, state);
3732     EXPECT_EQ(ret, ERR_INVALID_VALUE);
3733     TAG_LOGI(AAFwkTag::TEST, "ChangeAppGcState_001 end");
3734 }
3735 
3736 /**
3737  * @tc.name: SendReStartProcessEvent_001
3738  * @tc.desc: Change app Gc state
3739  * @tc.type: FUNC
3740  */
3741 HWTEST_F(AppMgrServiceInnerTest, SendReStartProcessEvent_001, TestSize.Level1)
3742 {
3743     TAG_LOGI(AAFwkTag::TEST, "SendReStartProcessEvent_001 start");
3744     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
3745     EXPECT_NE(appMgrServiceInner, nullptr);
3746     AAFwk::EventInfo eventInfo;
3747     appMgrServiceInner->SendReStartProcessEvent(eventInfo, 0);
3748     TAG_LOGI(AAFwkTag::TEST, "SendReStartProcessEvent_001 end");
3749 }
3750 
3751 /**
3752  * @tc.name: SendReStartProcessEvent_002
3753  * @tc.desc: Change app Gc state
3754  * @tc.type: FUNC
3755  */
3756 HWTEST_F(AppMgrServiceInnerTest, SendReStartProcessEvent_002, TestSize.Level1)
3757 {
3758     TAG_LOGI(AAFwkTag::TEST, "SendReStartProcessEvent_002 start");
3759     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
3760     EXPECT_NE(appMgrServiceInner, nullptr);
3761     AAFwk::EventInfo eventInfo;
3762     BundleInfo info;
3763     std::string processName = "test_processName";
3764     auto record = appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info);
3765     recordId_ += 1;
3766     int64_t restartTime = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::
3767         system_clock::now().time_since_epoch()).count();
3768     int64_t killedTime = restartTime - 3000;
3769     appMgrServiceInner->killedProcessMap_.emplace(killedTime, processName);
3770     appMgrServiceInner->SendReStartProcessEvent(eventInfo, record->GetUid());
3771     TAG_LOGI(AAFwkTag::TEST, "SendReStartProcessEvent_002 end");
3772 }
3773 
3774 /**
3775  * @tc.name: SendReStartProcessEvent_003
3776  * @tc.desc: Change app Gc state
3777  * @tc.type: FUNC
3778  */
3779 HWTEST_F(AppMgrServiceInnerTest, SendReStartProcessEvent_003, TestSize.Level1)
3780 {
3781     TAG_LOGI(AAFwkTag::TEST, "SendReStartProcessEvent_003 start");
3782     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
3783     EXPECT_NE(appMgrServiceInner, nullptr);
3784     AAFwk::EventInfo eventInfo;
3785     eventInfo.bundleName = "bundleName";
3786     eventInfo.callerBundleName = "callerBundleName";
3787     BundleInfo info;
3788     std::string processName = "test_processName";
3789     auto record = appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info);
3790     recordId_ += 1;
3791     int64_t restartTime = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::
3792         system_clock::now().time_since_epoch()).count();
3793     int64_t killedTime = restartTime - 1000;
3794     appMgrServiceInner->killedProcessMap_.emplace(killedTime, processName);
3795     appMgrServiceInner->SendReStartProcessEvent(eventInfo, record->GetUid());
3796     TAG_LOGI(AAFwkTag::TEST, "SendReStartProcessEvent_003 end");
3797 }
3798 
3799 /**
3800  * @tc.name: SendReStartProcessEvent_004
3801  * @tc.desc: Change app Gc state
3802  * @tc.type: FUNC
3803  */
3804 HWTEST_F(AppMgrServiceInnerTest, SendReStartProcessEvent_004, TestSize.Level1)
3805 {
3806     TAG_LOGI(AAFwkTag::TEST, "SendReStartProcessEvent_004 start");
3807     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
3808     EXPECT_NE(appMgrServiceInner, nullptr);
3809     AAFwk::EventInfo eventInfo;
3810     BundleInfo info;
3811     std::string processName = "test_processName";
3812     eventInfo.bundleName = "bundleName";
3813     eventInfo.callerBundleName = "bundleName";
3814     eventInfo.callerProcessName = processName;
3815     auto record = appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info);
3816     recordId_ += 1;
3817     int64_t restartTime = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::
3818         system_clock::now().time_since_epoch()).count();
3819     int64_t killedTime = restartTime - 1000;
3820     appMgrServiceInner->killedProcessMap_.emplace(killedTime, processName);
3821     appMgrServiceInner->SendReStartProcessEvent(eventInfo, record->GetUid());
3822     TAG_LOGI(AAFwkTag::TEST, "SendReStartProcessEvent_004 end");
3823 }
3824 
3825 /**
3826  * @tc.name: SendReStartProcessEvent_005
3827  * @tc.desc: Change app Gc state
3828  * @tc.type: FUNC
3829  */
3830 HWTEST_F(AppMgrServiceInnerTest, SendReStartProcessEvent_005, TestSize.Level1)
3831 {
3832     TAG_LOGI(AAFwkTag::TEST, "SendReStartProcessEvent_005 start");
3833     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
3834     EXPECT_NE(appMgrServiceInner, nullptr);
3835     AAFwk::EventInfo eventInfo;
3836     BundleInfo info;
3837     std::string processName = "test_processName";
3838     eventInfo.bundleName = "bundleName";
3839     eventInfo.callerBundleName = "bundleName";
3840     eventInfo.callerProcessName = "processName";
3841     auto record = appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info);
3842     recordId_ += 1;
3843     int64_t restartTime = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::
3844         system_clock::now().time_since_epoch()).count();
3845     int64_t killedTime = restartTime - 1000;
3846     appMgrServiceInner->killedProcessMap_.emplace(killedTime, processName);
3847     appMgrServiceInner->SendReStartProcessEvent(eventInfo, record->GetUid());
3848     TAG_LOGI(AAFwkTag::TEST, "SendReStartProcessEvent_005 end");
3849 }
3850 
3851 /**
3852  * @tc.name: SendAppLaunchEvent_001
3853  * @tc.desc: launch application.
3854  * @tc.type: FUNC
3855  * @tc.require: issueI5W4S7
3856  */
3857 HWTEST_F(AppMgrServiceInnerTest, SendAppLaunchEvent_001, TestSize.Level0)
3858 {
3859     TAG_LOGI(AAFwkTag::TEST, "SendAppLaunchEvent_001 start");
3860     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
3861     EXPECT_NE(appMgrServiceInner, nullptr);
3862 
3863     appMgrServiceInner->SendAppLaunchEvent(nullptr);
3864     BundleInfo info;
3865     std::string processName = "test_processName";
3866     std::shared_ptr<AppRunningRecord> appRecord =
3867         appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info);
3868     recordId_ += 1;
3869     std::shared_ptr<AppRunningRecord> appRecord2 =
3870         appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info);
3871     recordId_ += 1;
3872     appRecord->SetState(ApplicationState::APP_STATE_CREATE);
3873     appRecord->SetKeepAliveEnableState(false);
3874     appRecord->SetEmptyKeepAliveAppState(false);
3875     Want want;
3876     appRecord->SetSpecifiedAbilityFlagAndWant(-1, want, "");
3877     appMgrServiceInner->SendAppLaunchEvent(appRecord);
3878     appRecord->SetCallerPid(appRecord2->GetPriorityObject()->GetPid());
3879     appMgrServiceInner->SendAppLaunchEvent(appRecord);
3880     appRecord->appInfo_ = nullptr;
3881     appRecord2->appInfo_ = nullptr;
3882     appMgrServiceInner->SendAppLaunchEvent(appRecord);
3883     TAG_LOGI(AAFwkTag::TEST, "SendAppLaunchEvent_001 end");
3884 }
3885 HWTEST_F(AppMgrServiceInnerTest, IsMainProcess_001, TestSize.Level0)
3886 {
3887     TAG_LOGI(AAFwkTag::TEST, "IsMainProcess_001 start");
3888     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
3889     EXPECT_NE(appMgrServiceInner, nullptr);
3890 
3891     HapModuleInfo hapModuleInfo;
3892     hapModuleInfo.moduleName = "module123";
3893     applicationInfo_->process = "";
3894     EXPECT_EQ(appMgrServiceInner->IsMainProcess(nullptr, ""), true);
3895     EXPECT_EQ(appMgrServiceInner->IsMainProcess(applicationInfo_, ""), false);
3896     EXPECT_EQ(appMgrServiceInner->IsMainProcess(applicationInfo_, "processName1"), false);
3897     EXPECT_EQ(appMgrServiceInner->IsMainProcess(applicationInfo_, applicationInfo_->bundleName), true);
3898     applicationInfo_->process = "processName2";
3899     EXPECT_EQ(appMgrServiceInner->IsMainProcess(applicationInfo_, applicationInfo_->bundleName), false);
3900     EXPECT_EQ(appMgrServiceInner->IsMainProcess(applicationInfo_, "processName2"), true);
3901     applicationInfo_->process = "";
3902 
3903     TAG_LOGI(AAFwkTag::TEST, "IsMainProcess_001 end");
3904 }
3905 
3906 /**
3907  * @tc.name: IsApplicationRunning_001
3908  * @tc.desc: Obtain application running status through bundleName.
3909  * @tc.type: FUNC
3910  */
3911 HWTEST_F(AppMgrServiceInnerTest, IsApplicationRunning_001, TestSize.Level1)
3912 {
3913     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
3914     EXPECT_NE(appMgrServiceInner, nullptr);
3915     std::string bundleName = "com.is.hiserice";
3916     std::string processName = "test_processName";
3917     bool isRunning = false;
3918     auto appRecord = std::make_shared<AppRunningRecord>(applicationInfo_, ++recordId_, processName);
3919     EXPECT_NE(appRecord, nullptr);
3920     appRecord->mainBundleName_ = "com.is.hiserice";
3921     appMgrServiceInner->appRunningManager_->appRunningRecordMap_.emplace(recordId_, appRecord);
3922     int32_t ret = appMgrServiceInner->IsApplicationRunning(bundleName, isRunning);
3923     EXPECT_EQ(ret, ERR_OK);
3924     EXPECT_TRUE(isRunning);
3925 }
3926 
3927 /**
3928  * @tc.name: IsApplicationRunning_002
3929  * @tc.desc: Not passing in bundleName, unable to obtain application running status.
3930  * @tc.type: FUNC
3931  */
3932 HWTEST_F(AppMgrServiceInnerTest, IsApplicationRunning_002, TestSize.Level1)
3933 {
3934     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
3935     EXPECT_NE(appMgrServiceInner, nullptr);
3936     std::string bundleName = "com.is.hiserice";
3937     std::string processName = "test_processName";
3938     bool isRunning = false;
3939     auto appRecord = std::make_shared<AppRunningRecord>(applicationInfo_, ++recordId_, processName);
3940     EXPECT_NE(appRecord, nullptr);
3941     appMgrServiceInner->appRunningManager_->appRunningRecordMap_.emplace(recordId_, appRecord);
3942     int32_t ret = appMgrServiceInner->IsApplicationRunning(bundleName, isRunning);
3943     EXPECT_EQ(ret, ERR_OK);
3944     EXPECT_FALSE(isRunning);
3945 }
3946 
3947 /**
3948  * @tc.name: InitWindowVisibilityChangedListener_001
3949  * @tc.desc: init windowVisibilityChangedListener
3950  * @tc.type: FUNC
3951  */
3952 HWTEST_F(AppMgrServiceInnerTest, InitWindowVisibilityChangedListener_001, TestSize.Level1)
3953 {
3954     GTEST_LOG_(INFO) << "InitWindowVisibilityChangedListener_001 start" ;
3955     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
3956     EXPECT_NE(appMgrServiceInner, nullptr);
3957 
3958     appMgrServiceInner->InitWindowVisibilityChangedListener();
3959     EXPECT_NE(appMgrServiceInner->windowVisibilityChangedListener_, nullptr);
3960     GTEST_LOG_(INFO) << "InitWindowVisibilityChangedListener_001 end";
3961 }
3962 
3963 /**
3964  * @tc.name: FreeWindowVisibilityChangedListener_001
3965  * @tc.desc: free windowVisibilityChangedListener
3966  * @tc.type: FUNC
3967  */
3968 HWTEST_F(AppMgrServiceInnerTest, FreeWindowVisibilityChangedListener_001, TestSize.Level1)
3969 {
3970     GTEST_LOG_(INFO) << "FreeWindowVisibilityChangedListener_001 start";
3971     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
3972     EXPECT_NE(appMgrServiceInner, nullptr);
3973 
3974     appMgrServiceInner->FreeWindowVisibilityChangedListener();
3975     EXPECT_EQ(appMgrServiceInner->windowVisibilityChangedListener_, nullptr);
3976     GTEST_LOG_(INFO) << "FreeWindowVisibilityChangedListener_001 end";
3977 }
3978 
3979 /**
3980  * @tc.name: HandleWindowVisibilityChanged_001
3981  * @tc.desc: handle window visibility changed
3982  * @tc.type: FUNC
3983  */
3984 HWTEST_F(AppMgrServiceInnerTest, HandleWindowVisibilityChanged_001, TestSize.Level1)
3985 {
3986     GTEST_LOG_(INFO) << "HandleWindowVisibilityChanged_001 start";
3987     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
3988     EXPECT_NE(appMgrServiceInner, nullptr);
3989 
3990     std::vector<sptr<Rosen::WindowVisibilityInfo>> visibilityInfos;
3991     appMgrServiceInner->HandleWindowVisibilityChanged(visibilityInfos);
3992     EXPECT_NE(appMgrServiceInner, nullptr);
3993     GTEST_LOG_(INFO) << "HandleWindowVisibilityChanged_001 end";
3994 }
3995 
3996 /**
3997  * @tc.name: IsAppRunning_001
3998  * @tc.desc: Obtain application running status through bundleName.
3999  * @tc.type: FUNC
4000  */
4001 HWTEST_F(AppMgrServiceInnerTest, IsAppRunning_001, TestSize.Level1)
4002 {
4003     AAFwk::IsMockSaCall::IsMockSaCallWithPermission();
4004     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
4005     EXPECT_NE(appMgrServiceInner, nullptr);
4006     std::string bundleName = "com.is.hiserice";
4007     std::string processName = "test_processName";
4008     int32_t appCloneIndex = 0;
4009     bool isRunning = false;
4010     auto appRecord = std::make_shared<AppRunningRecord>(applicationInfo_, ++recordId_, processName);
4011     EXPECT_NE(appRecord, nullptr);
4012     appRecord->mainBundleName_ = "com.is.hiserice";
4013     appMgrServiceInner->appRunningManager_->appRunningRecordMap_.emplace(recordId_, appRecord);
4014     int32_t ret = appMgrServiceInner->IsAppRunning(bundleName, appCloneIndex, isRunning);
4015     EXPECT_EQ(ret, AAFwk::ERR_APP_CLONE_INDEX_INVALID);
4016     EXPECT_FALSE(isRunning);
4017 }
4018 
4019 /**
4020  * @tc.name: IsAppRunning_002
4021  * @tc.desc: Not passing in bundleName, unable to obtain application running status.
4022  * @tc.type: FUNC
4023  */
4024 HWTEST_F(AppMgrServiceInnerTest, IsAppRunning_002, TestSize.Level1)
4025 {
4026     AAFwk::IsMockSaCall::IsMockSaCallWithPermission();
4027     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
4028     EXPECT_NE(appMgrServiceInner, nullptr);
4029     std::string bundleName = "com.is.hiserice";
4030     std::string processName = "test_processName";
4031     int32_t appCloneIndex = 0;
4032     bool isRunning = false;
4033     auto appRecord = std::make_shared<AppRunningRecord>(applicationInfo_, ++recordId_, processName);
4034     EXPECT_NE(appRecord, nullptr);
4035     appMgrServiceInner->appRunningManager_->appRunningRecordMap_.emplace(recordId_, appRecord);
4036     int32_t ret = appMgrServiceInner->IsAppRunning(bundleName, appCloneIndex, isRunning);
4037     EXPECT_EQ(ret, AAFwk::ERR_APP_CLONE_INDEX_INVALID);
4038     EXPECT_FALSE(isRunning);
4039 }
4040 
4041 /**
4042  * @tc.name: RegisterAbilityForegroundStateObserver_0100
4043  * @tc.desc: Verify it when observer is nullptr.
4044  * @tc.type: FUNC
4045  */
4046 HWTEST_F(AppMgrServiceInnerTest, RegisterAbilityForegroundStateObserver_0100, TestSize.Level0)
4047 {
4048     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
4049     EXPECT_NE(appMgrServiceInner, nullptr);
4050     auto res = appMgrServiceInner->RegisterAbilityForegroundStateObserver(nullptr);
4051     EXPECT_EQ(res, ERR_INVALID_VALUE);
4052 }
4053 
4054 /**
4055  * @tc.name: UnregisterAbilityForegroundStateObserver_0100
4056  * @tc.desc: Verify it when observer is nullptr.
4057  * @tc.type: FUNC
4058  */
4059 HWTEST_F(AppMgrServiceInnerTest, UnregisterAbilityForegroundStateObserver_0100, TestSize.Level0)
4060 {
4061     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
4062     EXPECT_NE(appMgrServiceInner, nullptr);
4063     auto res = appMgrServiceInner->UnregisterAbilityForegroundStateObserver(nullptr);
4064     EXPECT_EQ(res, ERR_INVALID_VALUE);
4065 }
4066 
4067 /**
4068  * @tc.name: RegisterAppForegroundStateObserver_0100
4069  * @tc.desc: Test the return when observer is nullptr.
4070  * @tc.type: FUNC
4071  */
4072 HWTEST_F(AppMgrServiceInnerTest, RegisterAppForegroundStateObserver_0100, TestSize.Level1)
4073 {
4074     sptr<IAppForegroundStateObserver> observer = nullptr;
4075     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
4076     auto res = appMgrServiceInner->RegisterAppForegroundStateObserver(observer);
4077     EXPECT_EQ(ERR_INVALID_VALUE, res);
4078 }
4079 
4080 /**
4081  * @tc.name: UnregisterAppForegroundStateObserver_0100
4082  * @tc.desc: Test the return when observer is nullptr.
4083  * @tc.type: FUNC
4084  */
4085 HWTEST_F(AppMgrServiceInnerTest, UnregisterAppForegroundStateObserver_0100, TestSize.Level1)
4086 {
4087     sptr<IAppForegroundStateObserver> observer = nullptr;
4088     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
4089     auto res = appMgrServiceInner->RegisterAppForegroundStateObserver(observer);
4090     EXPECT_EQ(ERR_INVALID_VALUE, res);
4091 }
4092 
4093 /**
4094  * @tc.name: RegisterStateStateObserver_0100
4095  * @tc.desc: Test unregister by nullptr.
4096  * @tc.type: FUNC
4097  */
4098 HWTEST_F(AppMgrServiceInnerTest, RegisterRenderStateObserver_0100, TestSize.Level1)
4099 {
4100     sptr<IRenderStateObserver> observer = nullptr;
4101     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
4102     auto res = appMgrServiceInner->RegisterRenderStateObserver(observer);
4103     EXPECT_EQ(ERR_INVALID_VALUE, res);
4104 }
4105 
4106 /**
4107  * @tc.name: RegisterStateStateObserver_0200
4108  * @tc.desc: Test unregister without permission.
4109  * @tc.type: FUNC
4110  */
4111 HWTEST_F(AppMgrServiceInnerTest, RegisterRenderStateObserver_0200, TestSize.Level1)
4112 {
4113     AAFwk::IsMockSaCall::IsMockSaCallWithPermission();
4114     sptr<IRenderStateObserver> observer = new (std::nothrow) RenderStateObserverMock();
4115     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
4116     auto res = appMgrServiceInner->RegisterRenderStateObserver(observer);
4117     EXPECT_EQ(ERR_OK, res);
4118 }
4119 
4120 /**
4121  * @tc.name: UnregisterRenderStateObserver_0100
4122  * @tc.desc: Test unregister by nullptr.
4123  * @tc.type: FUNC
4124  */
4125 HWTEST_F(AppMgrServiceInnerTest, UnregisterRenderStateObserver_0100, TestSize.Level1)
4126 {
4127     sptr<IRenderStateObserver> observer = nullptr;
4128     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
4129     auto res = appMgrServiceInner->RegisterRenderStateObserver(observer);
4130     EXPECT_EQ(ERR_INVALID_VALUE, res);
4131 }
4132 
4133 /**
4134  * @tc.name: UnregisterRenderStateObserver_0200
4135  * @tc.desc: Test unregister without permission.
4136  * @tc.type: FUNC
4137  */
4138 HWTEST_F(AppMgrServiceInnerTest, UnregisterRenderStateObserver_0200, TestSize.Level1)
4139 {
4140     AAFwk::IsMockSaCall::IsMockSaCallWithPermission();
4141     sptr<IRenderStateObserver> observer = new (std::nothrow) RenderStateObserverMock();
4142     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
4143     auto res = appMgrServiceInner->RegisterRenderStateObserver(observer);
4144     EXPECT_EQ(ERR_OK, res);
4145 }
4146 
4147 /**
4148  * @tc.name: GetAllUIExtensionRootHostPid_0100
4149  * @tc.desc: Get all ui extension root host pid.
4150  * @tc.type: FUNC
4151  */
4152 HWTEST_F(AppMgrServiceInnerTest, GetAllUIExtensionRootHostPid_0100, TestSize.Level1)
4153 {
4154     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
4155     ASSERT_NE(appMgrServiceInner, nullptr);
4156     pid_t pid = 0;
4157     std::vector<pid_t> hostPids;
4158     auto ret = appMgrServiceInner->GetAllUIExtensionRootHostPid(pid, hostPids);
4159     EXPECT_EQ(ret, ERR_OK);
4160 }
4161 
4162 /**
4163  * @tc.name: GetAllUIExtensionProviderPid_0100
4164  * @tc.desc: Get all ui extension provider pid.
4165  * @tc.type: FUNC
4166  */
4167 HWTEST_F(AppMgrServiceInnerTest, GetAllUIExtensionProviderPid_0100, TestSize.Level1)
4168 {
4169     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
4170     ASSERT_NE(appMgrServiceInner, nullptr);
4171     pid_t hostPid = 0;
4172     std::vector<pid_t> providerPids;
4173     auto ret = appMgrServiceInner->GetAllUIExtensionProviderPid(hostPid, providerPids);
4174     EXPECT_EQ(ret, ERR_OK);
4175 }
4176 
4177 /**
4178  * @tc.name: AddUIExtensionLauncherItem_0100
4179  * @tc.desc: Add ui extension launcher item.
4180  * @tc.type: FUNC
4181  */
4182 HWTEST_F(AppMgrServiceInnerTest, AddUIExtensionLauncherItem_0100, TestSize.Level1)
4183 {
4184     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
4185     ASSERT_NE(appMgrServiceInner, nullptr);
4186 
4187     std::shared_ptr<AAFwk::Want> want = std::make_shared<AAFwk::Want>();
4188     ASSERT_NE(want, nullptr);
4189     want->SetParam("ability.want.params.uiExtensionAbilityId", 1);
4190     want->SetParam("ability.want.params.uiExtensionRootHostPid", 1000);
4191 
4192     std::shared_ptr<ApplicationInfo> appInfo = std::make_shared<ApplicationInfo>();
4193     ASSERT_NE(appInfo, nullptr);
4194     int32_t recordId = 0;
4195     std::string processName = "";
4196     std::shared_ptr<AppRunningRecord> appRecord = std::make_shared<AppRunningRecord>(appInfo, recordId, processName);
4197     ASSERT_NE(appRecord, nullptr);
4198     appRecord->GetPriorityObject()->SetPid(1001);
4199 
4200     sptr<IRemoteObject> token = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
4201 
4202     appMgrServiceInner->AddUIExtensionLauncherItem(want, appRecord, token);
4203     // check want param has been erased.
4204     EXPECT_EQ(want->HasParameter("ability.want.params.uiExtensionAbilityId"), false);
4205     EXPECT_EQ(want->HasParameter("ability.want.params.uiExtensionRootHostPid"), false);
4206     appMgrServiceInner->RemoveUIExtensionLauncherItem(appRecord, token);
4207 }
4208 
4209 /**
4210  * @tc.name: PreloadApplication_0100
4211  * @tc.desc: Preload Application.
4212  * @tc.type: FUNC
4213  */
4214 HWTEST_F(AppMgrServiceInnerTest, PreloadApplication_0100, TestSize.Level1)
4215 {
4216     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
4217     ASSERT_NE(appMgrServiceInner, nullptr);
4218 
4219     std::string bundleName = "com.acts.preloadtest";
4220     int32_t userId = 100;
4221     PreloadMode preloadMode = PreloadMode::PRE_MAKE;
4222     int32_t appIndex = 0;
4223     int32_t ret = appMgrServiceInner->PreloadApplication(bundleName, userId, preloadMode, appIndex);
4224     EXPECT_EQ(ret, ERR_PERMISSION_DENIED);
4225 }
4226 
4227 /**
4228  * @tc.name: SetSupportedProcessCacheSelf_001
4229  * @tc.desc: The application sets itself whether or not to support process cache.
4230  * @tc.type: FUNC
4231  */
4232 HWTEST_F(AppMgrServiceInnerTest, SetSupportedProcessCacheSelf_001, TestSize.Level0)
4233 {
4234     TAG_LOGI(AAFwkTag::TEST, "SetSupportedProcessCacheSelf_001 start");
4235     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
4236     EXPECT_NE(appMgrServiceInner, nullptr);
4237 
4238     bool isSupported = false;
4239     EXPECT_EQ(appMgrServiceInner->SetSupportedProcessCacheSelf(isSupported), ERR_INVALID_VALUE);
4240 
4241     appMgrServiceInner->appRunningManager_ = nullptr;
4242     EXPECT_EQ(appMgrServiceInner->SetSupportedProcessCacheSelf(isSupported), ERR_NO_INIT);
4243 
4244     TAG_LOGI(AAFwkTag::TEST, "SetSupportedProcessCacheSelf_001 end");
4245 }
4246 
4247 /**
4248  * @tc.name: OnAppCacheStateChanged_001
4249  * @tc.desc: on application cache state changed.
4250  * @tc.type: FUNC
4251  */
4252 HWTEST_F(AppMgrServiceInnerTest, OnAppCacheStateChanged_001, TestSize.Level0)
4253 {
4254     TAG_LOGI(AAFwkTag::TEST, "OnAppCacheStateChanged_001 start");
4255     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
4256     EXPECT_NE(appMgrServiceInner, nullptr);
4257 
4258     appMgrServiceInner->OnAppCacheStateChanged(nullptr, ApplicationState::APP_STATE_CACHED);
4259 
4260     std::string bundleName = "com.is.hiserice";
4261     std::string processName = "test_processName";
4262     bool isRunning = false;
4263     auto appRecord = std::make_shared<AppRunningRecord>(applicationInfo_, ++recordId_, processName);
4264     EXPECT_NE(appRecord, nullptr);
4265     appRecord->mainBundleName_ = "com.is.hiserice";
4266     appRecord->SetState(ApplicationState::APP_STATE_CACHED);
4267 
4268     appRecord->priorityObject_ = nullptr;
4269     appMgrServiceInner->OnAppCacheStateChanged(appRecord, ApplicationState::APP_STATE_CACHED);
4270 
4271     appRecord->priorityObject_ = std::make_shared<PriorityObject>();
4272     appMgrServiceInner->OnAppCacheStateChanged(appRecord, ApplicationState::APP_STATE_CACHED);
4273 
4274 
4275     TAG_LOGI(AAFwkTag::TEST, "OnAppCacheStateChanged_001 end");
4276 }
4277 
4278 /**
4279  * @tc.name: GetRunningMultiAppInfoByBundleName_001
4280  * @tc.desc: Get multiApp information list by bundleName.
4281  * @tc.type: FUNC
4282  * @tc.require: issueI9HMAO
4283  */
4284 HWTEST_F(AppMgrServiceInnerTest, GetRunningMultiAppInfoByBundleName_001, TestSize.Level1)
4285 {
4286     TAG_LOGI(AAFwkTag::TEST, "GetRunningMultiAppInfoByBundleName_001 start");
4287     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
4288     EXPECT_NE(appMgrServiceInner, nullptr);
4289 
4290     std::string bundleName = "testBundleName";
4291     RunningMultiAppInfo info;
4292     int32_t ret = appMgrServiceInner->GetRunningMultiAppInfoByBundleName(bundleName, info);
4293     EXPECT_NE(ret, ERR_OK);
4294 
4295     appMgrServiceInner->remoteClientManager_ = nullptr;
4296     ret = appMgrServiceInner->GetRunningMultiAppInfoByBundleName(bundleName, info);
4297     EXPECT_EQ(ret, ERR_INVALID_VALUE);
4298 
4299     TAG_LOGI(AAFwkTag::TEST, "GetRunningMultiAppInfoByBundleName_001 end");
4300 }
4301 
4302 /**
4303  * @tc.name: GetRunningMultiAppInfoByBundleName_002
4304  * @tc.desc: Get multiApp information list by bundleName.
4305  * @tc.type: FUNC
4306  * @tc.require: issueI9HMAO
4307  */
4308 HWTEST_F(AppMgrServiceInnerTest, GetRunningMultiAppInfoByBundleName_002, TestSize.Level1)
4309 {
4310     TAG_LOGI(AAFwkTag::TEST, "GetRunningMultiAppInfoByBundleName_002 start");
4311     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
4312     EXPECT_NE(appMgrServiceInner, nullptr);
4313 
4314     std::string bundleName = "";
4315     RunningMultiAppInfo info;
4316     int32_t ret = appMgrServiceInner->GetRunningMultiAppInfoByBundleName(bundleName, info);
4317     EXPECT_EQ(ret, AAFwk::INVALID_PARAMETERS_ERR);
4318 
4319     TAG_LOGI(AAFwkTag::TEST, "GetRunningMultiAppInfoByBundleName_002 end");
4320 }
4321 
4322 /**
4323  * @tc.name: GetAllRunningInstanceKeysBySelf_001
4324  * @tc.desc: GetAllRunningInstanceKeysBySelf.
4325  * @tc.type: FUNC
4326  * @tc.require: issueI9HMAO
4327  */
4328 HWTEST_F(AppMgrServiceInnerTest, GetAllRunningInstanceKeysBySelf_001, TestSize.Level1)
4329 {
4330     TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysBySelf_001 start");
4331     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
4332     EXPECT_NE(appMgrServiceInner, nullptr);
4333 
4334     std::vector<std::string> instanceKeys;
4335     int32_t ret = appMgrServiceInner->GetAllRunningInstanceKeysBySelf(instanceKeys);
4336     EXPECT_NE(ret, ERR_OK);
4337 
4338     appMgrServiceInner->remoteClientManager_ = nullptr;
4339     ret = appMgrServiceInner->GetAllRunningInstanceKeysBySelf(instanceKeys);
4340     EXPECT_EQ(ret, ERR_NO_INIT);
4341 
4342     appMgrServiceInner->remoteClientManager_ = std::make_shared<RemoteClientManager>();
4343     ret = appMgrServiceInner->GetAllRunningInstanceKeysBySelf(instanceKeys);
4344     EXPECT_NE(ret, ERR_NO_INIT);
4345 
4346     TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysBySelf_001 end");
4347 }
4348 
4349 /**
4350  * @tc.name: GetAllRunningInstanceKeysByBundleName_001
4351  * @tc.desc: GetAllRunningInstanceKeysByBundleName.
4352  * @tc.type: FUNC
4353  * @tc.require: issueI9HMAO
4354  */
4355 HWTEST_F(AppMgrServiceInnerTest, GetAllRunningInstanceKeysByBundleName_001, TestSize.Level1)
4356 {
4357     TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleName_001 start");
4358     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
4359     EXPECT_NE(appMgrServiceInner, nullptr);
4360 
4361     std::string bundleName = "testBundleName";
4362     std::vector<std::string> instanceKeys;
4363     int32_t ret = appMgrServiceInner->GetAllRunningInstanceKeysByBundleName(bundleName, instanceKeys);
4364     EXPECT_NE(ret, ERR_OK);
4365 
4366     TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleName_001 end");
4367 }
4368 
4369 /**
4370  * @tc.name: SendCreateAtomicServiceProcessEvent_001
4371  * @tc.desc: Report event of create atomic service process.
4372  * @tc.type: FUNC
4373  */
4374 HWTEST_F(AppMgrServiceInnerTest, SendCreateAtomicServiceProcessEvent_001, TestSize.Level1)
4375 {
4376     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
4377     EXPECT_NE(appMgrServiceInner, nullptr);
4378     std::string processName = "test_processName";
4379     std::string moduleName = "test_modulenName";
4380     std::string abilityName = "test_abilityName";
4381     auto appRecord = std::make_shared<AppRunningRecord>(applicationInfo_, ++recordId_, processName);
4382     auto bundleType = BundleType::ATOMIC_SERVICE;
4383     auto ret = appMgrServiceInner->SendCreateAtomicServiceProcessEvent(nullptr, bundleType, moduleName, abilityName);
4384     EXPECT_EQ(ret, false);
4385     ret = appMgrServiceInner->SendCreateAtomicServiceProcessEvent(appRecord, bundleType, moduleName, abilityName);
4386     EXPECT_EQ(ret, true);
4387     bundleType = BundleType::APP;
4388     ret = appMgrServiceInner->SendCreateAtomicServiceProcessEvent(appRecord, bundleType, moduleName, abilityName);
4389     EXPECT_EQ(ret, false);
4390 }
4391 
4392 /**
4393  * @tc.name: AttachedToStatusBar_001
4394  * @tc.desc: Attach one ability to status bar.
4395  * @tc.type: FUNC
4396  */
4397 HWTEST_F(AppMgrServiceInnerTest, AttachedToStatusBar_001, TestSize.Level1)
4398 {
4399     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
4400     EXPECT_NE(appMgrServiceInner, nullptr);
4401 
4402     appMgrServiceInner->AttachedToStatusBar(nullptr);
4403 
4404     OHOS::sptr<IRemoteObject> token = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
4405     appMgrServiceInner->AttachedToStatusBar(token);
4406 
4407     BundleInfo bundleInfo;
4408     HapModuleInfo hapModuleInfo;
4409     std::shared_ptr<AAFwk::Want> want;
4410     std::string processName = "test_processName";
4411     std::shared_ptr<AppRunningRecord> appRecord = appMgrServiceInner->CreateAppRunningRecord(token, nullptr,
4412         applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want, 0);
4413     EXPECT_NE(appRecord, nullptr);
4414     appMgrServiceInner->AttachedToStatusBar(token);
4415 }
4416 
4417 /**
4418  * @tc.name: BlockProcessCacheByPids_001
4419  * @tc.desc: Block process cache feature using pids.
4420  * @tc.type: FUNC
4421  */
4422 HWTEST_F(AppMgrServiceInnerTest, BlockProcessCacheByPids_001, TestSize.Level1)
4423 {
4424     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
4425     EXPECT_NE(appMgrServiceInner, nullptr);
4426 
4427     BundleInfo info;
4428     std::string processName = "test_processName";
4429     auto record = appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info);
4430     std::shared_ptr<PriorityObject> priorityObject = std::make_shared<PriorityObject>();
4431     EXPECT_NE(priorityObject, nullptr);
4432     std::string callerBundleName = "callerBundleName";
4433     priorityObject->SetPid(2);
4434     record->priorityObject_ = priorityObject;
4435     record->mainBundleName_ = callerBundleName;
4436     record->SetCallerPid(1);
4437 
4438     std::vector<int32_t> pids{2};
4439     appMgrServiceInner->BlockProcessCacheByPids(pids);
4440 }
4441 
4442 /**
4443  * @tc.name: GetSupportedProcessCachePids_001
4444  * @tc.desc: Get pids of processes which belong to specific bundle name and support process cache feature.
4445  * @tc.type: FUNC
4446  * @tc.require: issueI76JBF
4447  */
4448 HWTEST_F(AppMgrServiceInnerTest, GetSupportedProcessCachePids_001, TestSize.Level0)
4449 {
4450     TAG_LOGI(AAFwkTag::TEST, "GetSupportedProcessCachePids_001 start");
4451     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
4452     EXPECT_NE(appMgrServiceInner, nullptr);
4453 
4454     std::string bundleName = "testBundleName";
4455     std::vector<int32_t> pidList;
4456     int32_t ret = appMgrServiceInner->GetSupportedProcessCachePids(bundleName, pidList);
4457     EXPECT_EQ(ret, ERR_OK);
4458 
4459     appMgrServiceInner->appRunningManager_ = nullptr;
4460     ret = appMgrServiceInner->GetSupportedProcessCachePids(bundleName, pidList);
4461     EXPECT_NE(ret, ERR_OK);
4462 
4463     TAG_LOGI(AAFwkTag::TEST, "GetSupportedProcessCachePids_001 end");
4464 }
4465 } // namespace AppExecFwk
4466 } // namespace OHOS
4467