1 /* 2 * Copyright (c) 2022-2023 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_DEVICE_MANAGER_H 17 #define OHOS_DEVICE_MANAGER_H 18 19 #include <memory> 20 #include <string> 21 #include <vector> 22 23 #include "device_manager_callback.h" 24 #include "dm_device_info.h" 25 #include "dm_publish_info.h" 26 #include "dm_subscribe_info.h" 27 28 namespace OHOS { 29 namespace DistributedHardware { 30 class DeviceManager { 31 public: 32 static DeviceManager &GetInstance(); 33 34 public: 35 /** 36 * @brief Initialize DeviceManager. 37 * @param pkgName package name. 38 * @param dmInitCallback the callback to be invoked upon InitDeviceManager. 39 * @return Returns 0 if success. 40 */ 41 virtual int32_t InitDeviceManager(const std::string &pkgName, std::shared_ptr<DmInitCallback> dmInitCallback) = 0; 42 /** 43 * @brief UnInitialize DeviceManager. 44 * @param pkgName package name. 45 * @return Returns 0 if success. 46 */ 47 virtual int32_t UnInitDeviceManager(const std::string &pkgName) = 0; 48 /** 49 * @brief Get device info list of trusted devices. 50 * @param pkgName package name. 51 * @param extra extra info.This parameter can be null. 52 * @param deviceList device info list. 53 * @return Returns a list of trusted devices. 54 */ 55 virtual int32_t GetTrustedDeviceList(const std::string &pkgName, const std::string &extra, 56 std::vector<DmDeviceInfo> &deviceList) = 0; 57 /** 58 * @brief Get device info list of trusted devices. 59 * @param pkgName package name. 60 * @param extra extra info.This parameter can be null. 61 * @param isRefresh refresh the list quickly. 62 * @param deviceList device info list. 63 * @return Returns a list of trusted devices. 64 */ 65 virtual int32_t GetTrustedDeviceList(const std::string &pkgName, const std::string &extra, 66 bool isRefresh, std::vector<DmDeviceInfo> &deviceList) = 0; 67 /** 68 * @brief Get device info list of available devices. 69 * @param pkgName package name. 70 * @param extra extra info.This parameter can be null. 71 * @param deviceList device info list. 72 * @return Returns a list of available devices. 73 */ 74 virtual int32_t GetAvailableDeviceList(const std::string &pkgName, 75 std::vector<DmDeviceBasicInfo> &deviceList) = 0; 76 /** 77 * @brief Get local device information. 78 * @param pkgName package name. 79 * @param deviceInfo device info. 80 * @return Returns local device info. 81 */ 82 virtual int32_t GetLocalDeviceInfo(const std::string &pkgName, DmDeviceInfo &deviceInfo) = 0; 83 /** 84 * @tc.name: DeviceManagerImpl::GetDeviceInfo 85 * @tc.desc: Get local device information by networkId 86 * @tc.type: FUNC 87 */ 88 virtual int32_t GetDeviceInfo(const std::string &pkgName, const std::string networkId, 89 DmDeviceInfo &deviceInfo) = 0; 90 /** 91 * @brief Register device status callback. 92 * @param pkgName package name. 93 * @param extra extra info.This parameter can be null. 94 * @param callback device state callback. 95 * @return Returns 0 if success. 96 */ 97 virtual int32_t RegisterDevStateCallback(const std::string &pkgName, const std::string &extra, 98 std::shared_ptr<DeviceStateCallback> callback) = 0; 99 /** 100 * @brief Register device status callback. 101 * @param pkgName package name. 102 * @param callback device status callback. 103 * @return Returns 0 if success. 104 */ 105 virtual int32_t RegisterDevStatusCallback(const std::string &pkgName, const std::string &extra, 106 std::shared_ptr<DeviceStatusCallback> callback) = 0; 107 /** 108 * @brief Unregister device status callback. 109 * @param pkgName package name. 110 * @return Returns 0 if success. 111 */ 112 virtual int32_t UnRegisterDevStateCallback(const std::string &pkgName) = 0; 113 /** 114 * @brief Unregister device status callback. 115 * @param pkgName package name. 116 * @return Returns 0 if success. 117 */ 118 virtual int32_t UnRegisterDevStatusCallback(const std::string &pkgName) = 0; 119 /** 120 * @brief Initiate device discovery. 121 * @param pkgName package name. 122 * @param subscribeInfo subscribe info to discovery device. 123 * @param extra extra info.This parameter can be null. 124 * @param callback discovery callback. 125 * @return Returns 0 if success. 126 */ 127 virtual int32_t StartDeviceDiscovery(const std::string &pkgName, const DmSubscribeInfo &subscribeInfo, 128 const std::string &extra, std::shared_ptr<DiscoveryCallback> callback) = 0; 129 /** 130 * @brief Initiate device discovery. 131 * @param pkgName package name. 132 * @param subscribeId subscribe id to discovery device. 133 * @param extra extra info.This parameter can be null. 134 * @param callback discovery callback. 135 * @return Returns 0 if success. 136 */ 137 virtual int32_t StartDeviceDiscovery(const std::string &pkgName, uint64_t tokenId, 138 const std::string &filterOptions, std::shared_ptr<DiscoveryCallback> callback) = 0; 139 /** 140 * @brief Stop device discovery. 141 * @param pkgName package name. 142 * @param subscribeInfo subscribe info to discovery device. 143 * @return Returns 0 if success. 144 */ 145 virtual int32_t StopDeviceDiscovery(const std::string &pkgName, uint16_t subscribeId) = 0; 146 /** 147 * @brief Stop device discovery. 148 * @param pkgName package name. 149 * @param tokenId app flag to discovery device. 150 * @return Returns 0 if success. 151 */ 152 virtual int32_t StopDeviceDiscovery(uint64_t tokenId, const std::string &pkgName) = 0; 153 /** 154 * @brief Publish device discovery. 155 * @param pkgName package name. 156 * @param publishInfo publish info to Publish discovery device. 157 * @param callback the callback to be invoked upon PublishDeviceDiscovery. 158 * @return Returns 0 if success. 159 */ 160 virtual int32_t PublishDeviceDiscovery(const std::string &pkgName, const DmPublishInfo &publishInfo, 161 std::shared_ptr<PublishCallback> callback) = 0; 162 /** 163 * @brief UnPublish device discovery. 164 * @param pkgName package name. 165 * @param publishId service publish ID, identify a publish operation, should be a unique id in package range. 166 * @return Returns 0 if success. 167 */ 168 virtual int32_t UnPublishDeviceDiscovery(const std::string &pkgName, int32_t publishId) = 0; 169 /** 170 * @brief Authenticate the specified device. 171 * @param pkgName package name. 172 * @param authType authType of device to authenticate. 173 * @param deviceInfo deviceInfo of device to authenticate. 174 * @param extra extra info.This parameter can be null. 175 * @param callback the callback to be invoked upon AuthenticateDevice. 176 * @return Returns 0 if success. 177 */ 178 virtual int32_t AuthenticateDevice(const std::string &pkgName, int32_t authType, const DmDeviceInfo &deviceInfo, 179 const std::string &extra, std::shared_ptr<AuthenticateCallback> callback) = 0; 180 /** 181 * @brief Cancel complete verification of device. 182 * @param pkgName package name. 183 * @param deviceInfo deviceInfo of device to authenticate. 184 * @return Returns 0 if success. 185 */ 186 virtual int32_t UnAuthenticateDevice(const std::string &pkgName, const DmDeviceInfo &deviceInfo) = 0; 187 /** 188 * @brief Verify device authentication. 189 * @param pkgName package name. 190 * @param authPara authPara of device to authenticate. 191 * @param callback the callback to be invoked upon VerifyAuthentication. 192 * @return Returns 0 if success. 193 */ 194 virtual int32_t VerifyAuthentication(const std::string &pkgName, const std::string &authPara, 195 std::shared_ptr<VerifyAuthCallback> callback) = 0; 196 /** 197 * @brief Register Fa callback for device manager. 198 * @param pkgName package name. 199 * @param callback device manager Fa callback. 200 * @return Returns 0 if success. 201 */ 202 virtual int32_t RegisterDeviceManagerFaCallback(const std::string &pkgName, 203 std::shared_ptr<DeviceManagerUiCallback> callback) = 0; 204 /** 205 * @brief Unregister Fa callback for device manager. 206 * @param pkgName package name. 207 * @return Returns 0 if success. 208 */ 209 virtual int32_t UnRegisterDeviceManagerFaCallback(const std::string &pkgName) = 0; 210 /** 211 * @brief Get Fa Param. 212 * @param pkgName package name. 213 * @param faParam fa param. 214 * @return Returns 0 if success. 215 */ 216 virtual int32_t GetFaParam(const std::string &pkgName, DmAuthParam &faParam) = 0; 217 /** 218 * @brief Set User Actions. 219 * @param pkgName package name. 220 * @param action user operation action. 221 * @param params indicates the input param of the user. 222 * @return Returns 0 if success. 223 */ 224 virtual int32_t SetUserOperation(const std::string &pkgName, int32_t action, const std::string ¶ms) = 0; 225 /** 226 * @brief Get Udid by NetworkId. 227 * @param pkgName package name. 228 * @param netWorkId netWork Id. 229 * @param udid unique device id. 230 * @return Returns 0 if success. 231 */ 232 virtual int32_t GetUdidByNetworkId(const std::string &pkgName, const std::string &netWorkId, std::string &udid) = 0; 233 /** 234 * @brief Get Uuid by NetworkId. 235 * @param pkgName package name. 236 * @param netWorkId netWork Id. 237 * @param uuid universally unique id. 238 * @return Returns 0 if success. 239 */ 240 virtual int32_t GetUuidByNetworkId(const std::string &pkgName, const std::string &netWorkId, std::string &uuid) = 0; 241 /** 242 * @brief Unregister device status callback. 243 * @param pkgName package name. 244 * @param extra extra info.This parameter can be null. 245 * @return Returns 0 if success. 246 */ 247 virtual int32_t RegisterDevStateCallback(const std::string &pkgName, const std::string &extra) = 0; 248 /** 249 * @brief Unregister device status callback. 250 * @param pkgName package name. 251 * @param extra extra info.This parameter can be null. 252 * @return Returns 0 if success. 253 */ 254 virtual int32_t UnRegisterDevStateCallback(const std::string &pkgName, const std::string &extra) = 0; 255 /** 256 * @brief Request credential information. 257 * @param pkgName package name. 258 * @param reqJsonStr request credential params, the params is json string, it includes version and userId. 259 * @param returnJsonStr return json string, it includes deviceId, devicePk, useId and version. 260 * @return Returns 0 if success. 261 */ 262 virtual int32_t RequestCredential(const std::string &pkgName, const std::string &reqJsonStr, 263 std::string &returnJsonStr) = 0; 264 /** 265 * @brief Import credential information. 266 * @param pkgName package name. 267 * @param credentialInfo import credential params, the params is json string, it includes processType, authType, 268 * userId, deviceId, version, devicePk and credentialData, the credentialData is array, each array element 269 * includes credentialType, credentialId, serverPk, pkInfoSignature, pkInfo, authCode, peerDeviceId. 270 * @return Returns 0 if success. 271 */ 272 virtual int32_t ImportCredential(const std::string &pkgName, const std::string &credentialInfo) = 0; 273 /** 274 * @brief Delete credential information. 275 * @param pkgName package name. 276 * @param deleteInfo delete credential params. the params is json string, it includes processType, authType, userId. 277 * @return Returns 0 if success. 278 */ 279 virtual int32_t DeleteCredential(const std::string &pkgName, const std::string &deleteInfo) = 0; 280 /** 281 * @brief Register credential callback. 282 * @param pkgName package name. 283 * @param callback credential callback. 284 * @return Returns 0 if success. 285 */ 286 virtual int32_t RegisterCredentialCallback(const std::string &pkgName, 287 std::shared_ptr<CredentialCallback> callback) = 0; 288 /** 289 * @brief UnRegister credential callback. 290 * @param pkgName package name. 291 * @return Returns 0 if success. 292 */ 293 virtual int32_t UnRegisterCredentialCallback(const std::string &pkgName) = 0; 294 /** 295 * @brief Notify event to device manager. 296 * @param pkgName package name. 297 * @param event event info. 298 * @param event event string. 299 * @return Returns 0 if success. 300 */ 301 virtual int32_t NotifyEvent(const std::string &pkgName, const int32_t eventId, const std::string &event) = 0; 302 303 /** 304 * @brief Get encrypted uuid. 305 * @param networkId device networkId. 306 * @return Returns encrypted uuid. 307 */ 308 virtual int32_t GetEncryptedUuidByNetworkId(const std::string &pkgName, const std::string &networkId, 309 std::string &uuid) = 0; 310 311 /** 312 * @brief Get encrypted uuid. 313 * @param uuid device uuid. 314 * @param tokenId tokenId. 315 * @return Returns encrypted uuid. 316 */ 317 virtual int32_t GenerateEncryptedUuid(const std::string &pkgName, const std::string &uuid, const std::string &appId, 318 std::string &encryptedUuid) = 0; 319 320 /** 321 * @tc.name: DeviceManagerImpl::CheckAPIAccessPermission 322 * @tc.desc: check permission for device manager API 323 * @tc.type: FUNC 324 */ 325 virtual int32_t CheckAPIAccessPermission() = 0; 326 327 /** 328 * @brief Get local device netWorkId. 329 * @param pkgName package name. 330 * @return Returns local device networkId. 331 */ 332 virtual int32_t GetLocalDeviceNetWorkId(const std::string &pkgName, std::string &networkId) = 0; 333 334 /** 335 * @brief Get local deviceId. 336 * @param pkgName package name. 337 * @return Returns local deviceId. 338 */ 339 virtual int32_t GetLocalDeviceId(const std::string &pkgName, std::string &networkId) = 0; 340 341 /** 342 * @brief Get local device name. 343 * @param pkgName package name. 344 * @return Returns device name. 345 */ 346 virtual int32_t GetLocalDeviceName(const std::string &pkgName, std::string &deviceName) = 0; 347 348 /** 349 * @brief Get local device type. 350 * @param pkgName package name. 351 * @return Returns device type. 352 */ 353 virtual int32_t GetLocalDeviceType(const std::string &pkgName, int32_t &deviceType) = 0; 354 355 /** 356 * @brief Get device name. 357 * @param pkgName package name. 358 * @param networkId device networkId. 359 * @return Returns device name. 360 */ 361 virtual int32_t GetDeviceName(const std::string &pkgName, const std::string &networkId, 362 std::string &deviceName) = 0; 363 364 /** 365 * @brief Get device type. 366 * @param pkgName package name. 367 * @param networkId device networkId. 368 * @return Returns device type. 369 */ 370 virtual int32_t GetDeviceType(const std::string &pkgName, const std::string &networkId, int32_t &deviceType) = 0; 371 372 /** 373 * @brief Bind the specified device. 374 * @param pkgName package name. 375 * @param bindType bindType of device to bind. 376 * @param deviceInfo device id of device to bind. 377 * @param extra extra info.This parameter can be null. 378 * @param callback callback. 379 * @return Returns 0 if success. 380 */ 381 virtual int32_t BindDevice(const std::string &pkgName, int32_t bindType, const std::string &deviceId, 382 const std::string &extra, std::shared_ptr<AuthenticateCallback> callback) = 0; 383 384 /** 385 * @brief UnBind the specified device. 386 * @param pkgName package name. 387 * @param deviceId device id to UnBindDevice. 388 * @return Returns 0 if success. 389 */ 390 virtual int32_t UnBindDevice(const std::string &pkgName, const std::string &deviceId) = 0; 391 392 virtual int32_t CheckNewAPIAccessPermission() = 0; 393 394 /** 395 * @brief Get Network Type by NetworkId. 396 * @param pkgName package name. 397 * @param netWorkId netWork Id. 398 * @param netWorkType netWork Type. 399 * @return Returns 0 if success. 400 */ 401 virtual int32_t GetNetworkTypeByNetworkId(const std::string &pkgName, 402 const std::string &netWorkId, int32_t &netWorkType) = 0; 403 }; 404 } // namespace DistributedHardware 405 } // namespace OHOS 406 #endif // DEVICE_MANAGER_H 407