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