1/* 2 * Copyright (C) 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 16import type { AsyncCallback, Callback } from './@ohos.base'; 17import type constant from './@ohos.bluetooth.constant'; 18 19/** 20 * Provides methods to operate or manage Bluetooth. 21 * 22 * @namespace connection 23 * @syscap SystemCapability.Communication.Bluetooth.Core 24 * @since 10 25 */ 26declare namespace connection { 27 /** 28 * Indicate the profile connection state. 29 * 30 * @syscap SystemCapability.Communication.Bluetooth.Core 31 * @since 10 32 */ 33 type ProfileConnectionState = constant.ProfileConnectionState; 34 35 /** 36 * Indicate the profile id. 37 * 38 * @syscap SystemCapability.Communication.Bluetooth.Core 39 * @since 10 40 */ 41 type ProfileId = constant.ProfileId; 42 43 /** 44 * Indicate the profile uuid. 45 * 46 * @syscap SystemCapability.Communication.Bluetooth.Core 47 * @systemapi 48 * @since 10 49 */ 50 type ProfileUuids = constant.ProfileUuids; 51 52 /** 53 * Indicate the major class of a bluetooth device. 54 * 55 * @syscap SystemCapability.Communication.Bluetooth.Core 56 * @since 10 57 */ 58 type MajorClass = constant.MajorClass; 59 60 /** 61 * Indicate the major minor class of a bluetooth device. 62 * 63 * @syscap SystemCapability.Communication.Bluetooth.Core 64 * @since 10 65 */ 66 type MajorMinorClass = constant.MajorMinorClass; 67 68 /** 69 * Get the profile connection state of the current device. 70 * 71 * @permission ohos.permission.ACCESS_BLUETOOTH 72 * @param { ProfileId } [profileId] - Indicate the profile id. This is an optional parameter. 73 * With profileId, returns the current connection state of this profile, {@link ProfileConnectionState}. 74 * Without profileId, if any profile is connected, {@link ProfileConnectionState#STATE_CONNECTED} is returned. 75 * Otherwise, {@link ProfileConnectionState#STATE_DISCONNECTED} is returned. 76 * @returns { ProfileConnectionState } Returns the connection state. 77 * @throws { BusinessError } 201 - Permission denied. 78 * @throws { BusinessError } 401 - Invalid parameter. 79 * @throws { BusinessError } 801 - Capability not supported. 80 * @throws { BusinessError } 2900001 - Service stopped. 81 * @throws { BusinessError } 2900003 - Bluetooth switch is off. 82 * @throws { BusinessError } 2900004 - Profile is not supported. 83 * @throws { BusinessError } 2900099 - Operation failed. 84 * @syscap SystemCapability.Communication.Bluetooth.Core 85 * @since 10 86 */ 87 function getProfileConnectionState(profileId?: ProfileId): ProfileConnectionState; 88 89 /** 90 * Starts pairing with a remote Bluetooth device. 91 * 92 * @permission ohos.permission.ACCESS_BLUETOOTH 93 * @param { string } deviceId - Indicates device ID. For example, "11:22:33:AA:BB:FF". 94 * @param { AsyncCallback<void> } callback - the callback of pairDevice. 95 * @throws { BusinessError } 201 - Permission denied. 96 * @throws { BusinessError } 401 - Invalid parameter. 97 * @throws { BusinessError } 801 - Capability not supported. 98 * @throws { BusinessError } 2900001 - Service stopped. 99 * @throws { BusinessError } 2900003 - Bluetooth switch is off. 100 * @throws { BusinessError } 2900099 - Operation failed. 101 * @syscap SystemCapability.Communication.Bluetooth.Core 102 * @since 10 103 */ 104 function pairDevice(deviceId: string, callback: AsyncCallback<void>): void; 105 106 /** 107 * Starts pairing with a remote Bluetooth device. 108 * 109 * @permission ohos.permission.ACCESS_BLUETOOTH 110 * @param { string } deviceId - Indicates device ID. For example, "11:22:33:AA:BB:FF". 111 * @returns { Promise<void> } Returns the promise object. 112 * @throws { BusinessError } 201 - Permission denied. 113 * @throws { BusinessError } 401 - Invalid parameter. 114 * @throws { BusinessError } 801 - Capability not supported. 115 * @throws { BusinessError } 2900001 - Service stopped. 116 * @throws { BusinessError } 2900003 - Bluetooth switch is off. 117 * @throws { BusinessError } 2900099 - Operation failed. 118 * @syscap SystemCapability.Communication.Bluetooth.Core 119 * @since 10 120 */ 121 function pairDevice(deviceId: string): Promise<void>; 122 123 /** 124 * Starts pairing with a credible remote Bluetooth device with transport. 125 * This interface does not trigger a dialog box and does not require user authorization. 126 * Only specific system application can use this function. 127 * 128 * @permission ohos.permission.ACCESS_BLUETOOTH and ohos.permission.MANAGE_BLUETOOTH 129 * @param { string } deviceId - Indicates device ID. For example, "11:22:33:AA:BB:FF". 130 * @param { BluetoothTransport } transport - the transport of the remote device to pair. 131 * @param { AsyncCallback<void> } callback - the callback of pairCredibleDevice. 132 * @throws { BusinessError } 201 - Permission denied. 133 * @throws { BusinessError } 202 - Non-system applications are not allowed to use system APIs. 134 * @throws { BusinessError } 401 - Invalid parameter. 135 * @throws { BusinessError } 801 - Capability not supported. 136 * @throws { BusinessError } 2900001 - Service stopped. 137 * @throws { BusinessError } 2900003 - Bluetooth switch is off. 138 * @throws { BusinessError } 2900099 - Operation failed. 139 * @syscap SystemCapability.Communication.Bluetooth.Core 140 * @systemapi 141 * @since 10 142 */ 143 function pairCredibleDevice(deviceId: string, transport: BluetoothTransport, callback: AsyncCallback<void>): void; 144 145 /** 146 * Starts pairing with a credible remote Bluetooth device with transport. 147 * This interface does not trigger a dialog box and does not require user authorization. 148 * Only specific system application can use this function. 149 * 150 * @permission ohos.permission.ACCESS_BLUETOOTH and ohos.permission.MANAGE_BLUETOOTH 151 * @param { string } deviceId - Indicates device ID. For example, "11:22:33:AA:BB:FF". 152 * @param { BluetoothTransport } transport - the transport of the remote device to pair. 153 * @returns { Promise<void> } Returns the promise object. 154 * @throws { BusinessError } 201 - Permission denied. 155 * @throws { BusinessError } 202 - Non-system applications are not allowed to use system APIs. 156 * @throws { BusinessError } 401 - Invalid parameter. 157 * @throws { BusinessError } 801 - Capability not supported. 158 * @throws { BusinessError } 2900001 - Service stopped. 159 * @throws { BusinessError } 2900003 - Bluetooth switch is off. 160 * @throws { BusinessError } 2900099 - Operation failed. 161 * @syscap SystemCapability.Communication.Bluetooth.Core 162 * @systemapi 163 * @since 10 164 */ 165 function pairCredibleDevice(deviceId: string, transport: BluetoothTransport): Promise<void>; 166 167 /** 168 * Remove a paired remote device. 169 * 170 * @permission ohos.permission.ACCESS_BLUETOOTH 171 * @param { string } deviceId - Indicates device ID. For example, "11:22:33:AA:BB:FF". 172 * @param { AsyncCallback<void> } callback - the callback of cancelPairedDevice. 173 * @throws { BusinessError } 201 - Permission denied. 174 * @throws { BusinessError } 202 - Non-system applications are not allowed to use system APIs. 175 * @throws { BusinessError } 401 - Invalid parameter. 176 * @throws { BusinessError } 801 - Capability not supported. 177 * @throws { BusinessError } 2900001 - Service stopped. 178 * @throws { BusinessError } 2900003 - Bluetooth switch is off. 179 * @throws { BusinessError } 2900099 - Operation failed. 180 * @syscap SystemCapability.Communication.Bluetooth.Core 181 * @systemapi 182 * @since 10 183 */ 184 function cancelPairedDevice(deviceId: string, callback: AsyncCallback<void>): void; 185 186 /** 187 * Remove a paired remote device. 188 * 189 * @permission ohos.permission.ACCESS_BLUETOOTH 190 * @param { string } deviceId - Indicates device ID. For example, "11:22:33:AA:BB:FF". 191 * @returns { Promise<void> } Returns the promise object. 192 * @throws { BusinessError } 201 - Permission denied. 193 * @throws { BusinessError } 202 - Non-system applications are not allowed to use system APIs. 194 * @throws { BusinessError } 401 - Invalid parameter. 195 * @throws { BusinessError } 801 - Capability not supported. 196 * @throws { BusinessError } 2900001 - Service stopped. 197 * @throws { BusinessError } 2900003 - Bluetooth switch is off. 198 * @throws { BusinessError } 2900099 - Operation failed. 199 * @syscap SystemCapability.Communication.Bluetooth.Core 200 * @systemapi 201 * @since 10 202 */ 203 function cancelPairedDevice(deviceId: string): Promise<void>; 204 205 /** 206 * Remove a pairing remote device. 207 * 208 * @permission ohos.permission.ACCESS_BLUETOOTH 209 * @param { string } deviceId - Indicates device ID. For example, "11:22:33:AA:BB:FF". 210 * @param { AsyncCallback<void> } callback - the callback of cancelPairingDevice. 211 * @throws { BusinessError } 201 - Permission denied. 212 * @throws { BusinessError } 202 - Non-system applications are not allowed to use system APIs. 213 * @throws { BusinessError } 401 - Invalid parameter. 214 * @throws { BusinessError } 801 - Capability not supported. 215 * @throws { BusinessError } 2900001 - Service stopped. 216 * @throws { BusinessError } 2900003 - Bluetooth switch is off. 217 * @throws { BusinessError } 2900099 - Operation failed. 218 * @syscap SystemCapability.Communication.Bluetooth.Core 219 * @systemapi 220 * @since 10 221 */ 222 function cancelPairingDevice(deviceId: string, callback: AsyncCallback<void>): void; 223 224 /** 225 * Remove a pairing remote device. 226 * 227 * @permission ohos.permission.ACCESS_BLUETOOTH 228 * @param { string } deviceId - Indicates device ID. For example, "11:22:33:AA:BB:FF". 229 * @returns { Promise<void> } Returns the promise object. 230 * @throws { BusinessError } 201 - Permission denied. 231 * @throws { BusinessError } 202 - Non-system applications are not allowed to use system APIs. 232 * @throws { BusinessError } 401 - Invalid parameter. 233 * @throws { BusinessError } 801 - Capability not supported. 234 * @throws { BusinessError } 2900001 - Service stopped. 235 * @throws { BusinessError } 2900003 - Bluetooth switch is off. 236 * @throws { BusinessError } 2900099 - Operation failed. 237 * @syscap SystemCapability.Communication.Bluetooth.Core 238 * @systemapi 239 * @since 10 240 */ 241 function cancelPairingDevice(deviceId: string): Promise<void>; 242 243 /** 244 * Obtains the name of a peer Bluetooth device. 245 * 246 * @permission ohos.permission.ACCESS_BLUETOOTH 247 * @param { string } deviceId - Indicates device ID. For example, "11:22:33:AA:BB:FF". 248 * @returns { string } Returns the device name in character string format. 249 * @throws { BusinessError } 201 - Permission denied. 250 * @throws { BusinessError } 401 - Invalid parameter. 251 * @throws { BusinessError } 801 - Capability not supported. 252 * @throws { BusinessError } 2900001 - Service stopped. 253 * @throws { BusinessError } 2900003 - Bluetooth switch is off. 254 * @throws { BusinessError } 2900099 - Operation failed. 255 * @syscap SystemCapability.Communication.Bluetooth.Core 256 * @since 10 257 */ 258 function getRemoteDeviceName(deviceId: string): string; 259 260 /** 261 * Obtains the class of a peer Bluetooth device. 262 * 263 * @permission ohos.permission.ACCESS_BLUETOOTH 264 * @param { string } deviceId - Indicates device ID. For example, "11:22:33:AA:BB:FF". 265 * @returns { DeviceClass } The class of the remote device. 266 * @throws { BusinessError } 201 - Permission denied. 267 * @throws { BusinessError } 401 - Invalid parameter. 268 * @throws { BusinessError } 801 - Capability not supported. 269 * @throws { BusinessError } 2900001 - Service stopped. 270 * @throws { BusinessError } 2900003 - Bluetooth switch is off. 271 * @throws { BusinessError } 2900099 - Operation failed. 272 * @syscap SystemCapability.Communication.Bluetooth.Core 273 * @since 10 274 */ 275 function getRemoteDeviceClass(deviceId: string): DeviceClass; 276 277 /** 278 * Obtains the Bluetooth local name of a device. 279 * 280 * @permission ohos.permission.ACCESS_BLUETOOTH 281 * @returns { string } Returns the name the device. 282 * @throws { BusinessError } 201 - Permission denied. 283 * @throws { BusinessError } 801 - Capability not supported. 284 * @throws { BusinessError } 2900001 - Service stopped. 285 * @throws { BusinessError } 2900099 - Operation failed. 286 * @syscap SystemCapability.Communication.Bluetooth.Core 287 * @since 10 288 */ 289 function getLocalName(): string; 290 291 /** 292 * Obtains the list of Bluetooth devices that have been paired with the current device. 293 * 294 * @permission ohos.permission.ACCESS_BLUETOOTH 295 * @returns { Array<string> } Returns a list of paired Bluetooth devices's address. 296 * @throws { BusinessError } 201 - Permission denied. 297 * @throws { BusinessError } 801 - Capability not supported. 298 * @throws { BusinessError } 2900001 - Service stopped. 299 * @throws { BusinessError } 2900003 - Bluetooth switch is off. 300 * @throws { BusinessError } 2900099 - Operation failed. 301 * @syscap SystemCapability.Communication.Bluetooth.Core 302 * @since 10 303 */ 304 function getPairedDevices(): Array<string>; 305 306 /** 307 * Sets the confirmation of pairing with a certain device. 308 * 309 * @permission ohos.permission.ACCESS_BLUETOOTH and ohos.permission.MANAGE_BLUETOOTH 310 * @param { string } deviceId - Indicates device ID. For example, "11:22:33:AA:BB:FF". 311 * @param { boolean } accept - Indicates whether to accept the pairing request, {@code true} indicates accept or {@code false} otherwise. 312 * @throws { BusinessError } 201 - Permission denied. 313 * @throws { BusinessError } 401 - Invalid parameter. 314 * @throws { BusinessError } 801 - Capability not supported. 315 * @throws { BusinessError } 2900001 - Service stopped. 316 * @throws { BusinessError } 2900003 - Bluetooth switch is off. 317 * @throws { BusinessError } 2900099 - Operation failed. 318 * @syscap SystemCapability.Communication.Bluetooth.Core 319 * @since 10 320 */ 321 function setDevicePairingConfirmation(deviceId: string, accept: boolean): void; 322 323 /** 324 * Set the pin during pairing when the pin type is PIN_TYPE_ENTER_PIN_CODE. 325 * 326 * @permission ohos.permission.ACCESS_BLUETOOTH 327 * @param { string } deviceId - Indicates device ID. For example, "11:22:33:AA:BB:FF". 328 * @param { string } code - The pin code entered by the user. 329 * @param { AsyncCallback<void> } callback - the callback of setDevicePinCode. 330 * @throws { BusinessError } 201 - Permission denied. 331 * @throws { BusinessError } 401 - Invalid parameter. 332 * @throws { BusinessError } 801 - Capability not supported. 333 * @throws { BusinessError } 2900001 - Service stopped. 334 * @throws { BusinessError } 2900003 - Bluetooth switch is off. 335 * @throws { BusinessError } 2900099 - Operation failed. 336 * @syscap SystemCapability.Communication.Bluetooth.Core 337 * @since 10 338 */ 339 function setDevicePinCode(deviceId: string, code: string, callback: AsyncCallback<void>): void; 340 341 /** 342 * Set the pin during pairing when the pin type is PIN_TYPE_ENTER_PIN_CODE. 343 * 344 * @permission ohos.permission.ACCESS_BLUETOOTH 345 * @param { string } deviceId - Indicates device ID. For example, "11:22:33:AA:BB:FF". 346 * @param { string } code - The pin code entered by the user. 347 * @returns { Promise<void> } Returns the promise object. 348 * @throws { BusinessError } 201 - Permission denied. 349 * @throws { BusinessError } 401 - Invalid parameter. 350 * @throws { BusinessError } 801 - Capability not supported. 351 * @throws { BusinessError } 2900001 - Service stopped. 352 * @throws { BusinessError } 2900003 - Bluetooth switch is off. 353 * @throws { BusinessError } 2900099 - Operation failed. 354 * @syscap SystemCapability.Communication.Bluetooth.Core 355 * @since 10 356 */ 357 function setDevicePinCode(deviceId: string, code: string): Promise<void>; 358 359 /** 360 * Sets the Bluetooth friendly name of a device. 361 * 362 * @permission ohos.permission.ACCESS_BLUETOOTH 363 * @param { string } name - Indicates a valid Bluetooth name. 364 * @throws { BusinessError } 201 - Permission denied. 365 * @throws { BusinessError } 401 - Invalid parameter. 366 * @throws { BusinessError } 801 - Capability not supported. 367 * @throws { BusinessError } 2900001 - Service stopped. 368 * @throws { BusinessError } 2900003 - Bluetooth switch is off. 369 * @throws { BusinessError } 2900099 - Operation failed. 370 * @syscap SystemCapability.Communication.Bluetooth.Core 371 * @since 10 372 */ 373 function setLocalName(name: string): void; 374 375 /** 376 * Sets the Bluetooth scan mode for a device. 377 * 378 * @permission ohos.permission.ACCESS_BLUETOOTH 379 * @param { ScanMode } mode - Indicates the Bluetooth scan mode to set. 380 * @param { number } duration - Indicates the duration in seconds, in which the host is discoverable. 381 * @throws { BusinessError } 201 - Permission denied. 382 * @throws { BusinessError } 401 - Invalid parameter. 383 * @throws { BusinessError } 801 - Capability not supported. 384 * @throws { BusinessError } 2900001 - Service stopped. 385 * @throws { BusinessError } 2900003 - Bluetooth switch is off. 386 * @throws { BusinessError } 2900099 - Operation failed. 387 * @syscap SystemCapability.Communication.Bluetooth.Core 388 * @since 10 389 */ 390 function setBluetoothScanMode(mode: ScanMode, duration: number): void; 391 392 /** 393 * Obtains the Bluetooth scanning mode of a device. 394 * 395 * @permission ohos.permission.ACCESS_BLUETOOTH 396 * @returns { ScanMode } Returns the Bluetooth scanning mode. 397 * @throws { BusinessError } 201 - Permission denied. 398 * @throws { BusinessError } 801 - Capability not supported. 399 * @throws { BusinessError } 2900001 - Service stopped. 400 * @throws { BusinessError } 2900003 - Bluetooth switch is off. 401 * @throws { BusinessError } 2900099 - Operation failed. 402 * @syscap SystemCapability.Communication.Bluetooth.Core 403 * @since 10 404 */ 405 function getBluetoothScanMode(): ScanMode; 406 407 /** 408 * Starts scanning Bluetooth devices. 409 * 410 * @permission ohos.permission.ACCESS_BLUETOOTH 411 * @throws { BusinessError } 201 - Permission denied. 412 * @throws { BusinessError } 801 - Capability not supported. 413 * @throws { BusinessError } 2900001 - Service stopped. 414 * @throws { BusinessError } 2900003 - Bluetooth switch is off. 415 * @throws { BusinessError } 2900099 - Operation failed. 416 * @syscap SystemCapability.Communication.Bluetooth.Core 417 * @since 10 418 */ 419 function startBluetoothDiscovery(): void; 420 421 /** 422 * Stops Bluetooth device scanning. 423 * 424 * @permission ohos.permission.ACCESS_BLUETOOTH 425 * @throws { BusinessError } 201 - Permission denied. 426 * @throws { BusinessError } 801 - Capability not supported. 427 * @throws { BusinessError } 2900001 - Service stopped. 428 * @throws { BusinessError } 2900003 - Bluetooth switch is off. 429 * @throws { BusinessError } 2900099 - Operation failed. 430 * @syscap SystemCapability.Communication.Bluetooth.Core 431 * @since 10 432 */ 433 function stopBluetoothDiscovery(): void; 434 435 /** 436 * Obtains the profile UUIDs supported by the local device. 437 * 438 * @permission ohos.permission.ACCESS_BLUETOOTH 439 * @param { AsyncCallback<Array<ProfileUuids>> } callback - the callback of getLocalProfileUuids. 440 * @throws { BusinessError } 201 - Permission denied. 441 * @throws { BusinessError } 202 - Non-system applications are not allowed to use system APIs. 442 * @throws { BusinessError } 401 - Invalid parameter. 443 * @throws { BusinessError } 801 - Capability not supported. 444 * @throws { BusinessError } 2900001 - Service stopped. 445 * @throws { BusinessError } 2900003 - Bluetooth switch is off. 446 * @throws { BusinessError } 2900099 - Operation failed. 447 * @syscap SystemCapability.Communication.Bluetooth.Core 448 * @systemapi 449 * @since 10 450 */ 451 function getLocalProfileUuids(callback: AsyncCallback<Array<ProfileUuids>>): void; 452 453 /** 454 * Obtains the profile UUIDs supported by the local device. 455 * 456 * @permission ohos.permission.ACCESS_BLUETOOTH 457 * @returns { Promise<Array<ProfileUuids>> } Returns the promise object. 458 * @throws { BusinessError } 201 - Permission denied. 459 * @throws { BusinessError } 202 - Non-system applications are not allowed to use system APIs. 460 * @throws { BusinessError } 401 - Invalid parameter. 461 * @throws { BusinessError } 801 - Capability not supported. 462 * @throws { BusinessError } 2900001 - Service stopped. 463 * @throws { BusinessError } 2900003 - Bluetooth switch is off. 464 * @throws { BusinessError } 2900099 - Operation failed. 465 * @syscap SystemCapability.Communication.Bluetooth.Core 466 * @systemapi 467 * @since 10 468 */ 469 function getLocalProfileUuids(): Promise<Array<ProfileUuids>>; 470 471 /** 472 * Obtains the profile UUIDs supported by the remote device. 473 * 474 * @permission ohos.permission.ACCESS_BLUETOOTH 475 * @param { string } deviceId - Indicates device ID. For example, "11:22:33:AA:BB:FF". 476 * @param { AsyncCallback<Array<ProfileUuids>> } callback - the callback of getRemoteProfileUuids. 477 * @throws { BusinessError } 201 - Permission denied. 478 * @throws { BusinessError } 202 - Non-system applications are not allowed to use system APIs. 479 * @throws { BusinessError } 401 - Invalid parameter. 480 * @throws { BusinessError } 801 - Capability not supported. 481 * @throws { BusinessError } 2900001 - Service stopped. 482 * @throws { BusinessError } 2900003 - Bluetooth switch is off. 483 * @throws { BusinessError } 2900099 - Operation failed. 484 * @syscap SystemCapability.Communication.Bluetooth.Core 485 * @systemapi 486 * @since 10 487 */ 488 function getRemoteProfileUuids(deviceId: string, callback: AsyncCallback<Array<ProfileUuids>>): void; 489 490 /** 491 * Obtains the profile UUIDs supported by the remote device. 492 * 493 * @permission ohos.permission.ACCESS_BLUETOOTH 494 * @param { string } deviceId - Indicates device ID. For example, "11:22:33:AA:BB:FF". 495 * @returns { Promise<Array<ProfileUuids>> } Returns the promise object. 496 * @throws { BusinessError } 201 - Permission denied. 497 * @throws { BusinessError } 202 - Non-system applications are not allowed to use system APIs. 498 * @throws { BusinessError } 401 - Invalid parameter. 499 * @throws { BusinessError } 801 - Capability not supported. 500 * @throws { BusinessError } 2900001 - Service stopped. 501 * @throws { BusinessError } 2900003 - Bluetooth switch is off. 502 * @throws { BusinessError } 2900099 - Operation failed. 503 * @syscap SystemCapability.Communication.Bluetooth.Core 504 * @systemapi 505 * @since 10 506 */ 507 function getRemoteProfileUuids(deviceId: string): Promise<Array<ProfileUuids>>; 508 509 /** 510 * Subscribe the event reported when a remote Bluetooth device is discovered. 511 * 512 * @permission ohos.permission.ACCESS_BLUETOOTH 513 * @param { 'bluetoothDeviceFind' } type - Type of the discovering event to listen for. 514 * @param { Callback<Array<string>> } callback - Callback used to listen for the discovering event. 515 * @throws { BusinessError } 201 - Permission denied. 516 * @throws { BusinessError } 401 - Invalid parameter. 517 * @throws { BusinessError } 801 - Capability not supported. 518 * @throws { BusinessError } 2900099 - Operation failed. 519 * @syscap SystemCapability.Communication.Bluetooth.Core 520 * @since 10 521 */ 522 function on(type: 'bluetoothDeviceFind', callback: Callback<Array<string>>): void; 523 524 /** 525 * Unsubscribe the event reported when a remote Bluetooth device is discovered. 526 * 527 * @permission ohos.permission.ACCESS_BLUETOOTH 528 * @param { 'bluetoothDeviceFind' } type - Type of the discovering event to listen for. 529 * @param { Callback<Array<string>> } callback - Callback used to listen for the discovering event. 530 * @throws { BusinessError } 201 - Permission denied. 531 * @throws { BusinessError } 801 - Capability not supported. 532 * @throws { BusinessError } 2900099 - Operation failed. 533 * @syscap SystemCapability.Communication.Bluetooth.Core 534 * @since 10 535 */ 536 function off(type: 'bluetoothDeviceFind', callback?: Callback<Array<string>>): void; 537 538 /** 539 * Subscribe the event reported when a remote Bluetooth device is bonded. 540 * 541 * @permission ohos.permission.ACCESS_BLUETOOTH 542 * @param { 'bondStateChange' } type - Type of the bond state event to listen for. 543 * @param { Callback<BondStateParam> } callback - Callback used to listen for the bond state event. 544 * @throws { BusinessError } 201 - Permission denied. 545 * @throws { BusinessError } 401 - Invalid parameter. 546 * @throws { BusinessError } 801 - Capability not supported. 547 * @throws { BusinessError } 2900099 - Operation failed. 548 * @syscap SystemCapability.Communication.Bluetooth.Core 549 * @since 10 550 */ 551 function on(type: 'bondStateChange', callback: Callback<BondStateParam>): void; 552 553 /** 554 * Unsubscribe the event reported when a remote Bluetooth device is bonded. 555 * 556 * @permission ohos.permission.ACCESS_BLUETOOTH 557 * @param { 'bondStateChange' } type - Type of the bond state event to listen for. 558 * @param { Callback<BondStateParam> } callback - Callback used to listen for the bond state event. 559 * @throws { BusinessError } 201 - Permission denied. 560 * @throws { BusinessError } 401 - Invalid parameter. 561 * @throws { BusinessError } 801 - Capability not supported. 562 * @throws { BusinessError } 2900099 - Operation failed. 563 * @syscap SystemCapability.Communication.Bluetooth.Core 564 * @since 10 565 */ 566 function off(type: 'bondStateChange', callback?: Callback<BondStateParam>): void; 567 568 /** 569 * Subscribe the event of a pairing request from a remote Bluetooth device. 570 * 571 * @permission ohos.permission.ACCESS_BLUETOOTH 572 * @param { 'pinRequired' } type - Type of the pairing request event to listen for. 573 * @param { Callback<PinRequiredParam> } callback - Callback used to listen for the pairing request event. 574 * @throws { BusinessError } 201 - Permission denied. 575 * @throws { BusinessError } 401 - Invalid parameter. 576 * @throws { BusinessError } 801 - Capability not supported. 577 * @throws { BusinessError } 2900099 - Operation failed. 578 * @syscap SystemCapability.Communication.Bluetooth.Core 579 * @since 10 580 */ 581 function on(type: 'pinRequired', callback: Callback<PinRequiredParam>): void; 582 583 /** 584 * Unsubscribe the event of a pairing request from a remote Bluetooth device. 585 * 586 * @permission ohos.permission.ACCESS_BLUETOOTH 587 * @param { 'pinRequired' } type - Type of the pairing request event to listen for. 588 * @param { Callback<PinRequiredParam> } callback - Callback used to listen for the pairing request event. 589 * @throws { BusinessError } 201 - Permission denied. 590 * @throws { BusinessError } 401 - Invalid parameter. 591 * @throws { BusinessError } 801 - Capability not supported. 592 * @throws { BusinessError } 2900099 - Operation failed. 593 * @syscap SystemCapability.Communication.Bluetooth.Core 594 * @since 10 595 */ 596 function off(type: 'pinRequired', callback?: Callback<PinRequiredParam>): void; 597 598 /** 599 * Describes the class of a bluetooth device. 600 * 601 * @typedef BondStateParam 602 * @syscap SystemCapability.Communication.Bluetooth.Core 603 * @since 10 604 */ 605 interface BondStateParam { 606 /** 607 * Address of a Bluetooth device. 608 * 609 * @syscap SystemCapability.Communication.Bluetooth.Core 610 * @since 10 611 */ 612 deviceId: string; 613 /** 614 * Profile connection state of the device. 615 * 616 * @syscap SystemCapability.Communication.Bluetooth.Core 617 * @since 10 618 */ 619 state: BondState; 620 } 621 622 /** 623 * Describes the bond key param. 624 * 625 * @typedef PinRequiredParam 626 * @syscap SystemCapability.Communication.Bluetooth.Core 627 * @since 10 628 */ 629 interface PinRequiredParam { 630 /** 631 * ID of the device to pair. 632 * 633 * @syscap SystemCapability.Communication.Bluetooth.Core 634 * @since 10 635 */ 636 deviceId: string; 637 /** 638 * Key for the device pairing. 639 * 640 * @syscap SystemCapability.Communication.Bluetooth.Core 641 * @since 10 642 */ 643 pinCode: string; 644 /** 645 * Indicates the pairing type to a peer device. 646 * 647 * @syscap SystemCapability.Communication.Bluetooth.Core 648 * @systemapi 649 * @since 10 650 */ 651 pinType: PinType; 652 } 653 654 /** 655 * Describes the class of a bluetooth device. 656 * 657 * @typedef DeviceClass 658 * @syscap SystemCapability.Communication.Bluetooth.Core 659 * @since 10 660 */ 661 interface DeviceClass { 662 /** 663 * Major classes of Bluetooth devices. 664 * 665 * @syscap SystemCapability.Communication.Bluetooth.Core 666 * @since 10 667 */ 668 majorClass: MajorClass; 669 /** 670 * Major and minor classes of Bluetooth devices. 671 * 672 * @syscap SystemCapability.Communication.Bluetooth.Core 673 * @since 10 674 */ 675 majorMinorClass: MajorMinorClass; 676 /** 677 * Class of the device. 678 * 679 * @syscap SystemCapability.Communication.Bluetooth.Core 680 * @since 10 681 */ 682 classOfDevice: number; 683 } 684 685 /** 686 * Enum for the transport of a remote device 687 * 688 * @enum { number } 689 * @syscap SystemCapability.Communication.Bluetooth.Core 690 * @since 10 691 */ 692 enum BluetoothTransport { 693 /** 694 * The value of bluetooth transport BR/EDR. 695 * 696 * @syscap SystemCapability.Communication.Bluetooth.Core 697 * @since 10 698 */ 699 TRANSPORT_BR_EDR = 0, 700 /** 701 * The value of bluetooth transport LE. 702 * 703 * @syscap SystemCapability.Communication.Bluetooth.Core 704 * @since 10 705 */ 706 TRANSPORT_LE = 1 707 } 708 709 /** 710 * The enum of BR scan mode. 711 * 712 * @enum { number } 713 * @syscap SystemCapability.Communication.Bluetooth.Core 714 * @since 10 715 */ 716 enum ScanMode { 717 /** 718 * Indicates the scan mode is none 719 * 720 * @syscap SystemCapability.Communication.Bluetooth.Core 721 * @since 10 722 */ 723 SCAN_MODE_NONE = 0, 724 /** 725 * Indicates the scan mode is connectable 726 * 727 * @syscap SystemCapability.Communication.Bluetooth.Core 728 * @since 10 729 */ 730 SCAN_MODE_CONNECTABLE = 1, 731 /** 732 * Indicates the scan mode is general discoverable 733 * 734 * @syscap SystemCapability.Communication.Bluetooth.Core 735 * @since 10 736 */ 737 SCAN_MODE_GENERAL_DISCOVERABLE = 2, 738 /** 739 * Indicates the scan mode is limited discoverable 740 * 741 * @syscap SystemCapability.Communication.Bluetooth.Core 742 * @since 10 743 */ 744 SCAN_MODE_LIMITED_DISCOVERABLE = 3, 745 /** 746 * Indicates the scan mode is connectable and general discoverable 747 * 748 * @syscap SystemCapability.Communication.Bluetooth.Core 749 * @since 10 750 */ 751 SCAN_MODE_CONNECTABLE_GENERAL_DISCOVERABLE = 4, 752 /** 753 * Indicates the scan mode is connectable and limited discoverable 754 * 755 * @syscap SystemCapability.Communication.Bluetooth.Core 756 * @since 10 757 */ 758 SCAN_MODE_CONNECTABLE_LIMITED_DISCOVERABLE = 5 759 } 760 761 /** 762 * The enum of bond state. 763 * 764 * @enum { number } 765 * @syscap SystemCapability.Communication.Bluetooth.Core 766 * @since 10 767 */ 768 enum BondState { 769 /** 770 * Indicate the bond state is invalid 771 * 772 * @syscap SystemCapability.Communication.Bluetooth.Core 773 * @since 10 774 */ 775 BOND_STATE_INVALID = 0, 776 /** 777 * Indicate the bond state is bonding 778 * 779 * @syscap SystemCapability.Communication.Bluetooth.Core 780 * @since 10 781 */ 782 BOND_STATE_BONDING = 1, 783 /** 784 * Indicate the bond state is bonded 785 * 786 * @syscap SystemCapability.Communication.Bluetooth.Core 787 * @since 10 788 */ 789 BOND_STATE_BONDED = 2 790 } 791 792 /** 793 * Enum for the type of pairing to a remote device 794 * 795 * @enum { number } 796 * @syscap SystemCapability.Communication.Bluetooth.Core 797 * @systemapi 798 * @since 10 799 */ 800 enum PinType { 801 /** 802 * The user needs to enter the pin code displayed on the peer device. 803 * 804 * @syscap SystemCapability.Communication.Bluetooth.Core 805 * @systemapi 806 * @since 10 807 */ 808 PIN_TYPE_ENTER_PIN_CODE = 0, 809 /** 810 * The user needs to enter the passkey displayed on the peer device. 811 * 812 * @syscap SystemCapability.Communication.Bluetooth.Core 813 * @systemapi 814 * @since 10 815 */ 816 PIN_TYPE_ENTER_PASSKEY = 1, 817 /** 818 * The user needs to confirm the passkey displayed on the local device. 819 * 820 * @syscap SystemCapability.Communication.Bluetooth.Core 821 * @systemapi 822 * @since 10 823 */ 824 PIN_TYPE_CONFIRM_PASSKEY = 2, 825 /** 826 * The user needs to accept or deny the pairing request. 827 * 828 * @syscap SystemCapability.Communication.Bluetooth.Core 829 * @systemapi 830 * @since 10 831 */ 832 PIN_TYPE_NO_PASSKEY_CONSENT = 3, 833 /** 834 * The user needs to enter the passkey displayed on the local device on the peer device. 835 * 836 * @syscap SystemCapability.Communication.Bluetooth.Core 837 * @systemapi 838 * @since 10 839 */ 840 PIN_TYPE_NOTIFY_PASSKEY = 4, 841 /** 842 * The user needs to enter the pin code displayed on the peer device, used for bluetooth 2.0. 843 * 844 * @syscap SystemCapability.Communication.Bluetooth.Core 845 * @systemapi 846 * @since 10 847 */ 848 PIN_TYPE_DISPLAY_PIN_CODE = 5, 849 /** 850 * The user needs to accept or deny the OOB pairing request. 851 * 852 * @syscap SystemCapability.Communication.Bluetooth.Core 853 * @systemapi 854 * @since 10 855 */ 856 PIN_TYPE_OOB_CONSENT = 6, 857 /** 858 * The user needs to enter the 16-digit pin code displayed on the peer device. 859 * 860 * @syscap SystemCapability.Communication.Bluetooth.Core 861 * @systemapi 862 * @since 10 863 */ 864 PIN_TYPE_PIN_16_DIGITS = 7 865 } 866} 867 868export default connection;