1 /*
2 * Copyright (c) 2022-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 "soft_bus_manager.h"
16
17 #include <securec.h>
18 #include <thread>
19 #include <pthread.h>
20
21 #include "accesstoken_log.h"
22 #include "constant.h"
23 #include "constant_common.h"
24 #include "device_info_manager.h"
25 #include "dm_device_info.h"
26 #include "remote_command_manager.h"
27 #include "softbus_bus_center.h"
28 #include "soft_bus_device_connection_listener.h"
29 #include "soft_bus_socket_listener.h"
30
31 namespace OHOS {
32 namespace Security {
33 namespace AccessToken {
34 namespace {
35 static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "SoftBusManager"};
36 }
37 namespace {
38 static const int UDID_MAX_LENGTH = 128; // udid/uuid max length
39 static const int MAX_PTHREAD_NAME_LEN = 15; // pthread name max length
40
41 static const std::string TOKEN_SYNC_PACKAGE_NAME = "ohos.security.distributed_access_token";
42 static const std::string TOKEN_SYNC_SOCKET_NAME = "ohos.security.atm_channel.";
43
44 static const uint32_t SOCKET_NAME_MAX_LEN = 256;
45 static const uint32_t QOS_LEN = 3;
46 static const int32_t MIN_BW = 64 * 1024; // 64k
47 static const int32_t MAX_LATENCY = 10000; // 10s
48 static const int32_t MIN_LATENCY = 2000; // 2s
49
50 static const int32_t ERROR_TRANSFORM_STRING_TO_CHAR = -1;
51 static const int32_t ERROR_CREATE_SOCKET_FAIL = -2;
52 static const int32_t ERROR_CREATE_LISTENER_FAIL = -3;
53 static const int32_t ERROR_CLIENT_HAS_BIND_ALREADY = -4;
54
55 static const int32_t BIND_SERVICE_MAX_RETRY_TIMES = 10;
56 static const int32_t BIND_SERVICE_SLEEP_TIMES_MS = 100; // 0.1s
57 } // namespace
58
SoftBusManager()59 SoftBusManager::SoftBusManager() : isSoftBusServiceBindSuccess_(false), inited_(false), mutex_(), fulfillMutex_()
60 {
61 ACCESSTOKEN_LOG_DEBUG(LABEL, "SoftBusManager()");
62 }
63
~SoftBusManager()64 SoftBusManager::~SoftBusManager()
65 {
66 ACCESSTOKEN_LOG_DEBUG(LABEL, "~SoftBusManager()");
67 }
68
GetInstance()69 SoftBusManager &SoftBusManager::GetInstance()
70 {
71 static SoftBusManager instance;
72 return instance;
73 }
74
AddTrustedDeviceInfo()75 int SoftBusManager::AddTrustedDeviceInfo()
76 {
77 std::string packageName = TOKEN_SYNC_PACKAGE_NAME;
78 std::string extra = "";
79 std::vector<DistributedHardware::DmDeviceInfo> deviceList;
80
81 int32_t ret = DistributedHardware::DeviceManager::GetInstance().GetTrustedDeviceList(packageName,
82 extra, deviceList);
83 if (ret != Constant::SUCCESS) {
84 ACCESSTOKEN_LOG_ERROR(LABEL, "AddTrustedDeviceInfo: GetTrustedDeviceList error, result: %{public}d", ret);
85 return Constant::FAILURE;
86 }
87
88 for (const DistributedHardware::DmDeviceInfo& device : deviceList) {
89 std::string uuid = GetUuidByNodeId(device.networkId);
90 std::string udid = GetUdidByNodeId(device.networkId);
91 if (uuid.empty() || udid.empty()) {
92 ACCESSTOKEN_LOG_ERROR(LABEL, "uuid = %{public}s, udid = %{public}s, uuid or udid is empty, abort.",
93 ConstantCommon::EncryptDevId(uuid).c_str(), ConstantCommon::EncryptDevId(udid).c_str());
94 continue;
95 }
96
97 DeviceInfoManager::GetInstance().AddDeviceInfo(device.networkId, uuid, udid, device.deviceName,
98 std::to_string(device.deviceTypeId));
99 RemoteCommandManager::GetInstance().NotifyDeviceOnline(udid);
100 }
101
102 return Constant::SUCCESS;
103 }
104
DeviceInit()105 int SoftBusManager::DeviceInit()
106 {
107 std::string packageName = TOKEN_SYNC_PACKAGE_NAME;
108 std::shared_ptr<MyDmInitCallback> ptrDmInitCallback = std::make_shared<MyDmInitCallback>();
109
110 int ret = DistributedHardware::DeviceManager::GetInstance().InitDeviceManager(packageName, ptrDmInitCallback);
111 if (ret != ERR_OK) {
112 ACCESSTOKEN_LOG_ERROR(LABEL, "Initialize: InitDeviceManager error, result: %{public}d", ret);
113 return ret;
114 }
115
116 ret = AddTrustedDeviceInfo();
117 if (ret != ERR_OK) {
118 ACCESSTOKEN_LOG_ERROR(LABEL, "Initialize: AddTrustedDeviceInfo error, result: %{public}d", ret);
119 return ret;
120 }
121
122 std::string extra = "";
123 std::shared_ptr<SoftBusDeviceConnectionListener> ptrDeviceStateCallback =
124 std::make_shared<SoftBusDeviceConnectionListener>();
125 ret = DistributedHardware::DeviceManager::GetInstance().RegisterDevStateCallback(packageName, extra,
126 ptrDeviceStateCallback);
127 if (ret != ERR_OK) {
128 ACCESSTOKEN_LOG_ERROR(LABEL, "Initialize: RegisterDevStateCallback error, result: %{public}d", ret);
129 return ret;
130 }
131
132 return ERR_OK;
133 }
134
CheckAndCopyStr(char * dest,uint32_t destLen,const std::string & src)135 bool SoftBusManager::CheckAndCopyStr(char* dest, uint32_t destLen, const std::string& src)
136 {
137 if (destLen < src.length() + 1) {
138 ACCESSTOKEN_LOG_ERROR(LABEL, "Invalid src length");
139 return false;
140 }
141 if (strcpy_s(dest, destLen, src.c_str()) != EOK) {
142 ACCESSTOKEN_LOG_ERROR(LABEL, "Invalid src");
143 return false;
144 }
145 return true;
146 }
147
ServiceSocketInit()148 int32_t SoftBusManager::ServiceSocketInit()
149 {
150 std::string serviceName = TOKEN_SYNC_SOCKET_NAME + "service";
151 char name[SOCKET_NAME_MAX_LEN + 1];
152 if (!CheckAndCopyStr(name, SOCKET_NAME_MAX_LEN, serviceName)) {
153 return ERROR_TRANSFORM_STRING_TO_CHAR;
154 }
155
156 char pkgName[SOCKET_NAME_MAX_LEN + 1];
157 if (!CheckAndCopyStr(pkgName, SOCKET_NAME_MAX_LEN, TOKEN_SYNC_PACKAGE_NAME)) {
158 return ERROR_TRANSFORM_STRING_TO_CHAR;
159 }
160
161 SocketInfo info = {
162 .name = name,
163 .pkgName = pkgName,
164 .dataType = DATA_TYPE_BYTES
165 };
166 int32_t ret = ::Socket(info); // create service socket id
167 if (ret <= Constant::INVALID_SOCKET_FD) {
168 ACCESSTOKEN_LOG_ERROR(LABEL, "create service socket faild, ret is %{public}d.", ret);
169 return ERROR_CREATE_SOCKET_FAIL;
170 } else {
171 socketFd_ = ret;
172 ACCESSTOKEN_LOG_DEBUG(LABEL, "create service socket[%{public}d] success.", socketFd_);
173 }
174
175 // set service qos, no need to regist OnQos now, regist it
176 QosTV serverQos[] = {
177 { .qos = QOS_TYPE_MIN_BW, .value = MIN_BW },
178 { .qos = QOS_TYPE_MAX_LATENCY, .value = MAX_LATENCY },
179 { .qos = QOS_TYPE_MIN_LATENCY, .value = MIN_LATENCY },
180 };
181
182 ISocketListener listener;
183 listener.OnBind = SoftBusSocketListener::OnBind; // only service may receive OnBind
184 listener.OnShutdown = SoftBusSocketListener::OnShutdown;
185 listener.OnBytes = SoftBusSocketListener::OnClientBytes;
186
187 ret = ::Listen(socketFd_, serverQos, QOS_LEN, &listener);
188 if (ret != ERR_OK) {
189 ACCESSTOKEN_LOG_ERROR(LABEL, "create listener failed, ret is %{public}d.", ret);
190 return ERROR_CREATE_LISTENER_FAIL;
191 } else {
192 ACCESSTOKEN_LOG_DEBUG(LABEL, "create listener success.");
193 }
194
195 return ERR_OK;
196 }
197
Initialize()198 void SoftBusManager::Initialize()
199 {
200 bool inited = false;
201 // cas failed means already inited.
202 if (!inited_.compare_exchange_strong(inited, true)) {
203 ACCESSTOKEN_LOG_DEBUG(LABEL, "already initialized, skip");
204 return;
205 }
206
207 std::function<void()> runner = [&]() {
208 std::string name = "SoftBusMagInit";
209 pthread_setname_np(pthread_self(), name.substr(0, MAX_PTHREAD_NAME_LEN).c_str());
210 auto sleepTime = std::chrono::milliseconds(1000);
211 while (1) {
212 std::unique_lock<std::mutex> lock(mutex_);
213
214 int ret = DeviceInit();
215 if (ret != ERR_OK) {
216 std::this_thread::sleep_for(sleepTime);
217 continue;
218 }
219
220 ret = ServiceSocketInit();
221 if (ret != ERR_OK) {
222 std::this_thread::sleep_for(sleepTime);
223 continue;
224 }
225
226 isSoftBusServiceBindSuccess_ = true;
227 this->FulfillLocalDeviceInfo();
228 return;
229 }
230 };
231
232 std::thread initThread(runner);
233 initThread.detach();
234 ACCESSTOKEN_LOG_DEBUG(LABEL, "Initialize thread started");
235 }
236
Destroy()237 void SoftBusManager::Destroy()
238 {
239 ACCESSTOKEN_LOG_DEBUG(LABEL, "destroy, init: %{public}d, isSoftBusServiceBindSuccess: %{public}d", inited_.load(),
240 isSoftBusServiceBindSuccess_);
241
242 if (!inited_.load()) {
243 ACCESSTOKEN_LOG_DEBUG(LABEL, "not inited, skip");
244 return;
245 }
246
247 std::unique_lock<std::mutex> lock(mutex_);
248 if (!inited_.load()) {
249 ACCESSTOKEN_LOG_DEBUG(LABEL, "not inited, skip");
250 return;
251 }
252
253 if (isSoftBusServiceBindSuccess_) {
254 if (socketFd_ > Constant::INVALID_SOCKET_FD) {
255 ::Shutdown(socketFd_);
256 }
257
258 ACCESSTOKEN_LOG_DEBUG(LABEL, "destroy socket");
259 isSoftBusServiceBindSuccess_ = false;
260 }
261
262 std::string packageName = TOKEN_SYNC_PACKAGE_NAME;
263 int ret = DistributedHardware::DeviceManager::GetInstance().UnRegisterDevStateCallback(packageName);
264 if (ret != ERR_OK) {
265 ACCESSTOKEN_LOG_ERROR(LABEL, "UnRegisterDevStateCallback failed, code: %{public}d", ret);
266 }
267 ret = DistributedHardware::DeviceManager::GetInstance().UnInitDeviceManager(packageName);
268 if (ret != ERR_OK) {
269 ACCESSTOKEN_LOG_ERROR(LABEL, "UnInitDeviceManager failed, code: %{public}d", ret);
270 }
271
272 inited_.store(false);
273
274 ACCESSTOKEN_LOG_DEBUG(LABEL, "destroy, done");
275 }
276
InitSocketAndListener(const std::string & networkId,ISocketListener & listener)277 int32_t SoftBusManager::InitSocketAndListener(const std::string& networkId, ISocketListener& listener)
278 {
279 std::string clientName = TOKEN_SYNC_SOCKET_NAME + networkId;
280 char name[SOCKET_NAME_MAX_LEN + 1];
281 if (!CheckAndCopyStr(name, SOCKET_NAME_MAX_LEN, clientName)) {
282 return ERROR_TRANSFORM_STRING_TO_CHAR;
283 }
284
285 std::string serviceName = TOKEN_SYNC_SOCKET_NAME + "service";
286 char peerName[SOCKET_NAME_MAX_LEN + 1];
287 if (!CheckAndCopyStr(peerName, SOCKET_NAME_MAX_LEN, serviceName)) {
288 return ERROR_TRANSFORM_STRING_TO_CHAR;
289 }
290
291 char peerNetworkId[SOCKET_NAME_MAX_LEN + 1];
292 if (!CheckAndCopyStr(peerNetworkId, SOCKET_NAME_MAX_LEN, networkId)) {
293 return ERROR_TRANSFORM_STRING_TO_CHAR;
294 }
295
296 char pkgName[SOCKET_NAME_MAX_LEN + 1];
297 if (!CheckAndCopyStr(pkgName, SOCKET_NAME_MAX_LEN, TOKEN_SYNC_PACKAGE_NAME)) {
298 return ERROR_TRANSFORM_STRING_TO_CHAR;
299 }
300
301 SocketInfo info = {
302 .name = name,
303 .peerName = peerName,
304 .peerNetworkId = peerNetworkId,
305 .pkgName = pkgName,
306 .dataType = DATA_TYPE_BYTES
307 };
308
309 listener.OnShutdown = SoftBusSocketListener::OnShutdown;
310 listener.OnBytes = SoftBusSocketListener::OnServiceBytes;
311 listener.OnQos = SoftBusSocketListener::OnQos; // only client may receive OnQos
312
313 return ::Socket(info);
314 }
315
BindService(const std::string & deviceId)316 int32_t SoftBusManager::BindService(const std::string &deviceId)
317 {
318 #ifdef DEBUG_API_PERFORMANCE
319 ACCESSTOKEN_LOG_INFO(LABEL, "api_performance:start bind service");
320 #endif
321
322 DeviceInfo info;
323 bool result = DeviceInfoManager::GetInstance().GetDeviceInfo(deviceId, DeviceIdType::UNKNOWN, info);
324 if (!result) {
325 ACCESSTOKEN_LOG_WARN(LABEL, "device info not found for deviceId %{public}s",
326 ConstantCommon::EncryptDevId(deviceId).c_str());
327 return Constant::FAILURE;
328 }
329 std::string networkId = info.deviceId.networkId;
330
331 ISocketListener listener;
332 int32_t socketFd = InitSocketAndListener(networkId, listener);
333 if (socketFd_ <= Constant::INVALID_SOCKET_FD) {
334 ACCESSTOKEN_LOG_ERROR(LABEL, "create client socket faild.");
335 return ERROR_CREATE_SOCKET_FAIL;
336 } else {
337 ACCESSTOKEN_LOG_DEBUG(LABEL, "create client socket[%{public}d] success.", socketFd);
338 }
339
340 {
341 std::lock_guard<std::mutex> guard(clientSocketMutex_);
342 auto iter = clientSocketMap_.find(socketFd);
343 if (iter == clientSocketMap_.end()) {
344 clientSocketMap_.insert(std::pair<int32_t, std::string>(socketFd, networkId));
345 } else {
346 ACCESSTOKEN_LOG_ERROR(LABEL, "client socket has bind already");
347 return ERROR_CLIENT_HAS_BIND_ALREADY;
348 }
349 }
350
351 // set service qos
352 QosTV clientQos[] = {
353 { .qos = QOS_TYPE_MIN_BW, .value = MIN_BW },
354 { .qos = QOS_TYPE_MAX_LATENCY, .value = MAX_LATENCY },
355 { .qos = QOS_TYPE_MIN_LATENCY, .value = MIN_LATENCY },
356 };
357
358 // retry 10 times or bind success
359 int32_t retryTimes = 0;
360 auto sleepTime = std::chrono::milliseconds(BIND_SERVICE_SLEEP_TIMES_MS);
361 while (retryTimes < BIND_SERVICE_MAX_RETRY_TIMES) {
362 int32_t res = ::Bind(socketFd, clientQos, QOS_LEN, &listener);
363 if (res != Constant::SUCCESS) {
364 std::this_thread::sleep_for(sleepTime);
365 retryTimes++;
366 continue;
367 }
368 break;
369 }
370
371 ACCESSTOKEN_LOG_DEBUG(LABEL, "Bind service succeed, socketFd is %{public}d.", socketFd);
372 return socketFd;
373 }
374
CloseSocket(int socketFd)375 int SoftBusManager::CloseSocket(int socketFd)
376 {
377 if (socketFd <= Constant::INVALID_SOCKET_FD) {
378 ACCESSTOKEN_LOG_INFO(LABEL, "socket is invalid");
379 return Constant::FAILURE;
380 }
381
382 ::Shutdown(socketFd);
383
384 std::lock_guard<std::mutex> guard(clientSocketMutex_);
385 auto iter = clientSocketMap_.find(socketFd);
386 if (iter == clientSocketMap_.end()) {
387 clientSocketMap_.erase(iter);
388 }
389
390 ACCESSTOKEN_LOG_INFO(LABEL, "close socket");
391
392 return Constant::SUCCESS;
393 }
394
GetNetworkIdBySocket(const int32_t socket,std::string & networkId)395 bool SoftBusManager::GetNetworkIdBySocket(const int32_t socket, std::string& networkId)
396 {
397 std::lock_guard<std::mutex> guard(clientSocketMutex_);
398 auto iter = clientSocketMap_.find(socket);
399 if (iter != clientSocketMap_.end()) {
400 networkId = iter->second;
401 return true;
402 }
403 return false;
404 }
405
GetUniversallyUniqueIdByNodeId(const std::string & nodeId)406 std::string SoftBusManager::GetUniversallyUniqueIdByNodeId(const std::string &nodeId)
407 {
408 if (!DataValidator::IsDeviceIdValid(nodeId)) {
409 ACCESSTOKEN_LOG_ERROR(LABEL, "invalid nodeId: %{public}s", ConstantCommon::EncryptDevId(nodeId).c_str());
410 return "";
411 }
412
413 std::string uuid = GetUuidByNodeId(nodeId);
414 if (uuid.empty()) {
415 ACCESSTOKEN_LOG_ERROR(LABEL, "softbus return null or empty string");
416 return "";
417 }
418
419 DeviceInfo info;
420 bool result = DeviceInfoManager::GetInstance().GetDeviceInfo(uuid, DeviceIdType::UNIVERSALLY_UNIQUE_ID, info);
421 if (!result) {
422 ACCESSTOKEN_LOG_DEBUG(LABEL, "local device info not found for uuid %{public}s",
423 ConstantCommon::EncryptDevId(uuid).c_str());
424 } else {
425 std::string dimUuid = info.deviceId.universallyUniqueId;
426 if (uuid == dimUuid) {
427 // refresh cache
428 std::function<void()> fulfillDeviceInfo = std::bind(&SoftBusManager::FulfillLocalDeviceInfo, this);
429 std::thread fulfill(fulfillDeviceInfo);
430 fulfill.detach();
431 }
432 }
433
434 return uuid;
435 }
436
GetUniqueDeviceIdByNodeId(const std::string & nodeId)437 std::string SoftBusManager::GetUniqueDeviceIdByNodeId(const std::string &nodeId)
438 {
439 if (!DataValidator::IsDeviceIdValid(nodeId)) {
440 ACCESSTOKEN_LOG_ERROR(LABEL, "invalid nodeId: %{public}s", ConstantCommon::EncryptDevId(nodeId).c_str());
441 return "";
442 }
443 std::string udid = GetUdidByNodeId(nodeId);
444 if (udid.empty()) {
445 ACCESSTOKEN_LOG_ERROR(LABEL, "softbus return null or empty string: %{public}s",
446 ConstantCommon::EncryptDevId(udid).c_str());
447 return "";
448 }
449 std::string localUdid = ConstantCommon::GetLocalDeviceId();
450 if (udid == localUdid) {
451 // refresh cache
452 std::function<void()> fulfillDeviceInfo = std::bind(&SoftBusManager::FulfillLocalDeviceInfo, this);
453 std::thread fulfill(fulfillDeviceInfo);
454 fulfill.detach();
455 }
456 return udid;
457 }
458
GetUuidByNodeId(const std::string & nodeId) const459 std::string SoftBusManager::GetUuidByNodeId(const std::string &nodeId) const
460 {
461 uint8_t *info = new (std::nothrow) uint8_t[UDID_MAX_LENGTH + 1];
462 if (info == nullptr) {
463 ACCESSTOKEN_LOG_ERROR(LABEL, "no enough memory: %{public}d", UDID_MAX_LENGTH);
464 return "";
465 }
466 (void)memset_s(info, UDID_MAX_LENGTH + 1, 0, UDID_MAX_LENGTH + 1);
467 int32_t ret = ::GetNodeKeyInfo(TOKEN_SYNC_PACKAGE_NAME.c_str(), nodeId.c_str(),
468 NodeDeviceInfoKey::NODE_KEY_UUID, info, UDID_MAX_LENGTH);
469 if (ret != Constant::SUCCESS) {
470 delete[] info;
471 ACCESSTOKEN_LOG_WARN(LABEL, "GetNodeKeyInfo error, return code: %{public}d", ret);
472 return "";
473 }
474 std::string uuid(reinterpret_cast<char *>(info));
475 delete[] info;
476 ACCESSTOKEN_LOG_DEBUG(LABEL, "call softbus finished. nodeId(in): %{public}s, uuid: %{public}s",
477 ConstantCommon::EncryptDevId(nodeId).c_str(), ConstantCommon::EncryptDevId(uuid).c_str());
478 return uuid;
479 }
480
GetUdidByNodeId(const std::string & nodeId) const481 std::string SoftBusManager::GetUdidByNodeId(const std::string &nodeId) const
482 {
483 uint8_t *info = new (std::nothrow) uint8_t[UDID_MAX_LENGTH + 1];
484 if (info == nullptr) {
485 ACCESSTOKEN_LOG_ERROR(LABEL, "no enough memory: %{public}d", UDID_MAX_LENGTH);
486 return "";
487 }
488 (void)memset_s(info, UDID_MAX_LENGTH + 1, 0, UDID_MAX_LENGTH + 1);
489 int32_t ret = ::GetNodeKeyInfo(TOKEN_SYNC_PACKAGE_NAME.c_str(), nodeId.c_str(),
490 NodeDeviceInfoKey::NODE_KEY_UDID, info, UDID_MAX_LENGTH);
491 if (ret != Constant::SUCCESS) {
492 delete[] info;
493 ACCESSTOKEN_LOG_WARN(LABEL, "GetNodeKeyInfo error, code: %{public}d", ret);
494 return "";
495 }
496 std::string udid(reinterpret_cast<char *>(info));
497 delete[] info;
498 ACCESSTOKEN_LOG_DEBUG(LABEL, "call softbus finished: nodeId(in): %{public}s",
499 ConstantCommon::EncryptDevId(nodeId).c_str());
500 return udid;
501 }
502
FulfillLocalDeviceInfo()503 int SoftBusManager::FulfillLocalDeviceInfo()
504 {
505 // repeated task will just skip
506 if (!fulfillMutex_.try_lock()) {
507 ACCESSTOKEN_LOG_INFO(LABEL, "FulfillLocalDeviceInfo already running, skip.");
508 return Constant::SUCCESS;
509 }
510
511 NodeBasicInfo info;
512 int32_t ret = ::GetLocalNodeDeviceInfo(TOKEN_SYNC_PACKAGE_NAME.c_str(), &info);
513 if (ret != Constant::SUCCESS) {
514 ACCESSTOKEN_LOG_ERROR(LABEL, "GetLocalNodeDeviceInfo error");
515 fulfillMutex_.unlock();
516 return Constant::FAILURE;
517 }
518
519 ACCESSTOKEN_LOG_DEBUG(LABEL, "call softbus finished, type:%{public}d", info.deviceTypeId);
520
521 std::string uuid = GetUuidByNodeId(info.networkId);
522 std::string udid = GetUdidByNodeId(info.networkId);
523 if (uuid.empty() || udid.empty()) {
524 ACCESSTOKEN_LOG_ERROR(LABEL, "FulfillLocalDeviceInfo: uuid or udid is empty, abort.");
525 fulfillMutex_.unlock();
526 return Constant::FAILURE;
527 }
528
529 DeviceInfoManager::GetInstance().AddDeviceInfo(info.networkId, uuid, udid, info.deviceName,
530 std::to_string(info.deviceTypeId));
531 ACCESSTOKEN_LOG_DEBUG(LABEL, "AddDeviceInfo finished");
532
533 fulfillMutex_.unlock();
534 return Constant::SUCCESS;
535 }
536 } // namespace AccessToken
537 } // namespace Security
538 } // namespace OHOS
539