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