• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
16 /**
17  * @file
18  * @kit ConnectivityKit
19  */
20 
21 import 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 declare namespace access {
39   /**
40    * Enables 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   /**
51    * Enables Bluetooth on a device.
52    *
53    * @permission ohos.permission.ACCESS_BLUETOOTH
54    * @throws { BusinessError } 201 - Permission denied.
55    * @throws { BusinessError } 801 - Capability not supported.
56    * @throws { BusinessError } 2900001 - Service stopped.
57    * @throws { BusinessError } 2900099 - Operation failed.
58    * @syscap SystemCapability.Communication.Bluetooth.Core
59    * @atomicservice
60    * @since 12
61    */
62   function enableBluetooth(): void;
63 
64   /**
65    * Disables Bluetooth on a device.
66    *
67    * @permission ohos.permission.ACCESS_BLUETOOTH
68    * @throws { BusinessError } 201 - Permission denied.
69    * @throws { BusinessError } 801 - Capability not supported.
70    * @throws { BusinessError } 2900001 - Service stopped.
71    * @throws { BusinessError } 2900099 - Operation failed.
72    * @syscap SystemCapability.Communication.Bluetooth.Core
73    * @since 10
74    */
75   /**
76    * Disables Bluetooth on a device.
77    *
78    * @permission ohos.permission.ACCESS_BLUETOOTH
79    * @throws { BusinessError } 201 - Permission denied.
80    * @throws { BusinessError } 801 - Capability not supported.
81    * @throws { BusinessError } 2900001 - Service stopped.
82    * @throws { BusinessError } 2900099 - Operation failed.
83    * @syscap SystemCapability.Communication.Bluetooth.Core
84    * @atomicservice
85    * @since 12
86    */
87   function disableBluetooth(): void;
88 
89   /**
90    * Restrict Bluetooth BR/EDR ability on a device.
91    *
92    * @permission ohos.permission.ACCESS_BLUETOOTH and ohos.permission.MANAGE_BLUETOOTH
93    * @returns { Promise<void> } Promise that returns no value.
94    * @throws { BusinessError } 201 - Permission denied.
95    * @throws { BusinessError } 202 - Non-system applications are not allowed to use system APIs.
96    * @throws { BusinessError } 801 - Capability not supported.
97    * @throws { BusinessError } 2900001 - Service stopped.
98    * @throws { BusinessError } 2900099 - Operation failed.
99    * @syscap SystemCapability.Communication.Bluetooth.Core
100    * @systemapi
101    * @since 12
102    */
103   function restrictBluetooth(): Promise<void>;
104 
105   /**
106    * Obtains the Bluetooth status of a device.
107    *
108    * @permission ohos.permission.ACCESS_BLUETOOTH
109    * @returns { BluetoothState } Returns the Bluetooth status.
110    * @throws { BusinessError } 201 - Permission denied.
111    * @throws { BusinessError } 801 - Capability not supported.
112    * @throws { BusinessError } 2900001 - Service stopped.
113    * @throws { BusinessError } 2900099 - Operation failed.
114    * @syscap SystemCapability.Communication.Bluetooth.Core
115    * @since 10
116    */
117   /**
118    * Obtains the Bluetooth status of a device.
119    *
120    * @permission ohos.permission.ACCESS_BLUETOOTH
121    * @returns { BluetoothState } Returns the Bluetooth status.
122    * @throws { BusinessError } 201 - Permission denied.
123    * @throws { BusinessError } 801 - Capability not supported.
124    * @throws { BusinessError } 2900001 - Service stopped.
125    * @throws { BusinessError } 2900099 - Operation failed.
126    * @syscap SystemCapability.Communication.Bluetooth.Core
127    * @atomicservice
128    * @since 11
129    */
130   function getState(): BluetoothState;
131 
132   /**
133    * Restoring bluetooth settings.
134    *
135    * @permission ohos.permission.ACCESS_BLUETOOTH and ohos.permission.MANAGE_BLUETOOTH
136    * @param { AsyncCallback<void> } callback - Callback used to return the result.
137    * @throws { BusinessError } 201 - Permission denied.
138    * @throws { BusinessError } 202 - Non-system applications are not allowed to use system APIs.
139    * @throws { BusinessError } 401 - Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified.
140    * <br>2. Incorrect parameter types.
141    * @throws { BusinessError } 801 - Capability not supported.
142    * @throws { BusinessError } 2900001 - Service stopped.
143    * @throws { BusinessError } 2900099 - Operation failed.
144    * @syscap SystemCapability.Communication.Bluetooth.Core
145    * @systemapi
146    * @since 11
147    */
148   function factoryReset(callback: AsyncCallback<void>): void;
149 
150   /**
151    * Restoring bluetooth settings.
152    *
153    * @permission ohos.permission.ACCESS_BLUETOOTH and ohos.permission.MANAGE_BLUETOOTH
154    * @returns { Promise<void> } Promise that returns no value.
155    * @throws { BusinessError } 201 - Permission denied.
156    * @throws { BusinessError } 202 - Non-system applications are not allowed to use system APIs.
157    * @throws { BusinessError } 801 - Capability not supported.
158    * @throws { BusinessError } 2900001 - Service stopped.
159    * @throws { BusinessError } 2900099 - Operation failed.
160    * @syscap SystemCapability.Communication.Bluetooth.Core
161    * @systemapi
162    * @since 11
163    */
164   function factoryReset(): Promise<void>;
165 
166   /**
167    * Obtaining the MAC address of the local device.
168    *
169    * @permission ohos.permission.ACCESS_BLUETOOTH and ohos.permission.GET_BLUETOOTH_LOCAL_MAC
170    * @returns { string } The local MAC address. For example, "11:22:33:AA:BB:FF".
171    * @throws { BusinessError } 201 - Permission denied.
172    * @throws { BusinessError } 202 - Non-system applications are not allowed to use system APIs.
173    * @throws { BusinessError } 801 - Capability not supported.
174    * @throws { BusinessError } 2900001 - Service stopped.
175    * @throws { BusinessError } 2900099 - Operation failed.
176    * @syscap SystemCapability.Communication.Bluetooth.Core
177    * @systemapi
178    * @since 11
179    */
180   function getLocalAddress(): string;
181 
182   /**
183    * Subscribe the event reported when the Bluetooth state changes.
184    *
185    * @permission ohos.permission.ACCESS_BLUETOOTH
186    * @param { 'stateChange' } type - Type of the Bluetooth state changes event to listen for.
187    * @param { Callback<BluetoothState> } callback - Callback used to listen for the Bluetooth state event.
188    * @throws { BusinessError } 201 - Permission denied.
189    * @throws { BusinessError } 401 - Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified.
190    * <br>2. Incorrect parameter types. 3. Parameter verification failed.
191    * @throws { BusinessError } 801 - Capability not supported.
192    * @throws { BusinessError } 2900099 - Operation failed.
193    * @syscap SystemCapability.Communication.Bluetooth.Core
194    * @since 10
195    */
196   /**
197    * Subscribe the event reported when the Bluetooth state changes.
198    *
199    * @permission ohos.permission.ACCESS_BLUETOOTH
200    * @param { 'stateChange' } type - Type of the Bluetooth state changes event to listen for.
201    * @param { Callback<BluetoothState> } callback - Callback used to listen for the Bluetooth state event.
202    * @throws { BusinessError } 201 - Permission denied.
203    * @throws { BusinessError } 401 - Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified.
204    * <br>2. Incorrect parameter types. 3. Parameter verification failed.
205    * @throws { BusinessError } 801 - Capability not supported.
206    * @throws { BusinessError } 2900099 - Operation failed.
207    * @syscap SystemCapability.Communication.Bluetooth.Core
208    * @atomicservice
209    * @since 12
210    */
211   function on(type: 'stateChange', callback: Callback<BluetoothState>): void;
212 
213   /**
214    * Unsubscribe the event reported when the Bluetooth state changes.
215    *
216    * @permission ohos.permission.ACCESS_BLUETOOTH
217    * @param { 'stateChange' } type - Type of the Bluetooth state changes event to listen for.
218    * @param { Callback<BluetoothState> } callback - Callback used to listen for the Bluetooth state event.
219    * @throws { BusinessError } 201 - Permission denied.
220    * @throws { BusinessError } 401 - Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified.
221    * <br>2. Incorrect parameter types. 3. Parameter verification failed.
222    * @throws { BusinessError } 801 - Capability not supported.
223    * @throws { BusinessError } 2900099 - Operation failed.
224    * @syscap SystemCapability.Communication.Bluetooth.Core
225    * @since 10
226    */
227   /**
228    * Unsubscribe the event reported when the Bluetooth state changes.
229    *
230    * @permission ohos.permission.ACCESS_BLUETOOTH
231    * @param { 'stateChange' } type - Type of the Bluetooth state changes event to listen for.
232    * @param { Callback<BluetoothState> } callback - Callback used to listen for the Bluetooth state event.
233    * @throws { BusinessError } 201 - Permission denied.
234    * @throws { BusinessError } 401 - Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified.
235    * <br>2. Incorrect parameter types. 3. Parameter verification failed.
236    * @throws { BusinessError } 801 - Capability not supported.
237    * @throws { BusinessError } 2900099 - Operation failed.
238    * @syscap SystemCapability.Communication.Bluetooth.Core
239    * @atomicservice
240    * @since 12
241    */
242   function off(type: 'stateChange', callback?: Callback<BluetoothState>): void;
243 
244   /**
245    * The enum of bluetooth state.
246    *
247    * @enum { number }
248    * @syscap SystemCapability.Communication.Bluetooth.Core
249    * @since 10
250    */
251   /**
252    * The enum of bluetooth state.
253    *
254    * @enum { number }
255    * @syscap SystemCapability.Communication.Bluetooth.Core
256    * @atomicservice
257    * @since 11
258    */
259   export enum BluetoothState {
260     /**
261      * Indicates the local Bluetooth is off
262      *
263      * @syscap SystemCapability.Communication.Bluetooth.Core
264      * @since 10
265      */
266     /**
267      * Indicates the local Bluetooth is off
268      *
269      * @syscap SystemCapability.Communication.Bluetooth.Core
270      * @atomicservice
271      * @since 11
272      */
273     STATE_OFF = 0,
274     /**
275      * Indicates the local Bluetooth is turning on
276      *
277      * @syscap SystemCapability.Communication.Bluetooth.Core
278      * @since 10
279      */
280     /**
281      * Indicates the local Bluetooth is turning on
282      *
283      * @syscap SystemCapability.Communication.Bluetooth.Core
284      * @atomicservice
285      * @since 11
286      */
287     STATE_TURNING_ON = 1,
288     /**
289      * Indicates the local Bluetooth is on, and ready for use
290      *
291      * @syscap SystemCapability.Communication.Bluetooth.Core
292      * @since 10
293      */
294     /**
295      * Indicates the local Bluetooth is on, and ready for use
296      *
297      * @syscap SystemCapability.Communication.Bluetooth.Core
298      * @atomicservice
299      * @since 11
300      */
301     STATE_ON = 2,
302     /**
303      * Indicates the local Bluetooth is turning off
304      *
305      * @syscap SystemCapability.Communication.Bluetooth.Core
306      * @since 10
307      */
308     /**
309      * Indicates the local Bluetooth is turning off
310      *
311      * @syscap SystemCapability.Communication.Bluetooth.Core
312      * @atomicservice
313      * @since 11
314      */
315     STATE_TURNING_OFF = 3,
316     /**
317      * Indicates the local Bluetooth is turning LE mode on
318      *
319      * @syscap SystemCapability.Communication.Bluetooth.Core
320      * @since 10
321      */
322     /**
323      * Indicates the local Bluetooth is turning LE mode on
324      *
325      * @syscap SystemCapability.Communication.Bluetooth.Core
326      * @atomicservice
327      * @since 11
328      */
329     STATE_BLE_TURNING_ON = 4,
330     /**
331      * Indicates the local Bluetooth is in LE only mode
332      *
333      * @syscap SystemCapability.Communication.Bluetooth.Core
334      * @since 10
335      */
336     /**
337      * Indicates the local Bluetooth is in LE only mode
338      *
339      * @syscap SystemCapability.Communication.Bluetooth.Core
340      * @atomicservice
341      * @since 11
342      */
343     STATE_BLE_ON = 5,
344     /**
345      * Indicates the local Bluetooth is turning off LE only mode
346      *
347      * @syscap SystemCapability.Communication.Bluetooth.Core
348      * @since 10
349      */
350     /**
351      * Indicates the local Bluetooth is turning off LE only mode
352      *
353      * @syscap SystemCapability.Communication.Bluetooth.Core
354      * @atomicservice
355      * @since 11
356      */
357     STATE_BLE_TURNING_OFF = 6
358   }
359 }
360 
361 export default access;