1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #include <thread>
16 
17 #define private public
18 #define protected public
19 #include "gtest/gtest.h"
20 
21 #include "ability_connection_wrapper_stub.h"
22 #include "bundle/bundle_manager_internal.h"
23 #include "device_manager.h"
24 #include "distributed_sched_permission.h"
25 #include "distributed_sched_proxy.h"
26 #include "distributed_sched_service.h"
27 #include "distributed_sched_test_util.h"
28 #include "distributed_sched_utils.h"
29 #include "dtbschedmgr_device_info_storage.h"
30 #include "dtbschedmgr_log.h"
31 #include "form_mgr_errors.h"
32 #include "if_system_ability_manager.h"
33 #include "ipc_skeleton.h"
34 #include "iservice_registry.h"
35 #include "mock_form_mgr_service.h"
36 #include "mock_distributed_sched.h"
37 #include "system_ability_definition.h"
38 #include "test_log.h"
39 #include "thread_pool.h"
40 #undef private
41 #undef protected
42 
43 using namespace std;
44 using namespace testing;
45 using namespace testing::ext;
46 using namespace OHOS;
47 
48 namespace OHOS {
49 namespace DistributedSchedule {
50 using namespace AAFwk;
51 using namespace AppExecFwk;
52 using namespace DistributedHardware;
53 namespace {
54     const string LOCAL_DEVICEID = "192.168.43.100";
55     const string REMOTE_DEVICEID = "255.255.255.255";
56     const std::string DMS_MISSION_ID = "dmsMissionId";
57     const std::string DMS_CONNECT_TOKEN = "connectToken";
58     constexpr int32_t MISSION_ID = 1;
59     const std::string DMS_SRC_NETWORK_ID = "dmsSrcNetworkId";
60     const int DEFAULT_REQUEST_CODE = -1;
61     const string ABILITY_NAME = "com.ohos.permissionmanager.MainAbility";
62     const string BUNDLE_NAME = "com.ohos.permissionmanager";
63     const string DMS_IS_CALLER_BACKGROUND = "dmsIsCallerBackGround";
64     constexpr int32_t FOREGROUND = 2;
65     constexpr int32_t MAX_TOKEN_NUM = 100000000;
66     constexpr int32_t SLEEP_TIME = 1000;
67 }
68 
69 class DistributedSchedServiceSecondTest : public testing::Test {
70 public:
71     static void SetUpTestCase();
72     static void TearDownTestCase();
73     void SetUp();
74     void TearDown();
75     sptr<IDistributedSched> GetDms();
76     int32_t InstallBundle(const std::string &bundlePath) const;
77     sptr<IDistributedSched> proxy_;
78 
79 protected:
80     enum class LoopTime : int32_t {
81         LOOP_TIME = 10,
82         LOOP_PRESSURE_TIME = 100,
83     };
84     sptr<IRemoteObject> GetDSchedService() const;
85     void GetAbilityInfo(const std::string& package, const std::string& name,
86         const std::string& bundleName, const std::string& deviceId,
87         OHOS::AppExecFwk::AbilityInfo& abilityInfo);
88 
89     class DeviceInitCallBack : public DmInitCallback {
90         void OnRemoteDied() override;
91     };
92 };
93 
SetUpTestCase()94 void DistributedSchedServiceSecondTest::SetUpTestCase()
95 {
96     if (!DistributedSchedUtil::LoadDistributedSchedService()) {
97         DTEST_LOG << "DistributedSchedServiceSecondTest::SetUpTestCase LoadDistributedSchedService failed" << std::endl;
98     }
99     const std::string pkgName = "DBinderBus_" + std::to_string(getprocpid());
100     std::shared_ptr<DmInitCallback> initCallback_ = std::make_shared<DeviceInitCallBack>();
101     DeviceManager::GetInstance().InitDeviceManager(pkgName, initCallback_);
102     std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIME));
103 }
104 
TearDownTestCase()105 void DistributedSchedServiceSecondTest::TearDownTestCase()
106 {}
107 
SetUp()108 void DistributedSchedServiceSecondTest::SetUp()
109 {
110     DistributedSchedUtil::MockPermission();
111 }
112 
TearDown()113 void DistributedSchedServiceSecondTest::TearDown()
114 {}
115 
OnRemoteDied()116 void DistributedSchedServiceSecondTest::DeviceInitCallBack::OnRemoteDied()
117 {}
118 
GetDms()119 sptr<IDistributedSched> DistributedSchedServiceSecondTest::GetDms()
120 {
121     if (proxy_ != nullptr) {
122         return proxy_;
123     }
124     auto sm = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
125     EXPECT_TRUE(sm != nullptr);
126     if (sm == nullptr) {
127         DTEST_LOG << "DistributedSchedServiceSecondTest sm is nullptr" << std::endl;
128         return nullptr;
129     }
130     DTEST_LOG << "DistributedSchedServiceSecondTest sm is not nullptr" << std::endl;
131     auto distributedObject = sm->GetSystemAbility(DISTRIBUTED_SCHED_SA_ID);
132     proxy_ = iface_cast<IDistributedSched>(distributedObject);
133     if (proxy_ == nullptr) {
134         DTEST_LOG << "DistributedSchedServiceSecondTest DistributedSched is nullptr" << std::endl;
135     } else {
136         DTEST_LOG << "DistributedSchedServiceSecondTest DistributedSched is not nullptr" << std::endl;
137     }
138     return proxy_;
139 }
140 
GetDSchedService() const141 sptr<IRemoteObject> DistributedSchedServiceSecondTest::GetDSchedService() const
142 {
143     sptr<IRemoteObject> dsched(new MockDistributedSched());
144     return dsched;
145 }
146 
GetAbilityInfo(const std::string & package,const std::string & name,const std::string & bundleName,const std::string & deviceId,OHOS::AppExecFwk::AbilityInfo & abilityInfo)147 void DistributedSchedServiceSecondTest::GetAbilityInfo(const std::string& package, const std::string& name,
148     const std::string& bundleName, const std::string& deviceId, OHOS::AppExecFwk::AbilityInfo& abilityInfo)
149 {
150     abilityInfo.bundleName = bundleName;
151     abilityInfo.deviceId = deviceId;
152 }
153 
154 /**
155  * @tc.name: StartRemoteShareForm_001
156  * @tc.desc: call StartRemoteShareForm with dms
157  * @tc.type: StartRemoteShareForm
158  * @tc.require: issueI5M62D
159  */
160 HWTEST_F(DistributedSchedServiceSecondTest, StartRemoteShareForm_001, TestSize.Level1)
161 {
162     DTEST_LOG << "DistributedSchedServiceSecondTest StartRemoteShareForm_001 start" << std::endl;
163     sptr<IDistributedSched> proxy = GetDms();
164     const std::string remoteDeviceId = "";
165     const OHOS::AppExecFwk::FormShareInfo formShareInfo {};
166     auto result = proxy->StartRemoteShareForm(remoteDeviceId, formShareInfo);
167     DTEST_LOG << "result:" << result << std::endl;
168     EXPECT_EQ(static_cast<int>(INVALID_PARAMETERS_ERR), result);
169     DTEST_LOG << "DistributedSchedServiceSecondTest StartRemoteShareForm_001 end" << std::endl;
170 }
171 
172 /**
173  * @tc.name: StartRemoteShareForm_002
174  * @tc.desc: call StartAbilityFromRemote with dms
175  * @tc.type: StartRemoteShareForm
176  * @tc.require: issueI5M62D
177  */
178 HWTEST_F(DistributedSchedServiceSecondTest, StartRemoteShareForm_002, TestSize.Level1)
179 {
180     DTEST_LOG << "DistributedSchedServiceSecondTest StartRemoteShareForm_002 start" << std::endl;
181     sptr<IDistributedSched> proxy = GetDms();
182     const std::string remoteDeviceId = "123456";
183     const OHOS::AppExecFwk::FormShareInfo formShareInfo {};
184     auto result = proxy->StartRemoteShareForm(remoteDeviceId, formShareInfo);
185     DTEST_LOG << "result:" << result << std::endl;
186     EXPECT_EQ(static_cast<int>(DMS_PERMISSION_DENIED), result);
187     DTEST_LOG << "DistributedSchedServiceSecondTest StartRemoteShareForm_002 end" << std::endl;
188 }
189 
190 /**
191  * @tc.name: StartRemoteShareForm_003
192  * @tc.desc: call StartRemoteShareForm with dms
193  * @tc.type: StartRemoteShareForm
194  * @tc.require: issueI5M62D
195  */
196 HWTEST_F(DistributedSchedServiceSecondTest, StartRemoteShareForm_003, TestSize.Level1)
197 {
198     DTEST_LOG << "DistributedSchedServiceSecondTest StartRemoteShareForm_003 start" << std::endl;
199     sptr<IDistributedSched> proxy = GetDms();
200     const OHOS::AppExecFwk::FormShareInfo formShareInfo {};
201     auto result = proxy->StartRemoteShareForm(REMOTE_DEVICEID, formShareInfo);
202     DTEST_LOG << "result:" << result << std::endl;
203     EXPECT_NE(ERR_OK, result);
204     DTEST_LOG << "DistributedSchedServiceSecondTest StartRemoteShareForm_003 end" << std::endl;
205 }
206 
207 /**
208  * @tc.name: StartShareFormFromRemote_001
209  * @tc.desc: call StartAbilityFromRemote with dms
210  * @tc.type: StartShareFormFromRemote
211  * @tc.require: issueI5M62D
212  */
213 HWTEST_F(DistributedSchedServiceSecondTest, StartShareFormFromRemote_001, TestSize.Level1)
214 {
215     DTEST_LOG << "DistributedSchedServiceSecondTest StartShareFormFromRemote_001 start" << std::endl;
216     std::string remoteDeviceId = "";
217     DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(remoteDeviceId);
218     const OHOS::AppExecFwk::FormShareInfo formShareInfo {};
219     DistributedSchedService::GetInstance().formMgrProxy_ = new MockFormMgrService();
220     auto result = DistributedSchedService::GetInstance().StartShareFormFromRemote(remoteDeviceId, formShareInfo);
221     DTEST_LOG << "result:" << result << std::endl;
222     EXPECT_EQ(static_cast<int>(ERR_OK), result);
223 
224     DTEST_LOG << "DistributedSchedServiceSecondTest StartShareFormFromRemote_001 end" << std::endl;
225 }
226 
227 /**
228  * @tc.name: StartShareFormFromRemote_002
229  * @tc.desc: call StartAbilityFromRemote with dms
230  * @tc.type: StartShareFormFromRemote
231  * @tc.require: issueI5M62D
232  */
233 HWTEST_F(DistributedSchedServiceSecondTest, StartShareFormFromRemote_002, TestSize.Level1)
234 {
235     DTEST_LOG << "DistributedSchedServiceSecondTest StartShareFormFromRemote_002 start" << std::endl;
236     std::string remoteDeviceId = "123456";
237     const OHOS::AppExecFwk::FormShareInfo formShareInfo {};
238     /**
239      * @tc.steps: step1. call GetContinuaitonDevice
240      */
241     DTEST_LOG << "DistributedSchedServiceSecondTest GetContinuaitonDevice_001 start" << std::endl;
242     if (DistributedSchedService::GetInstance().dschedContinuation_ == nullptr) {
243         DistributedSchedService::GetInstance().dschedContinuation_ = std::make_shared<DSchedContinuation>();
244     }
245     int32_t missionId = MISSION_ID;
246     (void)DistributedSchedService::GetInstance().GetContinuaitonDevice(missionId);
247     DTEST_LOG << "DistributedSchedServiceSecondTest GetContinuaitonDevice_001 end" << std::endl;
248 
249     auto result = DistributedSchedService::GetInstance().StartShareFormFromRemote(remoteDeviceId, formShareInfo);
250     DTEST_LOG << "result:" << result << std::endl;
251     EXPECT_EQ(static_cast<int>(INVALID_REMOTE_PARAMETERS_ERR), result);
252     DTEST_LOG << "DistributedSchedServiceSecondTest StartShareFormFromRemote_002 end" << std::endl;
253 }
254 
255 /**
256  * @tc.name: ProcessCalleeDied_001
257  * @tc.desc: call ProcessCalleeDied
258  * @tc.type: FUNC
259  * @tc.require: I6YLV1
260  */
261 HWTEST_F(DistributedSchedServiceSecondTest, ProcessCalleeDied_001, TestSize.Level1)
262 {
263     DTEST_LOG << "DistributedSchedServiceSecondTest ProcessCalleeDied_001 start" << std::endl;
264     std::string localDeviceId;
265     DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
266     sptr<IRemoteObject> connect(new MockDistributedSched());
267     DistributedSchedService::GetInstance().ProcessCalleeDied(connect);
268     DistributedSchedService::GetInstance().calleeMap_.clear();
269     EXPECT_TRUE(DistributedSchedService::GetInstance().calleeMap_.empty());
270     DTEST_LOG << "DistributedSchedServiceSecondTest ProcessCalleeDied_001 end" << std::endl;
271 }
272 
273 /**
274  * @tc.name: StartRemoteFreeInstall_001
275  * @tc.desc: call StartRemoteFreeInstall
276  * @tc.type: FUNC
277  * @tc.require: I76THI
278  */
279 HWTEST_F(DistributedSchedServiceSecondTest, StartRemoteFreeInstall_001, TestSize.Level3)
280 {
281     DTEST_LOG << "DistributedSchedServiceSecondTest StartRemoteFreeInstall_001 start" << std::endl;
282     AAFwk::Want want;
283     AppExecFwk::ElementName element("devicdId", "com.ohos.distributedmusicplayer",
284         "com.ohos.distributedmusicplayer.MainAbility");
285     want.SetElement(element);
286     auto callback = GetDSchedService();
287     int32_t result = DistributedSchedService::GetInstance().StartRemoteFreeInstall(want, 0, 0, 0, callback);
288     EXPECT_EQ(result, INVALID_PARAMETERS_ERR);
289     DTEST_LOG << "DistributedSchedServiceSecondTest StartRemoteFreeInstall_001 end" << std::endl;
290 }
291 
292 /**
293  * @tc.name: NotifyCompleteFreeInstall_001
294  * @tc.desc: call NotifyCompleteFreeInstall
295  * @tc.type: FUNC
296  * @tc.require: I76THI
297  */
298 HWTEST_F(DistributedSchedServiceSecondTest, NotifyCompleteFreeInstall_001, TestSize.Level3)
299 {
300     DTEST_LOG << "DistributedSchedServiceSecondTest NotifyCompleteFreeInstall_001 start" << std::endl;
301 
302     sptr<IDistributedSched> proxy = GetDms();
303     if (proxy == nullptr) {
304         return;
305     }
306 
307     AAFwk::Want want;
308     AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
309         "com.ohos.distributedmusicplayer.MainAbility");
310     want.SetElement(element);
311     AppExecFwk::AbilityInfo abilityInfo;
312     GetAbilityInfo("com.ohos.distributedmusicplayer", "com.ohos.distributedmusicplayer.MainAbility",
313         "com.ohos.distributedmusicplayer", "192.168.43.100", abilityInfo);
314     CallerInfo callerInfo;
315     callerInfo.uid = 0;
316     callerInfo.sourceDeviceId = "255.255.255.255";
317     IDistributedSched::AccountInfo accountInfo;
318 
319     int result1 = proxy->StartAbilityFromRemote(want, abilityInfo, 0, callerInfo, accountInfo);
320     DTEST_LOG << "result1 is" << result1 << std::endl;
321 
322     AppExecFwk::ElementName element2("", "com.ohos.distributedmusicplayer",
323         "com.ohos.distributedmusicplayer.MainAbilityService");
324     want.SetElement(element2);
325     GetAbilityInfo("com.ohos.distributedmusicplayer", "com.ohos.distributedmusicplayer.MainAbilityService",
326         "com.ohos.distributedmusicplayer", "192.168.43.100", abilityInfo);
327     int result2 = proxy->StartAbilityFromRemote(want, abilityInfo, 0, callerInfo, accountInfo);
328     DTEST_LOG << "result2:" << result2 << std::endl;
329 
330     /**
331     * @tc.steps: step1. call NotifyCompleteFreeInstall when resultCode is not ERR_OK.
332     */
333     IDistributedSched::FreeInstallInfo info;
334     int32_t result = DistributedSchedService::GetInstance().NotifyCompleteFreeInstall(info, 1, -1);
335     EXPECT_NE(result, ERR_OK);
336     /**
337     * @tc.steps: step2. call ProcessCallResult.
338     */
339     sptr<IRemoteObject> connect(new MockDistributedSched());
340     DistributedSchedService::GetInstance().ProcessCallResult(connect, connect);
341     DTEST_LOG << "DistributedSchedServiceSecondTest NotifyCompleteFreeInstall_001 end" << std::endl;
342 }
343 
344 /**
345  * @tc.name: NotifyStateChangedFromRemote_001
346  * @tc.desc: call NotifyStateChangedFromRemote with illegal params
347  * @tc.type: FUNC
348  * @tc.require: I6SJQ6
349  */
350 HWTEST_F(DistributedSchedServiceSecondTest, NotifyStateChangedFromRemote_001, TestSize.Level1)
351 {
352     DTEST_LOG << "DistributedSchedServiceSecondTest NotifyStateChangedFromRemote_001 start" << std::endl;
353     sptr<IDistributedSched> proxy = GetDms();
354     if (proxy == nullptr) {
355         return;
356     }
357     AppExecFwk::ElementName element("", BUNDLE_NAME, ABILITY_NAME);
358     int result1 = proxy->NotifyStateChangedFromRemote(0, 0, element);
359     DTEST_LOG << "result1:" << result1 << std::endl;
360 
361     EXPECT_NE(result1, ERR_OK);
362     DTEST_LOG << "DistributedSchedServiceSecondTest NotifyStateChangedFromRemote_001 end" << std::endl;
363 }
364 
365 /**
366  * @tc.name: NotifyStateChangedFromRemote_002
367  * @tc.desc: test NotifyStateChangedFromRemote
368  * @tc.type: FUNC
369  * @tc.require: I6SJQ6
370  */
371 HWTEST_F(DistributedSchedServiceSecondTest, NotifyStateChangedFromRemote_002, TestSize.Level3)
372 {
373     DTEST_LOG << "DistributedSchedServiceSecondTest NotifyStateChangedFromRemote_002 start" << std::endl;
374     std::string localDeviceId;
375     DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
376     AppExecFwk::ElementName element(localDeviceId, BUNDLE_NAME, ABILITY_NAME);
377 
378     int ret = DistributedSchedService::GetInstance().NotifyStateChangedFromRemote(0, 0, element);
379     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
380     DTEST_LOG << "DistributedSchedServiceSecondTest NotifyStateChangedFromRemote_002 end" << std::endl;
381 }
382 
383 /**
384  * @tc.name: NotifyStateChangedFromRemote_003
385  * @tc.desc: test NotifyStateChangedFromRemote
386  * @tc.type: FUNC
387  * @tc.require: I6SJQ6
388  */
389 HWTEST_F(DistributedSchedServiceSecondTest, NotifyStateChangedFromRemote_003, TestSize.Level3)
390 {
391     DTEST_LOG << "DistributedSchedServiceSecondTest NotifyStateChangedFromRemote_003 start" << std::endl;
392     std::string localDeviceId;
393     DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
394     AppExecFwk::ElementName element(localDeviceId, BUNDLE_NAME, ABILITY_NAME);
395 
396     sptr<IRemoteObject> connect = nullptr;
397     DistributedSchedService::GetInstance().callMap_[connect] = {1, localDeviceId};
398     int ret = DistributedSchedService::GetInstance().NotifyStateChangedFromRemote(0, 0, element);
399     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
400     DTEST_LOG << "DistributedSchedServiceSecondTest NotifyStateChangedFromRemote_003 end" << std::endl;
401 }
402 
403 /**
404  * @tc.name: NotifyStateChangedFromRemote_004
405  * @tc.desc: test NotifyStateChangedFromRemote
406  * @tc.type: FUNC
407  * @tc.require: I6VDBO
408  */
409 HWTEST_F(DistributedSchedServiceSecondTest, NotifyStateChangedFromRemote_004, TestSize.Level3)
410 {
411     DTEST_LOG << "DistributedSchedServiceSecondTest NotifyStateChangedFromRemote_004 start" << std::endl;
412     sptr<AppStateObserver> appStateObserver = sptr<AppStateObserver>(new (std::nothrow) AppStateObserver());
413     int32_t abilityState = FOREGROUND;
414     std::string localDeviceId;
415     DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
416     AppExecFwk::ElementName element(localDeviceId, BUNDLE_NAME, ABILITY_NAME);
417     int32_t ret = DistributedSchedService::GetInstance().NotifyStateChangedFromRemote(abilityState, 0, element);
418     DTEST_LOG << "ret:" << ret << std::endl;
419     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
420     DTEST_LOG << "DistributedSchedServiceSecondTest NotifyStateChangedFromRemote_004 end" << std::endl;
421 }
422 
423 /**
424  * @tc.name: NotifyStateChangedFromRemote_005
425  * @tc.desc: test NotifyStateChangedFromRemote
426  * @tc.type: FUNC
427  * @tc.require: I6VDBO
428  */
429 HWTEST_F(DistributedSchedServiceSecondTest, NotifyStateChangedFromRemote_005, TestSize.Level3)
430 {
431     DTEST_LOG << "DistributedSchedServiceSecondTest NotifyStateChangedFromRemote_005 start" << std::endl;
432     sptr<AppStateObserver> appStateObserver = sptr<AppStateObserver>(new (std::nothrow) AppStateObserver());
433     int32_t abilityState = FOREGROUND;
434     std::string localDeviceId;
435     DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
436     sptr<IRemoteObject> connect = nullptr;
437     DistributedSchedService::GetInstance().callMap_[connect] = {2, localDeviceId};
438     AppExecFwk::ElementName element(localDeviceId, BUNDLE_NAME, ABILITY_NAME);
439     int32_t ret = DistributedSchedService::GetInstance().NotifyStateChangedFromRemote(abilityState, 0, element);
440     DTEST_LOG << "ret:" << ret << std::endl;
441     DistributedSchedService::GetInstance().callMap_.clear();
442     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
443     DTEST_LOG << "DistributedSchedServiceSecondTest NotifyStateChangedFromRemote_005 end" << std::endl;
444 }
445 
446 /**
447  * @tc.name: NotifyStateChangedFromRemote_006
448  * @tc.desc: test NotifyStateChangedFromRemote
449  * @tc.type: FUNC
450  * @tc.require: I6VDBO
451  */
452 HWTEST_F(DistributedSchedServiceSecondTest, NotifyStateChangedFromRemote_006, TestSize.Level3)
453 {
454     DTEST_LOG << "DistributedSchedServiceSecondTest NotifyStateChangedFromRemote_006 start" << std::endl;
455     sptr<AppStateObserver> appStateObserver = sptr<AppStateObserver>(new (std::nothrow) AppStateObserver());
456     int32_t abilityState = FOREGROUND;
457     std::string localDeviceId;
458     DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
459     sptr<IRemoteObject> connect(new MockDistributedSched());
460     DistributedSchedService::GetInstance().callMap_[connect] = {3, localDeviceId};
461     AppExecFwk::ElementName element(localDeviceId, BUNDLE_NAME, ABILITY_NAME);
462     int32_t ret = DistributedSchedService::GetInstance().NotifyStateChangedFromRemote(abilityState, 3, element);
463     DTEST_LOG << "ret:" << ret << std::endl;
464     DistributedSchedService::GetInstance().callMap_.clear();
465     EXPECT_EQ(ret, ERR_OK);
466     DTEST_LOG << "DistributedSchedServiceSecondTest NotifyStateChangedFromRemote_006 end" << std::endl;
467 }
468 
469 /**
470  * @tc.name: NotifyStateChanged_001
471  * @tc.desc: test NotifyStateChanged
472  * @tc.type: FUNC
473  * @tc.require: I6SJQ6
474  */
475 HWTEST_F(DistributedSchedServiceSecondTest, NotifyStateChanged_001, TestSize.Level3)
476 {
477     DTEST_LOG << "DistributedSchedServiceSecondTest NotifyStateChanged_001 start" << std::endl;
478 
479     sptr<IDistributedSched> proxy = GetDms();
480 
481     AAFwk::Want want;
482     AppExecFwk::ElementName element("1.1.1.1", "com.ohos.distributedmusicplayer",
483         "com.ohos.distributedmusicplayer.MainAbility");
484     want.SetElement(element);
485     CallerInfo callerInfo;
486     callerInfo.uid = 0;
487     callerInfo.sourceDeviceId = "255.255.255.255";
488     IDistributedSched::AccountInfo accountInfo;
489     accountInfo.accountType = 1;
490     accountInfo.groupIdList.push_back("123456");
491     int missionId = 0;
492     want.SetParam(DMS_SRC_NETWORK_ID, callerInfo.sourceDeviceId);
493     want.SetParam(DMS_MISSION_ID, missionId);
494 
495     int result1 = DistributedSchedService::GetInstance().SendResultFromRemote(want, 0, callerInfo, accountInfo, 0);
496     DTEST_LOG << "result1:" << result1 << std::endl;
497 
498     AppExecFwk::ElementName element2("1.1.1.1", "com.ohos.distributedmusicplayer",
499         "com.ohos.distributedmusicplayer.MainAbilityService");
500     want.SetElement(element2);
501     int result2 = DistributedSchedService::GetInstance().SendResultFromRemote(want, 0, callerInfo, accountInfo, 0);
502     DTEST_LOG << "result2:" << result2 << std::endl;
503 
504     int32_t abilityState = FOREGROUND;
505     std::string localDeviceId;
506     AppExecFwk::ElementName element3(localDeviceId, BUNDLE_NAME, ABILITY_NAME);
507     int32_t ret = DistributedSchedService::GetInstance().NotifyStateChanged(abilityState, element3, nullptr);
508     DTEST_LOG << "ret:" << ret << std::endl;
509     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
510     DTEST_LOG << "DistributedSchedServiceSecondTest NotifyStateChanged_001 end" << std::endl;
511 }
512 
513 /**
514  * @tc.name: NotifyStateChanged_002
515  * @tc.desc: test NotifyStateChanged
516  * @tc.type: FUNC
517  * @tc.require: I6VDBO
518  */
519 HWTEST_F(DistributedSchedServiceSecondTest, NotifyStateChanged_002, TestSize.Level3)
520 {
521     DTEST_LOG << "DistributedSchedServiceSecondTest NotifyStateChanged_002 start" << std::endl;
522     sptr<AppStateObserver> appStateObserver = sptr<AppStateObserver>(new (std::nothrow) AppStateObserver());
523     int32_t abilityState = FOREGROUND;
524     std::string localDeviceId;
525     DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
526     sptr<IRemoteObject> connect(new MockDistributedSched());
527     DistributedSchedService::GetInstance().observerMap_[connect] = {appStateObserver, localDeviceId, 0, BUNDLE_NAME,
528         ABILITY_NAME};
529     AppExecFwk::ElementName element(localDeviceId, BUNDLE_NAME, ABILITY_NAME);
530     int32_t ret = DistributedSchedService::GetInstance().NotifyStateChanged(abilityState, element, nullptr);
531     DTEST_LOG << "ret:" << ret << std::endl;
532     DistributedSchedService::GetInstance().observerMap_.clear();
533     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
534     DTEST_LOG << "DistributedSchedServiceSecondTest NotifyStateChanged_002 end" << std::endl;
535 }
536 
537 /**
538  * @tc.name: NotifyStateChanged_003
539  * @tc.desc: test NotifyStateChanged
540  * @tc.type: FUNC
541  * @tc.require: I6VDBO
542  */
543 HWTEST_F(DistributedSchedServiceSecondTest, NotifyStateChanged_003, TestSize.Level3)
544 {
545     DTEST_LOG << "DistributedSchedServiceSecondTest NotifyStateChanged_003 start" << std::endl;
546     sptr<AppStateObserver> appStateObserver = sptr<AppStateObserver>(new (std::nothrow) AppStateObserver());
547     int32_t abilityState = FOREGROUND;
548     std::string localDeviceId;
549     DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
550     sptr<IRemoteObject> connect(new MockDistributedSched());
551     DistributedSchedService::GetInstance().observerMap_[connect] = {appStateObserver, REMOTE_DEVICEID, 0, BUNDLE_NAME,
552         ABILITY_NAME};
553     AppExecFwk::ElementName element(localDeviceId, BUNDLE_NAME, ABILITY_NAME);
554     int32_t ret = DistributedSchedService::GetInstance().NotifyStateChanged(abilityState, element, nullptr);
555     DTEST_LOG << "ret:" << ret << std::endl;
556     DistributedSchedService::GetInstance().observerMap_.clear();
557     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
558     DTEST_LOG << "DistributedSchedServiceSecondTest NotifyStateChanged_003 end" << std::endl;
559 }
560 
561 /**
562  * @tc.name: StopRemoteExtensionAbility_001
563  * @tc.desc: StopRemoteExtensionAbility with uninitialized params, return INVALID_PARAMETERS_ERR.
564  * @tc.type: FUNC
565  */
566 HWTEST_F(DistributedSchedServiceSecondTest, StopRemoteExtensionAbility_001, TestSize.Level3)
567 {
568     DTEST_LOG << "DistributedSchedServiceSecondTest StopRemoteExtensionAbility_001 start" << std::endl;
569     AAFwk::Want want;
570     int32_t callerUid = 0;
571     uint32_t accessToken = 0;
572     int32_t extensionType = 3;
573     std::string deviceId;
574     DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(deviceId);
575     AppExecFwk::ElementName element(deviceId, "com.ohos.distributedmusicplayer",
576         "com.ohos.distributedmusicplayer.MainAbility");
577     want.SetElement(element);
578     EXPECT_EQ(DistributedSchedService::GetInstance().StopRemoteExtensionAbility(want, callerUid, accessToken,
579         extensionType), INVALID_PARAMETERS_ERR);
580     DTEST_LOG << "DistributedSchedServiceSecondTest StopRemoteExtensionAbility_001 end" << std::endl;
581 }
582 
583 /**
584  * @tc.name: StopRemoteExtensionAbility_002
585  * @tc.desc: StopRemoteExtensionAbility with empty want's deviceId, return INVALID_PARAMETERS_ERR.
586  * @tc.type: FUNC
587  */
588 HWTEST_F(DistributedSchedServiceSecondTest, StopRemoteExtensionAbility_002, TestSize.Level3)
589 {
590     DTEST_LOG << "DistributedSchedServiceSecondTest StopRemoteExtensionAbility_002 start" << std::endl;
591     AAFwk::Want want;
592     int32_t callerUid = 0;
593     uint32_t accessToken = 0;
594     int32_t extensionType = 3;
595     AppExecFwk::ElementName element("abcdefg123456", "com.ohos.distributedmusicplayer",
596         "com.ohos.distributedmusicplayer.MainAbility");
597     want.SetElement(element);
598     EXPECT_EQ(DistributedSchedService::GetInstance().StopRemoteExtensionAbility(want, callerUid, accessToken,
599         extensionType), INVALID_PARAMETERS_ERR);
600     DTEST_LOG << "DistributedSchedServiceSecondTest StopRemoteExtensionAbility_002 end" << std::endl;
601 }
602 
603 /**
604  * @tc.name: StopRemoteExtensionAbility_003
605  * @tc.desc: call StopRemoteExtensionAbility
606  * @tc.type: FUNC
607  * @tc.require: I6YLV1
608  */
609 HWTEST_F(DistributedSchedServiceSecondTest, StopRemoteExtensionAbility_003, TestSize.Level3)
610 {
611     DTEST_LOG << "DistributedSchedServiceSecondTest StopRemoteExtensionAbility_003 start" << std::endl;
612     sptr<IDistributedSched> proxy = GetDms();
613     if (proxy == nullptr) {
614         return;
615     }
616     AAFwk::Want want;
617     std::string localDeviceId;
618     DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
619     AppExecFwk::ElementName element(localDeviceId, BUNDLE_NAME,
620         ABILITY_NAME);
621     want.SetElement(element);
622     int32_t extensionType = 3;
623     int result = proxy->StopRemoteExtensionAbility(want, 0, 0, extensionType);
624     EXPECT_EQ(result, DMS_PERMISSION_DENIED);
625     DTEST_LOG << "DistributedSchedServiceSecondTest StopRemoteExtensionAbility_003 end" << std::endl;
626 }
627 
628 /**
629  * @tc.name: StopExtensionAbilityFromRemote_001
630  * @tc.desc: StopExtensionAbilityFromRemote with uninitialized params, return INVALID_REMOTE_PARAMETERS_ERR.
631  * @tc.type: FUNC
632  */
633 HWTEST_F(DistributedSchedServiceSecondTest, StopExtensionAbilityFromRemote_001, TestSize.Level3)
634 {
635     DTEST_LOG << "DistributedSchedServiceSecondTest StopExtensionAbilityFromRemote_001 start" << std::endl;
636     sptr<IDistributedSched> proxy = GetDms();
637     if (proxy == nullptr) {
638         return;
639     }
640     AAFwk::Want remoteWant;
641     std::string deviceId;
642     DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(deviceId);
643     AppExecFwk::ElementName element(deviceId, "com.ohos.distributedmusicplayer",
644         "com.ohos.distributedmusicplayer.MainAbility");
645     remoteWant.SetElement(element);
646     CallerInfo callerInfo;
647     callerInfo.uid = 0;
648     callerInfo.sourceDeviceId = "255.255.255.255";
649     IDistributedSched::AccountInfo accountInfo;
650     int32_t extensionType = 3;
651     EXPECT_EQ(DistributedSchedService::GetInstance().StopExtensionAbilityFromRemote(remoteWant, callerInfo,
652         accountInfo, extensionType), INVALID_REMOTE_PARAMETERS_ERR);
653     DTEST_LOG << "DistributedSchedServiceSecondTest StopExtensionAbilityFromRemote_001 end" << std::endl;
654 }
655 
656 /**
657  * @tc.name: StopExtensionAbilityFromRemote_002
658  * @tc.desc: StopExtensionAbilityFromRemote with empty want's deviceId, return DMS_PERMISSION_DENIED.
659  * @tc.type: FUNC
660  */
661 HWTEST_F(DistributedSchedServiceSecondTest, StopExtensionAbilityFromRemote_002, TestSize.Level3)
662 {
663     DTEST_LOG << "DistributedSchedServiceSecondTest StopExtensionAbilityFromRemote_002 start" << std::endl;
664 
665     sptr<IDistributedSched> proxy = GetDms();
666     if (proxy == nullptr) {
667         return;
668     }
669     /**
670      * @tc.steps: step1. set want and abilityInfo
671      */
672     AAFwk::Want want;
673     AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
674         "com.ohos.distributedmusicplayer.MainAbility");
675     want.SetElement(element);
676     CallerInfo callerInfo;
677     callerInfo.uid = 0;
678     callerInfo.sourceDeviceId = "255.255.255.255";
679     IDistributedSched::AccountInfo accountInfo;
680     int missionId = 0;
681     want.SetParam(DMS_SRC_NETWORK_ID, callerInfo.sourceDeviceId);
682     want.SetParam(DMS_MISSION_ID, missionId);
683     /**
684      * @tc.steps: step2. SendResultFromRemote for pressure test
685      * @tc.expected: step2. SendResultFromRemote for result
686      */
687     for (int index = 0; index < static_cast<int32_t>(LoopTime::LOOP_TIME); index++) {
688         int result = proxy->SendResultFromRemote(want, 0, callerInfo, accountInfo, 0);
689         DTEST_LOG << "pressure" + to_string(index) + " result is " << result << std::endl;
690     }
691 
692     AAFwk::Want remoteWant;
693     AppExecFwk::ElementName element1("abcdefg123456", "com.ohos.distributedmusicplayer",
694         "com.ohos.distributedmusicplayer.MainAbility");
695     remoteWant.SetElement(element1);
696     CallerInfo callerInfo1;
697     callerInfo1.uid = 0;
698     callerInfo1.sourceDeviceId = "255.255.255.255";
699     IDistributedSched::AccountInfo accountInfo1;
700     int32_t extensionType = 3;
701     EXPECT_EQ(DistributedSchedService::GetInstance().StopExtensionAbilityFromRemote(remoteWant, callerInfo1,
702         accountInfo1, extensionType), INVALID_REMOTE_PARAMETERS_ERR);
703     DTEST_LOG << "DistributedSchedServiceSecondTest StopExtensionAbilityFromRemote_002 end" << std::endl;
704 }
705 
706 /**
707  * @tc.name: StopExtensionAbilityFromRemote_003
708  * @tc.desc: StopExtensionAbilityFromRemote with empty want's deviceId, return INVALID_REMOTE_PARAMETERS_ERR.
709  * @tc.type: FUNC
710  */
711 HWTEST_F(DistributedSchedServiceSecondTest, StopExtensionAbilityFromRemote_003, TestSize.Level3)
712 {
713     DTEST_LOG << "DistributedSchedServiceSecondTest StopExtensionAbilityFromRemote_003 start" << std::endl;
714     sptr<IDistributedSched> proxy = GetDms();
715     if (proxy == nullptr) {
716         return;
717     }
718     AAFwk::Want remoteWant;
719     AppExecFwk::ElementName element("abcdefg123456", "com.ohos.distributedmusicplayer",
720         "com.ohos.distributedmusicplayer.MainAbility");
721     remoteWant.SetElement(element);
722     CallerInfo callerInfo;
723     callerInfo.uid = 0;
724     callerInfo.sourceDeviceId = "255.255.255.255";
725     IDistributedSched::AccountInfo accountInfo;
726     int32_t extensionType = 3;
727     EXPECT_EQ(proxy->StopExtensionAbilityFromRemote(remoteWant, callerInfo,
728         accountInfo, extensionType), IPC_STUB_UNKNOW_TRANS_ERR);
729     DTEST_LOG << "DistributedSchedServiceSecondTest StopExtensionAbilityFromRemote_003 end" << std::endl;
730 }
731 
732 /**
733  * @tc.name: StopExtensionAbilityFromRemote_004
734  * @tc.desc: call StopExtensionAbilityFromRemote
735  * @tc.type: FUNC
736  * @tc.require: I6YLV1
737  */
738 HWTEST_F(DistributedSchedServiceSecondTest, StopExtensionAbilityFromRemote_004, TestSize.Level3)
739 {
740     DTEST_LOG << "DistributedSchedServiceSecondTest StopExtensionAbilityFromRemote_004 start" << std::endl;
741     AAFwk::Want want;
742     std::string localDeviceId;
743     DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
744     AppExecFwk::ElementName element(localDeviceId, BUNDLE_NAME,
745         ABILITY_NAME);
746     want.SetElement(element);
747     want.SetParam(DMS_IS_CALLER_BACKGROUND, false);
748     AppExecFwk::AbilityInfo abilityInfo;
749     abilityInfo.permissions.clear();
750     sptr<IRemoteObject> connect(new MockDistributedSched());
751     CallerInfo callerInfo;
752     callerInfo.uid = 0;
753     callerInfo.sourceDeviceId = LOCAL_DEVICEID;
754     bool result = BundleManagerInternal::GetCallerAppIdFromBms(BUNDLE_NAME, callerInfo.callerAppId);
755     EXPECT_TRUE(result);
756     IDistributedSched::AccountInfo accountInfo;
757     accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
758     int32_t extensionType = 3;
759     int ret = DistributedSchedService::GetInstance().StopExtensionAbilityFromRemote(want, callerInfo,
760         accountInfo, extensionType);
761     EXPECT_EQ(ret, INVALID_REMOTE_PARAMETERS_ERR);
762     DTEST_LOG << "DistributedSchedServiceSecondTest StopExtensionAbilityFromRemote_004 end" << std::endl;
763 }
764 
765 /**
766  * @tc.name: CheckDistributedConnectLocked001
767  * @tc.desc: call CheckDistributedConnectLocked
768  * @tc.type: FUNC
769  * @tc.require: I6P0I9
770  */
771 HWTEST_F(DistributedSchedServiceSecondTest, CheckDistributedConnectLocked001, TestSize.Level3)
772 {
773     DTEST_LOG << "DistributedSchedServiceSecondTest CheckDistributedConnectLocked001 start" << std::endl;
774     int32_t uid = IPCSkeleton::GetCallingUid();
775     CallerInfo callerInfo;
776     callerInfo.uid = uid;
777     int32_t ret = DistributedSchedService::GetInstance().CheckDistributedConnectLocked(callerInfo);
778     EXPECT_EQ(ret, ERR_OK);
779     DTEST_LOG << "DistributedSchedServiceSecondTest CheckDistributedConnectLocked001 end" << std::endl;
780 }
781 
782 /**
783  * @tc.name: CheckDistributedConnectLocked002
784  * @tc.desc: call CheckDistributedConnectLocked
785  * @tc.type: FUNC
786  * @tc.require: I6P0I9
787  */
788 HWTEST_F(DistributedSchedServiceSecondTest, CheckDistributedConnectLocked002, TestSize.Level3)
789 {
790     DTEST_LOG << "DistributedSchedServiceSecondTest CheckDistributedConnectLocked002 start" << std::endl;
791     int32_t uid = -1;
792     CallerInfo callerInfo;
793     callerInfo.uid = uid;
794     int32_t ret = DistributedSchedService::GetInstance().CheckDistributedConnectLocked(callerInfo);
795     EXPECT_EQ(ret, BIND_ABILITY_UID_INVALID_ERR);
796     DTEST_LOG << "DistributedSchedServiceSecondTest CheckDistributedConnectLocked002 end" << std::endl;
797 }
798 
799 /**
800  * @tc.name: TryConnectRemoteAbility001
801  * @tc.desc: call TryConnectRemoteAbility
802  * @tc.type: FUNC
803  * @tc.require: I6P0I9
804  */
805 HWTEST_F(DistributedSchedServiceSecondTest, TryConnectRemoteAbility001, TestSize.Level3)
806 {
807     DTEST_LOG << "DistributedSchedServiceSecondTest TryConnectRemoteAbility001 start" << std::endl;
808     std::string remoteDeviceId = "remoteDeviceId";
809     OHOS::AAFwk::Want want;
810     want.SetElementName(remoteDeviceId, "ohos.demo.bundleName", "abilityName");
811     sptr<IRemoteObject> connect = nullptr;
812     CallerInfo callerInfo;
813     int32_t ret = DistributedSchedService::GetInstance().TryConnectRemoteAbility(want, connect, callerInfo);
814     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
815     DTEST_LOG << "DistributedSchedServiceSecondTest TryConnectRemoteAbility001 end" << std::endl;
816 }
817 
818 /**
819  * @tc.name: TryConnectRemoteAbility002
820  * @tc.desc: call TryConnectRemoteAbility
821  * @tc.type: FUNC
822  * @tc.require: I6P0I9
823  */
824 HWTEST_F(DistributedSchedServiceSecondTest, TryConnectRemoteAbility002, TestSize.Level3)
825 {
826     DTEST_LOG << "DistributedSchedServiceSecondTest TryConnectRemoteAbility002 start" << std::endl;
827     std::string remoteDeviceId = "remoteDeviceId";
828     OHOS::AAFwk::Want want;
829     want.SetElementName(remoteDeviceId, "ohos.demo.bundleName", "abilityName");
830     sptr<IRemoteObject> connect = nullptr;
831     CallerInfo callerInfo;
832     int32_t ret = DistributedSchedService::GetInstance().TryConnectRemoteAbility(want, connect, callerInfo);
833     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
834     DTEST_LOG << "DistributedSchedServiceSecondTest TryConnectRemoteAbility002 end" << std::endl;
835 }
836 
837 /**
838  * @tc.name: SetCallerInfo_001
839  * @tc.desc: call SetCallerInfo
840  * @tc.type: FUNC
841  * @tc.require: I76THI
842  */
843 HWTEST_F(DistributedSchedServiceSecondTest, SetCallerInfo_001, TestSize.Level3)
844 {
845     DTEST_LOG << "DistributedSchedServiceSecondTest SetCallerInfo_001 start" << std::endl;
846 
847     sptr<IDistributedSched> proxy = GetDms();
848     if (proxy == nullptr) {
849         return;
850     }
851     /**
852      * @tc.steps: step1. set want and abilityInfo
853      */
854     AAFwk::Want want;
855     AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
856         "com.ohos.distributedmusicplayer.MainAbility");
857     want.SetElement(element);
858     AppExecFwk::AbilityInfo abilityInfo;
859     GetAbilityInfo("com.ohos.distributedmusicplayer", "com.ohos.distributedmusicplayer.MainAbility",
860         "com.ohos.distributedmusicplayer", "192.168.43.100", abilityInfo);
861     CallerInfo callerInfo;
862     callerInfo.uid = 0;
863     callerInfo.sourceDeviceId = "255.255.255.255";
864     IDistributedSched::AccountInfo accountInfo;
865     /**
866      * @tc.steps: step2. StartAbilityFromRemote for pressure test
867      * @tc.expected: step2. StartAbilityFromRemote for result
868      */
869     for (int index = 0; index < static_cast<int32_t>(LoopTime::LOOP_TIME); index++) {
870         int result = proxy->StartAbilityFromRemote(want, abilityInfo, 0, callerInfo, accountInfo);
871         DTEST_LOG << "pressure" + to_string(index) + " result is " << result << std::endl;
872     }
873 
874     /**
875     * @tc.steps: step1. call SetCallerInfo with invalid parameters.
876     */
877     CallerInfo callerInfo1;
878     int32_t result = DistributedSchedService::GetInstance().SetCallerInfo(0, LOCAL_DEVICEID, 0, callerInfo1);
879     EXPECT_EQ(result, INVALID_PARAMETERS_ERR);
880     /**
881     * @tc.steps: step2. call OnRemoteDied.
882     */
883     const wptr<IRemoteObject> remote;
884     CallerDeathRecipient callerDeathRecipient;
885     callerDeathRecipient.OnRemoteDied(remote);
886     DTEST_LOG << "DistributedSchedServiceSecondTest StartRemoteAbilityByCall_001 end" << std::endl;
887 }
888 
889 /**
890  * @tc.name: ContinueRemoteMission_001
891  * @tc.desc: call ContinueRemoteMission
892  * @tc.type: FUNC
893  */
894 HWTEST_F(DistributedSchedServiceSecondTest, ContinueRemoteMission_001, TestSize.Level1)
895 {
896     DTEST_LOG << "DSchedContinuationTest ContinueRemoteMission_001 start" << std::endl;
897     if (DistributedSchedService::GetInstance().dschedContinuation_ == nullptr) {
898         DistributedSchedService::GetInstance().dschedContinuation_ = std::make_shared<DSchedContinuation>();
899     }
900     int32_t missionId = MISSION_ID;
901     int32_t timeout = 5;
902     DistributedSchedService::GetInstance().SetContinuationTimeout(missionId, timeout);
903     WantParams wantParams;
904     EXPECT_EQ(ERR_OK, LoadContinueConfig());
905     auto callback = GetDSchedService();
906     int32_t result = DistributedSchedService::GetInstance().ContinueRemoteMission(
907         "", "string", "bundleName", callback, wantParams);
908     EXPECT_EQ(static_cast<int>(INVALID_REMOTE_PARAMETERS_ERR), result);
909     DTEST_LOG << "DSchedContinuationTest ContinueRemoteMission_001 end" << std::endl;
910 }
911 
912 /**
913  * @tc.name: ContinueRemoteMission_002
914  * @tc.desc: call ContinueRemoteMission
915  * @tc.type: FUNC
916  */
917 HWTEST_F(DistributedSchedServiceSecondTest, ContinueRemoteMission_002, TestSize.Level1)
918 {
919     DTEST_LOG << "DSchedContinuationTest ContinueRemoteMission_002 start" << std::endl;
920     WantParams wantParams;
921     EXPECT_EQ(ERR_OK, LoadContinueConfig());
922     auto callback = GetDSchedService();
923     std::string localDeviceId;
924     DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
925     int32_t result = DistributedSchedService::GetInstance().ContinueRemoteMission(
926         "string", localDeviceId, "bundleName", callback, wantParams);
927     EXPECT_EQ(static_cast<int>(INVALID_REMOTE_PARAMETERS_ERR), result);
928     DTEST_LOG << "DSchedContinuationTest ContinueRemoteMission_002 end" << std::endl;
929 }
930 
931 /**
932  * @tc.name: StartLocalAbility_001
933  * @tc.desc: call StartLocalAbility with dms
934  * @tc.type: FUNC
935  */
936 HWTEST_F(DistributedSchedServiceSecondTest, StartLocalAbility_001, TestSize.Level1)
937 {
938     DTEST_LOG << "DistributedSchedServiceSecondTest StartLocalAbility_001 start" << std::endl;
939     sptr<IDistributedSched> proxy = GetDms();
940 
941     AAFwk::Want want;
942     AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
943         "com.ohos.distributedmusicplayer.MainAbility");
944     want.SetElement(element);
945     CallerInfo callerInfo;
946     callerInfo.uid = 0;
947     callerInfo.sourceDeviceId = "255.255.255.255";
948     IDistributedSched::AccountInfo accountInfo;
949     int missionId = 0;
950     want.SetParam(DMS_SRC_NETWORK_ID, callerInfo.sourceDeviceId);
951     want.SetParam(DMS_MISSION_ID, missionId);
952     DistributedSchedProxy::FreeInstallInfo info = {.want = want, .requestCode = 0, .callerInfo = callerInfo,
953         .accountInfo = accountInfo};
954     int result1 = DistributedSchedService::GetInstance().StartLocalAbility(info, 0, 0);
955     DTEST_LOG << "result1:" << result1 << std::endl;
956 
957     AppExecFwk::ElementName element2("", "com.ohos.distributedmusicplayer",
958         "com.ohos.distributedmusicplayer.MainAbilityService");
959     want.SetElement(element2);
960     DistributedSchedProxy::FreeInstallInfo info2 = {.want = want, .requestCode = 0, .callerInfo = callerInfo,
961         .accountInfo = accountInfo};
962     int result2 = DistributedSchedService::GetInstance().StartLocalAbility(info2, 0, 0);
963     DTEST_LOG << "result2:" << result2 << std::endl;
964     EXPECT_EQ(static_cast<int>(INVALID_PARAMETERS_ERR), result1);
965     EXPECT_EQ(static_cast<int>(INVALID_PARAMETERS_ERR), result2);
966     DTEST_LOG << "DistributedSchedServiceSecondTest StartLocalAbility_001 end" << std::endl;
967 }
968 
969 /**
970  * @tc.name: StartLocalAbility_002
971  * @tc.desc: call StartLocalAbility with dms
972  * @tc.type: FUNC
973  */
974 HWTEST_F(DistributedSchedServiceSecondTest, StartLocalAbility_002, TestSize.Level1)
975 {
976     DTEST_LOG << "DistributedSchedServiceSecondTest StartLocalAbility_002 start" << std::endl;
977     sptr<IDistributedSched> proxy = GetDms();
978 
979     AAFwk::Want want;
980     AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
981         "com.ohos.distributedmusicplayer.MainAbility");
982     want.SetElement(element);
983     CallerInfo callerInfo;
984     callerInfo.uid = 0;
985     callerInfo.sourceDeviceId = "255.255.255.255";
986     IDistributedSched::AccountInfo accountInfo;
987     DistributedSchedProxy::FreeInstallInfo info = {.want = want, .requestCode = DEFAULT_REQUEST_CODE,
988         .callerInfo = callerInfo, .accountInfo = accountInfo};
989     int result1 = DistributedSchedService::GetInstance().StartLocalAbility(info, 0, 0);
990     DTEST_LOG << "result1:" << result1 << std::endl;
991 
992     AppExecFwk::ElementName element2("", "com.ohos.distributedmusicplayer",
993         "com.ohos.distributedmusicplayer.MainAbilityService");
994     want.SetElement(element2);
995     DistributedSchedProxy::FreeInstallInfo info2 = {.want = want, .requestCode = DEFAULT_REQUEST_CODE,
996         .callerInfo = callerInfo, .accountInfo = accountInfo};
997     int result2 = DistributedSchedService::GetInstance().StartLocalAbility(info2, 0, 0);
998     DTEST_LOG << "result2:" << result2 << std::endl;
999     EXPECT_EQ(static_cast<int>(INVALID_PARAMETERS_ERR), result1);
1000     EXPECT_EQ(static_cast<int>(INVALID_PARAMETERS_ERR), result2);
1001     DTEST_LOG << "DistributedSchedServiceSecondTest StartLocalAbility_002 end" << std::endl;
1002 }
1003 
1004 /**
1005  * @tc.name: StartLocalAbility_003
1006  * @tc.desc: call StartLocalAbility with dms
1007  * @tc.type: FUNC
1008  */
1009 HWTEST_F(DistributedSchedServiceSecondTest, StartLocalAbility_003, TestSize.Level1)
1010 {
1011     DTEST_LOG << "DistributedSchedServiceSecondTest StartLocalAbility_003 start" << std::endl;
1012     sptr<IDistributedSched> proxy = GetDms();
1013 
1014     AAFwk::Want want;
1015     AppExecFwk::ElementName element("1.1.1.1", "com.ohos.distributedmusicplayer",
1016         "com.ohos.distributedmusicplayer.MainAbility");
1017     want.SetElement(element);
1018     CallerInfo callerInfo;
1019     callerInfo.uid = 0;
1020     callerInfo.sourceDeviceId = "255.255.255.255";
1021     IDistributedSched::AccountInfo accountInfo;
1022     accountInfo.accountType = 1;
1023     accountInfo.groupIdList.push_back("123456");
1024     int missionId = 0;
1025     want.SetParam(DMS_SRC_NETWORK_ID, callerInfo.sourceDeviceId);
1026     want.SetParam(DMS_MISSION_ID, missionId);
1027     DistributedSchedProxy::FreeInstallInfo info = {.want = want, .requestCode = 0, .callerInfo = callerInfo,
1028         .accountInfo = accountInfo};
1029     int result1 = DistributedSchedService::GetInstance().StartLocalAbility(info, 0, 0);
1030     DTEST_LOG << "result1:" << result1 << std::endl;
1031 
1032     AppExecFwk::ElementName element2("1.1.1.1", "com.ohos.distributedmusicplayer",
1033         "com.ohos.distributedmusicplayer.MainAbilityService");
1034     want.SetElement(element2);
1035     DistributedSchedProxy::FreeInstallInfo info2 = {.want = want, .requestCode = 0, .callerInfo = callerInfo,
1036         .accountInfo = accountInfo};
1037     int result2 = DistributedSchedService::GetInstance().StartLocalAbility(info2, 0, 0);
1038     DTEST_LOG << "result2:" << result2 << std::endl;
1039     DTEST_LOG << "DistributedSchedServiceSecondTest StartLocalAbility_003 end" << std::endl;
1040 }
1041 
1042 /**
1043  * @tc.name: StartLocalAbility_004
1044  * @tc.desc: call StartLocalAbility with dms
1045  * @tc.type: FUNC
1046  */
1047 HWTEST_F(DistributedSchedServiceSecondTest, StartLocalAbility_004, TestSize.Level1)
1048 {
1049     DTEST_LOG << "DistributedSchedServiceSecondTest StartLocalAbility_004 start" << std::endl;
1050     sptr<IDistributedSched> proxy = GetDms();
1051 
1052     AAFwk::Want want;
1053     AppExecFwk::ElementName element("1.1.1.1", "com.ohos.distributedmusicplayer",
1054         "com.ohos.distributedmusicplayer.MainAbility");
1055     want.SetElement(element);
1056     CallerInfo callerInfo;
1057     callerInfo.uid = 0;
1058     callerInfo.sourceDeviceId = "255.255.255.255";
1059     IDistributedSched::AccountInfo accountInfo;
1060     accountInfo.accountType = 1;
1061     accountInfo.groupIdList.push_back("123456");
1062     DistributedSchedProxy::FreeInstallInfo info = {.want = want, .requestCode = DEFAULT_REQUEST_CODE,
1063         .callerInfo = callerInfo, .accountInfo = accountInfo};
1064     int result1 = DistributedSchedService::GetInstance().StartLocalAbility(info, 0, 0);
1065     DTEST_LOG << "result1:" << result1 << std::endl;
1066 
1067     AppExecFwk::ElementName element2("1.1.1.1", "com.ohos.distributedmusicplayer",
1068         "com.ohos.distributedmusicplayer.MainAbilityService");
1069     want.SetElement(element2);
1070     DistributedSchedProxy::FreeInstallInfo info2 = {.want = want, .requestCode = DEFAULT_REQUEST_CODE,
1071         .callerInfo = callerInfo, .accountInfo = accountInfo};
1072     int result2 = DistributedSchedService::GetInstance().StartLocalAbility(info2, 0, 0);
1073     DTEST_LOG << "result2:" << result2 << std::endl;
1074     DTEST_LOG << "DistributedSchedServiceSecondTest StartLocalAbility_004 end" << std::endl;
1075 }
1076 
1077 /**
1078  * @tc.name: StartLocalAbility_005
1079  * @tc.desc: test StartLocalAbility
1080  * @tc.type: FUNC
1081  * @tc.require: issueI5T6GJ
1082  */
1083 HWTEST_F(DistributedSchedServiceSecondTest, StartLocalAbility_005, TestSize.Level3)
1084 {
1085     DTEST_LOG << "DistributedSchedServiceSecondTest StartLocalAbility_005 start" << std::endl;
1086     AAFwk::Want want;
1087     std::string localDeviceId;
1088     DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
1089     AppExecFwk::ElementName element(localDeviceId, "com.ohos.mms", "bmsThirdBundle");
1090     want.SetElement(element);
1091     want.SetParam(DMS_IS_CALLER_BACKGROUND, false);
1092     AppExecFwk::AbilityInfo abilityInfo;
1093     abilityInfo.permissions.clear();
1094     CallerInfo callerInfo;
1095     callerInfo.uid = 0;
1096     callerInfo.sourceDeviceId = LOCAL_DEVICEID;
1097     bool result = BundleManagerInternal::GetCallerAppIdFromBms("com.third.hiworld.example", callerInfo.callerAppId);
1098     EXPECT_TRUE(result);
1099     IDistributedSched::AccountInfo accountInfo;
1100     accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
1101     DistributedSchedProxy::FreeInstallInfo info = {.want = want, .requestCode = 0,
1102         .callerInfo = callerInfo, .accountInfo = accountInfo};
1103     int ret = DistributedSchedService::GetInstance().StartLocalAbility(info, 0, 0);
1104     EXPECT_NE(ret, ERR_OK);
1105     DTEST_LOG << "DistributedSchedServiceSecondTest StartLocalAbility_005 end" << std::endl;
1106 }
1107 
1108 /**
1109  * @tc.name: HandleLocalCallerDied_001
1110  * @tc.desc: call HandleLocalCallerDied
1111  * @tc.type: FUNC
1112  * @tc.require: I6YLV1
1113  */
1114 HWTEST_F(DistributedSchedServiceSecondTest, HandleLocalCallerDied_001, TestSize.Level1)
1115 {
1116     DTEST_LOG << "DistributedSchedServiceSecondTest HandleLocalCallerDied_001 start" << std::endl;
1117     std::string localDeviceId;
1118     DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
1119     sptr<IRemoteObject> connect(new MockDistributedSched());
1120     std::list<ConnectAbilitySession> sessionsList;
1121     DistributedSchedService::GetInstance().callerMap_[connect] = sessionsList;
1122     DistributedSchedService::GetInstance().callMap_[connect] = {4, localDeviceId};
1123     DistributedSchedService::GetInstance().HandleLocalCallerDied(connect);
1124     DistributedSchedService::GetInstance().callerMap_.clear();
1125     EXPECT_TRUE(DistributedSchedService::GetInstance().callerMap_.empty());
1126     DistributedSchedService::GetInstance().callMap_.clear();
1127     EXPECT_TRUE(DistributedSchedService::GetInstance().callMap_.empty());
1128     DTEST_LOG << "DistributedSchedServiceSecondTest HandleLocalCallerDied_001 end" << std::endl;
1129 }
1130 
1131 /**
1132  * @tc.name: RemoveCallerComponent_001
1133  * @tc.desc: call RemoveCallerComponent
1134  * @tc.type: FUNC
1135  * @tc.require: I6YLV1
1136  */
1137 HWTEST_F(DistributedSchedServiceSecondTest, RemoveCallerComponent_001, TestSize.Level1)
1138 {
1139     DTEST_LOG << "DistributedSchedServiceSecondTest RemoveCallerComponent_001 start" << std::endl;
1140     std::string localDeviceId;
1141     DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
1142     sptr<IRemoteObject> connect(new MockDistributedSched());
1143     std::list<ConnectAbilitySession> sessionsList;
1144     DistributedSchedService::GetInstance().callerMap_[connect] = sessionsList;
1145     DistributedSchedService::GetInstance().callMap_[connect] = {5, localDeviceId};
1146     DistributedSchedService::GetInstance().RemoveCallerComponent(connect);
1147     DistributedSchedService::GetInstance().RemoveCallerComponent(nullptr);
1148     DistributedSchedService::GetInstance().callerMap_.clear();
1149     EXPECT_TRUE(DistributedSchedService::GetInstance().callerMap_.empty());
1150     DistributedSchedService::GetInstance().callMap_.clear();
1151     EXPECT_TRUE(DistributedSchedService::GetInstance().callMap_.empty());
1152     DTEST_LOG << "DistributedSchedServiceSecondTest RemoveCallerComponent_001 end" << std::endl;
1153 }
1154 
1155 /**
1156  * @tc.name: ProcessCalleeOffline_001
1157  * @tc.desc: call ProcessCalleeOffline
1158  * @tc.type: FUNC
1159  * @tc.require: I6YLV1
1160  */
1161 HWTEST_F(DistributedSchedServiceSecondTest, ProcessCalleeOffline_001, TestSize.Level1)
1162 {
1163     DTEST_LOG << "DistributedSchedServiceSecondTest ProcessCalleeOffline_001 start" << std::endl;
1164     std::string localDeviceId;
1165     DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
1166     sptr<IRemoteObject> connect(new MockDistributedSched());
1167     std::list<ConnectAbilitySession> sessionsList;
1168     DistributedSchedService::GetInstance().callerMap_[connect] = sessionsList;
1169     DistributedSchedService::GetInstance().callMap_[connect] = {6, localDeviceId};
1170     DistributedSchedService::GetInstance().ProcessCalleeOffline(REMOTE_DEVICEID);
1171 
1172     sptr<IRemoteObject> mockConnect = nullptr;
1173     DistributedSchedService::GetInstance().callerMap_[mockConnect] = sessionsList;
1174     DistributedSchedService::GetInstance().ProcessCalleeOffline(localDeviceId);
1175     DistributedSchedService::GetInstance().callerMap_.clear();
1176     EXPECT_TRUE(DistributedSchedService::GetInstance().callerMap_.empty());
1177     DistributedSchedService::GetInstance().callMap_.clear();
1178     EXPECT_TRUE(DistributedSchedService::GetInstance().callMap_.empty());
1179     DTEST_LOG << "DistributedSchedServiceSecondTest ProcessCalleeOffline_001 end" << std::endl;
1180 }
1181 
1182 /**
1183  * @tc.name: GetConnectComponentList_001
1184  * @tc.desc: call GetConnectComponentList
1185  * @tc.type: FUNC
1186  * @tc.require: I76THI
1187  */
1188 HWTEST_F(DistributedSchedServiceSecondTest, GetConnectComponentList_001, TestSize.Level1)
1189 {
1190     DTEST_LOG << "DistributedSchedServiceSecondTest GetConnectComponentList_001 start" << std::endl;
1191     /**
1192     * @tc.steps: step1. call GetConnectComponentList when iter.second is empty.
1193     */
1194     sptr<IRemoteObject> connect(new MockDistributedSched());
1195     std::list<ConnectAbilitySession> sessionsList;
1196     std::vector<std::string> distributedComponents;
1197     {
1198         std::lock_guard<std::mutex> autoLock(DistributedSchedService::GetInstance().distributedLock_);
1199         DistributedSchedService::GetInstance().distributedConnectAbilityMap_.clear();
1200         DistributedSchedService::GetInstance().distributedConnectAbilityMap_[connect] = sessionsList;
1201     }
1202     DistributedSchedService::GetInstance().GetConnectComponentList(distributedComponents);
1203     EXPECT_TRUE(distributedComponents.empty());
1204     /**
1205     * @tc.steps: step2. call GetConnectComponentList when iter.second is not empty.
1206     */
1207     CallerInfo callerInfo;
1208     ConnectAbilitySession connectAbilitySession("sourceDeviceId", "destinationDeviceId", callerInfo);
1209     sessionsList.emplace_back(connectAbilitySession);
1210     {
1211         std::lock_guard<std::mutex> autoLock(DistributedSchedService::GetInstance().distributedLock_);
1212         DistributedSchedService::GetInstance().distributedConnectAbilityMap_[connect] = sessionsList;
1213     }
1214     DistributedSchedService::GetInstance().GetConnectComponentList(distributedComponents);
1215     EXPECT_FALSE(distributedComponents.empty());
1216     /**
1217     * @tc.steps: step3. call GetConnectComponentList when connectAbilityMap_ is not empty.
1218     */
1219     distributedComponents.clear();
1220     ConnectInfo connectInfo;
1221     {
1222         std::lock_guard<std::mutex> autoLock(DistributedSchedService::GetInstance().connectLock_);
1223         DistributedSchedService::GetInstance().connectAbilityMap_[connect] = connectInfo;
1224     }
1225     DistributedSchedService::GetInstance().GetConnectComponentList(distributedComponents);
1226     EXPECT_FALSE(distributedComponents.empty());
1227     DTEST_LOG << "DistributedSchedServiceSecondTest GetConnectComponentList_001 end" << std::endl;
1228 }
1229 
1230 /**
1231  * @tc.name: GetCallComponentList_001
1232  * @tc.desc: call GetCallComponentList
1233  * @tc.type: FUNC
1234  * @tc.require: I76THI
1235  */
1236 HWTEST_F(DistributedSchedServiceSecondTest, GetCallComponentList_001, TestSize.Level1)
1237 {
1238     DTEST_LOG << "DistributedSchedServiceSecondTest GetCallComponentList_001 start" << std::endl;
1239     /**
1240     * @tc.steps: step1. call GetCallComponentList when iter.second is empty.
1241     */
1242     sptr<IRemoteObject> connect(new MockDistributedSched());
1243     std::list<ConnectAbilitySession> sessionsList;
1244     std::vector<std::string> distributedComponents;
1245     {
1246         std::lock_guard<std::mutex> autoLock(DistributedSchedService::GetInstance().callerLock_);
1247         DistributedSchedService::GetInstance().callerMap_.clear();
1248         DistributedSchedService::GetInstance().callerMap_[connect] = sessionsList;
1249     }
1250     DistributedSchedService::GetInstance().GetCallComponentList(distributedComponents);
1251     EXPECT_TRUE(distributedComponents.empty());
1252     /**
1253     * @tc.steps: step2. call GetCallComponentList when iter.second is not empty.
1254     */
1255     CallerInfo callerInfo;
1256     ConnectAbilitySession connectAbilitySession("sourceDeviceId", "destinationDeviceId", callerInfo);
1257     sessionsList.emplace_back(connectAbilitySession);
1258     {
1259         std::lock_guard<std::mutex> autoLock(DistributedSchedService::GetInstance().callerLock_);
1260         DistributedSchedService::GetInstance().callerMap_[connect] = sessionsList;
1261     }
1262     DistributedSchedService::GetInstance().GetCallComponentList(distributedComponents);
1263     EXPECT_FALSE(distributedComponents.empty());
1264     /**
1265     * @tc.steps: step3. call GetCallComponentList when calleeMap_ is not empty.
1266     */
1267     distributedComponents.clear();
1268     ConnectInfo connectInfo;
1269     {
1270         std::lock_guard<std::mutex> autoLock(DistributedSchedService::GetInstance().calleeLock_);
1271         DistributedSchedService::GetInstance().calleeMap_[connect] = connectInfo;
1272     }
1273     DistributedSchedService::GetInstance().GetCallComponentList(distributedComponents);
1274     EXPECT_FALSE(distributedComponents.empty());
1275     DTEST_LOG << "DistributedSchedServiceSecondTest GetCallComponentList_001 end" << std::endl;
1276 }
1277 
1278 /**
1279  * @tc.name: RegisterAppStateObserver_001
1280  * @tc.desc: test RegisterAppStateObserver
1281  * @tc.type: FUNC
1282  * @tc.require: I6VDBO
1283  */
1284 HWTEST_F(DistributedSchedServiceSecondTest, RegisterAppStateObserver_001, TestSize.Level3)
1285 {
1286     DTEST_LOG << "DistributedSchedServiceSecondTest RegisterAppStateObserver_001 start" << std::endl;
1287     AAFwk::Want want;
1288     std::string localDeviceId;
1289     DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
1290     AppExecFwk::ElementName element(localDeviceId, BUNDLE_NAME, ABILITY_NAME);
1291     want.SetElement(element);
1292     want.SetParam(DMS_MISSION_ID, 0);
1293     want.SetParam(DMS_CONNECT_TOKEN, 0);
1294     sptr<IRemoteObject> connect(new MockDistributedSched());
1295     CallerInfo callerInfo;
1296     callerInfo.uid = 0;
1297     callerInfo.sourceDeviceId = localDeviceId;
1298     bool ret = DistributedSchedService::GetInstance().RegisterAppStateObserver(want, callerInfo, nullptr, connect);
1299     DistributedSchedService::GetInstance().UnregisterAppStateObserver(connect);
1300     EXPECT_TRUE(ret);
1301     DTEST_LOG << "DistributedSchedServiceSecondTest RegisterAppStateObserver_001 end" << std::endl;
1302 }
1303 
1304 /**
1305  * @tc.name: UnregisterAppStateObserver_001
1306  * @tc.desc: test UnregisterAppStateObserver
1307  * @tc.type: FUNC
1308  * @tc.require: I6VDBO
1309  */
1310 HWTEST_F(DistributedSchedServiceSecondTest, UnregisterAppStateObserver_001, TestSize.Level3)
1311 {
1312     DTEST_LOG << "DistributedSchedServiceSecondTest UnregisterAppStateObserver_001 start" << std::endl;
1313     sptr<IRemoteObject> connect = nullptr;
1314     DistributedSchedService::GetInstance().UnregisterAppStateObserver(connect);
1315     EXPECT_EQ(connect, nullptr);
1316     DTEST_LOG << "DistributedSchedServiceSecondTest UnregisterAppStateObserver_001 end" << std::endl;
1317 }
1318 
1319 /**
1320  * @tc.name: UnregisterAppStateObserver_002
1321  * @tc.desc: test UnregisterAppStateObserver
1322  * @tc.type: FUNC
1323  * @tc.require: I6VDBO
1324  */
1325 HWTEST_F(DistributedSchedServiceSecondTest, UnregisterAppStateObserver_002, TestSize.Level3)
1326 {
1327     DTEST_LOG << "DistributedSchedServiceSecondTest UnregisterAppStateObserver_002 start" << std::endl;
1328     AAFwk::Want want;
1329     std::string localDeviceId;
1330     DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
1331     AppExecFwk::ElementName element(localDeviceId, BUNDLE_NAME, ABILITY_NAME);
1332     want.SetElement(element);
1333     want.SetParam(DMS_MISSION_ID, 0);
1334     want.SetParam(DMS_CONNECT_TOKEN, 0);
1335     sptr<IRemoteObject> connect(new MockDistributedSched());
1336     CallerInfo callerInfo;
1337     callerInfo.uid = 0;
1338     callerInfo.sourceDeviceId = localDeviceId;
1339     bool ret = DistributedSchedService::GetInstance().RegisterAppStateObserver(want, callerInfo, nullptr, connect);
1340     EXPECT_TRUE(ret);
1341     sptr<IRemoteObject> connect1(new MockDistributedSched());
1342     DistributedSchedService::GetInstance().UnregisterAppStateObserver(connect1);
1343     EXPECT_NE(connect, connect1);
1344     DistributedSchedService::GetInstance().SaveCallerComponent(want, nullptr, callerInfo);
1345     DTEST_LOG << "DistributedSchedServiceSecondTest UnregisterAppStateObserver_002 end" << std::endl;
1346 }
1347 
1348 /**
1349  * @tc.name: GetAppManager_001
1350  * @tc.desc: test GetAppManager
1351  * @tc.type: FUNC
1352  * @tc.require: I6VDBO
1353  */
1354 HWTEST_F(DistributedSchedServiceSecondTest, GetAppManager_001, TestSize.Level3)
1355 {
1356     DTEST_LOG << "DistributedSchedServiceSecondTest GetAppManager_001 start" << std::endl;
1357     auto ret = DistributedSchedService::GetInstance().GetAppManager();
1358     EXPECT_NE(ret, nullptr);
1359     DTEST_LOG << "DistributedSchedServiceSecondTest GetAppManager_001 end" << std::endl;
1360 }
1361 
1362 /**
1363  * @tc.name: SaveConnectToken_001
1364  * @tc.desc: call SaveConnectToken
1365  * @tc.type: FUNC
1366  * @tc.require: I76THI
1367  */
1368 HWTEST_F(DistributedSchedServiceSecondTest, SaveConnectToken_001, TestSize.Level3)
1369 {
1370     DTEST_LOG << "DistributedSchedServiceSecondTest SaveConnectToken_001 start" << std::endl;
1371     AAFwk::Want want;
1372     std::string localDeviceId;
1373     DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
1374     AppExecFwk::ElementName element(localDeviceId, BUNDLE_NAME,
1375         ABILITY_NAME);
1376     sptr<IRemoteObject> connect(new MockDistributedSched());
1377     /**
1378     * @tc.steps: step1. call SaveConnectToken
1379     * @tc.expected: step1. SaveConnectToken return token_
1380     */
1381     int32_t token = 0;
1382     {
1383         std::lock_guard<std::mutex> tokenLock(DistributedSchedService::GetInstance().tokenMutex_);
1384         token = DistributedSchedService::GetInstance().token_.load();
1385     }
1386     int32_t result = DistributedSchedService::GetInstance().SaveConnectToken(want, connect);
1387     EXPECT_EQ(result, token + 1);
1388     /**
1389     * @tc.steps: step2. call SaveConnectToken when tToken > MAX_TOKEN_NUM
1390     * @tc.expected: step2. SaveConnectToken return 1
1391     */
1392     {
1393         std::lock_guard<std::mutex> tokenLock(DistributedSchedService::GetInstance().tokenMutex_);
1394         DistributedSchedService::GetInstance().token_.store(MAX_TOKEN_NUM);
1395     }
1396     result = DistributedSchedService::GetInstance().SaveConnectToken(want, connect);
1397     EXPECT_EQ(result, 1);
1398     DTEST_LOG << "DistributedSchedServiceSecondTest SaveConnectToken_001 end" << std::endl;
1399 }
1400 
1401 /**
1402  * @tc.name: ContinueMissionBundleName_001
1403  * @tc.desc: call ContinueMissionBundleName
1404  * @tc.type: FUNC
1405  */
1406 HWTEST_F(DistributedSchedServiceSecondTest, ContinueMissionBundleName_001, TestSize.Level1)
1407 {
1408     DTEST_LOG << "DSchedContinuationTest ContinueMissionBundleName_001 start" << std::endl;
1409     WantParams wantParams;
1410     auto callback = GetDSchedService();
1411     std::string localDeviceId;
1412     DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
1413     int32_t result = DistributedSchedService::GetInstance().ContinueMission(
1414         "string", localDeviceId, "bundleName", callback, wantParams);
1415     EXPECT_EQ(static_cast<int>(INVALID_REMOTE_PARAMETERS_ERR), result);
1416     DistributedSchedService::GetInstance().ContinueMission(
1417         localDeviceId, "string", "bundleName", callback, wantParams);
1418     DTEST_LOG << "DSchedContinuationTest ContinueMissionBundleName_001 end" << std::endl;
1419 }
1420 
1421 /**
1422  * @tc.name: ContinueMissionBundleName_002
1423  * @tc.desc: call ContinueMissionBundleName
1424  * @tc.type: FUNC
1425  */
1426 HWTEST_F(DistributedSchedServiceSecondTest, ContinueMissionBundleName_002, TestSize.Level1)
1427 {
1428     DTEST_LOG << "DSchedContinuationTest ContinueMissionBundleName_002 start" << std::endl;
1429     WantParams wantParams;
1430     auto callback = GetDSchedService();
1431     int32_t result = DistributedSchedService::GetInstance().ContinueMission(
1432         "string", "string", "bundleName", callback, wantParams);
1433     EXPECT_EQ(static_cast<int>(OPERATION_DEVICE_NOT_INITIATOR_OR_TARGET), result);
1434     DTEST_LOG << "DSchedContinuationTest ContinueMissionBundleName_002 end" << std::endl;
1435 }
1436 
1437 /**
1438  * @tc.name: GetCallerInfo_001
1439  * @tc.desc: GetCallerInfo
1440  * @tc.type: FUNC
1441  */
1442 HWTEST_F(DistributedSchedServiceSecondTest, GetCallerInfo_001, TestSize.Level3)
1443 {
1444     DTEST_LOG << "DistributedSchedServiceSecondTest GetCallerInfo_001 start" << std::endl;
1445     int32_t callerUid = 0;
1446     uint32_t accessToken = 0;
1447     CallerInfo callerInfo;
1448     int32_t result = DistributedSchedService::GetInstance().GetCallerInfo(
1449         LOCAL_DEVICEID, callerUid, accessToken, callerInfo);
1450     EXPECT_EQ(result, INVALID_PARAMETERS_ERR);
1451     DTEST_LOG << "DistributedSchedServiceSecondTest GetCallerInfo_001 end" << std::endl;
1452 }
1453 
1454 /**
1455  * @tc.name: ProcessContinueLocalMission_001
1456  * @tc.desc: ProcessContinueLocalMission
1457  * @tc.type: FUNC
1458  */
1459 HWTEST_F(DistributedSchedServiceSecondTest, ProcessContinueLocalMission_001, TestSize.Level3)
1460 {
1461     DTEST_LOG << "DistributedSchedServiceSecondTest ProcessContinueLocalMission_001 start" << std::endl;
1462     WantParams wantParams;
1463     int32_t result = DistributedSchedService::GetInstance().ProcessContinueLocalMission(
1464         LOCAL_DEVICEID, REMOTE_DEVICEID, BUNDLE_NAME, nullptr, wantParams);
1465 
1466     bool ret = DistributedSchedService::GetInstance().GetIsFreeInstall(0);
1467     EXPECT_EQ(ret, false);
1468     DTEST_LOG << "DistributedSchedServiceSecondTest ProcessContinueLocalMission_001 end" << std::endl;
1469 }
1470 
1471 /**
1472  * @tc.name: StartAbility_001
1473  * @tc.desc: StartAbility
1474  * @tc.type: FUNC
1475  */
1476 HWTEST_F(DistributedSchedServiceSecondTest, StartAbility_001, TestSize.Level3)
1477 {
1478     DTEST_LOG << "DistributedSchedServiceSecondTest StartAbility_001 start" << std::endl;
1479     Want want;
1480     int32_t requestCode = 0;
1481     int32_t ret = DistributedSchedService::GetInstance().StartAbility(want, requestCode);
1482     EXPECT_NE(ret, ERR_OK);
1483     DTEST_LOG << "DistributedSchedServiceSecondTest StartAbility_001 end" << std::endl;
1484 }
1485 }
1486 }