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