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 26namespace OHOS { 27namespace DistributedHardware { 28DM_IMPLEMENT_SINGLE_INSTANCE(DmRadarHelper); 29bool DmRadarHelper::ReportDiscoverRegCallback(struct RadarInfo &info) 30{ 31 return true; 32} 33 34bool DmRadarHelper::ReportDiscoverResCallback(struct RadarInfo &info) 35{ 36 return true; 37} 38 39bool DmRadarHelper::ReportDiscoverUserRes(struct RadarInfo &info) 40{ 41 return true; 42} 43 44bool DmRadarHelper::ReportAuthStart(const std::string &peerUdid, const std::string &pkgName) 45{ 46 return true; 47} 48 49bool DmRadarHelper::ReportAuthOpenSession(struct RadarInfo &info) 50{ 51 return true; 52} 53 54bool DmRadarHelper::ReportAuthSessionOpenCb(struct RadarInfo &info) 55{ 56 return true; 57} 58 59bool DmRadarHelper::ReportAuthSendRequest(struct RadarInfo &info) 60{ 61 return true; 62} 63 64bool DmRadarHelper::ReportAuthPullAuthBox(struct RadarInfo &info) 65{ 66 return true; 67} 68 69bool DmRadarHelper::ReportAuthConfirmBox(struct RadarInfo &info) 70{ 71 return true; 72} 73 74bool DmRadarHelper::ReportAuthCreateGroup(struct RadarInfo &info) 75{ 76 return true; 77} 78 79bool DmRadarHelper::ReportAuthCreateGroupCb(std::string funcName, int32_t stageRes) 80{ 81 return true; 82} 83 84bool DmRadarHelper::ReportAuthPullPinBox(struct RadarInfo &info) 85{ 86 return true; 87} 88 89bool DmRadarHelper::ReportAuthInputPinBox(struct RadarInfo &info) 90{ 91 return true; 92} 93 94bool DmRadarHelper::ReportAuthAddGroup(struct RadarInfo &info) 95{ 96 return true; 97} 98 99bool DmRadarHelper::ReportAuthAddGroupCb(std::string funcName, int32_t stageRes) 100{ 101 return true; 102} 103 104bool DmRadarHelper::ReportNetworkOnline(struct RadarInfo &info) 105{ 106 return true; 107} 108 109bool DmRadarHelper::ReportNetworkOffline(struct RadarInfo &info) 110{ 111 return true; 112} 113 114bool DmRadarHelper::ReportDeleteTrustRelation(struct RadarInfo &info) 115{ 116 return true; 117} 118 119void DmRadarHelper::ReportGetTrustDeviceList(std::string hostName, 120 std::string funcName, std::vector<DmDeviceInfo> &deviceInfoList, int32_t errCode) 121{ 122 return; 123} 124 125void DmRadarHelper::ReportCreatePinHolder(std::string hostName, 126 int32_t channelId, std::string peerUdid, int32_t errCode, int32_t stageRes) 127{ 128 return; 129} 130 131void DmRadarHelper::ReportDestroyPinHolder(std::string hostName, 132 std::string peerUdid, int32_t errCode, int32_t stageRes) 133{ 134 return; 135} 136 137void DmRadarHelper::ReportSendOrReceiveHolderMsg(int32_t bizStage, std::string funcName, std::string peerUdid) 138{ 139 return; 140} 141 142void DmRadarHelper::ReportDmBehavior(std::string hostName, std::string funcName, int32_t errCode) 143{ 144 return; 145} 146 147void DmRadarHelper::ReportGetLocalDevInfo(std::string hostName, 148 std::string funcName, DmDeviceInfo &info, int32_t errCode) 149{ 150 return; 151} 152 153void DmRadarHelper::ReportGetDeviceInfo(std::string hostName, 154 std::string funcName, DmDeviceInfo &info, int32_t errCode) 155{ 156 return; 157} 158 159std::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 169std::string DmRadarHelper::GetDeviceInfoList(std::vector<DmDeviceInfo> &deviceInfoList) 170{ 171 return ""; 172} 173 174std::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 182std::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 189int32_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 198IDmRadarHelper *CreateDmRadarInstance() 199{ 200 return &DmRadarHelper::GetInstance(); 201} 202} // namespace DistributedHardware 203} // namespace OHOS 204