1 /* 2 * Copyright (C) 2021 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 BLUETOOTH_REMOTE_DEVICE_H 17 #define BLUETOOTH_REMOTE_DEVICE_H 18 19 #include <string> 20 #include <vector> 21 22 #include "bluetooth_def.h" 23 #include "bluetooth_types.h" 24 #include "bluetooth_device_class.h" 25 #include "bluetooth_battery_info.h" 26 27 namespace OHOS { 28 namespace Bluetooth { 29 class BLUETOOTH_API BluetoothRemoteDevice { 30 public: 31 /// common 32 /** 33 * @brief A structor used to create the <b>BluetoothRemoteDevice</b> instance. 34 * 35 * @since 6 36 */ BluetoothRemoteDevice()37 BluetoothRemoteDevice(){}; 38 /** 39 * @brief A structor used to create the <b>BluetoothRemoteDevice</b> instance. 40 * 41 * @since 6 42 */ 43 BluetoothRemoteDevice(const std::string &addr, const int transport = BT_TRANSPORT_NONE); 44 /** 45 * @brief A destructor used to delete the <b>BluetoothRemoteDevice</b> instance. 46 * 47 * @since 6 48 */ ~BluetoothRemoteDevice()49 virtual ~BluetoothRemoteDevice(){}; 50 51 /** 52 * @brief Get phonebook permission for device. 53 * 54 * @return Returns permission grade. 55 * BTPermissionType::ACCESS_UNKNOWN; 56 * BTPermissionType::ACCESS_ALLOWED; 57 * BTPermissionType::ACCESS_FORBIDDEN. 58 * @since 6 59 */ 60 int GetPhonebookPermission() const; 61 62 /** 63 * @brief Set phonebook permission for device. 64 * 65 * @param permission permission grade. 66 * BTPermissionType::ACCESS_UNKNOWN; 67 * BTPermissionType::ACCESS_ALLOWED; 68 * BTPermissionType::ACCESS_FORBIDDEN. 69 * @return Returns <b>true</b> if the operation is successful; 70 * returns <b>false</b> if the operation fails. 71 * @since 6 72 */ 73 bool SetPhonebookPermission(int permission); 74 75 /** 76 * @brief Get message permission for device. 77 * 78 * @return Returns permission grade. 79 * BTPermissionType::ACCESS_UNKNOWN; 80 * BTPermissionType::ACCESS_ALLOWED; 81 * BTPermissionType::ACCESS_FORBIDDEN. 82 * @since 6 83 */ 84 int GetMessagePermission() const; 85 86 /** 87 * @brief Set message permission for device. 88 * 89 * @param permission permission grade. 90 * BTPermissionType::ACCESS_UNKNOWN; 91 * BTPermissionType::ACCESS_ALLOWED; 92 * BTPermissionType::ACCESS_FORBIDDEN. 93 * @return Returns <b>true</b> if the operation is successful; 94 * returns <b>false</b> if the operation fails. 95 * @since 6 96 */ 97 bool SetMessagePermission(int permission); 98 99 /** 100 * @brief Get power mode for device. 101 * 102 * @return Returns power mode grade. 103 * BTPowerMode::MODE_INVALID = 0x00, 104 * BTPowerMode::MODE_ACTIVE = 0x100, 105 * BTPowerMode::MODE_SNIFF_LEVEL_LOW = 0x201, 106 * BTPowerMode::MODE_SNIFF_LEVEL_MID = 0x202, 107 * BTPowerMode::MODE_SNIFF_LEVEL_HIG = 0x203, 108 * @since 6 109 */ 110 int GetPowerMode(void) const; 111 112 // gap 113 114 /** 115 * @brief Get device address. 116 * 117 * @return Returns device adress. 118 * @since 6 119 */ GetDeviceAddr()120 std::string GetDeviceAddr() const 121 { 122 return address_; 123 }; 124 125 /** 126 * @brief Get device name. 127 * 128 * @return Returns device name. 129 * @since 6 130 */ 131 std::string GetDeviceName() const; 132 133 /** 134 * @brief Get device name. 135 * 136 * @param Indicates whether to obtain the device alias. 137 * @return Returns device name. 138 * @since 6 139 */ 140 int GetDeviceName(std::string &name, bool alias = true) const; 141 142 /** 143 * @brief Get device alias. 144 * 145 * @return Returns device alias. 146 * @since 6 147 */ 148 std::string GetDeviceAlias() const; 149 150 /** 151 * @brief Set device alias. 152 * 153 * @param aliasName Device alias name. 154 * @return Returns <b>BT_NO_ERROR</b> if the operation is successful; 155 * returns <b>other error code</b> if the operation fails. 156 * @since 6 157 */ 158 int32_t SetDeviceAlias(const std::string &aliasName); 159 160 /** 161 * @brief Get device type. 162 * 163 * @return Returns device type. 164 * @since 6 165 */ 166 int GetDeviceType() const; 167 168 /** 169 * @brief Get device battery levele. 170 * 171 * @param[out] batteryInfo the device battery info. 172 * @return Returns operation code 173 * @since 12 174 */ 175 int GetRemoteDeviceBatteryInfo(DeviceBatteryInfo &batteryInfo) const; 176 177 /** 178 * @brief Get device pair state. 179 * 180 * @return Returns device pair state. 181 * @since 6 182 */ 183 int GetPairState(int &pairState) const; 184 185 /** 186 * @brief Device start pair. 187 * 188 * @return Returns <b>true</b> if the operation is successful; 189 * returns <b>false</b> if the operation fails. 190 * @since 6 191 */ 192 int StartPair(); 193 194 /** 195 * @brief Credible Device start pair. 196 * 197 * @return Returns <b>BT_NO_ERROR</b> if the operation is successful; 198 * returns <b>Other code</b> if the operation fails. 199 * @since 10 200 */ 201 int StartCrediblePair(); 202 203 /** 204 * @brief Cancel pair operation. 205 * 206 * @return Returns <b>true</b> if the operation is successful; 207 * returns <b>false</b> if the operation fails. 208 * @since 6 209 */ 210 int CancelPairing(); 211 212 /** 213 * @brief Check if device was bonded from local. 214 * 215 * @return Returns <b>true</b> if device was bonded from local; 216 * returns <b>false</b> if device was not bonded from local. 217 * @since 6 218 */ 219 bool IsBondedFromLocal() const; 220 221 /** 222 * @brief Check if device acl connected. 223 * 224 * @return Returns <b>true</b> if device acl connected; 225 * returns <b>false</b> if device does not acl connect. 226 * @since 6 227 */ 228 bool IsAclConnected() const; 229 230 /** 231 * @brief Check if device acl Encrypted. 232 * 233 * @return Returns <b>true</b> if device acl Encrypted; 234 * returns <b>false</b> if device does not acl Encrypt. 235 * @since 6 236 */ 237 bool IsAclEncrypted() const; 238 239 /** 240 * @brief Get device class. 241 * 242 * @return Returns device class; 243 * @since 6 244 */ 245 int GetDeviceClass(int &cod) const; 246 247 /** 248 * @brief Get the product id of a remote device. 249 * 250 * @return Returns device product id; 251 * @since 11 252 */ 253 int GetDeviceProductId(std::string &prodcutId) const; 254 255 /** 256 * @brief Get device uuids. 257 * 258 * @return Returns device uuids; 259 * @since 6 260 */ 261 int GetDeviceUuids(std::vector<std::string> &uuids) const; 262 263 /** 264 * @brief Set device pair pin. 265 * 266 * @param pin Pin code. 267 * @return Returns <b>true</b> if the operation is successful; 268 * returns <b>false</b> if the operation fails. 269 * @since 6 270 */ 271 int SetDevicePin(const std::string &pin); 272 273 /** 274 * @brief Set device pairing confirmation. 275 * 276 * @param accept Set gap accept flag. 277 * @return Returns <b>true</b> if the operation is successful; 278 * returns <b>false</b> if the operation fails. 279 * @since 6 280 */ 281 int SetDevicePairingConfirmation(bool accept); 282 283 /** 284 * @brief Set device pair passkey. 285 * 286 * @param passkey Device passkey. 287 * @param accept Set gap accept flag. 288 * @return Returns <b>true</b> if the operation is successful; 289 * returns <b>false</b> if the operation fails. 290 * @since 6 291 */ 292 bool SetDevicePasskey(int passkey, bool accept); 293 294 /** 295 * @brief Check device pair request reply. 296 * 297 * @param accept Set gap accept flag. 298 * @return Returns <b>true</b> if the operation is successful; 299 * returns <b>false</b> if the operation fails. 300 * @since 6 301 */ 302 bool PairRequestReply(bool accept); 303 304 /** 305 * @brief Get device transport type. 306 * 307 * @return Returns device transport type; 308 * @since 6 309 */ 310 int GetTransportType() const; 311 312 // ble 313 /** 314 * @brief Read remote device rssi value. 315 * 316 * @return Returns <b>true</b> if the operation is successful; 317 * returns <b>false</b> if the operation fails. 318 * @since 6 319 */ 320 bool ReadRemoteRssiValue(); 321 322 /** 323 * @brief Check if bluetooth remote device is valid. 324 * 325 * @return Returns <b>true</b> if bluetooth remote device is valid; 326 * returns <b>false</b> if bluetooth remote device is not valid. 327 * @since 6 328 */ 329 bool IsValidBluetoothRemoteDevice() const; 330 331 /** 332 * @brief Get the product type of the device, such as headsets, watchs and car. 333 * 334 * @param cod Class of device. 335 * @param majorClass The major class. 336 * @param majorMinorClass The minor class. 337 * @return Returns <b>BT_NO_ERROR</b> if the operation is successful; 338 * returns <b>Other code</b> if the operation fails. 339 * @since 11 340 */ 341 int GetDeviceProductType(int &cod, int &majorClass, int &majorMinorClass) const; 342 343 /** 344 * @brief Set the product type of the device, such as headsets, watchs and car. 345 * 346 * @param deviceType The type of device. 347 * @return Returns <b>BT_NO_ERROR</b> if the operation is successful; 348 * returns <b>Other code</b> if the operation fails. 349 * @since 12 350 */ 351 int32_t SetDeviceCustomType(int32_t deviceType) const; 352 353 /** 354 * @brief Get the product type of the device, such as headsets, watchs and car. 355 * 356 * @param deviceType The type of device. 357 * @return Returns <b>BT_NO_ERROR</b> if the operation is successful; 358 * returns <b>Other code</b> if the operation fails. 359 * @since 12 360 */ 361 int32_t GetDeviceCustomType(int32_t &deviceType) const; 362 363 /** 364 * @brief Get the vendor id of the device. 365 * 366 * @param[out] vendorId The vendor id of device. 367 * @return Returns <b>BT_NO_ERROR</b> if the operation is successful; 368 * returns <b>Other code</b> if the operation fails. 369 * @since 12 370 */ 371 int32_t GetDeviceVendorId(uint16_t &vendorId) const; 372 373 /** 374 * @brief Get the product id of the device. 375 * 376 * @param[out] productId The product id of device. 377 * @return Returns <b>BT_NO_ERROR</b> if the operation is successful; 378 * returns <b>Other code</b> if the operation fails. 379 * @since 12 380 */ 381 int32_t GetDeviceProductId(uint16_t &productId) const; 382 383 /** 384 * @brief Get remote device is supported virtual auto connect. 385 * 386 * @param[out] outSupport The remote device configured auto connect value. 387 * @return Returns <b>BT_NO_ERROR</b> if the operation is successful; 388 * returns <b>Other code</b> if the operation fails. 389 * @since 12 390 */ 391 int32_t IsSupportVirtualAutoConnect(bool &outSupport) const; 392 393 /** 394 * @brief Set remote device auto connect type and business connect type. 395 * 396 * @param connType Auto connect type value. 397 * @param businessType Business connect type value. 398 * @return Returns <b>BT_NO_ERROR</b> if the operation is successful; 399 * returns <b>Other code</b> if the operation fails. 400 * @since 12 401 */ 402 int32_t SetVirtualAutoConnectType(int connType, int businessType) const; 403 404 /** 405 * @brief Get latest connection time of device. 406 * 407 * @return latest connection time, or 0 if there was a problem. 408 * @since 16 409 */ 410 int32_t GetLastConnectionTime(int64_t &connectionTime) const; 411 412 int32_t GetCloudBondState(int32_t &cloudBondState) const; 413 private: 414 std::string address_ = "00:00:00:00:00:00"; 415 int transport_ = BT_TRANSPORT_NONE; 416 }; 417 } // namespace Bluetooth 418 } // namespace OHOS 419 420 #endif // BLUETOOTH_REMOTE_DEVICE_H 421