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 { Callback } from './@ohos.base'; 17 18/** 19 * Provides methods for enabling/disabling bluetooth or monitoring bluetooth state. 20 * 21 * @namespace access 22 * @syscap SystemCapability.Communication.Bluetooth.Core 23 * @since 10 24 */ 25declare namespace access { 26 /** 27 * Enables Bluetooth on a device. 28 * 29 * @permission ohos.permission.ACCESS_BLUETOOTH 30 * @throws { BusinessError } 201 - Permission denied. 31 * @throws { BusinessError } 801 - Capability not supported. 32 * @throws { BusinessError } 2900001 - Service stopped. 33 * @throws { BusinessError } 2900099 - Operation failed. 34 * @syscap SystemCapability.Communication.Bluetooth.Core 35 * @since 10 36 */ 37 function enableBluetooth(): void; 38 39 /** 40 * Disables Bluetooth on a device. 41 * 42 * @permission ohos.permission.ACCESS_BLUETOOTH 43 * @throws { BusinessError } 201 - Permission denied. 44 * @throws { BusinessError } 801 - Capability not supported. 45 * @throws { BusinessError } 2900001 - Service stopped. 46 * @throws { BusinessError } 2900099 - Operation failed. 47 * @syscap SystemCapability.Communication.Bluetooth.Core 48 * @since 10 49 */ 50 function disableBluetooth(): void; 51 52 /** 53 * Obtains the Bluetooth status of a device. 54 * 55 * @permission ohos.permission.ACCESS_BLUETOOTH 56 * @returns { BluetoothState } Returns the Bluetooth status. 57 * @throws { BusinessError } 201 - Permission denied. 58 * @throws { BusinessError } 801 - Capability not supported. 59 * @throws { BusinessError } 2900001 - Service stopped. 60 * @throws { BusinessError } 2900099 - Operation failed. 61 * @syscap SystemCapability.Communication.Bluetooth.Core 62 * @since 10 63 */ 64 function getState(): BluetoothState; 65 66 /** 67 * Subscribe the event reported when the Bluetooth state changes. 68 * 69 * @permission ohos.permission.ACCESS_BLUETOOTH 70 * @param { 'stateChange' } type - Type of the Bluetooth state changes event to listen for. 71 * @param { Callback<BluetoothState> } callback - Callback used to listen for the Bluetooth state event. 72 * @throws { BusinessError } 201 - Permission denied. 73 * @throws { BusinessError } 401 - Invalid parameter. 74 * @throws { BusinessError } 801 - Capability not supported. 75 * @throws { BusinessError } 2900099 - Operation failed. 76 * @syscap SystemCapability.Communication.Bluetooth.Core 77 * @since 10 78 */ 79 function on(type: 'stateChange', callback: Callback<BluetoothState>): void; 80 81 /** 82 * Unsubscribe the event reported when the Bluetooth state changes. 83 * 84 * @permission ohos.permission.ACCESS_BLUETOOTH 85 * @param { 'stateChange' } type - Type of the Bluetooth state changes event to listen for. 86 * @param { Callback<BluetoothState> } callback - Callback used to listen for the Bluetooth state event. 87 * @throws { BusinessError } 201 - Permission denied. 88 * @throws { BusinessError } 401 - Invalid parameter. 89 * @throws { BusinessError } 801 - Capability not supported. 90 * @throws { BusinessError } 2900099 - Operation failed. 91 * @syscap SystemCapability.Communication.Bluetooth.Core 92 * @since 10 93 */ 94 function off(type: 'stateChange', callback?: Callback<BluetoothState>): void; 95 96 /** 97 * The enum of bluetooth state. 98 * 99 * @enum { number } 100 * @syscap SystemCapability.Communication.Bluetooth.Core 101 * @since 10 102 */ 103 export enum BluetoothState { 104 /** 105 * Indicates the local Bluetooth is off 106 * 107 * @syscap SystemCapability.Communication.Bluetooth.Core 108 * @since 10 109 */ 110 STATE_OFF = 0, 111 /** 112 * Indicates the local Bluetooth is turning on 113 * 114 * @syscap SystemCapability.Communication.Bluetooth.Core 115 * @since 10 116 */ 117 STATE_TURNING_ON = 1, 118 /** 119 * Indicates the local Bluetooth is on, and ready for use 120 * 121 * @syscap SystemCapability.Communication.Bluetooth.Core 122 * @since 10 123 */ 124 STATE_ON = 2, 125 /** 126 * Indicates the local Bluetooth is turning off 127 * 128 * @syscap SystemCapability.Communication.Bluetooth.Core 129 * @since 10 130 */ 131 STATE_TURNING_OFF = 3, 132 /** 133 * Indicates the local Bluetooth is turning LE mode on 134 * 135 * @syscap SystemCapability.Communication.Bluetooth.Core 136 * @since 10 137 */ 138 STATE_BLE_TURNING_ON = 4, 139 /** 140 * Indicates the local Bluetooth is in LE only mode 141 * 142 * @syscap SystemCapability.Communication.Bluetooth.Core 143 * @since 10 144 */ 145 STATE_BLE_ON = 5, 146 /** 147 * Indicates the local Bluetooth is turning off LE only mode 148 * 149 * @syscap SystemCapability.Communication.Bluetooth.Core 150 * @since 10 151 */ 152 STATE_BLE_TURNING_OFF = 6 153 } 154} 155 156export default access;