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