• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package android.bluetooth;
18 
19 import android.bluetooth.BluetoothDevice;
20 
21 /**
22  * This abstract class is used to implement {@link BluetoothGattServer} callbacks.
23  */
24 public abstract class BluetoothGattServerCallback {
25 
26     /**
27      * Callback indicating when a remote device has been connected or disconnected.
28      *
29      * @param device Remote device that has been connected or disconnected.
30      * @param status Status of the connect or disconnect operation.
31      * @param newState Returns the new connection state. Can be one of
32      *                  {@link BluetoothProfile#STATE_DISCONNECTED} or
33      *                  {@link BluetoothProfile#STATE_CONNECTED}
34      */
onConnectionStateChange(BluetoothDevice device, int status, int newState)35     public void onConnectionStateChange(BluetoothDevice device, int status,
36                                         int newState) {
37     }
38 
39     /**
40      * Indicates whether a local service has been added successfully.
41      *
42      * @param status Returns {@link BluetoothGatt#GATT_SUCCESS} if the service
43      *               was added successfully.
44      * @param service The service that has been added
45      */
onServiceAdded(int status, BluetoothGattService service)46     public void onServiceAdded(int status, BluetoothGattService service) {
47     }
48 
49     /**
50      * A remote client has requested to read a local characteristic.
51      *
52      * <p>An application must call {@link BluetoothGattServer#sendResponse}
53      * to complete the request.
54      *
55      * @param device The remote device that has requested the read operation
56      * @param requestId The Id of the request
57      * @param offset Offset into the value of the characteristic
58      * @param characteristic Characteristic to be read
59      */
onCharacteristicReadRequest(BluetoothDevice device, int requestId, int offset, BluetoothGattCharacteristic characteristic)60     public void onCharacteristicReadRequest(BluetoothDevice device, int requestId,
61                         int offset, BluetoothGattCharacteristic characteristic) {
62     }
63 
64     /**
65      * A remote client has requested to write to a local characteristic.
66      *
67      * <p>An application must call {@link BluetoothGattServer#sendResponse}
68      * to complete the request.
69      *
70      * @param device The remote device that has requested the write operation
71      * @param requestId The Id of the request
72      * @param characteristic Characteristic to be written to.
73      * @param preparedWrite true, if this write operation should be queued for
74      *                      later execution.
75      * @param responseNeeded true, if the remote device requires a response
76      * @param offset The offset given for the value
77      * @param value The value the client wants to assign to the characteristic
78      */
onCharacteristicWriteRequest(BluetoothDevice device, int requestId, BluetoothGattCharacteristic characteristic, boolean preparedWrite, boolean responseNeeded, int offset, byte[] value)79     public void onCharacteristicWriteRequest(BluetoothDevice device, int requestId,
80                                              BluetoothGattCharacteristic characteristic,
81                                              boolean preparedWrite, boolean responseNeeded,
82                                              int offset, byte[] value) {
83     }
84 
85     /**
86      * A remote client has requested to read a local descriptor.
87      *
88      * <p>An application must call {@link BluetoothGattServer#sendResponse}
89      * to complete the request.
90      *
91      * @param device The remote device that has requested the read operation
92      * @param requestId The Id of the request
93      * @param offset Offset into the value of the characteristic
94      * @param descriptor Descriptor to be read
95      */
onDescriptorReadRequest(BluetoothDevice device, int requestId, int offset, BluetoothGattDescriptor descriptor)96     public void onDescriptorReadRequest(BluetoothDevice device, int requestId,
97                                         int offset, BluetoothGattDescriptor descriptor) {
98     }
99 
100     /**
101      * A remote client has requested to write to a local descriptor.
102      *
103      * <p>An application must call {@link BluetoothGattServer#sendResponse}
104      * to complete the request.
105      *
106      * @param device The remote device that has requested the write operation
107      * @param requestId The Id of the request
108      * @param descriptor Descriptor to be written to.
109      * @param preparedWrite true, if this write operation should be queued for
110      *                      later execution.
111      * @param responseNeeded true, if the remote device requires a response
112      * @param offset The offset given for the value
113      * @param value The value the client wants to assign to the descriptor
114      */
onDescriptorWriteRequest(BluetoothDevice device, int requestId, BluetoothGattDescriptor descriptor, boolean preparedWrite, boolean responseNeeded, int offset, byte[] value)115     public void onDescriptorWriteRequest(BluetoothDevice device, int requestId,
116                                          BluetoothGattDescriptor descriptor,
117                                          boolean preparedWrite, boolean responseNeeded,
118                                          int offset,  byte[] value) {
119     }
120 
121     /**
122      * Execute all pending write operations for this device.
123      *
124      * <p>An application must call {@link BluetoothGattServer#sendResponse}
125      * to complete the request.
126      *
127      * @param device The remote device that has requested the write operations
128      * @param requestId The Id of the request
129      * @param execute Whether the pending writes should be executed (true) or
130      *                cancelled (false)
131      */
onExecuteWrite(BluetoothDevice device, int requestId, boolean execute)132     public void onExecuteWrite(BluetoothDevice device, int requestId, boolean execute) {
133     }
134 
135     /**
136      * Callback invoked when a notification or indication has been sent to
137      * a remote device.
138      *
139      * <p>When multiple notifications are to be sent, an application must
140      * wait for this callback to be received before sending additional
141      * notifications.
142      *
143      * @param device The remote device the notification has been sent to
144      * @param status {@link BluetoothGatt#GATT_SUCCESS} if the operation was successful
145      */
onNotificationSent(BluetoothDevice device, int status)146     public void onNotificationSent(BluetoothDevice device, int status) {
147     }
148 
149     /**
150      * Callback indicating the MTU for a given device connection has changed.
151      *
152      * <p>This callback will be invoked if a remote client has requested to change
153      * the MTU for a given connection.
154      *
155      * @param device The remote device that requested the MTU change
156      * @param mtu The new MTU size
157      */
onMtuChanged(BluetoothDevice device, int mtu)158     public void onMtuChanged(BluetoothDevice device, int mtu) {
159     }
160 
161     /**
162      * Callback triggered as result of {@link BluetoothGattServer#setPreferredPhy}, or as a result
163      * of remote device changing the PHY.
164      *
165      * @param device The remote device
166      * @param txPhy the transmitter PHY in use. One of {@link BluetoothDevice#PHY_LE_1M},
167      *             {@link BluetoothDevice#PHY_LE_2M}, and {@link BluetoothDevice#PHY_LE_CODED}
168      * @param rxPhy the receiver PHY in use. One of {@link BluetoothDevice#PHY_LE_1M},
169      *             {@link BluetoothDevice#PHY_LE_2M}, and {@link BluetoothDevice#PHY_LE_CODED}
170      * @param status Status of the PHY update operation.
171      *                  {@link BluetoothGatt#GATT_SUCCESS} if the operation succeeds.
172      */
onPhyUpdate(BluetoothDevice device, int txPhy, int rxPhy, int status)173     public void onPhyUpdate(BluetoothDevice device, int txPhy, int rxPhy, int status) {
174     }
175 
176     /**
177      * Callback triggered as result of {@link BluetoothGattServer#readPhy}
178      *
179      * @param device The remote device that requested the PHY read
180      * @param txPhy the transmitter PHY in use. One of {@link BluetoothDevice#PHY_LE_1M},
181      *             {@link BluetoothDevice#PHY_LE_2M}, and {@link BluetoothDevice#PHY_LE_CODED}
182      * @param rxPhy the receiver PHY in use. One of {@link BluetoothDevice#PHY_LE_1M},
183      *             {@link BluetoothDevice#PHY_LE_2M}, and {@link BluetoothDevice#PHY_LE_CODED}
184      * @param status Status of the PHY read operation.
185      *                  {@link BluetoothGatt#GATT_SUCCESS} if the operation succeeds.
186      */
onPhyRead(BluetoothDevice device, int txPhy, int rxPhy, int status)187     public void onPhyRead(BluetoothDevice device, int txPhy, int rxPhy, int status) {
188     }
189 
190     /**
191      * Callback indicating the connection parameters were updated.
192      *
193      * @param device The remote device involved
194      * @param interval Connection interval used on this connection, 1.25ms unit. Valid
195      *            range is from 6 (7.5ms) to 3200 (4000ms).
196      * @param latency Slave latency for the connection in number of connection events. Valid
197      *            range is from 0 to 499
198      * @param timeout Supervision timeout for this connection, in 10ms unit. Valid range is
199      *            from 10 (0.1s) to 3200 (32s)
200      * @param status {@link BluetoothGatt#GATT_SUCCESS} if the connection has been updated
201      *                successfully
202      * @hide
203      */
onConnectionUpdated(BluetoothDevice gatt, int interval, int latency, int timeout, int status)204     public void onConnectionUpdated(BluetoothDevice gatt, int interval, int latency, int timeout,
205                                     int status) {
206     }
207 
208 }
209