• 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.annotation.NonNull;
20 
21 /**
22  * This abstract class is used to implement {@link BluetoothGatt} callbacks.
23  */
24 public abstract class BluetoothGattCallback {
25 
26     /**
27      * Callback triggered as result of {@link BluetoothGatt#setPreferredPhy}, or as a result of
28      * remote device changing the PHY.
29      *
30      * @param gatt GATT client
31      * @param txPhy the transmitter PHY in use. One of {@link BluetoothDevice#PHY_LE_1M}, {@link
32      * BluetoothDevice#PHY_LE_2M}, and {@link BluetoothDevice#PHY_LE_CODED}.
33      * @param rxPhy the receiver PHY in use. One of {@link BluetoothDevice#PHY_LE_1M}, {@link
34      * BluetoothDevice#PHY_LE_2M}, and {@link BluetoothDevice#PHY_LE_CODED}.
35      * @param status Status of the PHY update operation. {@link BluetoothGatt#GATT_SUCCESS} if the
36      * operation succeeds.
37      */
onPhyUpdate(BluetoothGatt gatt, int txPhy, int rxPhy, int status)38     public void onPhyUpdate(BluetoothGatt gatt, int txPhy, int rxPhy, int status) {
39     }
40 
41     /**
42      * Callback triggered as result of {@link BluetoothGatt#readPhy}
43      *
44      * @param gatt GATT client
45      * @param txPhy the transmitter PHY in use. One of {@link BluetoothDevice#PHY_LE_1M}, {@link
46      * BluetoothDevice#PHY_LE_2M}, and {@link BluetoothDevice#PHY_LE_CODED}.
47      * @param rxPhy the receiver PHY in use. One of {@link BluetoothDevice#PHY_LE_1M}, {@link
48      * BluetoothDevice#PHY_LE_2M}, and {@link BluetoothDevice#PHY_LE_CODED}.
49      * @param status Status of the PHY read operation. {@link BluetoothGatt#GATT_SUCCESS} if the
50      * operation succeeds.
51      */
onPhyRead(BluetoothGatt gatt, int txPhy, int rxPhy, int status)52     public void onPhyRead(BluetoothGatt gatt, int txPhy, int rxPhy, int status) {
53     }
54 
55     /**
56      * Callback indicating when GATT client has connected/disconnected to/from a remote
57      * GATT server.
58      *
59      * @param gatt GATT client
60      * @param status Status of the connect or disconnect operation. {@link
61      * BluetoothGatt#GATT_SUCCESS} if the operation succeeds.
62      * @param newState Returns the new connection state. Can be one of {@link
63      * BluetoothProfile#STATE_DISCONNECTED} or {@link BluetoothProfile#STATE_CONNECTED}
64      */
onConnectionStateChange(BluetoothGatt gatt, int status, int newState)65     public void onConnectionStateChange(BluetoothGatt gatt, int status,
66             int newState) {
67     }
68 
69     /**
70      * Callback invoked when the list of remote services, characteristics and descriptors
71      * for the remote device have been updated, ie new services have been discovered.
72      *
73      * @param gatt GATT client invoked {@link BluetoothGatt#discoverServices}
74      * @param status {@link BluetoothGatt#GATT_SUCCESS} if the remote device has been explored
75      * successfully.
76      */
onServicesDiscovered(BluetoothGatt gatt, int status)77     public void onServicesDiscovered(BluetoothGatt gatt, int status) {
78     }
79 
80     /**
81      * Callback reporting the result of a characteristic read operation.
82      *
83      * @param gatt           GATT client invoked
84      *                       {@link BluetoothGatt#readCharacteristic(BluetoothGattCharacteristic)}
85      * @param characteristic Characteristic that was read from the associated remote device.
86      * @param status         {@link BluetoothGatt#GATT_SUCCESS} if the read operation was completed
87      *                       successfully.
88      * @deprecated Use {@link BluetoothGattCallback#onCharacteristicRead(BluetoothGatt,
89      * BluetoothGattCharacteristic, byte[], int)} as it is memory safe
90      */
91     @Deprecated
onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status)92     public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic,
93             int status) {
94     }
95 
96     /**
97      * Callback reporting the result of a characteristic read operation.
98      *
99      * @param gatt           GATT client invoked
100      *                       {@link BluetoothGatt#readCharacteristic(BluetoothGattCharacteristic)}
101      * @param characteristic Characteristic that was read from the associated remote device.
102      * @param value          the value of the characteristic
103      * @param status         {@link BluetoothGatt#GATT_SUCCESS} if the read operation was completed
104      *                       successfully.
105      */
onCharacteristicRead(@onNull BluetoothGatt gatt, @NonNull BluetoothGattCharacteristic characteristic, @NonNull byte[] value, int status)106     public void onCharacteristicRead(@NonNull BluetoothGatt gatt, @NonNull
107             BluetoothGattCharacteristic characteristic, @NonNull byte[] value, int status) {
108         onCharacteristicRead(gatt, characteristic, status);
109     }
110 
111     /**
112      * Callback indicating the result of a characteristic write operation.
113      *
114      * <p>If this callback is invoked while a reliable write transaction is
115      * in progress, the value of the characteristic represents the value
116      * reported by the remote device. An application should compare this
117      * value to the desired value to be written. If the values don't match,
118      * the application must abort the reliable write transaction.
119      *
120      * @param gatt           GATT client that invoked
121      *                       {@link BluetoothGatt#writeCharacteristic(BluetoothGattCharacteristic,
122      *                       byte[], int)}
123      * @param characteristic Characteristic that was written to the associated remote device.
124      * @param status         The result of the write operation {@link BluetoothGatt#GATT_SUCCESS} if
125      *                       the
126      *                       operation succeeds.
127      */
onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status)128     public void onCharacteristicWrite(BluetoothGatt gatt,
129             BluetoothGattCharacteristic characteristic, int status) {
130     }
131 
132     /**
133      * Callback triggered as a result of a remote characteristic notification.
134      *
135      * @param gatt           GATT client the characteristic is associated with
136      * @param characteristic Characteristic that has been updated as a result of a remote
137      *                       notification event.
138      * @deprecated Use {@link BluetoothGattCallback#onCharacteristicChanged(BluetoothGatt,
139      * BluetoothGattCharacteristic, byte[])} as it is memory safe by providing the characteristic
140      * value at the time of notification.
141      */
142     @Deprecated
onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic)143     public void onCharacteristicChanged(BluetoothGatt gatt,
144             BluetoothGattCharacteristic characteristic) {
145     }
146 
147     /**
148      * Callback triggered as a result of a remote characteristic notification. Note that the value
149      * within the characteristic object may have changed since receiving the remote characteristic
150      * notification, so check the parameter value for the value at the time of notification.
151      *
152      * @param gatt           GATT client the characteristic is associated with
153      * @param characteristic Characteristic that has been updated as a result of a remote
154      *                       notification event.
155      * @param value          notified characteristic value
156      */
onCharacteristicChanged(@onNull BluetoothGatt gatt, @NonNull BluetoothGattCharacteristic characteristic, @NonNull byte[] value)157     public void onCharacteristicChanged(@NonNull BluetoothGatt gatt,
158             @NonNull BluetoothGattCharacteristic characteristic, @NonNull byte[] value) {
159         onCharacteristicChanged(gatt, characteristic);
160     }
161 
162     /**
163      * Callback reporting the result of a descriptor read operation.
164      *
165      * @param gatt       GATT client invoked {@link BluetoothGatt#readDescriptor}
166      * @param descriptor Descriptor that was read from the associated remote device.
167      * @param status     {@link BluetoothGatt#GATT_SUCCESS} if the read operation was completed
168      *                   successfully
169      * @deprecated Use {@link BluetoothGattCallback#onDescriptorRead(BluetoothGatt,
170      * BluetoothGattDescriptor, int, byte[])} as it is memory safe by providing the descriptor
171      * value at the time it was read.
172      */
173     @Deprecated
onDescriptorRead(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status)174     public void onDescriptorRead(BluetoothGatt gatt, BluetoothGattDescriptor descriptor,
175             int status) {
176     }
177 
178     /**
179      * Callback reporting the result of a descriptor read operation.
180      *
181      * @param gatt       GATT client invoked {@link BluetoothGatt#readDescriptor}
182      * @param descriptor Descriptor that was read from the associated remote device.
183      * @param status     {@link BluetoothGatt#GATT_SUCCESS} if the read operation was completed
184      *                   successfully
185      * @param value      the descriptor value at the time of the read operation
186      */
onDescriptorRead(@onNull BluetoothGatt gatt, @NonNull BluetoothGattDescriptor descriptor, int status, @NonNull byte[] value)187     public void onDescriptorRead(@NonNull BluetoothGatt gatt,
188             @NonNull BluetoothGattDescriptor descriptor, int status, @NonNull byte[] value) {
189         onDescriptorRead(gatt, descriptor, status);
190     }
191 
192     /**
193      * Callback indicating the result of a descriptor write operation.
194      *
195      * @param gatt       GATT client invoked {@link BluetoothGatt#writeDescriptor}
196      * @param descriptor Descriptor that was writte to the associated remote device.
197      * @param status     The result of the write operation {@link BluetoothGatt#GATT_SUCCESS} if the
198      *                   operation succeeds.
199      */
onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status)200     public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor,
201             int status) {
202     }
203 
204     /**
205      * Callback invoked when a reliable write transaction has been completed.
206      *
207      * @param gatt GATT client invoked {@link BluetoothGatt#executeReliableWrite}
208      * @param status {@link BluetoothGatt#GATT_SUCCESS} if the reliable write transaction was
209      * executed successfully
210      */
onReliableWriteCompleted(BluetoothGatt gatt, int status)211     public void onReliableWriteCompleted(BluetoothGatt gatt, int status) {
212     }
213 
214     /**
215      * Callback reporting the RSSI for a remote device connection.
216      *
217      * This callback is triggered in response to the
218      * {@link BluetoothGatt#readRemoteRssi} function.
219      *
220      * @param gatt GATT client invoked {@link BluetoothGatt#readRemoteRssi}
221      * @param rssi The RSSI value for the remote device
222      * @param status {@link BluetoothGatt#GATT_SUCCESS} if the RSSI was read successfully
223      */
onReadRemoteRssi(BluetoothGatt gatt, int rssi, int status)224     public void onReadRemoteRssi(BluetoothGatt gatt, int rssi, int status) {
225     }
226 
227     /**
228      * Callback indicating the MTU for a given device connection has changed.
229      *
230      * This callback is triggered in response to the
231      * {@link BluetoothGatt#requestMtu} function, or in response to a connection
232      * event.
233      *
234      * @param gatt GATT client invoked {@link BluetoothGatt#requestMtu}
235      * @param mtu The new MTU size
236      * @param status {@link BluetoothGatt#GATT_SUCCESS} if the MTU has been changed successfully
237      */
onMtuChanged(BluetoothGatt gatt, int mtu, int status)238     public void onMtuChanged(BluetoothGatt gatt, int mtu, int status) {
239     }
240 
241     /**
242      * Callback indicating the connection parameters were updated.
243      *
244      * @param gatt GATT client involved
245      * @param interval Connection interval used on this connection, 1.25ms unit. Valid range is from
246      * 6 (7.5ms) to 3200 (4000ms).
247      * @param latency Worker latency for the connection in number of connection events. Valid range
248      * is from 0 to 499
249      * @param timeout Supervision timeout for this connection, in 10ms unit. Valid range is from 10
250      * (0.1s) to 3200 (32s)
251      * @param status {@link BluetoothGatt#GATT_SUCCESS} if the connection has been updated
252      * successfully
253      * @hide
254      */
onConnectionUpdated(BluetoothGatt gatt, int interval, int latency, int timeout, int status)255     public void onConnectionUpdated(BluetoothGatt gatt, int interval, int latency, int timeout,
256             int status) {
257     }
258 
259     /**
260      * Callback indicating service changed event is received
261      *
262      * <p>Receiving this event means that the GATT database is out of sync with
263      * the remote device. {@link BluetoothGatt#discoverServices} should be
264      * called to re-discover the services.
265      *
266      * @param gatt GATT client involved
267      */
onServiceChanged(@onNull BluetoothGatt gatt)268     public void onServiceChanged(@NonNull BluetoothGatt gatt) {
269     }
270 
271     /**
272      * Callback indicating LE connection's subrate parameters have changed.
273      *
274      * @param gatt GATT client involved
275      * @param subrateFactor for the LE connection.
276      * @param latency Worker latency for the connection in number of connection events. Valid range
277      * is from 0 to 499
278      * @param contNum Valid range is from 0 to 499.
279      * @param timeout Supervision timeout for this connection, in 10ms unit. Valid range is from 10
280      * (0.1s) to 3200 (32s)
281      * @param status {@link BluetoothGatt#GATT_SUCCESS} if LE connection subrating has been changed
282      * successfully.
283      * @hide
284      */
onSubrateChange(BluetoothGatt gatt, int subrateFactor, int latency, int contNum, int timeout, int status)285     public void onSubrateChange(BluetoothGatt gatt, int subrateFactor, int latency, int contNum,
286             int timeout, int status) {}
287 }
288