• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "distributed_sched_utils.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 namespace {
54     const string LOCAL_DEVICEID = "192.168.43.100";
55     const string REMOTE_DEVICEID = "255.255.255.255";
56     const std::string DMS_MISSION_ID = "dmsMissionId";
57     const std::string DMS_CONNECT_TOKEN = "connectToken";
58     constexpr int32_t MISSION_ID = 1;
59     const std::string DMS_SRC_NETWORK_ID = "dmsSrcNetworkId";
60     const int DEFAULT_REQUEST_CODE = -1;
61     const string ABILITY_NAME = "com.ohos.permissionmanager.MainAbility";
62     const string BUNDLE_NAME = "com.ohos.permissionmanager";
63     const string DMS_IS_CALLER_BACKGROUND = "dmsIsCallerBackGround";
64     constexpr int32_t FOREGROUND = 2;
65     constexpr int32_t MAX_TOKEN_NUM = 100000000;
66     constexpr int32_t SLEEP_TIME = 1000;
67 }
68 
69 class DistributedSchedServiceSecondTest : public testing::Test {
70 public:
71     static void SetUpTestCase();
72     static void TearDownTestCase();
73     void SetUp();
74     void TearDown();
75     sptr<IDistributedSched> GetDms();
76     int32_t InstallBundle(const std::string &bundlePath) const;
77     sptr<IDistributedSched> proxy_;
78 
79 protected:
80     enum class LoopTime : int32_t {
81         LOOP_TIME = 10,
82         LOOP_PRESSURE_TIME = 100,
83     };
84     sptr<IRemoteObject> GetDSchedService() const;
85     void GetAbilityInfo(const std::string& package, const std::string& name,
86         const std::string& bundleName, const std::string& deviceId,
87         OHOS::AppExecFwk::AbilityInfo& abilityInfo);
88 
89     class DeviceInitCallBack : public DmInitCallback {
90         void OnRemoteDied() override;
91     };
92 };
93 
SetUpTestCase()94 void DistributedSchedServiceSecondTest::SetUpTestCase()
95 {
96     if (!DistributedSchedUtil::LoadDistributedSchedService()) {
97         DTEST_LOG << "DistributedSchedServiceSecondTest::SetUpTestCase LoadDistributedSchedService failed" << std::endl;
98     }
99     const std::string pkgName = "DBinderBus_" + std::to_string(getprocpid());
100     std::shared_ptr<DmInitCallback> initCallback_ = std::make_shared<DeviceInitCallBack>();
101     DeviceManager::GetInstance().InitDeviceManager(pkgName, initCallback_);
102     std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIME));
103 }
104 
TearDownTestCase()105 void DistributedSchedServiceSecondTest::TearDownTestCase()
106 {}
107 
SetUp()108 void DistributedSchedServiceSecondTest::SetUp()
109 {
110     DistributedSchedUtil::MockPermission();
111 }
112 
TearDown()113 void DistributedSchedServiceSecondTest::TearDown()
114 {}
115 
OnRemoteDied()116 void DistributedSchedServiceSecondTest::DeviceInitCallBack::OnRemoteDied()
117 {}
118 
GetDms()119 sptr<IDistributedSched> DistributedSchedServiceSecondTest::GetDms()
120 {
121     if (proxy_ != nullptr) {
122         return proxy_;
123     }
124     auto sm = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
125     EXPECT_TRUE(sm != nullptr);
126     if (sm == nullptr) {
127         DTEST_LOG << "DistributedSchedServiceSecondTest sm is nullptr" << std::endl;
128         return nullptr;
129     }
130     DTEST_LOG << "DistributedSchedServiceSecondTest sm is not nullptr" << std::endl;
131     auto distributedObject = sm->GetSystemAbility(DISTRIBUTED_SCHED_SA_ID);
132     proxy_ = iface_cast<IDistributedSched>(distributedObject);
133     if (proxy_ == nullptr) {
134         DTEST_LOG << "DistributedSchedServiceSecondTest DistributedSched is nullptr" << std::endl;
135     } else {
136         DTEST_LOG << "DistributedSchedServiceSecondTest DistributedSched is not nullptr" << std::endl;
137     }
138     return proxy_;
139 }
140 
GetDSchedService() const141 sptr<IRemoteObject> DistributedSchedServiceSecondTest::GetDSchedService() const
142 {
143     sptr<IRemoteObject> dsched(new MockDistributedSched());
144     return dsched;
145 }
146 
GetAbilityInfo(const std::string & package,const std::string & name,const std::string & bundleName,const std::string & deviceId,OHOS::AppExecFwk::AbilityInfo & abilityInfo)147 void DistributedSchedServiceSecondTest::GetAbilityInfo(const std::string& package, const std::string& name,
148     const std::string& bundleName, const std::string& deviceId, OHOS::AppExecFwk::AbilityInfo& abilityInfo)
149 {
150     abilityInfo.bundleName = bundleName;
151     abilityInfo.deviceId = deviceId;
152 }
153 
154 /**
155  * @tc.name: StartRemoteShareForm_001
156  * @tc.desc: call StartRemoteShareForm with dms
157  * @tc.type: StartRemoteShareForm
158  * @tc.require: issueI5M62D
159  */
160 HWTEST_F(DistributedSchedServiceSecondTest, StartRemoteShareForm_001, TestSize.Level1)
161 {
162     DTEST_LOG << "DistributedSchedServiceSecondTest StartRemoteShareForm_001 start" << std::endl;
163     sptr<IDistributedSched> proxy = GetDms();
164     const std::string remoteDeviceId = "";
165     const OHOS::AppExecFwk::FormShareInfo formShareInfo {};
166     auto result = proxy->StartRemoteShareForm(remoteDeviceId, formShareInfo);
167     DTEST_LOG << "result:" << result << std::endl;
168     EXPECT_EQ(static_cast<int>(INVALID_PARAMETERS_ERR), result);
169     DTEST_LOG << "DistributedSchedServiceSecondTest StartRemoteShareForm_001 end" << std::endl;
170 }
171 
172 /**
173  * @tc.name: StartRemoteShareForm_002
174  * @tc.desc: call StartAbilityFromRemote with dms
175  * @tc.type: StartRemoteShareForm
176  * @tc.require: issueI5M62D
177  */
178 HWTEST_F(DistributedSchedServiceSecondTest, StartRemoteShareForm_002, TestSize.Level1)
179 {
180     DTEST_LOG << "DistributedSchedServiceSecondTest StartRemoteShareForm_002 start" << std::endl;
181     sptr<IDistributedSched> proxy = GetDms();
182     const std::string remoteDeviceId = "123456";
183     const OHOS::AppExecFwk::FormShareInfo formShareInfo {};
184     auto result = proxy->StartRemoteShareForm(remoteDeviceId, formShareInfo);
185     DTEST_LOG << "result:" << result << std::endl;
186     EXPECT_EQ(static_cast<int>(DMS_PERMISSION_DENIED), result);
187     DTEST_LOG << "DistributedSchedServiceSecondTest StartRemoteShareForm_002 end" << std::endl;
188 }
189 
190 /**
191  * @tc.name: StartRemoteShareForm_003
192  * @tc.desc: call StartRemoteShareForm with dms
193  * @tc.type: StartRemoteShareForm
194  * @tc.require: issueI5M62D
195  */
196 HWTEST_F(DistributedSchedServiceSecondTest, StartRemoteShareForm_003, TestSize.Level1)
197 {
198     DTEST_LOG << "DistributedSchedServiceSecondTest StartRemoteShareForm_003 start" << std::endl;
199     sptr<IDistributedSched> proxy = GetDms();
200     const OHOS::AppExecFwk::FormShareInfo formShareInfo {};
201     auto result = proxy->StartRemoteShareForm(REMOTE_DEVICEID, formShareInfo);
202     DTEST_LOG << "result:" << result << std::endl;
203     EXPECT_NE(ERR_OK, result);
204     DTEST_LOG << "DistributedSchedServiceSecondTest StartRemoteShareForm_003 end" << std::endl;
205 }
206 
207 /**
208  * @tc.name: StartShareFormFromRemote_001
209  * @tc.desc: call StartAbilityFromRemote with dms
210  * @tc.type: StartShareFormFromRemote
211  * @tc.require: issueI5M62D
212  */
213 HWTEST_F(DistributedSchedServiceSecondTest, StartShareFormFromRemote_001, TestSize.Level1)
214 {
215     DTEST_LOG << "DistributedSchedServiceSecondTest StartShareFormFromRemote_001 start" << std::endl;
216     std::string remoteDeviceId = "";
217     DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(remoteDeviceId);
218     const OHOS::AppExecFwk::FormShareInfo formShareInfo {};
219     DistributedSchedService::GetInstance().formMgrProxy_ = new MockFormMgrService();
220     auto result = DistributedSchedService::GetInstance().StartShareFormFromRemote(remoteDeviceId, formShareInfo);
221     DTEST_LOG << "result:" << result << std::endl;
222     EXPECT_EQ(static_cast<int>(ERR_OK), result);
223 
224     DTEST_LOG << "DistributedSchedServiceSecondTest StartShareFormFromRemote_001 end" << std::endl;
225 }
226 
227 /**
228  * @tc.name: StartShareFormFromRemote_002
229  * @tc.desc: call StartAbilityFromRemote with dms
230  * @tc.type: StartShareFormFromRemote
231  * @tc.require: issueI5M62D
232  */
233 HWTEST_F(DistributedSchedServiceSecondTest, StartShareFormFromRemote_002, TestSize.Level1)
234 {
235     DTEST_LOG << "DistributedSchedServiceSecondTest StartShareFormFromRemote_002 start" << std::endl;
236     std::string remoteDeviceId = "123456";
237     const OHOS::AppExecFwk::FormShareInfo formShareInfo {};
238     /**
239      * @tc.steps: step1. call GetContinuaitonDevice
240      */
241     DTEST_LOG << "DistributedSchedServiceSecondTest GetContinuaitonDevice_001 start" << std::endl;
242     if (DistributedSchedService::GetInstance().dschedContinuation_ == nullptr) {
243         DistributedSchedService::GetInstance().dschedContinuation_ = std::make_shared<DSchedContinuation>();
244     }
245     int32_t missionId = MISSION_ID;
246     (void)DistributedSchedService::GetInstance().GetContinuaitonDevice(missionId);
247     DTEST_LOG << "DistributedSchedServiceSecondTest GetContinuaitonDevice_001 end" << std::endl;
248 
249     auto result = DistributedSchedService::GetInstance().StartShareFormFromRemote(remoteDeviceId, formShareInfo);
250     DTEST_LOG << "result:" << result << std::endl;
251     EXPECT_EQ(static_cast<int>(INVALID_REMOTE_PARAMETERS_ERR), result);
252     DTEST_LOG << "DistributedSchedServiceSecondTest StartShareFormFromRemote_002 end" << std::endl;
253 }
254 
255 /**
256  * @tc.name: ProcessCalleeDied_001
257  * @tc.desc: call ProcessCalleeDied
258  * @tc.type: FUNC
259  * @tc.require: I6YLV1
260  */
261 HWTEST_F(DistributedSchedServiceSecondTest, ProcessCalleeDied_001, TestSize.Level1)
262 {
263     DTEST_LOG << "DistributedSchedServiceSecondTest ProcessCalleeDied_001 start" << std::endl;
264     std::string localDeviceId;
265     DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
266     sptr<IRemoteObject> connect(new MockDistributedSched());
267     DistributedSchedService::GetInstance().ProcessCalleeDied(connect);
268     DistributedSchedService::GetInstance().calleeMap_.clear();
269     EXPECT_TRUE(DistributedSchedService::GetInstance().calleeMap_.empty());
270     DTEST_LOG << "DistributedSchedServiceSecondTest ProcessCalleeDied_001 end" << std::endl;
271 }
272 
273 /**
274  * @tc.name: StartRemoteFreeInstall_001
275  * @tc.desc: call StartRemoteFreeInstall
276  * @tc.type: FUNC
277  * @tc.require: I76THI
278  */
279 HWTEST_F(DistributedSchedServiceSecondTest, StartRemoteFreeInstall_001, TestSize.Level3)
280 {
281     DTEST_LOG << "DistributedSchedServiceSecondTest StartRemoteFreeInstall_001 start" << std::endl;
282     AAFwk::Want want;
283     AppExecFwk::ElementName element("devicdId", "com.ohos.distributedmusicplayer",
284         "com.ohos.distributedmusicplayer.MainAbility");
285     want.SetElement(element);
286     auto callback = GetDSchedService();
287     int32_t result = DistributedSchedService::GetInstance().StartRemoteFreeInstall(want, 0, 0, 0, callback);
288     EXPECT_EQ(result, INVALID_PARAMETERS_ERR);
289     DTEST_LOG << "DistributedSchedServiceSecondTest StartRemoteFreeInstall_001 end" << std::endl;
290 }
291 
292 /**
293  * @tc.name: NotifyCompleteFreeInstall_001
294  * @tc.desc: call NotifyCompleteFreeInstall
295  * @tc.type: FUNC
296  * @tc.require: I76THI
297  */
298 HWTEST_F(DistributedSchedServiceSecondTest, NotifyCompleteFreeInstall_001, TestSize.Level3)
299 {
300     DTEST_LOG << "DistributedSchedServiceSecondTest NotifyCompleteFreeInstall_001 start" << std::endl;
301 
302     sptr<IDistributedSched> proxy = GetDms();
303     ASSERT_NE(nullptr, proxy);
304 
305     AAFwk::Want want;
306     AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
307         "com.ohos.distributedmusicplayer.MainAbility");
308     want.SetElement(element);
309     AppExecFwk::AbilityInfo abilityInfo;
310     GetAbilityInfo("com.ohos.distributedmusicplayer", "com.ohos.distributedmusicplayer.MainAbility",
311         "com.ohos.distributedmusicplayer", "192.168.43.100", abilityInfo);
312     CallerInfo callerInfo;
313     callerInfo.uid = 0;
314     callerInfo.sourceDeviceId = "255.255.255.255";
315     IDistributedSched::AccountInfo accountInfo;
316 
317     int result1 = proxy->StartAbilityFromRemote(want, abilityInfo, 0, callerInfo, accountInfo);
318     DTEST_LOG << "result1 is" << result1 << std::endl;
319 
320     AppExecFwk::ElementName element2("", "com.ohos.distributedmusicplayer",
321         "com.ohos.distributedmusicplayer.MainAbilityService");
322     want.SetElement(element2);
323     GetAbilityInfo("com.ohos.distributedmusicplayer", "com.ohos.distributedmusicplayer.MainAbilityService",
324         "com.ohos.distributedmusicplayer", "192.168.43.100", abilityInfo);
325     int result2 = proxy->StartAbilityFromRemote(want, abilityInfo, 0, callerInfo, accountInfo);
326     DTEST_LOG << "result2:" << result2 << std::endl;
327 
328     /**
329     * @tc.steps: step1. call NotifyCompleteFreeInstall when resultCode is not ERR_OK.
330     */
331     IDistributedSched::FreeInstallInfo info;
332     int32_t result = DistributedSchedService::GetInstance().NotifyCompleteFreeInstall(info, 1, -1);
333     EXPECT_NE(result, ERR_OK);
334     /**
335     * @tc.steps: step2. call ProcessCallResult.
336     */
337     sptr<IRemoteObject> connect(new MockDistributedSched());
338     DistributedSchedService::GetInstance().ProcessCallResult(connect, connect);
339     DTEST_LOG << "DistributedSchedServiceSecondTest NotifyCompleteFreeInstall_001 end" << std::endl;
340 }
341 
342 /**
343  * @tc.name: NotifyStateChangedFromRemote_001
344  * @tc.desc: call NotifyStateChangedFromRemote with illegal params
345  * @tc.type: FUNC
346  * @tc.require: I6SJQ6
347  */
348 HWTEST_F(DistributedSchedServiceSecondTest, NotifyStateChangedFromRemote_001, TestSize.Level1)
349 {
350     DTEST_LOG << "DistributedSchedServiceSecondTest NotifyStateChangedFromRemote_001 start" << std::endl;
351     sptr<IDistributedSched> proxy = GetDms();
352     ASSERT_NE(nullptr, proxy);
353     AppExecFwk::ElementName element("", BUNDLE_NAME, ABILITY_NAME);
354     int result1 = proxy->NotifyStateChangedFromRemote(0, 0, element);
355     DTEST_LOG << "result1:" << result1 << std::endl;
356 
357     EXPECT_NE(result1, ERR_OK);
358     DTEST_LOG << "DistributedSchedServiceSecondTest NotifyStateChangedFromRemote_001 end" << std::endl;
359 }
360 
361 /**
362  * @tc.name: NotifyStateChangedFromRemote_002
363  * @tc.desc: test NotifyStateChangedFromRemote
364  * @tc.type: FUNC
365  * @tc.require: I6SJQ6
366  */
367 HWTEST_F(DistributedSchedServiceSecondTest, NotifyStateChangedFromRemote_002, TestSize.Level3)
368 {
369     DTEST_LOG << "DistributedSchedServiceSecondTest NotifyStateChangedFromRemote_002 start" << std::endl;
370     std::string localDeviceId;
371     DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
372     AppExecFwk::ElementName element(localDeviceId, BUNDLE_NAME, ABILITY_NAME);
373 
374     int ret = DistributedSchedService::GetInstance().NotifyStateChangedFromRemote(0, 0, element);
375     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
376     DTEST_LOG << "DistributedSchedServiceSecondTest NotifyStateChangedFromRemote_002 end" << std::endl;
377 }
378 
379 /**
380  * @tc.name: NotifyStateChangedFromRemote_003
381  * @tc.desc: test NotifyStateChangedFromRemote
382  * @tc.type: FUNC
383  * @tc.require: I6SJQ6
384  */
385 HWTEST_F(DistributedSchedServiceSecondTest, NotifyStateChangedFromRemote_003, TestSize.Level3)
386 {
387     DTEST_LOG << "DistributedSchedServiceSecondTest NotifyStateChangedFromRemote_003 start" << std::endl;
388     std::string localDeviceId;
389     DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
390     AppExecFwk::ElementName element(localDeviceId, BUNDLE_NAME, ABILITY_NAME);
391 
392     sptr<IRemoteObject> connect = nullptr;
393     DistributedSchedService::GetInstance().callMap_[connect] = {1, localDeviceId};
394     int ret = DistributedSchedService::GetInstance().NotifyStateChangedFromRemote(0, 0, element);
395     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
396     DTEST_LOG << "DistributedSchedServiceSecondTest NotifyStateChangedFromRemote_003 end" << std::endl;
397 }
398 
399 /**
400  * @tc.name: NotifyStateChangedFromRemote_004
401  * @tc.desc: test NotifyStateChangedFromRemote
402  * @tc.type: FUNC
403  * @tc.require: I6VDBO
404  */
405 HWTEST_F(DistributedSchedServiceSecondTest, NotifyStateChangedFromRemote_004, TestSize.Level3)
406 {
407     DTEST_LOG << "DistributedSchedServiceSecondTest NotifyStateChangedFromRemote_004 start" << std::endl;
408     sptr<AppStateObserver> appStateObserver = sptr<AppStateObserver>(new (std::nothrow) AppStateObserver());
409     int32_t abilityState = FOREGROUND;
410     std::string localDeviceId;
411     DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
412     AppExecFwk::ElementName element(localDeviceId, BUNDLE_NAME, ABILITY_NAME);
413     int32_t ret = DistributedSchedService::GetInstance().NotifyStateChangedFromRemote(abilityState, 0, element);
414     DTEST_LOG << "ret:" << ret << std::endl;
415     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
416     DTEST_LOG << "DistributedSchedServiceSecondTest NotifyStateChangedFromRemote_004 end" << std::endl;
417 }
418 
419 /**
420  * @tc.name: NotifyStateChangedFromRemote_005
421  * @tc.desc: test NotifyStateChangedFromRemote
422  * @tc.type: FUNC
423  * @tc.require: I6VDBO
424  */
425 HWTEST_F(DistributedSchedServiceSecondTest, NotifyStateChangedFromRemote_005, TestSize.Level3)
426 {
427     DTEST_LOG << "DistributedSchedServiceSecondTest NotifyStateChangedFromRemote_005 start" << std::endl;
428     sptr<AppStateObserver> appStateObserver = sptr<AppStateObserver>(new (std::nothrow) AppStateObserver());
429     int32_t abilityState = FOREGROUND;
430     std::string localDeviceId;
431     DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
432     sptr<IRemoteObject> connect = nullptr;
433     DistributedSchedService::GetInstance().callMap_[connect] = {2, localDeviceId};
434     AppExecFwk::ElementName element(localDeviceId, BUNDLE_NAME, ABILITY_NAME);
435     int32_t ret = DistributedSchedService::GetInstance().NotifyStateChangedFromRemote(abilityState, 0, element);
436     DTEST_LOG << "ret:" << ret << std::endl;
437     DistributedSchedService::GetInstance().callMap_.clear();
438     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
439     DTEST_LOG << "DistributedSchedServiceSecondTest NotifyStateChangedFromRemote_005 end" << std::endl;
440 }
441 
442 /**
443  * @tc.name: NotifyStateChangedFromRemote_006
444  * @tc.desc: test NotifyStateChangedFromRemote
445  * @tc.type: FUNC
446  * @tc.require: I6VDBO
447  */
448 HWTEST_F(DistributedSchedServiceSecondTest, NotifyStateChangedFromRemote_006, TestSize.Level3)
449 {
450     DTEST_LOG << "DistributedSchedServiceSecondTest NotifyStateChangedFromRemote_006 start" << std::endl;
451     sptr<AppStateObserver> appStateObserver = sptr<AppStateObserver>(new (std::nothrow) AppStateObserver());
452     int32_t abilityState = FOREGROUND;
453     std::string localDeviceId;
454     DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
455     sptr<IRemoteObject> connect(new MockDistributedSched());
456     DistributedSchedService::GetInstance().callMap_[connect] = {3, localDeviceId};
457     AppExecFwk::ElementName element(localDeviceId, BUNDLE_NAME, ABILITY_NAME);
458     int32_t ret = DistributedSchedService::GetInstance().NotifyStateChangedFromRemote(abilityState, 3, element);
459     DTEST_LOG << "ret:" << ret << std::endl;
460     DistributedSchedService::GetInstance().callMap_.clear();
461     EXPECT_EQ(ret, ERR_OK);
462     DTEST_LOG << "DistributedSchedServiceSecondTest NotifyStateChangedFromRemote_006 end" << std::endl;
463 }
464 
465 /**
466  * @tc.name: NotifyStateChanged_001
467  * @tc.desc: test NotifyStateChanged
468  * @tc.type: FUNC
469  * @tc.require: I6SJQ6
470  */
471 HWTEST_F(DistributedSchedServiceSecondTest, NotifyStateChanged_001, TestSize.Level3)
472 {
473     DTEST_LOG << "DistributedSchedServiceSecondTest NotifyStateChanged_001 start" << std::endl;
474 
475     sptr<IDistributedSched> proxy = GetDms();
476 
477     AAFwk::Want want;
478     AppExecFwk::ElementName element("1.1.1.1", "com.ohos.distributedmusicplayer",
479         "com.ohos.distributedmusicplayer.MainAbility");
480     want.SetElement(element);
481     CallerInfo callerInfo;
482     callerInfo.uid = 0;
483     callerInfo.sourceDeviceId = "255.255.255.255";
484     IDistributedSched::AccountInfo accountInfo;
485     accountInfo.accountType = 1;
486     accountInfo.groupIdList.push_back("123456");
487     int missionId = 0;
488     want.SetParam(DMS_SRC_NETWORK_ID, callerInfo.sourceDeviceId);
489     want.SetParam(DMS_MISSION_ID, missionId);
490 
491     int result1 = DistributedSchedService::GetInstance().SendResultFromRemote(want, 0, callerInfo, accountInfo, 0);
492     DTEST_LOG << "result1:" << result1 << std::endl;
493 
494     AppExecFwk::ElementName element2("1.1.1.1", "com.ohos.distributedmusicplayer",
495         "com.ohos.distributedmusicplayer.MainAbilityService");
496     want.SetElement(element2);
497     int result2 = DistributedSchedService::GetInstance().SendResultFromRemote(want, 0, callerInfo, accountInfo, 0);
498     DTEST_LOG << "result2:" << result2 << std::endl;
499 
500     int32_t abilityState = FOREGROUND;
501     std::string localDeviceId;
502     AppExecFwk::ElementName element3(localDeviceId, BUNDLE_NAME, ABILITY_NAME);
503     int32_t ret = DistributedSchedService::GetInstance().NotifyStateChanged(abilityState, element3, nullptr);
504     DTEST_LOG << "ret:" << ret << std::endl;
505     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
506     DTEST_LOG << "DistributedSchedServiceSecondTest NotifyStateChanged_001 end" << std::endl;
507 }
508 
509 /**
510  * @tc.name: NotifyStateChanged_002
511  * @tc.desc: test NotifyStateChanged
512  * @tc.type: FUNC
513  * @tc.require: I6VDBO
514  */
515 HWTEST_F(DistributedSchedServiceSecondTest, NotifyStateChanged_002, TestSize.Level3)
516 {
517     DTEST_LOG << "DistributedSchedServiceSecondTest NotifyStateChanged_002 start" << std::endl;
518     sptr<AppStateObserver> appStateObserver = sptr<AppStateObserver>(new (std::nothrow) AppStateObserver());
519     int32_t abilityState = FOREGROUND;
520     std::string localDeviceId;
521     DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
522     sptr<IRemoteObject> connect(new MockDistributedSched());
523     DistributedSchedService::GetInstance().observerMap_[connect] = {appStateObserver, localDeviceId, 0, BUNDLE_NAME,
524         ABILITY_NAME};
525     AppExecFwk::ElementName element(localDeviceId, BUNDLE_NAME, ABILITY_NAME);
526     int32_t ret = DistributedSchedService::GetInstance().NotifyStateChanged(abilityState, element, nullptr);
527     DTEST_LOG << "ret:" << ret << std::endl;
528     DistributedSchedService::GetInstance().observerMap_.clear();
529     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
530     DTEST_LOG << "DistributedSchedServiceSecondTest NotifyStateChanged_002 end" << std::endl;
531 }
532 
533 /**
534  * @tc.name: NotifyStateChanged_003
535  * @tc.desc: test NotifyStateChanged
536  * @tc.type: FUNC
537  * @tc.require: I6VDBO
538  */
539 HWTEST_F(DistributedSchedServiceSecondTest, NotifyStateChanged_003, TestSize.Level3)
540 {
541     DTEST_LOG << "DistributedSchedServiceSecondTest NotifyStateChanged_003 start" << std::endl;
542     sptr<AppStateObserver> appStateObserver = sptr<AppStateObserver>(new (std::nothrow) AppStateObserver());
543     int32_t abilityState = FOREGROUND;
544     std::string localDeviceId;
545     DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
546     sptr<IRemoteObject> connect(new MockDistributedSched());
547     DistributedSchedService::GetInstance().observerMap_[connect] = {appStateObserver, REMOTE_DEVICEID, 0, BUNDLE_NAME,
548         ABILITY_NAME};
549     AppExecFwk::ElementName element(localDeviceId, BUNDLE_NAME, ABILITY_NAME);
550     int32_t ret = DistributedSchedService::GetInstance().NotifyStateChanged(abilityState, element, nullptr);
551     DTEST_LOG << "ret:" << ret << std::endl;
552     DistributedSchedService::GetInstance().observerMap_.clear();
553     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
554     DTEST_LOG << "DistributedSchedServiceSecondTest NotifyStateChanged_003 end" << std::endl;
555 }
556 
557 /**
558  * @tc.name: StopRemoteExtensionAbility_001
559  * @tc.desc: StopRemoteExtensionAbility with uninitialized params, return INVALID_PARAMETERS_ERR.
560  * @tc.type: FUNC
561  */
562 HWTEST_F(DistributedSchedServiceSecondTest, StopRemoteExtensionAbility_001, TestSize.Level3)
563 {
564     DTEST_LOG << "DistributedSchedServiceSecondTest StopRemoteExtensionAbility_001 start" << std::endl;
565     AAFwk::Want want;
566     int32_t callerUid = 0;
567     uint32_t accessToken = 0;
568     int32_t extensionType = 3;
569     std::string deviceId;
570     DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(deviceId);
571     AppExecFwk::ElementName element(deviceId, "com.ohos.distributedmusicplayer",
572         "com.ohos.distributedmusicplayer.MainAbility");
573     want.SetElement(element);
574     EXPECT_EQ(DistributedSchedService::GetInstance().StopRemoteExtensionAbility(want, callerUid, accessToken,
575         extensionType), INVALID_PARAMETERS_ERR);
576     DTEST_LOG << "DistributedSchedServiceSecondTest StopRemoteExtensionAbility_001 end" << std::endl;
577 }
578 
579 /**
580  * @tc.name: StopRemoteExtensionAbility_002
581  * @tc.desc: StopRemoteExtensionAbility with empty want's deviceId, return INVALID_PARAMETERS_ERR.
582  * @tc.type: FUNC
583  */
584 HWTEST_F(DistributedSchedServiceSecondTest, StopRemoteExtensionAbility_002, TestSize.Level3)
585 {
586     DTEST_LOG << "DistributedSchedServiceSecondTest StopRemoteExtensionAbility_002 start" << std::endl;
587     AAFwk::Want want;
588     int32_t callerUid = 0;
589     uint32_t accessToken = 0;
590     int32_t extensionType = 3;
591     AppExecFwk::ElementName element("abcdefg123456", "com.ohos.distributedmusicplayer",
592         "com.ohos.distributedmusicplayer.MainAbility");
593     want.SetElement(element);
594     EXPECT_EQ(DistributedSchedService::GetInstance().StopRemoteExtensionAbility(want, callerUid, accessToken,
595         extensionType), INVALID_PARAMETERS_ERR);
596     DTEST_LOG << "DistributedSchedServiceSecondTest StopRemoteExtensionAbility_002 end" << std::endl;
597 }
598 
599 /**
600  * @tc.name: StopRemoteExtensionAbility_003
601  * @tc.desc: call StopRemoteExtensionAbility
602  * @tc.type: FUNC
603  * @tc.require: I6YLV1
604  */
605 HWTEST_F(DistributedSchedServiceSecondTest, StopRemoteExtensionAbility_003, TestSize.Level3)
606 {
607     DTEST_LOG << "DistributedSchedServiceSecondTest StopRemoteExtensionAbility_003 start" << std::endl;
608     sptr<IDistributedSched> proxy = GetDms();
609     ASSERT_NE(nullptr, proxy);
610     AAFwk::Want want;
611     std::string localDeviceId;
612     DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
613     AppExecFwk::ElementName element(localDeviceId, BUNDLE_NAME,
614         ABILITY_NAME);
615     want.SetElement(element);
616     int32_t extensionType = 3;
617     int result = proxy->StopRemoteExtensionAbility(want, 0, 0, extensionType);
618     EXPECT_EQ(result, DMS_PERMISSION_DENIED);
619     DTEST_LOG << "DistributedSchedServiceSecondTest StopRemoteExtensionAbility_003 end" << std::endl;
620 }
621 
622 /**
623  * @tc.name: StopExtensionAbilityFromRemote_001
624  * @tc.desc: StopExtensionAbilityFromRemote with uninitialized params, return INVALID_REMOTE_PARAMETERS_ERR.
625  * @tc.type: FUNC
626  */
627 HWTEST_F(DistributedSchedServiceSecondTest, StopExtensionAbilityFromRemote_001, TestSize.Level3)
628 {
629     DTEST_LOG << "DistributedSchedServiceSecondTest StopExtensionAbilityFromRemote_001 start" << std::endl;
630     sptr<IDistributedSched> proxy = GetDms();
631     ASSERT_NE(nullptr, proxy);
632     AAFwk::Want remoteWant;
633     std::string deviceId;
634     DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(deviceId);
635     AppExecFwk::ElementName element(deviceId, "com.ohos.distributedmusicplayer",
636         "com.ohos.distributedmusicplayer.MainAbility");
637     remoteWant.SetElement(element);
638     CallerInfo callerInfo;
639     callerInfo.uid = 0;
640     callerInfo.sourceDeviceId = "255.255.255.255";
641     IDistributedSched::AccountInfo accountInfo;
642     int32_t extensionType = 3;
643     EXPECT_EQ(DistributedSchedService::GetInstance().StopExtensionAbilityFromRemote(remoteWant, callerInfo,
644         accountInfo, extensionType), INVALID_REMOTE_PARAMETERS_ERR);
645     DTEST_LOG << "DistributedSchedServiceSecondTest StopExtensionAbilityFromRemote_001 end" << std::endl;
646 }
647 
648 /**
649  * @tc.name: StopExtensionAbilityFromRemote_002
650  * @tc.desc: StopExtensionAbilityFromRemote with empty want's deviceId, return DMS_PERMISSION_DENIED.
651  * @tc.type: FUNC
652  */
653 HWTEST_F(DistributedSchedServiceSecondTest, StopExtensionAbilityFromRemote_002, TestSize.Level3)
654 {
655     DTEST_LOG << "DistributedSchedServiceSecondTest StopExtensionAbilityFromRemote_002 start" << std::endl;
656 
657     sptr<IDistributedSched> proxy = GetDms();
658     ASSERT_NE(nullptr, proxy);
659     /**
660      * @tc.steps: step1. set want and abilityInfo
661      */
662     AAFwk::Want want;
663     AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
664         "com.ohos.distributedmusicplayer.MainAbility");
665     want.SetElement(element);
666     CallerInfo callerInfo;
667     callerInfo.uid = 0;
668     callerInfo.sourceDeviceId = "255.255.255.255";
669     IDistributedSched::AccountInfo accountInfo;
670     int missionId = 0;
671     want.SetParam(DMS_SRC_NETWORK_ID, callerInfo.sourceDeviceId);
672     want.SetParam(DMS_MISSION_ID, missionId);
673     /**
674      * @tc.steps: step2. SendResultFromRemote for pressure test
675      * @tc.expected: step2. SendResultFromRemote for result
676      */
677     for (int index = 0; index < static_cast<int32_t>(LoopTime::LOOP_TIME); index++) {
678         int result = proxy->SendResultFromRemote(want, 0, callerInfo, accountInfo, 0);
679         DTEST_LOG << "pressure" + to_string(index) + " result is " << result << std::endl;
680     }
681 
682     AAFwk::Want remoteWant;
683     AppExecFwk::ElementName element1("abcdefg123456", "com.ohos.distributedmusicplayer",
684         "com.ohos.distributedmusicplayer.MainAbility");
685     remoteWant.SetElement(element1);
686     CallerInfo callerInfo1;
687     callerInfo1.uid = 0;
688     callerInfo1.sourceDeviceId = "255.255.255.255";
689     IDistributedSched::AccountInfo accountInfo1;
690     int32_t extensionType = 3;
691     EXPECT_EQ(DistributedSchedService::GetInstance().StopExtensionAbilityFromRemote(remoteWant, callerInfo1,
692         accountInfo1, extensionType), INVALID_REMOTE_PARAMETERS_ERR);
693     DTEST_LOG << "DistributedSchedServiceSecondTest StopExtensionAbilityFromRemote_002 end" << std::endl;
694 }
695 
696 /**
697  * @tc.name: StopExtensionAbilityFromRemote_003
698  * @tc.desc: StopExtensionAbilityFromRemote with empty want's deviceId, return INVALID_REMOTE_PARAMETERS_ERR.
699  * @tc.type: FUNC
700  */
701 HWTEST_F(DistributedSchedServiceSecondTest, StopExtensionAbilityFromRemote_003, TestSize.Level3)
702 {
703     DTEST_LOG << "DistributedSchedServiceSecondTest StopExtensionAbilityFromRemote_003 start" << std::endl;
704     sptr<IDistributedSched> proxy = GetDms();
705     ASSERT_NE(nullptr, proxy);
706     AAFwk::Want remoteWant;
707     AppExecFwk::ElementName element("abcdefg123456", "com.ohos.distributedmusicplayer",
708         "com.ohos.distributedmusicplayer.MainAbility");
709     remoteWant.SetElement(element);
710     CallerInfo callerInfo;
711     callerInfo.uid = 0;
712     callerInfo.sourceDeviceId = "255.255.255.255";
713     IDistributedSched::AccountInfo accountInfo;
714     int32_t extensionType = 3;
715     EXPECT_EQ(proxy->StopExtensionAbilityFromRemote(remoteWant, callerInfo,
716         accountInfo, extensionType), IPC_STUB_UNKNOW_TRANS_ERR);
717     DTEST_LOG << "DistributedSchedServiceSecondTest StopExtensionAbilityFromRemote_003 end" << std::endl;
718 }
719 
720 /**
721  * @tc.name: StopExtensionAbilityFromRemote_004
722  * @tc.desc: call StopExtensionAbilityFromRemote
723  * @tc.type: FUNC
724  * @tc.require: I6YLV1
725  */
726 HWTEST_F(DistributedSchedServiceSecondTest, StopExtensionAbilityFromRemote_004, TestSize.Level3)
727 {
728     DTEST_LOG << "DistributedSchedServiceSecondTest StopExtensionAbilityFromRemote_004 start" << std::endl;
729     AAFwk::Want want;
730     std::string localDeviceId;
731     DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
732     AppExecFwk::ElementName element(localDeviceId, BUNDLE_NAME,
733         ABILITY_NAME);
734     want.SetElement(element);
735     want.SetParam(DMS_IS_CALLER_BACKGROUND, false);
736     AppExecFwk::AbilityInfo abilityInfo;
737     abilityInfo.permissions.clear();
738     sptr<IRemoteObject> connect(new MockDistributedSched());
739     CallerInfo callerInfo;
740     callerInfo.uid = 0;
741     callerInfo.sourceDeviceId = LOCAL_DEVICEID;
742     bool result = BundleManagerInternal::GetCallerAppIdFromBms(BUNDLE_NAME, callerInfo.callerAppId);
743     EXPECT_TRUE(result);
744     IDistributedSched::AccountInfo accountInfo;
745     accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
746     int32_t extensionType = 3;
747     int ret = DistributedSchedService::GetInstance().StopExtensionAbilityFromRemote(want, callerInfo,
748         accountInfo, extensionType);
749     EXPECT_EQ(ret, INVALID_REMOTE_PARAMETERS_ERR);
750     DTEST_LOG << "DistributedSchedServiceSecondTest StopExtensionAbilityFromRemote_004 end" << std::endl;
751 }
752 
753 /**
754  * @tc.name: CheckDistributedConnectLocked001
755  * @tc.desc: call CheckDistributedConnectLocked
756  * @tc.type: FUNC
757  * @tc.require: I6P0I9
758  */
759 HWTEST_F(DistributedSchedServiceSecondTest, CheckDistributedConnectLocked001, TestSize.Level3)
760 {
761     DTEST_LOG << "DistributedSchedServiceSecondTest CheckDistributedConnectLocked001 start" << std::endl;
762     int32_t uid = IPCSkeleton::GetCallingUid();
763     CallerInfo callerInfo;
764     callerInfo.uid = uid;
765     int32_t ret = DistributedSchedService::GetInstance().CheckDistributedConnectLocked(callerInfo);
766     EXPECT_EQ(ret, ERR_OK);
767     DTEST_LOG << "DistributedSchedServiceSecondTest CheckDistributedConnectLocked001 end" << std::endl;
768 }
769 
770 /**
771  * @tc.name: CheckDistributedConnectLocked002
772  * @tc.desc: call CheckDistributedConnectLocked
773  * @tc.type: FUNC
774  * @tc.require: I6P0I9
775  */
776 HWTEST_F(DistributedSchedServiceSecondTest, CheckDistributedConnectLocked002, TestSize.Level3)
777 {
778     DTEST_LOG << "DistributedSchedServiceSecondTest CheckDistributedConnectLocked002 start" << std::endl;
779     int32_t uid = -1;
780     CallerInfo callerInfo;
781     callerInfo.uid = uid;
782     int32_t ret = DistributedSchedService::GetInstance().CheckDistributedConnectLocked(callerInfo);
783     EXPECT_EQ(ret, BIND_ABILITY_UID_INVALID_ERR);
784     DTEST_LOG << "DistributedSchedServiceSecondTest CheckDistributedConnectLocked002 end" << std::endl;
785 }
786 
787 /**
788  * @tc.name: TryConnectRemoteAbility001
789  * @tc.desc: call TryConnectRemoteAbility
790  * @tc.type: FUNC
791  * @tc.require: I6P0I9
792  */
793 HWTEST_F(DistributedSchedServiceSecondTest, TryConnectRemoteAbility001, TestSize.Level3)
794 {
795     DTEST_LOG << "DistributedSchedServiceSecondTest TryConnectRemoteAbility001 start" << std::endl;
796     std::string remoteDeviceId = "remoteDeviceId";
797     OHOS::AAFwk::Want want;
798     want.SetElementName(remoteDeviceId, "ohos.demo.bundleName", "abilityName");
799     sptr<IRemoteObject> connect = nullptr;
800     CallerInfo callerInfo;
801     int32_t ret = DistributedSchedService::GetInstance().TryConnectRemoteAbility(want, connect, callerInfo);
802     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
803     DTEST_LOG << "DistributedSchedServiceSecondTest TryConnectRemoteAbility001 end" << std::endl;
804 }
805 
806 /**
807  * @tc.name: TryConnectRemoteAbility002
808  * @tc.desc: call TryConnectRemoteAbility
809  * @tc.type: FUNC
810  * @tc.require: I6P0I9
811  */
812 HWTEST_F(DistributedSchedServiceSecondTest, TryConnectRemoteAbility002, TestSize.Level3)
813 {
814     DTEST_LOG << "DistributedSchedServiceSecondTest TryConnectRemoteAbility002 start" << std::endl;
815     std::string remoteDeviceId = "remoteDeviceId";
816     OHOS::AAFwk::Want want;
817     want.SetElementName(remoteDeviceId, "ohos.demo.bundleName", "abilityName");
818     sptr<IRemoteObject> connect = nullptr;
819     CallerInfo callerInfo;
820     int32_t ret = DistributedSchedService::GetInstance().TryConnectRemoteAbility(want, connect, callerInfo);
821     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
822     DTEST_LOG << "DistributedSchedServiceSecondTest TryConnectRemoteAbility002 end" << std::endl;
823 }
824 
825 /**
826  * @tc.name: SetCallerInfo_001
827  * @tc.desc: call SetCallerInfo
828  * @tc.type: FUNC
829  * @tc.require: I76THI
830  */
831 HWTEST_F(DistributedSchedServiceSecondTest, SetCallerInfo_001, TestSize.Level3)
832 {
833     DTEST_LOG << "DistributedSchedServiceSecondTest SetCallerInfo_001 start" << std::endl;
834 
835     sptr<IDistributedSched> proxy = GetDms();
836     ASSERT_NE(nullptr, proxy);
837     /**
838      * @tc.steps: step1. set want and abilityInfo
839      */
840     AAFwk::Want want;
841     AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
842         "com.ohos.distributedmusicplayer.MainAbility");
843     want.SetElement(element);
844     AppExecFwk::AbilityInfo abilityInfo;
845     GetAbilityInfo("com.ohos.distributedmusicplayer", "com.ohos.distributedmusicplayer.MainAbility",
846         "com.ohos.distributedmusicplayer", "192.168.43.100", abilityInfo);
847     CallerInfo callerInfo;
848     callerInfo.uid = 0;
849     callerInfo.sourceDeviceId = "255.255.255.255";
850     IDistributedSched::AccountInfo accountInfo;
851     /**
852      * @tc.steps: step2. StartAbilityFromRemote for pressure test
853      * @tc.expected: step2. StartAbilityFromRemote for result
854      */
855     for (int index = 0; index < static_cast<int32_t>(LoopTime::LOOP_TIME); index++) {
856         int result = proxy->StartAbilityFromRemote(want, abilityInfo, 0, callerInfo, accountInfo);
857         DTEST_LOG << "pressure" + to_string(index) + " result is " << result << std::endl;
858     }
859 
860     /**
861     * @tc.steps: step1. call SetCallerInfo with invalid parameters.
862     */
863     CallerInfo callerInfo1;
864     int32_t result = DistributedSchedService::GetInstance().SetCallerInfo(0, LOCAL_DEVICEID, 0, callerInfo1);
865     EXPECT_EQ(result, INVALID_PARAMETERS_ERR);
866     /**
867     * @tc.steps: step2. call OnRemoteDied.
868     */
869     const wptr<IRemoteObject> remote;
870     CallerDeathRecipient callerDeathRecipient;
871     callerDeathRecipient.OnRemoteDied(remote);
872     DTEST_LOG << "DistributedSchedServiceSecondTest StartRemoteAbilityByCall_001 end" << std::endl;
873 }
874 
875 /**
876  * @tc.name: ContinueRemoteMission_001
877  * @tc.desc: call ContinueRemoteMission
878  * @tc.type: FUNC
879  */
880 HWTEST_F(DistributedSchedServiceSecondTest, ContinueRemoteMission_001, TestSize.Level1)
881 {
882     DTEST_LOG << "DSchedContinuationTest ContinueRemoteMission_001 start" << std::endl;
883     if (DistributedSchedService::GetInstance().dschedContinuation_ == nullptr) {
884         DistributedSchedService::GetInstance().dschedContinuation_ = std::make_shared<DSchedContinuation>();
885     }
886     int32_t missionId = MISSION_ID;
887     int32_t timeout = 5;
888     DistributedSchedService::GetInstance().SetContinuationTimeout(missionId, timeout);
889     WantParams wantParams;
890     EXPECT_EQ(ERR_OK, LoadContinueConfig());
891     auto callback = GetDSchedService();
892     int32_t result = DistributedSchedService::GetInstance().ContinueRemoteMission(
893         "", "string", "bundleName", callback, wantParams);
894     EXPECT_EQ(static_cast<int>(INVALID_REMOTE_PARAMETERS_ERR), result);
895     DTEST_LOG << "DSchedContinuationTest ContinueRemoteMission_001 end" << std::endl;
896 }
897 
898 /**
899  * @tc.name: ContinueRemoteMission_002
900  * @tc.desc: call ContinueRemoteMission
901  * @tc.type: FUNC
902  */
903 HWTEST_F(DistributedSchedServiceSecondTest, ContinueRemoteMission_002, TestSize.Level1)
904 {
905     DTEST_LOG << "DSchedContinuationTest ContinueRemoteMission_002 start" << std::endl;
906     WantParams wantParams;
907     EXPECT_EQ(ERR_OK, LoadContinueConfig());
908     auto callback = GetDSchedService();
909     std::string localDeviceId;
910     DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
911     int32_t result = DistributedSchedService::GetInstance().ContinueRemoteMission(
912         "string", localDeviceId, "bundleName", callback, wantParams);
913     EXPECT_EQ(static_cast<int>(INVALID_REMOTE_PARAMETERS_ERR), result);
914     DTEST_LOG << "DSchedContinuationTest ContinueRemoteMission_002 end" << std::endl;
915 }
916 
917 /**
918  * @tc.name: StartLocalAbility_001
919  * @tc.desc: call StartLocalAbility with dms
920  * @tc.type: FUNC
921  */
922 HWTEST_F(DistributedSchedServiceSecondTest, StartLocalAbility_001, TestSize.Level1)
923 {
924     DTEST_LOG << "DistributedSchedServiceSecondTest StartLocalAbility_001 start" << std::endl;
925     sptr<IDistributedSched> proxy = GetDms();
926 
927     AAFwk::Want want;
928     AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
929         "com.ohos.distributedmusicplayer.MainAbility");
930     want.SetElement(element);
931     CallerInfo callerInfo;
932     callerInfo.uid = 0;
933     callerInfo.sourceDeviceId = "255.255.255.255";
934     IDistributedSched::AccountInfo accountInfo;
935     int missionId = 0;
936     want.SetParam(DMS_SRC_NETWORK_ID, callerInfo.sourceDeviceId);
937     want.SetParam(DMS_MISSION_ID, missionId);
938     DistributedSchedProxy::FreeInstallInfo info = {.want = want, .requestCode = 0, .callerInfo = callerInfo,
939         .accountInfo = accountInfo};
940     int result1 = DistributedSchedService::GetInstance().StartLocalAbility(info, 0, 0);
941     DTEST_LOG << "result1:" << result1 << std::endl;
942 
943     AppExecFwk::ElementName element2("", "com.ohos.distributedmusicplayer",
944         "com.ohos.distributedmusicplayer.MainAbilityService");
945     want.SetElement(element2);
946     DistributedSchedProxy::FreeInstallInfo info2 = {.want = want, .requestCode = 0, .callerInfo = callerInfo,
947         .accountInfo = accountInfo};
948     int result2 = DistributedSchedService::GetInstance().StartLocalAbility(info2, 0, 0);
949     DTEST_LOG << "result2:" << result2 << std::endl;
950     EXPECT_EQ(static_cast<int>(INVALID_PARAMETERS_ERR), result1);
951     EXPECT_EQ(static_cast<int>(INVALID_PARAMETERS_ERR), result2);
952     DTEST_LOG << "DistributedSchedServiceSecondTest StartLocalAbility_001 end" << std::endl;
953 }
954 
955 /**
956  * @tc.name: StartLocalAbility_002
957  * @tc.desc: call StartLocalAbility with dms
958  * @tc.type: FUNC
959  */
960 HWTEST_F(DistributedSchedServiceSecondTest, StartLocalAbility_002, TestSize.Level1)
961 {
962     DTEST_LOG << "DistributedSchedServiceSecondTest StartLocalAbility_002 start" << std::endl;
963     sptr<IDistributedSched> proxy = GetDms();
964 
965     AAFwk::Want want;
966     AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
967         "com.ohos.distributedmusicplayer.MainAbility");
968     want.SetElement(element);
969     CallerInfo callerInfo;
970     callerInfo.uid = 0;
971     callerInfo.sourceDeviceId = "255.255.255.255";
972     IDistributedSched::AccountInfo accountInfo;
973     DistributedSchedProxy::FreeInstallInfo info = {.want = want, .requestCode = DEFAULT_REQUEST_CODE,
974         .callerInfo = callerInfo, .accountInfo = accountInfo};
975     int result1 = DistributedSchedService::GetInstance().StartLocalAbility(info, 0, 0);
976     DTEST_LOG << "result1:" << result1 << std::endl;
977 
978     AppExecFwk::ElementName element2("", "com.ohos.distributedmusicplayer",
979         "com.ohos.distributedmusicplayer.MainAbilityService");
980     want.SetElement(element2);
981     DistributedSchedProxy::FreeInstallInfo info2 = {.want = want, .requestCode = DEFAULT_REQUEST_CODE,
982         .callerInfo = callerInfo, .accountInfo = accountInfo};
983     int result2 = DistributedSchedService::GetInstance().StartLocalAbility(info2, 0, 0);
984     DTEST_LOG << "result2:" << result2 << std::endl;
985     EXPECT_EQ(static_cast<int>(INVALID_PARAMETERS_ERR), result1);
986     EXPECT_EQ(static_cast<int>(INVALID_PARAMETERS_ERR), result2);
987     DTEST_LOG << "DistributedSchedServiceSecondTest StartLocalAbility_002 end" << std::endl;
988 }
989 
990 /**
991  * @tc.name: StartLocalAbility_003
992  * @tc.desc: call StartLocalAbility with dms
993  * @tc.type: FUNC
994  */
995 HWTEST_F(DistributedSchedServiceSecondTest, StartLocalAbility_003, TestSize.Level1)
996 {
997     DTEST_LOG << "DistributedSchedServiceSecondTest StartLocalAbility_003 start" << std::endl;
998     sptr<IDistributedSched> proxy = GetDms();
999 
1000     AAFwk::Want want;
1001     AppExecFwk::ElementName element("1.1.1.1", "com.ohos.distributedmusicplayer",
1002         "com.ohos.distributedmusicplayer.MainAbility");
1003     want.SetElement(element);
1004     CallerInfo callerInfo;
1005     callerInfo.uid = 0;
1006     callerInfo.sourceDeviceId = "255.255.255.255";
1007     IDistributedSched::AccountInfo accountInfo;
1008     accountInfo.accountType = 1;
1009     accountInfo.groupIdList.push_back("123456");
1010     int missionId = 0;
1011     want.SetParam(DMS_SRC_NETWORK_ID, callerInfo.sourceDeviceId);
1012     want.SetParam(DMS_MISSION_ID, missionId);
1013     DistributedSchedProxy::FreeInstallInfo info = {.want = want, .requestCode = 0, .callerInfo = callerInfo,
1014         .accountInfo = accountInfo};
1015     int result1 = DistributedSchedService::GetInstance().StartLocalAbility(info, 0, 0);
1016     DTEST_LOG << "result1:" << result1 << std::endl;
1017 
1018     AppExecFwk::ElementName element2("1.1.1.1", "com.ohos.distributedmusicplayer",
1019         "com.ohos.distributedmusicplayer.MainAbilityService");
1020     want.SetElement(element2);
1021     DistributedSchedProxy::FreeInstallInfo info2 = {.want = want, .requestCode = 0, .callerInfo = callerInfo,
1022         .accountInfo = accountInfo};
1023     int result2 = DistributedSchedService::GetInstance().StartLocalAbility(info2, 0, 0);
1024     EXPECT_EQ(result2, INVALID_PARAMETERS_ERR);
1025     DTEST_LOG << "result2:" << result2 << std::endl;
1026     DTEST_LOG << "DistributedSchedServiceSecondTest StartLocalAbility_003 end" << std::endl;
1027 }
1028 
1029 /**
1030  * @tc.name: StartLocalAbility_004
1031  * @tc.desc: call StartLocalAbility with dms
1032  * @tc.type: FUNC
1033  */
1034 HWTEST_F(DistributedSchedServiceSecondTest, StartLocalAbility_004, TestSize.Level1)
1035 {
1036     DTEST_LOG << "DistributedSchedServiceSecondTest StartLocalAbility_004 start" << std::endl;
1037     sptr<IDistributedSched> proxy = GetDms();
1038 
1039     AAFwk::Want want;
1040     AppExecFwk::ElementName element("1.1.1.1", "com.ohos.distributedmusicplayer",
1041         "com.ohos.distributedmusicplayer.MainAbility");
1042     want.SetElement(element);
1043     CallerInfo callerInfo;
1044     callerInfo.uid = 0;
1045     callerInfo.sourceDeviceId = "255.255.255.255";
1046     IDistributedSched::AccountInfo accountInfo;
1047     accountInfo.accountType = 1;
1048     accountInfo.groupIdList.push_back("123456");
1049     DistributedSchedProxy::FreeInstallInfo info = {.want = want, .requestCode = DEFAULT_REQUEST_CODE,
1050         .callerInfo = callerInfo, .accountInfo = accountInfo};
1051     int result1 = DistributedSchedService::GetInstance().StartLocalAbility(info, 0, 0);
1052     DTEST_LOG << "result1:" << result1 << std::endl;
1053 
1054     AppExecFwk::ElementName element2("1.1.1.1", "com.ohos.distributedmusicplayer",
1055         "com.ohos.distributedmusicplayer.MainAbilityService");
1056     want.SetElement(element2);
1057     DistributedSchedProxy::FreeInstallInfo info2 = {.want = want, .requestCode = DEFAULT_REQUEST_CODE,
1058         .callerInfo = callerInfo, .accountInfo = accountInfo};
1059     int result2 = DistributedSchedService::GetInstance().StartLocalAbility(info2, 0, 0);
1060     EXPECT_EQ(result2, INVALID_PARAMETERS_ERR);
1061     DTEST_LOG << "result2:" << result2 << std::endl;
1062     DTEST_LOG << "DistributedSchedServiceSecondTest StartLocalAbility_004 end" << std::endl;
1063 }
1064 
1065 /**
1066  * @tc.name: StartLocalAbility_005
1067  * @tc.desc: test StartLocalAbility
1068  * @tc.type: FUNC
1069  * @tc.require: issueI5T6GJ
1070  */
1071 HWTEST_F(DistributedSchedServiceSecondTest, StartLocalAbility_005, TestSize.Level3)
1072 {
1073     DTEST_LOG << "DistributedSchedServiceSecondTest StartLocalAbility_005 start" << std::endl;
1074     AAFwk::Want want;
1075     std::string localDeviceId;
1076     DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
1077     AppExecFwk::ElementName element(localDeviceId, "com.ohos.mms", "bmsThirdBundle");
1078     want.SetElement(element);
1079     want.SetParam(DMS_IS_CALLER_BACKGROUND, false);
1080     AppExecFwk::AbilityInfo abilityInfo;
1081     abilityInfo.permissions.clear();
1082     CallerInfo callerInfo;
1083     callerInfo.uid = 0;
1084     callerInfo.sourceDeviceId = LOCAL_DEVICEID;
1085     bool result = BundleManagerInternal::GetCallerAppIdFromBms("com.third.hiworld.example", callerInfo.callerAppId);
1086     EXPECT_TRUE(result);
1087     IDistributedSched::AccountInfo accountInfo;
1088     accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
1089     DistributedSchedProxy::FreeInstallInfo info = {.want = want, .requestCode = 0,
1090         .callerInfo = callerInfo, .accountInfo = accountInfo};
1091     int ret = DistributedSchedService::GetInstance().StartLocalAbility(info, 0, 0);
1092     EXPECT_NE(ret, ERR_OK);
1093     DTEST_LOG << "DistributedSchedServiceSecondTest StartLocalAbility_005 end" << std::endl;
1094 }
1095 
1096 /**
1097  * @tc.name: HandleLocalCallerDied_001
1098  * @tc.desc: call HandleLocalCallerDied
1099  * @tc.type: FUNC
1100  * @tc.require: I6YLV1
1101  */
1102 HWTEST_F(DistributedSchedServiceSecondTest, HandleLocalCallerDied_001, TestSize.Level1)
1103 {
1104     DTEST_LOG << "DistributedSchedServiceSecondTest HandleLocalCallerDied_001 start" << std::endl;
1105     std::string localDeviceId;
1106     DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
1107     sptr<IRemoteObject> connect(new MockDistributedSched());
1108     std::list<ConnectAbilitySession> sessionsList;
1109     DistributedSchedService::GetInstance().callerMap_[connect] = sessionsList;
1110     DistributedSchedService::GetInstance().callMap_[connect] = {4, localDeviceId};
1111     DistributedSchedService::GetInstance().HandleLocalCallerDied(connect);
1112     DistributedSchedService::GetInstance().callerMap_.clear();
1113     EXPECT_TRUE(DistributedSchedService::GetInstance().callerMap_.empty());
1114     DistributedSchedService::GetInstance().callMap_.clear();
1115     EXPECT_TRUE(DistributedSchedService::GetInstance().callMap_.empty());
1116     DTEST_LOG << "DistributedSchedServiceSecondTest HandleLocalCallerDied_001 end" << std::endl;
1117 }
1118 
1119 /**
1120  * @tc.name: RemoveCallerComponent_001
1121  * @tc.desc: call RemoveCallerComponent
1122  * @tc.type: FUNC
1123  * @tc.require: I6YLV1
1124  */
1125 HWTEST_F(DistributedSchedServiceSecondTest, RemoveCallerComponent_001, TestSize.Level1)
1126 {
1127     DTEST_LOG << "DistributedSchedServiceSecondTest RemoveCallerComponent_001 start" << std::endl;
1128     std::string localDeviceId;
1129     DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
1130     sptr<IRemoteObject> connect(new MockDistributedSched());
1131     std::list<ConnectAbilitySession> sessionsList;
1132     DistributedSchedService::GetInstance().callerMap_[connect] = sessionsList;
1133     DistributedSchedService::GetInstance().callMap_[connect] = {5, localDeviceId};
1134     DistributedSchedService::GetInstance().RemoveCallerComponent(connect);
1135     DistributedSchedService::GetInstance().RemoveCallerComponent(nullptr);
1136     DistributedSchedService::GetInstance().callerMap_.clear();
1137     EXPECT_TRUE(DistributedSchedService::GetInstance().callerMap_.empty());
1138     DistributedSchedService::GetInstance().callMap_.clear();
1139     EXPECT_TRUE(DistributedSchedService::GetInstance().callMap_.empty());
1140     DTEST_LOG << "DistributedSchedServiceSecondTest RemoveCallerComponent_001 end" << std::endl;
1141 }
1142 
1143 /**
1144  * @tc.name: ProcessCalleeOffline_001
1145  * @tc.desc: call ProcessCalleeOffline
1146  * @tc.type: FUNC
1147  * @tc.require: I6YLV1
1148  */
1149 HWTEST_F(DistributedSchedServiceSecondTest, ProcessCalleeOffline_001, TestSize.Level1)
1150 {
1151     DTEST_LOG << "DistributedSchedServiceSecondTest ProcessCalleeOffline_001 start" << std::endl;
1152     std::string localDeviceId;
1153     DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
1154     sptr<IRemoteObject> connect(new MockDistributedSched());
1155     std::list<ConnectAbilitySession> sessionsList;
1156     DistributedSchedService::GetInstance().callerMap_[connect] = sessionsList;
1157     DistributedSchedService::GetInstance().callMap_[connect] = {6, localDeviceId};
1158     DistributedSchedService::GetInstance().ProcessCalleeOffline(REMOTE_DEVICEID);
1159 
1160     sptr<IRemoteObject> mockConnect = nullptr;
1161     DistributedSchedService::GetInstance().callerMap_[mockConnect] = sessionsList;
1162     DistributedSchedService::GetInstance().ProcessCalleeOffline(localDeviceId);
1163     DistributedSchedService::GetInstance().callerMap_.clear();
1164     EXPECT_TRUE(DistributedSchedService::GetInstance().callerMap_.empty());
1165     DistributedSchedService::GetInstance().callMap_.clear();
1166     EXPECT_TRUE(DistributedSchedService::GetInstance().callMap_.empty());
1167     DTEST_LOG << "DistributedSchedServiceSecondTest ProcessCalleeOffline_001 end" << std::endl;
1168 }
1169 
1170 /**
1171  * @tc.name: GetConnectComponentList_001
1172  * @tc.desc: call GetConnectComponentList
1173  * @tc.type: FUNC
1174  * @tc.require: I76THI
1175  */
1176 HWTEST_F(DistributedSchedServiceSecondTest, GetConnectComponentList_001, TestSize.Level1)
1177 {
1178     DTEST_LOG << "DistributedSchedServiceSecondTest GetConnectComponentList_001 start" << std::endl;
1179     /**
1180     * @tc.steps: step1. call GetConnectComponentList when iter.second is empty.
1181     */
1182     sptr<IRemoteObject> connect(new MockDistributedSched());
1183     std::list<ConnectAbilitySession> sessionsList;
1184     std::vector<std::string> distributedComponents;
1185     {
1186         std::lock_guard<std::mutex> autoLock(DistributedSchedService::GetInstance().distributedLock_);
1187         DistributedSchedService::GetInstance().distributedConnectAbilityMap_.clear();
1188         DistributedSchedService::GetInstance().distributedConnectAbilityMap_[connect] = sessionsList;
1189     }
1190     DistributedSchedService::GetInstance().GetConnectComponentList(distributedComponents);
1191     EXPECT_TRUE(distributedComponents.empty());
1192     /**
1193     * @tc.steps: step2. call GetConnectComponentList when iter.second is not empty.
1194     */
1195     CallerInfo callerInfo;
1196     ConnectAbilitySession connectAbilitySession("sourceDeviceId", "destinationDeviceId", callerInfo);
1197     sessionsList.emplace_back(connectAbilitySession);
1198     {
1199         std::lock_guard<std::mutex> autoLock(DistributedSchedService::GetInstance().distributedLock_);
1200         DistributedSchedService::GetInstance().distributedConnectAbilityMap_[connect] = sessionsList;
1201     }
1202     DistributedSchedService::GetInstance().GetConnectComponentList(distributedComponents);
1203     EXPECT_FALSE(distributedComponents.empty());
1204     /**
1205     * @tc.steps: step3. call GetConnectComponentList when connectAbilityMap_ is not empty.
1206     */
1207     distributedComponents.clear();
1208     ConnectInfo connectInfo;
1209     {
1210         std::lock_guard<std::mutex> autoLock(DistributedSchedService::GetInstance().connectLock_);
1211         DistributedSchedService::GetInstance().connectAbilityMap_[connect] = connectInfo;
1212     }
1213     DistributedSchedService::GetInstance().GetConnectComponentList(distributedComponents);
1214     EXPECT_FALSE(distributedComponents.empty());
1215     DTEST_LOG << "DistributedSchedServiceSecondTest GetConnectComponentList_001 end" << std::endl;
1216 }
1217 
1218 /**
1219  * @tc.name: GetCallComponentList_001
1220  * @tc.desc: call GetCallComponentList
1221  * @tc.type: FUNC
1222  * @tc.require: I76THI
1223  */
1224 HWTEST_F(DistributedSchedServiceSecondTest, GetCallComponentList_001, TestSize.Level1)
1225 {
1226     DTEST_LOG << "DistributedSchedServiceSecondTest GetCallComponentList_001 start" << std::endl;
1227     /**
1228     * @tc.steps: step1. call GetCallComponentList when iter.second is empty.
1229     */
1230     sptr<IRemoteObject> connect(new MockDistributedSched());
1231     std::list<ConnectAbilitySession> sessionsList;
1232     std::vector<std::string> distributedComponents;
1233     {
1234         std::lock_guard<std::mutex> autoLock(DistributedSchedService::GetInstance().callerLock_);
1235         DistributedSchedService::GetInstance().callerMap_.clear();
1236         DistributedSchedService::GetInstance().callerMap_[connect] = sessionsList;
1237     }
1238     DistributedSchedService::GetInstance().GetCallComponentList(distributedComponents);
1239     EXPECT_TRUE(distributedComponents.empty());
1240     /**
1241     * @tc.steps: step2. call GetCallComponentList when iter.second is not empty.
1242     */
1243     CallerInfo callerInfo;
1244     ConnectAbilitySession connectAbilitySession("sourceDeviceId", "destinationDeviceId", callerInfo);
1245     sessionsList.emplace_back(connectAbilitySession);
1246     {
1247         std::lock_guard<std::mutex> autoLock(DistributedSchedService::GetInstance().callerLock_);
1248         DistributedSchedService::GetInstance().callerMap_[connect] = sessionsList;
1249     }
1250     DistributedSchedService::GetInstance().GetCallComponentList(distributedComponents);
1251     EXPECT_FALSE(distributedComponents.empty());
1252     /**
1253     * @tc.steps: step3. call GetCallComponentList when calleeMap_ is not empty.
1254     */
1255     distributedComponents.clear();
1256     ConnectInfo connectInfo;
1257     {
1258         std::lock_guard<std::mutex> autoLock(DistributedSchedService::GetInstance().calleeLock_);
1259         DistributedSchedService::GetInstance().calleeMap_[connect] = connectInfo;
1260     }
1261     DistributedSchedService::GetInstance().GetCallComponentList(distributedComponents);
1262     EXPECT_FALSE(distributedComponents.empty());
1263     DTEST_LOG << "DistributedSchedServiceSecondTest GetCallComponentList_001 end" << std::endl;
1264 }
1265 
1266 /**
1267  * @tc.name: RegisterAppStateObserver_001
1268  * @tc.desc: test RegisterAppStateObserver
1269  * @tc.type: FUNC
1270  * @tc.require: I6VDBO
1271  */
1272 HWTEST_F(DistributedSchedServiceSecondTest, RegisterAppStateObserver_001, TestSize.Level3)
1273 {
1274     DTEST_LOG << "DistributedSchedServiceSecondTest RegisterAppStateObserver_001 start" << std::endl;
1275     AAFwk::Want want;
1276     std::string localDeviceId;
1277     DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
1278     AppExecFwk::ElementName element(localDeviceId, BUNDLE_NAME, ABILITY_NAME);
1279     want.SetElement(element);
1280     want.SetParam(DMS_MISSION_ID, 0);
1281     want.SetParam(DMS_CONNECT_TOKEN, 0);
1282     sptr<IRemoteObject> connect(new MockDistributedSched());
1283     CallerInfo callerInfo;
1284     callerInfo.uid = 0;
1285     callerInfo.sourceDeviceId = localDeviceId;
1286     bool ret = DistributedSchedService::GetInstance().RegisterAppStateObserver(want, callerInfo, nullptr, connect);
1287     DistributedSchedService::GetInstance().UnregisterAppStateObserver(connect);
1288     EXPECT_TRUE(ret);
1289     DTEST_LOG << "DistributedSchedServiceSecondTest RegisterAppStateObserver_001 end" << std::endl;
1290 }
1291 
1292 /**
1293  * @tc.name: UnregisterAppStateObserver_001
1294  * @tc.desc: test UnregisterAppStateObserver
1295  * @tc.type: FUNC
1296  * @tc.require: I6VDBO
1297  */
1298 HWTEST_F(DistributedSchedServiceSecondTest, UnregisterAppStateObserver_001, TestSize.Level3)
1299 {
1300     DTEST_LOG << "DistributedSchedServiceSecondTest UnregisterAppStateObserver_001 start" << std::endl;
1301     sptr<IRemoteObject> connect = nullptr;
1302     DistributedSchedService::GetInstance().UnregisterAppStateObserver(connect);
1303     EXPECT_EQ(connect, nullptr);
1304     DTEST_LOG << "DistributedSchedServiceSecondTest UnregisterAppStateObserver_001 end" << std::endl;
1305 }
1306 
1307 /**
1308  * @tc.name: UnregisterAppStateObserver_002
1309  * @tc.desc: test UnregisterAppStateObserver
1310  * @tc.type: FUNC
1311  * @tc.require: I6VDBO
1312  */
1313 HWTEST_F(DistributedSchedServiceSecondTest, UnregisterAppStateObserver_002, TestSize.Level3)
1314 {
1315     DTEST_LOG << "DistributedSchedServiceSecondTest UnregisterAppStateObserver_002 start" << std::endl;
1316     AAFwk::Want want;
1317     std::string localDeviceId;
1318     DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
1319     AppExecFwk::ElementName element(localDeviceId, BUNDLE_NAME, ABILITY_NAME);
1320     want.SetElement(element);
1321     want.SetParam(DMS_MISSION_ID, 0);
1322     want.SetParam(DMS_CONNECT_TOKEN, 0);
1323     sptr<IRemoteObject> connect(new MockDistributedSched());
1324     CallerInfo callerInfo;
1325     callerInfo.uid = 0;
1326     callerInfo.sourceDeviceId = localDeviceId;
1327     bool ret = DistributedSchedService::GetInstance().RegisterAppStateObserver(want, callerInfo, nullptr, connect);
1328     EXPECT_TRUE(ret);
1329     sptr<IRemoteObject> connect1(new MockDistributedSched());
1330     DistributedSchedService::GetInstance().UnregisterAppStateObserver(connect1);
1331     EXPECT_NE(connect, connect1);
1332     DistributedSchedService::GetInstance().SaveCallerComponent(want, nullptr, callerInfo);
1333     DTEST_LOG << "DistributedSchedServiceSecondTest UnregisterAppStateObserver_002 end" << std::endl;
1334 }
1335 
1336 /**
1337  * @tc.name: GetAppManager_001
1338  * @tc.desc: test GetAppManager
1339  * @tc.type: FUNC
1340  * @tc.require: I6VDBO
1341  */
1342 HWTEST_F(DistributedSchedServiceSecondTest, GetAppManager_001, TestSize.Level3)
1343 {
1344     DTEST_LOG << "DistributedSchedServiceSecondTest GetAppManager_001 start" << std::endl;
1345     auto ret = DistributedSchedService::GetInstance().GetAppManager();
1346     EXPECT_NE(ret, nullptr);
1347     DTEST_LOG << "DistributedSchedServiceSecondTest GetAppManager_001 end" << std::endl;
1348 }
1349 
1350 /**
1351  * @tc.name: SaveConnectToken_001
1352  * @tc.desc: call SaveConnectToken
1353  * @tc.type: FUNC
1354  * @tc.require: I76THI
1355  */
1356 HWTEST_F(DistributedSchedServiceSecondTest, SaveConnectToken_001, TestSize.Level3)
1357 {
1358     DTEST_LOG << "DistributedSchedServiceSecondTest SaveConnectToken_001 start" << std::endl;
1359     AAFwk::Want want;
1360     std::string localDeviceId;
1361     DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
1362     AppExecFwk::ElementName element(localDeviceId, BUNDLE_NAME,
1363         ABILITY_NAME);
1364     sptr<IRemoteObject> connect(new MockDistributedSched());
1365     /**
1366     * @tc.steps: step1. call SaveConnectToken
1367     * @tc.expected: step1. SaveConnectToken return token_
1368     */
1369     int32_t token = 0;
1370     {
1371         std::lock_guard<std::mutex> tokenLock(DistributedSchedService::GetInstance().tokenMutex_);
1372         token = DistributedSchedService::GetInstance().token_.load();
1373     }
1374     int32_t result = DistributedSchedService::GetInstance().SaveConnectToken(want, connect);
1375     EXPECT_EQ(result, token + 1);
1376     /**
1377     * @tc.steps: step2. call SaveConnectToken when tToken > MAX_TOKEN_NUM
1378     * @tc.expected: step2. SaveConnectToken return 1
1379     */
1380     {
1381         std::lock_guard<std::mutex> tokenLock(DistributedSchedService::GetInstance().tokenMutex_);
1382         DistributedSchedService::GetInstance().token_.store(MAX_TOKEN_NUM);
1383     }
1384     result = DistributedSchedService::GetInstance().SaveConnectToken(want, connect);
1385     EXPECT_EQ(result, 1);
1386     DTEST_LOG << "DistributedSchedServiceSecondTest SaveConnectToken_001 end" << std::endl;
1387 }
1388 
1389 /**
1390  * @tc.name: ContinueMissionBundleName_001
1391  * @tc.desc: call ContinueMissionBundleName
1392  * @tc.type: FUNC
1393  */
1394 HWTEST_F(DistributedSchedServiceSecondTest, ContinueMissionBundleName_001, TestSize.Level1)
1395 {
1396     DTEST_LOG << "DSchedContinuationTest ContinueMissionBundleName_001 start" << std::endl;
1397     WantParams wantParams;
1398     auto callback = GetDSchedService();
1399     std::string localDeviceId;
1400     DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
1401     int32_t result = DistributedSchedService::GetInstance().ContinueMission(
1402         "string", localDeviceId, "bundleName", callback, wantParams);
1403     EXPECT_EQ(static_cast<int>(INVALID_REMOTE_PARAMETERS_ERR), result);
1404     DistributedSchedService::GetInstance().ContinueMission(
1405         localDeviceId, "string", "bundleName", callback, wantParams);
1406     DTEST_LOG << "DSchedContinuationTest ContinueMissionBundleName_001 end" << std::endl;
1407 }
1408 
1409 /**
1410  * @tc.name: ContinueMissionBundleName_002
1411  * @tc.desc: call ContinueMissionBundleName
1412  * @tc.type: FUNC
1413  */
1414 HWTEST_F(DistributedSchedServiceSecondTest, ContinueMissionBundleName_002, TestSize.Level1)
1415 {
1416     DTEST_LOG << "DSchedContinuationTest ContinueMissionBundleName_002 start" << std::endl;
1417     WantParams wantParams;
1418     auto callback = GetDSchedService();
1419     int32_t result = DistributedSchedService::GetInstance().ContinueMission(
1420         "string", "string", "bundleName", callback, wantParams);
1421     EXPECT_EQ(static_cast<int>(OPERATION_DEVICE_NOT_INITIATOR_OR_TARGET), result);
1422     DTEST_LOG << "DSchedContinuationTest ContinueMissionBundleName_002 end" << std::endl;
1423 }
1424 
1425 /**
1426  * @tc.name: GetCallerInfo_001
1427  * @tc.desc: GetCallerInfo
1428  * @tc.type: FUNC
1429  */
1430 HWTEST_F(DistributedSchedServiceSecondTest, GetCallerInfo_001, TestSize.Level3)
1431 {
1432     DTEST_LOG << "DistributedSchedServiceSecondTest GetCallerInfo_001 start" << std::endl;
1433     int32_t callerUid = 0;
1434     uint32_t accessToken = 0;
1435     CallerInfo callerInfo;
1436     int32_t result = DistributedSchedService::GetInstance().GetCallerInfo(
1437         LOCAL_DEVICEID, callerUid, accessToken, callerInfo);
1438     EXPECT_EQ(result, INVALID_PARAMETERS_ERR);
1439     DTEST_LOG << "DistributedSchedServiceSecondTest GetCallerInfo_001 end" << std::endl;
1440 }
1441 
1442 /**
1443  * @tc.name: ProcessContinueLocalMission_001
1444  * @tc.desc: ProcessContinueLocalMission
1445  * @tc.type: FUNC
1446  */
1447 HWTEST_F(DistributedSchedServiceSecondTest, ProcessContinueLocalMission_001, TestSize.Level3)
1448 {
1449     DTEST_LOG << "DistributedSchedServiceSecondTest ProcessContinueLocalMission_001 start" << std::endl;
1450     WantParams wantParams;
1451     int32_t result = DistributedSchedService::GetInstance().ProcessContinueLocalMission(
1452         LOCAL_DEVICEID, REMOTE_DEVICEID, BUNDLE_NAME, nullptr, wantParams);
1453 
1454     bool ret = DistributedSchedService::GetInstance().GetIsFreeInstall(0);
1455     EXPECT_EQ(ret, false);
1456     DTEST_LOG << "DistributedSchedServiceSecondTest ProcessContinueLocalMission_001 end" << std::endl;
1457 }
1458 
1459 /**
1460  * @tc.name: StartAbility_001
1461  * @tc.desc: StartAbility
1462  * @tc.type: FUNC
1463  */
1464 HWTEST_F(DistributedSchedServiceSecondTest, StartAbility_001, TestSize.Level3)
1465 {
1466     DTEST_LOG << "DistributedSchedServiceSecondTest StartAbility_001 start" << std::endl;
1467     Want want;
1468     int32_t requestCode = 0;
1469     int32_t ret = DistributedSchedService::GetInstance().StartAbility(want, requestCode);
1470     EXPECT_NE(ret, ERR_OK);
1471     DTEST_LOG << "DistributedSchedServiceSecondTest StartAbility_001 end" << std::endl;
1472 }
1473 
1474 /**
1475  * @tc.name: CheckTargetPermission4DiffBundle_001
1476  * @tc.desc: CheckTargetPermission4DiffBundle
1477  * @tc.type: FUNC
1478  */
1479 HWTEST_F(DistributedSchedServiceSecondTest, CheckTargetPermission4DiffBundle_001, TestSize.Level3)
1480 {
1481     DTEST_LOG << "DistributedSchedServiceSecondTest CheckTargetPermission4DiffBundle_001 start" << std::endl;
1482     OHOS::AAFwk::Want want;
1483     CallerInfo callerInfo;
1484     AccountInfo accountInfo;
1485     int32_t flag = 0;
1486     int32_t ret = DistributedSchedService::GetInstance().CheckTargetPermission4DiffBundle(want,
1487         callerInfo, accountInfo, flag, true);
1488     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
1489     DTEST_LOG << "DistributedSchedServiceSecondTest CheckTargetPermission4DiffBundle_001 end" << std::endl;
1490 }
1491 
1492 #ifdef DMSFWK_INTERACTIVE_ADAPTER
1493 /**
1494  * @tc.name: StartRemoteAbilityAdapter_001
1495  * @tc.desc: StartRemoteAbilityAdapter
1496  * @tc.type: FUNC
1497  */
1498 HWTEST_F(DistributedSchedServiceSecondTest, StartRemoteAbilityAdapter_001, TestSize.Level3)
1499 {
1500     DTEST_LOG << "DistributedSchedServiceSecondTest StartRemoteAbilityAdapter_001 start" << std::endl;
1501     OHOS::AAFwk::Want want;
1502     int32_t callerUid = 0;
1503     int32_t requestCode = 0;
1504     uint32_t accessToken = 0;
1505     int32_t ret = DistributedSchedService::GetInstance().StartRemoteAbilityAdapter(want,
1506         callerUid, requestCode, accessToken);
1507     EXPECT_EQ(ret, NOT_FIND_SERVICE_REGISTRY);
1508     DTEST_LOG << "DistributedSchedServiceSecondTest StartRemoteAbilityAdapter_001 end" << std::endl;
1509 }
1510 
1511 /**
1512  * @tc.name: ConnectRemoteAbilityAdapter_001
1513  * @tc.desc: ConnectRemoteAbilityAdapter
1514  * @tc.type: FUNC
1515  */
1516 HWTEST_F(DistributedSchedServiceSecondTest, ConnectRemoteAbilityAdapter_001, TestSize.Level3)
1517 {
1518     DTEST_LOG << "DistributedSchedServiceSecondTest ConnectRemoteAbilityAdapter_001 start" << std::endl;
1519     OHOS::AAFwk::Want want;
1520     sptr<IRemoteObject> connect;
1521     int32_t callerUid = 0;
1522     int32_t callerPid = 0;
1523     uint32_t accessToken = 0;
1524     int32_t ret = DistributedSchedService::GetInstance().ConnectRemoteAbilityAdapter(want, connect,
1525         callerUid, callerPid, accessToken);
1526     EXPECT_EQ(ret, NOT_FIND_SERVICE_REGISTRY);
1527     DTEST_LOG << "DistributedSchedServiceSecondTest ConnectRemoteAbilityAdapter_001 end" << std::endl;
1528 }
1529 
1530 /**
1531  * @tc.name: StartAbilityFromRemoteAdapter_001
1532  * @tc.desc: StartAbilityFromRemoteAdapter
1533  * @tc.type: FUNC
1534  */
1535 HWTEST_F(DistributedSchedServiceSecondTest, StartAbilityFromRemoteAdapter_001, TestSize.Level3)
1536 {
1537     DTEST_LOG << "DistributedSchedServiceSecondTest StartAbilityFromRemoteAdapter_001 start" << std::endl;
1538     MessageParcel data;
1539     MessageParcel reply;
1540     int32_t ret = DistributedSchedService::GetInstance().StartAbilityFromRemoteAdapter(data, reply);
1541     EXPECT_EQ(ret, NOT_FIND_SERVICE_REGISTRY);
1542     DTEST_LOG << "DistributedSchedServiceSecondTest StartAbilityFromRemoteAdapter_001 end" << std::endl;
1543 }
1544 
1545 /**
1546  * @tc.name: StopAbilityFromRemoteAdapter_001
1547  * @tc.desc: StopAbilityFromRemoteAdapter
1548  * @tc.type: FUNC
1549  */
1550 HWTEST_F(DistributedSchedServiceSecondTest, StopAbilityFromRemoteAdapter_001, TestSize.Level3)
1551 {
1552     DTEST_LOG << "DistributedSchedServiceSecondTest StopAbilityFromRemoteAdapter_001 start" << std::endl;
1553     MessageParcel data;
1554     MessageParcel reply;
1555     int32_t ret = DistributedSchedService::GetInstance().StopAbilityFromRemoteAdapter(data, reply);
1556     EXPECT_EQ(ret, NOT_FIND_SERVICE_REGISTRY);
1557     DTEST_LOG << "DistributedSchedServiceSecondTest StopAbilityFromRemoteAdapter_001 end" << std::endl;
1558 }
1559 
1560 /**
1561  * @tc.name: ConnectAbilityFromRemoteAdapter_001
1562  * @tc.desc: ConnectAbilityFromRemoteAdapter
1563  * @tc.type: FUNC
1564  */
1565 HWTEST_F(DistributedSchedServiceSecondTest, ConnectAbilityFromRemoteAdapter_001, TestSize.Level3)
1566 {
1567     DTEST_LOG << "DistributedSchedServiceSecondTest ConnectAbilityFromRemoteAdapter_001 start" << std::endl;
1568     MessageParcel data;
1569     MessageParcel reply;
1570     int32_t ret = DistributedSchedService::GetInstance().ConnectAbilityFromRemoteAdapter(data, reply);
1571     EXPECT_EQ(ret, NOT_FIND_SERVICE_REGISTRY);
1572     DTEST_LOG << "DistributedSchedServiceSecondTest ConnectAbilityFromRemoteAdapter_001 end" << std::endl;
1573 }
1574 
1575 /**
1576  * @tc.name: DisconnectAbilityFromRemoteAdapter_001
1577  * @tc.desc: DisconnectAbilityFromRemoteAdapter
1578  * @tc.type: FUNC
1579  */
1580 HWTEST_F(DistributedSchedServiceSecondTest, DisconnectAbilityFromRemoteAdapter_001, TestSize.Level3)
1581 {
1582     DTEST_LOG << "DistributedSchedServiceSecondTest DisconnectAbilityFromRemoteAdapter_001 start" << std::endl;
1583     MessageParcel data;
1584     MessageParcel reply;
1585     int32_t ret = DistributedSchedService::GetInstance().DisconnectAbilityFromRemoteAdapter(data, reply);
1586     EXPECT_EQ(ret, NOT_FIND_SERVICE_REGISTRY);
1587     DTEST_LOG << "DistributedSchedServiceSecondTest DisconnectAbilityFromRemoteAdapter_001 end" << std::endl;
1588 }
1589 
1590 /**
1591  * @tc.name: NotifyAbilityLifecycleChangedFromRemoteAdapter_001
1592  * @tc.desc: NotifyAbilityLifecycleChangedFromRemoteAdapter
1593  * @tc.type: FUNC
1594  */
1595 HWTEST_F(DistributedSchedServiceSecondTest, NotifyAbilityLifecycleChangedFromRemoteAdapter_001, TestSize.Level3)
1596 {
1597     DTEST_LOG << "DistributedSchedServiceSecondTest NotifyAbilityLifecycleChangedFromRemoteAdapter_001 start" <<
1598         std::endl;
1599     MessageParcel data;
1600     MessageParcel reply;
1601     int32_t ret = DistributedSchedService::GetInstance().NotifyAbilityLifecycleChangedFromRemoteAdapter(data, reply);
1602     EXPECT_EQ(ret, NOT_FIND_SERVICE_REGISTRY);
1603     DTEST_LOG << "DistributedSchedServiceSecondTest NotifyAbilityLifecycleChangedFromRemoteAdapter_001 end" <<
1604         std::endl;
1605 }
1606 
1607 /**
1608  * @tc.name  : OnDeviceOnlineEx_Test_001
1609  * @tc.desc  : Test when dllHandle_ is nullptr then OnDeviceOnlineEx returns
1610  * @tc.type: FUNC
1611  */
1612 HWTEST_F(DistributedSchedServiceSecondTest, OnDeviceOnlineEx_Test_001, TestSize.Level1)
1613 {
1614     DTEST_LOG << "DistributedSchedServiceSecondTest OnDeviceOnlineEx_Test_001 start" << std::endl;
1615     OHOS::DistributedSchedule::DistributedSchedService service;
1616     OHOS::DistributedHardware::DmDeviceInfo deviceInfo;
1617     service.dllHandle_ = nullptr;
1618     service.OnDeviceOnlineEx(deviceInfo);
1619     ASSERT_EQ(service.dllHandle_, nullptr);
1620     DTEST_LOG << "DistributedSchedServiceSecondTest OnDeviceOnlineEx_Test_001 end" << std::endl;
1621 }
1622 
1623 /**
1624  * @tc.name  : OnDeviceOnlineEx_Test_002
1625  * @tc.desc  : Test when dmsAdapetr_.OnDeviceOnlineEx is nullptr then OnDeviceOnlineEx returns
1626  * @tc.type: FUNC
1627  */
1628 HWTEST_F(DistributedSchedServiceSecondTest, OnDeviceOnlineEx_Test_002, TestSize.Level1)
1629 {
1630     DTEST_LOG << "DistributedSchedServiceSecondTest OnDeviceOnlineEx_Test_002 start" << std::endl;
1631     OHOS::DistributedSchedule::DistributedSchedService service;
1632     OHOS::DistributedHardware::DmDeviceInfo deviceInfo;
1633     service.dmsAdapetr_.OnDeviceOnlineEx = nullptr;
1634     service.OnDeviceOnlineEx(deviceInfo);
1635     ASSERT_EQ(service.dmsAdapetr_.OnDeviceOnlineEx, nullptr);
1636     DTEST_LOG << "DistributedSchedServiceSecondTest OnDeviceOnlineEx_Test_002 end" << std::endl;
1637 }
1638 
1639 /**
1640  * @tc.name  : OnDeviceOfflineEx_Test_001
1641  * @tc.desc  : Test when dllHandle_ is nullptr then OnDeviceOfflineEx returns
1642  * @tc.type: FUNC
1643  */
1644 HWTEST_F(DistributedSchedServiceSecondTest, OnDeviceOfflineEx_Test_001, TestSize.Level1)
1645 {
1646     DTEST_LOG << "DistributedSchedServiceSecondTest OnDeviceOfflineEx_Test_001 start" << std::endl;
1647     OHOS::DistributedSchedule::DistributedSchedService service;
1648     OHOS::DistributedHardware::DmDeviceInfo deviceInfo;
1649     service.dllHandle_ = nullptr;
1650     service.OnDeviceOfflineEx(deviceInfo);
1651     ASSERT_EQ(service.dllHandle_, nullptr);
1652     DTEST_LOG << "DistributedSchedServiceSecondTest OnDeviceOfflineEx_Test_001 end" << std::endl;
1653 }
1654 
1655 /**
1656  * @tc.name  : OnDeviceOfflineEx_Test_002
1657  * @tc.desc  : Test when dmsAdapetr_.OnDeviceOfflineEx is nullptr then OnDeviceOfflineEx returns
1658  * @tc.type: FUNC
1659  */
1660 HWTEST_F(DistributedSchedServiceSecondTest, OnDeviceOfflineEx_Test_002, TestSize.Level1)
1661 {
1662     DTEST_LOG << "DistributedSchedServiceSecondTest OnDeviceOfflineEx_Test_002 start" << std::endl;
1663     OHOS::DistributedSchedule::DistributedSchedService service;
1664     OHOS::DistributedHardware::DmDeviceInfo deviceInfo;
1665     service.dmsAdapetr_.OnDeviceOfflineEx = nullptr;
1666     service.OnDeviceOfflineEx(deviceInfo);
1667     ASSERT_EQ(service.dmsAdapetr_.OnDeviceOfflineEx, nullptr);
1668     DTEST_LOG << "DistributedSchedServiceSecondTest OnDeviceOfflineEx_Test_002 end" << std::endl;
1669 }
1670 
1671 /**
1672  * @tc.name  : OnDeviceInfoChangedEx_Test_001
1673  * @tc.desc  : Test when dllHandle_ is nullptr then OnDeviceInfoChangedEx returns
1674  * @tc.type: FUNC
1675  */
1676 HWTEST_F(DistributedSchedServiceSecondTest, OnDeviceInfoChangedEx_Test_001, TestSize.Level1)
1677 {
1678     DTEST_LOG << "DistributedSchedServiceSecondTest OnDeviceInfoChangedEx_Test_001 start" << std::endl;
1679     OHOS::DistributedSchedule::DistributedSchedService service;
1680     OHOS::DistributedHardware::DmDeviceInfo deviceInfo;
1681     service.dllHandle_ = nullptr;
1682     service.OnDeviceInfoChangedEx(deviceInfo);
1683     ASSERT_EQ(service.dllHandle_, nullptr);
1684     DTEST_LOG << "DistributedSchedServiceSecondTest OnDeviceInfoChangedEx_Test_001 end" << std::endl;
1685 }
1686 
1687 /**
1688  * @tc.name  : OnDeviceInfoChangedEx_Test_002
1689  * @tc.desc  : Test when dmsAdapetr_.OnDeviceInfoChangedEx is nullptr then OnDeviceInfoChangedEx returns
1690  * @tc.type: FUNC
1691  */
1692 HWTEST_F(DistributedSchedServiceSecondTest, OnDeviceInfoChangedEx_Test_002, TestSize.Level1)
1693 {
1694     DTEST_LOG << "DistributedSchedServiceSecondTest OnDeviceInfoChangedEx_Test_002 start" << std::endl;
1695     OHOS::DistributedSchedule::DistributedSchedService service;
1696     OHOS::DistributedHardware::DmDeviceInfo deviceInfo;
1697     service.dmsAdapetr_.OnDeviceInfoChangedEx = nullptr;
1698     service.OnDeviceInfoChangedEx(deviceInfo);
1699     ASSERT_EQ(service.dmsAdapetr_.OnDeviceInfoChangedEx, nullptr);
1700     DTEST_LOG << "DistributedSchedServiceSecondTest OnDeviceInfoChangedEx_Test_002 end" << std::endl;
1701 }
1702 #endif // DMSFWK_INTERACTIVE_ADAPTER
1703 
1704 /**
1705  * @tc.name: NotifyDSchedEventResultFromRemote_001
1706  * @tc.desc: NotifyDSchedEventResultFromRemote
1707  * @tc.type: FUNC
1708  */
1709 HWTEST_F(DistributedSchedServiceSecondTest, NotifyDSchedEventResultFromRemote_001, TestSize.Level3)
1710 {
1711     DTEST_LOG << "DistributedSchedServiceSecondTest NotifyDSchedEventResultFromRemote_001 start" << std::endl;
1712     std::string type;
1713     int32_t dSchedEventResult = 0;
1714     int32_t ret = DistributedSchedService::GetInstance().NotifyDSchedEventResultFromRemote(type, dSchedEventResult);
1715     EXPECT_EQ(ret, ERR_OK);
1716     DTEST_LOG << "DistributedSchedServiceSecondTest NotifyDSchedEventResultFromRemote_001 end" << std::endl;
1717 }
1718 
1719 /**
1720  * @tc.name: ContinueLocalMission_001
1721  * @tc.desc: ContinueLocalMission
1722  * @tc.type: FUNC
1723  */
1724 HWTEST_F(DistributedSchedServiceSecondTest, ContinueLocalMission_001, TestSize.Level3)
1725 {
1726     DTEST_LOG << "DistributedSchedServiceSecondTest ContinueLocalMission_001 start" << std::endl;
1727     std::string dstDeviceId;
1728     int32_t missionId = 0;
1729     OHOS::AAFwk::WantParams wantParams;
1730     DistributedSchedService::GetInstance().dschedContinuation_ = nullptr;
1731     int32_t ret = DistributedSchedService::GetInstance().ContinueLocalMission(
1732         dstDeviceId, missionId, nullptr, wantParams);
1733     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
1734 
1735     ret = DistributedSchedService::GetInstance().ContinueAbilityWithTimeout(
1736         dstDeviceId, missionId, nullptr, 0);
1737     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
1738 
1739     DistributedSchedService::GetInstance().NotifyDSchedEventCallbackResult(FOREGROUND);
1740 
1741     ret = DistributedSchedService::GetInstance().NotifyContinuationResultFromRemote(
1742         FOREGROUND, true, dstDeviceId);
1743     EXPECT_EQ(ret, ERR_OK);
1744     DTEST_LOG << "DistributedSchedServiceSecondTest ContinueLocalMission_001 end" << std::endl;
1745 }
1746 
1747 /**
1748  * @tc.name: GetContinueInfo_001
1749  * @tc.desc: GetContinueInfo
1750  * @tc.type: FUNC
1751  */
1752 HWTEST_F(DistributedSchedServiceSecondTest, GetContinueInfo_001, TestSize.Level3)
1753 {
1754     DTEST_LOG << "DistributedSchedServiceSecondTest GetContinueInfo_001 start" << std::endl;
1755     std::string dstNetworkId;
1756     std::string srcNetworkId;
1757     DistributedSchedService::GetInstance().dschedContinuation_ = nullptr;
1758     int32_t ret = DistributedSchedService::GetInstance().GetContinueInfo(dstNetworkId, srcNetworkId);
1759     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
1760 
1761     DistributedSchedService::GetInstance().dschedContinuation_ = std::make_shared<DSchedContinuation>();
1762     ret = DistributedSchedService::GetInstance().GetContinueInfo(dstNetworkId, srcNetworkId);
1763     EXPECT_EQ(ret, ERR_OK);
1764     DTEST_LOG << "DistributedSchedServiceSecondTest GetContinueInfo_001 end" << std::endl;
1765 }
1766 
1767 /**
1768  * @tc.name: GetDSchedEventInfo_001
1769  * @tc.desc: GetDSchedEventInfo
1770  * @tc.type: FUNC
1771  */
1772 HWTEST_F(DistributedSchedServiceSecondTest, GetDSchedEventInfo_001, TestSize.Level3)
1773 {
1774     DTEST_LOG << "DistributedSchedServiceSecondTest GetDSchedEventInfo_001 start" << std::endl;
1775     std::vector<EventNotify> events;
1776     int32_t ret = DistributedSchedService::GetInstance().GetDSchedEventInfo(DMS_CONTINUE, events);
1777     EXPECT_EQ(ret, ERR_OK);
1778 
1779     ret = DistributedSchedService::GetInstance().GetDSchedEventInfo(DMS_ALL, events);
1780     EXPECT_EQ(ret, ERR_OK);
1781     DTEST_LOG << "DistributedSchedServiceSecondTest GetDSchedEventInfo_001 end" << std::endl;
1782 }
1783 
1784 /**
1785  * @tc.name: RegisterDSchedEventListener_001
1786  * @tc.desc: RegisterDSchedEventListener
1787  * @tc.type: FUNC
1788  */
1789 HWTEST_F(DistributedSchedServiceSecondTest, RegisterDSchedEventListener_001, TestSize.Level3)
1790 {
1791     DTEST_LOG << "DistributedSchedServiceSecondTest RegisterDSchedEventListener_001 start" << std::endl;
1792     DistributedSchedService::GetInstance().dschedContinuation_ = nullptr;
1793     DistributedSchedService::GetInstance().collaborateCbMgr_  = nullptr;
1794     int32_t ret = DistributedSchedService::GetInstance().RegisterDSchedEventListener(DMS_CONTINUE, nullptr);
1795     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
1796 
1797     ret = DistributedSchedService::GetInstance().UnRegisterDSchedEventListener(DMS_CONTINUE, nullptr);
1798     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
1799 
1800     DistributedSchedService::GetInstance().dschedContinuation_ = std::make_shared<DSchedContinuation>();
1801     ret = DistributedSchedService::GetInstance().RegisterDSchedEventListener(DMS_CONTINUE, nullptr);
1802     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
1803 
1804     ret = DistributedSchedService::GetInstance().UnRegisterDSchedEventListener(DMS_CONTINUE, nullptr);
1805     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
1806 
1807     DistributedSchedService::GetInstance().collaborateCbMgr_ = std::make_shared<DSchedCollaborationCallbackMgr>();
1808     DistributedSchedService::GetInstance().collaborateCbMgr_->Init();
1809     auto callback = GetDSchedService();
1810     ret = DistributedSchedService::GetInstance().RegisterDSchedEventListener(DMS_COLLABORATION, callback);
1811     EXPECT_EQ(ret, ERR_OK);
1812 
1813     ret = DistributedSchedService::GetInstance().UnRegisterDSchedEventListener(DMS_COLLABORATION, callback);
1814     EXPECT_EQ(ret, ERR_OK);
1815     DTEST_LOG << "DistributedSchedServiceSecondTest RegisterDSchedEventListener_001 end" << std::endl;
1816 }
1817 
1818 /**
1819  * @tc.name: ContinueStateCallbackRegister_001
1820  * @tc.desc: ContinueStateCallbackRegister
1821  * @tc.type: FUNC
1822  */
1823 HWTEST_F(DistributedSchedServiceSecondTest, ContinueStateCallbackRegister_001, TestSize.Level3)
1824 {
1825     DTEST_LOG << "DistributedSchedServiceSecondTest ContinueStateCallbackRegister_001 start" << std::endl;
1826     int32_t missionId = 1;
1827     std::string bundleName = "bundleName";
1828     std::string moduleName = "moduleName";
1829     std::string abilityName = "abilityName";
1830     sptr<IRemoteObject> callback(new MockDistributedSched());
1831 
1832     int32_t ret = DistributedSchedService::GetInstance().ContinueStateCallbackRegister(
1833         missionId, bundleName, moduleName, abilityName, nullptr);
1834     EXPECT_EQ(ret, NO_CONNECT_CALLBACK_ERR);
1835 
1836     ret = DistributedSchedService::GetInstance().ContinueStateCallbackRegister(
1837         missionId, bundleName, moduleName, abilityName, callback);
1838     EXPECT_EQ(ret, ERR_OK);
1839 
1840     DTEST_LOG << "DistributedSchedServiceSecondTest ContinueStateCallbackRegister_001 end" << std::endl;
1841 }
1842 
1843 /**
1844  * @tc.name: ContinueStateCallbackUnRegister_001
1845  * @tc.desc: ContinueStateCallbackUnRegister
1846  * @tc.type: FUNC
1847  */
1848 HWTEST_F(DistributedSchedServiceSecondTest, ContinueStateCallbackUnRegister_001, TestSize.Level3)
1849 {
1850     DTEST_LOG << "DistributedSchedServiceSecondTest ContinueStateCallbackUnRegister_001 start" << std::endl;
1851     int32_t missionId = 1;
1852     std::string bundleName = "bundleName";
1853     std::string moduleName = "moduleName";
1854     std::string abilityName = "abilityName";
1855     int32_t ret = DistributedSchedService::GetInstance().ContinueStateCallbackUnRegister(
1856         missionId, bundleName, moduleName, abilityName);
1857 
1858     EXPECT_EQ(ret, ERR_OK);
1859     DTEST_LOG << "DistributedSchedServiceSecondTest ContinueStateCallbackUnRegister_001 end" << std::endl;
1860 }
1861 
1862 /**
1863  * @tc.name  : SetCleanMissionFlag_Test_001
1864  * @tc.desc  : Test when dschedContinuation_ is nullptr then SetCleanMissionFlag returns
1865  * @tc.type: FUNC
1866  */
1867 HWTEST_F(DistributedSchedServiceSecondTest, SetCleanMissionFlag_Test_001, TestSize.Level1)
1868 {
1869     DTEST_LOG << "DistributedSchedServiceSecondTest SetCleanMissionFlag_Test_001 start" << std::endl;
1870     OHOS::AAFwk::Want want;
1871     int32_t missionId = 1;
1872     DistributedSchedService::GetInstance().dschedContinuation_ = nullptr;
1873     DistributedSchedService::GetInstance().SetCleanMissionFlag(want, missionId);
1874     ASSERT_EQ(DistributedSchedService::GetInstance().dschedContinuation_, nullptr);
1875     DTEST_LOG << "DistributedSchedServiceSecondTest SetCleanMissionFlag_Test_001 end" << std::endl;
1876 }
1877 
1878 /**
1879  * @tc.name  : SetCleanMissionFlag_Test_002
1880  * @tc.desc  : Test when dschedContinuation_ is not nullptr then SetCleanMissionFlag sets the flag
1881  * @tc.type: FUNC
1882  */
1883 HWTEST_F(DistributedSchedServiceSecondTest, SetCleanMissionFlag_Test_002, TestSize.Level1)
1884 {
1885     DTEST_LOG << "DistributedSchedServiceSecondTest SetCleanMissionFlag_Test_002 start" << std::endl;
1886     if (DistributedSchedService::GetInstance().dschedContinuation_ == nullptr) {
1887         DistributedSchedService::GetInstance().dschedContinuation_ = std::make_shared<DSchedContinuation>();
1888     }
1889     OHOS::AAFwk::Want want;
1890     int32_t missionId = 1;
1891     DistributedSchedService::GetInstance().SetCleanMissionFlag(want, missionId);
1892     ASSERT_NE(DistributedSchedService::GetInstance().dschedContinuation_, nullptr);
1893     DTEST_LOG << "DistributedSchedServiceSecondTest SetCleanMissionFlag_Test_002 end" << std::endl;
1894 }
1895 
1896 /**
1897  * @tc.name  : CheckCollabStartPermission_Test001
1898  * @tc.number: CheckCollabStartPermission_001
1899  * @tc.desc  : Test CheckCollabStartPermission function when GetTargetAbility return false.
1900  */
1901 HWTEST_F(DistributedSchedServiceSecondTest, CheckCollabStartPermission_Test001, TestSize.Level1)
1902 {
1903     OHOS::AAFwk::Want want;
1904     CallerInfo callerInfo;
1905     IDistributedSched::AccountInfo accountInfo;
1906     bool needQueryExtension = false;
1907     int32_t ret = DistributedSchedService::GetInstance().CheckCollabStartPermission(want,
1908         callerInfo, accountInfo, needQueryExtension);
1909     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
1910 }
1911 }
1912 }
1913