• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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';
22import type constant from './@ohos.bluetooth.constant';
23
24/**
25 * Provides basic profile methods.
26 *
27 * @namespace baseProfile
28 * @syscap SystemCapability.Communication.Bluetooth.Core
29 * @since 10
30 */
31/**
32 * Provides basic profile methods.
33 *
34 * @namespace baseProfile
35 * @syscap SystemCapability.Communication.Bluetooth.Core
36 * @crossplatform
37 * @since arkts {'1.1':'13','1.2':'20'}
38 * @arkts 1.1&1.2
39 */
40declare namespace baseProfile {
41  /**
42   * Indicate the profile connection state.
43   *
44   * @typedef { constant.ProfileConnectionState } ProfileConnectionState
45   * @syscap SystemCapability.Communication.Bluetooth.Core
46   * @since 10
47   */
48  /**
49   * Indicate the profile connection state.
50   *
51   * @typedef { constant.ProfileConnectionState } ProfileConnectionState
52   * @syscap SystemCapability.Communication.Bluetooth.Core
53   * @crossplatform
54   * @since arkts {'1.1':'13','1.2':'20'}
55   * @arkts 1.1&1.2
56   */
57  type ProfileConnectionState = constant.ProfileConnectionState;
58
59  /**
60   * Enum for connection strategy of the profile
61   *
62   * @enum { number }
63   * @syscap SystemCapability.Communication.Bluetooth.Core
64   * @systemapi
65   * @since 10
66   */
67  export enum ConnectionStrategy {
68    /**
69     * The value of connection strategy unsupported.
70     *
71     * @syscap SystemCapability.Communication.Bluetooth.Core
72     * @systemapi
73     * @since 10
74     */
75    CONNECTION_STRATEGY_UNSUPPORTED = 0,
76    /**
77     * The value of connection strategy allowed.
78     *
79     * @syscap SystemCapability.Communication.Bluetooth.Core
80     * @systemapi
81     * @since 10
82     */
83    CONNECTION_STRATEGY_ALLOWED = 1,
84    /**
85     * The value of connection strategy forbidden.
86     *
87     * @syscap SystemCapability.Communication.Bluetooth.Core
88     * @systemapi
89     * @since 10
90     */
91    CONNECTION_STRATEGY_FORBIDDEN = 2
92  }
93
94  /**
95   * Enum for cause of disconnect.
96   *
97   * @enum { number }
98   * @syscap SystemCapability.Communication.Bluetooth.Core
99   * @since 12
100   */
101  /**
102   * Enum for cause of disconnect.
103   *
104   * @enum { number }
105   * @syscap SystemCapability.Communication.Bluetooth.Core
106   * @crossplatform
107   * @since 13
108   */
109  enum DisconnectCause {
110    /**
111     * User disconnect device.
112     *
113     * @syscap SystemCapability.Communication.Bluetooth.Core
114     * @since 12
115     */
116    /**
117     * User disconnect device.
118     *
119     * @syscap SystemCapability.Communication.Bluetooth.Core
120     * @crossplatform
121     * @since 13
122     */
123    USER_DISCONNECT = 0,
124    /**
125     * The connection needs to be initiated from the keyboard side.
126     *
127     * @syscap SystemCapability.Communication.Bluetooth.Core
128     * @since 12
129     */
130    CONNECT_FROM_KEYBOARD = 1,
131    /**
132     * The connection needs to be initiated from the mouse side.
133     *
134     * @syscap SystemCapability.Communication.Bluetooth.Core
135     * @since 12
136     */
137    CONNECT_FROM_MOUSE = 2,
138    /**
139     * The connection needs to be initiated from the car side.
140     *
141     * @syscap SystemCapability.Communication.Bluetooth.Core
142     * @since 12
143     */
144    CONNECT_FROM_CAR = 3,
145    /**
146     * Too many devices are currently connected.
147     *
148     * @syscap SystemCapability.Communication.Bluetooth.Core
149     * @since 12
150     */
151    TOO_MANY_CONNECTED_DEVICES = 4,
152    /**
153     * Connection failed due to an internal error.
154     *
155     * @syscap SystemCapability.Communication.Bluetooth.Core
156     * @since 12
157     */
158    CONNECT_FAIL_INTERNAL = 5
159  }
160
161  /**
162   * Profile state change parameters.
163   *
164   * @typedef StateChangeParam
165   * @syscap SystemCapability.Communication.Bluetooth.Core
166   * @since 10
167   */
168  /**
169   * Profile state change parameters.
170   *
171   * @typedef StateChangeParam
172   * @syscap SystemCapability.Communication.Bluetooth.Core
173   * @crossplatform
174   * @since arkts {'1.1':'13','1.2':'20'}
175   * @arkts 1.1&1.2
176   */
177  export interface StateChangeParam {
178    /**
179     * The address of device
180     *
181     * @type { string }
182     * @syscap SystemCapability.Communication.Bluetooth.Core
183     * @since 10
184     */
185    /**
186     * The address of device
187     *
188     * @type { string }
189     * @syscap SystemCapability.Communication.Bluetooth.Core
190     * @crossplatform
191     * @since arkts {'1.1':'13','1.2':'20'}
192     * @arkts 1.1&1.2
193     */
194    deviceId: string;
195
196    /**
197     * Profile state value
198     *
199     * @type { ProfileConnectionState }
200     * @syscap SystemCapability.Communication.Bluetooth.Core
201     * @since 10
202     */
203    /**
204     * Profile state value
205     *
206     * @type { ProfileConnectionState }
207     * @syscap SystemCapability.Communication.Bluetooth.Core
208     * @crossplatform
209     * @since arkts {'1.1':'13','1.2':'20'}
210     * @arkts 1.1&1.2
211     */
212    state: ProfileConnectionState;
213
214    /**
215     * Cause of disconnect
216     *
217     * @type { DisconnectCause }
218     * @syscap SystemCapability.Communication.Bluetooth.Core
219     * @since 12
220     */
221    /**
222     * Cause of disconnect
223     *
224     * @type { DisconnectCause }
225     * @syscap SystemCapability.Communication.Bluetooth.Core
226     * @crossplatform
227     * @since 13
228     */
229    cause: DisconnectCause;
230  }
231
232  /**
233   * Base interface of profile.
234   *
235   * @typedef BaseProfile
236   * @syscap SystemCapability.Communication.Bluetooth.Core
237   * @since 10
238   */
239  /**
240   * Base interface of profile.
241   *
242   * @typedef BaseProfile
243   * @syscap SystemCapability.Communication.Bluetooth.Core
244   * @crossplatform
245   * @since arkts {'1.1':'13','1.2':'20'}
246   * @arkts 1.1&1.2
247   */
248  export interface BaseProfile {
249    /**
250     * Set connection strategy of this profile.
251     *
252     * @permission ohos.permission.ACCESS_BLUETOOTH and ohos.permission.MANAGE_BLUETOOTH
253     * @param { string } deviceId - Indicates device ID. For example, "11:22:33:AA:BB:FF".
254     * @param { ConnectionStrategy } strategy - the connection strategy of this profile.
255     * @returns { Promise<void> } Returns the promise object.
256     * @throws { BusinessError } 201 - Permission denied.
257     * @throws { BusinessError } 202 - Non-system applications are not allowed to use system APIs.
258     * @throws { BusinessError } 401 - Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified.
259     * <br>2. Incorrect parameter types. 3. Parameter verification failed.
260     * @throws { BusinessError } 801 - Capability not supported.
261     * @throws { BusinessError } 2900001 - Service stopped.
262     * @throws { BusinessError } 2900003 - Bluetooth disabled.
263     * @throws { BusinessError } 2900004 - Profile not supported.
264     * @throws { BusinessError } 2900099 - Operation failed.
265     * @syscap SystemCapability.Communication.Bluetooth.Core
266     * @systemapi
267     * @since 10
268     */
269    setConnectionStrategy(deviceId: string, strategy: ConnectionStrategy): Promise<void>;
270
271    /**
272     * Set connection strategy of this profile.
273     *
274     * @permission ohos.permission.ACCESS_BLUETOOTH and ohos.permission.MANAGE_BLUETOOTH
275     * @param { string } deviceId - Indicates device ID. For example, "11:22:33:AA:BB:FF".
276     * @param { ConnectionStrategy } strategy - the connection strategy of this profile.
277     * @param { AsyncCallback<void> } callback - the callback of setConnectionStrategy.
278     * @throws { BusinessError } 201 - Permission denied.
279     * @throws { BusinessError } 202 - Non-system applications are not allowed to use system APIs.
280     * @throws { BusinessError } 401 - Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified.
281     * <br>2. Incorrect parameter types. 3. Parameter verification failed.
282     * @throws { BusinessError } 801 - Capability not supported.
283     * @throws { BusinessError } 2900001 - Service stopped.
284     * @throws { BusinessError } 2900003 - Bluetooth disabled.
285     * @throws { BusinessError } 2900004 - Profile not supported.
286     * @throws { BusinessError } 2900099 - Operation failed.
287     * @syscap SystemCapability.Communication.Bluetooth.Core
288     * @systemapi
289     * @since 10
290     */
291    setConnectionStrategy(deviceId: string, strategy: ConnectionStrategy, callback: AsyncCallback<void>): void;
292
293    /**
294     * Get connection strategy of this profile.
295     *
296     * @permission ohos.permission.ACCESS_BLUETOOTH and ohos.permission.MANAGE_BLUETOOTH
297     * @param { string } deviceId - Indicates device ID. For example, "11:22:33:AA:BB:FF".
298     * @param { AsyncCallback<ConnectionStrategy> } callback - the callback of getConnectionStrategy.
299     * @throws { BusinessError } 201 - Permission denied.
300     * @throws { BusinessError } 202 - Non-system applications are not allowed to use system APIs.
301     * @throws { BusinessError } 401 - Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified.
302     * <br>2. Incorrect parameter types. 3. Parameter verification failed.
303     * @throws { BusinessError } 801 - Capability not supported.
304     * @throws { BusinessError } 2900001 - Service stopped.
305     * @throws { BusinessError } 2900003 - Bluetooth disabled.
306     * @throws { BusinessError } 2900004 - Profile not supported.
307     * @throws { BusinessError } 2900099 - Operation failed.
308     * @syscap SystemCapability.Communication.Bluetooth.Core
309     * @systemapi
310     * @since 10
311     */
312    getConnectionStrategy(deviceId: string, callback: AsyncCallback<ConnectionStrategy>): void;
313
314    /**
315     * Get connection strategy of this profile.
316     *
317     * @permission ohos.permission.ACCESS_BLUETOOTH and ohos.permission.MANAGE_BLUETOOTH
318     * @param { string } deviceId - Indicates device ID. For example, "11:22:33:AA:BB:FF".
319     * @returns { Promise<ConnectionStrategy> } Returns the promise object.
320     * @throws { BusinessError } 201 - Permission denied.
321     * @throws { BusinessError } 202 - Non-system applications are not allowed to use system APIs.
322     * @throws { BusinessError } 401 - Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified.
323     * <br>2. Incorrect parameter types. 3. Parameter verification failed.
324     * @throws { BusinessError } 801 - Capability not supported.
325     * @throws { BusinessError } 2900001 - Service stopped.
326     * @throws { BusinessError } 2900003 - Bluetooth disabled.
327     * @throws { BusinessError } 2900004 - Profile not supported.
328     * @throws { BusinessError } 2900099 - Operation failed.
329     * @syscap SystemCapability.Communication.Bluetooth.Core
330     * @systemapi
331     * @since 10
332     */
333    getConnectionStrategy(deviceId: string): Promise<ConnectionStrategy>;
334
335    /**
336     * Obtains the connected devices list of profile.
337     *
338     * @permission ohos.permission.ACCESS_BLUETOOTH
339     * @returns { Array<string> } Returns the address of connected devices list.
340     * @throws { BusinessError } 201 - Permission denied.
341     * @throws { BusinessError } 801 - Capability not supported.
342     * @throws { BusinessError } 2900001 - Service stopped.
343     * @throws { BusinessError } 2900003 - Bluetooth disabled.
344     * @throws { BusinessError } 2900004 - Profile not supported.
345     * @throws { BusinessError } 2900099 - Operation failed.
346     * @syscap SystemCapability.Communication.Bluetooth.Core
347     * @since 10
348     */
349    /**
350     * Obtains the connected devices list of profile.
351     *
352     * @permission ohos.permission.ACCESS_BLUETOOTH
353     * @returns { Array<string> } Returns the address of connected devices list.
354     * @throws { BusinessError } 201 - Permission denied.
355     * @throws { BusinessError } 801 - Capability not supported.
356     * @throws { BusinessError } 2900001 - Service stopped.
357     * @throws { BusinessError } 2900003 - Bluetooth disabled.
358     * @throws { BusinessError } 2900004 - Profile not supported.
359     * @throws { BusinessError } 2900099 - Operation failed.
360     * @syscap SystemCapability.Communication.Bluetooth.Core
361     * @crossplatform
362     * @since 13
363     */
364    getConnectedDevices(): Array<string>;
365
366    /**
367     * Obtains the profile connection state.
368     *
369     * @permission ohos.permission.ACCESS_BLUETOOTH
370     * @param { string } deviceId - Indicates device ID. For example, "11:22:33:AA:BB:FF".
371     * @returns { ProfileConnectionState } Returns the connection state.
372     * @throws { BusinessError } 201 - Permission denied.
373     * @throws { BusinessError } 401 - Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified.
374     * <br>2. Incorrect parameter types. 3. Parameter verification failed.
375     * @throws { BusinessError } 801 - Capability not supported.
376     * @throws { BusinessError } 2900001 - Service stopped.
377     * @throws { BusinessError } 2900003 - Bluetooth disabled.
378     * @throws { BusinessError } 2900004 - Profile not supported.
379     * @throws { BusinessError } 2900099 - Operation failed.
380     * @syscap SystemCapability.Communication.Bluetooth.Core
381     * @since 10
382     */
383    /**
384     * Obtains the profile connection state.
385     *
386     * @permission ohos.permission.ACCESS_BLUETOOTH
387     * @param { string } deviceId - Indicates device ID. For example, "11:22:33:AA:BB:FF".
388     * @returns { ProfileConnectionState } Returns the connection state.
389     * @throws { BusinessError } 201 - Permission denied.
390     * @throws { BusinessError } 401 - Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified.
391     * <br>2. Incorrect parameter types. 3. Parameter verification failed.
392     * @throws { BusinessError } 801 - Capability not supported.
393     * @throws { BusinessError } 2900001 - Service stopped.
394     * @throws { BusinessError } 2900003 - Bluetooth disabled.
395     * @throws { BusinessError } 2900004 - Profile not supported.
396     * @throws { BusinessError } 2900099 - Operation failed.
397     * @syscap SystemCapability.Communication.Bluetooth.Core
398     * @crossplatform
399     * @since 13
400     */
401    getConnectionState(deviceId: string): ProfileConnectionState;
402
403    /**
404     * Subscribe the event reported when the profile connection state changes .
405     *
406     * @permission ohos.permission.ACCESS_BLUETOOTH
407     * @param { 'connectionStateChange' } type - Type of the profile connection state changes event to listen for.
408     * @param { Callback<StateChangeParam> } callback - Callback used to listen for event.
409     * @throws { BusinessError } 201 - Permission denied.
410     * @throws { BusinessError } 401 - Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified.
411     * <br>2. Incorrect parameter types. 3. Parameter verification failed.
412     * @throws { BusinessError } 801 - Capability not supported.
413     * @syscap SystemCapability.Communication.Bluetooth.Core
414     * @since 10
415     */
416    /**
417     * Subscribe the event reported when the profile connection state changes .
418     *
419     * @permission ohos.permission.ACCESS_BLUETOOTH
420     * @param { 'connectionStateChange' } type - Type of the profile connection state changes event to listen for.
421     * @param { Callback<StateChangeParam> } callback - Callback used to listen for event.
422     * @throws { BusinessError } 201 - Permission denied.
423     * @throws { BusinessError } 401 - Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified.
424     * <br>2. Incorrect parameter types. 3. Parameter verification failed.
425     * @throws { BusinessError } 801 - Capability not supported.
426     * @syscap SystemCapability.Communication.Bluetooth.Core
427     * @crossplatform
428     * @since 13
429     */
430    on(type: 'connectionStateChange', callback: Callback<StateChangeParam>): void;
431
432    /**
433     * Unsubscribe the event reported when the profile connection state changes .
434     *
435     * @permission ohos.permission.ACCESS_BLUETOOTH
436     * @param { 'connectionStateChange' } type - Type of the profile connection state changes event to listen for.
437     * @param { Callback<StateChangeParam> } callback - Callback used to listen for event.
438     * @throws { BusinessError } 201 - Permission denied.
439     * @throws { BusinessError } 401 - Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified.
440     * <br>2. Incorrect parameter types. 3. Parameter verification failed.
441     * @throws { BusinessError } 801 - Capability not supported.
442     * @syscap SystemCapability.Communication.Bluetooth.Core
443     * @since 10
444     */
445    /**
446     * Unsubscribe the event reported when the profile connection state changes .
447     *
448     * @permission ohos.permission.ACCESS_BLUETOOTH
449     * @param { 'connectionStateChange' } type - Type of the profile connection state changes event to listen for.
450     * @param { Callback<StateChangeParam> } callback - Callback used to listen for event.
451     * @throws { BusinessError } 201 - Permission denied.
452     * @throws { BusinessError } 401 - Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified.
453     * <br>2. Incorrect parameter types. 3. Parameter verification failed.
454     * @throws { BusinessError } 801 - Capability not supported.
455     * @syscap SystemCapability.Communication.Bluetooth.Core
456     * @crossplatform
457     * @since 13
458     */
459    off(type: 'connectionStateChange', callback?: Callback<StateChangeParam>): void;
460  }
461}
462
463export default baseProfile;