Home | History | Annotate | Download | only in bluetooth
      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}, {@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.
     35      */
     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}, {@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.
     49      */
     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. {@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}
     62      */
     63     public void onConnectionStateChange(BluetoothGatt gatt, int status,
     64             int newState) {
     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}
     72      * @param status {@link BluetoothGatt#GATT_SUCCESS} if the remote device has been explored
     73      * successfully.
     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}
     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.
     85      */
     86     public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic,
     87             int status) {
     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}
    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.
    103      */
    104     public void onCharacteristicWrite(BluetoothGatt gatt,
    105             BluetoothGattCharacteristic characteristic, int status) {
    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
    112      * @param characteristic Characteristic that has been updated as a result of a remote
    113      * notification event.
    114      */
    115     public void onCharacteristicChanged(BluetoothGatt gatt,
    116             BluetoothGattCharacteristic characteristic) {
    117     }
    118 
    119     /**
    120      * Callback reporting the result of a descriptor read operation.
    121      *
    122      * @param gatt GATT client invoked {@link BluetoothGatt#readDescriptor}
    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
    126      */
    127     public void onDescriptorRead(BluetoothGatt gatt, BluetoothGattDescriptor descriptor,
    128             int status) {
    129     }
    130 
    131     /**
    132      * Callback indicating the result of a descriptor write operation.
    133      *
    134      * @param gatt GATT client invoked {@link BluetoothGatt#writeDescriptor}
    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.
    138      */
    139     public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor,
    140             int status) {
    141     }
    142 
    143     /**
    144      * Callback invoked when a reliable write transaction has been completed.
    145      *
    146      * @param gatt GATT client invoked {@link BluetoothGatt#executeReliableWrite}
    147      * @param status {@link BluetoothGatt#GATT_SUCCESS} if the reliable write transaction was
    148      * executed successfully
    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     }
    179 
    180     /**
    181      * Callback indicating the connection parameters were updated.
    182      *
    183      * @param gatt GATT client involved
    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)
    190      * @param status {@link BluetoothGatt#GATT_SUCCESS} if the connection has been updated
    191      * successfully
    192      * @hide
    193      */
    194     public void onConnectionUpdated(BluetoothGatt gatt, int interval, int latency, int timeout,
    195             int status) {
    196     }
    197 }
    198