• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2021 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 { AsyncCallback, Callback } from "./basic";
17
18/**
19 * Provides methods to operate or manage Bluetooth.
20 *
21 * @SysCap SystemCapability.Communication.Bluetooth
22 * @devices phone, tablet
23 * @since 7
24 */
25declare namespace bluetooth {
26  /**
27   * Obtains the Bluetooth status of a device.
28   *
29   * @return Returns the Bluetooth status, which can be {@link BluetoothState#STATE_OFF},
30   * {@link BluetoothState#STATE_TURNING_ON}, {@link BluetoothState#STATE_ON}, {@link BluetoothState#STATE_TURNING_OFF},
31   * {@link BluetoothState#STATE_BLE_TURNING_ON}, {@link BluetoothState#STATE_BLE_ON},
32   * or {@link BluetoothState#STATE_BLE_TURNING_OFF}.
33   * @since 7
34   */
35    function getState(): BluetoothState;
36
37    /**
38     * Get the status of the local device connection to any profile of any remote device.
39     *
40     * @return One of {@link ProfileConnectionState#STATE_DISCONNECTED},
41     * {@link ProfileConnectionState#STATE_CONNECTING}, {@link ProfileConnectionState#STATE_CONNECTED},
42     * {@link ProfileConnectionState#STATE_DISCONNECTING}.
43     * @since 7
44     */
45    function getBtConnectionState(): ProfileConnectionState;
46
47    /**
48     * Starts pairing with a remote Bluetooth device.
49     *
50     * @param deviceId The address of the remote device to pair.
51     * @return Returns {@code true} if the pairing process is started; returns {@code false} otherwise.
52     * @since 7
53     */
54    function pairDevice(deviceId: string): boolean;
55
56    function enableBluetooth(): boolean;
57    function disableBluetooth(): boolean;
58    function getLocalName(): string;
59    function getPairedDevices(): Array<string>;
60    function getProfileConnState(profileId: number): number;
61    function setDevicePariringConfirmation(device: string, accept: boolean): boolean;
62    function setLocalName(name: string): boolean;
63    function setBluetoothScanMode(mode: number, duration: number): boolean;
64    function getBluetoothScanMode(): number;
65    function startBluetoothDiscovery(): boolean;
66    function stopBluetoothDiscovery(): boolean;
67    function on(type: "bluetoothDeviceFind", callback: AsyncCallback<Array<string>>): void;
68    function off(type: "bluetoothDeviceFind", callback?: AsyncCallback<Array<string>>): void;
69    function on(type: "boneStateChange", callback: AsyncCallback<number>): void;
70    function off(type: "boneStateChange", callback?: AsyncCallback<number>): void;
71    function on(type: "pinRequired", callback: AsyncCallback<string>): void;
72    function off(type: "pinRequired", callback?: AsyncCallback<string>): void;
73    function on(type: "stateChange", callback: AsyncCallback<BluetoothState>);
74    function off(type: "stateChange", callback?: AsyncCallback<BluetoothState>);
75
76    function sppListen(name: string, option: SppOption, callback: AsyncCallback<serverSocket: number>): void;
77    function sppAccept(serverSocket: number, callback: AsyncCallback<clientSocket: number>): void;
78    function sppConnect(device: string, option: SppOption, callback: AsyncCallback<clientSocket: number>): void;
79    function sppCloseServerSocket(socket: number): void;
80    function sppCloseClientSocket(socket: number): void;
81    function sppWrite(clientSocket: number, data: ArrayBuffer): boolean;
82    function on(type: "sppRead", clientSocket: number, callback: AsyncCallback<ArrayBuffer>): void;
83    function off(type: "sppRead", clientSocket: number, callback?: AsyncCallback<ArrayBuffer>): void;
84
85    function getProfile(profileId: number): A2dpSinkProfile |
86      A2dpSourceProfile | AvrcpProfile | HandsFreeAudioGatewayProfile | HandsFreeUnitProfile | HidHostProfile |
87      PanNetworkProfile | PbapClientProfile | PbapServerProfile;
88
89    interface BaseProfile {
90      getConnectionDevices(): Array<string>;
91      getDeviceState(device: string): number;
92    }
93
94    interface A2dpSinkProfile extends BaseProfile {
95      connect(device: string): boolean;
96      disconnect(device: string): boolean;
97      getPlayingState(device: string): number;
98      on(type: "connectionStateChange", callback: AsyncCallback<number>): void;
99      off(type: "connectionStateChange", callback?: AsyncCallback<number>): void;
100    }
101
102    interface A2dpSourceProfile extends BaseProfile {
103      on(type: "connectionStateChange", callback: AsyncCallback<number>): void;
104      off(type: "connectionStateChange", callback?: AsyncCallback<number>): void;
105      getPlayingState(device: string): number;
106    }
107
108    interface AvrcpProfile extends BaseProfile {
109      on(type: "connectionStateChange", callback: AsyncCallback<number>): void;
110      off(type: "connectionStateChange", callback?: AsyncCallback<number>): void;
111    }
112
113    interface HandsFreeAudioGatewayProfile extends BaseProfile {
114      getScoState(device: string): number;
115      connectSco(device: string): boolean;
116      disconnectSco(device: string): boolean;
117      on(type: "connectionStateChange", callback: AsyncCallback<number>): void;
118      off(type: "connectionStateChange", callback?: AsyncCallback<number>): void;
119      on(type: "scoStateChange", callback: AsyncCallback<number>): void;
120      off(type: "scoStateChange", callback?: AsyncCallback<number>): void;
121      openVoiceRecognition(device: string): boolean;
122      closeVoiceRecognition(device: string): boolean;
123    }
124
125    interface HandsFreeUnitProfile extends BaseProfile {
126      getScoState(device: string): number;
127      connect(device: string): boolean;
128      disconnect(device: string): boolean;
129      on(type: "connectionStateChange", callback: AsyncCallback<number>): void;
130      off(type: "connectionStateChange", callback?: AsyncCallback<number>): void;
131      connectSco(device: string): boolean;
132      disconnectSco(device: string): boolean;
133      on(type: "scoStateChange", callback: AsyncCallback<number>): void;
134      off(type: "scoStateChange", callback?: AsyncCallback<number>): void;
135      sendDTMF(device: string, digit: number): void;
136    }
137
138    interface HidHostProfile extends BaseProfile {
139      connect(device: string): boolean;
140      disconnect(device: string): boolean;
141      on(type: "connectionStateChange", callback: AsyncCallback<number>): void;
142      off(type: "connectionStateChange", callback?: AsyncCallback<number>): void;
143    }
144
145    interface PanNetworkProfile extends BaseProfile {
146      connect(device: string): boolean;
147      disconnect(device: string): boolean;
148      on(type: "connectionStateChange", callback: AsyncCallback<number>): void;
149      off(type: "connectionStateChange", callback?: AsyncCallback<number>): void;
150    }
151
152    interface PbapClientProfile extends BaseProfile {
153      connect(device: string): boolean;
154      disconnect(device: string): boolean;
155      on(type: "connectionStateChange", callback: AsyncCallback<number>): void;
156      off(type: "connectionStateChange", callback?: AsyncCallback<number>): void;
157    }
158
159    interface PbapServerProfile extends BaseProfile {
160      disconnect(device: string): boolean;
161      on(type: "connectionStateChange", callback: AsyncCallback<number>): void;
162      off(type: "connectionStateChange", callback?: AsyncCallback<number>): void;
163    }
164
165    namespace BLE {
166        /**
167         * create a JavaScript Gatt server instance.
168         *
169         * @return Returns a JavaScript Gatt server instance {@code GattServer}.
170         * @since 7
171         */
172        function createGattServer(): GattServer;
173
174        /**
175         * create a JavaScript Gatt client device instance.
176         *
177         * @param deviceId The address of the remote device.
178         * @return Returns a JavaScript Gatt client device instance {@code GattClientDevice}.
179         * @since 7
180         */
181        function createGattClientDevice(deviceId: string): GattClientDevice;
182
183        /**
184         * Obtains the list of devices in the connected status.
185         *
186         * @return Returns the list of device address.
187         */
188        function getConnectedBLEDevices(): Array<string>;
189
190        /**
191         * Starts scanning for specified BLE devices with filters.
192         *
193         * @param filters Indicates the list of filters used to filter out specified devices.
194         * If you do not want to use filter, set this parameter to {@code null}.
195         * @param options Indicates the parameters for scanning and if the user does not assign a value, the default value will be used.
196         * {@link ScanOptions#interval} set to 0, {@link ScanOptions#dutyMode} set to {@link SCAN_MODE_LOW_POWER}
197         * and {@link ScanOptions#matchMode} set to {@link MATCH_MODE_AGGRESSIVE}.
198         * @since 7
199         */
200        function startBLEScan(filters: Array<ScanFilter>, options?: ScanOptions): void;
201
202        /**
203         * Stops BLE scanning.
204         *
205         * @since 7
206         */
207        function stopBLEScan(): void;
208
209        /**
210         * Subscribe BLE scan result.
211         *
212         * @param type Type of the scan result event to listen for.
213         * @param callback Callback used to listen for the scan result event.
214         * @since 7
215         */
216        function on(type: "BLEDeviceFind", callback: Callback<Array<ScanResult>>): void;
217
218        /**
219         * Unsubscribe BLE scan result.
220         *
221         * @param type Type of the scan result event to listen for.
222         * @param callback Callback used to listen for the scan result event.
223         * @since 7
224         */
225        function off(type: "BLEDeviceFind", callback?: Callback<Array<ScanResult>>): void;
226    }
227
228    /**
229     * Manages GATT server. Before calling an Gatt server method, you must use {@link createGattServer} to create an GattServer instance.
230     */
231    interface GattServer {
232
233        /**
234         * Starts BLE advertising.
235         *
236         * @param setting Indicates the settings for BLE advertising.
237         * If you need to use the default value, set this parameter to {@code null}.
238         * @param advData Indicates the advertising data.
239         * @param advResponse Indicates the scan response associated with the advertising data.
240         * @since 7
241         */
242        startAdvertising(setting: AdvertiseSetting, advData: AdvertiseData, advResponse?: AdvertiseData): void;
243
244        /**
245         * Stops BLE advertising.
246         *
247         * @since 7
248         */
249        stopAdvertising(): void;
250
251        /**
252         * Adds a specified service to be hosted.
253         *
254         * <p>The added service and its characteristics are provided by the local device.
255         *
256         * @param service Indicates the service to add.
257         * @return Returns {@code true} if the service is added; returns {@code false} otherwise.
258         * @since 7
259         */
260        addService(service: GattService): boolean;
261
262        /**
263         * Removes a specified service from the list of GATT services provided by this device.
264         *
265         * @param serviceUuid Indicates the UUID of the service to remove.
266         * @return Returns {@code true} if the service is removed; returns {@code false} otherwise.
267         * @since 7
268         */
269        removeService(serviceUuid: string): boolean;
270
271        /**
272         * Closes this {@code GattServer} object and unregisters its callbacks.
273         *
274         * @since 7
275         */
276        close(): void;
277
278        /**
279         * Sends a notification of a change in a specified local characteristic.
280         *
281         * <p>This method should be called for every BLE peripheral device that has requested notifications.
282         *
283         * @param deviceId Indicates the address of the BLE peripheral device to receive the notification.
284         * @param notifyCharacteristic Indicates the local characteristic that has changed.
285         * @return Returns {@code true} if the notification is sent successfully; returns {@code false} otherwise.
286         * @since 7
287         */
288        notifyCharacteristicChanged(deviceId: string, notifyCharacteristic: NotifyCharacteristic): boolean;
289
290        /**
291         * Sends a response to a specified read or write request to a given BLE peripheral device.
292         *
293         * @param serverResponse Indicates the response parameters {@link ServerResponse}.
294         * @return Returns {@code true} if the response is sent successfully; returns {@code false} otherwise.
295         * @since 7
296         */
297        sendResponse(serverResponse: ServerResponse): boolean;
298
299        /**
300         * Subscribe characteristic read event.
301         *
302         * @param type Type of the characteristic read event to listen for.
303         * @param callback Callback used to listen for the characteristic read event.
304         * @since 7
305         */
306        on(type: "characteristicRead", callback: Callback<CharacteristicReadReq>): void;
307
308        /**
309         * Unsubscribe characteristic read event.
310         *
311         * @param type Type of the characteristic read event to listen for.
312         * @param callback Callback used to listen for the characteristic read event.
313         * @since 7
314         */
315        off(type: "characteristicRead", callback?: Callback<CharacteristicReadReq>): void;
316
317        /**
318         * Subscribe characteristic write event.
319         *
320         * @param type Type of the characteristic write event to listen for.
321         * @param callback Callback used to listen for the characteristic write event.
322         * @since 7
323         */
324        on(type: "characteristicWrite", callback: Callback<CharacteristicWriteReq>): void;
325
326        /**
327         * Unsubscribe characteristic write event.
328         *
329         * @param type Type of the characteristic write event to listen for.
330         * @param callback Callback used to listen for the characteristic write event.
331         * @since 7
332         */
333        off(type: "characteristicWrite", callback?: Callback<CharacteristicWriteReq>): void;
334
335        /**
336         * Subscribe descriptor read event.
337         *
338         * @param type Type of the descriptor read event to listen for.
339         * @param callback Callback used to listen for the descriptor read event.
340         * @since 7
341         */
342        on(type: "descriptorRead", callback: Callback<DescriptorReadReq>): void;
343
344        /**
345         * Unsubscribe descriptor read event.
346         *
347         * @param type Type of the descriptor read event to listen for.
348         * @param callback Callback used to listen for the descriptor read event.
349         * @since 7
350         */
351        off(type: "descriptorRead", callback?: Callback<DescriptorReadReq>): void;
352
353        /**
354         * Subscribe descriptor write event.
355         *
356         * @param type Type of the descriptor write event to listen for.
357         * @param callback Callback used to listen for the descriptor write event.
358         * @since 7
359         */
360        on(type: "descriptorWrite", callback: Callback<DescriptorWriteReq>): void;
361
362        /**
363         * Unsubscribe descriptor write event.
364         *
365         * @param type Type of the descriptor write event to listen for.
366         * @param callback Callback used to listen for the descriptor write event.
367         * @since 7
368         */
369        off(type: "descriptorWrite", callback?: Callback<DescriptorWriteReq>): void;
370
371        /**
372         * Subscribe server connection state changed event.
373         *
374         * @param type Type of the connection state changed event to listen for.
375         * @param callback Callback used to listen for the connection state changed event.
376         * @since 7
377         */
378        on(type: "connectStateChange", callback: Callback<BLEConnectChangedState>): void;
379
380        /**
381         * Unsubscribe server connection state changed event.
382         *
383         * @param type Type of the connection state changed event to listen for.
384         * @param callback Callback used to listen for the connection state changed event.
385         * @since 7
386         */
387        off(type: "connectStateChange", callback?: Callback<BLEConnectChangedState>): void;
388    }
389
390    /**
391     * Manages GATT client. Before calling an Gatt client method, you must use {@link createGattClientDevice} to create an GattClientDevice instance.
392     */
393    interface GattClientDevice {
394
395        /**
396         * Connects to a BLE peripheral device.
397         *
398         * <p>The 'BLEConnectionStateChange' event is subscribed to return the connection state.
399         *
400         * @return Returns {@code true} if the connection process starts; returns {@code false} otherwise.
401         * @since 7
402         */
403        connect(): boolean;
404
405        /**
406         * Disconnects from or stops an ongoing connection to a BLE peripheral device.
407         *
408         * @return Returns {@code true} if the disconnection process starts; returns {@code false} otherwise.
409         * @since 7
410         */
411        disconnect(): boolean;
412
413        /**
414         * Disables a BLE peripheral device.
415         *
416         * <p> This method unregisters the device and clears the registered callbacks and handles.
417         *
418         * @return Returns {@code true} if the the device is disabled; returns {@code false} otherwise.
419         * @since 7
420         */
421        close(): boolean;
422
423        /**
424         * Obtains the name of BLE peripheral device.
425         *
426         * @return Returns a string representation of the name if obtained;
427         * returns {@code null} if the name fails to be obtained or the name does not exist.
428         * @since 7
429         */
430        getDeviceName(callback: AsyncCallback<string>): void;
431        getDeviceName(): Promise<string>;
432
433        /**
434         * Starts discovering services.
435         *
436         * @return Returns the list of services {@link GattService} of the BLE peripheral device.
437         * @since 7
438         */
439        getServices(callback: AsyncCallback<Array<GattService>>): void;
440        getServices(): Promise<Array<GattService>>;
441
442        /**
443         * Reads the characteristic of a BLE peripheral device.
444         *
445         * @param characteristic Indicates the characteristic to read.
446         * @since 7
447         */
448        readCharacteristicValue(characteristic: BLECharacteristic, callback: AsyncCallback<BLECharacteristic>): void;
449        readCharacteristicValue(characteristic: BLECharacteristic): Promise<BLECharacteristic>;
450
451        /**
452         * Reads the descriptor of a BLE peripheral device.
453         *
454         * @param descriptor Indicates the descriptor to read.
455         * @since 7
456         */
457        readDescriptorValue(descriptor: BLEDescriptor, callback: AsyncCallback<BLEDescriptor>): void;
458        readDescriptorValue(descriptor: BLEDescriptor): Promise<BLEDescriptor>;
459
460        /**
461         * Writes the characteristic of a BLE peripheral device.
462         *
463         * @param characteristic Indicates the characteristic to write.
464         * @return Returns {@code true} if the characteristic is written successfully; returns {@code false} otherwise.
465         * @since 7
466         */
467        writeCharacteristicValue(characteristic: BLECharacteristic): boolean;
468
469        /**
470         * Writes the descriptor of a BLE peripheral device.
471         *
472         * @param descriptor Indicates the descriptor to write.
473         * @return Returns {@code true} if the descriptor is written successfully; returns {@code false} otherwise.
474         * @since 7
475         */
476        writeDescriptorValue(descriptor: BLEDescriptor): boolean;
477
478        /**
479         * Get the RSSI value of this BLE peripheral device.
480         *
481         * @return Returns the RSSI value.
482         * @since 7
483         */
484        getRssiValue(callback: AsyncCallback<number>): void;
485        getRssiValue(): Promise<number>;
486
487        /**
488         * Set the mtu size of a BLE peripheral device.
489         *
490         * @param mtu The maximum transmission unit.
491         * @return Returns {@code true} if the set mtu is successfully; returns {@code false} otherwise.
492         * @since 7
493         */
494        setBLEMtuSize(mtu: number): boolean;
495
496        /**
497         * Enables or disables notification of a characteristic when value changed.
498         *
499         * @param enable Specifies whether to enable notification of the characteristic. The value {@code true} indicates
500         * that notification is enabled, and the value {@code false} indicates that notification is disabled.
501         * @return Returns {@code true} if notification of the characteristic is enabled or disabled;
502         * returns {@code false} otherwise.
503         * @since 7
504         */
505        setNotifyCharacteristicChanged(characteristic: BLECharacteristic, enable: boolean): boolean;
506
507        /**
508         * Subscribe characteristic value changed event.
509         *
510         * @param type Type of the characteristic value changed event to listen for.
511         * @param callback Callback used to listen for the characteristic value changed event.
512         * @since 7
513         */
514        on(type: "BLECharacteristicChange", callback: Callback<BLECharacteristic>): void;
515
516        /**
517         * Unsubscribe characteristic value changed event.
518         *
519         * @param type Type of the characteristic value changed event to listen for.
520         * @param callback Callback used to listen for the characteristic value changed event.
521         * @since 7
522         */
523        off(type: "BLECharacteristicChange", callback?: Callback<BLECharacteristic>): void;
524
525        /**
526         * Subscribe client connection state changed event.
527         *
528         * @param type Type of the connection state changed event to listen for.
529         * @param callback Callback used to listen for the connection state changed event.
530         * @since 7
531         */
532        on(type: "BLEConnectionStateChange", callback: Callback<BLEConnectChangedState>): void;
533
534        /**
535         * Unsubscribe client connection state changed event.
536         *
537         * @param type Type of the connection state changed event to listen for.
538         * @param callback Callback used to listen for the connection state changed event.
539         * @since 7
540         */
541        off(type: "BLEConnectionStateChange", callback?: Callback<BLEConnectChangedState>): void;
542    }
543
544    /**
545     * Describes the Gatt service.
546     *
547     * @devices phone, tablet
548     * @since 7
549     */
550    interface GattService {
551        /** The UUID of a GattService instance */
552        serviceUuid: string;
553        /** Indicates whether the GattService instance is primary or secondary. */
554        isPrimary: boolean;
555        /** The {@link BLECharacteristic} list belongs to this GattService instance */
556        characteristics: Array<BLECharacteristic>;
557        /** The list of GATT services contained in the service */
558        includeServices?: Array<GattService>;
559    }
560
561    /**
562     * Describes the Gatt characteristic.
563     *
564     * @devices phone, tablet
565     * @since 7
566     */
567    interface BLECharacteristic {
568        /** The UUID of the {@link GattService} instance to which the characteristic belongs */
569        serviceUuid: string;
570        /** The UUID of a BLECharacteristic instance */
571         characteristicUuid: string;
572        /** The value of a BLECharacteristic instance */
573         characteristicValue: ArrayBuffer;
574        /** The list of {@link BLEDescriptor} contained in the characteristic */
575        descriptors: Array<BLEDescriptor>;
576    }
577
578    /**
579     * Describes the Gatt descriptor.
580     *
581     * @devices phone, tablet
582     * @since 7
583     */
584    interface BLEDescriptor {
585        /** The UUID of the {@link GattService} instance to which the descriptor belongs */
586        serviceUuid: string;
587        /** The UUID of the {@link BLECharacteristic} instance to which the descriptor belongs */
588        characteristicUuid: string;
589        /** The UUID of the BLEDescriptor instance */
590        descriptorUuid: string;
591        /** The value of the BLEDescriptor instance */
592        descriptorValue: ArrayBuffer;
593    }
594
595    /**
596     * Describes the value of the indication or notification sent by the Gatt server.
597     *
598     * @devices phone, tablet
599     * @since 7
600     */
601    interface NotifyCharacteristic {
602        /** The UUID of the {@link GattService} instance to which the characteristic belongs */
603        serviceUuid: string;
604        /** The UUID of a NotifyCharacteristic instance */
605        characteristicUuid: string;
606        /** The value of a NotifyCharacteristic instance */
607        characteristicValue: ArrayBuffer;
608        /**
609         * Specifies whether to request confirmation from the BLE peripheral device (indication) or
610         * send a notification. Value {@code true} indicates the former and {@code false} indicates the latter.
611         */
612        confirm: boolean;
613    }
614
615    /**
616     * Describes the parameters of the Gatt client's characteristic read request.
617     *
618     * @devices phone, tablet
619     * @since 7
620     */
621    interface CharacteristicReadReq {
622        /** Indicates the address of the client that initiates the read request */
623        deviceId: string;
624        /** The Id of the read request */
625        transId: number;
626        /** Indicates the byte offset of the start position for reading characteristic value */
627        offset: number;
628        /** The UUID of a CharacteristicReadReq instance */
629        characteristicUuid: string;
630        /** The UUID of the service to which the characteristic belongs */
631        serviceUuid: string;
632    }
633
634    /**
635     * Describes the parameters of the of the Gatt client's characteristic write request.
636     *
637     * @devices phone, tablet
638     * @since 7
639     */
640    interface CharacteristicWriteReq {
641        /** Indicates the address of the client that initiates the write request */
642        deviceId: string;
643        /** The Id of the write request */
644        transId: number;
645        /** Indicates the byte offset of the start position for writing characteristic value */
646        offset: number;
647        /** Whether this request should be pending for later operation */
648        isPrep: boolean;
649        /** Whether the remote client need a response */
650        needRsp: boolean;
651        /** Indicates the value to be written */
652        value: ArrayBuffer;
653        /** The UUID of a CharacteristicWriteReq instance */
654        characteristicUuid: string;
655        /** The UUID of the service to which the characteristic belongs */
656        serviceUuid: string;
657    }
658
659    /**
660     * Describes the parameters of the Gatt client's descriptor read request.
661     *
662     * @devices phone, tablet
663     * @since 7
664     */
665    interface DescriptorReadReq {
666        /** Indicates the address of the client that initiates the read request */
667        deviceId: string;
668        /** The Id of the read request */
669        transId: number;
670        /** Indicates the byte offset of the start position for reading characteristic value */
671        offset: number;
672        /** The UUID of a DescriptorReadReq instance */
673        descriptorUuid: string;
674        /** The UUID of the characteristic to which the descriptor belongs */
675        characteristicUuid: string;
676        /** The UUID of the service to which the descriptor belongs */
677        serviceUuid: string;
678    }
679
680    /**
681     * Describes the parameters of the Gatt client's characteristic write request.
682     *
683     * @devices phone, tablet
684     * @since 7
685     */
686    interface DescriptorWriteReq {
687        /** Indicates the address of the client that initiates the write request */
688        deviceId: string;
689        /** The Id of the write request */
690        transId: number;
691        /** Indicates the byte offset of the start position for writing characteristic value */
692        offset: number;
693        /** Whether this request should be pending for later operation */
694        isPrep: boolean;
695        /** Whether the remote client need a response */
696        needRsp: boolean;
697        /** Indicates the value to be written */
698        value: ArrayBuffer;
699        /** The UUID of a DescriptorWriteReq instance */
700        descriptorUuid: string;
701        /** The UUID of the characteristic to which the descriptor belongs */
702        characteristicUuid: string;
703        /** The UUID of the service to which the descriptor belongs */
704        serviceUuid: string;
705    }
706
707    /**
708     * Describes the parameters of a response send by the server to a specified read or write request.
709     *
710     * @devices phone, tablet
711     * @since 7
712     */
713    interface ServerResponse {
714        /** Indicates the address of the client to which to send the response */
715        deviceId: string;
716        /** The Id of the write request */
717        transId: number;
718        /** Indicates the status of the read or write request, set this parameter to '0' in normal cases */
719        status: number;
720        /** Indicates the byte offset of the start position for reading or writing operation */
721        offset: number;
722        /** Indicates the value to be sent */
723        value: ArrayBuffer;
724    }
725
726    /**
727     * Describes the Gatt profile connection state.
728     *
729     * @devices phone, tablet
730     * @since 7
731     */
732    interface BLEConnectChangedState {
733        /** Indicates the peer device address */
734        deviceId: string;
735        /** Connection state of the Gatt profile */
736        state: ProfileConnectionState;
737    }
738
739    /**
740     * Describes the contents of the scan results.
741     *
742     * @devices phone, tablet
743     * @since 7
744     */
745    interface ScanResult {
746        /** Address of the scanned device */
747        deviceId: string;
748        /** RSSI of the remote device */
749        rssi: number;
750        /** The raw data of broadcast packet */
751        data: ArrayBuffer;
752    }
753
754    /**
755     * Describes the settings for BLE advertising.
756     *
757     * @devices phone, tablet
758     * @since 7
759     */
760    interface AdvertiseSetting {
761        /**
762         * Minimum slot value for the advertising interval, which is {@code 32} (20 ms)
763         * Maximum slot value for the advertising interval, which is {@code 16777215} (10485.759375s)
764         * Default slot value for the advertising interval, which is {@code 1600} (1s)
765         */
766        interval?: number;
767        /**
768         * Minimum transmission power level for advertising, which is {@code -127}
769         * Maximum transmission power level for advertising, which is {@code 1}
770         * Default transmission power level for advertising, which is {@code -7}
771         */
772        txPower?: number;
773        /** Indicates whether the BLE is connectable, default is {@code true} */
774        connectable?: boolean;
775    }
776
777    /**
778     * Describes the advertising data.
779     *
780     * @devices phone, tablet
781     * @since 7
782     */
783    interface AdvertiseData {
784        /** The specified service UUID list to this advertisement */
785        serviceUuids: Array<string>;
786        /** The specified manufacturer data list to this advertisement */
787        manufactureData: Array<ManufactureData>;
788        /** The specified service data list to this advertisement */
789        serviceData: Array<ServiceData>;
790    }
791
792    /**
793     * Describes the manufacturer data.
794     *
795     * @devices phone, tablet
796     * @since 7
797     */
798    interface ManufactureData {
799        /** Indicates the manufacturer ID assigned by Bluetooth SIG */
800        manufactureId: number;
801        /** Indicates the manufacturer data to add */
802        manufactureValue: ArrayBuffer;
803    }
804
805    /**
806     * Describes the service data.
807     *
808     * @devices phone, tablet
809     * @since 7
810     */
811    interface ServiceData {
812        /** Indicates the UUID of the service data to add */
813        serviceUuid: string;
814        /** Indicates the service data to add */
815        serviceValue: ArrayBuffer;
816    }
817
818    /**
819     * Describes the criteria for filtering scanning results can be set.
820     *
821     * @devices phone, tablet
822     * @since 7
823     */
824    interface ScanFilter {
825        /** The address of a BLE peripheral device */
826        deviceId?: string;
827        /** The name of a BLE peripheral device */
828        name?: string;
829        /** The service UUID of a BLE peripheral device */
830        serviceUuid?: string;
831    }
832
833    /**
834     * Describes the parameters for scan.
835     *
836     * @devices phone, tablet
837     * @since 7
838     */
839    interface ScanOptions {
840        /** Time of delay for reporting the scan result */
841        interval?: number;
842        /** Bluetooth LE scan mode */
843        dutyMode?: ScanDuty;
844        /** Match mode for Bluetooth LE scan filters hardware match */
845        matchMode?: MatchMode;
846    }
847
848    /**
849     * Describes the spp parameters.
850     *
851     * @devices phone, tablet
852     * @since 7
853     */
854    interface SppOption {
855        /** Indicates the UUID in the SDP record. */
856        uuid: string;
857        /** Indicates secure channel or not */
858        secure: boolean;
859        /** Spp link type {@link SppType}*/
860        type: SppType;
861    }
862
863    enum ScanDuty {
864        /** low power mode */
865        SCAN_MODE_LOW_POWER = 0,
866        /** balanced power mode */
867        SCAN_MODE_BALANCED = 1,
868        /** Scan using highest duty cycle */
869        SCAN_MODE_LOW_LATENCY = 2
870    }
871
872    enum MatchMode {
873        /** aggressive mode */
874        MATCH_MODE_AGGRESSIVE = 1,
875        /** sticky mode */
876        MATCH_MODE_STICKY = 2
877    }
878
879    enum ProfileConnectionState {
880        /** the current profile is disconnected */
881        STATE_DISCONNECTED = 0,
882        /** the current profile is being connected */
883        STATE_CONNECTING = 1,
884        /** the current profile is connected */
885        STATE_CONNECTED = 2,
886        /** the current profile is being disconnected */
887        STATE_DISCONNECTING = 3
888    }
889
890    enum BluetoothState {
891        /** Indicates the local Bluetooth is off */
892        STATE_OFF = 0,
893        /** Indicates the local Bluetooth is turning on */
894        STATE_TURNING_ON = 1,
895        /** Indicates the local Bluetooth is on, and ready for use */
896        STATE_ON = 2,
897        /** Indicates the local Bluetooth is turning off */
898        STATE_TURNING_OFF = 3,
899        /** Indicates the local Bluetooth is turning LE mode on */
900        STATE_BLE_TURNING_ON = 4,
901        /** Indicates the local Bluetooth is in LE only mode */
902        STATE_BLE_ON = 5,
903        /** Indicates the local Bluetooth is turning off LE only mode */
904        STATE_BLE_TURNING_OFF = 6
905    }
906
907    enum SppType {
908        SPP_RFCOMM;
909    }
910}
911
912export default bluetooth;