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 /** 20 * This abstract class is used to implement {@link BluetoothGatt} callbacks. 21 */ 22 public abstract class BluetoothGattCallback{ 23 24 /** 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 29 * @param txPhy the transmitter PHY in use. One of {@link BluetoothDevice#PHY_LE_1M}, 30 * {@link 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}, 32 * {@link BluetoothDevice#PHY_LE_2M}, and {@link BluetoothDevice#PHY_LE_CODED}. 33 * @param status Status of the PHY update operation. 34 * {@link BluetoothGatt#GATT_SUCCESS} if the operation succeeds. 35 */ onPhyUpdate(BluetoothGatt gatt, int txPhy, int rxPhy, int status)36 public void onPhyUpdate(BluetoothGatt gatt, int txPhy, int rxPhy, int status) { 37 } 38 39 /** 40 * Callback triggered as result of {@link BluetoothGatt#readPhy} 41 * 42 * @param gatt GATT client 43 * @param txPhy the transmitter PHY in use. One of {@link BluetoothDevice#PHY_LE_1M}, 44 * {@link 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}, 46 * {@link BluetoothDevice#PHY_LE_2M}, and {@link BluetoothDevice#PHY_LE_CODED}. 47 * @param status Status of the PHY read operation. 48 * {@link BluetoothGatt#GATT_SUCCESS} if the operation succeeds. 49 */ onPhyRead(BluetoothGatt gatt, int txPhy, int rxPhy, int status)50 public void onPhyRead(BluetoothGatt gatt, int txPhy, int rxPhy, int status) { 51 } 52 53 /** 54 * Callback indicating when GATT client has connected/disconnected to/from a remote 55 * GATT server. 56 * 57 * @param gatt GATT client 58 * @param status Status of the connect or disconnect operation. 59 * {@link BluetoothGatt#GATT_SUCCESS} if the operation succeeds. 60 * @param newState Returns the new connection state. Can be one of 61 * {@link BluetoothProfile#STATE_DISCONNECTED} or 62 * {@link BluetoothProfile#STATE_CONNECTED} 63 */ onConnectionStateChange(BluetoothGatt gatt, int status, int newState)64 public void onConnectionStateChange(BluetoothGatt gatt, int status, 65 int newState) { 66 } 67 68 /** 69 * Callback invoked when the list of remote services, characteristics and descriptors 70 * for the remote device have been updated, ie new services have been discovered. 71 * 72 * @param gatt GATT client invoked {@link BluetoothGatt#discoverServices} 73 * @param status {@link BluetoothGatt#GATT_SUCCESS} if the remote device 74 * has been explored successfully. 75 */ onServicesDiscovered(BluetoothGatt gatt, int status)76 public void onServicesDiscovered(BluetoothGatt gatt, int status) { 77 } 78 79 /** 80 * Callback reporting the result of a characteristic read operation. 81 * 82 * @param gatt GATT client invoked {@link BluetoothGatt#readCharacteristic} 83 * @param characteristic Characteristic that was read from the associated 84 * remote device. 85 * @param status {@link BluetoothGatt#GATT_SUCCESS} if the read operation 86 * was completed 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 103 * remote device. 104 * @param status The result of the write operation 105 * {@link BluetoothGatt#GATT_SUCCESS} if the operation succeeds. 106 */ onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status)107 public void onCharacteristicWrite(BluetoothGatt gatt, 108 BluetoothGattCharacteristic characteristic, int status) { 109 } 110 111 /** 112 * Callback triggered as a result of a remote characteristic notification. 113 * 114 * @param gatt GATT client the characteristic is associated with 115 * @param characteristic Characteristic that has been updated as a result 116 * of a remote notification event. 117 */ onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic)118 public void onCharacteristicChanged(BluetoothGatt gatt, 119 BluetoothGattCharacteristic characteristic) { 120 } 121 122 /** 123 * Callback reporting the result of a descriptor read operation. 124 * 125 * @param gatt GATT client invoked {@link BluetoothGatt#readDescriptor} 126 * @param descriptor Descriptor that was read from the associated 127 * remote device. 128 * @param status {@link BluetoothGatt#GATT_SUCCESS} if the read operation 129 * was completed successfully 130 */ onDescriptorRead(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status)131 public void onDescriptorRead(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, 132 int status) { 133 } 134 135 /** 136 * Callback indicating the result of a descriptor write operation. 137 * 138 * @param gatt GATT client invoked {@link BluetoothGatt#writeDescriptor} 139 * @param descriptor Descriptor that was writte to the associated 140 * remote device. 141 * @param status The result of the write operation 142 * {@link BluetoothGatt#GATT_SUCCESS} if the operation succeeds. 143 */ onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status)144 public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, 145 int status) { 146 } 147 148 /** 149 * Callback invoked when a reliable write transaction has been completed. 150 * 151 * @param gatt GATT client invoked {@link BluetoothGatt#executeReliableWrite} 152 * @param status {@link BluetoothGatt#GATT_SUCCESS} if the reliable write 153 * transaction was executed successfully 154 */ onReliableWriteCompleted(BluetoothGatt gatt, int status)155 public void onReliableWriteCompleted(BluetoothGatt gatt, int status) { 156 } 157 158 /** 159 * Callback reporting the RSSI for a remote device connection. 160 * 161 * This callback is triggered in response to the 162 * {@link BluetoothGatt#readRemoteRssi} function. 163 * 164 * @param gatt GATT client invoked {@link BluetoothGatt#readRemoteRssi} 165 * @param rssi The RSSI value for the remote device 166 * @param status {@link BluetoothGatt#GATT_SUCCESS} if the RSSI was read successfully 167 */ onReadRemoteRssi(BluetoothGatt gatt, int rssi, int status)168 public void onReadRemoteRssi(BluetoothGatt gatt, int rssi, int status) { 169 } 170 171 /** 172 * Callback indicating the MTU for a given device connection has changed. 173 * 174 * This callback is triggered in response to the 175 * {@link BluetoothGatt#requestMtu} function, or in response to a connection 176 * event. 177 * 178 * @param gatt GATT client invoked {@link BluetoothGatt#requestMtu} 179 * @param mtu The new MTU size 180 * @param status {@link BluetoothGatt#GATT_SUCCESS} if the MTU has been changed successfully 181 */ onMtuChanged(BluetoothGatt gatt, int mtu, int status)182 public void onMtuChanged(BluetoothGatt gatt, int mtu, int status) { 183 } 184 185 /** 186 * Callback indicating the connection parameters were updated. 187 * 188 * @param gatt GATT client involved 189 * @param interval Connection interval used on this connection, 1.25ms unit. Valid 190 * range is from 6 (7.5ms) to 3200 (4000ms). 191 * @param latency Slave latency for the connection in number of connection events. Valid 192 * range is from 0 to 499 193 * @param timeout Supervision timeout for this connection, in 10ms unit. Valid range is 194 * from 10 (0.1s) to 3200 (32s) 195 * @param status {@link BluetoothGatt#GATT_SUCCESS} if the connection has been updated 196 * successfully 197 * @hide 198 */ onConnectionUpdated(BluetoothGatt gatt, int interval, int latency, int timeout, int status)199 public void onConnectionUpdated(BluetoothGatt gatt, int interval, int latency, int timeout, 200 int status) { 201 } 202 } 203