• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2023 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 "gtest/gtest.h"
16 
17 #include "ability_connect_callback_interface.h"
18 #include "ability_connect_callback_stub.h"
19 #include "device_manager.h"
20 #include "if_system_ability_manager.h"
21 #include "ipc_skeleton.h"
22 #include "iservice_registry.h"
23 #include "system_ability_definition.h"
24 
25 #include "ability_connection_wrapper_stub.h"
26 #include "distributed_sched_test_util.h"
27 #include "dtbschedmgr_device_info_storage.h"
28 #include "dtbschedmgr_log.h"
29 #include "multi_user_manager.h"
30 #include "parcel_helper.h"
31 #include "test_log.h"
32 
33 #define private public
34 #define protected public
35 #include "distributed_sched_service.h"
36 #undef private
37 #undef protected
38 
39 namespace OHOS {
40 namespace DistributedSchedule {
41 using namespace AAFwk;
42 using namespace testing;
43 using namespace testing::ext;
44 using namespace OHOS::DistributedHardware;
45 
46 namespace {
47 const std::string TAG = "DistributedSchedConnectTest";
48 const std::u16string CONNECTION_CALLBACK_INTERFACE_TOKEN = u"ohos.abilityshell.DistributedConnection";
49 constexpr int32_t STDOUT_FD = 1;
50 constexpr int32_t REQUEST_CODE_ERR = 305;
51 constexpr int32_t ERROR_CONNECT_CODE = 1000;
52 }
53 
54 class AbilityConnectCallbackTest : public AAFwk::AbilityConnectionStub {
55 public:
56     AbilityConnectCallbackTest() = default;
57     ~AbilityConnectCallbackTest() = default;
58 
59     void OnAbilityConnectDone(const AppExecFwk::ElementName& element,
60         const sptr<IRemoteObject>& remoteObject, int32_t resultCode) override;
61     void OnAbilityDisconnectDone(const AppExecFwk::ElementName& element,
62         int32_t resultCode) override;
63 };
64 
65 class AbilityConnectionWrapperStubTest : public AAFwk::AbilityConnectionStub {
66 public:
AbilityConnectionWrapperStubTest(sptr<IRemoteObject> connection)67     explicit AbilityConnectionWrapperStubTest(sptr<IRemoteObject> connection) : distributedConnection_(connection) {}
68     ~AbilityConnectionWrapperStubTest() = default;
69 
70     void OnAbilityConnectDone(const AppExecFwk::ElementName& element,
71         const sptr<IRemoteObject>& remoteObject, int32_t resultCode) override;
72     void OnAbilityDisconnectDone(const AppExecFwk::ElementName& element,
73         int32_t resultCode) override;
74 
75 private:
76     sptr<IRemoteObject> distributedConnection_;
77 };
78 
79 class DistributedSchedConnectTest : public testing::Test {
80 public:
81     static void SetUpTestCase();
82     static void TearDownTestCase();
83     void SetUp();
84     void TearDown();
85 
86     void AddSession(const sptr<IRemoteObject>& connect, const std::string& localDeviceId,
87         const std::string& remoteDeviceId, const AAFwk::Want& want) const;
88     void RemoveSession(const sptr<IRemoteObject>& connect) const;
89 
90     void AddConnectInfo(const sptr<IRemoteObject>& connect, const std::string& localDeviceId,
91         const std::string& remoteDeviceId) const;
92     void RemoveConnectInfo(const sptr<IRemoteObject>& connect) const;
93 
94     void AddConnectCount(int32_t uid) const;
95     void DecreaseConnectCount(int32_t uid) const;
96     sptr<IDistributedSched> GetDms();
97 
98     class DeviceInitCallBack : public DmInitCallback {
99         void OnRemoteDied() override;
100     };
101 };
102 
103 static bool g_isForeground = true;
104 
IsCallerForeground(int32_t callingUid)105 bool MultiUserManager::IsCallerForeground(int32_t callingUid)
106 {
107     return g_isForeground;
108 }
109 
OnAbilityConnectDone(const AppExecFwk::ElementName & element,const sptr<IRemoteObject> & remoteObject,int32_t resultCode)110 void AbilityConnectCallbackTest::OnAbilityConnectDone(const AppExecFwk::ElementName& element,
111     const sptr<IRemoteObject>& remoteObject, int32_t resultCode)
112 {
113 }
114 
OnAbilityDisconnectDone(const AppExecFwk::ElementName & element,int32_t resultCode)115 void AbilityConnectCallbackTest::OnAbilityDisconnectDone(const AppExecFwk::ElementName& element,
116     int32_t resultCode)
117 {
118 }
119 
OnAbilityConnectDone(const AppExecFwk::ElementName & element,const sptr<IRemoteObject> & remoteObject,int32_t resultCode)120 void AbilityConnectionWrapperStubTest::OnAbilityConnectDone(const AppExecFwk::ElementName& element,
121     const sptr<IRemoteObject>& remoteObject, int32_t resultCode)
122 {
123 }
124 
OnAbilityDisconnectDone(const AppExecFwk::ElementName & element,int32_t resultCode)125 void AbilityConnectionWrapperStubTest::OnAbilityDisconnectDone(const AppExecFwk::ElementName& element,
126     int32_t resultCode)
127 {
128 }
129 
SetUpTestCase()130 void DistributedSchedConnectTest::SetUpTestCase()
131 {
132     if (!DistributedSchedUtil::LoadDistributedSchedService()) {
133         DTEST_LOG << "DistributedSchedConnectTest::SetUpTestCase LoadDistributedSchedService failed" << std::endl;
134     }
135     const std::string pkgName = "DBinderBus_" + std::to_string(getprocpid());
136     std::shared_ptr<DmInitCallback> initCallback_ = std::make_shared<DeviceInitCallBack>();
137     DeviceManager::GetInstance().InitDeviceManager(pkgName, initCallback_);
138 }
139 
TearDownTestCase()140 void DistributedSchedConnectTest::TearDownTestCase()
141 {
142 }
143 
SetUp()144 void DistributedSchedConnectTest::SetUp()
145 {
146     DistributedSchedUtil::MockPermission();
147 }
148 
TearDown()149 void DistributedSchedConnectTest::TearDown()
150 {
151 }
152 
OnRemoteDied()153 void DistributedSchedConnectTest::DeviceInitCallBack::OnRemoteDied()
154 {
155 }
156 
AddSession(const sptr<IRemoteObject> & connect,const std::string & localDeviceId,const std::string & remoteDeviceId,const AAFwk::Want & want) const157 void DistributedSchedConnectTest::AddSession(const sptr<IRemoteObject>& connect,
158     const std::string& localDeviceId, const std::string& remoteDeviceId, const AAFwk::Want& want) const
159 {
160     if (connect == nullptr) {
161         return;
162     }
163 
164     std::lock_guard<std::mutex> autoLock(DistributedSchedService::GetInstance().distributedLock_);
165     CallerInfo callerInfo;
166     callerInfo.uid = IPCSkeleton::GetCallingUid();
167     callerInfo.pid = IPCSkeleton::GetCallingRealPid();
168     callerInfo.sourceDeviceId = localDeviceId;
169     callerInfo.callerType = CALLER_TYPE_HARMONY;
170     DistributedSchedService::GetInstance().RemoteConnectAbilityMappingLocked(connect, localDeviceId,
171         remoteDeviceId, want.GetElement(), callerInfo, TargetComponent::HARMONY_COMPONENT);
172 }
173 
RemoveSession(const sptr<IRemoteObject> & connect) const174 void DistributedSchedConnectTest::RemoveSession(const sptr<IRemoteObject>& connect) const
175 {
176     if (connect == nullptr) {
177         return;
178     }
179 
180     std::lock_guard<std::mutex> autoLock(DistributedSchedService::GetInstance().distributedLock_);
181     DistributedSchedService::GetInstance().distributedConnectAbilityMap_.erase(connect);
182 }
183 
AddConnectInfo(const sptr<IRemoteObject> & connect,const std::string & localDeviceId,const std::string & remoteDeviceId) const184 void DistributedSchedConnectTest::AddConnectInfo(const sptr<IRemoteObject>& connect,
185     const std::string& localDeviceId, const std::string& remoteDeviceId) const
186 {
187     if (connect == nullptr) {
188         return;
189     }
190 
191     std::lock_guard<std::mutex> autoLock(DistributedSchedService::GetInstance().distributedLock_);
192     CallerInfo callerInfo;
193     callerInfo.uid = IPCSkeleton::GetCallingUid();
194     callerInfo.pid = IPCSkeleton::GetCallingRealPid();
195     callerInfo.sourceDeviceId = localDeviceId;
196     callerInfo.callerType = CALLER_TYPE_HARMONY;
197 
198     sptr<IRemoteObject> callbackWrapper(new AbilityConnectionWrapperStubTest(connect));
199     ConnectInfo connectInfo {callerInfo, callbackWrapper};
200     DistributedSchedService::GetInstance().connectAbilityMap_.emplace(connect, connectInfo);
201 }
202 
RemoveConnectInfo(const sptr<IRemoteObject> & connect) const203 void DistributedSchedConnectTest::RemoveConnectInfo(const sptr<IRemoteObject>& connect) const
204 {
205     if (connect == nullptr) {
206         return;
207     }
208 
209     std::lock_guard<std::mutex> autoLock(DistributedSchedService::GetInstance().distributedLock_);
210     DistributedSchedService::GetInstance().connectAbilityMap_.erase(connect);
211 }
212 
AddConnectCount(int32_t uid) const213 void DistributedSchedConnectTest::AddConnectCount(int32_t uid) const
214 {
215     if (uid < 0) {
216         return;
217     }
218 
219     auto& trackingUidMap = DistributedSchedService::GetInstance().trackingUidMap_;
220     ++trackingUidMap[uid];
221 }
222 
DecreaseConnectCount(int32_t uid) const223 void DistributedSchedConnectTest::DecreaseConnectCount(int32_t uid) const
224 {
225     if (uid < 0) {
226         return;
227     }
228 
229     DistributedSchedService::GetInstance().DecreaseConnectLocked(uid);
230 }
231 
GetDms()232 sptr<IDistributedSched> DistributedSchedConnectTest::GetDms()
233 {
234     auto sm = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
235     if (sm == nullptr) {
236         DTEST_LOG << "DistributedSchedConnectTest sm is nullptr" << std::endl;
237         return nullptr;
238     }
239     auto distributedObject = sm->GetSystemAbility(DISTRIBUTED_SCHED_SA_ID);
240     if (distributedObject == nullptr) {
241         DTEST_LOG << "distributedObject sm is nullptr" << std::endl;
242         return nullptr;
243     }
244     return iface_cast<IDistributedSched>(distributedObject);
245 }
246 
247 /**
248  * @tc.name: DumpConnectInfo_001
249  * @tc.desc: dump connect ability info by call Dump
250  * @tc.type: FUNC
251  */
252 HWTEST_F(DistributedSchedConnectTest, DumpConnectInfo_001, TestSize.Level1)
253 {
254     DTEST_LOG << "DistributedSchedServiceTest DumpConnectInfo_001 start " << std::endl;
255     sptr<ISystemAbilityManager> samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
256     if (samgr == nullptr) {
257         DTEST_LOG << "DistributedSchedServiceTest DumpConnectInfo_001 samgr null" << std::endl;
258     } else {
259         DTEST_LOG << "DistributedSchedServiceTest DumpConnectInfo_001 available" << std::endl;
260     }
261 
262     auto dms = samgr->GetSystemAbility(DISTRIBUTED_SCHED_SA_ID);
263     ASSERT_NE(nullptr, dms);
264     std::vector<std::u16string> args;
265     args.push_back(u"-connect");
266     int32_t result = dms->Dump(STDOUT_FD, args);
267     DTEST_LOG << "DistributedSchedServiceTest DumpConnectInfo_001 dump result: " << result << std::endl;
268 }
269 
270 /**
271  * @tc.name: DumpConnectInfo_002
272  * @tc.desc: dump connect ability info by call DumpConnectInfo
273  * @tc.type: FUNC
274  */
275 HWTEST_F(DistributedSchedConnectTest, DumpConnectInfo_002, TestSize.Level0)
276 {
277     DTEST_LOG << "DistributedSchedServiceTest DumpConnectInfo_002 start" << std::endl;
278     OHOS::AAFwk::Want want;
279     want.SetElementName("", "ohos.demo.bundleName", "abilityName");
280 
281     /**
282      * @tc.steps: step1. add one session
283      */
284     sptr<AbilityConnectCallbackTest> connect(new AbilityConnectCallbackTest());
285     AddSession(connect, "123_local_device_id", "123_remote_device_id", want);
286     /**
287      * @tc.steps: step2. and then dump connection info
288      * @tc.expected: step2. can find the newly-added connect session
289      */
290     std::string dumpInfo;
291     DistributedSchedService::GetInstance().DumpConnectInfo(dumpInfo);
292     DTEST_LOG << "DistributedSchedServiceTest DumpConnectInfo_002 dumpInfo " << dumpInfo << std::endl;
293     std::string::size_type pos = dumpInfo.find("123_remote_device_id");
294     EXPECT_NE(pos, std::string::npos);
295 
296     RemoveSession(connect);
297 }
298 
299 /**
300  * @tc.name: ProcessConnectDied001
301  * @tc.desc: process connect died
302  * @tc.type: FUNC
303  */
304 HWTEST_F(DistributedSchedConnectTest, ProcessConnectDied001, TestSize.Level1)
305 {
306     DTEST_LOG << "DistributedSchedServiceTest ProcessConnectDied001 start" << std::endl;
307     OHOS::AAFwk::Want want;
308     want.SetElementName("", "ohos.demo.bundleName", "abilityName");
309     auto& connectionMap = DistributedSchedService::GetInstance().distributedConnectAbilityMap_;
310     auto& distributedLock = DistributedSchedService::GetInstance().distributedLock_;
311 
312     /**
313      * @tc.steps: step1. add one session and check the map
314      * @tc.expected: step1. can find the newly-added connect session
315      */
316     sptr<AbilityConnectCallbackTest> connect(new AbilityConnectCallbackTest());
317     AddSession(connect, "123_local_device_id", "123_remote_device_id", want);
318     {
319         std::lock_guard<std::mutex> autoLock(distributedLock);
320         EXPECT_EQ(connectionMap.size(), static_cast<size_t>(1));
321     }
322 
323     /**
324      * @tc.steps: step2. process connect died and then check the map
325      * @tc.expected: step2. the connect session is removed
326      */
327     DistributedSchedService::GetInstance().ProcessConnectDied(connect);
328     {
329         std::lock_guard<std::mutex> autoLock(distributedLock);
330         EXPECT_EQ(connectionMap.size(), static_cast<size_t>(0));
331     }
332 
333     RemoveSession(connect);
334 }
335 
336 /**
337  * @tc.name: ProcessConnectDied002
338  * @tc.desc: process connect died which is not exist
339  * @tc.type: FUNC
340  */
341 HWTEST_F(DistributedSchedConnectTest, ProcessConnectDied002, TestSize.Level0)
342 {
343     DTEST_LOG << "DistributedSchedServiceTest ProcessConnectDied002 start" << std::endl;
344     OHOS::AAFwk::Want want;
345     want.SetElementName("", "ohos.demo.bundleName", "abilityName");
346     auto& connectionMap = DistributedSchedService::GetInstance().distributedConnectAbilityMap_;
347     auto& distributedLock = DistributedSchedService::GetInstance().distributedLock_;
348 
349     /**
350      * @tc.steps: step1. add one session
351      * @tc.expected: step1. can find the newly-added connect session
352      */
353     sptr<AbilityConnectCallbackTest> connect(new AbilityConnectCallbackTest());
354     AddSession(connect, "123_local_device_id", "123_remote_device_id", want);
355     {
356         std::lock_guard<std::mutex> autoLock(distributedLock);
357         EXPECT_EQ(connectionMap.size(), static_cast<size_t>(1));
358     }
359 
360     /**
361      * @tc.steps: step2. process connect died which is not exist
362      * @tc.expected: step2. still can find the newly-added connect session
363      */
364     DistributedSchedService::GetInstance().ProcessConnectDied(new AbilityConnectCallbackTest());
365     {
366         std::lock_guard<std::mutex> autoLock(distributedLock);
367         EXPECT_EQ(connectionMap.size(), static_cast<size_t>(1));
368     }
369 
370     RemoveSession(connect);
371 }
372 
373 /**
374  * @tc.name: ProcessConnectDied003
375  * @tc.desc: process connect died and check the trackingUidMap_
376  * @tc.type: FUNC
377  */
378 HWTEST_F(DistributedSchedConnectTest, ProcessConnectDied003, TestSize.Level1)
379 {
380     DTEST_LOG << "DistributedSchedServiceTest ProcessConnectDied003 start" << std::endl;
381     OHOS::AAFwk::Want want;
382     want.SetElementName("", "ohos.demo.bundleName", "abilityName");
383     sptr<AbilityConnectCallbackTest> connect(new AbilityConnectCallbackTest());
384     AddSession(connect, "123_local_device_id", "123_remote_device_id", want);
385 
386     auto& trackingUidMap = DistributedSchedService::GetInstance().trackingUidMap_;
387     /**
388      * @tc.steps: step1. Increase connect count
389      * @tc.expected: step1. connect count increase one
390      */
391 
392     int32_t uid = IPCSkeleton::GetCallingUid();
393     uint32_t oldCount = trackingUidMap[uid];
394     AddConnectCount(uid);
395     EXPECT_EQ(trackingUidMap[uid] - oldCount, static_cast<uint32_t>(1));
396 
397     /**
398      * @tc.steps: step2. process connect died and then check the trackingUidMap_
399      * @tc.expected: step2. the connect count is decrease
400      */
401     DistributedSchedService::GetInstance().ProcessConnectDied(connect);
402     auto iter = trackingUidMap.find(uid);
403     if (iter != trackingUidMap.end()) {
404         EXPECT_EQ(trackingUidMap[uid], oldCount);
405     }
406 
407     RemoveConnectInfo(connect);
408 }
409 
410 /**
411  * @tc.name: ProcessConnectDied004
412  * @tc.desc: process connect died and check the connectAbilityMap_
413  * @tc.type: FUNC
414  */
415 HWTEST_F(DistributedSchedConnectTest, ProcessConnectDied004, TestSize.Level1)
416 {
417     DTEST_LOG << "DistributedSchedServiceTest ProcessConnectDied004 start" << std::endl;
418     auto& connectAbilityMap = DistributedSchedService::GetInstance().connectAbilityMap_;
419     auto& distributedLock = DistributedSchedService::GetInstance().distributedLock_;
420 
421     /**
422      * @tc.steps: step1. add one connectInfo
423      * @tc.expected: step1. can find the newly-added connectInfo
424      */
425     sptr<AbilityConnectCallbackTest> connect(new AbilityConnectCallbackTest());
426     AddConnectInfo(connect, "123_local_device_id", "123_remote_device_id");
427     {
428         std::lock_guard<std::mutex> autoLock(distributedLock);
429         EXPECT_EQ(connectAbilityMap.size(), static_cast<size_t>(1));
430     }
431 
432     /**
433      * @tc.steps: step2. process connect died and then check the connectAbilityMap_
434      * @tc.expected: step2. the connectInfo is removed
435      */
436     DistributedSchedService::GetInstance().DisconnectAbilityFromRemote(connect,
437         IPCSkeleton::GetCallingUid(), "123_local_device_id");
438     {
439         std::lock_guard<std::mutex> autoLock(distributedLock);
440         EXPECT_EQ(connectAbilityMap.size(), static_cast<size_t>(0));
441     }
442 
443     RemoveConnectInfo(connect);
444 }
445 
446 /**
447  * @tc.name: ProcessDeviceOffline001
448  * @tc.desc: process device offline with only one connection
449  * @tc.type: FUNC
450  */
451 HWTEST_F(DistributedSchedConnectTest, ProcessDeviceOffline001, TestSize.Level0)
452 {
453     DTEST_LOG << "DistributedSchedServiceTest ProcessDeviceOffline001 start" << std::endl;
454     OHOS::AAFwk::Want want;
455     want.SetElementName("", "ohos.demo.bundleName", "abilityName");
456     auto& connectionMap = DistributedSchedService::GetInstance().distributedConnectAbilityMap_;
457     auto& distributedLock = DistributedSchedService::GetInstance().distributedLock_;
458 
459     /**
460      * @tc.steps: step1. add one session
461      */
462     sptr<AbilityConnectCallbackTest> connect(new AbilityConnectCallbackTest());
463     AddSession(connect, "123_local_device_id", "123_remote_device_id", want);
464     /**
465      * @tc.steps: step2. process device offline and check the map
466      * @tc.expected: step2. the connect session is removed
467      */
468     DistributedSchedService::GetInstance().ProcessDeviceOffline("123_remote_device_id");
469     {
470         std::lock_guard<std::mutex> autoLock(distributedLock);
471         EXPECT_EQ(connectionMap.size(), static_cast<size_t>(0));
472     }
473 
474     RemoveSession(connect);
475 }
476 
477 /**
478  * @tc.name: ProcessDeviceOffline002
479  * @tc.desc: process device offline with multiple connections
480  * @tc.type: FUNC
481  */
482 HWTEST_F(DistributedSchedConnectTest, ProcessDeviceOffline002, TestSize.Level0)
483 {
484     DTEST_LOG << "DistributedSchedServiceTest ProcessDeviceOffline002 start" << std::endl;
485     OHOS::AAFwk::Want want;
486     want.SetElementName("", "ohos.demo.bundleName", "abilityName");
487     auto& connectionMap = DistributedSchedService::GetInstance().distributedConnectAbilityMap_;
488     auto& distributedLock = DistributedSchedService::GetInstance().distributedLock_;
489 
490     /**
491      * @tc.steps: step1. add one session
492      * @tc.expected: step1. can find the two newly-added connect sessions
493      */
494     sptr<AbilityConnectCallbackTest> connect1(new AbilityConnectCallbackTest());
495     AddSession(connect1, "123_local_device_id", "123_remote_device_id", want);
496     sptr<AbilityConnectCallbackTest> connect2(new AbilityConnectCallbackTest());
497     AddSession(connect2, "123_local_device_id", "123_remote_device_id", want);
498     {
499         std::lock_guard<std::mutex> autoLock(distributedLock);
500         EXPECT_EQ(connectionMap.size(), static_cast<size_t>(2));
501     }
502 
503     /**
504      * @tc.steps: step2. process device offline
505      * @tc.expected: step2. the connect sessions are removed
506      */
507     DistributedSchedService::GetInstance().ProcessDeviceOffline("123_remote_device_id");
508     {
509         std::lock_guard<std::mutex> autoLock(distributedLock);
510         EXPECT_EQ(connectionMap.size(), static_cast<size_t>(0));
511     }
512 
513     RemoveSession(connect1);
514     RemoveSession(connect2);
515 }
516 
517 /**
518  * @tc.name: ProcessDeviceOffline003
519  * @tc.desc: process device offline with multiple online devices
520  * @tc.type: FUNC
521  */
522 HWTEST_F(DistributedSchedConnectTest, ProcessDeviceOffline003, TestSize.Level0)
523 {
524     DTEST_LOG << "DistributedSchedServiceTest ProcessDeviceOffline003 start" << std::endl;
525     OHOS::AAFwk::Want want;
526     want.SetElementName("", "ohos.demo.bundleName", "abilityName");
527     auto& connectionMap = DistributedSchedService::GetInstance().distributedConnectAbilityMap_;
528     auto& distributedLock = DistributedSchedService::GetInstance().distributedLock_;
529 
530     /**
531      * @tc.steps: step1. add one session
532      */
533     sptr<AbilityConnectCallbackTest> connect(new AbilityConnectCallbackTest());
534     AddSession(connect, "123_local_device_id", "123_remote_device_id", want);
535     /**
536      * @tc.steps: step2. process other device offline and check the map
537      * @tc.expected: step2. still can find the newly-added connect session
538      */
539     DistributedSchedService::GetInstance().ProcessDeviceOffline("456_remote_device_id");
540     {
541         std::lock_guard<std::mutex> autoLock(distributedLock);
542         auto iter = connectionMap.find(connect);
543         EXPECT_NE(iter, connectionMap.end());
544         EXPECT_EQ(connectionMap.size(), static_cast<size_t>(1));
545     }
546 
547     RemoveSession(connect);
548 }
549 
550 /**
551  * @tc.name: ProcessDeviceOffline004
552  * @tc.desc: process device offline and check the trackingUidMap_
553  * @tc.type: FUNC
554  */
555 HWTEST_F(DistributedSchedConnectTest, ProcessDeviceOffline004, TestSize.Level1)
556 {
557     DTEST_LOG << "DistributedSchedServiceTest ProcessDeviceOffline004 start" << std::endl;
558     OHOS::AAFwk::Want want;
559     want.SetElementName("", "ohos.demo.bundleName", "abilityName");
560     sptr<AbilityConnectCallbackTest> connect(new AbilityConnectCallbackTest());
561     AddSession(connect, "123_local_device_id", "123_remote_device_id", want);
562 
563     auto& trackingUidMap = DistributedSchedService::GetInstance().trackingUidMap_;
564     /**
565      * @tc.steps: step1. Increase connect count
566      * @tc.expected: step1. connect count increase one
567      */
568     int32_t uid = IPCSkeleton::GetCallingUid();
569     uint32_t oldCount = trackingUidMap[uid];
570     AddConnectCount(uid);
571     EXPECT_EQ(trackingUidMap[uid] - oldCount, static_cast<uint32_t>(1));
572 
573     /**
574      * @tc.steps: step2. process device offline and then check the trackingUidMap_
575      * @tc.expected: step2. the connect count is decrease
576      */
577     DistributedSchedService::GetInstance().ProcessDeviceOffline("123_remote_device_id");
578     auto iter = trackingUidMap.find(uid);
579     if (iter != trackingUidMap.end()) {
580         EXPECT_EQ(trackingUidMap[uid], oldCount);
581     }
582 
583     RemoveConnectInfo(connect);
584 }
585 
586 /**
587  * @tc.name: ProcessDeviceOffline005
588  * @tc.desc: process device offline and check the connectAbilityMap_
589  * @tc.type: FUNC
590  */
591 HWTEST_F(DistributedSchedConnectTest, ProcessDeviceOffline005, TestSize.Level1)
592 {
593     DTEST_LOG << "DistributedSchedServiceTest ProcessDeviceOffline005 start" << std::endl;
594     auto& connectAbilityMap = DistributedSchedService::GetInstance().connectAbilityMap_;
595     auto& distributedLock = DistributedSchedService::GetInstance().distributedLock_;
596 
597     /**
598      * @tc.steps: step1. add one connectInfo
599      * @tc.expected: step1. can find the newly-added connectInfo
600      */
601     sptr<AbilityConnectCallbackTest> connect(new AbilityConnectCallbackTest());
602     AddConnectInfo(connect, "123_local_device_id", "123_remote_device_id");
603     {
604         std::lock_guard<std::mutex> autoLock(distributedLock);
605         EXPECT_EQ(connectAbilityMap.size(), static_cast<size_t>(1));
606     }
607 
608     /**
609      * @tc.steps: step2. process device offline and then check the connectAbilityMap_
610      * @tc.expected: step2. the connectInfo is removed
611      */
612     DistributedSchedService::GetInstance().ProcessDeviceOffline("123_local_device_id");
613     {
614         std::lock_guard<std::mutex> autoLock(distributedLock);
615         EXPECT_EQ(connectAbilityMap.size(), static_cast<size_t>(0));
616     }
617 
618     RemoveConnectInfo(connect);
619 }
620 
621 /**
622  * @tc.name: DisconnectRemoteAbility001
623  * @tc.desc: disconnect remote ability
624  * @tc.type: FUNC
625  */
626 HWTEST_F(DistributedSchedConnectTest, DisconnectRemoteAbility001, TestSize.Level0)
627 {
628     DTEST_LOG << "DistributedSchedServiceTest DisconnectRemoteAbility001 start" << std::endl;
629     OHOS::AAFwk::Want want;
630     want.SetElementName("", "ohos.demo.bundleName", "abilityName");
631     auto& connectionMap = DistributedSchedService::GetInstance().distributedConnectAbilityMap_;
632     auto& distributedLock = DistributedSchedService::GetInstance().distributedLock_;
633 
634     /**
635      * @tc.steps: step1. add one session
636      */
637     sptr<AbilityConnectCallbackTest> connect(new AbilityConnectCallbackTest());
638     AddSession(connect, "123_local_device_id", "123_remote_device_id", want);
639     /**
640      * @tc.steps: step2. disconnect the ability and check the map
641      * @tc.expected: step2. the connect session is removed
642      */
643     DistributedSchedService::GetInstance().DisconnectRemoteAbility(connect, 0, 0);
644     {
645         std::lock_guard<std::mutex> autoLock(distributedLock);
646         EXPECT_EQ(connectionMap.size(), static_cast<size_t>(0));
647     }
648 
649     RemoveSession(connect);
650 }
651 
652 /**
653  * @tc.name: DisconnectRemoteAbility002
654  * @tc.desc: disconnect remote ability and check the trackingUidMap_
655  * @tc.type: FUNC
656  */
657 HWTEST_F(DistributedSchedConnectTest, DisconnectRemoteAbility002, TestSize.Level1)
658 {
659     DTEST_LOG << "DistributedSchedServiceTest DisconnectRemoteAbility002 start" << std::endl;
660     OHOS::AAFwk::Want want;
661     want.SetElementName("", "ohos.demo.bundleName", "abilityName");
662     sptr<AbilityConnectCallbackTest> connect(new AbilityConnectCallbackTest());
663     AddSession(connect, "123_local_device_id", "123_remote_device_id", want);
664 
665     auto& trackingUidMap = DistributedSchedService::GetInstance().trackingUidMap_;
666     /**
667      * @tc.steps: step1. Increase connect count
668      * @tc.expected: step1. connect count increase one
669      */
670     int32_t uid = IPCSkeleton::GetCallingUid();
671     uint32_t oldCount = trackingUidMap[uid];
672     AddConnectCount(uid);
673     uint32_t newCount = trackingUidMap[uid];
674     EXPECT_EQ(newCount - oldCount, static_cast<uint32_t>(1));
675 
676     /**
677      * @tc.steps: step2. disconnect remote ability and then check the trackingUidMap_
678      * @tc.expected: step2. the connect count is decrease
679      */
680     DistributedSchedService::GetInstance().DisconnectRemoteAbility(connect, 0, 0);
681     auto iter = trackingUidMap.find(uid);
682     if (iter != trackingUidMap.end()) {
683         EXPECT_EQ(trackingUidMap[uid], oldCount);
684     }
685 
686     RemoveConnectInfo(connect);
687 }
688 
689 /**
690  * @tc.name: DisconnectRemoteAbility003
691  * @tc.desc: disconnect remote ability whith error callback
692  * @tc.type: FUNC
693  * @tc.require: I5OOKG
694  */
695 HWTEST_F(DistributedSchedConnectTest, DisconnectRemoteAbility003, TestSize.Level4)
696 {
697     DTEST_LOG << "DistributedSchedServiceTest DisconnectRemoteAbility003 start" << std::endl;
698     int32_t ret = DistributedSchedService::GetInstance().DisconnectRemoteAbility(nullptr, 0, 0);
699     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
700     DTEST_LOG << "DistributedSchedServiceTest DisconnectRemoteAbility003 end" << std::endl;
701 }
702 
703 /**
704  * @tc.name: ConnectRemoteAbility
705  * @tc.desc: connect remote ability whith error uid and pid
706  * @tc.type: FUNC
707  * @tc.require: I5OOKG
708  */
709 HWTEST_F(DistributedSchedConnectTest, ConnectRemoteAbility001, TestSize.Level4)
710 {
711     DTEST_LOG << "DistributedSchedServiceTest ConnectRemoteAbility001 start" << std::endl;
712     OHOS::AAFwk::Want want;
713     want.SetElementName("123_remote_device_id", "ohos.demo.bundleName", "abilityName");
714     sptr<AbilityConnectCallbackTest> connect(new AbilityConnectCallbackTest());
715     int32_t ret = DistributedSchedService::GetInstance().ConnectRemoteAbility(want, connect, -1, -1, -1);
716     EXPECT_EQ(ret, BIND_ABILITY_UID_INVALID_ERR);
717     DTEST_LOG << "DistributedSchedServiceTest ConnectRemoteAbility001 end" << std::endl;
718 }
719 
720 /**
721  * @tc.name: ConnectRemoteAbility
722  * @tc.desc: connect remote ability whith empty deviceId.
723  * @tc.type: FUNC
724  * @tc.require: I5OOKG
725  */
726 HWTEST_F(DistributedSchedConnectTest, ConnectRemoteAbility002, TestSize.Level4)
727 {
728     DTEST_LOG << "DistributedSchedServiceTest ConnectRemoteAbility002 start" << std::endl;
729     OHOS::AAFwk::Want want;
730     want.SetElementName("", "ohos.demo.bundleName", "abilityName");
731     sptr<AbilityConnectCallbackTest> connect(new AbilityConnectCallbackTest());
732     int32_t ret = DistributedSchedService::GetInstance().ConnectRemoteAbility(want, connect, -1, -1, -1);
733     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
734     DTEST_LOG << "DistributedSchedServiceTest ConnectRemoteAbility002 end" << std::endl;
735 }
736 
737 /**
738  * @tc.name: ConnectRemoteAbility
739  * @tc.desc: user is not foreground
740  * @tc.type: FUNC
741  * @tc.require: I5OOKG
742  */
743 HWTEST_F(DistributedSchedConnectTest, ConnectRemoteAbility006, TestSize.Level4)
744 {
745     DTEST_LOG << "DistributedSchedServiceTest ConnectRemoteAbility006 start" << std::endl;
746     OHOS::AAFwk::Want want;
747     want.SetElementName("123_remote_device_id", "ohos.demo.bundleName", "abilityName");
748     sptr<AbilityConnectCallbackTest> connect(new AbilityConnectCallbackTest());
749     g_isForeground = false;
750     int32_t ret = DistributedSchedService::GetInstance().ConnectRemoteAbility(want, connect, -1, -1, -1);
751     EXPECT_EQ(ret, DMS_NOT_FOREGROUND_USER);
752     DTEST_LOG << "DistributedSchedServiceTest ConnectRemoteAbility006 end" << std::endl;
753 }
754 
755 /**
756  * @tc.name: ConnectAbilityFromRemote
757  * @tc.desc: connect remote ability whith fake deviceId.
758  * @tc.type: FUNC
759  * @tc.require: I5OOKG
760  */
761 HWTEST_F(DistributedSchedConnectTest, ConnectAbilityFromRemote001, TestSize.Level3)
762 {
763     DTEST_LOG << "DistributedSchedConnectTest ConnectAbilityFromRemote001 start" << std::endl;
764     OHOS::AAFwk::Want want;
765     want.SetElementName("123_remote_device_id", "ohos.demo.bundleName", "abilityName");
766     AppExecFwk::AbilityInfo abilityInfo;
767     sptr<AbilityConnectCallbackTest> connect(new AbilityConnectCallbackTest());
768     CallerInfo callerInfo;
769     IDistributedSched::AccountInfo accountInfo;
770     int32_t ret = DistributedSchedService::GetInstance().ConnectAbilityFromRemote(want,
771         abilityInfo, connect, callerInfo, accountInfo);
772     EXPECT_EQ(ret, INVALID_REMOTE_PARAMETERS_ERR);
773     DTEST_LOG << "DistributedSchedConnectTest ConnectAbilityFromRemote001 end" << std::endl;
774 }
775 
776 /**
777  * @tc.name: ConnectAbilityFromRemote
778  * @tc.desc: connect remote ability whith error callback.
779  * @tc.type: FUNC
780  * @tc.require: I5OOKG
781  */
782 HWTEST_F(DistributedSchedConnectTest, ConnectAbilityFromRemote002, TestSize.Level4)
783 {
784     DTEST_LOG << "DistributedSchedConnectTest ConnectAbilityFromRemote002 start" << std::endl;
785     OHOS::AAFwk::Want want;
786     want.SetElementName("123_remote_device_id", "ohos.demo.bundleName", "abilityName");
787     AppExecFwk::AbilityInfo abilityInfo;
788     CallerInfo callerInfo;
789     IDistributedSched::AccountInfo accountInfo;
790     int32_t ret = DistributedSchedService::GetInstance().ConnectAbilityFromRemote(want,
791         abilityInfo, nullptr, callerInfo, accountInfo);
792     EXPECT_EQ(ret, INVALID_REMOTE_PARAMETERS_ERR);
793     DTEST_LOG << "DistributedSchedConnectTest ConnectAbilityFromRemote002 end" << std::endl;
794 }
795 
796 /**
797  * @tc.name: ConnectAbilityFromRemote
798  * @tc.desc: connect remote ability whith error param
799  * @tc.type: FUNC
800  * @tc.require: I5OOKG
801  */
802 HWTEST_F(DistributedSchedConnectTest, ConnectAbilityFromRemote003, TestSize.Level4)
803 {
804     DTEST_LOG << "DistributedSchedConnectTest ConnectAbilityFromRemote003 start" << std::endl;
805     OHOS::AAFwk::Want want;
806     want.SetElementName("", "ohos.demo.bundleName", "abilityName");
807     sptr<AbilityConnectCallbackTest> connect(new AbilityConnectCallbackTest());
808     AppExecFwk::AbilityInfo abilityInfo;
809     CallerInfo callerInfo;
810     IDistributedSched::AccountInfo accountInfo;
811     int32_t ret = DistributedSchedService::GetInstance().ConnectAbilityFromRemote(want,
812         abilityInfo, connect, callerInfo, accountInfo);
813     EXPECT_EQ(ret, INVALID_REMOTE_PARAMETERS_ERR);
814     DTEST_LOG << "DistributedSchedConnectTest ConnectAbilityFromRemote003 end" << std::endl;
815 }
816 
817 /**
818  * @tc.name: ConnectAbilityFromRemote
819  * @tc.desc: connect remote ability whith null callback
820  * @tc.type: FUNC
821  * @tc.require: I5OOKG
822  */
823 HWTEST_F(DistributedSchedConnectTest, ConnectAbilityFromRemote004, TestSize.Level4)
824 {
825     DTEST_LOG << "DistributedSchedConnectTest ConnectAbilityFromRemote004 start" << std::endl;
826     OHOS::AAFwk::Want want;
827     want.SetElementName("", "ohos.demo.bundleName", "abilityName");
828     AppExecFwk::AbilityInfo abilityInfo;
829     CallerInfo callerInfo;
830     IDistributedSched::AccountInfo accountInfo;
831     int32_t ret = DistributedSchedService::GetInstance().ConnectAbilityFromRemote(want,
832         abilityInfo, nullptr, callerInfo, accountInfo);
833     EXPECT_EQ(ret, INVALID_REMOTE_PARAMETERS_ERR);
834     DTEST_LOG << "DistributedSchedConnectTest ConnectAbilityFromRemote004 end" << std::endl;
835 }
836 
837 /**
838  * @tc.name: DisconnectEachRemoteAbilityLocked
839  * @tc.desc: disconnect remote ability.
840  * @tc.type: FUNC
841  * @tc.require: I5OOKG
842  */
843 HWTEST_F(DistributedSchedConnectTest, DisconnectEachRemoteAbilityLocked001, TestSize.Level4)
844 {
845     DTEST_LOG << "DistributedSchedConnectTest DisconnectEachRemoteAbilityLocked001 start" << std::endl;
846     int32_t ret = DistributedSchedService::GetInstance().DisconnectEachRemoteAbilityLocked("", "", nullptr);
847     EXPECT_NE(ret, ERR_OK);
848     DTEST_LOG << "DistributedSchedConnectTest DisconnectEachRemoteAbilityLocked001 end" << std::endl;
849 }
850 
851 /**
852  * @tc.name: DisconnectEachRemoteAbilityLocked
853  * @tc.desc: disconnect remote ability.
854  * @tc.type: FUNC
855  * @tc.require: I5OOKG
856  */
857 HWTEST_F(DistributedSchedConnectTest, DisconnectEachRemoteAbilityLocked002, TestSize.Level4)
858 {
859     DTEST_LOG << "DistributedSchedConnectTest DisconnectEachRemoteAbilityLocked002 start" << std::endl;
860     sptr<AbilityConnectCallbackTest> connect(new AbilityConnectCallbackTest());
861     int32_t ret = DistributedSchedService::GetInstance().DisconnectEachRemoteAbilityLocked("", "", connect);
862     EXPECT_NE(ret, ERR_OK);
863     DTEST_LOG << "DistributedSchedConnectTest DisconnectEachRemoteAbilityLocked002 end" << std::endl;
864 }
865 
866 /**
867  * @tc.name: DisconnectEachRemoteAbilityLocked
868  * @tc.desc: disconnect remote ability.
869  * @tc.type: FUNC
870  * @tc.require: I5OOKG
871  */
872 HWTEST_F(DistributedSchedConnectTest, DisconnectEachRemoteAbilityLocked003, TestSize.Level3)
873 {
874     DTEST_LOG << "DistributedSchedConnectTest DisconnectEachRemoteAbilityLocked003 start" << std::endl;
875     sptr<AbilityConnectCallbackTest> connect(new AbilityConnectCallbackTest());
876     int32_t ret = DistributedSchedService::GetInstance().DisconnectEachRemoteAbilityLocked(
877         "123_remote_device_id", "123_remote_device_id", connect);
878     EXPECT_NE(ret, ERR_OK);
879     DTEST_LOG << "DistributedSchedConnectTest DisconnectEachRemoteAbilityLocked003 end" << std::endl;
880 }
881 
882 /**
883  * @tc.name: DisconnectEachRemoteAbilityLocked
884  * @tc.desc: disconnect remote ability.
885  * @tc.type: FUNC
886  * @tc.require: I5OOKG
887  */
888 HWTEST_F(DistributedSchedConnectTest, DisconnectEachRemoteAbilityLocked004, TestSize.Level3)
889 {
890     DTEST_LOG << "DistributedSchedConnectTest DisconnectEachRemoteAbilityLocked004 start" << std::endl;
891     sptr<AbilityConnectCallbackTest> connect(new AbilityConnectCallbackTest());
892     std::string deviceId;
893     DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(deviceId);
894     int32_t ret = DistributedSchedService::GetInstance().DisconnectEachRemoteAbilityLocked(
895         deviceId, deviceId, connect);
896     EXPECT_NE(ret, ERR_OK);
897     DTEST_LOG << "DistributedSchedConnectTest DisconnectEachRemoteAbilityLocked004 end" << std::endl;
898 }
899 
900 /**
901  * @tc.name: DisconnectRemoteAbility
902  * @tc.desc: disconnect remote ability.
903  * @tc.type: FUNC
904  * @tc.require: I5OOKG
905  */
906 HWTEST_F(DistributedSchedConnectTest, DisconnectRemoteAbility004, TestSize.Level4)
907 {
908     DTEST_LOG << "DistributedSchedConnectTest DisconnectRemoteAbility004 start" << std::endl;
909     sptr<AbilityConnectCallbackTest> connect(new AbilityConnectCallbackTest());
910     int32_t ret = DistributedSchedService::GetInstance().DisconnectRemoteAbility(connect, 0, 0);
911     EXPECT_NE(ret, ERR_OK);
912     DTEST_LOG << "DistributedSchedConnectTest DisconnectRemoteAbility004 end" << std::endl;
913 }
914 
915 /**
916  * @tc.name: DisconnectRemoteAbility
917  * @tc.desc: disconnect remote ability.
918  * @tc.type: FUNC
919  * @tc.require: I5OOKG
920  */
921 HWTEST_F(DistributedSchedConnectTest, DisconnectRemoteAbility005, TestSize.Level4)
922 {
923     DTEST_LOG << "DistributedSchedConnectTest DisconnectRemoteAbility005 start" << std::endl;
924     /**
925      * @tc.steps: step1. call RemoveCallerComponent
926      */
927     DTEST_LOG << "DistributedSchedServiceTest RemoveCallerComponent001 start" << std::endl;
928     OHOS::AAFwk::Want want;
929     std::string localDeviceId = "123_local_device_id";
930     std::string remoteDeviceId = "123_remote_device_id";
931     want.SetElementName(remoteDeviceId, "ohos.demo.bundleName", "abilityName");
932     sptr<AbilityConnectCallbackTest> connect(new AbilityConnectCallbackTest());
933     CallerInfo callerInfo;
934     callerInfo.uid = IPCSkeleton::GetCallingUid();
935     callerInfo.pid = IPCSkeleton::GetCallingRealPid();
936     callerInfo.sourceDeviceId = localDeviceId;
937     callerInfo.callerType = CALLER_TYPE_HARMONY;
938     DistributedSchedService::GetInstance().SaveCallerComponent(want, connect, callerInfo);
939     DistributedSchedService::GetInstance().RemoveCallerComponent(connect);
940     DTEST_LOG << "DistributedSchedServiceTest RemoveCallerComponent001 end" << std::endl;
941 
942     int32_t ret = DistributedSchedService::GetInstance().DisconnectRemoteAbility(nullptr, 0, 0);
943     EXPECT_NE(ret, ERR_OK);
944     DTEST_LOG << "DistributedSchedConnectTest DisconnectRemoteAbility005 end" << std::endl;
945 }
946 
947 /**
948  * @tc.name: DisconnectAbilityFromRemote
949  * @tc.desc: disconnect ability from remote.
950  * @tc.type: FUNC
951  * @tc.require: I5OOKG
952  */
953 HWTEST_F(DistributedSchedConnectTest, DisconnectAbilityFromRemote001, TestSize.Level4)
954 {
955     DTEST_LOG << "DistributedSchedConnectTest DisconnectAbilityFromRemote001 start" << std::endl;
956     /**
957      * @tc.steps: step1. call RemoveCallerComponent
958      */
959     DTEST_LOG << "DistributedSchedServiceTest SaveCallerComponent002 start" << std::endl;
960     std::string localDeviceId = "123_local_device_id";
961     std::string remoteDeviceId = "123_remote_device_id";
962     OHOS::AAFwk::Want want1;
963     want1.SetElementName(remoteDeviceId, "ohos.demo.bundleName1", "abilityName1");
964     OHOS::AAFwk::Want want2;
965     want2.SetElementName(remoteDeviceId, "ohos.demo.bundleName2", "abilityName2");
966     sptr<AbilityConnectCallbackTest> connect(new AbilityConnectCallbackTest());
967     CallerInfo callerInfo;
968     callerInfo.uid = IPCSkeleton::GetCallingUid();
969     callerInfo.pid = IPCSkeleton::GetCallingRealPid();
970     callerInfo.sourceDeviceId = localDeviceId;
971     callerInfo.callerType = CALLER_TYPE_HARMONY;
972     DistributedSchedService::GetInstance().SaveCallerComponent(want1, connect, callerInfo);
973     DistributedSchedService::GetInstance().SaveCallerComponent(want2, connect, callerInfo);
974     DTEST_LOG << "DistributedSchedServiceTest SaveCallerComponent002 end" << std::endl;
975 
976     int32_t ret = DistributedSchedService::GetInstance().DisconnectAbilityFromRemote(nullptr, 0, "");
977     EXPECT_NE(ret, ERR_OK);
978     DTEST_LOG << "DistributedSchedConnectTest DisconnectAbilityFromRemote001 end" << std::endl;
979 }
980 
981 /**
982  * @tc.name: DisconnectAbilityFromRemote
983  * @tc.desc: disconnect ability from remote.
984  * @tc.type: FUNC
985  * @tc.require: I5OOKG
986  */
987 HWTEST_F(DistributedSchedConnectTest, DisconnectAbilityFromRemote002, TestSize.Level4)
988 {
989     DTEST_LOG << "DistributedSchedConnectTest DisconnectAbilityFromRemote002 start" << std::endl;
990     sptr<AbilityConnectCallbackTest> connect(new AbilityConnectCallbackTest());
991     int32_t ret = DistributedSchedService::GetInstance().DisconnectAbilityFromRemote(connect, 0, "");
992     EXPECT_NE(ret, ERR_OK);
993     DTEST_LOG << "DistributedSchedConnectTest DisconnectAbilityFromRemote002 end" << std::endl;
994 }
995 
996 /**
997  * @tc.name: DisconnectAbilityFromRemote
998  * @tc.desc: disconnect ability from remote.
999  * @tc.type: FUNC
1000  * @tc.require: I5OOKG
1001  */
1002 HWTEST_F(DistributedSchedConnectTest, DisconnectAbilityFromRemote003, TestSize.Level4)
1003 {
1004     DTEST_LOG << "DistributedSchedConnectTest DisconnectAbilityFromRemote003 start" << std::endl;
1005     sptr<AbilityConnectCallbackTest> connect(new AbilityConnectCallbackTest());
1006     std::string deviceId;
1007     DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(deviceId);
1008     int32_t ret = DistributedSchedService::GetInstance().DisconnectAbilityFromRemote(connect, 0, deviceId);
1009     EXPECT_NE(ret, ERR_OK);
1010     DTEST_LOG << "DistributedSchedConnectTest DisconnectAbilityFromRemote003 end" << std::endl;
1011 }
1012 
1013 /**
1014  * @tc.name: DisconnectAbilityFromRemote
1015  * @tc.desc: disconnect ability from remote.
1016  * @tc.type: FUNC
1017  * @tc.require: I5OOKG
1018  */
1019 HWTEST_F(DistributedSchedConnectTest, DisconnectAbilityFromRemote004, TestSize.Level4)
1020 {
1021     DTEST_LOG << "DistributedSchedConnectTest DisconnectAbilityFromRemote004 start" << std::endl;
1022     sptr<AbilityConnectCallbackTest> connect(new AbilityConnectCallbackTest());
1023     /**
1024      * @tc.steps: step1. call SaveCallerComponent
1025      */
1026     DTEST_LOG << "DistributedSchedServiceTest SaveCallerComponent001 start" << std::endl;
1027     OHOS::AAFwk::Want want;
1028     std::string localDeviceId = "123_local_device_id";
1029     std::string remoteDeviceId = "123_remote_device_id";
1030     want.SetElementName(remoteDeviceId, "ohos.demo.bundleName", "abilityName");
1031     CallerInfo callerInfo;
1032     callerInfo.uid = IPCSkeleton::GetCallingUid();
1033     callerInfo.pid = IPCSkeleton::GetCallingRealPid();
1034     callerInfo.sourceDeviceId = localDeviceId;
1035     callerInfo.callerType = CALLER_TYPE_HARMONY;
1036     DistributedSchedService::GetInstance().SaveCallerComponent(want, connect, callerInfo);
1037     DTEST_LOG << "DistributedSchedServiceTest SaveCallerComponent001 end" << std::endl;
1038 
1039     int32_t ret = DistributedSchedService::GetInstance().DisconnectAbilityFromRemote(
1040         connect, 0, "123_remote_device_id");
1041     EXPECT_NE(ret, ERR_OK);
1042     DTEST_LOG << "DistributedSchedConnectTest DisconnectAbilityFromRemote004 end" << std::endl;
1043 }
1044 
1045 /**
1046  * @tc.name: ProcessDeviceOffline
1047  * @tc.desc: device offline, clear the connect info using fake deviceId.
1048  * @tc.type: FUNC
1049  * @tc.require: I5OOKG
1050  */
1051 HWTEST_F(DistributedSchedConnectTest, ProcessDeviceOffline006, TestSize.Level3)
1052 {
1053     DTEST_LOG << "DistributedSchedConnectTest ProcessDeviceOffline006 start" << std::endl;
1054     EXPECT_NO_FATAL_FAILURE(DistributedSchedService::GetInstance().ProcessDeviceOffline("123_remote_device_id"));
1055     DTEST_LOG << "DistributedSchedConnectTest ProcessDeviceOffline006 end" << std::endl;
1056 }
1057 
1058 /**
1059  * @tc.name: ProcessDeviceOffline
1060  * @tc.desc: device offline, clear connect info using empty deviceId.
1061  * @tc.type: FUNC
1062  * @tc.require: I5OOKG
1063  */
1064 HWTEST_F(DistributedSchedConnectTest, ProcessDeviceOffline007, TestSize.Level4)
1065 {
1066     DTEST_LOG << "DistributedSchedConnectTest ProcessDeviceOffline007 start" << std::endl;
1067     EXPECT_NO_FATAL_FAILURE(DistributedSchedService::GetInstance().ProcessDeviceOffline(""));
1068     DTEST_LOG << "DistributedSchedConnectTest ProcessDeviceOffline007 end" << std::endl;
1069 }
1070 
1071 /**
1072  * @tc.name: ProcessDeviceOffline
1073  * @tc.desc: device offline, clear connect info using local deviceId.
1074  * @tc.type: FUNC
1075  * @tc.require: I5OOKG
1076  */
1077 HWTEST_F(DistributedSchedConnectTest, ProcessDeviceOffline008, TestSize.Level3)
1078 {
1079     DTEST_LOG << "DistributedSchedConnectTest ProcessDeviceOffline008 start" << std::endl;
1080     std::string deviceId;
1081     DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(deviceId);
1082     EXPECT_NO_FATAL_FAILURE(DistributedSchedService::GetInstance().ProcessDeviceOffline(deviceId));
1083     DTEST_LOG << "DistributedSchedConnectTest ProcessDeviceOffline008 end" << std::endl;
1084 }
1085 
1086 /**
1087  * @tc.name: NotifyApp
1088  * @tc.desc: notify app to dealwith the offline message.
1089  * @tc.type: FUNC
1090  * @tc.require: I5OOKG
1091  */
1092 HWTEST_F(DistributedSchedConnectTest, NotifyApp001, TestSize.Level3)
1093 {
1094     DTEST_LOG << "DistributedSchedConnectTest NotifyApp001 start" << std::endl;
1095     AppExecFwk::ElementName element;
1096     sptr<AbilityConnectCallbackTest> connect(new AbilityConnectCallbackTest());
1097     /**
1098      * @tc.steps: step1. call ProcessCalleeDied
1099      */
1100     DTEST_LOG << "DistributedSchedServiceTest ProcessCalleeDied002 start" << std::endl;
1101     sptr<IRemoteObject> callbackWrapper(new AbilityConnectionWrapperStubTest(connect));
1102     CallerInfo callerInfo;
1103     ConnectInfo connectInfo {callerInfo, callbackWrapper};
1104     DistributedSchedService::GetInstance().calleeMap_.emplace(connect, connectInfo);
1105     DistributedSchedService::GetInstance().ProcessCalleeDied(connect);
1106     DTEST_LOG << "DistributedSchedServiceTest ProcessCalleeDied002 end" << std::endl;
1107 
1108     int32_t ret = DistributedSchedService::GetInstance().NotifyApp(connect, element, 0);
1109     EXPECT_EQ(ret, ERR_OK);
1110     DTEST_LOG << "DistributedSchedConnectTest NotifyApp001 end" << std::endl;
1111 }
1112 
1113 /**
1114  * @tc.name: NotifyApp
1115  * @tc.desc: notify app to dealwith the offline message.
1116  * @tc.type: FUNC
1117  * @tc.require: I5OOKG
1118  */
1119 HWTEST_F(DistributedSchedConnectTest, NotifyApp002, TestSize.Level4)
1120 {
1121     DTEST_LOG << "DistributedSchedConnectTest NotifyApp002 start" << std::endl;
1122     AppExecFwk::ElementName element;
1123     /**
1124      * @tc.steps: step1. call ProcessCalleeDied
1125      */
1126     DTEST_LOG << "DistributedSchedServiceTest ProcessCalleeDied001 start" << std::endl;
1127     DistributedSchedService::GetInstance().ProcessCalleeDied(nullptr);
1128     DTEST_LOG << "DistributedSchedServiceTest ProcessCalleeDied001 end" << std::endl;
1129 
1130     int32_t ret = DistributedSchedService::GetInstance().NotifyApp(nullptr, element, 0);
1131     EXPECT_NE(ret, ERR_OK);
1132     DTEST_LOG << "DistributedSchedConnectTest NotifyApp002 end" << std::endl;
1133 }
1134 
1135 /**
1136  * @tc.name: ProcessConnectDied
1137  * @tc.desc: dealwith the app died message.
1138  * @tc.type: FUNC
1139  * @tc.require: I5OOKG
1140  */
1141 HWTEST_F(DistributedSchedConnectTest, ProcessConnectDied005, TestSize.Level4)
1142 {
1143     DTEST_LOG << "DistributedSchedConnectTest ProcessConnectDied005 start" << std::endl;
1144     DistributedSchedService::GetInstance().ProcessConnectDied(nullptr);
1145     sptr<AbilityConnectCallbackTest> connect(new AbilityConnectCallbackTest());
1146     EXPECT_NO_FATAL_FAILURE(DistributedSchedService::GetInstance().ProcessConnectDied(connect));
1147     DTEST_LOG << "DistributedSchedConnectTest ProcessConnectDied005 end" << std::endl;
1148 }
1149 
1150 /**
1151  * @tc.name: NotifyProcessDied001
1152  * @tc.desc: notify process died message to remote.
1153  * @tc.type: FUNC
1154  * @tc.require: I5OOKG
1155  */
1156 HWTEST_F(DistributedSchedConnectTest, NotifyProcessDied001, TestSize.Level4)
1157 {
1158     DTEST_LOG << "DistributedSchedConnectTest NotifyProcessDied001 start" << std::endl;
1159     TargetComponent targetComponent {TargetComponent::HARMONY_COMPONENT};
1160     CallerInfo callerInfo;
1161     DistributedSchedService::GetInstance().NotifyProcessDied("", callerInfo, targetComponent);
1162     EXPECT_NO_FATAL_FAILURE(DistributedSchedService::GetInstance().NotifyProcessDied("123_remote_device_id",
1163         callerInfo, targetComponent));
1164     DTEST_LOG << "DistributedSchedConnectTest NotifyProcessDied001 end" << std::endl;
1165 }
1166 
1167 /**
1168  * @tc.name: ProxyCallDisconnectRemoteAbility001
1169  * @tc.desc: call dms proxy DisconnectRemoteAbility
1170  * @tc.type: FUNC
1171  * @tc.require: I5OOKG
1172  */
1173 HWTEST_F(DistributedSchedConnectTest, ProxyCallDisconnectRemoteAbility001, TestSize.Level3)
1174 {
1175     DTEST_LOG << "DistributedSchedServiceTest ProxyCallDisconnectRemoteAbility001 start" << std::endl;
1176     sptr<IDistributedSched> proxy = GetDms();
1177     ASSERT_NE(nullptr, proxy);
1178     /**
1179      * @tc.steps: step1. call HandleLocalCallerDied
1180      */
1181     DTEST_LOG << "DistributedSchedServiceTest HandleLocalCallerDied002 start" << std::endl;
1182     sptr<AbilityConnectCallbackTest> connect(new AbilityConnectCallbackTest());
1183     DistributedSchedService::GetInstance().RemoveCallerComponent(connect);
1184     DistributedSchedService::GetInstance().HandleLocalCallerDied(connect);
1185     DTEST_LOG << "DistributedSchedServiceTest HandleLocalCallerDied002 end" << std::endl;
1186 
1187     int32_t ret = proxy->DisconnectRemoteAbility(nullptr, 0, 0);
1188     EXPECT_EQ(ret, ERR_NULL_OBJECT);
1189     DTEST_LOG << "DistributedSchedServiceTest ProxyCallDisconnectRemoteAbility001 end" << std::endl;
1190 }
1191 
1192 /**
1193  * @tc.name: ProxyCallDisconnectRemoteAbility002
1194  * @tc.desc: call dms proxy DisconnectRemoteAbility
1195  * @tc.type: FUNC
1196  * @tc.require: I5OOKG
1197  */
1198 HWTEST_F(DistributedSchedConnectTest, ProxyCallDisconnectRemoteAbility002, TestSize.Level3)
1199 {
1200     DTEST_LOG << "DistributedSchedServiceTest ProxyCallDisconnectRemoteAbility002 start" << std::endl;
1201     sptr<IDistributedSched> proxy = GetDms();
1202     ASSERT_NE(nullptr, proxy);
1203     sptr<AbilityConnectCallbackTest> connect(new AbilityConnectCallbackTest());
1204     /**
1205      * @tc.steps: step1. call HandleLocalCallerDied
1206      */
1207     DTEST_LOG << "DistributedSchedServiceTest HandleLocalCallerDied001 start" << std::endl;
1208     OHOS::AAFwk::Want want;
1209     std::string localDeviceId = "123_local_device_id";
1210     std::string remoteDeviceId = "123_remote_device_id";
1211     want.SetElementName(remoteDeviceId, "ohos.demo.bundleName", "abilityName");
1212     CallerInfo callerInfo;
1213     callerInfo.uid = IPCSkeleton::GetCallingUid();
1214     callerInfo.pid = IPCSkeleton::GetCallingRealPid();
1215     callerInfo.sourceDeviceId = localDeviceId;
1216     callerInfo.callerType = CALLER_TYPE_HARMONY;
1217     DistributedSchedService::GetInstance().SaveCallerComponent(want, connect, callerInfo);
1218     DistributedSchedService::GetInstance().HandleLocalCallerDied(connect);
1219     DTEST_LOG << "DistributedSchedServiceTest HandleLocalCallerDied001 end" << std::endl;
1220 
1221     int32_t ret = proxy->DisconnectRemoteAbility(connect, 0, 0);
1222     EXPECT_EQ(ret, DMS_PERMISSION_DENIED);
1223     DTEST_LOG << "DistributedSchedServiceTest ProxyCallDisconnectRemoteAbility002 end" << std::endl;
1224 }
1225 
1226 /**
1227  * @tc.name: ProxyCallConnectRemoteAbility001
1228  * @tc.desc: call dms proxy ConnectRemoteAbility
1229  * @tc.type: FUNC
1230  * @tc.require: I5OOKG
1231  */
1232 HWTEST_F(DistributedSchedConnectTest, ProxyCallConnectRemoteAbility001, TestSize.Level3)
1233 {
1234     DTEST_LOG << "DistributedSchedServiceTest ProxyCallConnectRemoteAbility001 start" << std::endl;
1235     sptr<IDistributedSched> proxy = GetDms();
1236     ASSERT_NE(nullptr, proxy);
1237     OHOS::AAFwk::Want want;
1238     want.SetElementName("123_remote_device_id", "ohos.demo.bundleName", "abilityName");
1239     sptr<AbilityConnectCallbackTest> connect(new AbilityConnectCallbackTest());
1240     /**
1241      * @tc.steps: step1. call GetUidLocked
1242      */
1243     DTEST_LOG << "DistributedSchedConnectTest GetUidLocked001 start" << std::endl;
1244     std::list<ConnectAbilitySession> sessionsList;
1245     DistributedSchedService::GetInstance().GetUidLocked(sessionsList);
1246     DTEST_LOG << "DistributedSchedConnectTest GetUidLocked001 end" << std::endl;
1247 
1248     g_isForeground = true;
1249     int32_t ret = proxy->ConnectRemoteAbility(want, connect, 0, 0, 0);
1250     EXPECT_EQ(ret, DMS_PERMISSION_DENIED);
1251     DTEST_LOG << "DistributedSchedServiceTest ProxyCallConnectRemoteAbility001 end" << std::endl;
1252 }
1253 
1254 /**
1255  * @tc.name: ProxyCallConnectRemoteAbility002
1256  * @tc.desc: call dms proxy ConnectRemoteAbility
1257  * @tc.type: FUNC
1258  * @tc.require: I5OOKG
1259  */
1260 HWTEST_F(DistributedSchedConnectTest, ProxyCallConnectRemoteAbility002, TestSize.Level3)
1261 {
1262     DTEST_LOG << "DistributedSchedServiceTest ProxyCallConnectRemoteAbility002 start" << std::endl;
1263     sptr<IDistributedSched> proxy = GetDms();
1264     ASSERT_NE(nullptr, proxy);
1265     OHOS::AAFwk::Want want;
1266     want.SetElementName("123_remote_device_id", "ohos.demo.bundleName", "abilityName");
1267     /**
1268      * @tc.steps: step1. call DecreaseConnectLocked
1269      */
1270     DTEST_LOG << "DistributedSchedConnectTest DecreaseConnectLocked002 start" << std::endl;
1271     int32_t uid = 1000;
1272     AddConnectCount(uid);
1273     DistributedSchedService::GetInstance().DecreaseConnectLocked(uid);
1274     DTEST_LOG << "DistributedSchedConnectTest DecreaseConnectLocked002 end" << std::endl;
1275 
1276     g_isForeground = true;
1277     int32_t ret = proxy->ConnectRemoteAbility(want, nullptr, 0, 0, 0);
1278     EXPECT_EQ(ret, ERR_NULL_OBJECT);
1279     DTEST_LOG << "DistributedSchedServiceTest ProxyCallConnectRemoteAbility002 end" << std::endl;
1280 }
1281 
1282 /**
1283  * @tc.name: ProxyCallConnectAbilityFromRemote001
1284  * @tc.desc: call dms proxy ConnectAbilityFromRemote
1285  * @tc.type: FUNC
1286  * @tc.require: I5OOKG
1287  */
1288 HWTEST_F(DistributedSchedConnectTest, ProxyCallConnectAbilityFromRemote001, TestSize.Level3)
1289 {
1290     DTEST_LOG << "DistributedSchedServiceTest ProxyCallConnectAbilityFromRemote001 start" << std::endl;
1291     sptr<IDistributedSched> proxy = GetDms();
1292     ASSERT_NE(nullptr, proxy);
1293     OHOS::AAFwk::Want want;
1294     want.SetElementName("123_remote_device_id", "ohos.demo.bundleName", "abilityName");
1295     AppExecFwk::AbilityInfo abilityInfo;
1296     sptr<AbilityConnectCallbackTest> connect(new AbilityConnectCallbackTest());
1297     CallerInfo callerInfo;
1298     IDistributedSched::AccountInfo accountInfo;
1299     /**
1300      * @tc.steps: step1. call DecreaseConnectLocked
1301      */
1302     DTEST_LOG << "DistributedSchedConnectTest DecreaseConnectLocked001 start" << std::endl;
1303     int32_t uid = -1;
1304     DistributedSchedService::GetInstance().DecreaseConnectLocked(uid);
1305     DTEST_LOG << "DistributedSchedConnectTest DecreaseConnectLocked001 end" << std::endl;
1306 
1307     int32_t ret = proxy->ConnectAbilityFromRemote(want, abilityInfo,
1308         connect, callerInfo, accountInfo);
1309     EXPECT_EQ(ret, REQUEST_CODE_ERR);
1310     DTEST_LOG << "DistributedSchedServiceTest ProxyCallConnectAbilityFromRemote001 end" << std::endl;
1311 }
1312 
1313 /**
1314  * @tc.name: ProxyCallConnectAbilityFromRemote002
1315  * @tc.desc: call dms proxy ConnectAbilityFromRemote
1316  * @tc.type: FUNC
1317  * @tc.require: I5OOKG
1318  */
1319 HWTEST_F(DistributedSchedConnectTest, ProxyCallConnectAbilityFromRemote002, TestSize.Level3)
1320 {
1321     DTEST_LOG << "DistributedSchedServiceTest ProxyCallConnectAbilityFromRemote002 start" << std::endl;
1322     sptr<IDistributedSched> proxy = GetDms();
1323     ASSERT_NE(nullptr, proxy);
1324     OHOS::AAFwk::Want want;
1325     want.SetElementName("123_remote_device_id", "ohos.demo.bundleName", "abilityName");
1326     AppExecFwk::AbilityInfo abilityInfo;
1327     CallerInfo callerInfo;
1328     IDistributedSched::AccountInfo accountInfo;
1329     /**
1330      * @tc.steps: step1. call CheckDistributedConnectLocked
1331      */
1332     DTEST_LOG << "DistributedSchedConnectTest CheckDistributedConnectLocked002 start" << std::endl;
1333     int32_t uid = IPCSkeleton::GetCallingUid();
1334     callerInfo.uid = uid;
1335     DistributedSchedService::GetInstance().CheckDistributedConnectLocked(callerInfo);
1336     DTEST_LOG << "DistributedSchedConnectTest CheckDistributedConnectLocked002 end" << std::endl;
1337 
1338     int32_t ret = proxy->ConnectAbilityFromRemote(want, abilityInfo,
1339         nullptr, callerInfo, accountInfo);
1340     EXPECT_EQ(ret, ERR_NULL_OBJECT);
1341     DTEST_LOG << "DistributedSchedServiceTest ProxyCallConnectAbilityFromRemote002 end" << std::endl;
1342 }
1343 
1344 /**
1345  * @tc.name: ProxyCallDisconnectAbilityFromRemote001
1346  * @tc.desc: call dms proxy DisconnectAbilityFromRemote
1347  * @tc.type: FUNC
1348  * @tc.require: I5OOKG
1349  */
1350 HWTEST_F(DistributedSchedConnectTest, ProxyCallDisconnectAbilityFromRemote001, TestSize.Level3)
1351 {
1352     DTEST_LOG << "DistributedSchedServiceTest ProxyCallDisconnectAbilityFromRemote001 start" << std::endl;
1353     sptr<IDistributedSched> proxy = GetDms();
1354     ASSERT_NE(nullptr, proxy);
1355     sptr<AbilityConnectCallbackTest> connect(new AbilityConnectCallbackTest());
1356     /**
1357      * @tc.steps: step1. call CheckDistributedConnectLocked
1358      */
1359     DTEST_LOG << "DistributedSchedConnectTest CheckDistributedConnectLocked001 start" << std::endl;
1360     int32_t uid = IPCSkeleton::GetCallingUid();
1361     CallerInfo callerInfo;
1362     callerInfo.uid = uid;
1363     AddConnectCount(uid);
1364     DistributedSchedService::GetInstance().CheckDistributedConnectLocked(callerInfo);
1365     DTEST_LOG << "DistributedSchedConnectTest CheckDistributedConnectLocked001 end" << std::endl;
1366 
1367     int32_t ret = proxy->DisconnectAbilityFromRemote(connect, 0, "");
1368     EXPECT_EQ(ret, REQUEST_CODE_ERR);
1369     DTEST_LOG << "DistributedSchedServiceTest ProxyCallDisconnectAbilityFromRemote001 end" << std::endl;
1370 }
1371 
1372 /**
1373  * @tc.name: ProxyCallDisconnectAbilityFromRemote002
1374  * @tc.desc: call dms proxy DisconnectAbilityFromRemote
1375  * @tc.type: FUNC
1376  * @tc.require: I5OOKG
1377  */
1378 HWTEST_F(DistributedSchedConnectTest, ProxyCallDisconnectAbilityFromRemote002, TestSize.Level3)
1379 {
1380     DTEST_LOG << "DistributedSchedServiceTest ProxyCallDisconnectAbilityFromRemote002 start" << std::endl;
1381     sptr<IDistributedSched> proxy = GetDms();
1382     ASSERT_NE(nullptr, proxy);
1383     /**
1384      * @tc.steps: step1. call RemoteConnectAbilityMappingLocked
1385      */
1386     DTEST_LOG << "DistributedSchedConnectTest CheckDistributedConnectLocked001 start" << std::endl;
1387     OHOS::AAFwk::Want want;
1388     want.SetElementName("", "ohos.demo.bundleName", "abilityName");
1389     sptr<AbilityConnectCallbackTest> connect(new AbilityConnectCallbackTest());
1390     std::string localDeviceId = "123_local_device_id";
1391     std::string remoteDeviceId = "123_remote_device_id";
1392     CallerInfo callerInfo;
1393     AddSession(connect, localDeviceId, remoteDeviceId, want);
1394     DistributedSchedService::GetInstance().RemoteConnectAbilityMappingLocked(connect, localDeviceId,
1395         remoteDeviceId, want.GetElement(), callerInfo, TargetComponent::HARMONY_COMPONENT);
1396     DTEST_LOG << "DistributedSchedConnectTest RemoteConnectAbilityMappingLocked001 end" << std::endl;
1397 
1398     int32_t ret = proxy->DisconnectAbilityFromRemote(nullptr, 0, "");
1399     EXPECT_EQ(ret, ERR_NULL_OBJECT);
1400     DTEST_LOG << "DistributedSchedServiceTest ProxyCallDisconnectAbilityFromRemote002 end" << std::endl;
1401 }
1402 
1403 /**
1404  * @tc.name: ConnectRemoteAbility003
1405  * @tc.desc: call ConnectRemoteAbility
1406  * @tc.type: FUNC
1407  */
1408 HWTEST_F(DistributedSchedConnectTest, ConnectRemoteAbility003, TestSize.Level4)
1409 {
1410     DTEST_LOG << "DistributedSchedServiceTest ConnectRemoteAbility003 start" << std::endl;
1411     std::string remoteDeviceId = "remoteDeviceId";
1412     OHOS::AAFwk::Want want;
1413     want.SetElementName(remoteDeviceId, "ohos.demo.bundleName", "abilityName");
1414     sptr<AbilityConnectCallbackTest> connect(new AbilityConnectCallbackTest());
1415     int32_t uid = IPCSkeleton::GetCallingUid();
1416     int32_t pid = IPCSkeleton::GetCallingRealPid();
1417     int32_t accessToken = IPCSkeleton::GetCallingTokenID();
1418 
1419     g_isForeground = true;
1420     int32_t ret = DistributedSchedService::GetInstance().ConnectRemoteAbility(want, connect, uid, pid, accessToken);
1421     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
1422     DTEST_LOG << "DistributedSchedServiceTest ConnectRemoteAbility003 end" << std::endl;
1423 }
1424 
1425 /**
1426  * @tc.name: TryConnectRemoteAbility001
1427  * @tc.desc: call TryConnectRemoteAbility
1428  * @tc.type: FUNC
1429  */
1430 HWTEST_F(DistributedSchedConnectTest, TryConnectRemoteAbility001, TestSize.Level4)
1431 {
1432     DTEST_LOG << "DistributedSchedServiceTest TryConnectRemoteAbility001 start" << std::endl;
1433     std::string remoteDeviceId = "remoteDeviceId";
1434     OHOS::AAFwk::Want want;
1435     want.SetElementName(remoteDeviceId, "ohos.demo.bundleName", "abilityName");
1436     sptr<AbilityConnectCallbackTest> connect(new AbilityConnectCallbackTest());
1437     CallerInfo callerInfo;
1438     int32_t ret = DistributedSchedService::GetInstance().TryConnectRemoteAbility(want, connect, callerInfo);
1439     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
1440     DTEST_LOG << "DistributedSchedServiceTest TryConnectRemoteAbility001 end" << std::endl;
1441 }
1442 
1443 /**
1444  * @tc.name: ProcessCallerDied001
1445  * @tc.desc: call ProcessCallerDied
1446  * @tc.type: FUNC
1447  */
1448 HWTEST_F(DistributedSchedConnectTest, ProcessCallerDied001, TestSize.Level4)
1449 {
1450     DTEST_LOG << "DistributedSchedServiceTest ProcessCallerDied001 start" << std::endl;
1451     int32_t deviceType = IDistributedSched::CALLER;
1452     EXPECT_NO_FATAL_FAILURE(DistributedSchedService::GetInstance().ProcessCallerDied(nullptr, deviceType));
1453     DTEST_LOG << "DistributedSchedServiceTest ProcessCallerDied001 end" << std::endl;
1454 }
1455 
1456 /**
1457  * @tc.name: ProcessCallerDied002
1458  * @tc.desc: call ProcessCallerDied
1459  * @tc.type: FUNC
1460  */
1461 HWTEST_F(DistributedSchedConnectTest, ProcessCallerDied002, TestSize.Level4)
1462 {
1463     DTEST_LOG << "DistributedSchedServiceTest ProcessCallerDied002 start" << std::endl;
1464     sptr<AbilityConnectCallbackTest> connect(new AbilityConnectCallbackTest());
1465     int32_t deviceType = IDistributedSched::CALLER;
1466     EXPECT_NO_FATAL_FAILURE(DistributedSchedService::GetInstance().ProcessCallerDied(connect, deviceType));
1467     DTEST_LOG << "DistributedSchedServiceTest ProcessCallerDied002 end" << std::endl;
1468 }
1469 
1470 /**
1471  * @tc.name: ProcessCallerDied003
1472  * @tc.desc: call ProcessCallerDied
1473  * @tc.type: FUNC
1474  */
1475 HWTEST_F(DistributedSchedConnectTest, ProcessCallerDied003, TestSize.Level4)
1476 {
1477     DTEST_LOG << "DistributedSchedServiceTest ProcessCallerDied003 start" << std::endl;
1478     sptr<AbilityConnectCallbackTest> connect(new AbilityConnectCallbackTest());
1479     int32_t deviceType = IDistributedSched::CALLEE;
1480     CallerInfo callerInfo;
1481     sptr<IRemoteObject> callbackWrapper(new AbilityConnectionWrapperStubTest(connect));
1482     ConnectInfo connectInfo {callerInfo, callbackWrapper};
1483     DistributedSchedService::GetInstance().calleeMap_.emplace(connect, connectInfo);
1484     EXPECT_NO_FATAL_FAILURE(DistributedSchedService::GetInstance().ProcessCallerDied(connect, deviceType));
1485     DTEST_LOG << "DistributedSchedServiceTest ProcessCallerDied003 end" << std::endl;
1486 }
1487 
1488 /**
1489  * @tc.name: AbilityConnectionWrapperStub001
1490  * @tc.desc: receive connect message
1491  * @tc.type: FUNC
1492  */
1493 HWTEST_F(DistributedSchedConnectTest, AbilityConnectionWrapperStub001, TestSize.Level3)
1494 {
1495     DTEST_LOG << "DistributedSchedServiceTest AbilityConnectionWrapperStub001 start" << std::endl;
1496     sptr<AbilityConnectCallbackTest> connect(new AbilityConnectCallbackTest());
1497     ASSERT_NE(connect, nullptr);
1498     sptr<AbilityConnectionWrapperStub> connectStub(new AbilityConnectionWrapperStub(connect));
1499     ASSERT_NE(connectStub, nullptr);
1500     MessageParcel data;
1501     ASSERT_NE(false, data.WriteInterfaceToken(CONNECTION_CALLBACK_INTERFACE_TOKEN));
1502     MessageParcel reply;
1503     MessageOption option;
1504     AppExecFwk::ElementName element;
1505     PARCEL_WRITE_HELPER_NORET(data, Parcelable, &element);
1506     PARCEL_WRITE_HELPER_NORET(data, RemoteObject, connect);
1507     PARCEL_WRITE_HELPER_NORET(data, Int32, 1);
1508     int32_t result = connectStub->OnRemoteRequest(IAbilityConnection::ON_ABILITY_CONNECT_DONE, data, reply, option);
1509     EXPECT_EQ(result, ERR_NONE);
1510     DTEST_LOG << "DistributedSchedServiceTest AbilityConnectionWrapperStub001 end" << std::endl;
1511 }
1512 
1513 /**
1514  * @tc.name: AbilityConnectionWrapperStub002
1515  * @tc.desc: receive oncall message
1516  * @tc.type: FUNC
1517  */
1518 HWTEST_F(DistributedSchedConnectTest, AbilityConnectionWrapperStub002, TestSize.Level3)
1519 {
1520     DTEST_LOG << "DistributedSchedServiceTest AbilityConnectionWrapperStub002 start" << std::endl;
1521     sptr<AbilityConnectCallbackTest> connect(new AbilityConnectCallbackTest());
1522     ASSERT_NE(connect, nullptr);
1523     sptr<AbilityConnectionWrapperStub> connectStub(new AbilityConnectionWrapperStub(connect, "localDeviceId"));
1524     ASSERT_NE(connectStub, nullptr);
1525     MessageParcel data;
1526     ASSERT_NE(false, data.WriteInterfaceToken(CONNECTION_CALLBACK_INTERFACE_TOKEN));
1527     MessageParcel reply;
1528     MessageOption option;
1529     AppExecFwk::ElementName element;
1530     PARCEL_WRITE_HELPER_NORET(data, Parcelable, &element);
1531     PARCEL_WRITE_HELPER_NORET(data, RemoteObject, connect);
1532     PARCEL_WRITE_HELPER_NORET(data, Int32, 1);
1533     int32_t result = connectStub->OnRemoteRequest(IAbilityConnection::ON_ABILITY_CONNECT_DONE, data, reply, option);
1534     EXPECT_EQ(result, ERR_NONE);
1535     DTEST_LOG << "DistributedSchedServiceTest AbilityConnectionWrapperStub002 end" << std::endl;
1536 }
1537 
1538 /**
1539  * @tc.name: AbilityConnectionWrapperStub003
1540  * @tc.desc: receive disconnect message
1541  * @tc.type: FUNC
1542  */
1543 HWTEST_F(DistributedSchedConnectTest, AbilityConnectionWrapperStub003, TestSize.Level3)
1544 {
1545     DTEST_LOG << "DistributedSchedServiceTest AbilityConnectionWrapperStub003 start" << std::endl;
1546     sptr<AbilityConnectCallbackTest> connect(new AbilityConnectCallbackTest());
1547     ASSERT_NE(connect, nullptr);
1548     sptr<AbilityConnectionWrapperStub> connectStub(new AbilityConnectionWrapperStub(connect));
1549     ASSERT_NE(connectStub, nullptr);
1550     MessageParcel data;
1551     ASSERT_NE(false, data.WriteInterfaceToken(CONNECTION_CALLBACK_INTERFACE_TOKEN));
1552     MessageParcel reply;
1553     MessageOption option;
1554     AppExecFwk::ElementName element;
1555     PARCEL_WRITE_HELPER_NORET(data, Parcelable, &element);
1556     PARCEL_WRITE_HELPER_NORET(data, Int32, 1);
1557     int32_t result = connectStub->OnRemoteRequest(IAbilityConnection::ON_ABILITY_DISCONNECT_DONE, data, reply, option);
1558     EXPECT_EQ(result, ERR_NONE);
1559     DTEST_LOG << "DistributedSchedServiceTest AbilityConnectionWrapperStub003 end" << std::endl;
1560 }
1561 
1562 /**
1563  * @tc.name: AbilityConnectionWrapperStub004
1564  * @tc.desc: receive oncall disconnect message
1565  * @tc.type: FUNC
1566  */
1567 HWTEST_F(DistributedSchedConnectTest, AbilityConnectionWrapperStub004, TestSize.Level3)
1568 {
1569     DTEST_LOG << "DistributedSchedServiceTest AbilityConnectionWrapperStub004 start" << std::endl;
1570     sptr<AbilityConnectCallbackTest> connect(new AbilityConnectCallbackTest());
1571     ASSERT_NE(connect, nullptr);
1572     sptr<AbilityConnectionWrapperStub> connectStub(new AbilityConnectionWrapperStub(connect, "localDeviceId"));
1573     ASSERT_NE(connectStub, nullptr);
1574     MessageParcel data;
1575     ASSERT_NE(false, data.WriteInterfaceToken(CONNECTION_CALLBACK_INTERFACE_TOKEN));
1576     MessageParcel reply;
1577     MessageOption option;
1578     AppExecFwk::ElementName element;
1579     PARCEL_WRITE_HELPER_NORET(data, Parcelable, &element);
1580     PARCEL_WRITE_HELPER_NORET(data, Int32, 1);
1581     int32_t result = connectStub->OnRemoteRequest(IAbilityConnection::ON_ABILITY_DISCONNECT_DONE, data, reply, option);
1582     EXPECT_EQ(result, ERR_NONE);
1583     DTEST_LOG << "DistributedSchedServiceTest AbilityConnectionWrapperStub004 end" << std::endl;
1584 }
1585 
1586 /**
1587  * @tc.name: AbilityConnectionWrapperStub005
1588  * @tc.desc: receive error connect message
1589  * @tc.type: FUNC
1590  */
1591 HWTEST_F(DistributedSchedConnectTest, AbilityConnectionWrapperStub005, TestSize.Level3)
1592 {
1593     DTEST_LOG << "DistributedSchedServiceTest AbilityConnectionWrapperStub005 start" << std::endl;
1594     sptr<AbilityConnectCallbackTest> connect(new AbilityConnectCallbackTest());
1595     ASSERT_NE(connect, nullptr);
1596     sptr<AbilityConnectionWrapperStub> connectStub(new AbilityConnectionWrapperStub(connect, "localDeviceId"));
1597     ASSERT_NE(connectStub, nullptr);
1598     MessageParcel data;
1599     MessageParcel reply;
1600     MessageOption option;
1601     // no interface token
1602     AppExecFwk::ElementName element;
1603     PARCEL_WRITE_HELPER_NORET(data, Parcelable, &element);
1604     PARCEL_WRITE_HELPER_NORET(data, Int32, 1);
1605     int32_t result = connectStub->OnRemoteRequest(IAbilityConnection::ON_ABILITY_DISCONNECT_DONE, data, reply, option);
1606     EXPECT_EQ(result, ERR_INVALID_STATE);
1607     DTEST_LOG << "DistributedSchedServiceTest AbilityConnectionWrapperStub005 end" << std::endl;
1608 }
1609 
1610 /**
1611  * @tc.name: AbilityConnectionWrapperStub006
1612  * @tc.desc: receive error connect message
1613  * @tc.type: FUNC
1614  */
1615 HWTEST_F(DistributedSchedConnectTest, AbilityConnectionWrapperStub006, TestSize.Level3)
1616 {
1617     DTEST_LOG << "DistributedSchedServiceTest AbilityConnectionWrapperStub006 start" << std::endl;
1618     sptr<AbilityConnectCallbackTest> connect(new AbilityConnectCallbackTest());
1619     ASSERT_NE(connect, nullptr);
1620     sptr<AbilityConnectionWrapperStub> connectStub(new AbilityConnectionWrapperStub(connect, "localDeviceId"));
1621     ASSERT_NE(connectStub, nullptr);
1622     MessageParcel data;
1623     MessageParcel reply;
1624     MessageOption option;
1625     ASSERT_NE(false, data.WriteInterfaceToken(CONNECTION_CALLBACK_INTERFACE_TOKEN));
1626     // no element
1627     int32_t result = connectStub->OnRemoteRequest(IAbilityConnection::ON_ABILITY_DISCONNECT_DONE, data, reply, option);
1628     EXPECT_EQ(result, ERR_INVALID_VALUE);
1629     DTEST_LOG << "DistributedSchedServiceTest AbilityConnectionWrapperStub006 end" << std::endl;
1630 }
1631 
1632 /**
1633  * @tc.name: AbilityConnectionWrapperStub007
1634  * @tc.desc: receive disconnect message
1635  * @tc.type: FUNC
1636  */
1637 HWTEST_F(DistributedSchedConnectTest, AbilityConnectionWrapperStub007, TestSize.Level3)
1638 {
1639     DTEST_LOG << "DistributedSchedServiceTest AbilityConnectionWrapperStub007 start" << std::endl;
1640     sptr<AbilityConnectCallbackTest> connect(new AbilityConnectCallbackTest());
1641     ASSERT_NE(connect, nullptr);
1642     sptr<AbilityConnectionWrapperStub> connectStub(new AbilityConnectionWrapperStub(connect, "localDeviceId"));
1643     ASSERT_NE(connectStub, nullptr);
1644     MessageParcel data;
1645     ASSERT_NE(false, data.WriteInterfaceToken(CONNECTION_CALLBACK_INTERFACE_TOKEN));
1646     MessageParcel reply;
1647     MessageOption option;
1648     AppExecFwk::ElementName element;
1649     PARCEL_WRITE_HELPER_NORET(data, Parcelable, &element);
1650     PARCEL_WRITE_HELPER_NORET(data, Int32, 1);
1651     // using error code
1652     int32_t result = connectStub->OnRemoteRequest(ERROR_CONNECT_CODE, data, reply, option);
1653     EXPECT_NE(result, ERR_NONE);
1654     DTEST_LOG << "DistributedSchedServiceTest AbilityConnectionWrapperStub007 end" << std::endl;
1655 }
1656 
1657 /**
1658  * @tc.name: AbilityConnectionWrapperStub008
1659  * @tc.desc: receive error connect message
1660  * @tc.type: FUNC
1661  */
1662 HWTEST_F(DistributedSchedConnectTest, AbilityConnectionWrapperStub008, TestSize.Level3)
1663 {
1664     DTEST_LOG << "DistributedSchedServiceTest AbilityConnectionWrapperStub008 start" << std::endl;
1665     sptr<AbilityConnectCallbackTest> connect(new AbilityConnectCallbackTest());
1666     ASSERT_NE(connect, nullptr);
1667     sptr<AbilityConnectionWrapperStub> connectStub(new AbilityConnectionWrapperStub(connect, "localDeviceId"));
1668     ASSERT_NE(connectStub, nullptr);
1669     MessageParcel data;
1670     ASSERT_NE(false, data.WriteInterfaceToken(CONNECTION_CALLBACK_INTERFACE_TOKEN));
1671     MessageParcel reply;
1672     MessageOption option;
1673     // no remoteObject
1674     AppExecFwk::ElementName element;
1675     PARCEL_WRITE_HELPER_NORET(data, Parcelable, &element);
1676     PARCEL_WRITE_HELPER_NORET(data, Int32, 1);
1677     int32_t result = connectStub->OnRemoteRequest(IAbilityConnection::ON_ABILITY_CONNECT_DONE, data, reply, option);
1678     EXPECT_NE(result, ERR_NONE);
1679     DTEST_LOG << "DistributedSchedServiceTest AbilityConnectionWrapperStub008 end" << std::endl;
1680 }
1681 }
1682 }
1683