19908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta/*
29908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * Copyright (C) 2013 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 Battaimport android.bluetooth.BluetoothDevice;
209908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta
219908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta/**
229908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * This abstract class is used to implement {@link BluetoothGattServer} callbacks.
239908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta */
249908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Battapublic abstract class BluetoothGattServerCallback {
259908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta
269908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    /**
279908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * Callback indicating when a remote device has been connected or disconnected.
289908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     *
299908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * @param device Remote device that has been connected or disconnected.
309908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * @param status Status of the connect or disconnect operation.
319908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * @param newState Returns the new connection state. Can be one of
329908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     *                  {@link BluetoothProfile#STATE_DISCONNECTED} or
339908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     *                  {@link BluetoothProfile#STATE_CONNECTED}
349908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     */
359908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    public void onConnectionStateChange(BluetoothDevice device, int status,
369908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta                                        int newState) {
379908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    }
389908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta
399908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    /**
409908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * Indicates whether a local service has been added successfully.
419908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     *
429908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * @param status Returns {@link BluetoothGatt#GATT_SUCCESS} if the service
439908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     *               was added successfully.
449908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * @param service The service that has been added
459908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     */
469908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    public void onServiceAdded(int status, BluetoothGattService service) {
479908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    }
489908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta
499908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    /**
509908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * A remote client has requested to read a local characteristic.
519908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     *
529908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * <p>An application must call {@link BluetoothGattServer#sendResponse}
539908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * to complete the request.
549908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     *
559908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * @param device The remote device that has requested the read operation
569908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * @param requestId The Id of the request
579908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * @param offset Offset into the value of the characteristic
589908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * @param characteristic Characteristic to be read
599908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     */
609908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    public void onCharacteristicReadRequest(BluetoothDevice device, int requestId,
619908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta                        int offset, BluetoothGattCharacteristic characteristic) {
629908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    }
639908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta
649908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    /**
659908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * A remote client has requested to write to a local characteristic.
669908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     *
679908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * <p>An application must call {@link BluetoothGattServer#sendResponse}
689908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * to complete the request.
699908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     *
709908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * @param device The remote device that has requested the write operation
719908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * @param requestId The Id of the request
729908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * @param characteristic Characteristic to be written to.
739908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * @param preparedWrite true, if this write operation should be queued for
749908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     *                      later execution.
759908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * @param responseNeeded true, if the remote device requires a response
769908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * @param offset The offset given for the value
779908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * @param value The value the client wants to assign to the characteristic
789908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     */
799908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    public void onCharacteristicWriteRequest(BluetoothDevice device, int requestId,
80ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie                                             BluetoothGattCharacteristic characteristic,
81ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie                                             boolean preparedWrite, boolean responseNeeded,
82ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie                                             int offset, byte[] value) {
839908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    }
849908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta
859908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    /**
869908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * A remote client has requested to read a local descriptor.
879908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     *
889908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * <p>An application must call {@link BluetoothGattServer#sendResponse}
899908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * to complete the request.
909908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     *
919908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * @param device The remote device that has requested the read operation
929908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * @param requestId The Id of the request
939908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * @param offset Offset into the value of the characteristic
949908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * @param descriptor Descriptor to be read
959908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     */
969908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    public void onDescriptorReadRequest(BluetoothDevice device, int requestId,
97ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie                                        int offset, BluetoothGattDescriptor descriptor) {
989908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    }
999908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta
1009908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    /**
1019908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * A remote client has requested to write to a local descriptor.
1029908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     *
1039908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * <p>An application must call {@link BluetoothGattServer#sendResponse}
1049908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * to complete the request.
1059908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     *
1069908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * @param device The remote device that has requested the write operation
1079908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * @param requestId The Id of the request
1089908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * @param descriptor Descriptor to be written to.
1099908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * @param preparedWrite true, if this write operation should be queued for
1109908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     *                      later execution.
1119908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * @param responseNeeded true, if the remote device requires a response
1129908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * @param offset The offset given for the value
1139908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * @param value The value the client wants to assign to the descriptor
1149908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     */
1159908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    public void onDescriptorWriteRequest(BluetoothDevice device, int requestId,
116ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie                                         BluetoothGattDescriptor descriptor,
117ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie                                         boolean preparedWrite, boolean responseNeeded,
118ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie                                         int offset,  byte[] value) {
1199908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    }
1209908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta
1219908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    /**
1229908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * Execute all pending write operations for this device.
1239908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     *
1249908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * <p>An application must call {@link BluetoothGattServer#sendResponse}
1259908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * to complete the request.
1269908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     *
1279908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * @param device The remote device that has requested the write operations
1289908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * @param requestId The Id of the request
1299908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * @param execute Whether the pending writes should be executed (true) or
1309908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     *                cancelled (false)
1319908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     */
1329908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    public void onExecuteWrite(BluetoothDevice device, int requestId, boolean execute) {
1339908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    }
134dadefdad8ef424991feb45f02f923a2f8224285bAndre Eisenbach
135dadefdad8ef424991feb45f02f923a2f8224285bAndre Eisenbach    /**
136dadefdad8ef424991feb45f02f923a2f8224285bAndre Eisenbach     * Callback invoked when a notification or indication has been sent to
137dadefdad8ef424991feb45f02f923a2f8224285bAndre Eisenbach     * a remote device.
138dadefdad8ef424991feb45f02f923a2f8224285bAndre Eisenbach     *
139dadefdad8ef424991feb45f02f923a2f8224285bAndre Eisenbach     * <p>When multiple notifications are to be sent, an application must
140dadefdad8ef424991feb45f02f923a2f8224285bAndre Eisenbach     * wait for this callback to be received before sending additional
141dadefdad8ef424991feb45f02f923a2f8224285bAndre Eisenbach     * notifications.
142dadefdad8ef424991feb45f02f923a2f8224285bAndre Eisenbach     *
143dadefdad8ef424991feb45f02f923a2f8224285bAndre Eisenbach     * @param device The remote device the notification has been sent to
1444072da041da2911dd56635b530b276671ce0199dAndre Eisenbach     * @param status {@link BluetoothGatt#GATT_SUCCESS} if the operation was successful
145dadefdad8ef424991feb45f02f923a2f8224285bAndre Eisenbach     */
146dadefdad8ef424991feb45f02f923a2f8224285bAndre Eisenbach    public void onNotificationSent(BluetoothDevice device, int status) {
147dadefdad8ef424991feb45f02f923a2f8224285bAndre Eisenbach    }
1489908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta}
149