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 /** 17 * @addtogroup Bluetooth 18 * @{ 19 * 20 * @brief Defines adapter classic, including observer and common functions. 21 * 22 * @since 6 23 */ 24 25 /** 26 * @file interface_adapter_classic.h 27 * 28 * @brief Adapter classic interface. 29 * 30 * @since 6 31 */ 32 33 #ifndef INTERFACE_ADAPTER_CLASSIC_H 34 #define INTERFACE_ADAPTER_CLASSIC_H 35 36 #include "interface_adapter.h" 37 38 namespace OHOS { 39 namespace bluetooth { 40 /** 41 * @brief Represents adapter classic observer. 42 * 43 * @since 6 44 */ 45 class IAdapterClassicObserver { 46 public: 47 /** 48 * @brief A destructor used to delete the <b>IAdapterClassicObserver</b> instance. 49 * 50 * @since 6 51 */ 52 virtual ~IAdapterClassicObserver() = default; 53 54 /** 55 * @brief Discovery state changed observer. 56 * 57 * @param status Device discovery status. 58 * @since 6 59 */ 60 virtual void OnDiscoveryStateChanged(int status) = 0; 61 62 /** 63 * @brief Discovery result observer. 64 * 65 * @param device Remote device. 66 * @since 6 67 */ 68 virtual void OnDiscoveryResult(const RawAddress &device) = 0; 69 70 /** 71 * @brief Pair requester observer. 72 * 73 * @param device Remote device. 74 * @since 6 75 */ 76 virtual void OnPairRequested(const BTTransport transport, const RawAddress &device) = 0; 77 78 /** 79 * @brief Pair confirmed observer. 80 * 81 * @param device Remote device. 82 * @param reqType Pair type. 83 * @param number Paired passkey. 84 * @since 6 85 */ 86 virtual void OnPairConfirmed(const BTTransport transport, const RawAddress &device, int reqType, int number) = 0; 87 88 /** 89 * @brief Scan mode changed observer. 90 * 91 * @param mode Device scan mode. 92 * @since 6 93 */ 94 virtual void OnScanModeChanged(int mode) = 0; 95 96 /** 97 * @brief Device name changed observer. 98 * 99 * @param deviceName Device name. 100 * @since 6 101 */ 102 virtual void OnDeviceNameChanged(const std::string &deviceName) = 0; 103 104 /** 105 * @brief Device address changed observer. 106 * 107 * @param address Device address. 108 * @since 6 109 */ 110 virtual void OnDeviceAddrChanged(const std::string &address) = 0; 111 }; 112 113 /** 114 * @brief Represents remote device observer. 115 * 116 * @since 6 117 */ 118 class IClassicRemoteDeviceObserver { 119 public: 120 /** 121 * @brief A destructor used to delete the <b>IClassicRemoteDeviceObserver</b> instance. 122 * 123 * @since 6 124 */ 125 virtual ~IClassicRemoteDeviceObserver() = default; 126 127 virtual void OnAclStateChanged(const RawAddress &device, int state, unsigned int reason) = 0; 128 129 /** 130 * @brief Pair status changed observer. 131 * 132 * @param device Remote device. 133 * @param status Remote device pair status. 134 * @since 6 135 */ 136 virtual void OnPairStatusChanged(const BTTransport transport, const RawAddress &device, int status) = 0; 137 138 /** 139 * @brief Remote uuid changed observer. 140 * 141 * @param device Remote device. 142 * @param uuids Remote device uuids. 143 * @since 6 144 */ 145 virtual void OnRemoteUuidChanged(const RawAddress &device, const std::vector<Uuid> &uuids) = 0; 146 147 /** 148 * @brief Remote name changed observer. 149 * 150 * @param device Remote device. 151 * @param deviceName Remote device name. 152 * @since 6 153 */ 154 virtual void OnRemoteNameChanged(const RawAddress &device, const std::string &deviceName) = 0; 155 156 /** 157 * @brief Remote alias changed observer. 158 * 159 * @param device Remote device. 160 * @param alias Remote device alias. 161 * @since 6 162 */ 163 virtual void OnRemoteAliasChanged(const RawAddress &device, const std::string &alias) = 0; 164 165 /** 166 * @brief Remote cod changed observer. 167 * 168 * @param device Remote device. 169 * @param cod Remote device cod. 170 * @since 6 171 */ 172 virtual void OnRemoteCodChanged(const RawAddress &device, int cod) = 0; 173 174 /** 175 * @brief Remote battery level changed observer. 176 * 177 * @param device Remote device. 178 * @param batteryLevel Remote device battery Level. 179 * @since 6 180 */ 181 virtual void OnRemoteBatteryLevelChanged(const RawAddress &device, int batteryLevel) = 0; 182 }; 183 184 /** 185 * @brief Represents classic adapter interface. 186 * 187 * @since 6 188 */ 189 class IAdapterClassic : public IAdapter { 190 public: 191 /** 192 * @brief A destructor used to delete the <b>IAdapterClassic</b> instance. 193 * 194 * @since 6 195 */ 196 virtual ~IAdapterClassic() = default; 197 198 /** 199 * @brief Get remote device class. 200 * 201 * @param device Remote device. 202 * @return Returns remote device class. 203 * @since 6 204 */ 205 virtual int GetDeviceClass(const RawAddress &device) const = 0; 206 207 /** 208 * @brief Get remote device alias name. 209 * 210 * @param device Remote device 211 * @return Returns remote device alias name. 212 * @since 6 213 */ 214 virtual std::string GetAliasName(const RawAddress &device) const = 0; 215 216 /** 217 * @brief Set remote device alias name. 218 * 219 * @param device Remote device which set alias name. 220 * @param name Alias name. 221 * @return Returns <b>true</b> if the operation is successful; 222 * returns <b>false</b> if the operation fails. 223 * @since 6 224 */ 225 virtual bool SetAliasName(const RawAddress &device, const std::string &name) const = 0; 226 227 /** 228 * @brief Get remote device battery level. 229 * 230 * @param device Remote device 231 * @return Returns remote device battery level. 232 * @since 6 233 */ 234 virtual int GetDeviceBatteryLevel(const RawAddress &device) const = 0; 235 236 /** 237 * @brief Set remote device battery level. 238 * 239 * @param device Remote device 240 * @param batteryLevel battery level 241 * @since 6 242 */ 243 virtual void SetDeviceBatteryLevel(const RawAddress &device, int batteryLevel) const = 0; 244 245 /** 246 * @brief Register remote device observer. 247 * 248 * @param observer Class IClassicRemoteDeviceObserver pointer to register observer. 249 * @return Returns <b>true</b> if the operation is successful; 250 * returns <b>false</b> if the operation fails. 251 * @since 6 252 */ 253 virtual bool RegisterRemoteDeviceObserver(IClassicRemoteDeviceObserver &observer) const = 0; 254 255 /** 256 * @brief Deregister remote device observer. 257 * 258 * @return Returns <b>true</b> if the operation is successful; 259 * returns <b>false</b> if the operation fails. 260 * @since 6 261 */ 262 virtual bool DeregisterRemoteDeviceObserver(IClassicRemoteDeviceObserver &observer) const = 0; 263 264 /** 265 * @brief Set device scan mode. 266 * 267 * @param mode Scan mode. 268 * @param duration Scan time. 269 * @return Returns <b>true</b> if the operation is successful; 270 * returns <b>false</b> if the operation fails. 271 * @since 6 272 */ 273 virtual bool SetBtScanMode(int mode, int duration) = 0; 274 275 /** 276 * @brief Get device scan mode. 277 * 278 * @return Returns bluetooth scan mode. 279 * @since 6 280 */ 281 virtual int GetBtScanMode() const = 0; 282 283 /** 284 * @brief Get local device class. 285 * 286 * @return Returns local device class. 287 * @since 6 288 */ 289 virtual int GetLocalDeviceClass() const = 0; 290 291 /** 292 * @brief Set local device class. 293 * 294 * @param deviceClass Device class. 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 virtual bool SetLocalDeviceClass(int deviceClass) const = 0; 300 301 /** 302 * @brief Get device address. 303 * 304 * @return Returns <b>true</b> if the operation is successful; 305 * returns <b>false</b> if the operation fails. 306 * @since 6 307 */ 308 virtual bool StartBtDiscovery() = 0; 309 310 /** 311 * @brief Cancel device discovery. 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 virtual bool CancelBtDiscovery() = 0; 318 319 /** 320 * @brief Check if device is discovering. 321 * 322 * @return Returns <b>true</b> if device is discovering; 323 * returns <b>false</b> if device is not discovering. 324 * @since 6 325 */ 326 virtual bool IsBtDiscovering() const = 0; 327 328 /** 329 * @brief Get device discovery end time. 330 * 331 * @return Returns device discovery end time. 332 * @since 6 333 */ 334 virtual long GetBtDiscoveryEndMillis() const = 0; 335 336 /** 337 * @brief Set device pair pin. 338 * 339 * @param device Remote device address. 340 * @param pinCode Pin code. 341 * @return Returns <b>true</b> if the operation is successful; 342 * returns <b>false</b> if the operation fails. 343 * @since 6 344 */ 345 virtual bool SetDevicePin(const RawAddress &device, const std::string &pinCode) const = 0; 346 347 /** 348 * @brief Register classic adapter observer. 349 * 350 * @param observer Class IAdapterClassicObserver pointer to register observer. 351 * @return Returns <b>true</b> if the operation is successful; 352 * returns <b>false</b> if the operation fails. 353 * @since 6 354 */ 355 virtual bool RegisterClassicAdapterObserver(IAdapterClassicObserver &observer) const = 0; 356 357 /** 358 * @brief Deregister classic adapter observer. 359 * 360 * @return Returns <b>true</b> if the operation is successful; 361 * returns <b>false</b> if the operation fails. 362 * @since 6 363 */ 364 virtual bool DeregisterClassicAdapterObserver(IAdapterClassicObserver &observer) const = 0; 365 366 /** 367 * @brief Check if device is support hfp. 368 * 369 * @param device Remote device which set alias name 370 * @return Returns <b>true</b> if device is support hfp profile; 371 * returns <b>false</b> if device is not support hfp profile. 372 * @since 6 373 */ 374 virtual bool IsHfpCodSupported(const RawAddress &device) = 0; 375 }; 376 } // namespace bluetooth 377 } // namespace OHOS 378 379 #endif // INTERFACE_ADAPTER_CLASSIC_H