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