1 /*
2 * Copyright (c) 2023-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 "dm_radar_helper.h"
17 #include <errors.h>
18 #include <algorithm>
19 #include <sstream>
20 #include <iomanip>
21 #include <cJSON.h>
22 #include "dm_constants.h"
23 #include "dm_log.h"
24 #include "parameter.h"
25
26 namespace OHOS {
27 namespace DistributedHardware {
28 DM_IMPLEMENT_SINGLE_INSTANCE(DmRadarHelper);
ReportDiscoverRegCallback(struct RadarInfo &info)29 bool DmRadarHelper::ReportDiscoverRegCallback(struct RadarInfo &info)
30 {
31 return true;
32 }
33
ReportDiscoverResCallback(struct RadarInfo &info)34 bool DmRadarHelper::ReportDiscoverResCallback(struct RadarInfo &info)
35 {
36 return true;
37 }
38
ReportDiscoverUserRes(struct RadarInfo &info)39 bool DmRadarHelper::ReportDiscoverUserRes(struct RadarInfo &info)
40 {
41 return true;
42 }
43
ReportAuthStart(const std::string &peerUdid, const std::string &pkgName)44 bool DmRadarHelper::ReportAuthStart(const std::string &peerUdid, const std::string &pkgName)
45 {
46 return true;
47 }
48
ReportAuthOpenSession(struct RadarInfo &info)49 bool DmRadarHelper::ReportAuthOpenSession(struct RadarInfo &info)
50 {
51 return true;
52 }
53
ReportAuthSessionOpenCb(struct RadarInfo &info)54 bool DmRadarHelper::ReportAuthSessionOpenCb(struct RadarInfo &info)
55 {
56 return true;
57 }
58
ReportAuthSendRequest(struct RadarInfo &info)59 bool DmRadarHelper::ReportAuthSendRequest(struct RadarInfo &info)
60 {
61 return true;
62 }
63
ReportAuthPullAuthBox(struct RadarInfo &info)64 bool DmRadarHelper::ReportAuthPullAuthBox(struct RadarInfo &info)
65 {
66 return true;
67 }
68
ReportAuthConfirmBox(struct RadarInfo &info)69 bool DmRadarHelper::ReportAuthConfirmBox(struct RadarInfo &info)
70 {
71 return true;
72 }
73
ReportAuthCreateGroup(struct RadarInfo &info)74 bool DmRadarHelper::ReportAuthCreateGroup(struct RadarInfo &info)
75 {
76 return true;
77 }
78
ReportAuthCreateGroupCb(std::string funcName, int32_t stageRes)79 bool DmRadarHelper::ReportAuthCreateGroupCb(std::string funcName, int32_t stageRes)
80 {
81 return true;
82 }
83
ReportAuthPullPinBox(struct RadarInfo &info)84 bool DmRadarHelper::ReportAuthPullPinBox(struct RadarInfo &info)
85 {
86 return true;
87 }
88
ReportAuthInputPinBox(struct RadarInfo &info)89 bool DmRadarHelper::ReportAuthInputPinBox(struct RadarInfo &info)
90 {
91 return true;
92 }
93
ReportAuthAddGroup(struct RadarInfo &info)94 bool DmRadarHelper::ReportAuthAddGroup(struct RadarInfo &info)
95 {
96 return true;
97 }
98
ReportAuthAddGroupCb(std::string funcName, int32_t stageRes)99 bool DmRadarHelper::ReportAuthAddGroupCb(std::string funcName, int32_t stageRes)
100 {
101 return true;
102 }
103
ReportNetworkOnline(struct RadarInfo &info)104 bool DmRadarHelper::ReportNetworkOnline(struct RadarInfo &info)
105 {
106 return true;
107 }
108
ReportNetworkOffline(struct RadarInfo &info)109 bool DmRadarHelper::ReportNetworkOffline(struct RadarInfo &info)
110 {
111 return true;
112 }
113
ReportDeleteTrustRelation(struct RadarInfo &info)114 bool DmRadarHelper::ReportDeleteTrustRelation(struct RadarInfo &info)
115 {
116 return true;
117 }
118
ReportGetTrustDeviceList(std::string hostName, std::string funcName, std::vector<DmDeviceInfo> &deviceInfoList, int32_t errCode)119 void DmRadarHelper::ReportGetTrustDeviceList(std::string hostName,
120 std::string funcName, std::vector<DmDeviceInfo> &deviceInfoList, int32_t errCode)
121 {
122 return;
123 }
124
ReportCreatePinHolder(std::string hostName, int32_t channelId, std::string peerUdid, int32_t errCode, int32_t stageRes)125 void DmRadarHelper::ReportCreatePinHolder(std::string hostName,
126 int32_t channelId, std::string peerUdid, int32_t errCode, int32_t stageRes)
127 {
128 return;
129 }
130
ReportDestroyPinHolder(std::string hostName, std::string peerUdid, int32_t errCode, int32_t stageRes)131 void DmRadarHelper::ReportDestroyPinHolder(std::string hostName,
132 std::string peerUdid, int32_t errCode, int32_t stageRes)
133 {
134 return;
135 }
136
ReportSendOrReceiveHolderMsg(int32_t bizStage, std::string funcName, std::string peerUdid)137 void DmRadarHelper::ReportSendOrReceiveHolderMsg(int32_t bizStage, std::string funcName, std::string peerUdid)
138 {
139 return;
140 }
141
ReportDmBehavior(std::string hostName, std::string funcName, int32_t errCode)142 void DmRadarHelper::ReportDmBehavior(std::string hostName, std::string funcName, int32_t errCode)
143 {
144 return;
145 }
146
ReportGetLocalDevInfo(std::string hostName, std::string funcName, DmDeviceInfo &info, int32_t errCode)147 void DmRadarHelper::ReportGetLocalDevInfo(std::string hostName,
148 std::string funcName, DmDeviceInfo &info, int32_t errCode)
149 {
150 return;
151 }
152
ReportGetDeviceInfo(std::string hostName, std::string funcName, DmDeviceInfo &info, int32_t errCode)153 void DmRadarHelper::ReportGetDeviceInfo(std::string hostName,
154 std::string funcName, DmDeviceInfo &info, int32_t errCode)
155 {
156 return;
157 }
158
ConvertHexToString(uint16_t hex)159 std::string DmRadarHelper::ConvertHexToString(uint16_t hex)
160 {
161 std::stringstream str;
162 int32_t with = 3;
163 str << std::hex << std::setw(with) << std::setfill('0') << hex;
164 std::string hexStr = str.str();
165 transform(hexStr.begin(), hexStr.end(), hexStr.begin(), ::toupper);
166 return hexStr;
167 }
168
GetDeviceInfoList(std::vector<DmDeviceInfo> &deviceInfoList)169 std::string DmRadarHelper::GetDeviceInfoList(std::vector<DmDeviceInfo> &deviceInfoList)
170 {
171 return "";
172 }
173
GetAnonyUdid(std::string udid)174 std::string DmRadarHelper::GetAnonyUdid(std::string udid)
175 {
176 if (udid.empty() || udid.length() < INVALID_UDID_LENGTH) {
177 return "unknown";
178 }
179 return udid.substr(0, SUBSTR_UDID_LENGTH) + "**" + udid.substr(udid.length() - SUBSTR_UDID_LENGTH);
180 }
181
GetAnonyLocalUdid()182 std::string DmRadarHelper::GetAnonyLocalUdid()
183 {
184 char localDeviceId[DEVICE_UUID_LENGTH] = {0};
185 GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH);
186 return GetAnonyUdid(std::string(localDeviceId));
187 }
188
GetErrCode(int32_t errCode)189 int32_t DmRadarHelper::GetErrCode(int32_t errCode)
190 {
191 auto flag = MAP_ERROR_CODE.find(errCode);
192 if (flag == MAP_ERROR_CODE.end()) {
193 return errCode;
194 }
195 return flag->second;
196 }
197
CreateDmRadarInstance()198 IDmRadarHelper *CreateDmRadarInstance()
199 {
200 return &DmRadarHelper::GetInstance();
201 }
202 } // namespace DistributedHardware
203 } // namespace OHOS
204