Home | History | Annotate | Download | only in bluetooth
      1 /*
      2  * Copyright (C) 2013 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.bluetooth.BluetoothDevice;
     20 
     21 /**
     22  * This abstract class is used to implement {@link BluetoothGattServer} callbacks.
     23  */
     24 public abstract class BluetoothGattServerCallback {
     25 
     26     /**
     27      * Callback indicating when a remote device has been connected or disconnected.
     28      *
     29      * @param device Remote device that has been connected or disconnected.
     30      * @param status Status of the connect or disconnect operation.
     31      * @param newState Returns the new connection state. Can be one of
     32      *                  {@link BluetoothProfile#STATE_DISCONNECTED} or
     33      *                  {@link BluetoothProfile#STATE_CONNECTED}
     34      */
     35     public void onConnectionStateChange(BluetoothDevice device, int status,
     36                                         int newState) {
     37     }
     38 
     39     /**
     40      * Indicates whether a local service has been added successfully.
     41      *
     42      * @param status Returns {@link BluetoothGatt#GATT_SUCCESS} if the service
     43      *               was added successfully.
     44      * @param service The service that has been added
     45      */
     46     public void onServiceAdded(int status, BluetoothGattService service) {
     47     }
     48 
     49     /**
     50      * A remote client has requested to read a local characteristic.
     51      *
     52      * <p>An application must call {@link BluetoothGattServer#sendResponse}
     53      * to complete the request.
     54      *
     55      * @param device The remote device that has requested the read operation
     56      * @param requestId The Id of the request
     57      * @param offset Offset into the value of the characteristic
     58      * @param characteristic Characteristic to be read
     59      */
     60     public void onCharacteristicReadRequest(BluetoothDevice device, int requestId,
     61                         int offset, BluetoothGattCharacteristic characteristic) {
     62     }
     63 
     64     /**
     65      * A remote client has requested to write to a local characteristic.
     66      *
     67      * <p>An application must call {@link BluetoothGattServer#sendResponse}
     68      * to complete the request.
     69      *
     70      * @param device The remote device that has requested the write operation
     71      * @param requestId The Id of the request
     72      * @param characteristic Characteristic to be written to.
     73      * @param preparedWrite true, if this write operation should be queued for
     74      *                      later execution.
     75      * @param responseNeeded true, if the remote device requires a response
     76      * @param offset The offset given for the value
     77      * @param value The value the client wants to assign to the characteristic
     78      */
     79     public void onCharacteristicWriteRequest(BluetoothDevice device, int requestId,
     80                                              BluetoothGattCharacteristic characteristic,
     81                                              boolean preparedWrite, boolean responseNeeded,
     82                                              int offset, byte[] value) {
     83     }
     84 
     85     /**
     86      * A remote client has requested to read a local descriptor.
     87      *
     88      * <p>An application must call {@link BluetoothGattServer#sendResponse}
     89      * to complete the request.
     90      *
     91      * @param device The remote device that has requested the read operation
     92      * @param requestId The Id of the request
     93      * @param offset Offset into the value of the characteristic
     94      * @param descriptor Descriptor to be read
     95      */
     96     public void onDescriptorReadRequest(BluetoothDevice device, int requestId,
     97                                         int offset, BluetoothGattDescriptor descriptor) {
     98     }
     99 
    100     /**
    101      * A remote client has requested to write to a local descriptor.
    102      *
    103      * <p>An application must call {@link BluetoothGattServer#sendResponse}
    104      * to complete the request.
    105      *
    106      * @param device The remote device that has requested the write operation
    107      * @param requestId The Id of the request
    108      * @param descriptor Descriptor to be written to.
    109      * @param preparedWrite true, if this write operation should be queued for
    110      *                      later execution.
    111      * @param responseNeeded true, if the remote device requires a response
    112      * @param offset The offset given for the value
    113      * @param value The value the client wants to assign to the descriptor
    114      */
    115     public void onDescriptorWriteRequest(BluetoothDevice device, int requestId,
    116                                          BluetoothGattDescriptor descriptor,
    117                                          boolean preparedWrite, boolean responseNeeded,
    118                                          int offset,  byte[] value) {
    119     }
    120 
    121     /**
    122      * Execute all pending write operations for this device.
    123      *
    124      * <p>An application must call {@link BluetoothGattServer#sendResponse}
    125      * to complete the request.
    126      *
    127      * @param device The remote device that has requested the write operations
    128      * @param requestId The Id of the request
    129      * @param execute Whether the pending writes should be executed (true) or
    130      *                cancelled (false)
    131      */
    132     public void onExecuteWrite(BluetoothDevice device, int requestId, boolean execute) {
    133     }
    134 
    135     /**
    136      * Callback invoked when a notification or indication has been sent to
    137      * a remote device.
    138      *
    139      * <p>When multiple notifications are to be sent, an application must
    140      * wait for this callback to be received before sending additional
    141      * notifications.
    142      *
    143      * @param device The remote device the notification has been sent to
    144      * @param status {@link BluetoothGatt#GATT_SUCCESS} if the operation was successful
    145      */
    146     public void onNotificationSent(BluetoothDevice device, int status) {
    147     }
    148 
    149     /**
    150      * Callback indicating the MTU for a given device connection has changed.
    151      *
    152      * <p>This callback will be invoked if a remote client has requested to change
    153      * the MTU for a given connection.
    154      *
    155      * @param device The remote device that requested the MTU change
    156      * @param mtu The new MTU size
    157      */
    158     public void onMtuChanged(BluetoothDevice device, int mtu) {
    159     }
    160 }
    161