Ganesh Ganapathi Batta | 9908112 | 2013-02-05 15:28:33 -0800 | [diff] [blame] | 1 | /* |
Jakub Pawlowski | d64bb88 | 2017-03-22 11:22:18 -0700 | [diff] [blame] | 2 | * Copyright (C) 2017 The Android Open Source Project |
Ganesh Ganapathi Batta | 9908112 | 2013-02-05 15:28:33 -0800 | [diff] [blame] | 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 | |
Ganesh Ganapathi Batta | 9908112 | 2013-02-05 15:28:33 -0800 | [diff] [blame] | 19 | /** |
| 20 | * This abstract class is used to implement {@link BluetoothGatt} callbacks. |
Ganesh Ganapathi Batta | 9908112 | 2013-02-05 15:28:33 -0800 | [diff] [blame] | 21 | */ |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 22 | public abstract class BluetoothGattCallback { |
Ganesh Ganapathi Batta | 9908112 | 2013-02-05 15:28:33 -0800 | [diff] [blame] | 23 | |
| 24 | /** |
Jakub Pawlowski | d64bb88 | 2017-03-22 11:22:18 -0700 | [diff] [blame] | 25 | * Callback triggered as result of {@link BluetoothGatt#setPreferredPhy}, or as a result of |
| 26 | * remote device changing the PHY. |
| 27 | * |
| 28 | * @param gatt GATT client |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 29 | * @param txPhy the transmitter PHY in use. One of {@link BluetoothDevice#PHY_LE_1M}, {@link |
| 30 | * BluetoothDevice#PHY_LE_2M}, and {@link BluetoothDevice#PHY_LE_CODED}. |
| 31 | * @param rxPhy the receiver PHY in use. One of {@link BluetoothDevice#PHY_LE_1M}, {@link |
| 32 | * BluetoothDevice#PHY_LE_2M}, and {@link BluetoothDevice#PHY_LE_CODED}. |
| 33 | * @param status Status of the PHY update operation. {@link BluetoothGatt#GATT_SUCCESS} if the |
| 34 | * operation succeeds. |
Ganesh Ganapathi Batta | 9908112 | 2013-02-05 15:28:33 -0800 | [diff] [blame] | 35 | */ |
Jakub Pawlowski | 409cee6 | 2017-02-02 08:07:12 -0800 | [diff] [blame] | 36 | public void onPhyUpdate(BluetoothGatt gatt, int txPhy, int rxPhy, int status) { |
Ganesh Ganapathi Batta | 9908112 | 2013-02-05 15:28:33 -0800 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | /** |
Jakub Pawlowski | d64bb88 | 2017-03-22 11:22:18 -0700 | [diff] [blame] | 40 | * Callback triggered as result of {@link BluetoothGatt#readPhy} |
| 41 | * |
| 42 | * @param gatt GATT client |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 43 | * @param txPhy the transmitter PHY in use. One of {@link BluetoothDevice#PHY_LE_1M}, {@link |
| 44 | * BluetoothDevice#PHY_LE_2M}, and {@link BluetoothDevice#PHY_LE_CODED}. |
| 45 | * @param rxPhy the receiver PHY in use. One of {@link BluetoothDevice#PHY_LE_1M}, {@link |
| 46 | * BluetoothDevice#PHY_LE_2M}, and {@link BluetoothDevice#PHY_LE_CODED}. |
| 47 | * @param status Status of the PHY read operation. {@link BluetoothGatt#GATT_SUCCESS} if the |
| 48 | * operation succeeds. |
Ganesh Ganapathi Batta | 9908112 | 2013-02-05 15:28:33 -0800 | [diff] [blame] | 49 | */ |
Jakub Pawlowski | 409cee6 | 2017-02-02 08:07:12 -0800 | [diff] [blame] | 50 | public void onPhyRead(BluetoothGatt gatt, int txPhy, int rxPhy, int status) { |
Ganesh Ganapathi Batta | 9908112 | 2013-02-05 15:28:33 -0800 | [diff] [blame] | 51 | } |
| 52 | |
Jakub Pawlowski | d64bb88 | 2017-03-22 11:22:18 -0700 | [diff] [blame] | 53 | /** |
| 54 | * Callback indicating when GATT client has connected/disconnected to/from a remote |
| 55 | * GATT server. |
| 56 | * |
| 57 | * @param gatt GATT client |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 58 | * @param status Status of the connect or disconnect operation. {@link |
| 59 | * BluetoothGatt#GATT_SUCCESS} if the operation succeeds. |
| 60 | * @param newState Returns the new connection state. Can be one of {@link |
| 61 | * BluetoothProfile#STATE_DISCONNECTED} or {@link BluetoothProfile#STATE_CONNECTED} |
Jakub Pawlowski | d64bb88 | 2017-03-22 11:22:18 -0700 | [diff] [blame] | 62 | */ |
| 63 | public void onConnectionStateChange(BluetoothGatt gatt, int status, |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 64 | int newState) { |
Jakub Pawlowski | d64bb88 | 2017-03-22 11:22:18 -0700 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Callback invoked when the list of remote services, characteristics and descriptors |
| 69 | * for the remote device have been updated, ie new services have been discovered. |
| 70 | * |
| 71 | * @param gatt GATT client invoked {@link BluetoothGatt#discoverServices} |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 72 | * @param status {@link BluetoothGatt#GATT_SUCCESS} if the remote device has been explored |
| 73 | * successfully. |
Jakub Pawlowski | d64bb88 | 2017-03-22 11:22:18 -0700 | [diff] [blame] | 74 | */ |
| 75 | public void onServicesDiscovered(BluetoothGatt gatt, int status) { |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Callback reporting the result of a characteristic read operation. |
| 80 | * |
| 81 | * @param gatt GATT client invoked {@link BluetoothGatt#readCharacteristic} |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 82 | * @param characteristic Characteristic that was read from the associated remote device. |
| 83 | * @param status {@link BluetoothGatt#GATT_SUCCESS} if the read operation was completed |
| 84 | * successfully. |
Jakub Pawlowski | d64bb88 | 2017-03-22 11:22:18 -0700 | [diff] [blame] | 85 | */ |
| 86 | public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 87 | int status) { |
Jakub Pawlowski | d64bb88 | 2017-03-22 11:22:18 -0700 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | /** |
| 91 | * Callback indicating the result of a characteristic write operation. |
| 92 | * |
| 93 | * <p>If this callback is invoked while a reliable write transaction is |
| 94 | * in progress, the value of the characteristic represents the value |
| 95 | * reported by the remote device. An application should compare this |
| 96 | * value to the desired value to be written. If the values don't match, |
| 97 | * the application must abort the reliable write transaction. |
| 98 | * |
| 99 | * @param gatt GATT client invoked {@link BluetoothGatt#writeCharacteristic} |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 100 | * @param characteristic Characteristic that was written to the associated remote device. |
| 101 | * @param status The result of the write operation {@link BluetoothGatt#GATT_SUCCESS} if the |
| 102 | * operation succeeds. |
Jakub Pawlowski | d64bb88 | 2017-03-22 11:22:18 -0700 | [diff] [blame] | 103 | */ |
| 104 | public void onCharacteristicWrite(BluetoothGatt gatt, |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 105 | BluetoothGattCharacteristic characteristic, int status) { |
Jakub Pawlowski | d64bb88 | 2017-03-22 11:22:18 -0700 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | /** |
| 109 | * Callback triggered as a result of a remote characteristic notification. |
| 110 | * |
| 111 | * @param gatt GATT client the characteristic is associated with |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 112 | * @param characteristic Characteristic that has been updated as a result of a remote |
| 113 | * notification event. |
Jakub Pawlowski | d64bb88 | 2017-03-22 11:22:18 -0700 | [diff] [blame] | 114 | */ |
| 115 | public void onCharacteristicChanged(BluetoothGatt gatt, |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 116 | BluetoothGattCharacteristic characteristic) { |
Jakub Pawlowski | d64bb88 | 2017-03-22 11:22:18 -0700 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | /** |
| 120 | * Callback reporting the result of a descriptor read operation. |
| 121 | * |
| 122 | * @param gatt GATT client invoked {@link BluetoothGatt#readDescriptor} |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 123 | * @param descriptor Descriptor that was read from the associated remote device. |
| 124 | * @param status {@link BluetoothGatt#GATT_SUCCESS} if the read operation was completed |
| 125 | * successfully |
Jakub Pawlowski | d64bb88 | 2017-03-22 11:22:18 -0700 | [diff] [blame] | 126 | */ |
| 127 | public void onDescriptorRead(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 128 | int status) { |
Jakub Pawlowski | d64bb88 | 2017-03-22 11:22:18 -0700 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | /** |
| 132 | * Callback indicating the result of a descriptor write operation. |
| 133 | * |
| 134 | * @param gatt GATT client invoked {@link BluetoothGatt#writeDescriptor} |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 135 | * @param descriptor Descriptor that was writte to the associated remote device. |
| 136 | * @param status The result of the write operation {@link BluetoothGatt#GATT_SUCCESS} if the |
| 137 | * operation succeeds. |
Jakub Pawlowski | d64bb88 | 2017-03-22 11:22:18 -0700 | [diff] [blame] | 138 | */ |
| 139 | public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 140 | int status) { |
Jakub Pawlowski | d64bb88 | 2017-03-22 11:22:18 -0700 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | /** |
| 144 | * Callback invoked when a reliable write transaction has been completed. |
| 145 | * |
| 146 | * @param gatt GATT client invoked {@link BluetoothGatt#executeReliableWrite} |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 147 | * @param status {@link BluetoothGatt#GATT_SUCCESS} if the reliable write transaction was |
| 148 | * executed successfully |
Jakub Pawlowski | d64bb88 | 2017-03-22 11:22:18 -0700 | [diff] [blame] | 149 | */ |
| 150 | public void onReliableWriteCompleted(BluetoothGatt gatt, int status) { |
| 151 | } |
| 152 | |
| 153 | /** |
| 154 | * Callback reporting the RSSI for a remote device connection. |
| 155 | * |
| 156 | * This callback is triggered in response to the |
| 157 | * {@link BluetoothGatt#readRemoteRssi} function. |
| 158 | * |
| 159 | * @param gatt GATT client invoked {@link BluetoothGatt#readRemoteRssi} |
| 160 | * @param rssi The RSSI value for the remote device |
| 161 | * @param status {@link BluetoothGatt#GATT_SUCCESS} if the RSSI was read successfully |
| 162 | */ |
| 163 | public void onReadRemoteRssi(BluetoothGatt gatt, int rssi, int status) { |
| 164 | } |
| 165 | |
| 166 | /** |
| 167 | * Callback indicating the MTU for a given device connection has changed. |
| 168 | * |
| 169 | * This callback is triggered in response to the |
| 170 | * {@link BluetoothGatt#requestMtu} function, or in response to a connection |
| 171 | * event. |
| 172 | * |
| 173 | * @param gatt GATT client invoked {@link BluetoothGatt#requestMtu} |
| 174 | * @param mtu The new MTU size |
| 175 | * @param status {@link BluetoothGatt#GATT_SUCCESS} if the MTU has been changed successfully |
| 176 | */ |
| 177 | public void onMtuChanged(BluetoothGatt gatt, int mtu, int status) { |
| 178 | } |
Jakub Pawlowski | 326f7b3 | 2017-03-23 19:05:55 -0700 | [diff] [blame] | 179 | |
| 180 | /** |
| 181 | * Callback indicating the connection parameters were updated. |
| 182 | * |
| 183 | * @param gatt GATT client involved |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 184 | * @param interval Connection interval used on this connection, 1.25ms unit. Valid range is from |
| 185 | * 6 (7.5ms) to 3200 (4000ms). |
| 186 | * @param latency Slave latency for the connection in number of connection events. Valid range |
| 187 | * is from 0 to 499 |
| 188 | * @param timeout Supervision timeout for this connection, in 10ms unit. Valid range is from 10 |
| 189 | * (0.1s) to 3200 (32s) |
Jakub Pawlowski | 326f7b3 | 2017-03-23 19:05:55 -0700 | [diff] [blame] | 190 | * @param status {@link BluetoothGatt#GATT_SUCCESS} if the connection has been updated |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 191 | * successfully |
Jakub Pawlowski | 326f7b3 | 2017-03-23 19:05:55 -0700 | [diff] [blame] | 192 | * @hide |
| 193 | */ |
| 194 | public void onConnectionUpdated(BluetoothGatt gatt, int interval, int latency, int timeout, |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 195 | int status) { |
Jakub Pawlowski | 326f7b3 | 2017-03-23 19:05:55 -0700 | [diff] [blame] | 196 | } |
Ganesh Ganapathi Batta | 9908112 | 2013-02-05 15:28:33 -0800 | [diff] [blame] | 197 | } |