1 /*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 #include <thread>
16
17 #define private public
18 #define protected public
19 #include "gtest/gtest.h"
20
21 #include "ability_connection_wrapper_stub.h"
22 #include "bundle/bundle_manager_internal.h"
23 #include "device_manager.h"
24 #include "distributed_sched_permission.h"
25 #include "distributed_sched_proxy.h"
26 #include "distributed_sched_service.h"
27 #include "distributed_sched_test_util.h"
28 #include "dms_constant.h"
29 #include "dtbschedmgr_device_info_storage.h"
30 #include "dtbschedmgr_log.h"
31 #include "form_mgr_errors.h"
32 #include "if_system_ability_manager.h"
33 #include "ipc_skeleton.h"
34 #include "iservice_registry.h"
35 #include "mock_form_mgr_service.h"
36 #include "mock_distributed_sched.h"
37 #include "multi_user_manager.h"
38 #include "system_ability_definition.h"
39 #include "test_log.h"
40 #include "thread_pool.h"
41 #undef private
42 #undef protected
43
44 using namespace std;
45 using namespace testing;
46 using namespace testing::ext;
47 using namespace OHOS;
48
49 namespace OHOS {
50 namespace DistributedSchedule {
51 using namespace AAFwk;
52 using namespace AppExecFwk;
53 using namespace DistributedHardware;
54 using namespace Constants;
55 namespace {
56 const string LOCAL_DEVICEID = "192.168.43.100";
57 const string REMOTE_DEVICEID = "255.255.255.255";
58 const std::u16string DEVICE_ID = u"192.168.43.100";
59 const std::u16string DEVICE_ID_NULL = u"";
60 constexpr int32_t SESSION_ID = 123;
61 const std::string DMS_MISSION_ID = "dmsMissionId";
62 constexpr int32_t MISSION_ID = 1;
63 const std::string DMS_SRC_NETWORK_ID = "dmsSrcNetworkId";
64 const string ABILITY_NAME = "com.ohos.permissionmanager.MainAbility";
65 const string BUNDLE_NAME = "com.ohos.permissionmanager";
66 const string DMS_IS_CALLER_BACKGROUND = "dmsIsCallerBackGround";
67 const string DMS_VERSION_ID = "dmsVersion";
68 constexpr int32_t SLEEP_TIME = 1000;
69 }
70
71 class DistributedSchedServiceFirstTest : public testing::Test {
72 public:
73 static void SetUpTestCase();
74 static void TearDownTestCase();
75 void SetUp();
76 void TearDown();
77 sptr<IDistributedSched> GetDms();
78 int32_t InstallBundle(const std::string &bundlePath) const;
79 sptr<IDistributedSched> proxy_;
80
81 protected:
82 enum class LoopTime : int32_t {
83 LOOP_TIME = 10,
84 LOOP_PRESSURE_TIME = 100,
85 };
86 sptr<IRemoteObject> GetDSchedService() const;
87 void GetAbilityInfo(const std::string& package, const std::string& name,
88 const std::string& bundleName, const std::string& deviceId,
89 OHOS::AppExecFwk::AbilityInfo& abilityInfo);
90
91 class DeviceInitCallBack : public DmInitCallback {
92 void OnRemoteDied() override;
93 };
94 };
95
SetUpTestCase()96 void DistributedSchedServiceFirstTest::SetUpTestCase()
97 {
98 if (!DistributedSchedUtil::LoadDistributedSchedService()) {
99 DTEST_LOG << "DistributedSchedServiceFirstTest::SetUpTestCase LoadDistributedSchedService failed" << std::endl;
100 }
101 const std::string pkgName = "DBinderBus_" + std::to_string(getprocpid());
102 std::shared_ptr<DmInitCallback> initCallback_ = std::make_shared<DeviceInitCallBack>();
103 DeviceManager::GetInstance().InitDeviceManager(pkgName, initCallback_);
104 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIME));
105 }
106
TearDownTestCase()107 void DistributedSchedServiceFirstTest::TearDownTestCase()
108 {}
109
SetUp()110 void DistributedSchedServiceFirstTest::SetUp()
111 {
112 DistributedSchedUtil::MockPermission();
113 }
114
TearDown()115 void DistributedSchedServiceFirstTest::TearDown()
116 {}
117
OnRemoteDied()118 void DistributedSchedServiceFirstTest::DeviceInitCallBack::OnRemoteDied()
119 {}
120
121 static bool g_isForeground = true;
122
IsCallerForeground(int32_t callingUid)123 bool MultiUserManager::IsCallerForeground(int32_t callingUid)
124 {
125 return g_isForeground;
126 }
127
GetDms()128 sptr<IDistributedSched> DistributedSchedServiceFirstTest::GetDms()
129 {
130 if (proxy_ != nullptr) {
131 return proxy_;
132 }
133 auto sm = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
134 EXPECT_TRUE(sm != nullptr);
135 if (sm == nullptr) {
136 DTEST_LOG << "DistributedSchedServiceFirstTest sm is nullptr" << std::endl;
137 return nullptr;
138 }
139 DTEST_LOG << "DistributedSchedServiceFirstTest sm is not nullptr" << std::endl;
140 auto distributedObject = sm->GetSystemAbility(DISTRIBUTED_SCHED_SA_ID);
141 proxy_ = iface_cast<IDistributedSched>(distributedObject);
142 if (proxy_ == nullptr) {
143 DTEST_LOG << "DistributedSchedServiceFirstTest DistributedSched is nullptr" << std::endl;
144 } else {
145 DTEST_LOG << "DistributedSchedServiceFirstTest DistributedSched is not nullptr" << std::endl;
146 }
147 return proxy_;
148 }
149
GetDSchedService() const150 sptr<IRemoteObject> DistributedSchedServiceFirstTest::GetDSchedService() const
151 {
152 sptr<IRemoteObject> dsched(new MockDistributedSched());
153 return dsched;
154 }
155
GetAbilityInfo(const std::string & package,const std::string & name,const std::string & bundleName,const std::string & deviceId,OHOS::AppExecFwk::AbilityInfo & abilityInfo)156 void DistributedSchedServiceFirstTest::GetAbilityInfo(const std::string& package, const std::string& name,
157 const std::string& bundleName, const std::string& deviceId, OHOS::AppExecFwk::AbilityInfo& abilityInfo)
158 {
159 abilityInfo.bundleName = bundleName;
160 abilityInfo.deviceId = deviceId;
161 }
162
163 /**
164 * @tc.name: Dump001
165 * @tc.desc: call Dump
166 * @tc.type: FUNC
167 * @tc.require: I6O5T3
168 */
169 HWTEST_F(DistributedSchedServiceFirstTest, Dump001, TestSize.Level3)
170 {
171 DTEST_LOG << "DistributedSchedServiceFirstTest Dump001 start" << std::endl;
172 int32_t fd = 1;
173 const std::vector<std::u16string> args;
174 const wptr<IRemoteObject> remote;
175 int32_t missionId = 0;
176 bool resultCode = ERR_OK;
177 int32_t ret = DistributedSchedService::GetInstance().Dump(fd, args);
178 DistributedSchedService::GetInstance().NotifyContinuationCallbackResult(missionId, resultCode);
179 DistributedSchedService::GetInstance().ProcessFormMgrDied(remote);
180 EXPECT_EQ(ret, ERR_OK);
181 DTEST_LOG << "DistributedSchedServiceFirstTest Dump001 end" << std::endl;
182 }
183
184 /**
185 * @tc.name: Dump002
186 * @tc.desc: call Dump
187 * @tc.type: FUNC
188 * @tc.require: I6O5T3
189 */
190 HWTEST_F(DistributedSchedServiceFirstTest, Dump002, TestSize.Level3)
191 {
192 DTEST_LOG << "DistributedSchedServiceFirstTest Dump002 start" << std::endl;
193 int32_t fd = 0;
194 const std::vector<std::u16string> args;
195 const std::string deviceId;
196 int32_t ret = DistributedSchedService::GetInstance().Dump(fd, args);
197 DistributedSchedService::GetInstance().DeviceOnlineNotify(deviceId);
198 DistributedSchedService::GetInstance().DeviceOfflineNotify(deviceId);
199 DistributedSchedService::GetInstance().DeviceOfflineNotifyAfterDelete(deviceId);
200 EXPECT_EQ(ret, DMS_WRITE_FILE_FAILED_ERR);
201 DTEST_LOG << "DistributedSchedServiceFirstTest Dump002 end" << std::endl;
202 }
203
204 /**
205 * @tc.name: StartRemoteAbility_001
206 * @tc.desc: call StartRemoteAbility with illegal params
207 * @tc.type: FUNC
208 */
209 HWTEST_F(DistributedSchedServiceFirstTest, StartRemoteAbility_001, TestSize.Level1)
210 {
211 DTEST_LOG << "DistributedSchedServiceFirstTest StartRemoteAbility_001 start" << std::endl;
212 sptr<IDistributedSched> proxy = GetDms();
213 ASSERT_NE(nullptr, proxy);
214 /**
215 * @tc.steps: step1. StartRemoteAbility with uninitialized params
216 * @tc.expected: step1. StartRemoteAbility return INVALID_PARAMETERS_ERR
217 */
218 AAFwk::Want want;
219 int result1 = proxy->StartRemoteAbility(want, 0, 0, 0);
220 DTEST_LOG << "result1:" << result1 << std::endl;
221 /**
222 * @tc.steps: step2. StartRemoteAbility with empty want's deviceId
223 * @tc.expected: step2. StartRemoteAbility return INVALID_PARAMETERS_ERR
224 */
225 AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
226 "com.ohos.distributedmusicplayer.MainAbility");
227 want.SetElement(element);
228 int result2 = proxy->StartRemoteAbility(want, 0, 0, 0);
229 DTEST_LOG << "result2:" << result2 << std::endl;
230
231 EXPECT_EQ(static_cast<int>(DMS_PERMISSION_DENIED), result1);
232 EXPECT_EQ(static_cast<int>(DMS_PERMISSION_DENIED), result2);
233 DTEST_LOG << "DistributedSchedServiceFirstTest StartRemoteAbility_001 end" << std::endl;
234 }
235
236 /**
237 * @tc.name: StartRemoteAbility_002
238 * @tc.desc: call StartRemoteAbility with dms with wrong deviceId and local deviceId
239 * @tc.type: FUNC
240 */
241 HWTEST_F(DistributedSchedServiceFirstTest, StartRemoteAbility_002, TestSize.Level1)
242 {
243 DTEST_LOG << "DistributedSchedServiceFirstTest StartRemoteAbility_002 start" << std::endl;
244 sptr<IDistributedSched> proxy = GetDms();
245 ASSERT_NE(nullptr, proxy);
246 /**
247 * @tc.steps: step1. set want with wrong deviceId
248 * @tc.expected: step2. StartRemoteAbility return INVALID_PARAMETERS_ERR
249 */
250 AAFwk::Want want;
251 AppExecFwk::ElementName element("123456", "com.ohos.distributedmusicplayer",
252 "com.ohos.distributedmusicplayer.MainAbility");
253 want.SetElement(element);
254 int result1 = DistributedSchedService::GetInstance().StartRemoteAbility(want, 0, 0, 0);
255 DTEST_LOG << "result:" << result1 << std::endl;
256 std::string deviceId;
257 DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(deviceId);
258 AppExecFwk::ElementName element1(deviceId, "com.ohos.distributedmusicplayer",
259 "com.ohos.distributedmusicplayer.MainAbility");
260 want.SetElement(element1);
261 int result2 = DistributedSchedService::GetInstance().StartRemoteAbility(want, 0, 0, 0);
262 DTEST_LOG << "result:" << result2 << std::endl;
263 EXPECT_EQ(static_cast<int>(INVALID_PARAMETERS_ERR), result1);
264 EXPECT_EQ(static_cast<int>(INVALID_PARAMETERS_ERR), result2);
265 DTEST_LOG << "DistributedSchedServiceFirstTest StartRemoteAbility_002 end" << std::endl;
266 }
267
268 /**
269 * @tc.name: StartRemoteAbility_003
270 * @tc.desc: call StartRemoteAbility with dms
271 * @tc.type: FUNC
272 */
273 HWTEST_F(DistributedSchedServiceFirstTest, StartRemoteAbility_003, TestSize.Level1)
274 {
275 DTEST_LOG << "DistributedSchedServiceFirstTest StartRemoteAbility_003 start" << std::endl;
276 /**
277 * @tc.steps: step1. set want with wrong deviceId
278 * @tc.expected: step2. StartRemoteAbility return INVALID_PARAMETERS_ERR
279 */
280 AAFwk::Want want;
281 AppExecFwk::ElementName element("123456", "com.ohos.distributedmusicplayer",
282 "com.ohos.distributedmusicplayer.MainAbility");
283 want.SetElement(element);
284 int result = DistributedSchedService::GetInstance().StartRemoteAbility(want, 0, 0, 0);
285 DTEST_LOG << "result:" << result << std::endl;
286 EXPECT_EQ(static_cast<int>(INVALID_PARAMETERS_ERR), result);
287 DTEST_LOG << "DistributedSchedServiceFirstTest StartRemoteAbility_003 end" << std::endl;
288 }
289
290 /**
291 * @tc.name: StartRemoteAbility_004
292 * @tc.desc: call StartRemoteAbility
293 * @tc.type: FUNC
294 */
295 HWTEST_F(DistributedSchedServiceFirstTest, StartRemoteAbility_004, TestSize.Level1)
296 {
297 DTEST_LOG << "DistributedSchedServiceFirstTest StartRemoteAbility_004 start" << std::endl;
298 sptr<IDistributedSched> proxy = GetDms();
299 ASSERT_NE(nullptr, proxy);
300 /**
301 * @tc.steps: step1. set want and abilityInfo
302 * @tc.expected: step2. StartRemoteAbility return INVALID_PARAMETERS_ERR
303 */
304 AAFwk::Want want;
305 AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
306 "com.ohos.distributedmusicplayer.MainAbility");
307 want.SetElement(element);
308 int result = proxy->StartRemoteAbility(want, 0, 0, 0);
309 DTEST_LOG << "result:" << result << std::endl;
310 EXPECT_EQ(static_cast<int>(DMS_PERMISSION_DENIED), result);
311 DTEST_LOG << "DistributedSchedServiceFirstTest StartRemoteAbility_004 end" << std::endl;
312 }
313
314 /**
315 * @tc.name: StartRemoteAbility_005
316 * @tc.desc: user is not foreground
317 * @tc.type: FUNC
318 */
319 HWTEST_F(DistributedSchedServiceFirstTest, StartRemoteAbility_005, TestSize.Level1)
320 {
321 DTEST_LOG << "DistributedSchedServiceFirstTest StartRemoteAbility_005 start" << std::endl;
322 /**
323 * @tc.steps: step1. set want with wrong deviceId
324 * @tc.expected: step2. StartRemoteAbility return INVALID_PARAMETERS_ERR
325 */
326 AAFwk::Want want;
327 AppExecFwk::ElementName element("123456", "com.ohos.distributedmusicplayer",
328 "com.ohos.distributedmusicplayer.MainAbility");
329 want.SetElement(element);
330 g_isForeground = false;
331 int result = DistributedSchedService::GetInstance().StartRemoteAbility(want, 0, 0, 0);
332 DTEST_LOG << "result:" << result << std::endl;
333 EXPECT_EQ(static_cast<int>(DMS_NOT_FOREGROUND_USER), result);
334 DTEST_LOG << "DistributedSchedServiceFirstTest StartRemoteAbility_005 end" << std::endl;
335 }
336
337 /**
338 * @tc.name: StartRemoteAbility001
339 * @tc.desc: call StartRemoteAbility
340 * @tc.type: FUNC
341 * @tc.require: I6P0I9
342 */
343 HWTEST_F(DistributedSchedServiceFirstTest, StartRemoteAbility001, TestSize.Level3)
344 {
345 DTEST_LOG << "DistributedSchedServiceFirstTest StartRemoteAbility001 start" << std::endl;
346 AAFwk::Want want;
347 int32_t callerUid = 0;
348 int32_t requestCode = 0;
349 uint32_t accessToken = 0;
350 g_isForeground = true;
351 int32_t ret = DistributedSchedService::GetInstance().StartRemoteAbility(want, callerUid, requestCode, accessToken);
352 EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
353 DTEST_LOG << "DistributedSchedServiceFirstTest StartRemoteAbility001 end" << std::endl;
354 }
355
356 /**
357 * @tc.name: StartRemoteAbility002
358 * @tc.desc: call StartRemoteAbility
359 * @tc.type: FUNC
360 * @tc.require: I6P0I9
361 */
362 HWTEST_F(DistributedSchedServiceFirstTest, StartRemoteAbility002, TestSize.Level3)
363 {
364 DTEST_LOG << "DistributedSchedServiceFirstTest StartRemoteAbility002 start" << std::endl;
365 AAFwk::Want want;
366 int32_t callerUid = 1;
367 int32_t requestCode = 0;
368 uint32_t accessToken = 0;
369 g_isForeground = true;
370 int32_t ret = DistributedSchedService::GetInstance().StartRemoteAbility(want, callerUid, requestCode, accessToken);
371 EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
372 DTEST_LOG << "DistributedSchedServiceFirstTest StartRemoteAbility002 end" << std::endl;
373 }
374
375 /**
376 * @tc.name: StartRemoteAbility003
377 * @tc.desc: call StartRemoteAbility
378 * @tc.type: FUNC
379 * @tc.require: I6P0I9
380 */
381 HWTEST_F(DistributedSchedServiceFirstTest, StartRemoteAbility003, TestSize.Level3)
382 {
383 DTEST_LOG << "DistributedSchedServiceFirstTest StartRemoteAbility003 start" << std::endl;
384 AAFwk::Want want;
385 int32_t callerUid = 0;
386 int32_t requestCode = 1;
387 uint32_t accessToken = 0;
388 g_isForeground = true;
389 int32_t ret = DistributedSchedService::GetInstance().StartRemoteAbility(want, callerUid, requestCode, accessToken);
390 EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
391 DTEST_LOG << "DistributedSchedServiceFirstTest StartRemoteAbility003 end" << std::endl;
392 }
393
394 /**
395 * @tc.name: StartRemoteAbility004
396 * @tc.desc: call StartRemoteAbility
397 * @tc.type: FUNC
398 * @tc.require: I6P0I9
399 */
400 HWTEST_F(DistributedSchedServiceFirstTest, StartRemoteAbility004, TestSize.Level3)
401 {
402 DTEST_LOG << "DistributedSchedServiceFirstTest StartRemoteAbility004 start" << std::endl;
403 AAFwk::Want want;
404 int32_t callerUid = 0;
405 int32_t requestCode = 0;
406 uint32_t accessToken = 1;
407 g_isForeground = true;
408 int32_t ret = DistributedSchedService::GetInstance().StartRemoteAbility(want, callerUid, requestCode, accessToken);
409 EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
410 DTEST_LOG << "DistributedSchedServiceFirstTest StartRemoteAbility004 end" << std::endl;
411 }
412
413 /**
414 * @tc.name: StartRemoteAbility005
415 * @tc.desc: call StartRemoteAbility
416 * @tc.type: FUNC
417 * @tc.require: I6P0I9
418 */
419 HWTEST_F(DistributedSchedServiceFirstTest, StartRemoteAbility005, TestSize.Level3)
420 {
421 DTEST_LOG << "DistributedSchedServiceFirstTest StartRemoteAbility005 start" << std::endl;
422 AAFwk::Want want;
423 int32_t callerUid = 1;
424 int32_t requestCode = 1;
425 uint32_t accessToken = 0;
426 g_isForeground = true;
427 int32_t ret = DistributedSchedService::GetInstance().StartRemoteAbility(want, callerUid, requestCode, accessToken);
428 EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
429 DTEST_LOG << "DistributedSchedServiceFirstTest StartRemoteAbility005 end" << std::endl;
430 }
431
432 /**
433 * @tc.name: StartRemoteAbility006
434 * @tc.desc: call StartRemoteAbility
435 * @tc.type: FUNC
436 * @tc.require: I6P0I9
437 */
438 HWTEST_F(DistributedSchedServiceFirstTest, StartRemoteAbility006, TestSize.Level3)
439 {
440 DTEST_LOG << "DistributedSchedServiceFirstTest StartRemoteAbility006 start" << std::endl;
441 AAFwk::Want want;
442 int32_t callerUid = 1;
443 int32_t requestCode = 1;
444 uint32_t accessToken = 1;
445 g_isForeground = true;
446 int32_t ret = DistributedSchedService::GetInstance().StartRemoteAbility(want, callerUid, requestCode, accessToken);
447 EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
448 DTEST_LOG << "DistributedSchedServiceFirstTest StartRemoteAbility006 end" << std::endl;
449 }
450
451 /**
452 * @tc.name: StartRemoteAbility007
453 * @tc.desc: user is not foreground
454 * @tc.type: FUNC
455 */
456 HWTEST_F(DistributedSchedServiceFirstTest, StartRemoteAbility007, TestSize.Level3)
457 {
458 DTEST_LOG << "DistributedSchedServiceFirstTest StartRemoteAbility007 start" << std::endl;
459 AAFwk::Want want;
460 int32_t callerUid = 0;
461 int32_t requestCode = 0;
462 uint32_t accessToken = 0;
463 g_isForeground = false;
464 int32_t ret = DistributedSchedService::GetInstance().StartRemoteAbility(want, callerUid, requestCode, accessToken);
465 EXPECT_EQ(ret, DMS_NOT_FOREGROUND_USER);
466 DTEST_LOG << "DistributedSchedServiceFirstTest StartRemoteAbility007 end" << std::endl;
467 }
468
469 /**
470 * @tc.name: StartAbilityFromRemote_001
471 * @tc.desc: call StartAbilityFromRemote with illegal param
472 * @tc.type: FUNC
473 */
474 HWTEST_F(DistributedSchedServiceFirstTest, StartAbilityFromRemote_001, TestSize.Level1)
475 {
476 DTEST_LOG << "DistributedSchedServiceFirstTest StartAbilityFromRemote_001 start" << std::endl;
477 sptr<IDistributedSched> proxy = GetDms();
478 ASSERT_NE(nullptr, proxy);
479 AAFwk::Want want;
480 AppExecFwk::AbilityInfo abilityInfo;
481 CallerInfo callerInfo;
482 callerInfo.uid = 0;
483 callerInfo.sourceDeviceId = "255.255.255.255";
484 IDistributedSched::AccountInfo accountInfo;
485 /**
486 * @tc.steps: step1. StartAbilityFromRemote with uninitialized params
487 * @tc.expected: step1. StartAbilityFromRemote return INVALID_REMOTE_PARAMETERS_ERR
488 */
489 int result1 = proxy->StartAbilityFromRemote(want, abilityInfo, 0, callerInfo, accountInfo);
490 DTEST_LOG << "result1:" << result1 << std::endl;
491 /**
492 * @tc.steps: step1. StartAbilityFromRemote with with empty deviceId
493 * @tc.expected: step1. StartAbilityFromRemote return INVALID_REMOTE_PARAMETERS_ERR
494 */
495 AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
496 "com.ohos.distributedmusicplayer.MainAbility");
497 want.SetElement(element);
498 GetAbilityInfo("com.ohos.distributedmusicplayer", "com.ohos.distributedmusicplayer.MainAbility",
499 "com.ohos.distributedmusicplayer", "192.168.43.101", abilityInfo);
500 int result2 = proxy->StartAbilityFromRemote(want, abilityInfo, 0, callerInfo, accountInfo);
501 DTEST_LOG << "result2:" << result2 << std::endl;
502 EXPECT_EQ(static_cast<int>(IPC_STUB_UNKNOW_TRANS_ERR), result1);
503 EXPECT_EQ(static_cast<int>(IPC_STUB_UNKNOW_TRANS_ERR), result2);
504 DTEST_LOG << "DistributedSchedServiceFirstTest StartAbilityFromRemote_001 end" << std::endl;
505 }
506
507 #ifdef SUPPORT_DISTRIBUTED_FORM_SHARE
508 /**
509 * @tc.name: StartRemoteShareForm_002
510 * @tc.desc: call StartAbilityFromRemote with dms
511 * @tc.type: FUNC
512 * @tc.require: I76THI
513 */
514 HWTEST_F(DistributedSchedServiceFirstTest, StartRemoteShareForm_002, TestSize.Level1)
515 {
516 DTEST_LOG << "DistributedSchedServiceFirstTest StartRemoteShareForm_002 start" << std::endl;
517
518 sptr<IDistributedSched> proxy = GetDms();
519 ASSERT_NE(nullptr, proxy);
520
521 AAFwk::Want want;
522 AppExecFwk::ElementName element("255.255.255.255", "com.ohos.distributedmusicplayer",
523 "com.ohos.distributedmusicplayer.MainAbility");
524 want.SetElement(element);
525 AppExecFwk::AbilityInfo abilityInfo;
526 CallerInfo callerInfo;
527 callerInfo.uid = 0;
528 callerInfo.sourceDeviceId = "255.255.255.255";
529 IDistributedSched::AccountInfo accountInfo;
530
531 int result1 = proxy->SendResultFromRemote(want, 0, callerInfo, accountInfo, 0);
532 DTEST_LOG << "result1 is" << result1 << std::endl;
533 AppExecFwk::ElementName element2("", "com.ohos.distributedmusicplayer",
534 "com.ohos.distributedmusicplayer.MainAbilityService");
535 want.SetElement(element2);
536 int missionId = 0;
537 want.SetParam(DMS_SRC_NETWORK_ID, callerInfo.sourceDeviceId);
538 want.SetParam(DMS_MISSION_ID, missionId);
539 int result2 = proxy->SendResultFromRemote(want, 0, callerInfo, accountInfo, 0);
540 DTEST_LOG << "result2:" << result2 << std::endl;
541
542 /**
543 * @tc.steps: step1. call StartAbilityFromRemote when remoteDeviceId is valid.
544 */
545 const std::string remoteDeviceId = "123456";
546 const OHOS::AppExecFwk::FormShareInfo formShareInfo {};
547 int32_t result = DistributedSchedService::GetInstance().StartRemoteShareForm(remoteDeviceId, formShareInfo);
548 EXPECT_EQ(result, GET_REMOTE_DMS_FAIL);
549 DTEST_LOG << "DistributedSchedServiceFirstTest StartRemoteShareForm_002 end" << std::endl;
550 }
551 #endif
552
553 /**
554 * @tc.name: StartAbilityFromRemote_003
555 * @tc.desc: call StartAbilityFromRemote with dms
556 * @tc.type: FUNC
557 */
558 HWTEST_F(DistributedSchedServiceFirstTest, StartAbilityFromRemote_003, TestSize.Level1)
559 {
560 DTEST_LOG << "DistributedSchedServiceFirstTest StartAbilityFromRemote_003 start" << std::endl;
561 sptr<IDistributedSched> proxy = GetDms();
562
563 AAFwk::Want want;
564 AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
565 "com.ohos.distributedmusicplayer.MainAbility");
566 want.SetElement(element);
567 AppExecFwk::AbilityInfo abilityInfo;
568 GetAbilityInfo("com.ohos.distributedmusicplayer", "com.ohos.distributedmusicplayer.MainAbility",
569 "com.ohos.distributedmusicplayer", "192.168.43.100", abilityInfo);
570 CallerInfo callerInfo;
571 callerInfo.uid = 0;
572 callerInfo.sourceDeviceId = "255.255.255.255";
573 IDistributedSched::AccountInfo accountInfo;
574
575 int result1 = DistributedSchedService::GetInstance().StartAbilityFromRemote(want,
576 abilityInfo, 0, callerInfo, accountInfo);
577 DTEST_LOG << "result1:" << result1 << std::endl;
578
579 AppExecFwk::ElementName element2("", "com.ohos.distributedmusicplayer",
580 "com.ohos.distributedmusicplayer.MainAbilityService");
581 want.SetElement(element2);
582 GetAbilityInfo("com.ohos.distributedmusicplayer", "com.ohos.distributedmusicplayer.MainAbilityService",
583 "com.ohos.distributedmusicplayer", "192.168.43.100", abilityInfo);
584 int result2 = DistributedSchedService::GetInstance().StartAbilityFromRemote(want,
585 abilityInfo, 0, callerInfo, accountInfo);
586 DTEST_LOG << "result2:" << result2 << std::endl;
587 EXPECT_EQ(static_cast<int>(INVALID_REMOTE_PARAMETERS_ERR), result1);
588 EXPECT_EQ(static_cast<int>(INVALID_REMOTE_PARAMETERS_ERR), result2);
589 DTEST_LOG << "DistributedSchedServiceFirstTest StartAbilityFromRemote_003 end" << std::endl;
590 }
591
592 /**
593 * @tc.name: StartAbilityFromRemote_004
594 * @tc.desc: call StartAbilityFromRemote
595 * @tc.type: FUNC
596 */
597 HWTEST_F(DistributedSchedServiceFirstTest, StartAbilityFromRemote_004, TestSize.Level1)
598 {
599 DTEST_LOG << "DistributedSchedServiceFirstTest StartAbilityFromRemote_004 start" << std::endl;
600 AAFwk::Want want;
601 std::string localDeviceId;
602 DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
603 AppExecFwk::ElementName element(localDeviceId, "com.ohos.distributedmusicplayer",
604 "com.ohos.distributedmusicplayer.MainAbility");
605 want.SetElement(element);
606 AppExecFwk::AbilityInfo abilityInfo;
607 GetAbilityInfo("com.ohos.distributedmusicplayer", "com.ohos.distributedmusicplayer.MainAbility",
608 "com.ohos.distributedmusicplayer", "192.168.43.100", abilityInfo);
609 abilityInfo.visible = true;
610 abilityInfo.permissions.clear();
611 CallerInfo callerInfo;
612 callerInfo.uid = 0;
613 callerInfo.sourceDeviceId = LOCAL_DEVICEID;
614 IDistributedSched::AccountInfo accountInfo;
615 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
616 accountInfo.groupIdList.push_back("123456");
617 int result = DistributedSchedService::GetInstance().StartAbilityFromRemote(want,
618 abilityInfo, 0, callerInfo, accountInfo);
619 DTEST_LOG << "result:" << result << std::endl;
620 EXPECT_EQ(static_cast<int>(INVALID_REMOTE_PARAMETERS_ERR), result);
621 DTEST_LOG << "DistributedSchedServiceFirstTest StartAbilityFromRemote_004 end" << std::endl;
622 }
623
624 /**
625 * @tc.name: StartAbilityFromRemote_005
626 * @tc.desc: test StartAbilityFromRemote
627 * @tc.type: FUNC
628 * @tc.require: issueI5T6GJ
629 */
630 HWTEST_F(DistributedSchedServiceFirstTest, StartAbilityFromRemote_005, TestSize.Level3)
631 {
632 DTEST_LOG << "DistributedSchedServiceFirstTest StartAbilityFromRemote_005 start" << std::endl;
633
634 if (DistributedSchedService::GetInstance().dschedContinuation_ == nullptr) {
635 DistributedSchedService::GetInstance().dschedContinuation_ = std::make_shared<DSchedContinuation>();
636 }
637 int32_t missionId = MISSION_ID;
638 bool isSuccess = false;
639 DistributedSchedService::GetInstance().NotifyContinuationCallbackResult(missionId, isSuccess);
640
641 AAFwk::Want want;
642 std::string localDeviceId;
643 DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
644 AppExecFwk::ElementName element(localDeviceId, BUNDLE_NAME,
645 ABILITY_NAME);
646 want.SetElement(element);
647 want.SetParam(DMS_IS_CALLER_BACKGROUND, false);
648 AppExecFwk::AbilityInfo abilityInfo;
649 abilityInfo.permissions.clear();
650 CallerInfo callerInfo;
651 callerInfo.uid = 0;
652 callerInfo.sourceDeviceId = LOCAL_DEVICEID;
653 bool result = BundleManagerInternal::GetCallerAppIdFromBms(BUNDLE_NAME, callerInfo.callerAppId);
654 EXPECT_TRUE(result);
655 IDistributedSched::AccountInfo accountInfo;
656 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
657 int ret = DistributedSchedService::GetInstance().StartAbilityFromRemote(want,
658 abilityInfo, 0, callerInfo, accountInfo);
659 EXPECT_EQ(ret, INVALID_REMOTE_PARAMETERS_ERR);
660 DTEST_LOG << "DistributedSchedServiceFirstTest StartAbilityFromRemote_005 end" << std::endl;
661 }
662
663 /**
664 * @tc.name: SendResultFromRemote_001
665 * @tc.desc: call SendResultFromRemote with illegal param
666 * @tc.type: FUNC
667 */
668 HWTEST_F(DistributedSchedServiceFirstTest, SendResultFromRemote_001, TestSize.Level1)
669 {
670 DTEST_LOG << "DistributedSchedServiceFirstTest SendResultFromRemote_001 start" << std::endl;
671 sptr<IDistributedSched> proxy = GetDms();
672 ASSERT_NE(nullptr, proxy);
673 AAFwk::Want want;
674 CallerInfo callerInfo;
675 callerInfo.uid = 0;
676 callerInfo.sourceDeviceId = "255.255.255.255";
677 IDistributedSched::AccountInfo accountInfo;
678 /**
679 * @tc.steps: step1. SendResultFromRemote with uninitialized params
680 * @tc.expected: step1. SendResultFromRemote return INVALID_REMOTE_PARAMETERS_ERR
681 */
682 int result1 = proxy->SendResultFromRemote(want, 0, callerInfo, accountInfo, 0);
683 DTEST_LOG << "result1:" << result1 << std::endl;
684 /**
685 * @tc.steps: step1. SendResultFromRemote with with empty deviceId
686 * @tc.expected: step1. SendResultFromRemote return INVALID_REMOTE_PARAMETERS_ERR
687 */
688 AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
689 "com.ohos.distributedmusicplayer.MainAbility");
690 want.SetElement(element);
691 int result2 = proxy->SendResultFromRemote(want, 0, callerInfo, accountInfo, 0);
692 DTEST_LOG << "result2:" << result2 << std::endl;
693 EXPECT_EQ(static_cast<int>(IPC_STUB_UNKNOW_TRANS_ERR), result1);
694 EXPECT_EQ(static_cast<int>(IPC_STUB_UNKNOW_TRANS_ERR), result2);
695 DTEST_LOG << "DistributedSchedServiceFirstTest SendResultFromRemote end" << std::endl;
696 }
697
698 /**
699 * @tc.name: SendResultFromRemote_002
700 * @tc.desc: call SendResultFromRemote with dms
701 * @tc.type: FUNC
702 */
703 HWTEST_F(DistributedSchedServiceFirstTest, SendResultFromRemote_002, TestSize.Level1)
704 {
705 DTEST_LOG << "DistributedSchedServiceFirstTest SendResultFromRemote_002 start" << std::endl;
706 sptr<IDistributedSched> proxy = GetDms();
707
708 AAFwk::Want want;
709 AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
710 "com.ohos.distributedmusicplayer.MainAbility");
711 want.SetElement(element);
712 CallerInfo callerInfo;
713 callerInfo.uid = 0;
714 callerInfo.sourceDeviceId = "255.255.255.255";
715 IDistributedSched::AccountInfo accountInfo;
716
717 int result1 = DistributedSchedService::GetInstance().SendResultFromRemote(want, 0, callerInfo, accountInfo, 0);
718 DTEST_LOG << "result1:" << result1 << std::endl;
719
720 AppExecFwk::ElementName element2("", "com.ohos.distributedmusicplayer",
721 "com.ohos.distributedmusicplayer.MainAbilityService");
722 want.SetElement(element2);
723 int result2 = DistributedSchedService::GetInstance().SendResultFromRemote(want, 0, callerInfo, accountInfo, 0);
724 DTEST_LOG << "result2:" << result2 << std::endl;
725 EXPECT_EQ(static_cast<int>(INVALID_REMOTE_PARAMETERS_ERR), result1);
726 EXPECT_EQ(static_cast<int>(INVALID_REMOTE_PARAMETERS_ERR), result2);
727 DTEST_LOG << "DistributedSchedServiceFirstTest SendResultFromRemote_002 end" << std::endl;
728 }
729
730 /**
731 * @tc.name: SendResultFromRemote_003
732 * @tc.desc: call SendResultFromRemote
733 * @tc.type: FUNC
734 */
735 HWTEST_F(DistributedSchedServiceFirstTest, SendResultFromRemote_003, TestSize.Level1)
736 {
737 DTEST_LOG << "DistributedSchedServiceFirstTest SendResultFromRemote_003 start" << std::endl;
738 AAFwk::Want want;
739 AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
740 "com.ohos.distributedmusicplayer.MainAbility");
741 want.SetElement(element);
742 std::string localDeviceId;
743 DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
744 want.SetParam(DMS_SRC_NETWORK_ID, localDeviceId);
745 CallerInfo callerInfo;
746 callerInfo.uid = 0;
747 callerInfo.sourceDeviceId = LOCAL_DEVICEID;
748 IDistributedSched::AccountInfo accountInfo;
749 /**
750 * @tc.steps: step1. call RemoveContinuationTimeout
751 */
752 DTEST_LOG << "DistributedSchedServiceFirstTest RemoveContinuationTimeout_001 start" << std::endl;
753 if (DistributedSchedService::GetInstance().dschedContinuation_ == nullptr) {
754 DistributedSchedService::GetInstance().dschedContinuation_ = std::make_shared<DSchedContinuation>();
755 }
756 int32_t missionId = MISSION_ID;
757 DistributedSchedService::GetInstance().RemoveContinuationTimeout(missionId);
758 DTEST_LOG << "DistributedSchedServiceFirstTest RemoveContinuationTimeout_001 end" << std::endl;
759
760 int result = DistributedSchedService::GetInstance().SendResultFromRemote(want, 0, callerInfo, accountInfo, 0);
761 DTEST_LOG << "result:" << result << std::endl;
762 EXPECT_EQ(static_cast<int>(INVALID_REMOTE_PARAMETERS_ERR), result);
763 /**
764 * @tc.steps: step2. call RemoteConnectAbilityMappingLocked when connect == nullptr;
765 */
766 DistributedSchedService::GetInstance().RemoteConnectAbilityMappingLocked(nullptr,
767 localDeviceId, localDeviceId, element, callerInfo, TargetComponent::HARMONY_COMPONENT);
768 DTEST_LOG << "DistributedSchedServiceFirstTest SendResultFromRemote_003 end" << std::endl;
769 }
770
771 /**
772 * @tc.name: SendResultFromRemote_004
773 * @tc.desc: test SendResultFromRemote
774 * @tc.type: FUNC
775 * @tc.require: issueI5T6GJ
776 */
777 HWTEST_F(DistributedSchedServiceFirstTest, SendResultFromRemote_004, TestSize.Level3)
778 {
779 DTEST_LOG << "DistributedSchedServiceFirstTest SendResultFromRemote_004 start" << std::endl;
780
781 if (DistributedSchedService::GetInstance().dschedContinuation_ == nullptr) {
782 DistributedSchedService::GetInstance().dschedContinuation_ = std::make_shared<DSchedContinuation>();
783 }
784 int32_t missionId = MISSION_ID;
785 bool resultCode = ERR_OK;
786 DistributedSchedService::GetInstance().NotifyContinuationCallbackResult(missionId, resultCode);
787
788 AAFwk::Want want;
789 std::string localDeviceId;
790 DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
791 want.SetParam(DMS_SRC_NETWORK_ID, localDeviceId);
792 AppExecFwk::ElementName element(localDeviceId, "com.third.hiworld.example",
793 "bmsThirdBundle");
794 want.SetElement(element);
795 CallerInfo callerInfo;
796 callerInfo.uid = 0;
797 callerInfo.sourceDeviceId = LOCAL_DEVICEID;
798 IDistributedSched::AccountInfo accountInfo;
799 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
800 int ret = DistributedSchedService::GetInstance().SendResultFromRemote(want, 0, callerInfo, accountInfo, 0);
801 EXPECT_NE(ret, ERR_OK);
802 DTEST_LOG << "DistributedSchedServiceFirstTest SendResultFromRemote_004 end" << std::endl;
803 }
804
805 /**
806 * @tc.name: SendResultFromRemote_005
807 * @tc.desc: test SendResultFromRemote
808 * @tc.type: FUNC
809 * @tc.require: I6P0I9
810 */
811 HWTEST_F(DistributedSchedServiceFirstTest, SendResultFromRemote_005, TestSize.Level3)
812 {
813 DTEST_LOG << "DistributedSchedServiceFirstTest SendResultFromRemote_005 start" << std::endl;
814 AAFwk::Want want;
815 std::string localDeviceId;
816 DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
817 want.SetParam(DMS_SRC_NETWORK_ID, localDeviceId);
818 AppExecFwk::ElementName element(localDeviceId, "com.third.hiworld.example",
819 "bmsThirdBundle");
820 want.SetElement(element);
821 CallerInfo callerInfo;
822 callerInfo.uid = 0;
823 callerInfo.sourceDeviceId = LOCAL_DEVICEID;
824 IDistributedSched::AccountInfo accountInfo;
825 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
826 int ret = DistributedSchedService::GetInstance().SendResultFromRemote(want, 1, callerInfo, accountInfo, 0);
827 EXPECT_NE(ret, ERR_OK);
828 DTEST_LOG << "DistributedSchedServiceFirstTest SendResultFromRemote_005 end" << std::endl;
829 }
830
831 /**
832 * @tc.name: SendResultFromRemote_006
833 * @tc.desc: test SendResultFromRemote
834 * @tc.type: FUNC
835 * @tc.require: I6P0I9
836 */
837 HWTEST_F(DistributedSchedServiceFirstTest, SendResultFromRemote_006, TestSize.Level3)
838 {
839 DTEST_LOG << "DistributedSchedServiceFirstTest SendResultFromRemote_006 start" << std::endl;
840 AAFwk::Want want;
841 std::string localDeviceId;
842 DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
843 want.SetParam(DMS_SRC_NETWORK_ID, localDeviceId);
844 AppExecFwk::ElementName element(localDeviceId, "com.third.hiworld.example",
845 "bmsThirdBundle");
846 want.SetElement(element);
847 CallerInfo callerInfo;
848 callerInfo.uid = 1;
849 callerInfo.sourceDeviceId = LOCAL_DEVICEID;
850 IDistributedSched::AccountInfo accountInfo;
851 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
852 int ret = DistributedSchedService::GetInstance().SendResultFromRemote(want, 1, callerInfo, accountInfo, 0);
853 EXPECT_NE(ret, ERR_OK);
854 DTEST_LOG << "DistributedSchedServiceFirstTest SendResultFromRemote_006 end" << std::endl;
855 }
856
857 /**
858 * @tc.name: SendResultFromRemote_007
859 * @tc.desc: test SendResultFromRemote
860 * @tc.type: FUNC
861 * @tc.require: I6P0I9
862 */
863 HWTEST_F(DistributedSchedServiceFirstTest, SendResultFromRemote_007, TestSize.Level3)
864 {
865 DTEST_LOG << "DistributedSchedServiceFirstTest SendResultFromRemote_007 start" << std::endl;
866 AAFwk::Want want;
867 std::string localDeviceId;
868 DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
869 want.SetParam(DMS_SRC_NETWORK_ID, localDeviceId);
870 AppExecFwk::ElementName element(localDeviceId, "com.third.hiworld.example",
871 "bmsThirdBundle");
872 want.SetElement(element);
873 CallerInfo callerInfo;
874 callerInfo.uid = 0;
875 callerInfo.sourceDeviceId = localDeviceId;
876 IDistributedSched::AccountInfo accountInfo;
877 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
878 int32_t ret = DistributedSchedService::GetInstance().SendResultFromRemote(want, 0, callerInfo, accountInfo, 0);
879 EXPECT_NE(ret, ERR_OK);
880 DTEST_LOG << "DistributedSchedServiceFirstTest SendResultFromRemote_007 end" << std::endl;
881 }
882
883 /**
884 * @tc.name: SendResultFromRemote_008
885 * @tc.desc: test SendResultFromRemote
886 * @tc.type: FUNC
887 * @tc.require: I6P0I9
888 */
889 HWTEST_F(DistributedSchedServiceFirstTest, SendResultFromRemote_008, TestSize.Level3)
890 {
891 DTEST_LOG << "DistributedSchedServiceFirstTest SendResultFromRemote_008 start" << std::endl;
892 AAFwk::Want want;
893 std::string localDeviceId;
894 DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
895 want.SetParam(DMS_SRC_NETWORK_ID, localDeviceId);
896 AppExecFwk::ElementName element(localDeviceId, "com.third.hiworld.example",
897 "bmsThirdBundle");
898 want.SetElement(element);
899 CallerInfo callerInfo;
900 callerInfo.uid = 0;
901 callerInfo.sourceDeviceId = localDeviceId;
902 IDistributedSched::AccountInfo accountInfo;
903 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
904 int ret = DistributedSchedService::GetInstance().SendResultFromRemote(want, 1, callerInfo, accountInfo, 0);
905 EXPECT_NE(ret, ERR_OK);
906 DTEST_LOG << "DistributedSchedServiceFirstTest SendResultFromRemote_008 end" << std::endl;
907 }
908
909 /**
910 * @tc.name: ContinueMission_001
911 * @tc.desc: call ContinueMission
912 * @tc.type: FUNC
913 */
914 HWTEST_F(DistributedSchedServiceFirstTest, ContinueMission_001, TestSize.Level1)
915 {
916 DTEST_LOG << "DSchedContinuationTest ContinueMission_001 start" << std::endl;
917 WantParams wantParams;
918 auto callback = GetDSchedService();
919 int32_t missionId = MISSION_ID;
920 std::string localDeviceId;
921 DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
922 int32_t result = DistributedSchedService::GetInstance().ContinueMission(
923 "string", localDeviceId, missionId, callback, wantParams);
924 EXPECT_EQ(static_cast<int>(INVALID_REMOTE_PARAMETERS_ERR), result);
925 DTEST_LOG << "DSchedContinuationTest ContinueMission_001 end" << std::endl;
926 }
927
928 /**
929 * @tc.name: ContinueMission_002
930 * @tc.desc: call ContinueMission
931 * @tc.type: FUNC
932 */
933 HWTEST_F(DistributedSchedServiceFirstTest, ContinueMission_002, TestSize.Level1)
934 {
935 DTEST_LOG << "DSchedContinuationTest ContinueMission_002 start" << std::endl;
936 WantParams wantParams;
937 auto callback = GetDSchedService();
938 int32_t missionId = MISSION_ID;
939 std::string localDeviceId;
940 DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
941 int32_t result = DistributedSchedService::GetInstance().ContinueMission(
942 "string", "string", missionId, callback, wantParams);
943 EXPECT_EQ(static_cast<int>(OPERATION_DEVICE_NOT_INITIATOR_OR_TARGET), result);
944 DTEST_LOG << "DSchedContinuationTest ContinueMission_002 end" << std::endl;
945 }
946
947 /**
948 * @tc.name: ContinueMission_003
949 * @tc.desc: call ContinueMission
950 * @tc.type: FUNC
951 * @tc.require: I7F8KH
952 */
953 HWTEST_F(DistributedSchedServiceFirstTest, ContinueMission_003, TestSize.Level1)
954 {
955 DTEST_LOG << "DSchedContinuationTest ContinueMission_003 start" << std::endl;
956
957 WantParams wantParams;
958 auto callback = GetDSchedService();
959 std::string bundleName = BUNDLE_NAME;
960
961 /**
962 * @tc.steps: step1. test ContinueMission when srcDeviceId is empty;
963 */
964 int32_t result = DistributedSchedService::GetInstance().ContinueMission(
965 "", "string", BUNDLE_NAME, callback, wantParams);
966 EXPECT_EQ(result, INVALID_PARAMETERS_ERR);
967
968 /**
969 * @tc.steps: step2. test ContinueMission when dstDeviceId is empty;
970 */
971 result = DistributedSchedService::GetInstance().ContinueMission(
972 "string", "", bundleName, callback, wantParams);
973 EXPECT_EQ(result, INVALID_PARAMETERS_ERR);
974
975 /**
976 * @tc.steps: step3. test ContinueMission when callback is empty;
977 */
978 result = DistributedSchedService::GetInstance().ContinueMission(
979 "string", "string", bundleName, nullptr, wantParams);
980 EXPECT_EQ(result, INVALID_PARAMETERS_ERR);
981
982 DTEST_LOG << "DSchedContinuationTest ContinueMission_003 end" << std::endl;
983 }
984
985 /**
986 * @tc.name: StartContinuation_001
987 * @tc.desc: call StartContinuation
988 * @tc.type: FUNC
989 * @tc.require: I5NOA1
990 */
991 HWTEST_F(DistributedSchedServiceFirstTest, StartContinuation_001, TestSize.Level1)
992 {
993 DTEST_LOG << "DSchedContinuationTest StartContinuation_001 start" << std::endl;
994 AAFwk::Want want;
995 AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
996 "com.ohos.distributedmusicplayer.MainAbility");
997 want.SetElement(element);
998 int32_t missionId = MISSION_ID;
999 int32_t callerUid = 0;
1000 int32_t status = 1;
1001 uint32_t accessToken = 0;
1002 int32_t ret = DistributedSchedService::GetInstance().StartContinuation(
1003 want, missionId, callerUid, status, accessToken);
1004 EXPECT_EQ(static_cast<int>(INVALID_REMOTE_PARAMETERS_ERR), ret);
1005 CallerInfo callerInfo;
1006 ConnectInfo connectInfo;
1007 /**
1008 * @tc.steps: step1. ReportDistributedComponentChange when componentChangeHandler_ is nullptr
1009 */
1010 DistributedSchedService::GetInstance().componentChangeHandler_ = nullptr;
1011 DistributedSchedService::GetInstance().ReportDistributedComponentChange(callerInfo,
1012 1, IDistributedSched::CALL, IDistributedSched::CALLER);
1013 /**
1014 * @tc.steps: step2. ReportDistributedComponentChange when componentChangeHandler_ is nullptr
1015 */
1016 DistributedSchedService::GetInstance().ReportDistributedComponentChange(connectInfo,
1017 1, IDistributedSched::CALL, IDistributedSched::CALLEE);
1018 /**
1019 * @tc.steps: step3. ReportDistributedComponentChange when componentChangeHandler_ is not nullptr
1020 */
1021 auto runner = AppExecFwk::EventRunner::Create("DmsComponentChange");
1022 DistributedSchedService::GetInstance().componentChangeHandler_ = std::make_shared<AppExecFwk::EventHandler>(runner);
1023 DistributedSchedService::GetInstance().ReportDistributedComponentChange(callerInfo,
1024 1, IDistributedSched::CALL, IDistributedSched::CALLER);
1025 /**
1026 * @tc.steps: step4. ReportDistributedComponentChange when callerInfo.bundleNames is not empty
1027 */
1028 callerInfo.bundleNames.emplace_back("bundleName");
1029 DistributedSchedService::GetInstance().ReportDistributedComponentChange(callerInfo,
1030 1, IDistributedSched::CALL, IDistributedSched::CALLER);
1031 /**
1032 * @tc.steps: step5. ReportDistributedComponentChange when componentChangeHandler_ is not nullptr
1033 */
1034 DistributedSchedService::GetInstance().ReportDistributedComponentChange(connectInfo,
1035 1, IDistributedSched::CALL, IDistributedSched::CALLEE);
1036 DTEST_LOG << "DSchedContinuationTest StartContinuation_001 end" << std::endl;
1037 }
1038
1039 /**
1040 * @tc.name: StartContinuation_002
1041 * @tc.desc: call StartContinuation
1042 * @tc.type: FUNC
1043 */
1044 HWTEST_F(DistributedSchedServiceFirstTest, StartContinuation_002, TestSize.Level1)
1045 {
1046 DTEST_LOG << "DSchedContinuationTest StartContinuation_002 start" << std::endl;
1047 if (DistributedSchedService::GetInstance().dschedContinuation_ == nullptr) {
1048 DistributedSchedService::GetInstance().dschedContinuation_ = std::make_shared<DSchedContinuation>();
1049 }
1050 AAFwk::Want want;
1051 AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
1052 "com.ohos.distributedmusicplayer.MainAbility");
1053 int32_t flags = Want::FLAG_ABILITY_CONTINUATION;
1054 want.SetElement(element);
1055 want.SetFlags(flags);
1056 int32_t missionId = MISSION_ID;
1057 int32_t callerUid = 0;
1058 int32_t status = 1;
1059 uint32_t accessToken = 0;
1060 int32_t ret = DistributedSchedService::GetInstance().StartContinuation(
1061 want, missionId, callerUid, status, accessToken);
1062 EXPECT_EQ(static_cast<int>(INVALID_REMOTE_PARAMETERS_ERR), ret);
1063 DTEST_LOG << "DSchedContinuationTest StartContinuation_002 end" << std::endl;
1064 }
1065
1066 /**
1067 * @tc.name: StartContinuation_003
1068 * @tc.desc: call StartContinuation
1069 * @tc.type: FUNC
1070 * @tc.require: I6O5T3
1071 */
1072 HWTEST_F(DistributedSchedServiceFirstTest, StartContinuation_003, TestSize.Level3)
1073 {
1074 DTEST_LOG << "DSchedContinuationTest StartContinuation_003 start" << std::endl;
1075 if (DistributedSchedService::GetInstance().dschedContinuation_ == nullptr) {
1076 DistributedSchedService::GetInstance().dschedContinuation_ = std::make_shared<DSchedContinuation>();
1077 }
1078 AAFwk::Want want;
1079 AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
1080 "com.ohos.distributedmusicplayer.MainAbility");
1081 int32_t flags = Want::FLAG_ABILITY_CONTINUATION;
1082 want.SetElement(element);
1083 want.SetFlags(flags);
1084 int32_t missionId = 0;
1085 int32_t callerUid = 1;
1086 int32_t status = ERR_OK;
1087 uint32_t accessToken = 0;
1088 int32_t ret = DistributedSchedService::GetInstance().StartContinuation(
1089 want, missionId, callerUid, status, accessToken);
1090 EXPECT_EQ(static_cast<int>(INVALID_PARAMETERS_ERR), ret);
1091 DTEST_LOG << "DSchedContinuationTest StartContinuation_003 end" << std::endl;
1092 }
1093
1094 /**
1095 * @tc.name: StartContinuation_004
1096 * @tc.desc: call StartContinuation
1097 * @tc.type: FUNC
1098 * @tc.require: I6O5T3
1099 */
1100 HWTEST_F(DistributedSchedServiceFirstTest, StartContinuation_004, TestSize.Level3)
1101 {
1102 DTEST_LOG << "DSchedContinuationTest StartContinuation_004 start" << std::endl;
1103 if (DistributedSchedService::GetInstance().dschedContinuation_ == nullptr) {
1104 DistributedSchedService::GetInstance().dschedContinuation_ = std::make_shared<DSchedContinuation>();
1105 }
1106 AAFwk::Want want;
1107 AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
1108 "com.ohos.distributedmusicplayer.MainAbility");
1109 int32_t flags = Want::FLAG_ABILITY_CONTINUATION;
1110 want.SetElement(element);
1111 want.SetFlags(flags);
1112 int32_t missionId = 0;
1113 int32_t callerUid = 0;
1114 int32_t status = ERR_OK;
1115 uint32_t accessToken = 1;
1116 int32_t ret = DistributedSchedService::GetInstance().StartContinuation(
1117 want, missionId, callerUid, status, accessToken);
1118 EXPECT_EQ(static_cast<int>(INVALID_PARAMETERS_ERR), ret);
1119 DTEST_LOG << "DSchedContinuationTest StartContinuation_004 end" << std::endl;
1120 }
1121
1122 /**
1123 * @tc.name: StartContinuation_005
1124 * @tc.desc: call StartContinuation
1125 * @tc.type: FUNC
1126 * @tc.require: I6O5T3
1127 */
1128 HWTEST_F(DistributedSchedServiceFirstTest, StartContinuation_005, TestSize.Level3)
1129 {
1130 DTEST_LOG << "DSchedContinuationTest StartContinuation_005 start" << std::endl;
1131 if (DistributedSchedService::GetInstance().dschedContinuation_ == nullptr) {
1132 DistributedSchedService::GetInstance().dschedContinuation_ = std::make_shared<DSchedContinuation>();
1133 }
1134 AAFwk::Want want;
1135 AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
1136 "com.ohos.distributedmusicplayer.MainAbility");
1137 int32_t flags = Want::FLAG_ABILITY_CONTINUATION;
1138 want.SetElement(element);
1139 want.SetFlags(flags);
1140 int32_t missionId = 0;
1141 int32_t callerUid = 1;
1142 int32_t status = ERR_OK;
1143 uint32_t accessToken = 1;
1144 bool resultCode = true;
1145 int32_t ret = DistributedSchedService::GetInstance().StartContinuation(
1146 want, missionId, callerUid, status, accessToken);
1147 DistributedSchedService::GetInstance().NotifyContinuationCallbackResult(missionId, resultCode);
1148 EXPECT_EQ(static_cast<int>(INVALID_PARAMETERS_ERR), ret);
1149 DTEST_LOG << "DSchedContinuationTest StartContinuation_005 end" << std::endl;
1150 }
1151
1152 /**
1153 * @tc.name: StartContinuation_006
1154 * @tc.desc: call StartContinuation
1155 * @tc.type: FUNC
1156 * @tc.require: I6O5T3
1157 */
1158 HWTEST_F(DistributedSchedServiceFirstTest, StartContinuation_006, TestSize.Level3)
1159 {
1160 DTEST_LOG << "DSchedContinuationTest StartContinuation_006 start" << std::endl;
1161 if (DistributedSchedService::GetInstance().dschedContinuation_ == nullptr) {
1162 DistributedSchedService::GetInstance().dschedContinuation_ = std::make_shared<DSchedContinuation>();
1163 }
1164 AAFwk::Want want;
1165 AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
1166 "com.ohos.distributedmusicplayer.MainAbility");
1167 int32_t flags = Want::FLAG_ABILITY_CONTINUATION;
1168 want.SetElement(element);
1169 want.SetFlags(flags);
1170 int32_t missionId = 0;
1171 int32_t callerUid = 0;
1172 int32_t status = ERR_OK;
1173 uint32_t accessToken = 0;
1174 bool resultCode = ERR_OK;
1175 int32_t ret = DistributedSchedService::GetInstance().StartContinuation(
1176 want, missionId, callerUid, status, accessToken);
1177 DistributedSchedService::GetInstance().NotifyContinuationCallbackResult(missionId, resultCode);
1178 EXPECT_EQ(static_cast<int>(INVALID_PARAMETERS_ERR), ret);
1179 DTEST_LOG << "DSchedContinuationTest StartContinuation_006 end" << std::endl;
1180 }
1181
1182 /**
1183 * @tc.name: StartContinuation_007
1184 * @tc.desc: call StartContinuation
1185 * @tc.type: FUNC
1186 * @tc.type: I6O5T3
1187 */
1188 HWTEST_F(DistributedSchedServiceFirstTest, StartContinuation_007, TestSize.Level3)
1189 {
1190 DTEST_LOG << "DSchedContinuationTest StartContinuation_007 start" << std::endl;
1191 if (DistributedSchedService::GetInstance().dschedContinuation_ == nullptr) {
1192 DistributedSchedService::GetInstance().dschedContinuation_ = std::make_shared<DSchedContinuation>();
1193 }
1194 AAFwk::Want want;
1195 AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
1196 "com.ohos.distributedmusicplayer.MainAbility");
1197 int32_t flags = Want::FLAG_ABILITY_CONTINUATION;
1198 want.SetElement(element);
1199 want.SetFlags(flags);
1200 int32_t missionId = 0;
1201 int32_t callerUid = 0;
1202 int32_t status = ERR_OK;
1203 uint32_t accessToken = 0;
1204 bool isSuccess = false;
1205 /**
1206 * @tc.steps: step1. call GetFormMgrProxy
1207 */
1208 #ifdef SUPPORT_DISTRIBUTED_FORM_SHARE
1209 DTEST_LOG << "DSchedContinuationTest GetFormMgrProxy_001 start" << std::endl;
1210 DistributedSchedService::GetInstance().GetFormMgrProxy();
1211 DTEST_LOG << "DSchedContinuationTest GetFormMgrProxy_001 end" << std::endl;
1212 #endif
1213
1214 int32_t ret = DistributedSchedService::GetInstance().StartContinuation(
1215 want, missionId, callerUid, status, accessToken);
1216 DistributedSchedService::GetInstance().NotifyCompleteContinuation(DEVICE_ID_NULL, SESSION_ID, isSuccess);
1217 EXPECT_EQ(static_cast<int>(INVALID_PARAMETERS_ERR), ret);
1218 DTEST_LOG << "DSchedContinuationTest StartContinuation_007 end" << std::endl;
1219 }
1220
1221 /**
1222 * @tc.name: StartContinuation_008
1223 * @tc.desc: call StartContinuation
1224 * @tc.type: FUNC
1225 * @tc.type: I6O5T3
1226 */
1227 HWTEST_F(DistributedSchedServiceFirstTest, StartContinuation_008, TestSize.Level3)
1228 {
1229 DTEST_LOG << "DSchedContinuationTest StartContinuation_008 start" << std::endl;
1230 if (DistributedSchedService::GetInstance().dschedContinuation_ == nullptr) {
1231 DistributedSchedService::GetInstance().dschedContinuation_ = std::make_shared<DSchedContinuation>();
1232 }
1233 AAFwk::Want want;
1234 AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
1235 "com.ohos.distributedmusicplayer.MainAbility");
1236 int32_t flags = Want::FLAG_ABILITY_CONTINUATION;
1237 want.SetElement(element);
1238 want.SetFlags(flags);
1239 int32_t missionId = 0;
1240 int32_t callerUid = 0;
1241 int32_t status = ERR_OK;
1242 uint32_t accessToken = 0;
1243 bool isSuccess = false;
1244 /**
1245 * @tc.steps: step1. call GetFormMgrProxy
1246 */
1247 #ifdef SUPPORT_DISTRIBUTED_FORM_SHARE
1248 DTEST_LOG << "DSchedContinuationTest GetFormMgrProxy_001 start" << std::endl;
1249 DistributedSchedService::GetInstance().GetFormMgrProxy();
1250 DTEST_LOG << "DSchedContinuationTest GetFormMgrProxy_001 end" << std::endl;
1251 #endif
1252
1253 int32_t ret = DistributedSchedService::GetInstance().StartContinuation(
1254 want, missionId, callerUid, status, accessToken);
1255 DistributedSchedService::GetInstance().NotifyCompleteContinuation(DEVICE_ID_NULL, SESSION_ID, isSuccess);
1256 EXPECT_EQ(static_cast<int>(INVALID_PARAMETERS_ERR), ret);
1257 DTEST_LOG << "DSchedContinuationTest StartContinuation_008 end" << std::endl;
1258 }
1259
1260 /**
1261 * @tc.name: NotifyCompleteContinuation_001
1262 * @tc.desc: call NotifyCompleteContinuation
1263 * @tc.type: FUNC
1264 */
1265 HWTEST_F(DistributedSchedServiceFirstTest, NotifyCompleteContinuation_001, TestSize.Level1)
1266 {
1267 DTEST_LOG << "DSchedContinuationTest NotifyCompleteContinuation_001 start" << std::endl;
1268 bool isSuccess = false;
1269 EXPECT_NO_FATAL_FAILURE(DistributedSchedService::GetInstance().NotifyCompleteContinuation(DEVICE_ID,
1270 SESSION_ID, isSuccess));
1271 DTEST_LOG << "DSchedContinuationTest NotifyCompleteContinuation_001 end" << std::endl;
1272 }
1273
1274 /**
1275 * @tc.name: ConnectRemoteAbility001
1276 * @tc.desc: connect remote ability with right uid and pid
1277 * @tc.type: FUNC
1278 * @tc.require: I6P0I9
1279 */
1280 HWTEST_F(DistributedSchedServiceFirstTest, ConnectRemoteAbility001, TestSize.Level3)
1281 {
1282 DTEST_LOG << "DistributedSchedServiceFirstTest ConnectRemoteAbility001 start" << std::endl;
1283 OHOS::AAFwk::Want want;
1284 want.SetElementName("123_remote_device_id", "ohos.demo.bundleName", "abilityName");
1285 const sptr<IRemoteObject> connect = nullptr;
1286 g_isForeground = true;
1287 int32_t ret = DistributedSchedService::GetInstance().ConnectRemoteAbility(want, connect, 1, 1, 1);
1288 EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
1289 DTEST_LOG << "DistributedSchedServiceFirstTest ConnectRemoteAbility001 end" << std::endl;
1290 }
1291
1292 /**
1293 * @tc.name: ConnectRemoteAbility002
1294 * @tc.desc: connect remote ability with empty deviceId.
1295 * @tc.type: FUNC
1296 * @tc.require: I6P0I9
1297 */
1298 HWTEST_F(DistributedSchedServiceFirstTest, ConnectRemoteAbility002, TestSize.Level3)
1299 {
1300 DTEST_LOG << "DistributedSchedServiceFirstTest ConnectRemoteAbility002 start" << std::endl;
1301 OHOS::AAFwk::Want want;
1302 want.SetElementName("", "ohos.demo.bundleName", "abilityName");
1303 const sptr<IRemoteObject> connect = nullptr;
1304 g_isForeground = true;
1305 int32_t ret = DistributedSchedService::GetInstance().ConnectRemoteAbility(want, connect, 1, 1, 1);
1306 EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
1307 DTEST_LOG << "DistributedSchedServiceFirstTest ConnectRemoteAbility002 end" << std::endl;
1308 }
1309
1310 /**
1311 * @tc.name: ConnectAbilityFromRemote_001
1312 * @tc.desc: test ConnectAbilityFromRemote
1313 * @tc.type: FUNC
1314 * @tc.require: issueI5T6GJ
1315 */
1316 HWTEST_F(DistributedSchedServiceFirstTest, ConnectAbilityFromRemote_001, TestSize.Level3)
1317 {
1318 DTEST_LOG << "DistributedSchedServiceFirstTest ConnectAbilityFromRemote_001 start" << std::endl;
1319 AAFwk::Want want;
1320 AppExecFwk::AbilityInfo abilityInfo;
1321 sptr<IRemoteObject> connect = nullptr;
1322 CallerInfo callerInfo;
1323 IDistributedSched::AccountInfo accountInfo;
1324 int32_t ret = DistributedSchedService::GetInstance().ConnectAbilityFromRemote(want,
1325 abilityInfo, connect, callerInfo, accountInfo);
1326 EXPECT_EQ(ret, INVALID_REMOTE_PARAMETERS_ERR);
1327 DTEST_LOG << "DistributedSchedServiceFirstTest ConnectAbilityFromRemote_001 end" << std::endl;
1328 }
1329
1330 /**
1331 * @tc.name: ConnectAbilityFromRemote_002
1332 * @tc.desc: input invalid params
1333 * @tc.type: FUNC
1334 * @tc.require: issueI5T6GJ
1335 */
1336 HWTEST_F(DistributedSchedServiceFirstTest, ConnectAbilityFromRemote_002, TestSize.Level3)
1337 {
1338 DTEST_LOG << "DistributedSchedServiceFirstTest ConnectAbilityFromRemote_002 start" << std::endl;
1339 AAFwk::Want want;
1340 AppExecFwk::AbilityInfo abilityInfo;
1341 sptr<IRemoteObject> connect(new MockDistributedSched());
1342 CallerInfo callerInfo;
1343 IDistributedSched::AccountInfo accountInfo;
1344 int32_t ret = DistributedSchedService::GetInstance().ConnectAbilityFromRemote(want,
1345 abilityInfo, connect, callerInfo, accountInfo);
1346 EXPECT_EQ(ret, INVALID_REMOTE_PARAMETERS_ERR);
1347 DTEST_LOG << "DistributedSchedServiceFirstTest ConnectAbilityFromRemote_002 end" << std::endl;
1348 }
1349
1350 /**
1351 * @tc.name: ConnectAbilityFromRemote_003
1352 * @tc.desc: input invalid params
1353 * @tc.type: FUNC
1354 * @tc.require: issueI5T6GJ
1355 */
1356 HWTEST_F(DistributedSchedServiceFirstTest, ConnectAbilityFromRemote_003, TestSize.Level3)
1357 {
1358 DTEST_LOG << "DistributedSchedServiceFirstTest ConnectAbilityFromRemote_003 start" << std::endl;
1359 AAFwk::Want want;
1360 AppExecFwk::AbilityInfo abilityInfo;
1361 sptr<IRemoteObject> connect(new MockDistributedSched());
1362 CallerInfo callerInfo;
1363 IDistributedSched::AccountInfo accountInfo;
1364 callerInfo.callerType = CALLER_TYPE_HARMONY;
1365 int32_t ret = DistributedSchedService::GetInstance().ConnectAbilityFromRemote(want,
1366 abilityInfo, connect, callerInfo, accountInfo);
1367 EXPECT_EQ(ret, INVALID_REMOTE_PARAMETERS_ERR);
1368 DTEST_LOG << "DistributedSchedServiceFirstTest ConnectAbilityFromRemote_003 end" << std::endl;
1369 }
1370
1371 /**
1372 * @tc.name: NotifyProcessDiedFromRemote_001
1373 * @tc.desc: call NotifyProcessDiedFromRemote when sourceDeviceId == sourceDeviceId.
1374 * @tc.type: FUNC
1375 * @tc.require: I76THI
1376 */
1377 HWTEST_F(DistributedSchedServiceFirstTest, NotifyProcessDiedFromRemote_001, TestSize.Level3)
1378 {
1379 DTEST_LOG << "DistributedSchedServiceFirstTest NotifyProcessDiedFromRemote_001 start" << std::endl;
1380
1381 sptr<IDistributedSched> proxy = GetDms();
1382
1383 AAFwk::Want want;
1384 AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
1385 "com.ohos.distributedmusicplayer.MainAbility");
1386 want.SetElement(element);
1387 AppExecFwk::AbilityInfo abilityInfo;
1388 GetAbilityInfo("com.ohos.distributedmusicplayer", "com.ohos.distributedmusicplayer.MainAbility",
1389 "com.ohos.distributedmusicplayer", "192.168.43.100", abilityInfo);
1390 CallerInfo callerInfo1;
1391 callerInfo1.uid = 0;
1392 callerInfo1.sourceDeviceId = "255.255.255.255";
1393 IDistributedSched::AccountInfo accountInfo;
1394 accountInfo.accountType = 1;
1395 accountInfo.groupIdList.push_back("123456");
1396
1397 int result1 = DistributedSchedService::GetInstance().StartAbilityFromRemote(want,
1398 abilityInfo, 0, callerInfo1, accountInfo);
1399 DTEST_LOG << "result1:" << result1 << std::endl;
1400
1401 AppExecFwk::ElementName element2("", "com.ohos.distributedmusicplayer",
1402 "com.ohos.distributedmusicplayer.MainAbilityService");
1403 want.SetElement(element2);
1404 GetAbilityInfo("com.ohos.distributedmusicplayer", "com.ohos.distributedmusicplayer.MainAbilityService",
1405 "com.ohos.distributedmusicplayer", "192.168.43.100", abilityInfo);
1406 int result2 = DistributedSchedService::GetInstance().StartAbilityFromRemote(want,
1407 abilityInfo, 0, callerInfo1, accountInfo);
1408
1409 /**
1410 * @tc.steps: step1. call NotifyProcessDiedFromRemote when sourceDeviceId == sourceDeviceId.
1411 */
1412 sptr<IRemoteObject> connect(new MockDistributedSched());
1413 ConnectInfo connectInfo;
1414 connectInfo.callerInfo.sourceDeviceId = LOCAL_DEVICEID;
1415 connectInfo.callerInfo.uid = 0;
1416 connectInfo.callerInfo.pid = 0;
1417 connectInfo.callerInfo.callerType = 0;
1418 {
1419 std::lock_guard<std::mutex> autoLock(DistributedSchedService::GetInstance().connectLock_);
1420 DistributedSchedService::GetInstance().calleeMap_[connect] = connectInfo;
1421 }
1422 CallerInfo callerInfo;
1423 callerInfo.sourceDeviceId = LOCAL_DEVICEID;
1424 callerInfo.uid = 0;
1425 callerInfo.pid = 0;
1426 callerInfo.callerType = 0;
1427 int32_t result = DistributedSchedService::GetInstance().NotifyProcessDiedFromRemote(callerInfo);
1428 EXPECT_EQ(result, ERR_OK);
1429 /**
1430 * @tc.steps: step2. call NotifyProcessDiedFromRemote when sourceDeviceId != sourceDeviceId.
1431 */
1432 callerInfo.sourceDeviceId = REMOTE_DEVICEID;
1433 result = DistributedSchedService::GetInstance().NotifyProcessDiedFromRemote(callerInfo);
1434 EXPECT_EQ(result, ERR_OK);
1435
1436 /**
1437 * @tc.steps: step3. call ProcessFreeInstallOffline when dmsCallbackTask_ is not empty.
1438 */
1439 DistributedSchedService::GetInstance().dmsCallbackTask_ = make_shared<DmsCallbackTask>();
1440 DistributedSchedService::GetInstance().ProcessCalleeOffline("deviceId");
1441 DTEST_LOG << "DistributedSchedServiceFirstTest NotifyProcessDiedFromRemote_001 end" << std::endl;
1442 }
1443
1444 /**
1445 * @tc.name: StartAbilityByCallFromRemote_001
1446 * @tc.desc: input invalid params
1447 * @tc.type: FUNC
1448 * @tc.require: issueI5T6GJ
1449 */
1450 HWTEST_F(DistributedSchedServiceFirstTest, StartAbilityByCallFromRemote_001, TestSize.Level3)
1451 {
1452 DTEST_LOG << "DistributedSchedServiceFirstTest StartAbilityByCallFromRemote_001 start" << std::endl;
1453 AAFwk::Want want;
1454 std::string localDeviceId;
1455 DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
1456 AppExecFwk::ElementName element(localDeviceId, "com.third.hiworld.example",
1457 "bmsThirdBundle");
1458 want.SetElement(element);
1459 want.SetParam(DMS_IS_CALLER_BACKGROUND, false);
1460 sptr<IRemoteObject> connect(new MockDistributedSched());
1461 CallerInfo callerInfo;
1462 callerInfo.uid = 0;
1463 callerInfo.sourceDeviceId = LOCAL_DEVICEID;
1464 bool result = BundleManagerInternal::GetCallerAppIdFromBms("com.third.hiworld.example",
1465 callerInfo.callerAppId);
1466 EXPECT_EQ(result, true);
1467 IDistributedSched::AccountInfo accountInfo;
1468 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
1469 auto mockDms = iface_cast<IDistributedSched>(GetDSchedService());
1470 int ret = mockDms->StartAbilityByCallFromRemote(want, connect, callerInfo, accountInfo);
1471 EXPECT_EQ(ret, ERR_OK);
1472 DTEST_LOG << "DistributedSchedServiceFirstTest StartAbilityByCallFromRemote_001 end" << std::endl;
1473 }
1474
1475 /**
1476 * @tc.name: StartAbilityByCallFromRemote_002
1477 * @tc.desc: input invalid params
1478 * @tc.type: FUNC
1479 * @tc.require: issueI5T6GJ
1480 */
1481 HWTEST_F(DistributedSchedServiceFirstTest, StartAbilityByCallFromRemote_002, TestSize.Level3)
1482 {
1483 DTEST_LOG << "DistributedSchedServiceFirstTest StartAbilityByCallFromRemote_002 start" << std::endl;
1484 AAFwk::Want want;
1485 std::string localDeviceId;
1486 DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
1487 AppExecFwk::ElementName element(localDeviceId, "com.third.hiworld.example",
1488 "bmsThirdBundle");
1489 want.SetElement(element);
1490 want.SetParam(DMS_IS_CALLER_BACKGROUND, false);
1491 sptr<IRemoteObject> connect = new MockDistributedSched();
1492 CallerInfo callerInfo;
1493 callerInfo.uid = 0;
1494 callerInfo.sourceDeviceId = LOCAL_DEVICEID;
1495 IDistributedSched::AccountInfo accountInfo;
1496 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
1497 int ret = DistributedSchedService::GetInstance().StartAbilityByCallFromRemote(want, connect,
1498 callerInfo, accountInfo);
1499 EXPECT_EQ(ret, INVALID_REMOTE_PARAMETERS_ERR);
1500 DTEST_LOG << "DistributedSchedServiceFirstTest StartAbilityByCallFromRemote_002 end" << std::endl;
1501 }
1502
1503 /**
1504 * @tc.name: StartAbilityByCallFromRemote_003
1505 * @tc.desc: call StartAbilityByCallFromRemote
1506 * @tc.type: FUNC
1507 * @tc.require: I6YLV1
1508 */
1509 HWTEST_F(DistributedSchedServiceFirstTest, StartAbilityByCallFromRemote_003, TestSize.Level3)
1510 {
1511 DTEST_LOG << "DistributedSchedServiceFirstTest StartAbilityByCallFromRemote_003 start" << std::endl;
1512 AAFwk::Want want;
1513 std::string localDeviceId;
1514 DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
1515 AppExecFwk::ElementName element(localDeviceId, "com.third.hiworld.example",
1516 "bmsThirdBundle");
1517 want.SetElement(element);
1518 want.SetParam(DMS_IS_CALLER_BACKGROUND, false);
1519 CallerInfo callerInfo;
1520 bool result = BundleManagerInternal::GetCallerAppIdFromBms("com.third.hiworld.example", callerInfo.callerAppId);
1521 EXPECT_EQ(result, true);
1522 callerInfo.extraInfoJson[DMS_VERSION_ID] = DMS_VERSION;
1523 sptr<IRemoteObject> connect(new MockDistributedSched());
1524 callerInfo.uid = 0;
1525 callerInfo.sourceDeviceId = localDeviceId;
1526 IDistributedSched::AccountInfo accountInfo;
1527 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
1528 sptr<IRemoteObject> callbackWrapper(new AbilityConnectionWrapperStub(connect, localDeviceId));
1529 ConnectInfo connectInfo {callerInfo, callbackWrapper, want.GetElement()};
1530 DistributedSchedService::GetInstance().calleeMap_[connect] = connectInfo;
1531 int ret = DistributedSchedService::GetInstance().StartAbilityByCallFromRemote(want, connect,
1532 callerInfo, accountInfo);
1533 EXPECT_EQ(ret, INVALID_REMOTE_PARAMETERS_ERR);
1534 DTEST_LOG << "DistributedSchedServiceFirstTest StartAbilityByCallFromRemote_003 end" << std::endl;
1535 }
1536
1537 /**
1538 * @tc.name: StartAbilityByCallFromRemote_004
1539 * @tc.desc: call StartAbilityByCallFromRemote
1540 * @tc.type: FUNC
1541 * @tc.require: I6YLV1
1542 */
1543 HWTEST_F(DistributedSchedServiceFirstTest, StartAbilityByCallFromRemote_004, TestSize.Level3)
1544 {
1545 DTEST_LOG << "DistributedSchedServiceFirstTest StartAbilityByCallFromRemote_004 start" << std::endl;
1546 AAFwk::Want want;
1547 std::string localDeviceId;
1548 DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
1549 AppExecFwk::ElementName element(localDeviceId, "com.third.hiworld.example",
1550 "bmsThirdBundle");
1551 want.SetElement(element);
1552 want.SetParam(DMS_IS_CALLER_BACKGROUND, false);
1553 CallerInfo callerInfo;
1554 bool result = BundleManagerInternal::GetCallerAppIdFromBms("com.third.hiworld.example", callerInfo.callerAppId);
1555 EXPECT_EQ(result, true);
1556 callerInfo.extraInfoJson[DMS_VERSION_ID] = DMS_VERSION;
1557 sptr<IRemoteObject> connect(new MockDistributedSched());
1558 callerInfo.uid = 0;
1559 callerInfo.sourceDeviceId = localDeviceId;
1560 IDistributedSched::AccountInfo accountInfo;
1561 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
1562 int ret = DistributedSchedService::GetInstance().StartAbilityByCallFromRemote(want, connect,
1563 callerInfo, accountInfo);
1564 EXPECT_EQ(ret, INVALID_REMOTE_PARAMETERS_ERR);
1565 DTEST_LOG << "DistributedSchedServiceFirstTest StartAbilityByCallFromRemote_004 end" << std::endl;
1566 }
1567
1568 /**
1569 * @tc.name: StartRemoteAbilityByCall_001
1570 * @tc.desc: call StartRemoteAbilityByCall
1571 * @tc.type: FUNC
1572 * @tc.require: I76THI
1573 */
1574 HWTEST_F(DistributedSchedServiceFirstTest, StartRemoteAbilityByCall_001, TestSize.Level3)
1575 {
1576 DTEST_LOG << "DistributedSchedServiceFirstTest StartRemoteAbilityByCall_001 start" << std::endl;
1577 AAFwk::Want want;
1578 int32_t callerUid = 0;
1579 int32_t callerPid = 0;
1580 uint32_t accessToken = 0;
1581 AppExecFwk::ElementName element("remoteDeviceId", "com.ohos.distributedmusicplayer",
1582 "com.ohos.distributedmusicplayer.MainAbility");
1583 want.SetElement(element);
1584 sptr<IRemoteObject> connect(new MockDistributedSched());
1585 g_isForeground = true;
1586 int32_t result = DistributedSchedService::GetInstance().StartRemoteAbilityByCall(want,
1587 connect, callerUid, callerPid, accessToken);
1588 EXPECT_EQ(result, INVALID_PARAMETERS_ERR);
1589 DTEST_LOG << "DistributedSchedServiceFirstTest StartRemoteAbilityByCall_001 end" << std::endl;
1590 }
1591
1592 /**
1593 * @tc.name: ReleaseAbilityFromRemote_001
1594 * @tc.desc: call ReleaseAbilityFromRemote
1595 * @tc.type: FUNC
1596 * @tc.require: I76THI
1597 */
1598 HWTEST_F(DistributedSchedServiceFirstTest, ReleaseAbilityFromRemote_001, TestSize.Level3)
1599 {
1600 DTEST_LOG << "DistributedSchedServiceFirstTest ReleaseAbilityFromRemote_001 start" << std::endl;
1601 sptr<IRemoteObject> connect(new MockDistributedSched());
1602 AAFwk::Want want;
1603 AppExecFwk::ElementName element;
1604 CallerInfo callerInfo;
1605 /**
1606 * @tc.steps: step1. call ReleaseAbilityFromRemote when callerInfo.sourceDeviceId is empty.
1607 * @tc.expected: step1. ReleaseAbilityFromRemote return INVALID_REMOTE_PARAMETERS_ERR
1608 */
1609 int32_t result = DistributedSchedService::GetInstance().ReleaseAbilityFromRemote(connect, element, callerInfo);
1610 EXPECT_EQ(result, INVALID_REMOTE_PARAMETERS_ERR);
1611 /**
1612 * @tc.steps: step2. call ReleaseAbilityFromRemote when localDeviceId == callerInfo.sourceDeviceId.
1613 * @tc.expected: step2. ReleaseAbilityFromRemote return INVALID_REMOTE_PARAMETERS_ERR
1614 */
1615 std::string localDeviceId;
1616 DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
1617 callerInfo.sourceDeviceId = localDeviceId;
1618 result = DistributedSchedService::GetInstance().ReleaseAbilityFromRemote(connect, element, callerInfo);
1619 EXPECT_EQ(result, INVALID_REMOTE_PARAMETERS_ERR);
1620 /**
1621 * @tc.steps: step3. call ReleaseAbilityFromRemote when itConnect == calleeMap_.end().
1622 * @tc.expected: step3. ReleaseAbilityFromRemote return INVALID_REMOTE_PARAMETERS_ERR
1623 */
1624 {
1625 std::lock_guard<std::mutex> autoLock(DistributedSchedService::GetInstance().calleeLock_);
1626 DistributedSchedService::GetInstance().calleeMap_.clear();
1627 }
1628 callerInfo.sourceDeviceId = "sourceDeviceId";
1629 result = DistributedSchedService::GetInstance().ReleaseAbilityFromRemote(connect, element, callerInfo);
1630 EXPECT_EQ(result, INVALID_REMOTE_PARAMETERS_ERR);
1631 DTEST_LOG << "DistributedSchedServiceFirstTest ReleaseAbilityFromRemote_001 end" << std::endl;
1632 }
1633
1634 /**
1635 * @tc.name: ReleaseAbilityFromRemote_002
1636 * @tc.desc: call ReleaseAbilityFromRemote when itConnect != calleeMap_.end().
1637 * @tc.type: FUNC
1638 * @tc.require: I76THI
1639 */
1640 HWTEST_F(DistributedSchedServiceFirstTest, ReleaseAbilityFromRemote_002, TestSize.Level3)
1641 {
1642 DTEST_LOG << "DistributedSchedServiceFirstTest ReleaseAbilityFromRemote_002 start" << std::endl;
1643 /**
1644 * @tc.steps: step1. call ReleaseAbilityFromRemote when itConnect != calleeMap_.end().
1645 */
1646 sptr<IRemoteObject> connect(new MockDistributedSched());
1647 AAFwk::Want want;
1648 AppExecFwk::ElementName element;
1649 CallerInfo callerInfo;
1650 callerInfo.sourceDeviceId = "sourceDeviceId";
1651 ConnectInfo connectInfo;
1652 {
1653 std::lock_guard<std::mutex> autoLock(DistributedSchedService::GetInstance().calleeLock_);
1654 DistributedSchedService::GetInstance().calleeMap_[connect] = connectInfo;
1655 }
1656 int32_t result = DistributedSchedService::GetInstance().ReleaseAbilityFromRemote(connect, element, callerInfo);
1657 EXPECT_NE(result, ERR_OK);
1658 /**
1659 * @tc.steps: step2. call ProcessConnectDied when connectSessionsList is empty.
1660 */
1661 std::list<ConnectAbilitySession> sessionsList;
1662 {
1663 std::lock_guard<std::mutex> autoLock(DistributedSchedService::GetInstance().distributedLock_);
1664 DistributedSchedService::GetInstance().distributedConnectAbilityMap_[connect] = sessionsList;
1665 }
1666 DistributedSchedService::GetInstance().ProcessConnectDied(connect);
1667 /**
1668 * @tc.steps: step3. call ProcessConnectDied when sessionsList is empty.
1669 */
1670 DistributedSchedService::GetInstance().ProcessConnectDied(connect);
1671 DTEST_LOG << "DistributedSchedServiceFirstTest ReleaseAbilityFromRemote_002 end" << std::endl;
1672 }
1673
1674 /**
1675 * @tc.name : ConnectDExtAbility_Test01
1676 * @tc.number: ConnectDExtAbility_001
1677 * @tc.desc : Test ConnectDExtAbility function when user is not foreground.
1678 */
1679 HWTEST_F(DistributedSchedServiceFirstTest, ConnectDExtAbility_Test01, TestSize.Level1)
1680 {
1681 std::string bundleName = "testBundle";
1682 std::string abilityName = "testAbility";
1683 int32_t userId = 1;
1684 int32_t result = DistributedSchedService::GetInstance().ConnectDExtAbility(bundleName, abilityName, userId);
1685 EXPECT_EQ(result, DMS_NOT_FOREGROUND_USER);
1686 DTEST_LOG << "DistributedSchedServiceFirstTest ConnectDExtAbility_Test01 end" << std::endl;
1687 }
1688
1689 /**
1690 * @tc.name : ConnectDExtAbility_Test02
1691 * @tc.number: ConnectDExtAbility_002
1692 * @tc.desc : Test ConnectDExtAbility function when proxy is empty.
1693 */
1694 HWTEST_F(DistributedSchedServiceFirstTest, ConnectDExtAbility_Test02, TestSize.Level1)
1695 {
1696 std::string bundleName = "com.example.dms_extension";
1697 std::string abilityName = "EntrydistributedAbility";
1698 int32_t userId = 100;
1699 int32_t result = DistributedSchedService::GetInstance().ConnectDExtAbility(bundleName, abilityName, userId);
1700 EXPECT_EQ(result, INVALID_PARAMETERS_ERR);
1701 DTEST_LOG << "DistributedSchedServiceFirstTest ConnectDExtAbility_Test02 end" << std::endl;
1702 }
1703 }
1704 }