19908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta/* 2d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski * Copyright (C) 2017 The Android Open Source Project 39908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * 49908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * Licensed under the Apache License, Version 2.0 (the "License"); 59908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * you may not use this file except in compliance with the License. 69908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * You may obtain a copy of the License at 79908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * 89908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * http://www.apache.org/licenses/LICENSE-2.0 99908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * 109908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * Unless required by applicable law or agreed to in writing, software 119908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * distributed under the License is distributed on an "AS IS" BASIS, 129908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 139908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * See the License for the specific language governing permissions and 149908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * limitations under the License. 159908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta */ 169908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta 179908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Battapackage android.bluetooth; 189908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta 199908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta/** 209908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * This abstract class is used to implement {@link BluetoothGatt} callbacks. 219908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta */ 22a355e5efaf45a534ee6437aa4bae7d30f18c0ec2Jack Hepublic abstract class BluetoothGattCallback { 239908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta 249908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta /** 25d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski * Callback triggered as result of {@link BluetoothGatt#setPreferredPhy}, or as a result of 26d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski * remote device changing the PHY. 27d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski * 28d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski * @param gatt GATT client 29a355e5efaf45a534ee6437aa4bae7d30f18c0ec2Jack He * @param txPhy the transmitter PHY in use. One of {@link BluetoothDevice#PHY_LE_1M}, {@link 30a355e5efaf45a534ee6437aa4bae7d30f18c0ec2Jack He * BluetoothDevice#PHY_LE_2M}, and {@link BluetoothDevice#PHY_LE_CODED}. 31a355e5efaf45a534ee6437aa4bae7d30f18c0ec2Jack He * @param rxPhy the receiver PHY in use. One of {@link BluetoothDevice#PHY_LE_1M}, {@link 32a355e5efaf45a534ee6437aa4bae7d30f18c0ec2Jack He * BluetoothDevice#PHY_LE_2M}, and {@link BluetoothDevice#PHY_LE_CODED}. 33a355e5efaf45a534ee6437aa4bae7d30f18c0ec2Jack He * @param status Status of the PHY update operation. {@link BluetoothGatt#GATT_SUCCESS} if the 34a355e5efaf45a534ee6437aa4bae7d30f18c0ec2Jack He * operation succeeds. 359908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta */ 36409cee69b2b09bcd11f1273752c016116436f247Jakub Pawlowski public void onPhyUpdate(BluetoothGatt gatt, int txPhy, int rxPhy, int status) { 379908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta } 389908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta 399908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta /** 40d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski * Callback triggered as result of {@link BluetoothGatt#readPhy} 41d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski * 42d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski * @param gatt GATT client 43a355e5efaf45a534ee6437aa4bae7d30f18c0ec2Jack He * @param txPhy the transmitter PHY in use. One of {@link BluetoothDevice#PHY_LE_1M}, {@link 44a355e5efaf45a534ee6437aa4bae7d30f18c0ec2Jack He * BluetoothDevice#PHY_LE_2M}, and {@link BluetoothDevice#PHY_LE_CODED}. 45a355e5efaf45a534ee6437aa4bae7d30f18c0ec2Jack He * @param rxPhy the receiver PHY in use. One of {@link BluetoothDevice#PHY_LE_1M}, {@link 46a355e5efaf45a534ee6437aa4bae7d30f18c0ec2Jack He * BluetoothDevice#PHY_LE_2M}, and {@link BluetoothDevice#PHY_LE_CODED}. 47a355e5efaf45a534ee6437aa4bae7d30f18c0ec2Jack He * @param status Status of the PHY read operation. {@link BluetoothGatt#GATT_SUCCESS} if the 48a355e5efaf45a534ee6437aa4bae7d30f18c0ec2Jack He * operation succeeds. 499908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta */ 50409cee69b2b09bcd11f1273752c016116436f247Jakub Pawlowski public void onPhyRead(BluetoothGatt gatt, int txPhy, int rxPhy, int status) { 519908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta } 529908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta 53d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski /** 54d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski * Callback indicating when GATT client has connected/disconnected to/from a remote 55d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski * GATT server. 56d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski * 57d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski * @param gatt GATT client 58a355e5efaf45a534ee6437aa4bae7d30f18c0ec2Jack He * @param status Status of the connect or disconnect operation. {@link 59a355e5efaf45a534ee6437aa4bae7d30f18c0ec2Jack He * BluetoothGatt#GATT_SUCCESS} if the operation succeeds. 60a355e5efaf45a534ee6437aa4bae7d30f18c0ec2Jack He * @param newState Returns the new connection state. Can be one of {@link 61a355e5efaf45a534ee6437aa4bae7d30f18c0ec2Jack He * BluetoothProfile#STATE_DISCONNECTED} or {@link BluetoothProfile#STATE_CONNECTED} 62d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski */ 63d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski public void onConnectionStateChange(BluetoothGatt gatt, int status, 64a355e5efaf45a534ee6437aa4bae7d30f18c0ec2Jack He int newState) { 65d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski } 66d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski 67d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski /** 68d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski * Callback invoked when the list of remote services, characteristics and descriptors 69d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski * for the remote device have been updated, ie new services have been discovered. 70d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski * 71d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski * @param gatt GATT client invoked {@link BluetoothGatt#discoverServices} 72a355e5efaf45a534ee6437aa4bae7d30f18c0ec2Jack He * @param status {@link BluetoothGatt#GATT_SUCCESS} if the remote device has been explored 73a355e5efaf45a534ee6437aa4bae7d30f18c0ec2Jack He * successfully. 74d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski */ 75d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski public void onServicesDiscovered(BluetoothGatt gatt, int status) { 76d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski } 77d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski 78d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski /** 79d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski * Callback reporting the result of a characteristic read operation. 80d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski * 81d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski * @param gatt GATT client invoked {@link BluetoothGatt#readCharacteristic} 82a355e5efaf45a534ee6437aa4bae7d30f18c0ec2Jack He * @param characteristic Characteristic that was read from the associated remote device. 83a355e5efaf45a534ee6437aa4bae7d30f18c0ec2Jack He * @param status {@link BluetoothGatt#GATT_SUCCESS} if the read operation was completed 84a355e5efaf45a534ee6437aa4bae7d30f18c0ec2Jack He * successfully. 85d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski */ 86d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, 87a355e5efaf45a534ee6437aa4bae7d30f18c0ec2Jack He int status) { 88d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski } 89d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski 90d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski /** 91d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski * Callback indicating the result of a characteristic write operation. 92d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski * 93d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski * <p>If this callback is invoked while a reliable write transaction is 94d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski * in progress, the value of the characteristic represents the value 95d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski * reported by the remote device. An application should compare this 96d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski * value to the desired value to be written. If the values don't match, 97d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski * the application must abort the reliable write transaction. 98d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski * 99d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski * @param gatt GATT client invoked {@link BluetoothGatt#writeCharacteristic} 100a355e5efaf45a534ee6437aa4bae7d30f18c0ec2Jack He * @param characteristic Characteristic that was written to the associated remote device. 101a355e5efaf45a534ee6437aa4bae7d30f18c0ec2Jack He * @param status The result of the write operation {@link BluetoothGatt#GATT_SUCCESS} if the 102a355e5efaf45a534ee6437aa4bae7d30f18c0ec2Jack He * operation succeeds. 103d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski */ 104d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski public void onCharacteristicWrite(BluetoothGatt gatt, 105a355e5efaf45a534ee6437aa4bae7d30f18c0ec2Jack He BluetoothGattCharacteristic characteristic, int status) { 106d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski } 107d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski 108d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski /** 109d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski * Callback triggered as a result of a remote characteristic notification. 110d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski * 111d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski * @param gatt GATT client the characteristic is associated with 112a355e5efaf45a534ee6437aa4bae7d30f18c0ec2Jack He * @param characteristic Characteristic that has been updated as a result of a remote 113a355e5efaf45a534ee6437aa4bae7d30f18c0ec2Jack He * notification event. 114d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski */ 115d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski public void onCharacteristicChanged(BluetoothGatt gatt, 116a355e5efaf45a534ee6437aa4bae7d30f18c0ec2Jack He BluetoothGattCharacteristic characteristic) { 117d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski } 118d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski 119d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski /** 120d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski * Callback reporting the result of a descriptor read operation. 121d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski * 122d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski * @param gatt GATT client invoked {@link BluetoothGatt#readDescriptor} 123a355e5efaf45a534ee6437aa4bae7d30f18c0ec2Jack He * @param descriptor Descriptor that was read from the associated remote device. 124a355e5efaf45a534ee6437aa4bae7d30f18c0ec2Jack He * @param status {@link BluetoothGatt#GATT_SUCCESS} if the read operation was completed 125a355e5efaf45a534ee6437aa4bae7d30f18c0ec2Jack He * successfully 126d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski */ 127d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski public void onDescriptorRead(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, 128a355e5efaf45a534ee6437aa4bae7d30f18c0ec2Jack He int status) { 129d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski } 130d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski 131d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski /** 132d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski * Callback indicating the result of a descriptor write operation. 133d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski * 134d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski * @param gatt GATT client invoked {@link BluetoothGatt#writeDescriptor} 135a355e5efaf45a534ee6437aa4bae7d30f18c0ec2Jack He * @param descriptor Descriptor that was writte to the associated remote device. 136a355e5efaf45a534ee6437aa4bae7d30f18c0ec2Jack He * @param status The result of the write operation {@link BluetoothGatt#GATT_SUCCESS} if the 137a355e5efaf45a534ee6437aa4bae7d30f18c0ec2Jack He * operation succeeds. 138d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski */ 139d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, 140a355e5efaf45a534ee6437aa4bae7d30f18c0ec2Jack He int status) { 141d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski } 142d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski 143d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski /** 144d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski * Callback invoked when a reliable write transaction has been completed. 145d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski * 146d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski * @param gatt GATT client invoked {@link BluetoothGatt#executeReliableWrite} 147a355e5efaf45a534ee6437aa4bae7d30f18c0ec2Jack He * @param status {@link BluetoothGatt#GATT_SUCCESS} if the reliable write transaction was 148a355e5efaf45a534ee6437aa4bae7d30f18c0ec2Jack He * executed successfully 149d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski */ 150d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski public void onReliableWriteCompleted(BluetoothGatt gatt, int status) { 151d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski } 152d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski 153d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski /** 154d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski * Callback reporting the RSSI for a remote device connection. 155d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski * 156d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski * This callback is triggered in response to the 157d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski * {@link BluetoothGatt#readRemoteRssi} function. 158d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski * 159d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski * @param gatt GATT client invoked {@link BluetoothGatt#readRemoteRssi} 160d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski * @param rssi The RSSI value for the remote device 161d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski * @param status {@link BluetoothGatt#GATT_SUCCESS} if the RSSI was read successfully 162d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski */ 163d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski public void onReadRemoteRssi(BluetoothGatt gatt, int rssi, int status) { 164d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski } 165d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski 166d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski /** 167d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski * Callback indicating the MTU for a given device connection has changed. 168d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski * 169d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski * This callback is triggered in response to the 170d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski * {@link BluetoothGatt#requestMtu} function, or in response to a connection 171d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski * event. 172d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski * 173d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski * @param gatt GATT client invoked {@link BluetoothGatt#requestMtu} 174d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski * @param mtu The new MTU size 175d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski * @param status {@link BluetoothGatt#GATT_SUCCESS} if the MTU has been changed successfully 176d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski */ 177d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski public void onMtuChanged(BluetoothGatt gatt, int mtu, int status) { 178d64bb883d822e1db445e09e77150ffd281e83cbeJakub Pawlowski } 179326f7b31b9ab7bf82e3c05f9b606d10ece306dc0Jakub Pawlowski 180326f7b31b9ab7bf82e3c05f9b606d10ece306dc0Jakub Pawlowski /** 181326f7b31b9ab7bf82e3c05f9b606d10ece306dc0Jakub Pawlowski * Callback indicating the connection parameters were updated. 182326f7b31b9ab7bf82e3c05f9b606d10ece306dc0Jakub Pawlowski * 183326f7b31b9ab7bf82e3c05f9b606d10ece306dc0Jakub Pawlowski * @param gatt GATT client involved 184a355e5efaf45a534ee6437aa4bae7d30f18c0ec2Jack He * @param interval Connection interval used on this connection, 1.25ms unit. Valid range is from 185a355e5efaf45a534ee6437aa4bae7d30f18c0ec2Jack He * 6 (7.5ms) to 3200 (4000ms). 186a355e5efaf45a534ee6437aa4bae7d30f18c0ec2Jack He * @param latency Slave latency for the connection in number of connection events. Valid range 187a355e5efaf45a534ee6437aa4bae7d30f18c0ec2Jack He * is from 0 to 499 188a355e5efaf45a534ee6437aa4bae7d30f18c0ec2Jack He * @param timeout Supervision timeout for this connection, in 10ms unit. Valid range is from 10 189a355e5efaf45a534ee6437aa4bae7d30f18c0ec2Jack He * (0.1s) to 3200 (32s) 190326f7b31b9ab7bf82e3c05f9b606d10ece306dc0Jakub Pawlowski * @param status {@link BluetoothGatt#GATT_SUCCESS} if the connection has been updated 191a355e5efaf45a534ee6437aa4bae7d30f18c0ec2Jack He * successfully 192326f7b31b9ab7bf82e3c05f9b606d10ece306dc0Jakub Pawlowski * @hide 193326f7b31b9ab7bf82e3c05f9b606d10ece306dc0Jakub Pawlowski */ 194326f7b31b9ab7bf82e3c05f9b606d10ece306dc0Jakub Pawlowski public void onConnectionUpdated(BluetoothGatt gatt, int interval, int latency, int timeout, 195a355e5efaf45a534ee6437aa4bae7d30f18c0ec2Jack He int status) { 196326f7b31b9ab7bf82e3c05f9b606d10ece306dc0Jakub Pawlowski } 1979908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta} 198