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