1/* 2 * Copyright (C) 2023-2024 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 * @file 18 * @kit ConnectivityKit 19 */ 20 21import type { AsyncCallback, Callback } from './@ohos.base'; 22 23/** 24 * Provides methods for enabling/disabling bluetooth or monitoring bluetooth state. 25 * 26 * @namespace access 27 * @syscap SystemCapability.Communication.Bluetooth.Core 28 * @since 10 29 */ 30/** 31 * Provides methods for enabling/disabling bluetooth or monitoring bluetooth state. 32 * 33 * @namespace access 34 * @syscap SystemCapability.Communication.Bluetooth.Core 35 * @atomicservice 36 * @since 11 37 */ 38/** 39 * Provides methods for enabling/disabling bluetooth or monitoring bluetooth state. 40 * 41 * @namespace access 42 * @syscap SystemCapability.Communication.Bluetooth.Core 43 * @crossplatform 44 * @atomicservice 45 * @since 13 46 */ 47declare namespace access { 48 /** 49 * Enables Bluetooth on a device. 50 * 51 * @permission ohos.permission.ACCESS_BLUETOOTH 52 * @throws { BusinessError } 201 - Permission denied. 53 * @throws { BusinessError } 801 - Capability not supported. 54 * @throws { BusinessError } 2900001 - Service stopped. 55 * @throws { BusinessError } 2900099 - Operation failed. 56 * @syscap SystemCapability.Communication.Bluetooth.Core 57 * @since 10 58 */ 59 /** 60 * Enables Bluetooth on a device. 61 * 62 * @permission ohos.permission.ACCESS_BLUETOOTH 63 * @throws { BusinessError } 201 - Permission denied. 64 * @throws { BusinessError } 801 - Capability not supported. 65 * @throws { BusinessError } 2900001 - Service stopped. 66 * @throws { BusinessError } 2900099 - Operation failed. 67 * @syscap SystemCapability.Communication.Bluetooth.Core 68 * @atomicservice 69 * @since 12 70 */ 71 /** 72 * Enables Bluetooth on a device. 73 * 74 * @permission ohos.permission.ACCESS_BLUETOOTH 75 * @throws { BusinessError } 201 - Permission denied. 76 * @throws { BusinessError } 801 - Capability not supported. 77 * @throws { BusinessError } 2900001 - Service stopped. 78 * @throws { BusinessError } 2900099 - Operation failed. 79 * @syscap SystemCapability.Communication.Bluetooth.Core 80 * @crossplatform 81 * @atomicservice 82 * @since 13 83 */ 84 function enableBluetooth(): void; 85 86 /** 87 * Disables Bluetooth on a device. 88 * 89 * @permission ohos.permission.ACCESS_BLUETOOTH 90 * @throws { BusinessError } 201 - Permission denied. 91 * @throws { BusinessError } 801 - Capability not supported. 92 * @throws { BusinessError } 2900001 - Service stopped. 93 * @throws { BusinessError } 2900099 - Operation failed. 94 * @syscap SystemCapability.Communication.Bluetooth.Core 95 * @since 10 96 */ 97 /** 98 * Disables Bluetooth on a device. 99 * 100 * @permission ohos.permission.ACCESS_BLUETOOTH 101 * @throws { BusinessError } 201 - Permission denied. 102 * @throws { BusinessError } 801 - Capability not supported. 103 * @throws { BusinessError } 2900001 - Service stopped. 104 * @throws { BusinessError } 2900099 - Operation failed. 105 * @syscap SystemCapability.Communication.Bluetooth.Core 106 * @atomicservice 107 * @since 12 108 */ 109 /** 110 * Disables Bluetooth on a device. 111 * 112 * @permission ohos.permission.ACCESS_BLUETOOTH 113 * @throws { BusinessError } 201 - Permission denied. 114 * @throws { BusinessError } 801 - Capability not supported. 115 * @throws { BusinessError } 2900001 - Service stopped. 116 * @throws { BusinessError } 2900099 - Operation failed. 117 * @syscap SystemCapability.Communication.Bluetooth.Core 118 * @crossplatform 119 * @atomicservice 120 * @since 13 121 */ 122 function disableBluetooth(): void; 123 124 /** 125 * Restrict Bluetooth BR/EDR ability on a device. 126 * 127 * @permission ohos.permission.ACCESS_BLUETOOTH and ohos.permission.MANAGE_BLUETOOTH 128 * @returns { Promise<void> } Promise that returns no value. 129 * @throws { BusinessError } 201 - Permission denied. 130 * @throws { BusinessError } 202 - Non-system applications are not allowed to use system APIs. 131 * @throws { BusinessError } 801 - Capability not supported. 132 * @throws { BusinessError } 2900001 - Service stopped. 133 * @throws { BusinessError } 2900099 - Operation failed. 134 * @syscap SystemCapability.Communication.Bluetooth.Core 135 * @systemapi 136 * @since 12 137 */ 138 function restrictBluetooth(): Promise<void>; 139 140 /** 141 * Obtains the Bluetooth status of a device. 142 * 143 * @permission ohos.permission.ACCESS_BLUETOOTH 144 * @returns { BluetoothState } Returns the Bluetooth status. 145 * @throws { BusinessError } 201 - Permission denied. 146 * @throws { BusinessError } 801 - Capability not supported. 147 * @throws { BusinessError } 2900001 - Service stopped. 148 * @throws { BusinessError } 2900099 - Operation failed. 149 * @syscap SystemCapability.Communication.Bluetooth.Core 150 * @since 10 151 */ 152 /** 153 * Obtains the Bluetooth status of a device. 154 * 155 * @permission ohos.permission.ACCESS_BLUETOOTH 156 * @returns { BluetoothState } Returns the Bluetooth status. 157 * @throws { BusinessError } 201 - Permission denied. 158 * @throws { BusinessError } 801 - Capability not supported. 159 * @throws { BusinessError } 2900001 - Service stopped. 160 * @throws { BusinessError } 2900099 - Operation failed. 161 * @syscap SystemCapability.Communication.Bluetooth.Core 162 * @atomicservice 163 * @since 11 164 */ 165 /** 166 * Obtains the Bluetooth status of a device. 167 * 168 * @returns { BluetoothState } Returns the Bluetooth status. 169 * @throws { BusinessError } 801 - Capability not supported. 170 * @throws { BusinessError } 2900001 - Service stopped. 171 * @throws { BusinessError } 2900099 - Operation failed. 172 * @syscap SystemCapability.Communication.Bluetooth.Core 173 * @crossplatform 174 * @atomicservice 175 * @since 13 176 */ 177 function getState(): BluetoothState; 178 179 /** 180 * Restoring bluetooth settings. 181 * 182 * @permission ohos.permission.ACCESS_BLUETOOTH and ohos.permission.MANAGE_BLUETOOTH 183 * @param { AsyncCallback<void> } callback - Callback used to return the result. 184 * @throws { BusinessError } 201 - Permission denied. 185 * @throws { BusinessError } 202 - Non-system applications are not allowed to use system APIs. 186 * @throws { BusinessError } 401 - Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 187 * <br>2. Incorrect parameter types. 188 * @throws { BusinessError } 801 - Capability not supported. 189 * @throws { BusinessError } 2900001 - Service stopped. 190 * @throws { BusinessError } 2900099 - Operation failed. 191 * @syscap SystemCapability.Communication.Bluetooth.Core 192 * @systemapi 193 * @since 11 194 */ 195 function factoryReset(callback: AsyncCallback<void>): void; 196 197 /** 198 * Restoring bluetooth settings. 199 * 200 * @permission ohos.permission.ACCESS_BLUETOOTH and ohos.permission.MANAGE_BLUETOOTH 201 * @returns { Promise<void> } Promise that returns no value. 202 * @throws { BusinessError } 201 - Permission denied. 203 * @throws { BusinessError } 202 - Non-system applications are not allowed to use system APIs. 204 * @throws { BusinessError } 801 - Capability not supported. 205 * @throws { BusinessError } 2900001 - Service stopped. 206 * @throws { BusinessError } 2900099 - Operation failed. 207 * @syscap SystemCapability.Communication.Bluetooth.Core 208 * @systemapi 209 * @since 11 210 */ 211 function factoryReset(): Promise<void>; 212 213 /** 214 * Obtaining the MAC address of the local device. 215 * 216 * @permission ohos.permission.ACCESS_BLUETOOTH and ohos.permission.GET_BLUETOOTH_LOCAL_MAC 217 * @returns { string } The local MAC address. For example, "11:22:33:AA:BB:FF". 218 * @throws { BusinessError } 201 - Permission denied. 219 * @throws { BusinessError } 202 - Non-system applications are not allowed to use system APIs. 220 * @throws { BusinessError } 801 - Capability not supported. 221 * @throws { BusinessError } 2900001 - Service stopped. 222 * @throws { BusinessError } 2900099 - Operation failed. 223 * @syscap SystemCapability.Communication.Bluetooth.Core 224 * @systemapi 225 * @since 11 226 */ 227 function getLocalAddress(): string; 228 229 /** 230 * Subscribe the event reported when the Bluetooth state changes. 231 * 232 * @permission ohos.permission.ACCESS_BLUETOOTH 233 * @param { 'stateChange' } type - Type of the Bluetooth state changes event to listen for. 234 * @param { Callback<BluetoothState> } callback - Callback used to listen for the Bluetooth state event. 235 * @throws { BusinessError } 201 - Permission denied. 236 * @throws { BusinessError } 401 - Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 237 * <br>2. Incorrect parameter types. 3. Parameter verification failed. 238 * @throws { BusinessError } 801 - Capability not supported. 239 * @throws { BusinessError } 2900099 - Operation failed. 240 * @syscap SystemCapability.Communication.Bluetooth.Core 241 * @since 10 242 */ 243 /** 244 * Subscribe the event reported when the Bluetooth state changes. 245 * 246 * @permission ohos.permission.ACCESS_BLUETOOTH 247 * @param { 'stateChange' } type - Type of the Bluetooth state changes event to listen for. 248 * @param { Callback<BluetoothState> } callback - Callback used to listen for the Bluetooth state event. 249 * @throws { BusinessError } 201 - Permission denied. 250 * @throws { BusinessError } 401 - Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 251 * <br>2. Incorrect parameter types. 3. Parameter verification failed. 252 * @throws { BusinessError } 801 - Capability not supported. 253 * @throws { BusinessError } 2900099 - Operation failed. 254 * @syscap SystemCapability.Communication.Bluetooth.Core 255 * @atomicservice 256 * @since 12 257 */ 258 /** 259 * Subscribe the event reported when the Bluetooth state changes. 260 * 261 * @permission ohos.permission.ACCESS_BLUETOOTH 262 * @param { 'stateChange' } type - Type of the Bluetooth state changes event to listen for. 263 * @param { Callback<BluetoothState> } callback - Callback used to listen for the Bluetooth state event. 264 * @throws { BusinessError } 201 - Permission denied. 265 * @throws { BusinessError } 401 - Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 266 * <br>2. Incorrect parameter types. 3. Parameter verification failed. 267 * @throws { BusinessError } 801 - Capability not supported. 268 * @throws { BusinessError } 2900099 - Operation failed. 269 * @syscap SystemCapability.Communication.Bluetooth.Core 270 * @crossplatform 271 * @atomicservice 272 * @since 13 273 */ 274 function on(type: 'stateChange', callback: Callback<BluetoothState>): void; 275 276 /** 277 * Unsubscribe the event reported when the Bluetooth state changes. 278 * 279 * @permission ohos.permission.ACCESS_BLUETOOTH 280 * @param { 'stateChange' } type - Type of the Bluetooth state changes event to listen for. 281 * @param { Callback<BluetoothState> } callback - Callback used to listen for the Bluetooth state event. 282 * @throws { BusinessError } 201 - Permission denied. 283 * @throws { BusinessError } 401 - Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 284 * <br>2. Incorrect parameter types. 3. Parameter verification failed. 285 * @throws { BusinessError } 801 - Capability not supported. 286 * @throws { BusinessError } 2900099 - Operation failed. 287 * @syscap SystemCapability.Communication.Bluetooth.Core 288 * @since 10 289 */ 290 /** 291 * Unsubscribe the event reported when the Bluetooth state changes. 292 * 293 * @permission ohos.permission.ACCESS_BLUETOOTH 294 * @param { 'stateChange' } type - Type of the Bluetooth state changes event to listen for. 295 * @param { Callback<BluetoothState> } callback - Callback used to listen for the Bluetooth state event. 296 * @throws { BusinessError } 201 - Permission denied. 297 * @throws { BusinessError } 401 - Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 298 * <br>2. Incorrect parameter types. 3. Parameter verification failed. 299 * @throws { BusinessError } 801 - Capability not supported. 300 * @throws { BusinessError } 2900099 - Operation failed. 301 * @syscap SystemCapability.Communication.Bluetooth.Core 302 * @atomicservice 303 * @since 12 304 */ 305 /** 306 * Unsubscribe the event reported when the Bluetooth state changes. 307 * 308 * @permission ohos.permission.ACCESS_BLUETOOTH 309 * @param { 'stateChange' } type - Type of the Bluetooth state changes event to listen for. 310 * @param { Callback<BluetoothState> } callback - Callback used to listen for the Bluetooth state event. 311 * @throws { BusinessError } 201 - Permission denied. 312 * @throws { BusinessError } 401 - Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 313 * <br>2. Incorrect parameter types. 3. Parameter verification failed. 314 * @throws { BusinessError } 801 - Capability not supported. 315 * @throws { BusinessError } 2900099 - Operation failed. 316 * @syscap SystemCapability.Communication.Bluetooth.Core 317 * @crossplatform 318 * @atomicservice 319 * @since 13 320 */ 321 function off(type: 'stateChange', callback?: Callback<BluetoothState>): void; 322 323 /** 324 * The enum of bluetooth state. 325 * 326 * @enum { number } 327 * @syscap SystemCapability.Communication.Bluetooth.Core 328 * @since 10 329 */ 330 /** 331 * The enum of bluetooth state. 332 * 333 * @enum { number } 334 * @syscap SystemCapability.Communication.Bluetooth.Core 335 * @atomicservice 336 * @since 11 337 */ 338 /** 339 * The enum of bluetooth state. 340 * 341 * @enum { number } 342 * @syscap SystemCapability.Communication.Bluetooth.Core 343 * @crossplatform 344 * @atomicservice 345 * @since 13 346 */ 347 export enum BluetoothState { 348 /** 349 * Indicates the local Bluetooth is off 350 * 351 * @syscap SystemCapability.Communication.Bluetooth.Core 352 * @since 10 353 */ 354 /** 355 * Indicates the local Bluetooth is off 356 * 357 * @syscap SystemCapability.Communication.Bluetooth.Core 358 * @atomicservice 359 * @since 11 360 */ 361 /** 362 * Indicates the local Bluetooth is off 363 * 364 * @syscap SystemCapability.Communication.Bluetooth.Core 365 * @crossplatform 366 * @atomicservice 367 * @since 13 368 */ 369 STATE_OFF = 0, 370 /** 371 * Indicates the local Bluetooth is turning on 372 * 373 * @syscap SystemCapability.Communication.Bluetooth.Core 374 * @since 10 375 */ 376 /** 377 * Indicates the local Bluetooth is turning on 378 * 379 * @syscap SystemCapability.Communication.Bluetooth.Core 380 * @atomicservice 381 * @since 11 382 */ 383 /** 384 * Indicates the local Bluetooth is turning on 385 * 386 * @syscap SystemCapability.Communication.Bluetooth.Core 387 * @crossplatform 388 * @atomicservice 389 * @since 13 390 */ 391 STATE_TURNING_ON = 1, 392 /** 393 * Indicates the local Bluetooth is on, and ready for use 394 * 395 * @syscap SystemCapability.Communication.Bluetooth.Core 396 * @since 10 397 */ 398 /** 399 * Indicates the local Bluetooth is on, and ready for use 400 * 401 * @syscap SystemCapability.Communication.Bluetooth.Core 402 * @atomicservice 403 * @since 11 404 */ 405 /** 406 * Indicates the local Bluetooth is on, and ready for use 407 * 408 * @syscap SystemCapability.Communication.Bluetooth.Core 409 * @crossplatform 410 * @atomicservice 411 * @since 13 412 */ 413 STATE_ON = 2, 414 /** 415 * Indicates the local Bluetooth is turning off 416 * 417 * @syscap SystemCapability.Communication.Bluetooth.Core 418 * @since 10 419 */ 420 /** 421 * Indicates the local Bluetooth is turning off 422 * 423 * @syscap SystemCapability.Communication.Bluetooth.Core 424 * @atomicservice 425 * @since 11 426 */ 427 /** 428 * Indicates the local Bluetooth is turning off 429 * 430 * @syscap SystemCapability.Communication.Bluetooth.Core 431 * @crossplatform 432 * @atomicservice 433 * @since 13 434 */ 435 STATE_TURNING_OFF = 3, 436 /** 437 * Indicates the local Bluetooth is turning LE mode on 438 * 439 * @syscap SystemCapability.Communication.Bluetooth.Core 440 * @since 10 441 */ 442 /** 443 * Indicates the local Bluetooth is turning LE mode on 444 * 445 * @syscap SystemCapability.Communication.Bluetooth.Core 446 * @atomicservice 447 * @since 11 448 */ 449 STATE_BLE_TURNING_ON = 4, 450 /** 451 * Indicates the local Bluetooth is in LE only mode 452 * 453 * @syscap SystemCapability.Communication.Bluetooth.Core 454 * @since 10 455 */ 456 /** 457 * Indicates the local Bluetooth is in LE only mode 458 * 459 * @syscap SystemCapability.Communication.Bluetooth.Core 460 * @atomicservice 461 * @since 11 462 */ 463 STATE_BLE_ON = 5, 464 /** 465 * Indicates the local Bluetooth is turning off LE only mode 466 * 467 * @syscap SystemCapability.Communication.Bluetooth.Core 468 * @since 10 469 */ 470 /** 471 * Indicates the local Bluetooth is turning off LE only mode 472 * 473 * @syscap SystemCapability.Communication.Bluetooth.Core 474 * @atomicservice 475 * @since 11 476 */ 477 STATE_BLE_TURNING_OFF = 6 478 } 479} 480 481export default access;