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 "accesstoken_kit.h"
25 #include "app_scheduler.h"
26 #include "appspawn_util.h"
27 #include "app_spawn_client.h"
28 #include "event_handler.h"
29 #include "hilog_tag_wrapper.h"
30 #include "ipc_skeleton.h"
31 #include "mock_ability_token.h"
32 #include "mock_app_scheduler.h"
33 #include "mock_bundle_manager.h"
34 #include "mock_configuration_observer.h"
35 #include "mock_iapp_state_callback.h"
36 #include "mock_native_token.h"
37 #include "mock_render_scheduler.h"
38 #include "mock_sa_call.h"
39 #include "mock_task_handler_wrap.h"
40 #include "param.h"
41 #include "parameters.h"
42 #include "render_state_observer_stub.h"
43 #include "window_manager.h"
44
45 using namespace testing;
46 using namespace testing::ext;
47
48 namespace OHOS {
49 namespace AppExecFwk {
50 class WindowFocusChangedListener : public OHOS::Rosen::IFocusChangedListener {
51 public:
52 WindowFocusChangedListener(const std::shared_ptr<AppMgrServiceInner>& owner,
53 const std::shared_ptr<AAFwk::TaskHandlerWrap>& handler);
54 virtual ~WindowFocusChangedListener();
55
56 void OnFocused(const sptr<OHOS::Rosen::FocusChangeInfo> &focusChangeInfo) override;
57 void OnUnfocused(const sptr<OHOS::Rosen::FocusChangeInfo> &focusChangeInfo) override;
58
59 private:
60 std::weak_ptr<AppMgrServiceInner> owner_;
61 std::shared_ptr<AAFwk::TaskHandlerWrap> taskHandler_;
62 };
63 namespace {
64 constexpr int32_t RECORD_ID = 1;
65 constexpr int32_t APP_DEBUG_INFO_PID = 0;
66 constexpr int32_t APP_DEBUG_INFO_UID = 0;
67 }
68 static int recordId_ = 0;
69 class AppMgrServiceInnerTest : public testing::Test {
70 public:
71 static void SetUpTestCase();
72 static void TearDownTestCase();
73 void SetUp() override;
74 void TearDown() override;
75
76 void InitAppInfo(const std::string& deviceName, const std::string& abilityName,
77 const std::string& appName, const std::string& bundleName, const std::string& moduleName);
78
79 public:
80 std::shared_ptr<AbilityInfo> abilityInfo_;
81 std::shared_ptr<ApplicationInfo> applicationInfo_;
82 };
83
84 class RenderStateObserverMock : public RenderStateObserverStub {
85 public:
86 RenderStateObserverMock() = default;
87 virtual ~RenderStateObserverMock() = default;
OnRenderStateChanged(const RenderStateData & renderStateData)88 void OnRenderStateChanged(const RenderStateData &renderStateData) override
89 {}
90 };
91
InitAppInfo(const std::string & deviceName,const std::string & abilityName,const std::string & appName,const std::string & bundleName,const std::string & moduleName)92 void AppMgrServiceInnerTest::InitAppInfo(const std::string& deviceName,
93 const std::string& abilityName, const std::string& appName, const std::string& bundleName,
94 const std::string& moduleName)
95 {
96 ApplicationInfo applicationInfo;
97 applicationInfo.name = appName;
98 applicationInfo.bundleName = bundleName;
99 applicationInfo_ = std::make_shared<ApplicationInfo>(applicationInfo);
100
101 AbilityInfo abilityInfo;
102 abilityInfo.visible = true;
103 abilityInfo.applicationName = appName;
104 abilityInfo.type = AbilityType::EXTENSION;
105 abilityInfo.name = abilityName;
106 abilityInfo.bundleName = bundleName;
107 abilityInfo.moduleName = moduleName;
108 abilityInfo.deviceId = deviceName;
109 abilityInfo_ = std::make_shared<AbilityInfo>(abilityInfo);
110 }
111
SetUpTestCase(void)112 void AppMgrServiceInnerTest::SetUpTestCase(void)
113 {
114 MockNativeToken::SetNativeToken();
115 }
116
TearDownTestCase(void)117 void AppMgrServiceInnerTest::TearDownTestCase(void)
118 {}
119
SetUp()120 void AppMgrServiceInnerTest::SetUp()
121 {
122 // init test app info
123 std::string deviceName = "device";
124 std::string abilityName = "ServiceAbility";
125 std::string appName = "hiservcie";
126 std::string bundleName = "com.ix.hiservcie";
127 std::string moduleName = "entry";
128 InitAppInfo(deviceName, abilityName, appName, bundleName, moduleName);
129 }
130
TearDown()131 void AppMgrServiceInnerTest::TearDown()
132 {}
133
134 /**
135 * @tc.name: PointerDeviceCallback_0100
136 * @tc.desc: set parameter, expect config update
137 * @tc.type: FUNC
138 */
139 HWTEST_F(AppMgrServiceInnerTest, PointerDeviceCallback_0100, TestSize.Level1)
140 {
141 TAG_LOGI(AAFwkTag::TEST, "PointerDeviceCallback_0100 start");
142
143 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
144 EXPECT_NE(appMgrServiceInner, nullptr);
145 std::string key = AAFwk::GlobalConfigurationKey::INPUT_POINTER_DEVICE;
146 auto context = new (std::nothrow) std::weak_ptr<AppMgrServiceInner>(appMgrServiceInner);
147 std::shared_ptr<AppExecFwk::Configuration> config = nullptr;
148 std::string value;
149
150 // invalid parameter value
151 appMgrServiceInner->PointerDeviceEventCallback(key.c_str(), "false", context);
152 config = appMgrServiceInner->GetConfiguration();
153 EXPECT_NE(config, nullptr);
154
155 TAG_LOGI(AAFwkTag::TEST, "PointerDeviceCallback_0100 end");
156 }
157
158 /**
159 * @tc.name: PointerDeviceCallback_0200
160 * @tc.desc: set parameter, expect config update
161 * @tc.type: FUNC
162 */
163 HWTEST_F(AppMgrServiceInnerTest, PointerDeviceCallback_0200, TestSize.Level1)
164 {
165 TAG_LOGI(AAFwkTag::TEST, "PointerDeviceCallback_0200 start");
166
167 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
168 EXPECT_NE(appMgrServiceInner, nullptr);
169 std::string key = AAFwk::GlobalConfigurationKey::INPUT_POINTER_DEVICE;
170 auto context = new (std::nothrow) std::weak_ptr<AppMgrServiceInner>(appMgrServiceInner);
171 std::shared_ptr<AppExecFwk::Configuration> config = nullptr;
172 std::string value;
173
174 // invalid parameter value
175 appMgrServiceInner->PointerDeviceEventCallback(key.c_str(), "true", context);
176 config = appMgrServiceInner->GetConfiguration();
177 EXPECT_NE(config, nullptr);
178
179 TAG_LOGI(AAFwkTag::TEST, "PointerDeviceCallback_0200 end");
180 }
181
182 /**
183 * @tc.name: PointerDeviceCallback_0300
184 * @tc.desc: set parameter, expect config update
185 * @tc.type: FUNC
186 */
187 HWTEST_F(AppMgrServiceInnerTest, PointerDeviceCallback_0300, TestSize.Level1)
188 {
189 TAG_LOGI(AAFwkTag::TEST, "PointerDeviceCallback_0300 start");
190
191 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
192 EXPECT_NE(appMgrServiceInner, nullptr);
193 std::string key = AAFwk::GlobalConfigurationKey::INPUT_POINTER_DEVICE;
194 auto context = new (std::nothrow) std::weak_ptr<AppMgrServiceInner>(appMgrServiceInner);
195 std::shared_ptr<AppExecFwk::Configuration> config = nullptr;
196 std::string value;
197
198 // invalid parameter value
199 appMgrServiceInner->PointerDeviceEventCallback("invalid_key", "false", context);
200 config = appMgrServiceInner->GetConfiguration();
201 EXPECT_NE(config, nullptr);
202
203 TAG_LOGI(AAFwkTag::TEST, "PointerDeviceCallback_0300 end");
204 }
205
206 /**
207 * @tc.name: PointerDeviceCallback_0400
208 * @tc.desc: set parameter, expect config update
209 * @tc.type: FUNC
210 */
211 HWTEST_F(AppMgrServiceInnerTest, PointerDeviceCallback_0400, TestSize.Level1)
212 {
213 TAG_LOGI(AAFwkTag::TEST, "PointerDeviceCallback_0400 start");
214
215 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
216 EXPECT_NE(appMgrServiceInner, nullptr);
217 std::string key = AAFwk::GlobalConfigurationKey::INPUT_POINTER_DEVICE;
218 auto context = new (std::nothrow) std::weak_ptr<AppMgrServiceInner>(appMgrServiceInner);
219 std::shared_ptr<AppExecFwk::Configuration> config = nullptr;
220 std::string value;
221
222 // invalid parameter value
223 appMgrServiceInner->PointerDeviceEventCallback(key.c_str(), "invalid", context);
224 config = appMgrServiceInner->GetConfiguration();
225 EXPECT_NE(config, nullptr);
226
227 TAG_LOGI(AAFwkTag::TEST, "PointerDeviceCallback_0400 end");
228 }
229
230 /**
231 * @tc.name: PointerDeviceWatchParameter_0100
232 * @tc.desc: set parameter, expect config update
233 * @tc.type: FUNC
234 */
235 HWTEST_F(AppMgrServiceInnerTest, PointerDeviceWatchParameter_0100, TestSize.Level1)
236 {
237 TAG_LOGI(AAFwkTag::TEST, "PointerDeviceWatchParameter_0100 start");
238
239 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
240 EXPECT_NE(appMgrServiceInner, nullptr);
241 std::string key = AAFwk::GlobalConfigurationKey::INPUT_POINTER_DEVICE;
242 std::shared_ptr<AppExecFwk::Configuration> config = nullptr;
243 std::string value;
244
245 appMgrServiceInner->AddWatchParameter();
246 sleep(1);
247
248 // invalid parameter value
249 system::SetParameter(key.c_str(), "invalid");
250 sleep(1);
251 config = appMgrServiceInner->GetConfiguration();
252 EXPECT_NE(config, nullptr);
253
254 TAG_LOGI(AAFwkTag::TEST, "PointerDeviceWatchParameter_0100 end");
255 }
256
257 /**
258 * @tc.name: PointerDeviceWatchParameter_0200
259 * @tc.desc: set parameter, expect config update
260 * @tc.type: FUNC
261 */
262 HWTEST_F(AppMgrServiceInnerTest, PointerDeviceWatchParameter_0200, TestSize.Level1)
263 {
264 TAG_LOGI(AAFwkTag::TEST, "PointerDeviceWatchParameter_0200 start");
265
266 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
267 EXPECT_NE(appMgrServiceInner, nullptr);
268 std::string key = AAFwk::GlobalConfigurationKey::INPUT_POINTER_DEVICE;
269 std::shared_ptr<AppExecFwk::Configuration> config = nullptr;
270 std::string value;
271
272 appMgrServiceInner->AddWatchParameter();
273 sleep(1);
274
275 // set "input.pointer.device" to false
276 system::SetParameter(key.c_str(), "false");
277 sleep(1);
278 config = appMgrServiceInner->GetConfiguration();
279 EXPECT_NE(config, nullptr);
280
281 TAG_LOGI(AAFwkTag::TEST, "PointerDeviceWatchParameter_0200 end");
282 }
283
284 /**
285 * @tc.name: PointerDeviceWatchParameter_0300
286 * @tc.desc: set parameter, expect config update
287 * @tc.type: FUNC
288 */
289 HWTEST_F(AppMgrServiceInnerTest, PointerDeviceWatchParameter_0300, TestSize.Level1)
290 {
291 TAG_LOGI(AAFwkTag::TEST, "PointerDeviceWatchParameter_0300 start");
292
293 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
294 EXPECT_NE(appMgrServiceInner, nullptr);
295 std::string key = AAFwk::GlobalConfigurationKey::INPUT_POINTER_DEVICE;
296 std::shared_ptr<AppExecFwk::Configuration> config = nullptr;
297 std::string value;
298
299 appMgrServiceInner->AddWatchParameter();
300 sleep(1);
301
302 // set "input.pointer.device" to true
303 system::SetParameter(key.c_str(), "true");
304 sleep(1);
305 config = appMgrServiceInner->GetConfiguration();
306 EXPECT_NE(config, nullptr);
307
308 TAG_LOGI(AAFwkTag::TEST, "PointerDeviceWatchParameter_0300 end");
309 }
310
311 /**
312 * @tc.name: PointerDeviceUpdateConfig_0100
313 * @tc.desc: set parameter, expect config update
314 * @tc.type: FUNC
315 * @tc.require: I581UL
316 */
317 HWTEST_F(AppMgrServiceInnerTest, PointerDeviceUpdateConfig_0100, TestSize.Level1)
318 {
319 TAG_LOGI(AAFwkTag::TEST, "PointerDeviceUpdateConfig_0100 start");
320
321 AAFwk::IsMockSaCall::IsMockSaCallWithPermission();
322 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
323 EXPECT_NE(appMgrServiceInner, nullptr);
324 std::shared_ptr<AppExecFwk::Configuration> config;
325 std::string value;
326 int32_t result;
327
328 appMgrServiceInner->InitGlobalConfiguration();
329 config = appMgrServiceInner->GetConfiguration();
330 EXPECT_NE(config, nullptr);
331 value = config->GetItem(AAFwk::GlobalConfigurationKey::INPUT_POINTER_DEVICE);
332 EXPECT_TRUE((value == "true") || (value == "false"));
333
334 // config didn't change
335 result = appMgrServiceInner->UpdateConfiguration(*config);
336 EXPECT_EQ(result, ERR_INVALID_VALUE);
337
338 Configuration changeConfig;
339 if (value == "true") {
340 changeConfig.AddItem(AAFwk::GlobalConfigurationKey::INPUT_POINTER_DEVICE, "false");
341 result = appMgrServiceInner->UpdateConfiguration(changeConfig);
342 EXPECT_EQ(result, ERR_OK);
343 config = appMgrServiceInner->GetConfiguration();
344 EXPECT_NE(config, nullptr);
345 value = config->GetItem(AAFwk::GlobalConfigurationKey::INPUT_POINTER_DEVICE);
346 EXPECT_EQ(value, "false");
347 } else {
348 changeConfig.AddItem(AAFwk::GlobalConfigurationKey::INPUT_POINTER_DEVICE, "true");
349 result = appMgrServiceInner->UpdateConfiguration(changeConfig);
350 EXPECT_EQ(result, ERR_PERMISSION_DENIED);
351 config = appMgrServiceInner->GetConfiguration();
352 EXPECT_NE(config, nullptr);
353 value = config->GetItem(AAFwk::GlobalConfigurationKey::INPUT_POINTER_DEVICE);
354 EXPECT_EQ(value, "true");
355 }
356
357 TAG_LOGI(AAFwkTag::TEST, "PointerDeviceUpdateConfig_0100 end");
358 }
359
360 /**
361 * @tc.name: PreStartNWebSpawnProcess_001
362 * @tc.desc: prestart nwebspawn process.
363 * @tc.type: FUNC
364 * @tc.require: issueI5W4S7
365 */
366 HWTEST_F(AppMgrServiceInnerTest, PreStartNWebSpawnProcess_001, TestSize.Level0)
367 {
368 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
369 EXPECT_NE(appMgrServiceInner, nullptr);
370
371 int callingPid = IPCSkeleton::GetCallingPid();
372 int ret = appMgrServiceInner->PreStartNWebSpawnProcess(callingPid);
373 EXPECT_NE(ret, ERR_OK);
374 }
375
376 /**
377 * @tc.name: PreStartNWebSpawnProcess_002
378 * @tc.desc: prestart nwebspawn process.
379 * @tc.type: FUNC
380 * @tc.require: issueI5W4S7
381 */
382 HWTEST_F(AppMgrServiceInnerTest, PreStartNWebSpawnProcess_002, TestSize.Level0)
383 {
384 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
385 EXPECT_NE(appMgrServiceInner, nullptr);
386
387 int callingPid = 0;
388 int ret = appMgrServiceInner->PreStartNWebSpawnProcess(callingPid);
389 EXPECT_EQ(ret, ERR_INVALID_VALUE);
390 }
391
392 /**
393 * @tc.name: LoadAbility_001
394 * @tc.desc: load ability.
395 * @tc.type: FUNC
396 * @tc.require: issueI5W4S7
397 */
398 HWTEST_F(AppMgrServiceInnerTest, LoadAbility_001, TestSize.Level0)
399 {
400 TAG_LOGI(AAFwkTag::TEST, "LoadAbility_001 start");
401 OHOS::sptr<IRemoteObject> token = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
402 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
403 EXPECT_NE(appMgrServiceInner, nullptr);
404
405 appMgrServiceInner->appRunningManager_ = nullptr;
406 AbilityRuntime::LoadParam loadParam;
407 loadParam.token = token;
408 auto loadParamPtr = std::make_shared<AbilityRuntime::LoadParam>(loadParam);
409 appMgrServiceInner->LoadAbility(abilityInfo_, applicationInfo_, nullptr, loadParamPtr);
410
411 auto appMgrServiceInner1 = std::make_shared<AppMgrServiceInner>();
412 EXPECT_NE(appMgrServiceInner1, nullptr);
413
414 appMgrServiceInner1->remoteClientManager_->SetBundleManagerHelper(nullptr);
415 appMgrServiceInner1->LoadAbility(abilityInfo_, applicationInfo_, nullptr, loadParamPtr);
416
417 auto appMgrServiceInner2 = std::make_shared<AppMgrServiceInner>();
418 EXPECT_NE(appMgrServiceInner2, nullptr);
419
420 appMgrServiceInner2->LoadAbility(abilityInfo_, applicationInfo_, nullptr, loadParamPtr);
421 TAG_LOGI(AAFwkTag::TEST, "LoadAbility_001 end");
422 }
423
424 /**
425 * @tc.name: CheckLoadAbilityConditions_001
426 * @tc.desc: check load ability conditions.
427 * @tc.type: FUNC
428 * @tc.require: issueI5W4S7
429 */
430 HWTEST_F(AppMgrServiceInnerTest, CheckLoadAbilityConditions_001, TestSize.Level0)
431 {
432 TAG_LOGI(AAFwkTag::TEST, "CheckLoadAbilityConditions_001 start");
433 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
434 EXPECT_NE(appMgrServiceInner, nullptr);
435
436 OHOS::sptr<IRemoteObject> token = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
437
438 appMgrServiceInner->CheckLoadAbilityConditions(nullptr, nullptr, nullptr);
439
440 appMgrServiceInner->CheckLoadAbilityConditions(nullptr, abilityInfo_, nullptr);
441
442 appMgrServiceInner->CheckLoadAbilityConditions(nullptr, nullptr, applicationInfo_);
443
444 appMgrServiceInner->CheckLoadAbilityConditions(token, nullptr, nullptr);
445
446 appMgrServiceInner->CheckLoadAbilityConditions(token, abilityInfo_, nullptr);
447
448 appMgrServiceInner->CheckLoadAbilityConditions(nullptr, abilityInfo_, applicationInfo_);
449
450 appMgrServiceInner->CheckLoadAbilityConditions(token, nullptr, applicationInfo_);
451
452 appMgrServiceInner->CheckLoadAbilityConditions(token, abilityInfo_, applicationInfo_);
453
454 EXPECT_NE(appMgrServiceInner, nullptr);
455 TAG_LOGI(AAFwkTag::TEST, "CheckLoadAbilityConditions_001 end");
456 }
457
458 /**
459 * @tc.name: MakeProcessName_001
460 * @tc.desc: make process name.
461 * @tc.type: FUNC
462 * @tc.require: issueI5W4S7
463 */
464 HWTEST_F(AppMgrServiceInnerTest, MakeProcessName_001, TestSize.Level0)
465 {
466 TAG_LOGI(AAFwkTag::TEST, "MakeProcessName_001 start");
467 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
468 EXPECT_NE(appMgrServiceInner, nullptr);
469
470 HapModuleInfo hapModuleInfo;
471 hapModuleInfo.moduleName = "module789";
472 std::string processName = "test_processName";
473 appMgrServiceInner->MakeProcessName(nullptr, nullptr, hapModuleInfo, 1, "", processName);
474 appMgrServiceInner->MakeProcessName(nullptr, applicationInfo_, hapModuleInfo, 1, "", processName);
475 appMgrServiceInner->MakeProcessName(abilityInfo_, nullptr, hapModuleInfo, 1, "", processName);
476 appMgrServiceInner->MakeProcessName(abilityInfo_, applicationInfo_, hapModuleInfo, 1, "", processName);
477
478 EXPECT_NE(appMgrServiceInner, nullptr);
479 TAG_LOGI(AAFwkTag::TEST, "MakeProcessName_001 end");
480 }
481
482 /**
483 * @tc.name: MakeProcessName_002
484 * @tc.desc: make process name.
485 * @tc.type: FUNC
486 * @tc.require: issueI5W4S7
487 */
488 HWTEST_F(AppMgrServiceInnerTest, MakeProcessName_002, TestSize.Level0)
489 {
490 TAG_LOGI(AAFwkTag::TEST, "MakeProcessName_002 start");
491 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
492 EXPECT_NE(appMgrServiceInner, nullptr);
493
494 HapModuleInfo hapModuleInfo;
495 hapModuleInfo.moduleName = "module789";
496 std::string processName = "test_processName";
497 appMgrServiceInner->MakeProcessName(nullptr, hapModuleInfo, processName);
498 appMgrServiceInner->MakeProcessName(applicationInfo_, hapModuleInfo, processName);
499 hapModuleInfo.isStageBasedModel = false;
500 hapModuleInfo.process = "";
501 appMgrServiceInner->MakeProcessName(applicationInfo_, hapModuleInfo, processName);
502
503 hapModuleInfo.isStageBasedModel = true;
504 hapModuleInfo.process = "";
505 appMgrServiceInner->MakeProcessName(applicationInfo_, hapModuleInfo, processName);
506
507 hapModuleInfo.isStageBasedModel = false;
508 hapModuleInfo.process = "test_process";
509 appMgrServiceInner->MakeProcessName(applicationInfo_, hapModuleInfo, processName);
510
511 hapModuleInfo.isStageBasedModel = true;
512 hapModuleInfo.process = "test_process";
513 appMgrServiceInner->MakeProcessName(applicationInfo_, hapModuleInfo, processName);
514
515 hapModuleInfo.isStageBasedModel = false;
516 applicationInfo_->process = "";
517 appMgrServiceInner->MakeProcessName(applicationInfo_, hapModuleInfo, processName);
518
519 hapModuleInfo.isStageBasedModel = false;
520 applicationInfo_->process = "test_process";
521 appMgrServiceInner->MakeProcessName(applicationInfo_, hapModuleInfo, processName);
522
523 EXPECT_NE(appMgrServiceInner, nullptr);
524 TAG_LOGI(AAFwkTag::TEST, "MakeProcessName_002 end");
525 }
526
527 /**
528 * @tc.name: GetBundleAndHapInfo_001
529 * @tc.desc: get bundle and hapInfo.
530 * @tc.type: FUNC
531 * @tc.require: issueI5W4S7
532 */
533 HWTEST_F(AppMgrServiceInnerTest, GetBundleAndHapInfo_001, TestSize.Level0)
534 {
535 TAG_LOGI(AAFwkTag::TEST, "GetBundleAndHapInfo_001 start");
536 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
537 EXPECT_NE(appMgrServiceInner, nullptr);
538
539 BundleInfo bundleInfo;
540 HapModuleInfo hapModuleInfo;
541 appMgrServiceInner->GetBundleAndHapInfo(*abilityInfo_, applicationInfo_, bundleInfo, hapModuleInfo, 1);
542
543 appMgrServiceInner->remoteClientManager_->SetBundleManagerHelper(nullptr);
544 appMgrServiceInner->GetBundleAndHapInfo(*abilityInfo_, applicationInfo_, bundleInfo, hapModuleInfo, 1);
545 TAG_LOGI(AAFwkTag::TEST, "GetBundleAndHapInfo_001 end");
546 }
547
548 /**
549 * @tc.name: AttachApplication_001
550 * @tc.desc: attach application.
551 * @tc.type: FUNC
552 * @tc.require: issueI5W4S7
553 */
554 HWTEST_F(AppMgrServiceInnerTest, AttachApplication_001, TestSize.Level0)
555 {
556 TAG_LOGI(AAFwkTag::TEST, "AttachApplication_001 start");
557 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
558 EXPECT_NE(appMgrServiceInner, nullptr);
559
560 appMgrServiceInner->AttachApplication(0, nullptr);
561
562 appMgrServiceInner->AttachApplication(1, nullptr);
563
564 sptr<MockAppScheduler> mockAppScheduler = new (std::nothrow) MockAppScheduler();
565 sptr<IAppScheduler> client = iface_cast<IAppScheduler>(mockAppScheduler.GetRefPtr());
566 appMgrServiceInner->AttachApplication(1, client);
567 TAG_LOGI(AAFwkTag::TEST, "AttachApplication_001 end");
568 }
569
570 /**
571 * @tc.name: LaunchApplication_001
572 * @tc.desc: launch application.
573 * @tc.type: FUNC
574 * @tc.require: issueI5W4S7
575 */
576 HWTEST_F(AppMgrServiceInnerTest, LaunchApplication_001, TestSize.Level0)
577 {
578 TAG_LOGI(AAFwkTag::TEST, "LaunchApplication_001 start");
579 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
580 EXPECT_NE(appMgrServiceInner, nullptr);
581
582 appMgrServiceInner->LaunchApplication(nullptr);
583
584 BundleInfo info;
585 std::string processName = "test_processName";
586 std::shared_ptr<AppRunningRecord> appRecord =
587 appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info);
588 recordId_ += 1;
589 appMgrServiceInner->LaunchApplication(appRecord);
590
591 appRecord->SetState(ApplicationState::APP_STATE_FOREGROUND);
592 appMgrServiceInner->LaunchApplication(appRecord);
593
594 appRecord->SetState(ApplicationState::APP_STATE_CREATE);
595 appMgrServiceInner->LaunchApplication(appRecord);
596
597 appRecord->SetEmptyKeepAliveAppState(true);
598 appRecord->SetKeepAliveEnableState(false);
599 appMgrServiceInner->LaunchApplication(appRecord);
600
601 appRecord->SetKeepAliveEnableState(true);
602 appRecord->SetEmptyKeepAliveAppState(false);
603 appMgrServiceInner->LaunchApplication(appRecord);
604
605 appRecord->SetKeepAliveEnableState(true);
606 appRecord->SetEmptyKeepAliveAppState(true);
607 appMgrServiceInner->LaunchApplication(appRecord);
608
609 appRecord->SetKeepAliveEnableState(false);
610 appRecord->SetEmptyKeepAliveAppState(false);
611 appMgrServiceInner->LaunchApplication(appRecord);
612
613 Want want;
614 appRecord->SetSpecifiedAbilityFlagAndWant(-1, want, "");
615 appMgrServiceInner->LaunchApplication(appRecord);
616
617 appRecord->SetSpecifiedAbilityFlagAndWant(1, want, "");
618 appMgrServiceInner->LaunchApplication(appRecord);
619
620 appMgrServiceInner->LaunchApplication(appRecord);
621 TAG_LOGI(AAFwkTag::TEST, "LaunchApplication_001 end");
622 }
623
624 /**
625 * @tc.name: AddAbilityStageDone_001
626 * @tc.desc: add ability stage done.
627 * @tc.type: FUNC
628 * @tc.require: issueI5W4S7
629 */
630 HWTEST_F(AppMgrServiceInnerTest, AddAbilityStageDone_001, TestSize.Level0)
631 {
632 TAG_LOGI(AAFwkTag::TEST, "AddAbilityStageDone_001 start");
633 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
634 EXPECT_NE(appMgrServiceInner, nullptr);
635
636 appMgrServiceInner->AddAbilityStageDone(99);
637
638 BundleInfo info;
639 std::string processName = "test_processName";
640 appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info);
641 recordId_ += 1;
642
643 appMgrServiceInner->AddAbilityStageDone(recordId_);
644 TAG_LOGI(AAFwkTag::TEST, "AddAbilityStageDone_001 end");
645 }
646
647 /**
648 * @tc.name: ApplicationForegrounded_001
649 * @tc.desc: application foregrounded.
650 * @tc.type: FUNC
651 * @tc.require: issueI5W4S7
652 */
653 HWTEST_F(AppMgrServiceInnerTest, ApplicationForegrounded_001, TestSize.Level0)
654 {
655 TAG_LOGI(AAFwkTag::TEST, "ApplicationForegrounded_001 start");
656 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
657 EXPECT_NE(appMgrServiceInner, nullptr);
658
659 appMgrServiceInner->ApplicationForegrounded(99);
660
661 BundleInfo info;
662 std::string processName = "test_processName";
663 appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info);
664 recordId_ += 1;
665
666 appMgrServiceInner->ApplicationForegrounded(recordId_);
667 TAG_LOGI(AAFwkTag::TEST, "ApplicationForegrounded_001 end");
668 }
669
670 /**
671 * @tc.name: ApplicationForegrounded_002
672 * @tc.desc: application foregrounded.
673 * @tc.type: FUNC
674 * @tc.require: issueI5W4S7
675 */
676 HWTEST_F(AppMgrServiceInnerTest, ApplicationForegrounded_002, TestSize.Level0)
677 {
678 TAG_LOGI(AAFwkTag::TEST, "ApplicationForegrounded_002 start");
679 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
680 EXPECT_NE(appMgrServiceInner, nullptr);
681
682 BundleInfo info;
683 std::string processName = "test_processName";
684 auto record = appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info);
685 recordId_ += 1;
686
687 appMgrServiceInner->ApplicationForegrounded(recordId_);
688 TAG_LOGI(AAFwkTag::TEST, "ApplicationForegrounded_002 end");
689 }
690
691 /**
692 * @tc.name: ApplicationForegrounded_003
693 * @tc.desc: application foregrounded.
694 * @tc.type: FUNC
695 * @tc.require: issueI5W4S7
696 */
697 HWTEST_F(AppMgrServiceInnerTest, ApplicationForegrounded_003, TestSize.Level0)
698 {
699 TAG_LOGI(AAFwkTag::TEST, "ApplicationForegrounded_003 start");
700 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
701 EXPECT_NE(appMgrServiceInner, nullptr);
702
703 BundleInfo info;
704 std::string processName = "test_processName";
705 auto record = appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info);
706 recordId_ += 1;
707 auto record2 = appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info);
708 recordId_ += 1;
709 std::shared_ptr<PriorityObject> priorityObject = std::make_shared<PriorityObject>();
710 std::string callerBundleName = "callerBundleName";
711 priorityObject->SetPid(1);
712 record2->priorityObject_ = priorityObject;
713 record2->mainBundleName_ = callerBundleName;
714 record->SetCallerPid(1);
715
716 appMgrServiceInner->ApplicationForegrounded(--recordId_);
717 TAG_LOGI(AAFwkTag::TEST, "ApplicationForegrounded_003 end");
718 }
719
720 /**
721 * @tc.name: ApplicationBackgrounded_001
722 * @tc.desc: application backgrounded.
723 * @tc.type: FUNC
724 * @tc.require: issueI5W4S7
725 */
726 HWTEST_F(AppMgrServiceInnerTest, ApplicationBackgrounded_001, TestSize.Level0)
727 {
728 TAG_LOGI(AAFwkTag::TEST, "ApplicationBackgrounded_001 start");
729 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
730 EXPECT_NE(appMgrServiceInner, nullptr);
731 appMgrServiceInner->Init();
732
733 appMgrServiceInner->ApplicationBackgrounded(99);
734
735 BundleInfo info;
736 std::string processName = "test_processName";
737 auto appRecord =
738 appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info);
739 EXPECT_NE(appRecord, nullptr);
740 recordId_ += 1;
741
742 appMgrServiceInner->ApplicationBackgrounded(recordId_);
743
744 appRecord->SetState(ApplicationState::APP_STATE_FOREGROUND);
745 appMgrServiceInner->ApplicationBackgrounded(recordId_);
746
747 TAG_LOGI(AAFwkTag::TEST, "ApplicationBackgrounded_001 end");
748 }
749
750 /**
751 * @tc.name: ApplicationTerminated_001
752 * @tc.desc: application terminated.
753 * @tc.type: FUNC
754 * @tc.require: issueI5W4S7
755 */
756 HWTEST_F(AppMgrServiceInnerTest, ApplicationTerminated_001, TestSize.Level0)
757 {
758 TAG_LOGI(AAFwkTag::TEST, "ApplicationTerminated_001 start");
759 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
760 EXPECT_NE(appMgrServiceInner, nullptr);
761
762 appMgrServiceInner->ApplicationTerminated(99);
763
764 BundleInfo info;
765 std::string processName = "test_processName";
766 auto appRecord =
767 appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info);
768 EXPECT_NE(appRecord, nullptr);
769 recordId_ += 1;
770
771 appMgrServiceInner->ApplicationTerminated(recordId_);
772
773 appRecord->SetKeepAliveEnableState(false);
774 appRecord->SetEmptyKeepAliveAppState(true);
775 appMgrServiceInner->ApplicationTerminated(recordId_);
776
777 appRecord->SetKeepAliveEnableState(true);
778 appRecord->SetEmptyKeepAliveAppState(false);
779 appMgrServiceInner->ApplicationTerminated(recordId_);
780
781 appRecord->SetKeepAliveEnableState(true);
782 appRecord->SetEmptyKeepAliveAppState(true);
783 appMgrServiceInner->ApplicationTerminated(recordId_);
784
785 appRecord->SetKeepAliveEnableState(false);
786 appRecord->SetEmptyKeepAliveAppState(false);
787 appMgrServiceInner->ApplicationTerminated(recordId_);
788
789 appRecord->SetState(ApplicationState::APP_STATE_FOREGROUND);
790 appMgrServiceInner->ApplicationTerminated(recordId_);
791
792 appRecord->SetState(ApplicationState::APP_STATE_BACKGROUND);
793 appMgrServiceInner->ApplicationTerminated(recordId_);
794
795 appMgrServiceInner->appRunningManager_ = nullptr;
796 appMgrServiceInner->ApplicationTerminated(recordId_);
797
798 TAG_LOGI(AAFwkTag::TEST, "ApplicationTerminated_001 end");
799 }
800
801 /**
802 * @tc.name: KillApplication_001
803 * @tc.desc: kill application.
804 * @tc.type: FUNC
805 * @tc.require: issueI5W4S7
806 */
807 HWTEST_F(AppMgrServiceInnerTest, KillApplication_001, TestSize.Level0)
808 {
809 TAG_LOGI(AAFwkTag::TEST, "KillApplication_001 start");
810 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
811 EXPECT_NE(appMgrServiceInner, nullptr);
812
813 std::string bundleName = "test_bundleName";
814 appMgrServiceInner->KillApplication(bundleName);
815
816 appMgrServiceInner->appRunningManager_ = nullptr;
817 appMgrServiceInner->KillApplication(bundleName);
818
819 TAG_LOGI(AAFwkTag::TEST, "KillApplication_001 end");
820 }
821
822 /**
823 * @tc.name: KillApplicationByUid_001
824 * @tc.desc: kill application by uid.
825 * @tc.type: FUNC
826 * @tc.require: issueI5W4S7
827 */
828 HWTEST_F(AppMgrServiceInnerTest, KillApplicationByUid_001, TestSize.Level0)
829 {
830 TAG_LOGI(AAFwkTag::TEST, "KillApplicationByUid_001 start");
831 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
832 EXPECT_NE(appMgrServiceInner, nullptr);
833
834 std::string bundleName = "test_bundleName";
835 appMgrServiceInner->KillApplicationByUid(bundleName, 0);
836
837 appMgrServiceInner->remoteClientManager_->SetBundleManagerHelper(nullptr);
838 appMgrServiceInner->KillApplicationByUid(bundleName, 0);
839
840 appMgrServiceInner->remoteClientManager_ = nullptr;
841 appMgrServiceInner->KillApplicationByUid(bundleName, 0);
842
843 appMgrServiceInner->appRunningManager_ = nullptr;
844 appMgrServiceInner->KillApplicationByUid(bundleName, 0);
845
846 TAG_LOGI(AAFwkTag::TEST, "KillApplicationByUid_001 end");
847 }
848
849 /**
850 * @tc.name: KillApplicationSelf_001
851 * @tc.desc: kill application self.
852 * @tc.type: FUNC
853 * @tc.require: issueI5W4S7
854 */
855 HWTEST_F(AppMgrServiceInnerTest, KillApplicationSelf_001, TestSize.Level0)
856 {
857 TAG_LOGI(AAFwkTag::TEST, "KillApplicationSelf_001 start");
858 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
859 EXPECT_NE(appMgrServiceInner, nullptr);
860
861 EXPECT_EQ(appMgrServiceInner->KillApplicationSelf(), ERR_INVALID_VALUE);
862
863 appMgrServiceInner->appRunningManager_ = nullptr;
864 EXPECT_EQ(appMgrServiceInner->KillApplicationSelf(), ERR_NO_INIT);
865
866 TAG_LOGI(AAFwkTag::TEST, "KillApplicationSelf_001 end");
867 }
868
869 /**
870 * @tc.name: KillApplicationByUserId_001
871 * @tc.desc: kill application by user id.
872 * @tc.type: FUNC
873 * @tc.require: issueI5W4S7
874 */
875 HWTEST_F(AppMgrServiceInnerTest, KillApplicationByUserId_001, TestSize.Level0)
876 {
877 TAG_LOGI(AAFwkTag::TEST, "KillApplicationByUserId_001 start");
878 AAFwk::IsMockSaCall::IsMockSaCallWithPermission();
879 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
880 EXPECT_NE(appMgrServiceInner, nullptr);
881
882 std::string bundleName = "test_bundleName";
883 int result = appMgrServiceInner->KillApplicationByUserId(bundleName, 0, 0);
884 EXPECT_EQ(result, 0);
885
886 appMgrServiceInner->remoteClientManager_->SetBundleManagerHelper(nullptr);
887 appMgrServiceInner->KillApplicationByUserId(bundleName, 0, 0);
888 EXPECT_EQ(result, 0);
889
890 appMgrServiceInner->remoteClientManager_ = nullptr;
891 appMgrServiceInner->KillApplicationByUserId(bundleName, 0, 0);
892 EXPECT_EQ(result, 0);
893
894 appMgrServiceInner->appRunningManager_ = nullptr;
895 appMgrServiceInner->KillApplicationByUserId(bundleName, 0, 0);
896 EXPECT_EQ(result, 0);
897
898 TAG_LOGI(AAFwkTag::TEST, "KillApplicationByUserId_001 end");
899 }
900
901 /**
902 * @tc.name: KillApplicationByUserIdLocked_001
903 * @tc.desc: kill application by user id locked.
904 * @tc.type: FUNC
905 * @tc.require: issueI5W4S7
906 */
907 HWTEST_F(AppMgrServiceInnerTest, KillApplicationByUserIdLocked_001, TestSize.Level0)
908 {
909 TAG_LOGI(AAFwkTag::TEST, "KillApplicationByUserIdLocked_001 start");
910 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
911 EXPECT_NE(appMgrServiceInner, nullptr);
912
913 std::string bundleName = "test_bundleName";
914 int result = appMgrServiceInner->KillApplicationByUserIdLocked(bundleName, 0, 0);
915 EXPECT_EQ(result, 0);
916
917 appMgrServiceInner->remoteClientManager_->SetBundleManagerHelper(nullptr);
918 appMgrServiceInner->KillApplicationByUserIdLocked(bundleName, 0, 0);
919 EXPECT_EQ(result, 0);
920
921 appMgrServiceInner->remoteClientManager_ = nullptr;
922 appMgrServiceInner->KillApplicationByUserIdLocked(bundleName, 0, 0);
923 EXPECT_EQ(result, 0);
924
925 appMgrServiceInner->appRunningManager_ = nullptr;
926 appMgrServiceInner->KillApplicationByUserIdLocked(bundleName, 0, 0);
927 EXPECT_EQ(result, 0);
928
929 TAG_LOGI(AAFwkTag::TEST, "KillApplicationByUserIdLocked_001 end");
930 }
931
932 /**
933 * @tc.name: ClearUpApplicationData_001
934 * @tc.desc: clear up application data.
935 * @tc.type: FUNC
936 * @tc.require: issueI5W4S7
937 */
938 HWTEST_F(AppMgrServiceInnerTest, ClearUpApplicationData_001, TestSize.Level0)
939 {
940 TAG_LOGI(AAFwkTag::TEST, "ClearUpApplicationData_001 start");
941 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
942 EXPECT_NE(appMgrServiceInner, nullptr);
943
944 std::string bundleName = "test_bundleName";
945 appMgrServiceInner->ClearUpApplicationData(bundleName, 0, 0, 0);
946
947 TAG_LOGI(AAFwkTag::TEST, "ClearUpApplicationData_001 end");
948 }
949
950 /**
951 * @tc.name: ClearUpApplicationDataByUserId_001
952 * @tc.desc: clear up application data by user id.
953 * @tc.type: FUNC
954 * @tc.require: issueI5W4S7
955 */
956 HWTEST_F(AppMgrServiceInnerTest, ClearUpApplicationDataByUserId_001, TestSize.Level0)
957 {
958 TAG_LOGI(AAFwkTag::TEST, "ClearUpApplicationDataByUserId_001 start");
959 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
960 EXPECT_NE(appMgrServiceInner, nullptr);
961
962 std::string bundleName = "test_bundleName";
963 appMgrServiceInner->ClearUpApplicationDataByUserId(bundleName, 0, 0, 0, 0);
964 appMgrServiceInner->ClearUpApplicationDataByUserId(bundleName, 1, 0, 0, 0);
965 appMgrServiceInner->ClearUpApplicationDataByUserId(bundleName, 1, 1, 0, 0);
966
967 appMgrServiceInner->appRunningManager_ = nullptr;
968 appMgrServiceInner->ClearUpApplicationDataByUserId(bundleName, 1, 1, 0, 0);
969
970 appMgrServiceInner->remoteClientManager_->SetBundleManagerHelper(nullptr);
971 appMgrServiceInner->ClearUpApplicationDataByUserId(bundleName, 1, 1, 0, 0);
972
973 TAG_LOGI(AAFwkTag::TEST, "ClearUpApplicationDataByUserId_001 end");
974 }
975
976 /**
977 * @tc.name: GetAllRunningProcesses_001
978 * @tc.desc: get all running processes.
979 * @tc.type: FUNC
980 * @tc.require: issueI5W4S7
981 */
982 HWTEST_F(AppMgrServiceInnerTest, GetAllRunningProcesses_001, TestSize.Level0)
983 {
984 TAG_LOGI(AAFwkTag::TEST, "GetAllRunningProcesses_001 start");
985 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
986 EXPECT_NE(appMgrServiceInner, nullptr);
987
988 std::vector<RunningProcessInfo> info;
989 appMgrServiceInner->GetAllRunningProcesses(info);
990
991 TAG_LOGI(AAFwkTag::TEST, "GetAllRunningProcesses_001 end");
992 }
993
994 /**
995 * @tc.name: GetProcessRunningInfosByUserId_001
996 * @tc.desc: get process running infos by user id.
997 * @tc.type: FUNC
998 * @tc.require: issueI5W4S7
999 */
1000 HWTEST_F(AppMgrServiceInnerTest, GetProcessRunningInfosByUserId_001, TestSize.Level0)
1001 {
1002 TAG_LOGI(AAFwkTag::TEST, "GetProcessRunningInfosByUserId_001 start");
1003 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1004 EXPECT_NE(appMgrServiceInner, nullptr);
1005
1006 std::vector<RunningProcessInfo> info;
1007 appMgrServiceInner->GetProcessRunningInfosByUserId(info, 0);
1008
1009 TAG_LOGI(AAFwkTag::TEST, "GetProcessRunningInfosByUserId_001 end");
1010 }
1011
1012 /**
1013 * @tc.name: GetAllRenderProcesses_001
1014 * @tc.desc: get all render processes.
1015 * @tc.type: FUNC
1016 */
1017 HWTEST_F(AppMgrServiceInnerTest, GetAllRenderProcesses_001, TestSize.Level0)
1018 {
1019 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1020 EXPECT_NE(appMgrServiceInner, nullptr);
1021
1022 std::vector<RenderProcessInfo> info;
1023 appMgrServiceInner->GetAllRenderProcesses(info);
1024 }
1025
1026 /**
1027 * @tc.name: GetAllChildrenProcesses_001
1028 * @tc.desc: get all children processes.
1029 * @tc.type: FUNC
1030 */
1031 HWTEST_F(AppMgrServiceInnerTest, GetAllChildrenProcesses_001, TestSize.Level0)
1032 {
1033 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1034 EXPECT_NE(appMgrServiceInner, nullptr);
1035
1036 std::vector<ChildProcessInfo> info;
1037 auto result = appMgrServiceInner->GetAllChildrenProcesses(info);
1038 EXPECT_EQ(result, ERR_OK);
1039 }
1040
1041 /**
1042 * @tc.name: NotifyMemoryLevel_001
1043 * @tc.desc: notify memory level.
1044 * @tc.type: FUNC
1045 * @tc.require: issueI5W4S7
1046 */
1047 HWTEST_F(AppMgrServiceInnerTest, NotifyMemoryLevel_001, TestSize.Level0)
1048 {
1049 TAG_LOGI(AAFwkTag::TEST, "NotifyMemoryLevel_001 start");
1050 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1051 EXPECT_NE(appMgrServiceInner, nullptr);
1052
1053 std::vector<RunningProcessInfo> info;
1054 int result = appMgrServiceInner->NotifyMemoryLevel(0);
1055 EXPECT_EQ(result, ERR_INVALID_VALUE);
1056
1057 result = appMgrServiceInner->NotifyMemoryLevel(1);
1058 EXPECT_EQ(result, ERR_INVALID_VALUE);
1059
1060 result = appMgrServiceInner->NotifyMemoryLevel(2);
1061 EXPECT_EQ(result, ERR_INVALID_VALUE);
1062
1063 result = appMgrServiceInner->NotifyMemoryLevel(3);
1064 EXPECT_EQ(result, ERR_INVALID_VALUE);
1065
1066 appMgrServiceInner->appRunningManager_ = nullptr;
1067 result = appMgrServiceInner->NotifyMemoryLevel(3);
1068 EXPECT_EQ(result, ERR_INVALID_VALUE);
1069
1070 TAG_LOGI(AAFwkTag::TEST, "NotifyMemoryLevel_001 end");
1071 }
1072
1073 /**
1074 * @tc.name: KillProcessByPid_001
1075 * @tc.desc: kill process by pid.
1076 * @tc.type: FUNC
1077 * @tc.require: issueI5W4S7
1078 */
1079 HWTEST_F(AppMgrServiceInnerTest, KillProcessByPid_001, TestSize.Level0)
1080 {
1081 TAG_LOGI(AAFwkTag::TEST, "KillProcessByPid_001 start");
1082 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1083 EXPECT_NE(appMgrServiceInner, nullptr);
1084
1085 int result = appMgrServiceInner->KillProcessByPid(0, "KillProcessByPid_001");
1086 EXPECT_EQ(result, AAFwk::ERR_KILL_PROCESS_NOT_EXIST);
1087
1088 result = appMgrServiceInner->KillProcessByPid(1, "KillProcessByPid_001");
1089 EXPECT_EQ(result, 0);
1090
1091 TAG_LOGI(AAFwkTag::TEST, "KillProcessByPid_001 end");
1092 }
1093
1094 /**
1095 * @tc.name: KillProcessByPid_002
1096 * @tc.desc: kill process by pid.
1097 * @tc.type: FUNC
1098 * @tc.require: issueI5W4S7
1099 */
1100 HWTEST_F(AppMgrServiceInnerTest, KillProcessByPid_002, TestSize.Level0)
1101 {
1102 TAG_LOGI(AAFwkTag::TEST, "KillProcessByPid_002 start");
1103 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1104 EXPECT_NE(appMgrServiceInner, nullptr);
1105 int pid = 0;
1106 std::string processName = "test_processName";
1107 std::shared_ptr<AppRunningRecord> appRecord =
1108 std::make_shared<AppRunningRecord>(applicationInfo_, ++recordId_, processName);
1109 auto appRunningManager = std::make_shared<AppRunningManager>();
1110 auto priorityObject = std::make_shared<PriorityObject>();
1111 priorityObject->SetPid(0);
1112 appRecord->priorityObject_ = priorityObject;
1113 appRunningManager->appRunningRecordMap_.emplace(recordId_, appRecord);
1114
1115 int result = appMgrServiceInner->KillProcessByPid(pid, "KillProcessByPid_002");
1116 EXPECT_EQ(result, AAFwk::ERR_KILL_PROCESS_NOT_EXIST);
1117
1118 TAG_LOGI(AAFwkTag::TEST, "KillProcessByPid_002 end");
1119 }
1120
1121 /**
1122 * @tc.name: ProcessExist_001
1123 * @tc.desc: process exist.
1124 * @tc.type: FUNC
1125 * @tc.require: issueI5W4S7
1126 */
1127 HWTEST_F(AppMgrServiceInnerTest, ProcessExist_001, TestSize.Level0)
1128 {
1129 TAG_LOGI(AAFwkTag::TEST, "ProcessExist_001 start");
1130 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1131 EXPECT_NE(appMgrServiceInner, nullptr);
1132
1133 pid_t pid = 0;
1134 bool result = appMgrServiceInner->ProcessExist(pid);
1135 EXPECT_FALSE(result);
1136
1137 TAG_LOGI(AAFwkTag::TEST, "ProcessExist_001 end");
1138 }
1139
1140 /**
1141 * @tc.name: CreateAppRunningRecord_001
1142 * @tc.desc: create app running record.
1143 * @tc.type: FUNC
1144 * @tc.require: issueI5W4S7
1145 */
1146 HWTEST_F(AppMgrServiceInnerTest, CreateAppRunningRecord_001, TestSize.Level0)
1147 {
1148 TAG_LOGI(AAFwkTag::TEST, "CreateAppRunningRecord_001 start");
1149 OHOS::sptr<IRemoteObject> token = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
1150 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1151 EXPECT_NE(appMgrServiceInner, nullptr);
1152
1153 BundleInfo bundleInfo;
1154 HapModuleInfo hapModuleInfo;
1155 std::shared_ptr<AAFwk::Want> want;
1156 std::string processName = "test_processName";
1157
1158 std::shared_ptr<AppRunningRecord> appRecord = appMgrServiceInner->CreateAppRunningRecord(nullptr, nullptr,
1159 nullptr, nullptr, "", bundleInfo, hapModuleInfo, nullptr, 0);
1160 EXPECT_EQ(appRecord, nullptr);
1161
1162 appRecord = appMgrServiceInner->CreateAppRunningRecord(token, nullptr,
1163 nullptr, nullptr, "", bundleInfo, hapModuleInfo, nullptr, 0);
1164 EXPECT_EQ(appRecord, nullptr);
1165
1166 appRecord = appMgrServiceInner->CreateAppRunningRecord(token, nullptr,
1167 applicationInfo_, nullptr, "", bundleInfo, hapModuleInfo, nullptr, 0);
1168 EXPECT_EQ(appRecord, nullptr);
1169
1170 appRecord = appMgrServiceInner->CreateAppRunningRecord(token, nullptr,
1171 applicationInfo_, abilityInfo_, "", bundleInfo, hapModuleInfo, nullptr, 0);
1172 EXPECT_EQ(appRecord, nullptr);
1173
1174 appRecord = appMgrServiceInner->CreateAppRunningRecord(token, nullptr,
1175 applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, nullptr, 0);
1176 EXPECT_NE(appRecord, nullptr);
1177
1178 appRecord = appMgrServiceInner->CreateAppRunningRecord(token, nullptr,
1179 applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, nullptr, 0);
1180 EXPECT_NE(appRecord, nullptr);
1181
1182 appRecord = appMgrServiceInner->CreateAppRunningRecord(token, nullptr,
1183 applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, nullptr, 0);
1184 EXPECT_NE(appRecord, nullptr);
1185
1186 std::shared_ptr<AppRunningRecord> appRecord1 = appMgrServiceInner->CreateAppRunningRecord(token, nullptr,
1187 nullptr, abilityInfo_, processName, bundleInfo, hapModuleInfo, want, 0);
1188 EXPECT_EQ(appRecord1, nullptr);
1189
1190 std::shared_ptr<AppRunningRecord> appRecord2 = appMgrServiceInner->CreateAppRunningRecord(token, nullptr,
1191 applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want, 0);
1192 EXPECT_NE(appRecord2, nullptr);
1193
1194 want = std::make_shared<Want>();
1195 const std::string COLD_START = "coldStart";
1196 want->SetParam(COLD_START, true);
1197 std::shared_ptr<AppRunningRecord> appRecord3 = appMgrServiceInner->CreateAppRunningRecord(token, nullptr,
1198 applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want, 0);
1199 EXPECT_NE(appRecord3, nullptr);
1200
1201 want->SetParam(COLD_START, false);
1202 std::shared_ptr<AppRunningRecord> appRecord4 = appMgrServiceInner->CreateAppRunningRecord(token, nullptr,
1203 applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want, 0);
1204 EXPECT_NE(appRecord4, nullptr);
1205
1206 appMgrServiceInner->appRunningManager_ = nullptr;
1207 std::shared_ptr<AppRunningRecord> appRecord5 = appMgrServiceInner->CreateAppRunningRecord(token, nullptr,
1208 applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want, 0);
1209 EXPECT_EQ(appRecord5, nullptr);
1210
1211 appMgrServiceInner->appRunningManager_ = nullptr;
1212 want->SetParam("multiThread", false);
1213 std::shared_ptr<AppRunningRecord> appRecord6 = appMgrServiceInner->CreateAppRunningRecord(token, nullptr,
1214 applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want, 0);
1215 EXPECT_EQ(appRecord6, nullptr);
1216
1217 TAG_LOGI(AAFwkTag::TEST, "CreateAppRunningRecord_001 end");
1218 }
1219
1220 /**
1221 * @tc.name: TerminateAbility_001
1222 * @tc.desc: terminate ability.
1223 * @tc.type: FUNC
1224 * @tc.require: issueI5W4S7
1225 */
1226 HWTEST_F(AppMgrServiceInnerTest, TerminateAbility_001, TestSize.Level0)
1227 {
1228 TAG_LOGI(AAFwkTag::TEST, "TerminateAbility_001 start");
1229 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1230 EXPECT_NE(appMgrServiceInner, nullptr);
1231
1232 appMgrServiceInner->TerminateAbility(nullptr, true);
1233 appMgrServiceInner->TerminateAbility(nullptr, false);
1234
1235 OHOS::sptr<IRemoteObject> token = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
1236 appMgrServiceInner->TerminateAbility(token, true);
1237 appMgrServiceInner->TerminateAbility(token, false);
1238
1239 appMgrServiceInner->appRunningManager_ = nullptr;
1240 appMgrServiceInner->TerminateAbility(token, true);
1241
1242 TAG_LOGI(AAFwkTag::TEST, "TerminateAbility_001 end");
1243 }
1244
1245 /**
1246 * @tc.name: UpdateAbilityState_001
1247 * @tc.desc: update ability state.
1248 * @tc.type: FUNC
1249 * @tc.require: issueI5W4S7
1250 */
1251 HWTEST_F(AppMgrServiceInnerTest, UpdateAbilityState_001, TestSize.Level0)
1252 {
1253 TAG_LOGI(AAFwkTag::TEST, "UpdateAbilityState_001 start");
1254 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1255 EXPECT_NE(appMgrServiceInner, nullptr);
1256
1257 appMgrServiceInner->UpdateAbilityState(nullptr, AbilityState::ABILITY_STATE_CREATE);
1258
1259 OHOS::sptr<IRemoteObject> token = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
1260 appMgrServiceInner->UpdateAbilityState(token, AbilityState::ABILITY_STATE_CREATE);
1261
1262 BundleInfo bundleInfo;
1263 HapModuleInfo hapModuleInfo;
1264 std::shared_ptr<AAFwk::Want> want;
1265 std::string processName = "test_processName";
1266 std::shared_ptr<AppRunningRecord> appRecord = appMgrServiceInner->CreateAppRunningRecord(token, nullptr,
1267 applicationInfo_, nullptr, processName, bundleInfo, hapModuleInfo, want, 0);
1268 EXPECT_NE(appRecord, nullptr);
1269 appMgrServiceInner->UpdateAbilityState(token, AbilityState::ABILITY_STATE_CREATE);
1270
1271 OHOS::sptr<IRemoteObject> token1 = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
1272 std::shared_ptr<AppRunningRecord> appRecord1 = appMgrServiceInner->CreateAppRunningRecord(token1, nullptr,
1273 applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want, 0);
1274 EXPECT_NE(appRecord1, nullptr);
1275
1276 appMgrServiceInner->UpdateAbilityState(token1, AbilityState::ABILITY_STATE_READY);
1277 appMgrServiceInner->UpdateAbilityState(token1, AbilityState::ABILITY_STATE_CREATE);
1278
1279 auto abilityRecord1 =
1280 appMgrServiceInner->GetAppRunningRecordByAbilityToken(token1)->GetAbilityRunningRecordByToken(token1);
1281 abilityRecord1->SetState(AbilityState::ABILITY_STATE_TERMINATED);
1282 appMgrServiceInner->UpdateAbilityState(token1, AbilityState::ABILITY_STATE_TERMINATED);
1283
1284 abilityRecord1->SetState(AbilityState::ABILITY_STATE_CONNECTED);
1285 appMgrServiceInner->UpdateAbilityState(token1, AbilityState::ABILITY_STATE_CONNECTED);
1286
1287 abilityRecord1->SetState(AbilityState::ABILITY_STATE_DISCONNECTED);
1288 appMgrServiceInner->UpdateAbilityState(token1, AbilityState::ABILITY_STATE_DISCONNECTED);
1289
1290 abilityRecord1->SetState(AbilityState::ABILITY_STATE_END);
1291 appMgrServiceInner->UpdateAbilityState(token1, AbilityState::ABILITY_STATE_END);
1292
1293 abilityRecord1->SetState(AbilityState::ABILITY_STATE_BACKGROUND);
1294 appMgrServiceInner->UpdateAbilityState(token1, AbilityState::ABILITY_STATE_BACKGROUND);
1295
1296 OHOS::sptr<IRemoteObject> token2 = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
1297 abilityInfo_->type = AbilityType::SERVICE;
1298 std::shared_ptr<AppRunningRecord> appRecord2 = appMgrServiceInner->CreateAppRunningRecord(token2, nullptr,
1299 applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want, 0);
1300 EXPECT_NE(appRecord2, nullptr);
1301 appMgrServiceInner->UpdateAbilityState(token2, AbilityState::ABILITY_STATE_CREATE);
1302
1303 auto abilityRecord2 =
1304 appMgrServiceInner->GetAppRunningRecordByAbilityToken(token2)->GetAbilityRunningRecordByToken(token2);
1305 abilityRecord2->SetState(AbilityState::ABILITY_STATE_TERMINATED);
1306 appMgrServiceInner->UpdateAbilityState(token2, AbilityState::ABILITY_STATE_TERMINATED);
1307
1308 abilityRecord2->SetState(AbilityState::ABILITY_STATE_CONNECTED);
1309 appMgrServiceInner->UpdateAbilityState(token2, AbilityState::ABILITY_STATE_CONNECTED);
1310
1311 abilityRecord2->SetState(AbilityState::ABILITY_STATE_DISCONNECTED);
1312 appMgrServiceInner->UpdateAbilityState(token2, AbilityState::ABILITY_STATE_DISCONNECTED);
1313
1314 abilityRecord2->SetState(AbilityState::ABILITY_STATE_END);
1315 appMgrServiceInner->UpdateAbilityState(token2, AbilityState::ABILITY_STATE_END);
1316
1317 abilityRecord2->SetState(AbilityState::ABILITY_STATE_BACKGROUND);
1318 appMgrServiceInner->UpdateAbilityState(token2, AbilityState::ABILITY_STATE_BACKGROUND);
1319
1320 TAG_LOGI(AAFwkTag::TEST, "UpdateAbilityState_001 end");
1321 }
1322
1323 /**
1324 * @tc.name: UpdateExtensionState_001
1325 * @tc.desc: update extension state.
1326 * @tc.type: FUNC
1327 * @tc.require: issueI5W4S7
1328 */
1329 HWTEST_F(AppMgrServiceInnerTest, UpdateExtensionState_001, TestSize.Level0)
1330 {
1331 TAG_LOGI(AAFwkTag::TEST, "UpdateExtensionState_001 start");
1332 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1333 EXPECT_NE(appMgrServiceInner, nullptr);
1334
1335 appMgrServiceInner->UpdateExtensionState(nullptr, ExtensionState::EXTENSION_STATE_CREATE);
1336
1337 OHOS::sptr<IRemoteObject> token = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
1338 appMgrServiceInner->UpdateExtensionState(token, ExtensionState::EXTENSION_STATE_CREATE);
1339
1340 BundleInfo bundleInfo;
1341 HapModuleInfo hapModuleInfo;
1342 std::shared_ptr<AAFwk::Want> want;
1343 std::string processName = "test_processName";
1344 std::shared_ptr<AppRunningRecord> appRecord = appMgrServiceInner->CreateAppRunningRecord(token, nullptr,
1345 applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want, 0);
1346 EXPECT_NE(appRecord, nullptr);
1347 appMgrServiceInner->UpdateExtensionState(token, ExtensionState::EXTENSION_STATE_CREATE);
1348
1349 TAG_LOGI(AAFwkTag::TEST, "UpdateExtensionState_001 end");
1350 }
1351
1352 /**
1353 * @tc.name: OpenAppSpawnConnection_001
1354 * @tc.desc: open app spawn connection.
1355 * @tc.type: FUNC
1356 * @tc.require: issueI5W4S7
1357 */
1358 HWTEST_F(AppMgrServiceInnerTest, OpenAppSpawnConnection_001, TestSize.Level0)
1359 {
1360 TAG_LOGI(AAFwkTag::TEST, "OpenAppSpawnConnection_001 start");
1361 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1362 EXPECT_NE(appMgrServiceInner, nullptr);
1363
1364 appMgrServiceInner->remoteClientManager_->SetSpawnClient(nullptr);
1365 auto errorCode = appMgrServiceInner->OpenAppSpawnConnection();
1366 EXPECT_EQ(errorCode, ERR_APPEXECFWK_BAD_APPSPAWN_CLIENT);
1367
1368 appMgrServiceInner->remoteClientManager_ = nullptr;
1369 auto errorCode1 = appMgrServiceInner->OpenAppSpawnConnection();
1370 EXPECT_EQ(errorCode1, ERR_INVALID_VALUE);
1371
1372 TAG_LOGI(AAFwkTag::TEST, "OpenAppSpawnConnection_001 end");
1373 }
1374
1375 /**
1376 * @tc.name: CloseAppSpawnConnection_001
1377 * @tc.desc: close app spawn connection.
1378 * @tc.type: FUNC
1379 * @tc.require: issueI5W4S7
1380 */
1381 HWTEST_F(AppMgrServiceInnerTest, CloseAppSpawnConnection_001, TestSize.Level0)
1382 {
1383 TAG_LOGI(AAFwkTag::TEST, "CloseAppSpawnConnection_001 start");
1384 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1385 EXPECT_NE(appMgrServiceInner, nullptr);
1386
1387 appMgrServiceInner->CloseAppSpawnConnection();
1388
1389 appMgrServiceInner->remoteClientManager_ = nullptr;
1390 appMgrServiceInner->CloseAppSpawnConnection();
1391
1392 TAG_LOGI(AAFwkTag::TEST, "CloseAppSpawnConnection_001 end");
1393 }
1394
1395 /**
1396 * @tc.name: QueryAppSpawnConnectionState_001
1397 * @tc.desc: query app spawn connection.
1398 * @tc.type: FUNC
1399 * @tc.require: issueI5W4S7
1400 */
1401 HWTEST_F(AppMgrServiceInnerTest, QueryAppSpawnConnectionState_001, TestSize.Level0)
1402 {
1403 TAG_LOGI(AAFwkTag::TEST, "QueryAppSpawnConnectionState_001 start");
1404 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1405 EXPECT_NE(appMgrServiceInner, nullptr);
1406
1407 auto connectionState = appMgrServiceInner->QueryAppSpawnConnectionState();
1408 EXPECT_EQ(connectionState, SpawnConnectionState::STATE_NOT_CONNECT);
1409
1410 appMgrServiceInner->remoteClientManager_->SetSpawnClient(nullptr);
1411 connectionState = appMgrServiceInner->QueryAppSpawnConnectionState();
1412 EXPECT_EQ(connectionState, SpawnConnectionState::STATE_NOT_CONNECT);
1413
1414
1415 appMgrServiceInner->remoteClientManager_ = nullptr;
1416 connectionState = appMgrServiceInner->QueryAppSpawnConnectionState();
1417 EXPECT_EQ(connectionState, SpawnConnectionState::STATE_NOT_CONNECT);
1418
1419 TAG_LOGI(AAFwkTag::TEST, "QueryAppSpawnConnectionState_001 end");
1420 }
1421
1422 /**
1423 * @tc.name: SetAppSpawnClient_001
1424 * @tc.desc: set app spawn client.
1425 * @tc.type: FUNC
1426 * @tc.require: issueI5W4S7
1427 */
1428 HWTEST_F(AppMgrServiceInnerTest, SetAppSpawnClient_001, TestSize.Level0)
1429 {
1430 TAG_LOGI(AAFwkTag::TEST, "SetAppSpawnClient_001 start");
1431 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1432 EXPECT_NE(appMgrServiceInner, nullptr);
1433
1434 std::shared_ptr<AppSpawnClient> spawnClient;
1435 appMgrServiceInner->SetAppSpawnClient(spawnClient);
1436
1437 appMgrServiceInner->remoteClientManager_ = nullptr;
1438 appMgrServiceInner->SetAppSpawnClient(spawnClient);
1439
1440 TAG_LOGI(AAFwkTag::TEST, "SetAppSpawnClient_001 end");
1441 }
1442
1443 /**
1444 * @tc.name: SetBundleManager_001
1445 * @tc.desc: set bundle manager.
1446 * @tc.type: FUNC
1447 * @tc.require: issueI5W4S7
1448 */
1449 HWTEST_F(AppMgrServiceInnerTest, SetBundleManager_001, TestSize.Level0)
1450 {
1451 TAG_LOGI(AAFwkTag::TEST, "SetBundleManager_001 start");
1452 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1453 EXPECT_NE(appMgrServiceInner, nullptr);
1454
1455 std::shared_ptr<BundleMgrHelper> bundleManager;
1456 appMgrServiceInner->SetBundleManagerHelper(bundleManager);
1457
1458 appMgrServiceInner->remoteClientManager_ = nullptr;
1459 appMgrServiceInner->SetBundleManagerHelper(bundleManager);
1460
1461 TAG_LOGI(AAFwkTag::TEST, "SetBundleManager_001 end");
1462 }
1463
1464 /**
1465 * @tc.name: RegisterAppStateCallback_001
1466 * @tc.desc: register app state call back.
1467 * @tc.type: FUNC
1468 * @tc.require: issueI5W4S7
1469 */
1470 HWTEST_F(AppMgrServiceInnerTest, RegisterAppStateCallback_001, TestSize.Level0)
1471 {
1472 TAG_LOGI(AAFwkTag::TEST, "RegisterAppStateCallback_001 start");
1473 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1474 EXPECT_NE(appMgrServiceInner, nullptr);
1475
1476 appMgrServiceInner->RegisterAppStateCallback(nullptr);
1477
1478 sptr<IAppStateCallback> callback;
1479 appMgrServiceInner->RegisterAppStateCallback(callback);
1480
1481 TAG_LOGI(AAFwkTag::TEST, "RegisterAppStateCallback_001 end");
1482 }
1483
1484 /**
1485 * @tc.name: AbilityBehaviorAnalysis_001
1486 * @tc.desc: ability behavior analysis.
1487 * @tc.type: FUNC
1488 * @tc.require: issueI5W4S7
1489 */
1490 HWTEST_F(AppMgrServiceInnerTest, AbilityBehaviorAnalysis_001, TestSize.Level0)
1491 {
1492 TAG_LOGI(AAFwkTag::TEST, "AbilityBehaviorAnalysis_001 start");
1493 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1494 EXPECT_NE(appMgrServiceInner, nullptr);
1495
1496 appMgrServiceInner->AbilityBehaviorAnalysis(nullptr, nullptr, 0, 0, 0);
1497
1498 OHOS::sptr<IRemoteObject> token = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
1499 appMgrServiceInner->AbilityBehaviorAnalysis(token, nullptr, 0, 0, 0);
1500
1501 BundleInfo bundleInfo;
1502 HapModuleInfo hapModuleInfo;
1503 std::shared_ptr<AAFwk::Want> want;
1504 std::string processName = "test_processName";
1505 std::shared_ptr<AppRunningRecord> appRecord = appMgrServiceInner->CreateAppRunningRecord(token, nullptr,
1506 applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want, 0);
1507 EXPECT_NE(appRecord, nullptr);
1508 appMgrServiceInner->AbilityBehaviorAnalysis(token, nullptr, 0, 0, 0);
1509
1510 OHOS::sptr<IRemoteObject> preToken = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
1511 appMgrServiceInner->AbilityBehaviorAnalysis(token, preToken, 0, 0, 0);
1512
1513 TAG_LOGI(AAFwkTag::TEST, "AbilityBehaviorAnalysis_001 end");
1514 }
1515
1516 /**
1517 * @tc.name: KillProcessByAbilityToken_001
1518 * @tc.desc: kill process by ability token.
1519 * @tc.type: FUNC
1520 * @tc.require: issueI5W4S7
1521 */
1522 HWTEST_F(AppMgrServiceInnerTest, KillProcessByAbilityToken_001, TestSize.Level0)
1523 {
1524 TAG_LOGI(AAFwkTag::TEST, "KillProcessByAbilityToken_001 start");
1525 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1526 EXPECT_NE(appMgrServiceInner, nullptr);
1527
1528 appMgrServiceInner->KillProcessByAbilityToken(nullptr);
1529
1530 OHOS::sptr<IRemoteObject> token = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
1531 appMgrServiceInner->KillProcessByAbilityToken(token);
1532
1533 BundleInfo bundleInfo;
1534 HapModuleInfo hapModuleInfo;
1535 std::shared_ptr<AAFwk::Want> want;
1536 std::string processName = "test_processName";
1537 std::shared_ptr<AppRunningRecord> appRecord = appMgrServiceInner->CreateAppRunningRecord(token, nullptr,
1538 applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want, 0);
1539 EXPECT_NE(appRecord, nullptr);
1540 appMgrServiceInner->KillProcessByAbilityToken(token);
1541
1542 appRecord->SetKeepAliveEnableState(true);
1543 appRecord->SetEmptyKeepAliveAppState(true);
1544 appMgrServiceInner->KillProcessByAbilityToken(token);
1545
1546 TAG_LOGI(AAFwkTag::TEST, "KillProcessByAbilityToken_001 end");
1547 }
1548
1549 /**
1550 * @tc.name: KillProcessesByUserId_001
1551 * @tc.desc: kill process by user id.
1552 * @tc.type: FUNC
1553 * @tc.require: issueI5W4S7
1554 */
1555 HWTEST_F(AppMgrServiceInnerTest, KillProcessesByUserId_001, TestSize.Level0)
1556 {
1557 TAG_LOGI(AAFwkTag::TEST, "KillProcessesByUserId_001 start");
1558 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1559 EXPECT_NE(appMgrServiceInner, nullptr);
1560
1561 appMgrServiceInner->KillProcessesByUserId(0);
1562
1563 appMgrServiceInner->appRunningManager_ = nullptr;
1564 appMgrServiceInner->KillProcessesByUserId(0);
1565
1566 TAG_LOGI(AAFwkTag::TEST, "KillProcessesByUserId_001 end");
1567 }
1568
1569 /**
1570 * @tc.name: StartAbility_001
1571 * @tc.desc: start ability.
1572 * @tc.type: FUNC
1573 * @tc.require: issueI5W4S7
1574 */
1575 HWTEST_F(AppMgrServiceInnerTest, StartAbility_001, TestSize.Level0)
1576 {
1577 TAG_LOGI(AAFwkTag::TEST, "StartAbility_001 start");
1578 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1579 EXPECT_NE(appMgrServiceInner, nullptr);
1580
1581 HapModuleInfo hapModuleInfo;
1582 std::shared_ptr<AAFwk::Want> want;
1583 std::shared_ptr<AppRunningRecord> appRecord;
1584 appMgrServiceInner->StartAbility(nullptr, nullptr, abilityInfo_, nullptr, hapModuleInfo, nullptr, 0);
1585 appMgrServiceInner->StartAbility(nullptr, nullptr, abilityInfo_, appRecord, hapModuleInfo, nullptr, 0);
1586 appMgrServiceInner->StartAbility(nullptr, nullptr, abilityInfo_, appRecord, hapModuleInfo, want, 0);
1587
1588 OHOS::sptr<IRemoteObject> token = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
1589 OHOS::sptr<IRemoteObject> preToken = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
1590 appMgrServiceInner->StartAbility(token, nullptr, abilityInfo_, appRecord, hapModuleInfo, want, 0);
1591 appMgrServiceInner->StartAbility(nullptr, preToken, abilityInfo_, appRecord, hapModuleInfo, want, 0);
1592 appMgrServiceInner->StartAbility(token, preToken, abilityInfo_, appRecord, hapModuleInfo, want, 0);
1593
1594 BundleInfo bundleInfo;
1595 std::string processName = "test_processName";
1596 appRecord = appMgrServiceInner->CreateAppRunningRecord(token, nullptr,
1597 applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want, 0);
1598 EXPECT_NE(appRecord, nullptr);
1599 appMgrServiceInner->StartAbility(token, nullptr, abilityInfo_, appRecord, hapModuleInfo, want, 0);
1600 appMgrServiceInner->StartAbility(token, preToken, abilityInfo_, appRecord, hapModuleInfo, want, 0);
1601
1602 abilityInfo_->applicationInfo.name = "hiservcie";
1603 abilityInfo_->applicationInfo.bundleName = "com.ix.hiservcie";
1604 appMgrServiceInner->StartAbility(token, preToken, abilityInfo_, appRecord, hapModuleInfo, want, 0);
1605
1606 TAG_LOGI(AAFwkTag::TEST, "StartAbility_001 end");
1607 }
1608
1609 /**
1610 * @tc.name: GetAppRunningRecordByAbilityToken_001
1611 * @tc.desc: get app running record by ability token.
1612 * @tc.type: FUNC
1613 * @tc.require: issueI5W4S7
1614 */
1615 HWTEST_F(AppMgrServiceInnerTest, GetAppRunningRecordByAbilityToken_001, TestSize.Level0)
1616 {
1617 TAG_LOGI(AAFwkTag::TEST, "GetAppRunningRecordByAbilityToken_001 start");
1618 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1619 EXPECT_NE(appMgrServiceInner, nullptr);
1620
1621 OHOS::sptr<IRemoteObject> token = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
1622 appMgrServiceInner->GetAppRunningRecordByAbilityToken(token);
1623
1624 appMgrServiceInner->appRunningManager_ = nullptr;
1625 appMgrServiceInner->GetAppRunningRecordByAbilityToken(token);
1626
1627 TAG_LOGI(AAFwkTag::TEST, "GetAppRunningRecordByAbilityToken_001 end");
1628 }
1629
1630 /**
1631 * @tc.name: AbilityTerminated_001
1632 * @tc.desc: ability terminated.
1633 * @tc.type: FUNC
1634 * @tc.require: issueI5W4S7
1635 */
1636 HWTEST_F(AppMgrServiceInnerTest, AbilityTerminated_001, TestSize.Level0)
1637 {
1638 TAG_LOGI(AAFwkTag::TEST, "AbilityTerminated_001 start");
1639 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1640 EXPECT_NE(appMgrServiceInner, nullptr);
1641
1642 appMgrServiceInner->AbilityTerminated(nullptr);
1643
1644 OHOS::sptr<IRemoteObject> token = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
1645 appMgrServiceInner->AbilityTerminated(token);
1646
1647 BundleInfo bundleInfo;
1648 HapModuleInfo hapModuleInfo;
1649 std::shared_ptr<AAFwk::Want> want;
1650 std::string processName = "test_processName";
1651 std::shared_ptr<AppRunningRecord> appRecord = appMgrServiceInner->CreateAppRunningRecord(token, nullptr,
1652 applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want, 0);
1653 EXPECT_NE(appRecord, nullptr);
1654 appMgrServiceInner->AbilityTerminated(token);
1655
1656 TAG_LOGI(AAFwkTag::TEST, "AbilityTerminated_001 end");
1657 }
1658
1659 /**
1660 * @tc.name: GetAppRunningRecordByAppRecordId_001
1661 * @tc.desc: get app running record by app record id.
1662 * @tc.type: FUNC
1663 * @tc.require: issueI5W4S7
1664 */
1665 HWTEST_F(AppMgrServiceInnerTest, GetAppRunningRecordByAppRecordId_001, TestSize.Level0)
1666 {
1667 TAG_LOGI(AAFwkTag::TEST, "GetAppRunningRecordByAppRecordId_001 start");
1668 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1669 EXPECT_NE(appMgrServiceInner, nullptr);
1670
1671 appMgrServiceInner->GetAppRunningRecordByAppRecordId(0);
1672
1673 appMgrServiceInner->appRunningManager_ = nullptr;
1674 appMgrServiceInner->GetAppRunningRecordByAppRecordId(0);
1675
1676 TAG_LOGI(AAFwkTag::TEST, "GetAppRunningRecordByAppRecordId_001 end");
1677 }
1678
1679 /**
1680 * @tc.name: OnAppStateChanged_001
1681 * @tc.desc: on app state changed.
1682 * @tc.type: FUNC
1683 * @tc.require: issueI5W4S7
1684 */
1685 HWTEST_F(AppMgrServiceInnerTest, OnAppStateChanged_001, TestSize.Level0)
1686 {
1687 TAG_LOGI(AAFwkTag::TEST, "OnAppStateChanged_001 start");
1688 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1689 EXPECT_NE(appMgrServiceInner, nullptr);
1690
1691 appMgrServiceInner->OnAppStateChanged(nullptr, ApplicationState::APP_STATE_CREATE, true, false);
1692 appMgrServiceInner->OnAppStateChanged(nullptr, ApplicationState::APP_STATE_CREATE, false, false);
1693
1694 BundleInfo bundleInfo;
1695 std::string processName = "test_processName";
1696 std::shared_ptr<AppRunningRecord> appRecord =
1697 appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo);
1698 EXPECT_NE(appRecord, nullptr);
1699 appMgrServiceInner->OnAppStateChanged(appRecord, ApplicationState::APP_STATE_CREATE, true, false);
1700
1701 sptr<MockAppStateCallback> mockCallback(new MockAppStateCallback());
1702 EXPECT_CALL(*mockCallback, OnAppStateChanged(_)).Times(2);
1703 sptr<IAppStateCallback> callback1 = iface_cast<IAppStateCallback>(mockCallback);
1704 appMgrServiceInner->appStateCallbacks_.push_back({ callback1, 100 });
1705 appMgrServiceInner->OnAppStateChanged(appRecord, ApplicationState::APP_STATE_CREATE, true, false);
1706
1707 sptr<IAppStateCallback> callback;
1708 appMgrServiceInner->appStateCallbacks_.push_back({ callback, 100 });
1709 appMgrServiceInner->OnAppStateChanged(appRecord, ApplicationState::APP_STATE_CREATE, true, false);
1710
1711 TAG_LOGI(AAFwkTag::TEST, "OnAppStateChanged_001 end");
1712 }
1713
1714 /**
1715 * @tc.name: OnAbilityStateChanged_001
1716 * @tc.desc: on ability state changed.
1717 * @tc.type: FUNC
1718 * @tc.require: issueI5W4S7
1719 */
1720 HWTEST_F(AppMgrServiceInnerTest, OnAbilityStateChanged_001, TestSize.Level0)
1721 {
1722 TAG_LOGI(AAFwkTag::TEST, "OnAbilityStateChanged_001 start");
1723 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1724 EXPECT_NE(appMgrServiceInner, nullptr);
1725
1726 appMgrServiceInner->OnAbilityStateChanged(nullptr, AbilityState::ABILITY_STATE_CREATE);
1727
1728 sptr<IRemoteObject> token = new MockAbilityToken();
1729 std::shared_ptr<AbilityRunningRecord> abilityRunningRecord =
1730 std::make_shared<AbilityRunningRecord>(abilityInfo_, token, 0);
1731 appMgrServiceInner->OnAbilityStateChanged(abilityRunningRecord, AbilityState::ABILITY_STATE_CREATE);
1732
1733 sptr<MockAppStateCallback> mockCallback(new MockAppStateCallback());
1734 EXPECT_CALL(*mockCallback, OnAbilityRequestDone(_, _)).Times(2);
1735 sptr<IAppStateCallback> callback1 = iface_cast<IAppStateCallback>(mockCallback);
1736 appMgrServiceInner->appStateCallbacks_.push_back({ callback1, 100 });
1737 appMgrServiceInner->OnAbilityStateChanged(abilityRunningRecord, AbilityState::ABILITY_STATE_CREATE);
1738
1739 sptr<IAppStateCallback> callback;
1740 appMgrServiceInner->appStateCallbacks_.push_back({ callback, 100 });
1741 appMgrServiceInner->OnAbilityStateChanged(abilityRunningRecord, AbilityState::ABILITY_STATE_CREATE);
1742
1743 TAG_LOGI(AAFwkTag::TEST, "OnAbilityStateChanged_001 end");
1744 }
1745
1746 /**
1747 * @tc.name: StartProcess_001
1748 * @tc.desc: start process.
1749 * @tc.type: FUNC
1750 * @tc.require: issueI5W4S7
1751 */
1752 HWTEST_F(AppMgrServiceInnerTest, StartProcess_001, TestSize.Level0)
1753 {
1754 TAG_LOGI(AAFwkTag::TEST, "StartProcess_001 start");
1755 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1756 EXPECT_NE(appMgrServiceInner, nullptr);
1757
1758 BundleInfo bundleInfo;
1759 std::string appName = "test_appName";
1760 std::string processName = "test_processName";
1761 std::string bundleName = "test_bundleName";
1762 sptr<IRemoteObject> token = new MockAbilityToken();
1763 std::shared_ptr<AppRunningRecord> appRecord =
1764 appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo);
1765 EXPECT_NE(appRecord, nullptr);
1766 appMgrServiceInner->StartProcess(appName, processName, 0, nullptr, 0, bundleInfo, bundleName, 0);
1767 appMgrServiceInner->StartProcess(appName, processName, 0, appRecord, 0, bundleInfo, bundleName, 0);
1768
1769 TAG_LOGI(AAFwkTag::TEST, "StartProcess_001 end");
1770 }
1771
1772 /**
1773 * @tc.name: OnRemoteDied_001
1774 * @tc.desc: on remote died.
1775 * @tc.type: FUNC
1776 * @tc.require: issueI5W4S7
1777 */
1778 HWTEST_F(AppMgrServiceInnerTest, OnRemoteDied_001, TestSize.Level0)
1779 {
1780 TAG_LOGI(AAFwkTag::TEST, "OnRemoteDied_001 start");
1781 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1782 EXPECT_NE(appMgrServiceInner, nullptr);
1783
1784 sptr<IRemoteObject> remoteObject;
1785 appMgrServiceInner->OnRemoteDied(remoteObject, true);
1786 appMgrServiceInner->OnRemoteDied(remoteObject, false);
1787
1788 TAG_LOGI(AAFwkTag::TEST, "OnRemoteDied_001 end");
1789 }
1790
1791 /**
1792 * @tc.name: ClearAppRunningData_001
1793 * @tc.desc: clear app running data.
1794 * @tc.type: FUNC
1795 */
1796 HWTEST_F(AppMgrServiceInnerTest, ClearAppRunningData_001, TestSize.Level0)
1797 {
1798 TAG_LOGI(AAFwkTag::TEST, "ClearAppRunningData_001 start");
1799 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1800 EXPECT_NE(appMgrServiceInner, nullptr);
1801
1802 appMgrServiceInner->ClearAppRunningData(nullptr, true);
1803 TAG_LOGI(AAFwkTag::TEST, "ClearAppRunningData_001 end");
1804 }
1805
1806 /**
1807 * @tc.name: ClearAppRunningData_002
1808 * @tc.desc: clear app running data.
1809 * @tc.type: FUNC
1810 */
1811 HWTEST_F(AppMgrServiceInnerTest, ClearAppRunningData_002, TestSize.Level0)
1812 {
1813 TAG_LOGI(AAFwkTag::TEST, "ClearAppRunningData_002 start");
1814 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1815 EXPECT_NE(appMgrServiceInner, nullptr);
1816 BundleInfo info;
1817 std::string processName = "test_processName";
1818 std::shared_ptr<AppRunningRecord> appRecord =
1819 appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info);
1820 appMgrServiceInner->ClearAppRunningData(appRecord, true);
1821 TAG_LOGI(AAFwkTag::TEST, "ClearAppRunningData_002 end");
1822 }
1823
1824 /**
1825 * @tc.name: ClearAppRunningData_003
1826 * @tc.desc: clear app running data.
1827 * @tc.type: FUNC
1828 */
1829 HWTEST_F(AppMgrServiceInnerTest, ClearAppRunningData_003, TestSize.Level0)
1830 {
1831 TAG_LOGI(AAFwkTag::TEST, "ClearAppRunningData_003 start");
1832 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1833 EXPECT_NE(appMgrServiceInner, nullptr);
1834 BundleInfo info;
1835 std::string processName = "test_processName";
1836 std::shared_ptr<AppRunningRecord> appRecord =
1837 appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info);
1838 appMgrServiceInner->ClearAppRunningData(appRecord, false);
1839 TAG_LOGI(AAFwkTag::TEST, "ClearAppRunningData_003 end");
1840 }
1841
1842 /**
1843 * @tc.name: ClearAppRunningData_004
1844 * @tc.desc: clear app running data.
1845 * @tc.type: FUNC
1846 */
1847 HWTEST_F(AppMgrServiceInnerTest, ClearAppRunningData_004, TestSize.Level0)
1848 {
1849 TAG_LOGI(AAFwkTag::TEST, "ClearAppRunningData_004 start");
1850 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1851 EXPECT_NE(appMgrServiceInner, nullptr);
1852
1853 appMgrServiceInner->ClearAppRunningData(nullptr, false);
1854 TAG_LOGI(AAFwkTag::TEST, "ClearAppRunningData_004 end");
1855 }
1856
1857 /**
1858 * @tc.name: HandleTimeOut_001
1859 * @tc.desc: handle time out.
1860 * @tc.type: FUNC
1861 * @tc.require: issueI5W4S7
1862 */
1863 HWTEST_F(AppMgrServiceInnerTest, HandleTimeOut_001, TestSize.Level0)
1864 {
1865 TAG_LOGI(AAFwkTag::TEST, "HandleTimeOut_001 start");
1866 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1867 EXPECT_NE(appMgrServiceInner, nullptr);
1868
1869 AAFwk::EventWrap innerEvent(0);
1870 appMgrServiceInner->HandleTimeOut(innerEvent);
1871
1872 appMgrServiceInner->appRunningManager_ = nullptr;
1873 appMgrServiceInner->HandleTimeOut(innerEvent);
1874
1875 TAG_LOGI(AAFwkTag::TEST, "HandleTimeOut_001 end");
1876 }
1877
1878 /**
1879 * @tc.name: HandleAbilityAttachTimeOut_001
1880 * @tc.desc: handle ability attach time out.
1881 * @tc.type: FUNC
1882 * @tc.require: issueI5W4S7
1883 */
1884 HWTEST_F(AppMgrServiceInnerTest, HandleAbilityAttachTimeOut_001, TestSize.Level0)
1885 {
1886 TAG_LOGI(AAFwkTag::TEST, "HandleAbilityAttachTimeOut_001 start");
1887 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1888 EXPECT_NE(appMgrServiceInner, nullptr);
1889
1890 appMgrServiceInner->HandleAbilityAttachTimeOut(nullptr);
1891
1892 appMgrServiceInner->appRunningManager_ = nullptr;
1893 appMgrServiceInner->HandleAbilityAttachTimeOut(nullptr);
1894
1895 TAG_LOGI(AAFwkTag::TEST, "HandleAbilityAttachTimeOut_001 end");
1896 }
1897
1898 /**
1899 * @tc.name: PrepareTerminate_001
1900 * @tc.desc: prepare terminate.
1901 * @tc.type: FUNC
1902 * @tc.require: issueI5W4S7
1903 */
1904 HWTEST_F(AppMgrServiceInnerTest, PrepareTerminate_001, TestSize.Level0)
1905 {
1906 TAG_LOGI(AAFwkTag::TEST, "PrepareTerminate_001 start");
1907 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1908 EXPECT_NE(appMgrServiceInner, nullptr);
1909
1910 appMgrServiceInner->PrepareTerminate(nullptr);
1911
1912 appMgrServiceInner->appRunningManager_ = nullptr;
1913 appMgrServiceInner->PrepareTerminate(nullptr);
1914
1915 TAG_LOGI(AAFwkTag::TEST, "PrepareTerminate_001 end");
1916 }
1917
1918 /**
1919 * @tc.name: HandleTerminateApplicationTimeOut_001
1920 * @tc.desc: handle terminate application time out.
1921 * @tc.type: FUNC
1922 * @tc.require: issueI5W4S7
1923 */
1924 HWTEST_F(AppMgrServiceInnerTest, HandleTerminateApplicationTimeOut_001, TestSize.Level0)
1925 {
1926 TAG_LOGI(AAFwkTag::TEST, "HandleTerminateApplicationTimeOut_001 start");
1927 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1928 EXPECT_NE(appMgrServiceInner, nullptr);
1929
1930 appMgrServiceInner->HandleTerminateApplicationTimeOut(0);
1931
1932 BundleInfo bundleInfo;
1933 std::string appName = "test_appName";
1934 std::string processName = "test_processName";
1935 std::string bundleName = "test_bundleName";
1936 sptr<IRemoteObject> token = new MockAbilityToken();
1937 std::shared_ptr<AppRunningRecord> appRecord =
1938 appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo);
1939 EXPECT_NE(appRecord, nullptr);
1940 appRecord->eventId_ = 0;
1941 appMgrServiceInner->HandleTerminateApplicationTimeOut(0);
1942
1943 pid_t pid = 1;
1944 appRecord->GetPriorityObject()->SetPid(pid);
1945 appMgrServiceInner->HandleTerminateApplicationTimeOut(0);
1946
1947 appMgrServiceInner->taskHandler_ = nullptr;
1948 appMgrServiceInner->HandleTerminateApplicationTimeOut(0);
1949
1950 appMgrServiceInner->appRunningManager_ = nullptr;
1951 appMgrServiceInner->HandleTerminateApplicationTimeOut(0);
1952
1953 TAG_LOGI(AAFwkTag::TEST, "HandleTerminateApplicationTimeOut_001 end");
1954 }
1955
1956 /**
1957 * @tc.name: HandleAddAbilityStageTimeOut_001
1958 * @tc.desc: handle add ability stage time out.
1959 * @tc.type: FUNC
1960 * @tc.require: issueI5W4S7
1961 */
1962 HWTEST_F(AppMgrServiceInnerTest, HandleAddAbilityStageTimeOut_001, TestSize.Level0)
1963 {
1964 TAG_LOGI(AAFwkTag::TEST, "HandleAddAbilityStageTimeOut_001 start");
1965 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
1966 EXPECT_NE(appMgrServiceInner, nullptr);
1967
1968 appMgrServiceInner->HandleAddAbilityStageTimeOut(0);
1969
1970 BundleInfo bundleInfo;
1971 std::string appName = "test_appName";
1972 std::string processName = "test_processName";
1973 std::string bundleName = "test_bundleName";
1974 sptr<IRemoteObject> token = new MockAbilityToken();
1975 std::shared_ptr<AppRunningRecord> appRecord =
1976 appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo);
1977 EXPECT_NE(appRecord, nullptr);
1978 appRecord->eventId_ = 0;
1979 appMgrServiceInner->HandleAddAbilityStageTimeOut(0);
1980
1981 appRecord->specifiedRequestId_ = 1;
1982 appMgrServiceInner->HandleAddAbilityStageTimeOut(0);
1983
1984 sptr<IStartSpecifiedAbilityResponse> response;
1985 appMgrServiceInner->startSpecifiedAbilityResponse_ = response;
1986 appMgrServiceInner->HandleAddAbilityStageTimeOut(0);
1987
1988 appMgrServiceInner->appRunningManager_ = nullptr;
1989 appMgrServiceInner->HandleAddAbilityStageTimeOut(0);
1990
1991 TAG_LOGI(AAFwkTag::TEST, "HandleAddAbilityStageTimeOut_001 end");
1992 }
1993
1994 /**
1995 * @tc.name: GetRunningProcessInfoByToken_001
1996 * @tc.desc: get running process info by token.
1997 * @tc.type: FUNC
1998 * @tc.require: issueI5W4S7
1999 */
2000 HWTEST_F(AppMgrServiceInnerTest, GetRunningProcessInfoByToken_001, TestSize.Level0)
2001 {
2002 TAG_LOGI(AAFwkTag::TEST, "GetRunningProcessInfoByToken_001 start");
2003 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2004 EXPECT_NE(appMgrServiceInner, nullptr);
2005
2006 AppExecFwk::RunningProcessInfo info;
2007 appMgrServiceInner->GetRunningProcessInfoByToken(nullptr, info);
2008
2009 appMgrServiceInner->appRunningManager_ = nullptr;
2010 appMgrServiceInner->GetRunningProcessInfoByToken(nullptr, info);
2011
2012 TAG_LOGI(AAFwkTag::TEST, "GetRunningProcessInfoByToken_001 end");
2013 }
2014
2015 /**
2016 * @tc.name: GetRunningProcessInfoByPid_001
2017 * @tc.desc: get running process info by pid.
2018 * @tc.type: FUNC
2019 * @tc.require: issueI5W4S7
2020 */
2021 HWTEST_F(AppMgrServiceInnerTest, GetRunningProcessInfoByPid_001, TestSize.Level0)
2022 {
2023 TAG_LOGI(AAFwkTag::TEST, "GetRunningProcessInfoByPid_001 start");
2024 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2025 EXPECT_NE(appMgrServiceInner, nullptr);
2026
2027 AppExecFwk::RunningProcessInfo info;
2028 appMgrServiceInner->GetRunningProcessInfoByPid(0, info);
2029
2030 appMgrServiceInner->appRunningManager_ = nullptr;
2031 appMgrServiceInner->GetRunningProcessInfoByPid(0, info);
2032
2033 TAG_LOGI(AAFwkTag::TEST, "GetRunningProcessInfoByPid_001 end");
2034 }
2035
2036 /**
2037 * @tc.name: CheckGetRunningInfoPermission_001
2038 * @tc.desc: check get running info permission.
2039 * @tc.type: FUNC
2040 * @tc.require: issueI5W4S7
2041 */
2042 HWTEST_F(AppMgrServiceInnerTest, CheckGetRunningInfoPermission_001, TestSize.Level0)
2043 {
2044 TAG_LOGI(AAFwkTag::TEST, "CheckGetRunningInfoPermission_001 start");
2045 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2046 EXPECT_NE(appMgrServiceInner, nullptr);
2047
2048 appMgrServiceInner->CheckGetRunningInfoPermission();
2049
2050 appMgrServiceInner->appRunningManager_ = nullptr;
2051 appMgrServiceInner->CheckGetRunningInfoPermission();
2052
2053 TAG_LOGI(AAFwkTag::TEST, "CheckGetRunningInfoPermission_001 end");
2054 }
2055
2056 /**
2057 * @tc.name: IsMemorySizeSufficent_001
2058 * @tc.desc: check get running info permission.
2059 * @tc.type: FUNC
2060 * @tc.require: issueI5W4S7
2061 */
2062 HWTEST_F(AppMgrServiceInnerTest, IsMemorySizeSufficent_001, TestSize.Level0)
2063 {
2064 TAG_LOGI(AAFwkTag::TEST, "IsMemorySizeSufficent start");
2065 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2066 EXPECT_NE(appMgrServiceInner, nullptr);
2067
2068 appMgrServiceInner->IsMemorySizeSufficent();
2069
2070 appMgrServiceInner->appRunningManager_ = nullptr;
2071 appMgrServiceInner->IsMemorySizeSufficent();
2072
2073 TAG_LOGI(AAFwkTag::TEST, "IsMemorySizeSufficent_001 end");
2074 }
2075
2076 /**
2077 * @tc.name: LoadResidentProcess_001
2078 * @tc.desc: load resident process.
2079 * @tc.type: FUNC
2080 * @tc.require: issueI5W4S7
2081 */
2082 HWTEST_F(AppMgrServiceInnerTest, LoadResidentProcess_001, TestSize.Level0)
2083 {
2084 TAG_LOGI(AAFwkTag::TEST, "LoadResidentProcess_001 start");
2085 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2086 EXPECT_NE(appMgrServiceInner, nullptr);
2087
2088 std::vector<BundleInfo> infos;
2089 appMgrServiceInner->LoadResidentProcess(infos);
2090
2091 TAG_LOGI(AAFwkTag::TEST, "LoadResidentProcess_001 end");
2092 }
2093
2094 /**
2095 * @tc.name: StartResidentProcess_001
2096 * @tc.desc: start resident process.
2097 * @tc.type: FUNC
2098 * @tc.require: issueI5W4S7
2099 */
2100 HWTEST_F(AppMgrServiceInnerTest, StartResidentProcess_001, TestSize.Level0)
2101 {
2102 TAG_LOGI(AAFwkTag::TEST, "StartResidentProcess_001 start");
2103 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2104 EXPECT_NE(appMgrServiceInner, nullptr);
2105
2106 std::vector<BundleInfo> infos;
2107 appMgrServiceInner->StartResidentProcess(infos, 0, true);
2108
2109 BundleInfo info;
2110 infos.push_back(info);
2111
2112 BundleInfo info1;
2113 info1.applicationInfo.process = "";
2114 infos.push_back(info1);
2115
2116 BundleInfo info2;
2117 info2.applicationInfo.process = "test_process";
2118 infos.push_back(info2);
2119 appMgrServiceInner->StartResidentProcess(infos, 0, true);
2120
2121 appMgrServiceInner->appRunningManager_ = nullptr;
2122 appMgrServiceInner->StartResidentProcess(infos, 0, true);
2123
2124 TAG_LOGI(AAFwkTag::TEST, "StartResidentProcess_001 end");
2125 }
2126
2127 /**
2128 * @tc.name: StartEmptyResidentProcess_001
2129 * @tc.desc: start empty resident process.
2130 * @tc.type: FUNC
2131 * @tc.require: issueI5W4S7
2132 */
2133 HWTEST_F(AppMgrServiceInnerTest, StartEmptyResidentProcess_001, TestSize.Level0)
2134 {
2135 TAG_LOGI(AAFwkTag::TEST, "StartEmptyResidentProcess_001 start");
2136 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2137 EXPECT_NE(appMgrServiceInner, nullptr);
2138
2139 BundleInfo info;
2140 info.applicationInfo = *applicationInfo_;
2141 std::string processName = "test_process";
2142 appMgrServiceInner->StartEmptyResidentProcess(info, processName, 0, true);
2143
2144 appMgrServiceInner->StartEmptyResidentProcess(info, processName, 1, true);
2145
2146 appMgrServiceInner->StartEmptyResidentProcess(info, "", 0, true);
2147
2148 appMgrServiceInner->appRunningManager_ = nullptr;
2149 appMgrServiceInner->StartEmptyResidentProcess(info, processName, 0, true);
2150
2151 appMgrServiceInner->remoteClientManager_ = nullptr;
2152 appMgrServiceInner->StartEmptyResidentProcess(info, processName, 0, true);
2153
2154 TAG_LOGI(AAFwkTag::TEST, "StartEmptyResidentProcess_001 end");
2155 }
2156
2157 /**
2158 * @tc.name: CheckRemoteClient_001
2159 * @tc.desc: check remote client.
2160 * @tc.type: FUNC
2161 * @tc.require: issueI5W4S7
2162 */
2163 HWTEST_F(AppMgrServiceInnerTest, CheckRemoteClient_001, TestSize.Level0)
2164 {
2165 TAG_LOGI(AAFwkTag::TEST, "CheckRemoteClient_001 start");
2166 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2167 EXPECT_NE(appMgrServiceInner, nullptr);
2168
2169 appMgrServiceInner->CheckRemoteClient();
2170
2171 appMgrServiceInner->remoteClientManager_->SetSpawnClient(nullptr);
2172 appMgrServiceInner->CheckRemoteClient();
2173
2174 appMgrServiceInner->remoteClientManager_->SetBundleManagerHelper(nullptr);
2175 appMgrServiceInner->CheckRemoteClient();
2176
2177 appMgrServiceInner->remoteClientManager_ = nullptr;
2178 appMgrServiceInner->CheckRemoteClient();
2179
2180 TAG_LOGI(AAFwkTag::TEST, "CheckRemoteClient_001 end");
2181 }
2182
2183 /**
2184 * @tc.name: RestartResidentProcess_001
2185 * @tc.desc: restart resident process.
2186 * @tc.type: FUNC
2187 * @tc.require: issueI5W4S7
2188 */
2189 HWTEST_F(AppMgrServiceInnerTest, RestartResidentProcess_001, TestSize.Level0)
2190 {
2191 TAG_LOGI(AAFwkTag::TEST, "RestartResidentProcess_001 start");
2192 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2193 EXPECT_NE(appMgrServiceInner, nullptr);
2194
2195 appMgrServiceInner->RestartResidentProcess(nullptr);
2196
2197 std::shared_ptr<AppRunningRecord> appRecord;
2198 appMgrServiceInner->RestartResidentProcess(appRecord);
2199
2200 BundleInfo bundleInfo;
2201 std::string processName = "test_processName";
2202 appRecord =
2203 appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo);
2204 EXPECT_NE(appRecord, nullptr);
2205 appRecord->mainBundleName_ = "com.ohos.settings";
2206 appMgrServiceInner->RestartResidentProcess(appRecord);
2207
2208 appMgrServiceInner->appRunningManager_ = nullptr;
2209 appMgrServiceInner->RestartResidentProcess(appRecord);
2210
2211 appMgrServiceInner->remoteClientManager_ = nullptr;
2212 appMgrServiceInner->RestartResidentProcess(appRecord);
2213
2214 TAG_LOGI(AAFwkTag::TEST, "RestartResidentProcess_001 end");
2215 }
2216
2217 /**
2218 * @tc.name: NotifyAppStatusByCallerUid_001
2219 * @tc.desc: notify app status by caller uid.
2220 * @tc.type: FUNC
2221 * @tc.require: issueI5W4S7
2222 */
2223 HWTEST_F(AppMgrServiceInnerTest, NotifyAppStatusByCallerUid_001, TestSize.Level0)
2224 {
2225 TAG_LOGI(AAFwkTag::TEST, "NotifyAppStatusByCallerUid_001 start");
2226 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2227 EXPECT_NE(appMgrServiceInner, nullptr);
2228
2229 std::string bundleName = "test_bundle_name";
2230 std::string eventData = "test_event_data";
2231 appMgrServiceInner->NotifyAppStatusByCallerUid(bundleName, 0, 0, 0, 0, eventData);
2232
2233 TAG_LOGI(AAFwkTag::TEST, "NotifyAppStatusByCallerUid_001 end");
2234 }
2235
2236 /**
2237 * @tc.name: RegisterApplicationStateObserver_001
2238 * @tc.desc: register application state observer.
2239 * @tc.type: FUNC
2240 * @tc.require: issueI5W4S7
2241 */
2242 HWTEST_F(AppMgrServiceInnerTest, RegisterApplicationStateObserver_001, TestSize.Level0)
2243 {
2244 TAG_LOGI(AAFwkTag::TEST, "RegisterApplicationStateObserver_001 start");
2245 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2246 EXPECT_NE(appMgrServiceInner, nullptr);
2247
2248 sptr<IApplicationStateObserver> observer;
2249 std::vector<std::string> bundleNameList;
2250 appMgrServiceInner->RegisterApplicationStateObserver(observer, bundleNameList);
2251
2252 TAG_LOGI(AAFwkTag::TEST, "RegisterApplicationStateObserver_001 end");
2253 }
2254
2255 /**
2256 * @tc.name: UnregisterApplicationStateObserver_001
2257 * @tc.desc: unregister application state observer.
2258 * @tc.type: FUNC
2259 * @tc.require: issueI5W4S7
2260 */
2261 HWTEST_F(AppMgrServiceInnerTest, UnregisterApplicationStateObserver_001, TestSize.Level0)
2262 {
2263 TAG_LOGI(AAFwkTag::TEST, "UnregisterApplicationStateObserver_001 start");
2264 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2265 EXPECT_NE(appMgrServiceInner, nullptr);
2266
2267 sptr<IApplicationStateObserver> observer;
2268 appMgrServiceInner->UnregisterApplicationStateObserver(observer);
2269
2270 TAG_LOGI(AAFwkTag::TEST, "UnregisterApplicationStateObserver_001 end");
2271 }
2272
2273 /**
2274 * @tc.name: GetForegroundApplications_001
2275 * @tc.desc: get foreground applications.
2276 * @tc.type: FUNC
2277 * @tc.require: issueI5W4S7
2278 */
2279 HWTEST_F(AppMgrServiceInnerTest, GetForegroundApplications_001, TestSize.Level0)
2280 {
2281 TAG_LOGI(AAFwkTag::TEST, "GetForegroundApplications_001 start");
2282 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2283 EXPECT_NE(appMgrServiceInner, nullptr);
2284
2285 std::vector<AppStateData> list;
2286 appMgrServiceInner->GetForegroundApplications(list);
2287
2288 TAG_LOGI(AAFwkTag::TEST, "GetForegroundApplications_001 end");
2289 }
2290
2291 /**
2292 * @tc.name: StartUserTestProcess_001
2293 * @tc.desc: start user test process.
2294 * @tc.type: FUNC
2295 * @tc.require: issueI5W4S7
2296 */
2297 HWTEST_F(AppMgrServiceInnerTest, StartUserTestProcess_001, TestSize.Level0)
2298 {
2299 TAG_LOGI(AAFwkTag::TEST, "StartUserTestProcess_001 start");
2300 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2301 EXPECT_NE(appMgrServiceInner, nullptr);
2302
2303 AAFwk::Want want;
2304 sptr<IRemoteObject> observer;
2305 BundleInfo bundleInfo;
2306 appMgrServiceInner->StartUserTestProcess(want, nullptr, bundleInfo, 0);
2307
2308 appMgrServiceInner->StartUserTestProcess(want, observer, bundleInfo, 0);
2309
2310 std::string bundle_name = "test_bundle_name";
2311 want.SetParam("-b", bundle_name);
2312 appMgrServiceInner->StartUserTestProcess(want, observer, bundleInfo, 0);
2313
2314 std::string moduleName = "test_module_name";
2315 want.SetParam("-m", moduleName);
2316 HapModuleInfo hapModuleInfo;
2317 hapModuleInfo.moduleName = moduleName;
2318 bundleInfo.hapModuleInfos.push_back(hapModuleInfo);
2319 appMgrServiceInner->StartUserTestProcess(want, observer, bundleInfo, 0);
2320
2321 appMgrServiceInner->remoteClientManager_ = nullptr;
2322 appMgrServiceInner->StartUserTestProcess(want, observer, bundleInfo, 0);
2323
2324 appMgrServiceInner->appRunningManager_ = nullptr;
2325 appMgrServiceInner->StartUserTestProcess(want, observer, bundleInfo, 0);
2326
2327 TAG_LOGI(AAFwkTag::TEST, "StartUserTestProcess_001 end");
2328 }
2329
2330 /**
2331 * @tc.name: GetHapModuleInfoForTestRunner_001
2332 * @tc.desc: get hap module info for test runner.
2333 * @tc.type: FUNC
2334 * @tc.require: issueI5W4S7
2335 */
2336 HWTEST_F(AppMgrServiceInnerTest, GetHapModuleInfoForTestRunner_001, TestSize.Level0)
2337 {
2338 TAG_LOGI(AAFwkTag::TEST, "GetHapModuleInfoForTestRunner_001 start");
2339 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2340 EXPECT_NE(appMgrServiceInner, nullptr);
2341
2342 AAFwk::Want want;
2343 sptr<IRemoteObject> observer;
2344 BundleInfo bundleInfo;
2345 HapModuleInfo hapModuleInfo;
2346 appMgrServiceInner->GetHapModuleInfoForTestRunner(want, nullptr, bundleInfo, hapModuleInfo);
2347
2348 appMgrServiceInner->GetHapModuleInfoForTestRunner(want, observer, bundleInfo, hapModuleInfo);
2349
2350 hapModuleInfo.moduleName = "test_module_name";
2351 bundleInfo.hapModuleInfos.push_back(hapModuleInfo);
2352 appMgrServiceInner->GetHapModuleInfoForTestRunner(want, observer, bundleInfo, hapModuleInfo);
2353
2354 bundleInfo.hapModuleInfos.back().isModuleJson = true;
2355 appMgrServiceInner->GetHapModuleInfoForTestRunner(want, observer, bundleInfo, hapModuleInfo);
2356
2357 std::string testmoduleName = "test_XXX";
2358 want.SetParam("-m", testmoduleName);
2359 appMgrServiceInner->GetHapModuleInfoForTestRunner(want, observer, bundleInfo, hapModuleInfo);
2360
2361 std::string moduleName = "test_module_name";
2362 want.SetParam("-m", moduleName);
2363 appMgrServiceInner->GetHapModuleInfoForTestRunner(want, observer, bundleInfo, hapModuleInfo);
2364
2365 TAG_LOGI(AAFwkTag::TEST, "GetHapModuleInfoForTestRunner_001 end");
2366 }
2367
2368 /**
2369 * @tc.name: UserTestAbnormalFinish_001
2370 * @tc.desc: user test abnormal finish.
2371 * @tc.type: FUNC
2372 * @tc.require: issueI5W4S7
2373 */
2374 HWTEST_F(AppMgrServiceInnerTest, UserTestAbnormalFinish_001, TestSize.Level0)
2375 {
2376 TAG_LOGI(AAFwkTag::TEST, "UserTestAbnormalFinish_001 start");
2377 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2378 EXPECT_NE(appMgrServiceInner, nullptr);
2379
2380 sptr<IRemoteObject> observer;
2381 std::string msg = "testmsg";
2382 appMgrServiceInner->UserTestAbnormalFinish(nullptr, "");
2383 appMgrServiceInner->UserTestAbnormalFinish(nullptr, msg);
2384 appMgrServiceInner->UserTestAbnormalFinish(observer, "");
2385 appMgrServiceInner->UserTestAbnormalFinish(observer, msg);
2386
2387 TAG_LOGI(AAFwkTag::TEST, "UserTestAbnormalFinish_001 end");
2388 }
2389
2390 /**
2391 * @tc.name: StartEmptyProcess_001
2392 * @tc.desc: start empty process.
2393 * @tc.type: FUNC
2394 * @tc.require: issueI5W4S7
2395 */
2396 HWTEST_F(AppMgrServiceInnerTest, StartEmptyProcess_001, TestSize.Level0)
2397 {
2398 TAG_LOGI(AAFwkTag::TEST, "StartEmptyProcess_001 start");
2399 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2400 EXPECT_NE(appMgrServiceInner, nullptr);
2401
2402 AAFwk::Want want;
2403 sptr<IRemoteObject> observer;
2404 BundleInfo info;
2405 HapModuleInfo hapModuleInfo;
2406 std::string processName = "test_processName";
2407 appMgrServiceInner->StartEmptyProcess(want, nullptr, info, "", 0);
2408 appMgrServiceInner->StartEmptyProcess(want, observer, info, "", 0);
2409 appMgrServiceInner->StartEmptyProcess(want, observer, info, processName, 0);
2410
2411 info.applicationInfo = *applicationInfo_;
2412 appMgrServiceInner->StartEmptyProcess(want, observer, info, processName, 0);
2413
2414 want.SetParam("coldStart", true);
2415 appMgrServiceInner->StartEmptyProcess(want, observer, info, processName, 0);
2416
2417 appMgrServiceInner->remoteClientManager_ = nullptr;
2418 appMgrServiceInner->StartEmptyProcess(want, observer, info, processName, 0);
2419
2420 appMgrServiceInner->appRunningManager_ = nullptr;
2421 appMgrServiceInner->StartEmptyProcess(want, observer, info, processName, 0);
2422
2423 TAG_LOGI(AAFwkTag::TEST, "StartEmptyProcess_001 end");
2424 }
2425
2426 /**
2427 * @tc.name: FinishUserTest_001
2428 * @tc.desc: finish user test.
2429 * @tc.type: FUNC
2430 * @tc.require: issueI5W4S7
2431 */
2432 HWTEST_F(AppMgrServiceInnerTest, FinishUserTest_001, TestSize.Level0)
2433 {
2434 TAG_LOGI(AAFwkTag::TEST, "FinishUserTest_001 start");
2435 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2436 EXPECT_NE(appMgrServiceInner, nullptr);
2437
2438 pid_t pid = 0;
2439 appMgrServiceInner->FinishUserTest("", 0, "", pid);
2440
2441 std::string msg = "testmsg";
2442 std::string bundleName = "test_bundle_name";
2443 appMgrServiceInner->FinishUserTest("", 0, bundleName, pid);
2444 appMgrServiceInner->FinishUserTest(msg, 0, "", pid);
2445 appMgrServiceInner->FinishUserTest(msg, 0, bundleName, pid);
2446
2447 BundleInfo bundleInfo;
2448 HapModuleInfo hapModuleInfo;
2449 std::shared_ptr<AAFwk::Want> want;
2450 sptr<IRemoteObject> token = new MockAbilityToken();
2451 std::string processName = "test_processName";
2452 std::shared_ptr<AppRunningRecord> appRecord = appMgrServiceInner->CreateAppRunningRecord(token, nullptr,
2453 applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want, 0);
2454 EXPECT_NE(appRecord, nullptr);
2455 pid = appRecord->GetPriorityObject()->GetPid();
2456 appMgrServiceInner->FinishUserTest(msg, 0, bundleName, pid);
2457
2458 std::shared_ptr<UserTestRecord> record = std::make_shared<UserTestRecord>();
2459 appRecord->SetUserTestInfo(record);
2460 appMgrServiceInner->FinishUserTest(msg, 0, bundleName, pid);
2461
2462 appMgrServiceInner->appRunningManager_ = nullptr;
2463 appMgrServiceInner->FinishUserTest(msg, 0, bundleName, pid);
2464
2465 TAG_LOGI(AAFwkTag::TEST, "FinishUserTest_001 end");
2466 }
2467
2468 /**
2469 * @tc.name: FinishUserTestLocked_001
2470 * @tc.desc: finish user test locked.
2471 * @tc.type: FUNC
2472 * @tc.require: issueI5W4S7
2473 */
2474 HWTEST_F(AppMgrServiceInnerTest, FinishUserTestLocked_001, TestSize.Level0)
2475 {
2476 TAG_LOGI(AAFwkTag::TEST, "FinishUserTestLocked_001 start");
2477 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2478 EXPECT_NE(appMgrServiceInner, nullptr);
2479
2480 appMgrServiceInner->FinishUserTestLocked("", 0, nullptr);
2481
2482 std::shared_ptr<AppRunningRecord> appRecord;
2483 appMgrServiceInner->FinishUserTestLocked("", 0, appRecord);
2484
2485 std::string msg = "testmsg";
2486 appMgrServiceInner->FinishUserTestLocked(msg, 0, nullptr);
2487 appMgrServiceInner->FinishUserTestLocked(msg, 0, appRecord);
2488
2489 BundleInfo bundleInfo;
2490 std::string processName = "test_processName";
2491 appRecord =
2492 appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo);
2493 EXPECT_NE(appRecord, nullptr);
2494 std::shared_ptr<UserTestRecord> record = std::make_shared<UserTestRecord>();
2495 appRecord->SetUserTestInfo(record);
2496 appMgrServiceInner->FinishUserTestLocked(msg, 0, appRecord);
2497
2498 record->isFinished = true;
2499 appRecord->SetUserTestInfo(record);
2500 appMgrServiceInner->FinishUserTestLocked(msg, 0, appRecord);
2501
2502 record->observer = nullptr;
2503 appRecord->SetUserTestInfo(record);
2504 appMgrServiceInner->FinishUserTestLocked(msg, 0, appRecord);
2505
2506 TAG_LOGI(AAFwkTag::TEST, "FinishUserTestLocked_001 end");
2507 }
2508
2509 /**
2510 * @tc.name: StartSpecifiedAbility_001
2511 * @tc.desc: start specified ability.
2512 * @tc.type: FUNC
2513 * @tc.require: issueI5W4S7
2514 */
2515 HWTEST_F(AppMgrServiceInnerTest, StartSpecifiedAbility_001, TestSize.Level0)
2516 {
2517 TAG_LOGI(AAFwkTag::TEST, "StartSpecifiedAbility_001 start");
2518 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2519 EXPECT_NE(appMgrServiceInner, nullptr);
2520
2521 AAFwk::Want want;
2522 AbilityInfo abilityInfo;
2523 appMgrServiceInner->StartSpecifiedAbility(want, abilityInfo);
2524
2525 appMgrServiceInner->StartSpecifiedAbility(want, *abilityInfo_);
2526
2527 abilityInfo_->applicationInfo = *applicationInfo_;
2528 appMgrServiceInner->StartSpecifiedAbility(want, *abilityInfo_);
2529
2530 appMgrServiceInner->remoteClientManager_->SetBundleManagerHelper(nullptr);
2531 appMgrServiceInner->StartSpecifiedAbility(want, *abilityInfo_);
2532
2533 appMgrServiceInner->remoteClientManager_ = nullptr;
2534 appMgrServiceInner->StartSpecifiedAbility(want, *abilityInfo_);
2535
2536 TAG_LOGI(AAFwkTag::TEST, "StartSpecifiedAbility_001 end");
2537 }
2538
2539 /**
2540 * @tc.name: RegisterStartSpecifiedAbilityResponse_001
2541 * @tc.desc: register start specified ability response.
2542 * @tc.type: FUNC
2543 * @tc.require: issueI5W4S7
2544 */
2545 HWTEST_F(AppMgrServiceInnerTest, RegisterStartSpecifiedAbilityResponse_001, TestSize.Level0)
2546 {
2547 TAG_LOGI(AAFwkTag::TEST, "RegisterStartSpecifiedAbilityResponse_001 start");
2548 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2549 EXPECT_NE(appMgrServiceInner, nullptr);
2550
2551 appMgrServiceInner->RegisterStartSpecifiedAbilityResponse(nullptr);
2552
2553 sptr<IStartSpecifiedAbilityResponse> response;
2554 appMgrServiceInner->RegisterStartSpecifiedAbilityResponse(response);
2555
2556 TAG_LOGI(AAFwkTag::TEST, "RegisterStartSpecifiedAbilityResponse_001 end");
2557 }
2558
2559 /**
2560 * @tc.name: ScheduleAcceptWantDone_001
2561 * @tc.desc: schedule accept want done.
2562 * @tc.type: FUNC
2563 * @tc.require: issueI5W4S7
2564 */
2565 HWTEST_F(AppMgrServiceInnerTest, ScheduleAcceptWantDone_001, TestSize.Level0)
2566 {
2567 TAG_LOGI(AAFwkTag::TEST, "ScheduleAcceptWantDone_001 start");
2568 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2569 EXPECT_NE(appMgrServiceInner, nullptr);
2570
2571 AAFwk::Want want;
2572 std::string flag = "test_flag";
2573 appMgrServiceInner->ScheduleAcceptWantDone(0, want, flag);
2574
2575 BundleInfo bundleInfo;
2576 std::string processName = "test_processName";
2577 std::shared_ptr<AppRunningRecord> appRecord =
2578 appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo);
2579 appMgrServiceInner->ScheduleAcceptWantDone(appRecord->GetRecordId(), want, flag);
2580
2581 sptr<IStartSpecifiedAbilityResponse> response;
2582 appMgrServiceInner->RegisterStartSpecifiedAbilityResponse(response);
2583 appMgrServiceInner->ScheduleAcceptWantDone(appRecord->GetRecordId(), want, flag);
2584
2585 TAG_LOGI(AAFwkTag::TEST, "ScheduleAcceptWantDone_001 end");
2586 }
2587
2588 /**
2589 * @tc.name: HandleStartSpecifiedAbilityTimeOut_001
2590 * @tc.desc: handle start specified ability time out.
2591 * @tc.type: FUNC
2592 * @tc.require: issueI5W4S7
2593 */
2594 HWTEST_F(AppMgrServiceInnerTest, HandleStartSpecifiedAbilityTimeOut_001, TestSize.Level0)
2595 {
2596 TAG_LOGI(AAFwkTag::TEST, "HandleStartSpecifiedAbilityTimeOut_001 start");
2597 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2598 EXPECT_NE(appMgrServiceInner, nullptr);
2599
2600 appMgrServiceInner->HandleStartSpecifiedAbilityTimeOut(0);
2601
2602 BundleInfo bundleInfo;
2603 std::string appName = "test_appName";
2604 std::string processName = "test_processName";
2605 std::string bundleName = "test_bundleName";
2606 sptr<IRemoteObject> token = new MockAbilityToken();
2607 std::shared_ptr<AppRunningRecord> appRecord =
2608 appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo);
2609 EXPECT_NE(appRecord, nullptr);
2610 appRecord->eventId_ = 0;
2611 appMgrServiceInner->HandleStartSpecifiedAbilityTimeOut(0);
2612
2613 appRecord->specifiedRequestId_ = 1;
2614 appMgrServiceInner->HandleStartSpecifiedAbilityTimeOut(0);
2615
2616 sptr<IStartSpecifiedAbilityResponse> response;
2617 appMgrServiceInner->startSpecifiedAbilityResponse_ = response;
2618 appMgrServiceInner->HandleStartSpecifiedAbilityTimeOut(0);
2619
2620 appRecord->specifiedRequestId_ = -1;
2621 appMgrServiceInner->HandleStartSpecifiedAbilityTimeOut(0);
2622
2623 appMgrServiceInner->appRunningManager_ = nullptr;
2624 appMgrServiceInner->HandleStartSpecifiedAbilityTimeOut(0);
2625
2626 TAG_LOGI(AAFwkTag::TEST, "HandleStartSpecifiedAbilityTimeOut_001 end");
2627 }
2628
2629 /**
2630 * @tc.name: UpdateConfiguration_001
2631 * @tc.desc: update configuration.
2632 * @tc.type: FUNC
2633 * @tc.require: issueI5W4S7
2634 */
2635 HWTEST_F(AppMgrServiceInnerTest, UpdateConfiguration_001, TestSize.Level0)
2636 {
2637 TAG_LOGI(AAFwkTag::TEST, "UpdateConfiguration_001 start");
2638 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2639 EXPECT_NE(appMgrServiceInner, nullptr);
2640
2641 Configuration config;
2642 appMgrServiceInner->UpdateConfiguration(config);
2643
2644 auto testLanguge = "ch-zh";
2645 config.AddItem(AAFwk::GlobalConfigurationKey::SYSTEM_LANGUAGE, testLanguge);
2646 appMgrServiceInner->UpdateConfiguration(config);
2647
2648 auto appRunningRecordMap = appMgrServiceInner->appRunningManager_->appRunningRecordMap_;
2649 for (const auto& item : appRunningRecordMap) {
2650 const auto& appRecord = item.second;
2651 if (appRecord) {
2652 appRecord->appLifeCycleDeal_ = nullptr;
2653 }
2654 }
2655 appMgrServiceInner->UpdateConfiguration(config);
2656
2657 sptr<MockConfigurationObserver> observer(new (std::nothrow) MockConfigurationObserver());
2658 appMgrServiceInner->configurationObservers_.push_back({ observer, 100 });
2659 sptr<IConfigurationObserver> observer1;
2660 appMgrServiceInner->configurationObservers_.push_back({ observer1, 100 });
2661 appMgrServiceInner->configurationObservers_.push_back({ nullptr, 100 });
2662 appMgrServiceInner->UpdateConfiguration(config);
2663
2664 appMgrServiceInner->appRunningManager_ = nullptr;
2665 appMgrServiceInner->UpdateConfiguration(config);
2666
2667 TAG_LOGI(AAFwkTag::TEST, "UpdateConfiguration_001 end");
2668 }
2669
2670 /**
2671 * @tc.name: RegisterConfigurationObserver_001
2672 * @tc.desc: register configuration observer.
2673 * @tc.type: FUNC
2674 * @tc.require: issueI5W4S7
2675 */
2676 HWTEST_F(AppMgrServiceInnerTest, RegisterConfigurationObserver_001, TestSize.Level0)
2677 {
2678 TAG_LOGI(AAFwkTag::TEST, "RegisterConfigurationObserver_001 start");
2679 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2680 EXPECT_NE(appMgrServiceInner, nullptr);
2681
2682 appMgrServiceInner->configurationObservers_.clear();
2683
2684 appMgrServiceInner->RegisterConfigurationObserver(nullptr);
2685
2686 sptr<MockConfigurationObserver> observer(new (std::nothrow) MockConfigurationObserver());
2687 appMgrServiceInner->RegisterConfigurationObserver(observer);
2688 appMgrServiceInner->RegisterConfigurationObserver(observer);
2689
2690 TAG_LOGI(AAFwkTag::TEST, "RegisterConfigurationObserver_001 end");
2691 }
2692
2693 /**
2694 * @tc.name: UnregisterConfigurationObserver_001
2695 * @tc.desc: unregister configuration observer.
2696 * @tc.type: FUNC
2697 * @tc.require: issueI5W4S7
2698 */
2699 HWTEST_F(AppMgrServiceInnerTest, UnregisterConfigurationObserver_001, TestSize.Level0)
2700 {
2701 TAG_LOGI(AAFwkTag::TEST, "UnregisterConfigurationObserver_001 start");
2702 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2703 EXPECT_NE(appMgrServiceInner, nullptr);
2704
2705 appMgrServiceInner->configurationObservers_.clear();
2706
2707 appMgrServiceInner->UnregisterConfigurationObserver(nullptr);
2708
2709 sptr<MockConfigurationObserver> observer(new (std::nothrow) MockConfigurationObserver());
2710 appMgrServiceInner->UnregisterConfigurationObserver(observer);
2711
2712 appMgrServiceInner->RegisterConfigurationObserver(observer);
2713 appMgrServiceInner->UnregisterConfigurationObserver(observer);
2714
2715 TAG_LOGI(AAFwkTag::TEST, "UnregisterConfigurationObserver_001 end");
2716 }
2717
2718 /**
2719 * @tc.name: InitGlobalConfiguration_001
2720 * @tc.desc: init global configuration.
2721 * @tc.type: FUNC
2722 * @tc.require: issueI5W4S7
2723 */
2724 HWTEST_F(AppMgrServiceInnerTest, InitGlobalConfiguration_001, TestSize.Level0)
2725 {
2726 TAG_LOGI(AAFwkTag::TEST, "InitGlobalConfiguration_001 start");
2727 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
2728 EXPECT_NE(appMgrServiceInner, nullptr);
2729
2730 appMgrServiceInner->InitGlobalConfiguration();
2731
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 /**
4466 * @tc.name: SendAppSpawnUninstallDebugHapMsg_001
4467 * @tc.desc: SendAppSpawnUninstallDebugHapMsg
4468 * @tc.type: FUNC
4469 */
4470 HWTEST_F(AppMgrServiceInnerTest, SendAppSpawnUninstallDebugHapMsg_001, TestSize.Level0)
4471 {
4472 TAG_LOGI(AAFwkTag::TEST, "SendAppSpawnUninstallDebugHapMsg_001 start");
4473 auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
4474 EXPECT_NE(appMgrServiceInner, nullptr);
4475 appMgrServiceInner->SendAppSpawnUninstallDebugHapMsg(0);
4476 TAG_LOGI(AAFwkTag::TEST, "SendAppSpawnUninstallDebugHapMsg_001 end");
4477 }
4478
4479 /**
4480 * @tc.name: SetJITPermissions_001
4481 * @tc.desc: set jit permissions.
4482 * @tc.type: FUNC
4483 */
4484 HWTEST_F(AppMgrServiceInnerTest, SetJITPermissions_001, TestSize.Level0)
4485 {
4486 TAG_LOGI(AAFwkTag::TEST, "SetJITPermissions_001 start");
4487 uint32_t accessTokenId = 0;
4488 AppSpawnStartMsg startMsg = {0};
4489 AppspawnUtil::SetJITPermissions(accessTokenId, startMsg.jitPermissionsList);
4490 TAG_LOGI(AAFwkTag::TEST, "SetJITPermissions_001 end");
4491 }
4492
4493 } // namespace AppExecFwk
4494 } // namespace OHOS
4495