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#ifndef OHOS_DM_RADAR_HELPER_H 17#define OHOS_DM_RADAR_HELPER_H 18 19#include <cstdint> 20#include <chrono> 21#include <string> 22#include <vector> 23 24#include "dm_single_instance.h" 25 26#include "dm_device_info.h" 27 28namespace OHOS { 29namespace DistributedHardware { 30const std::string ORGPKGNAME = "deviceManager"; 31const std::string SOFTBUSNAME = "dsoftbus"; 32const std::string HICHAINNAME = "hichain"; 33const std::string DM_DISCOVER_BEHAVIOR = "DM_DISCOVER_BEHAVIOR"; 34const std::string DM_AUTHCATION_BEHAVIOR = "DM_AUTHCATION_BEHAVIOR"; 35constexpr int32_t SUBSYS_DISTRIBUTEDHARDWARE_DM = 204; 36constexpr int32_t INVALID_UDID_LENGTH = 10; 37constexpr int32_t SUBSTR_UDID_LENGTH = 5; 38constexpr int32_t DEFAULT_STAGE = 1; 39enum class DiscoverScene : int32_t { 40 DM_DISCOVER = 0x1, 41 DM_GET_TRUST_DEVICE_LIST = 0x2, 42 DM_GET_LOCAL_DEVICE_INFO = 0x3, 43 DM_GET_DEVICE_INFO = 0x4, 44 DM_BEHAVIOR = 0x5, 45}; 46 47enum class AuthScene : int32_t { 48 DM_AUTHCATION = 0x1, 49 DM_NETWORK = 0x2, 50 DM_DELET_TRUST_RELATION = 0x3, 51 DM_PIN_HOLDER = 0x4, 52}; 53 54enum class StageRes : int32_t { 55 STAGE_IDLE = 0x0, 56 STAGE_SUCC = 0x1, 57 STAGE_FAIL = 0x2, 58 STAGE_CANCEL = 0x3, 59 STAGE_UNKNOW = 0x4, 60}; 61 62enum class BizState : int32_t { 63 BIZ_STATE_START = 0x1, 64 BIZ_STATE_END = 0x2, 65 BIZ_STATE_CANCEL = 0x3, 66}; 67 68enum class DisCoverStage : int32_t { 69 DISCOVER_REGISTER_CALLBACK = 0x1, 70 DISCOVER_USER_DEAL_RES = 0x2, 71 DISCOVER_GET_TRUST_DEVICE_LIST = 0x3, 72}; 73 74enum class AuthStage : int32_t { 75 AUTH_START = 0x1, 76 AUTH_OPEN_SESSION = 0x2, 77 AUTH_SEND_REQUEST = 0x3, 78 AUTH_PULL_AUTH_BOX = 0x4, 79 AUTH_CREATE_HICHAIN_GROUP = 0x5, 80 AUTH_PULL_PIN_BOX_START = 0x6, 81 AUTH_PULL_PIN_INPUT_BOX_END = 0x7, 82 AUTH_ADD_HICHAIN_GROUP = 0x8, 83}; 84 85enum class NetworkStage : int32_t { 86 NETWORK_ONLINE = 0x1, 87 NETWORK_OFFLINE = 0x2, 88}; 89 90enum class DeleteTrust : int32_t { 91 DELETE_TRUST = 0x1, 92}; 93 94enum class PinHolderStage : int32_t { 95 CREATE_PIN_HOLDER = 0x1, 96 SESSION_OPENED = 0x2, 97 SEND_CREATE_PIN_HOLDER_MSG = 0x3, 98 RECEIVE_CREATE_PIN_HOLDER_MSG = 0x4, 99 DESTROY_PIN_HOLDER = 0x5, 100 RECEIVE_DESTROY_PIN_HOLDER_MSG = 0x6, 101}; 102 103enum class GetTrustDeviceList : int32_t { 104 GET_TRUST_DEVICE_LIST = 0x1, 105}; 106 107enum class TrustStatus : int32_t { 108 NOT_TRUST = 0x0, 109 IS_TRUST = 0x1, 110}; 111 112enum class ApiType : int32_t { 113 API_UNKNOW = 0x0, 114 API_JS = 0x1, 115 API_NATIVE = 0x2, 116}; 117 118enum class CommServ : int32_t { 119 NOT_USE_SOFTBUS = 0x0, 120 USE_SOFTBUS = 0x1, 121}; 122 123enum class Module : int32_t { 124 DEVICE_MANAGER = 0x0, 125 HICHAIN = 0x1, 126 SOFTBUS = 0x2, 127 USER = 0x3 128}; 129 130struct RadarInfo { 131 std::string funcName; 132 std::string toCallPkg; 133 std::string hostName; 134 int32_t stageRes; 135 int32_t bizState; 136 std::string localSessName; 137 std::string peerSessName; 138 int32_t isTrust; 139 int32_t commServ; 140 std::string peerNetId; 141 std::string localUdid; 142 std::string peerUdid; 143 std::string discoverDevList; 144 int32_t channelId; 145 int32_t errCode; 146}; 147 148class IDmRadarHelper { 149public: 150 virtual ~IDmRadarHelper() {} 151 /** 152 * @tc.name: ReportDiscoverRegCallback 153 * @tc.desc: report discover regsit callback 154 * @tc.type: FUNC 155 */ 156 virtual bool ReportDiscoverRegCallback(struct RadarInfo &info) = 0; 157 virtual bool ReportDiscoverResCallback(struct RadarInfo &info) = 0; 158 virtual bool ReportDiscoverUserRes(struct RadarInfo &info) = 0; 159 virtual bool ReportAuthStart(const std::string &peerUdid, const std::string &pkgName) = 0; 160 virtual bool ReportAuthOpenSession(struct RadarInfo &info) = 0; 161 virtual bool ReportAuthSessionOpenCb(struct RadarInfo &info) = 0; 162 virtual bool ReportAuthSendRequest(struct RadarInfo &info) = 0; 163 virtual bool ReportAuthPullAuthBox(struct RadarInfo &info) = 0; 164 virtual bool ReportAuthConfirmBox(struct RadarInfo &info) = 0; 165 virtual bool ReportAuthCreateGroup(struct RadarInfo &info) = 0; 166 virtual bool ReportAuthCreateGroupCb(std::string funcName, int32_t stageRes) = 0; 167 virtual bool ReportAuthPullPinBox(struct RadarInfo &info) = 0; 168 virtual bool ReportAuthInputPinBox(struct RadarInfo &info) = 0; 169 virtual bool ReportAuthAddGroup(struct RadarInfo &info) = 0; 170 virtual bool ReportAuthAddGroupCb(std::string funcName, int32_t stageRes) = 0; 171 virtual bool ReportNetworkOnline(struct RadarInfo &info) = 0; 172 virtual bool ReportNetworkOffline(struct RadarInfo &info) = 0; 173 virtual bool ReportDeleteTrustRelation(struct RadarInfo &info) = 0; 174 virtual void ReportGetTrustDeviceList(std::string hostName, 175 std::string funcName, std::vector<DmDeviceInfo> &deviceInfoList, int32_t errCode) = 0; 176 virtual void ReportCreatePinHolder(std::string hostName, 177 int32_t channelId, std::string peerUdid, int32_t errCode, int32_t stageRes) = 0; 178 virtual void ReportDestroyPinHolder(std::string hostName, 179 std::string peerUdid, int32_t errCode, int32_t stageRes) = 0; 180 virtual void ReportSendOrReceiveHolderMsg(int32_t bizStage, std::string funcName, std::string peerUdid) = 0; 181 virtual void ReportDmBehavior(std::string hostName, std::string funcName, int32_t errCode) = 0; 182 virtual void ReportGetLocalDevInfo(std::string hostName, 183 std::string funcName, DmDeviceInfo &info, int32_t errCode) = 0; 184 virtual void ReportGetDeviceInfo(std::string hostName, 185 std::string funcName, DmDeviceInfo &info, int32_t errCode) = 0; 186 virtual std::string GetDeviceInfoList(std::vector<DmDeviceInfo> &deviceInfoList) = 0; 187}; 188 189class DmRadarHelper : public IDmRadarHelper { 190 DM_DECLARE_SINGLE_INSTANCE(DmRadarHelper); 191public: 192 bool ReportDiscoverRegCallback(struct RadarInfo &info) override; 193 bool ReportDiscoverResCallback(struct RadarInfo &info) override; 194 bool ReportDiscoverUserRes(struct RadarInfo &info) override; 195 bool ReportAuthStart(const std::string &peerUdid, const std::string &pkgName) override; 196 bool ReportAuthOpenSession(struct RadarInfo &info) override; 197 bool ReportAuthSessionOpenCb(struct RadarInfo &info) override; 198 bool ReportAuthSendRequest(struct RadarInfo &info) override; 199 bool ReportAuthPullAuthBox(struct RadarInfo &info) override; 200 bool ReportAuthConfirmBox(struct RadarInfo &info) override; 201 bool ReportAuthCreateGroup(struct RadarInfo &info) override; 202 bool ReportAuthCreateGroupCb(std::string funcName, int32_t stageRes) override; 203 bool ReportAuthPullPinBox(struct RadarInfo &info) override; 204 bool ReportAuthInputPinBox(struct RadarInfo &info) override; 205 bool ReportAuthAddGroup(struct RadarInfo &info) override; 206 bool ReportAuthAddGroupCb(std::string funcName, int32_t stageRes) override; 207 bool ReportNetworkOnline(struct RadarInfo &info) override; 208 bool ReportNetworkOffline(struct RadarInfo &info) override; 209 bool ReportDeleteTrustRelation(struct RadarInfo &info) override; 210 void ReportGetTrustDeviceList(std::string hostName, 211 std::string funcName, std::vector<DmDeviceInfo> &deviceInfoList, int32_t errCode) override; 212 void ReportCreatePinHolder(std::string hostName, 213 int32_t channelId, std::string peerUdid, int32_t errCode, int32_t stageRes) override; 214 void ReportDestroyPinHolder(std::string hostName, 215 std::string peerUdid, int32_t errCode, int32_t stageRes) override; 216 void ReportSendOrReceiveHolderMsg(int32_t bizStage, std::string funcName, std::string peerUdid) override; 217 void ReportDmBehavior(std::string hostName, std::string funcName, int32_t errCode) override; 218 void ReportGetLocalDevInfo(std::string hostName, 219 std::string funcName, DmDeviceInfo &info, int32_t errCode) override; 220 void ReportGetDeviceInfo(std::string hostName, 221 std::string funcName, DmDeviceInfo &info, int32_t errCode) override; 222 std::string GetDeviceInfoList(std::vector<DmDeviceInfo> &deviceInfoList) override; 223 std::string ConvertHexToString(uint16_t hex); 224 int32_t GetErrCode(int32_t errCode); 225private: 226 std::string GetAnonyUdid(std::string udid); 227 std::string GetAnonyLocalUdid(); 228 int32_t GetApiType(); 229}; 230 231extern "C" IDmRadarHelper *CreateDmRadarInstance(); 232using CreateDmRadarFuncPtr = IDmRadarHelper *(*)(void); 233} // namespace DistributedHardware 234} // namespace OHOS 235#endif // OHOS_DM_RADAR_HELPER_H