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
16 #include "dbms_device_manager.h"
17
18 #include "app_log_wrapper.h"
19 #include "bundle_constants.h"
20 #include "device_manager.h"
21 #include "service_control.h"
22 #include "system_ability_definition.h"
23
24 namespace OHOS {
25 namespace AppExecFwk {
26 namespace {
27 const std::string DISTRIBUTED_BUNDLE_NAME = "distributed_bundle_framework";
28 const std::string SERVICES_NAME = "d-bms";
29 }
30
DbmsDeviceManager()31 DbmsDeviceManager::DbmsDeviceManager()
32 {
33 APP_LOGI("DbmsDeviceManager instance is created");
34 }
35
InitDeviceManager()36 bool DbmsDeviceManager::InitDeviceManager()
37 {
38 std::lock_guard<std::mutex> lock(isInitMutex_);
39 if (isInit_) {
40 APP_LOGI("device manager already init");
41 return true;
42 }
43
44 initCallback_ = std::make_shared<DeviceInitCallBack>();
45 int32_t ret =
46 DistributedHardware::DeviceManager::GetInstance().InitDeviceManager(DISTRIBUTED_BUNDLE_NAME, initCallback_);
47 if (ret != 0) {
48 APP_LOGE("init device manager failed, ret:%{public}d", ret);
49 return false;
50 }
51 isInit_ = true;
52 APP_LOGI("register device manager success");
53 return true;
54 }
55
OnRemoteDied()56 void DbmsDeviceManager::DeviceInitCallBack::OnRemoteDied()
57 {
58 APP_LOGI("DeviceInitCallBack OnRemoteDied");
59 }
60
GetUdidByNetworkId(const std::string & netWorkId,std::string & udid)61 int32_t DbmsDeviceManager::GetUdidByNetworkId(const std::string &netWorkId, std::string &udid)
62 {
63 APP_LOGI("GetUdidByNetworkId");
64 if (!InitDeviceManager()) {
65 return -1;
66 }
67 return DistributedHardware::DeviceManager::GetInstance().GetUdidByNetworkId(
68 DISTRIBUTED_BUNDLE_NAME, netWorkId, udid);
69 }
70
GetUuidByNetworkId(const std::string & netWorkId,std::string & uuid)71 int32_t DbmsDeviceManager::GetUuidByNetworkId(const std::string &netWorkId, std::string &uuid)
72 {
73 APP_LOGI("GetUuidByNetworkId");
74 if (!InitDeviceManager()) {
75 return -1;
76 }
77 int32_t errCode = DistributedHardware::DeviceManager::GetInstance()
78 .GetUuidByNetworkId(DISTRIBUTED_BUNDLE_NAME, netWorkId, uuid);
79 if (errCode != ERR_OK) {
80 APP_LOGE("GetUuidByNetworkId failed");
81 }
82 return errCode;
83 }
84 }
85 }