• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-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 
16 #include "discovery_manager.h"
17 
18 #include <dlfcn.h>
19 #include <securec.h>
20 
21 #include "dm_anonymous.h"
22 #include "dm_constants.h"
23 #include "parameter.h"
24 namespace OHOS {
25 namespace DistributedHardware {
26 const int32_t DISCOVERY_TIMEOUT = 120;
27 const uint16_t DM_INVALID_FLAG_ID = 0;
28 constexpr const char* LNN_DISC_CAPABILITY = "capability";
29 constexpr const char* DISCOVERY_TIMEOUT_TASK = "deviceManagerTimer:discovery";
30 const std::string TYPE_MINE = "findDeviceMode";
31 #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE))
32 static std::mutex comDependencyLoadLock;
33 constexpr const char* LIB_DM_COMDENPENDENCY_NAME = "libdevicemanagerdependency.z.so";
34 bool DiscoveryManager::isSoLoaded_ = false;
35 IDeviceProfileConnector* DiscoveryManager::dpConnector_ = nullptr;
36 void* DiscoveryManager::dpConnectorHandle_ = nullptr;
37 #endif
38 
DiscoveryManager(std::shared_ptr<SoftbusListener> softbusListener,std::shared_ptr<IDeviceManagerServiceListener> listener)39 DiscoveryManager::DiscoveryManager(std::shared_ptr<SoftbusListener> softbusListener,
40     std::shared_ptr<IDeviceManagerServiceListener> listener) : softbusListener_(softbusListener), listener_(listener)
41 {
42     LOGI("DiscoveryManager constructor.");
43 }
44 
~DiscoveryManager()45 DiscoveryManager::~DiscoveryManager()
46 {
47 #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE))
48     CloseCommonDependencyObj();
49 #endif
50     LOGI("DiscoveryManager destructor.");
51 }
52 
EnableDiscoveryListener(const std::string & pkgName,const std::map<std::string,std::string> & discoverParam,const std::map<std::string,std::string> & filterOptions)53 int32_t DiscoveryManager::EnableDiscoveryListener(const std::string &pkgName,
54     const std::map<std::string, std::string> &discoverParam, const std::map<std::string, std::string> &filterOptions)
55 {
56     LOGI("DiscoveryManager::EnableDiscoveryListener begin for pkgName = %s.", pkgName.c_str());
57     if (pkgName.empty()) {
58         LOGE("Invalid parameter, pkgName is empty.");
59         return ERR_DM_INPUT_PARA_INVALID;
60     }
61     DmSubscribeInfo dmSubInfo;
62     dmSubInfo.subscribeId = DM_INVALID_FLAG_ID;
63     dmSubInfo.mode = DmDiscoverMode::DM_DISCOVER_MODE_PASSIVE;
64     dmSubInfo.medium = DmExchangeMedium::DM_BLE;
65     dmSubInfo.freq = DmExchangeFreq::DM_LOW;
66     dmSubInfo.isSameAccount = false;
67     dmSubInfo.isWakeRemote = false;
68     strcpy_s(dmSubInfo.capability, DM_MAX_DEVICE_CAPABILITY_LEN, DM_CAPABILITY_APPROACH);
69 
70     if (discoverParam.find(PARAM_KEY_META_TYPE) != discoverParam.end()) {
71         std::string metaType = discoverParam.find(PARAM_KEY_META_TYPE)->second;
72         LOGI("EnableDiscoveryListener, input MetaType = %s in discoverParam map.", metaType.c_str());
73     }
74     if (discoverParam.find(PARAM_KEY_SUBSCRIBE_ID) != discoverParam.end()) {
75         dmSubInfo.subscribeId = std::atoi((discoverParam.find(PARAM_KEY_SUBSCRIBE_ID)->second).c_str());
76         pkgName2SubIdMap_[pkgName] = dmSubInfo.subscribeId;
77     }
78 
79     int32_t ret = softbusListener_->RefreshSoftbusLNN(DM_PKG_NAME, dmSubInfo, LNN_DISC_CAPABILITY);
80     if (ret != DM_OK) {
81         LOGE("EnableDiscoveryListener failed, softbus refresh lnn ret: %d.", ret);
82         return ERR_DM_ENABLE_DISCOVERY_LISTENER_FAILED;
83     }
84     softbusListener_->RegisterSoftbusLnnOpsCbk(pkgName, shared_from_this());
85     return DM_OK;
86 }
87 
DisableDiscoveryListener(const std::string & pkgName,const std::map<std::string,std::string> & extraParam)88 int32_t DiscoveryManager::DisableDiscoveryListener(const std::string &pkgName,
89     const std::map<std::string, std::string> &extraParam)
90 {
91     LOGI("DiscoveryManager::DisableDiscoveryListener begin for pkgName = %s.", pkgName.c_str());
92     if (pkgName.empty()) {
93         LOGE("Invalid parameter, pkgName is empty.");
94         return ERR_DM_INPUT_PARA_INVALID;
95     }
96 
97     if (extraParam.find(PARAM_KEY_META_TYPE) != extraParam.end()) {
98         LOGI("DisableDiscoveryListener, input MetaType = %s", (extraParam.find(PARAM_KEY_META_TYPE)->second).c_str());
99     }
100     uint16_t subscribeId = DM_INVALID_FLAG_ID;
101     if (extraParam.find(PARAM_KEY_SUBSCRIBE_ID) != extraParam.end()) {
102         subscribeId = std::atoi((extraParam.find(PARAM_KEY_SUBSCRIBE_ID)->second).c_str());
103         pkgName2SubIdMap_.erase(pkgName);
104     }
105     softbusListener_->UnRegisterSoftbusLnnOpsCbk(pkgName);
106     return softbusListener_->StopRefreshSoftbusLNN(subscribeId);
107 }
108 
StartDiscovering(const std::string & pkgName,const std::map<std::string,std::string> & discoverParam,const std::map<std::string,std::string> & filterOptions)109 int32_t DiscoveryManager::StartDiscovering(const std::string &pkgName,
110                                            const std::map<std::string, std::string> &discoverParam,
111                                            const std::map<std::string, std::string> &filterOptions)
112 {
113     LOGI("DiscoveryManager::StartDiscovering begin for pkgName = %s.", pkgName.c_str());
114     if (pkgName.empty()) {
115         LOGE("Invalid parameter, pkgName is empty.");
116         return ERR_DM_INPUT_PARA_INVALID;
117     }
118     DmSubscribeInfo dmSubInfo;
119     dmSubInfo.subscribeId = DM_INVALID_FLAG_ID;
120     dmSubInfo.mode = DmDiscoverMode::DM_DISCOVER_MODE_ACTIVE;
121     dmSubInfo.medium = DmExchangeMedium::DM_AUTO;
122     dmSubInfo.freq = DmExchangeFreq::DM_SUPER_HIGH;
123     dmSubInfo.isSameAccount = false;
124     dmSubInfo.isWakeRemote = false;
125     if (discoverParam.find(PARAM_KEY_SUBSCRIBE_ID) != discoverParam.end()) {
126         dmSubInfo.subscribeId = std::atoi((discoverParam.find(PARAM_KEY_SUBSCRIBE_ID)->second).c_str());
127     }
128     if (discoverParam.find(PARAM_KEY_DISC_MEDIUM) != discoverParam.end()) {
129         int32_t medium = std::atoi((discoverParam.find(PARAM_KEY_DISC_MEDIUM)->second).c_str());
130         dmSubInfo.medium = static_cast<DmExchangeMedium>(medium);
131     }
132     if (HandleDiscoveryQueue(pkgName, dmSubInfo.subscribeId, filterOptions) != DM_OK) {
133         return ERR_DM_DISCOVERY_REPEATED;
134     }
135 
136     bool isStandardMetaNode = true;
137     if (discoverParam.find(PARAM_KEY_META_TYPE) != discoverParam.end()) {
138         MetaNodeType metaType = (MetaNodeType)(std::atoi((discoverParam.find(PARAM_KEY_META_TYPE)->second).c_str()));
139         isStandardMetaNode = (metaType == MetaNodeType::PROXY_TRANSMISION);
140     }
141 
142     softbusListener_->RegisterSoftbusLnnOpsCbk(pkgName, shared_from_this());
143     StartDiscoveryTimer();
144 
145     auto it = filterOptions.find(PARAM_KEY_FILTER_OPTIONS);
146     nlohmann::json jsonObject = nlohmann::json::parse(it->second, nullptr, false);
147     if (jsonObject.contains(TYPE_MINE)) {
148         return StartDiscovering4MineMetaNode(pkgName, dmSubInfo, it->second);
149     }
150 
151     int32_t ret = isStandardMetaNode ? StartDiscoveringNoMetaType(dmSubInfo, discoverParam) :
152             StartDiscovering4MetaType(dmSubInfo, discoverParam);
153     if (ret != DM_OK) {
154         LOGE("StartDiscovering for meta node process failed, ret = %d", ret);
155         return ERR_DM_START_DISCOVERING_FAILED;
156     }
157     return ret;
158 }
159 
StartDiscovering4MineMetaNode(const std::string & pkgName,DmSubscribeInfo & dmSubInfo,const std::string & searchJson)160 int32_t DiscoveryManager::StartDiscovering4MineMetaNode(const std::string &pkgName, DmSubscribeInfo &dmSubInfo,
161     const std::string &searchJson)
162 {
163     LOGI("StartDiscovering for mine meta node process.");
164     int32_t ret = softbusListener_->StartDiscovery(pkgName, searchJson, dmSubInfo);
165     if (ret != DM_OK) {
166         LOGE("StartDiscovering for meta node process failed, ret = %d", ret);
167         return ERR_DM_START_DISCOVERING_FAILED;
168     }
169     return ret;
170 }
171 
StartDiscoveringNoMetaType(DmSubscribeInfo & dmSubInfo,const std::map<std::string,std::string> & param)172 int32_t DiscoveryManager::StartDiscoveringNoMetaType(DmSubscribeInfo &dmSubInfo,
173     const std::map<std::string, std::string> &param)
174 {
175     LOGI("StartDiscovering for standard meta node process.");
176     (void)param;
177     strcpy_s(dmSubInfo.capability, DM_MAX_DEVICE_CAPABILITY_LEN, DM_CAPABILITY_OSD);
178 
179     int32_t ret = softbusListener_->RefreshSoftbusLNN(DM_PKG_NAME, dmSubInfo, LNN_DISC_CAPABILITY);
180     if (ret != DM_OK) {
181         LOGE("StartDiscoveringNoMetaType failed, softbus refresh lnn ret: %d.", ret);
182     }
183     return ret;
184 }
185 
StartDiscovering4MetaType(DmSubscribeInfo & dmSubInfo,const std::map<std::string,std::string> & param)186 int32_t DiscoveryManager::StartDiscovering4MetaType(DmSubscribeInfo &dmSubInfo,
187     const std::map<std::string, std::string> &param)
188 {
189     LOGI("StartDiscovering for meta node process, input metaType = %s",
190          (param.find(PARAM_KEY_META_TYPE)->second).c_str());
191     MetaNodeType metaType = (MetaNodeType)(std::atoi((param.find(PARAM_KEY_META_TYPE)->second).c_str()));
192     switch (metaType) {
193         case MetaNodeType::PROXY_SHARE:
194             LOGI("StartDiscovering4MetaType for share meta node process.");
195             strcpy_s(dmSubInfo.capability, DM_MAX_DEVICE_CAPABILITY_LEN, DM_CAPABILITY_SHARE);
196             break;
197         case MetaNodeType::PROXY_WEAR:
198             LOGI("StartDiscovering4MetaType for wear meta node process.");
199             strcpy_s(dmSubInfo.capability, DM_MAX_DEVICE_CAPABILITY_LEN, DM_CAPABILITY_WEAR);
200             break;
201         case MetaNodeType::PROXY_CASTPLUS:
202             LOGI("StartDiscovering4MetaType for cast_plus meta node process.");
203             strcpy_s(dmSubInfo.capability, DM_MAX_DEVICE_CAPABILITY_LEN, DM_CAPABILITY_CASTPLUS);
204             break;
205         default:
206             LOGE("StartDiscovering4MetaType failed, unsupport meta type : %d.", metaType);
207             return ERR_DM_UNSUPPORTED_METHOD;
208     }
209 
210     std::string customData = "";
211     if (param.find(PARAM_KEY_CUSTOM_DATA) != param.end()) {
212         customData = param.find(PARAM_KEY_CUSTOM_DATA)->second;
213     }
214 
215     int32_t ret = softbusListener_->RefreshSoftbusLNN(DM_PKG_NAME, dmSubInfo, customData);
216     if (ret != DM_OK) {
217         LOGE("StartDiscovering4MetaType failed, softbus refresh lnn ret: %d.", ret);
218     }
219     return ret;
220 }
221 
StopDiscovering(const std::string & pkgName,uint16_t subscribeId)222 int32_t DiscoveryManager::StopDiscovering(const std::string &pkgName, uint16_t subscribeId)
223 {
224     LOGI("DiscoveryManager::StopDiscovering begin for pkgName = %s.", pkgName.c_str());
225     if (pkgName.empty()) {
226         LOGE("Invalid parameter, pkgName is empty.");
227         return ERR_DM_INPUT_PARA_INVALID;
228     }
229     {
230         std::lock_guard<std::mutex> autoLock(locks_);
231         if (!discoveryQueue_.empty()) {
232             discoveryQueue_.pop();
233         }
234         if (!discoveryContextMap_.empty()) {
235             discoveryContextMap_.erase(pkgName);
236             timer_->DeleteTimer(std::string(DISCOVERY_TIMEOUT_TASK));
237         }
238     }
239     softbusListener_->UnRegisterSoftbusLnnOpsCbk(pkgName);
240     return softbusListener_->StopRefreshSoftbusLNN(subscribeId);
241 }
242 
OnDeviceFound(const std::string & pkgName,const DmDeviceInfo & info,bool isOnline)243 void DiscoveryManager::OnDeviceFound(const std::string &pkgName, const DmDeviceInfo &info, bool isOnline)
244 {
245     DiscoveryContext discoveryContext;
246     DiscoveryFilter filter;
247     DeviceFilterPara filterPara;
248     filterPara.isOnline = false;
249     filterPara.range = info.range;
250     filterPara.deviceType = info.deviceTypeId;
251     std::string deviceIdHash = static_cast<std::string>(info.deviceId);
252     if (isOnline && GetDeviceAclParam(pkgName, deviceIdHash, filterPara.isOnline, filterPara.authForm) != DM_OK) {
253         LOGE("The found device get online param failed.");
254     }
255     {
256         std::lock_guard<std::mutex> autoLock(locks_);
257         auto iter = discoveryContextMap_.find(pkgName);
258         if (iter == discoveryContextMap_.end()) {
259             listener_->OnDeviceFound(pkgName, pkgName2SubIdMap_[pkgName], info);
260             return;
261         }
262         discoveryContext = iter->second;
263     }
264     if (filter.IsValidDevice(discoveryContext.filterOp, discoveryContext.filters, filterPara)) {
265         listener_->OnDeviceFound(pkgName, discoveryContext.subscribeId, info);
266     }
267 }
268 
OnDiscoveringResult(const std::string & pkgName,int32_t subscribeId,int32_t result)269 void DiscoveryManager::OnDiscoveringResult(const std::string &pkgName, int32_t subscribeId, int32_t result)
270 {
271     LOGI("DiscoveryManager::OnDiscoveringResult, subscribeId = %d, result = %d.", subscribeId, result);
272     if (pkgName.empty() || (listener_ == nullptr)) {
273         LOGE("DiscoveryManager::OnDiscoveringResult failed, IDeviceManagerServiceListener is null.");
274         return;
275     }
276     if (result == 0) {
277         std::lock_guard<std::mutex> autoLock(locks_);
278         discoveryContextMap_[pkgName].subscribeId = (uint32_t)subscribeId;
279         listener_->OnDiscoverySuccess(pkgName, subscribeId);
280         return;
281     }
282     {
283         std::lock_guard<std::mutex> autoLock(locks_);
284         if (!discoveryQueue_.empty()) {
285             discoveryQueue_.pop();
286         }
287         if (!discoveryContextMap_.empty()) {
288             discoveryContextMap_.erase(pkgName);
289             timer_->DeleteTimer(std::string(DISCOVERY_TIMEOUT_TASK));
290         }
291     }
292     struct RadarInfo info = {
293         .funcName = "OnSoftbusDiscoveryResult",
294         .stageRes = static_cast<int32_t>(StageRes::STAGE_FAIL),
295         .errCode = result,
296     };
297     if (SoftbusListener::IsDmRadarHelperReady() && SoftbusListener::GetDmRadarHelperObj() != nullptr) {
298         if (!SoftbusListener::GetDmRadarHelperObj()->ReportDiscoverResCallback(info)) {
299             LOGE("ReportDiscoverResCallback failed");
300         }
301     }
302     listener_->OnDiscoveryFailed(pkgName, (uint32_t)subscribeId, result);
303     softbusListener_->StopRefreshSoftbusLNN(subscribeId);
304 }
305 
StartDiscoveryTimer()306 void DiscoveryManager::StartDiscoveryTimer()
307 {
308     if (timer_ == nullptr) {
309         timer_ = std::make_shared<DmTimer>();
310     }
311     timer_->StartTimer(std::string(DISCOVERY_TIMEOUT_TASK), DISCOVERY_TIMEOUT,
312         [this] (std::string name) {
313             DiscoveryManager::HandleDiscoveryTimeout(name);
314         });
315 }
316 
HandleDiscoveryQueue(const std::string & pkgName,uint16_t subscribeId,const std::map<std::string,std::string> & filterOps)317 int32_t DiscoveryManager::HandleDiscoveryQueue(const std::string &pkgName, uint16_t subscribeId,
318     const std::map<std::string, std::string> &filterOps)
319 {
320     std::string filterData = "";
321     if (filterOps.find(PARAM_KEY_FILTER_OPTIONS) != filterOps.end()) {
322         filterData = filterOps.find(PARAM_KEY_FILTER_OPTIONS)->second;
323     }
324     DeviceFilterOption dmFilter;
325     if ((dmFilter.TransformToFilter(filterData) != DM_OK) && (dmFilter.TransformFilterOption(filterData) != DM_OK)) {
326         return ERR_DM_INPUT_PARA_INVALID;
327     }
328     uint16_t frontSubscribeId = 0;
329     std::string frontPkgName = "";
330     {
331         std::lock_guard<std::mutex> autoLock(locks_);
332         if (discoveryQueue_.empty()) {
333             discoveryQueue_.push(pkgName);
334             DiscoveryContext context = {pkgName, filterData, subscribeId, dmFilter.filterOp_, dmFilter.filters_};
335             discoveryContextMap_.emplace(pkgName, context);
336             return DM_OK;
337         }
338         frontPkgName = discoveryQueue_.front();
339         frontSubscribeId = discoveryContextMap_[frontPkgName].subscribeId;
340         if (pkgName == frontPkgName) {
341             LOGE("DiscoveryManager::HandleDiscoveryQueue repeated, pkgName : %s.", pkgName.c_str());
342             return ERR_DM_DISCOVERY_REPEATED;
343         }
344     }
345     StopDiscovering(frontPkgName, frontSubscribeId);
346     {
347         std::lock_guard<std::mutex> autoLock(locks_);
348         discoveryQueue_.push(pkgName);
349         DiscoveryContext context = {pkgName, filterData, subscribeId, dmFilter.filterOp_, dmFilter.filters_};
350         discoveryContextMap_.emplace(pkgName, context);
351     }
352     return DM_OK;
353 }
354 
HandleDiscoveryTimeout(std::string name)355 void DiscoveryManager::HandleDiscoveryTimeout(std::string name)
356 {
357     (void)name;
358     LOGI("DiscoveryManager::HandleDiscoveryTimeout");
359     uint16_t subscribeId = 0;
360     std::string pkgName = "";
361     {
362         std::lock_guard<std::mutex> autoLock(locks_);
363         if (discoveryQueue_.empty()) {
364             LOGE("HandleDiscoveryTimeout: discovery queue is empty.");
365             return;
366         }
367 
368         pkgName = discoveryQueue_.front();
369         auto iter = discoveryContextMap_.find(pkgName);
370         if (iter == discoveryContextMap_.end()) {
371             LOGE("HandleDiscoveryTimeout: subscribeId not found by pkgName %s.", GetAnonyString(pkgName).c_str());
372             return;
373         }
374         subscribeId = discoveryContextMap_[pkgName].subscribeId;
375     }
376     StopDiscovering(pkgName, subscribeId);
377 }
378 
GetDeviceAclParam(const std::string & pkgName,std::string deviceId,bool & isOnline,int32_t & authForm)379 int32_t DiscoveryManager::GetDeviceAclParam(const std::string &pkgName, std::string deviceId,
380     bool &isOnline, int32_t &authForm)
381 {
382 #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE))
383     LOGI("Get deviceId = %s isOnline and authForm.", GetAnonyString(deviceId).c_str());
384     char localDeviceId[DEVICE_UUID_LENGTH];
385     GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH);
386     std::string requestDeviceId = static_cast<std::string>(localDeviceId);
387     DmDiscoveryInfo discoveryInfo;
388     discoveryInfo.pkgname = pkgName;
389     discoveryInfo.localDeviceId = requestDeviceId;
390     discoveryInfo.remoteDeviceIdHash = deviceId;
391     if (DiscoveryManager::IsCommonDependencyReady() && DiscoveryManager::GetCommonDependencyObj() != nullptr) {
392         if (DiscoveryManager::GetCommonDependencyObj()->GetDeviceAclParam(discoveryInfo, isOnline, authForm) != DM_OK) {
393             LOGE("GetDeviceAclParam failed.");
394             return ERR_DM_FAILED;
395         }
396     }
397 #endif
398     return DM_OK;
399 }
400 
401 #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE))
GetCommonDependencyObj()402 IDeviceProfileConnector* DiscoveryManager::GetCommonDependencyObj()
403 {
404     return dpConnector_;
405 }
406 
IsCommonDependencyReady()407 bool DiscoveryManager::IsCommonDependencyReady()
408 {
409     LOGI("DiscoveryManager::IsCommonDependencyReady.");
410     std::lock_guard<std::mutex> lock(comDependencyLoadLock);
411     if (isSoLoaded_ && dpConnector_ != nullptr && dpConnectorHandle_ != nullptr) {
412         LOGI("IsCommonDependencyReady already.");
413         return true;
414     }
415     char path[PATH_MAX + 1] = {0x00};
416     std::string soName = std::string(DM_LIB_LOAD_PATH) + std::string(LIB_DM_COMDENPENDENCY_NAME);
417     if ((soName.length() == 0) || (soName.length() > PATH_MAX) || (realpath(soName.c_str(), path) == nullptr)) {
418         LOGE("File %s canonicalization failed.", soName.c_str());
419         return false;
420     }
421     dpConnectorHandle_ = dlopen(path, RTLD_NOW | RTLD_NODELETE);
422     if (dpConnectorHandle_ == nullptr) {
423         LOGE("load libdevicemanagerdependency so %s failed, errMsg: %s.", soName.c_str(), dlerror());
424         return false;
425     }
426     dlerror();
427     auto func = (CreateDpConnectorFuncPtr)dlsym(dpConnectorHandle_, "CreateDpConnectorInstance");
428     if (dlerror() != nullptr || func == nullptr) {
429         dlclose(dpConnectorHandle_);
430         LOGE("Create object function is not exist.");
431         return false;
432     }
433     dpConnector_ = func();
434     isSoLoaded_ = true;
435     LOGI("IsCommonDependencyReady success.");
436     return true;
437 }
438 
CloseCommonDependencyObj()439 bool DiscoveryManager::CloseCommonDependencyObj()
440 {
441     LOGI("DiscoveryManager::CloseCommonDependencyObj start.");
442     std::lock_guard<std::mutex> lock(comDependencyLoadLock);
443     if (!isSoLoaded_ && (dpConnector_ == nullptr) && (dpConnectorHandle_ == nullptr)) {
444         return true;
445     }
446 
447     int32_t ret = dlclose(dpConnectorHandle_);
448     if (ret != 0) {
449         LOGE("close libdevicemanagerdependency failed ret = %d.", ret);
450         return false;
451     }
452     isSoLoaded_ = false;
453     dpConnector_ = nullptr;
454     dpConnectorHandle_ = nullptr;
455     LOGI("close libdevicemanagerdependency so success.");
456     return true;
457 }
458 #endif
459 } // namespace DistributedHardware
460 } // namespace OHOS
461