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