• 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 {@link BluetoothGatt#readCharacteristic}
84      * @param characteristic Characteristic that was read from the associated remote device.
85      * @param status {@link BluetoothGatt#GATT_SUCCESS} if the read operation was completed
86      * successfully.
87      */
onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status)88     public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic,
89             int status) {
90     }
91 
92     /**
93      * Callback indicating the result of a characteristic write operation.
94      *
95      * <p>If this callback is invoked while a reliable write transaction is
96      * in progress, the value of the characteristic represents the value
97      * reported by the remote device. An application should compare this
98      * value to the desired value to be written. If the values don't match,
99      * the application must abort the reliable write transaction.
100      *
101      * @param gatt GATT client invoked {@link BluetoothGatt#writeCharacteristic}
102      * @param characteristic Characteristic that was written to the associated remote device.
103      * @param status The result of the write operation {@link BluetoothGatt#GATT_SUCCESS} if the
104      * operation succeeds.
105      */
onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status)106     public void onCharacteristicWrite(BluetoothGatt gatt,
107             BluetoothGattCharacteristic characteristic, int status) {
108     }
109 
110     /**
111      * Callback triggered as a result of a remote characteristic notification.
112      *
113      * @param gatt GATT client the characteristic is associated with
114      * @param characteristic Characteristic that has been updated as a result of a remote
115      * notification event.
116      */
onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic)117     public void onCharacteristicChanged(BluetoothGatt gatt,
118             BluetoothGattCharacteristic characteristic) {
119     }
120 
121     /**
122      * Callback reporting the result of a descriptor read operation.
123      *
124      * @param gatt GATT client invoked {@link BluetoothGatt#readDescriptor}
125      * @param descriptor Descriptor that was read from the associated remote device.
126      * @param status {@link BluetoothGatt#GATT_SUCCESS} if the read operation was completed
127      * successfully
128      */
onDescriptorRead(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status)129     public void onDescriptorRead(BluetoothGatt gatt, BluetoothGattDescriptor descriptor,
130             int status) {
131     }
132 
133     /**
134      * Callback indicating the result of a descriptor write operation.
135      *
136      * @param gatt GATT client invoked {@link BluetoothGatt#writeDescriptor}
137      * @param descriptor Descriptor that was writte to the associated remote device.
138      * @param status The result of the write operation {@link BluetoothGatt#GATT_SUCCESS} if the
139      * operation succeeds.
140      */
onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status)141     public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor,
142             int status) {
143     }
144 
145     /**
146      * Callback invoked when a reliable write transaction has been completed.
147      *
148      * @param gatt GATT client invoked {@link BluetoothGatt#executeReliableWrite}
149      * @param status {@link BluetoothGatt#GATT_SUCCESS} if the reliable write transaction was
150      * executed successfully
151      */
onReliableWriteCompleted(BluetoothGatt gatt, int status)152     public void onReliableWriteCompleted(BluetoothGatt gatt, int status) {
153     }
154 
155     /**
156      * Callback reporting the RSSI for a remote device connection.
157      *
158      * This callback is triggered in response to the
159      * {@link BluetoothGatt#readRemoteRssi} function.
160      *
161      * @param gatt GATT client invoked {@link BluetoothGatt#readRemoteRssi}
162      * @param rssi The RSSI value for the remote device
163      * @param status {@link BluetoothGatt#GATT_SUCCESS} if the RSSI was read successfully
164      */
onReadRemoteRssi(BluetoothGatt gatt, int rssi, int status)165     public void onReadRemoteRssi(BluetoothGatt gatt, int rssi, int status) {
166     }
167 
168     /**
169      * Callback indicating the MTU for a given device connection has changed.
170      *
171      * This callback is triggered in response to the
172      * {@link BluetoothGatt#requestMtu} function, or in response to a connection
173      * event.
174      *
175      * @param gatt GATT client invoked {@link BluetoothGatt#requestMtu}
176      * @param mtu The new MTU size
177      * @param status {@link BluetoothGatt#GATT_SUCCESS} if the MTU has been changed successfully
178      */
onMtuChanged(BluetoothGatt gatt, int mtu, int status)179     public void onMtuChanged(BluetoothGatt gatt, int mtu, int status) {
180     }
181 
182     /**
183      * Callback indicating the connection parameters were updated.
184      *
185      * @param gatt GATT client involved
186      * @param interval Connection interval used on this connection, 1.25ms unit. Valid range is from
187      * 6 (7.5ms) to 3200 (4000ms).
188      * @param latency Worker latency for the connection in number of connection events. Valid range
189      * is from 0 to 499
190      * @param timeout Supervision timeout for this connection, in 10ms unit. Valid range is from 10
191      * (0.1s) to 3200 (32s)
192      * @param status {@link BluetoothGatt#GATT_SUCCESS} if the connection has been updated
193      * successfully
194      * @hide
195      */
onConnectionUpdated(BluetoothGatt gatt, int interval, int latency, int timeout, int status)196     public void onConnectionUpdated(BluetoothGatt gatt, int interval, int latency, int timeout,
197             int status) {
198     }
199 
200     /**
201      * Callback indicating service changed event is received
202      *
203      * <p>Receiving this event means that the GATT database is out of sync with
204      * the remote device. {@link BluetoothGatt#discoverServices} should be
205      * called to re-discover the services.
206      *
207      * @param gatt GATT client involved
208      */
onServiceChanged(@onNull BluetoothGatt gatt)209     public void onServiceChanged(@NonNull BluetoothGatt gatt) {
210     }
211 }
212