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 26 namespace OHOS { 27 namespace Bluetooth { 28 class BLUETOOTH_API BluetoothRemoteDevice { 29 public: 30 /// common 31 /** 32 * @brief A structor used to create the <b>BluetoothRemoteDevice</b> instance. 33 * 34 * @since 6 35 */ BluetoothRemoteDevice()36 BluetoothRemoteDevice(){}; 37 /** 38 * @brief A structor used to create the <b>BluetoothRemoteDevice</b> instance. 39 * 40 * @since 6 41 */ 42 BluetoothRemoteDevice(const std::string &addr, const int transport = BT_TRANSPORT_NONE); 43 /** 44 * @brief A destructor used to delete the <b>BluetoothRemoteDevice</b> instance. 45 * 46 * @since 6 47 */ ~BluetoothRemoteDevice()48 virtual ~BluetoothRemoteDevice(){}; 49 50 /** 51 * @brief Get phonebook permission for device. 52 * 53 * @return Returns permission grade. 54 * BTPermissionType::ACCESS_UNKNOWN; 55 * BTPermissionType::ACCESS_ALLOWED; 56 * BTPermissionType::ACCESS_FORBIDDEN. 57 * @since 6 58 */ 59 int GetPhonebookPermission() const; 60 61 /** 62 * @brief Set phonebook permission for device. 63 * 64 * @param permission permission grade. 65 * BTPermissionType::ACCESS_UNKNOWN; 66 * BTPermissionType::ACCESS_ALLOWED; 67 * BTPermissionType::ACCESS_FORBIDDEN. 68 * @return Returns <b>true</b> if the operation is successful; 69 * returns <b>false</b> if the operation fails. 70 * @since 6 71 */ 72 bool SetPhonebookPermission(int permission); 73 74 /** 75 * @brief Get message permission for device. 76 * 77 * @return Returns permission grade. 78 * BTPermissionType::ACCESS_UNKNOWN; 79 * BTPermissionType::ACCESS_ALLOWED; 80 * BTPermissionType::ACCESS_FORBIDDEN. 81 * @since 6 82 */ 83 int GetMessagePermission() const; 84 85 /** 86 * @brief Set message permission for device. 87 * 88 * @param permission permission grade. 89 * BTPermissionType::ACCESS_UNKNOWN; 90 * BTPermissionType::ACCESS_ALLOWED; 91 * BTPermissionType::ACCESS_FORBIDDEN. 92 * @return Returns <b>true</b> if the operation is successful; 93 * returns <b>false</b> if the operation fails. 94 * @since 6 95 */ 96 bool SetMessagePermission(int permission); 97 98 /** 99 * @brief Get power mode for device. 100 * 101 * @return Returns power mode grade. 102 * BTPowerMode::MODE_INVALID = 0x00, 103 * BTPowerMode::MODE_ACTIVE = 0x100, 104 * BTPowerMode::MODE_SNIFF_LEVEL_LOW = 0x201, 105 * BTPowerMode::MODE_SNIFF_LEVEL_MID = 0x202, 106 * BTPowerMode::MODE_SNIFF_LEVEL_HIG = 0x203, 107 * @since 6 108 */ 109 int GetPowerMode(void) const; 110 111 // gap 112 113 /** 114 * @brief Get device address. 115 * 116 * @return Returns device adress. 117 * @since 6 118 */ GetDeviceAddr()119 std::string GetDeviceAddr() const 120 { 121 return address_; 122 }; 123 124 /** 125 * @brief Get device name. 126 * 127 * @return Returns device name. 128 * @since 6 129 */ 130 std::string GetDeviceName() const; 131 132 /** 133 * @brief Get device name. 134 * 135 * @return Returns device name. 136 * @since 6 137 */ 138 int GetDeviceName(std::string &name) const; 139 140 /** 141 * @brief Get device alias. 142 * 143 * @return Returns device alias. 144 * @since 6 145 */ 146 std::string GetDeviceAlias() const; 147 148 /** 149 * @brief Set device alias. 150 * 151 * @param aliasName Device alias name. 152 * @return Returns <b>true</b> if the operation is successful; 153 * returns <b>false</b> if the operation fails. 154 * @since 6 155 */ 156 bool SetDeviceAlias(const std::string &aliasName); 157 158 /** 159 * @brief Get device type. 160 * 161 * @return Returns device type. 162 * @since 6 163 */ 164 int GetDeviceType() const; 165 166 /** 167 * @brief Get device battery levele. 168 * 169 * @return Returns device battery levele. 170 * @since 6 171 */ 172 int GetDeviceBatteryLevel() const; 173 174 /** 175 * @brief Get device pair state. 176 * 177 * @return Returns device pair state. 178 * @since 6 179 */ 180 int GetPairState(int &pairState) const; 181 182 /** 183 * @brief Device start pair. 184 * 185 * @return Returns <b>true</b> if the operation is successful; 186 * returns <b>false</b> if the operation fails. 187 * @since 6 188 */ 189 int StartPair(); 190 191 /** 192 * @brief Credible Device start pair. 193 * 194 * @return Returns <b>BT_NO_ERROR</b> if the operation is successful; 195 * returns <b>Other code</b> if the operation fails. 196 * @since 10 197 */ 198 int StartCrediblePair(); 199 200 /** 201 * @brief Cancel pair operation. 202 * 203 * @return Returns <b>true</b> if the operation is successful; 204 * returns <b>false</b> if the operation fails. 205 * @since 6 206 */ 207 int CancelPairing(); 208 209 /** 210 * @brief Check if device was bonded from local. 211 * 212 * @return Returns <b>true</b> if device was bonded from local; 213 * returns <b>false</b> if device was not bonded from local. 214 * @since 6 215 */ 216 bool IsBondedFromLocal() const; 217 218 /** 219 * @brief Check if device acl connected. 220 * 221 * @return Returns <b>true</b> if device acl connected; 222 * returns <b>false</b> if device does not acl connect. 223 * @since 6 224 */ 225 bool IsAclConnected() const; 226 227 /** 228 * @brief Check if device acl Encrypted. 229 * 230 * @return Returns <b>true</b> if device acl Encrypted; 231 * returns <b>false</b> if device does not acl Encrypt. 232 * @since 6 233 */ 234 bool IsAclEncrypted() const; 235 236 /** 237 * @brief Get device class. 238 * 239 * @return Returns device class; 240 * @since 6 241 */ 242 int GetDeviceClass(int &cod) const; 243 244 /** 245 * @brief Get the product id of a remote device. 246 * 247 * @return Returns device product id; 248 * @since 11 249 */ 250 int GetDeviceProductId(std::string &prodcutId) const; 251 252 /** 253 * @brief Get device uuids. 254 * 255 * @return Returns device uuids; 256 * @since 6 257 */ 258 int GetDeviceUuids(std::vector<std::string> &uuids) const; 259 260 /** 261 * @brief Set device pair pin. 262 * 263 * @param pin Pin code. 264 * @return Returns <b>true</b> if the operation is successful; 265 * returns <b>false</b> if the operation fails. 266 * @since 6 267 */ 268 int SetDevicePin(const std::string &pin); 269 270 /** 271 * @brief Set device pairing confirmation. 272 * 273 * @param accept Set gap accept flag. 274 * @return Returns <b>true</b> if the operation is successful; 275 * returns <b>false</b> if the operation fails. 276 * @since 6 277 */ 278 int SetDevicePairingConfirmation(bool accept); 279 280 /** 281 * @brief Set device pair passkey. 282 * 283 * @param passkey Device passkey. 284 * @param accept Set gap accept flag. 285 * @return Returns <b>true</b> if the operation is successful; 286 * returns <b>false</b> if the operation fails. 287 * @since 6 288 */ 289 bool SetDevicePasskey(int passkey, bool accept); 290 291 /** 292 * @brief Check device pair request reply. 293 * 294 * @param accept Set gap accept flag. 295 * @return Returns <b>true</b> if the operation is successful; 296 * returns <b>false</b> if the operation fails. 297 * @since 6 298 */ 299 bool PairRequestReply(bool accept); 300 301 /** 302 * @brief Get device transport type. 303 * 304 * @return Returns device transport type; 305 * @since 6 306 */ 307 int GetTransportType() const; 308 309 // ble 310 /** 311 * @brief Read remote device rssi value. 312 * 313 * @return Returns <b>true</b> if the operation is successful; 314 * returns <b>false</b> if the operation fails. 315 * @since 6 316 */ 317 bool ReadRemoteRssiValue(); 318 319 /** 320 * @brief Check if bluetooth remote device is valid. 321 * 322 * @return Returns <b>true</b> if bluetooth remote device is valid; 323 * returns <b>false</b> if bluetooth remote device is not valid. 324 * @since 6 325 */ 326 bool IsValidBluetoothRemoteDevice() const; 327 328 /** 329 * @brief Get the product type of the device, such as headsets, watchs and car. 330 * 331 * @param cod Class of device. 332 * @param majorClass The major class. 333 * @param majorMinorClass The minor class. 334 * @return Returns <b>BT_NO_ERROR</b> if the operation is successful; 335 * returns <b>Other code</b> if the operation fails. 336 * @since 11 337 */ 338 int GetDeviceProductType(int &cod, int &majorClass, int &majorMinorClass) const; 339 340 private: 341 std::string address_ = "00:00:00:00:00:00"; 342 int transport_ = BT_TRANSPORT_NONE; 343 }; 344 } // namespace Bluetooth 345 } // namespace OHOS 346 347 #endif // BLUETOOTH_REMOTE_DEVICE_H 348