BluetoothGattServerCallback.java revision 9908112fd085d8b0d91e0562d32eebd1884f09a5
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 Battaimport android.util.Log; 229908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta 239908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta/** 249908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * This abstract class is used to implement {@link BluetoothGattServer} callbacks. 259908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * @hide 269908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta */ 279908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Battapublic abstract class BluetoothGattServerCallback { 289908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta /** 299908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * Callback to inform change in registration state of the application. 309908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * 319908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * @param status Returns {@link BluetoothGatt#GATT_SUCCESS} if the application 329908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * was successfully registered. 339908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta */ 349908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta public void onAppRegistered(int status) { 359908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta } 369908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta 379908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta /** 389908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * Callback reporting an LE device found during a device scan initiated 399908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * by the {@link BluetoothGattServer#startScan} function. 409908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * 419908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * @param device Identifies the remote device 429908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * @param rssi The RSSI value for the remote device as reported by the 439908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * Bluetooth hardware. 0 if no RSSI value is available. 449908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * @param scanRecord The content of the advertisement record offered by 459908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * the remote device. 469908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta */ 479908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta public void onScanResult(BluetoothDevice device, int rssi, byte[] scanRecord) { 489908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta } 499908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta 509908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta /** 519908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * Callback indicating when a remote device has been connected or disconnected. 529908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * 539908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * @param device Remote device that has been connected or disconnected. 549908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * @param status Status of the connect or disconnect operation. 559908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * @param newState Returns the new connection state. Can be one of 569908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * {@link BluetoothProfile#STATE_DISCONNECTED} or 579908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * {@link BluetoothProfile#STATE_CONNECTED} 589908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta */ 599908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta public void onConnectionStateChange(BluetoothDevice device, int status, 609908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta int newState) { 619908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta } 629908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta 639908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta /** 649908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * Indicates whether a local service has been added successfully. 659908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * 669908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * @param status Returns {@link BluetoothGatt#GATT_SUCCESS} if the service 679908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * was added successfully. 689908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * @param service The service that has been added 699908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta */ 709908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta public void onServiceAdded(int status, BluetoothGattService service) { 719908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta } 729908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta 739908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta /** 749908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * A remote client has requested to read a local characteristic. 759908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * 769908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * <p>An application must call {@link BluetoothGattServer#sendResponse} 779908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * to complete the request. 789908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * 799908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * @param device The remote device that has requested the read operation 809908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * @param requestId The Id of the request 819908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * @param offset Offset into the value of the characteristic 829908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * @param characteristic Characteristic to be read 839908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta */ 849908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta public void onCharacteristicReadRequest(BluetoothDevice device, int requestId, 859908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta int offset, BluetoothGattCharacteristic characteristic) { 869908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta } 879908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta 889908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta /** 899908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * A remote client has requested to write to a local characteristic. 909908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * 919908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * <p>An application must call {@link BluetoothGattServer#sendResponse} 929908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * to complete the request. 939908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * 949908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * @param device The remote device that has requested the write operation 959908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * @param requestId The Id of the request 969908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * @param characteristic Characteristic to be written to. 979908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * @param preparedWrite true, if this write operation should be queued for 989908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * later execution. 999908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * @param responseNeeded true, if the remote device requires a response 1009908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * @param offset The offset given for the value 1019908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * @param value The value the client wants to assign to the characteristic 1029908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta */ 1039908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta public void onCharacteristicWriteRequest(BluetoothDevice device, int requestId, 1049908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta BluetoothGattCharacteristic characteristic, 1059908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta boolean preparedWrite, boolean responseNeeded, 1069908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta int offset, byte[] value) { 1079908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta } 1089908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta 1099908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta /** 1109908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * A remote client has requested to read a local descriptor. 1119908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * 1129908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * <p>An application must call {@link BluetoothGattServer#sendResponse} 1139908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * to complete the request. 1149908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * 1159908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * @param device The remote device that has requested the read operation 1169908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * @param requestId The Id of the request 1179908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * @param offset Offset into the value of the characteristic 1189908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * @param descriptor Descriptor to be read 1199908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta */ 1209908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta public void onDescriptorReadRequest(BluetoothDevice device, int requestId, 1219908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta int offset, BluetoothGattDescriptor descriptor) { 1229908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta } 1239908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta 1249908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta /** 1259908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * A remote client has requested to write to a local descriptor. 1269908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * 1279908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * <p>An application must call {@link BluetoothGattServer#sendResponse} 1289908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * to complete the request. 1299908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * 1309908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * @param device The remote device that has requested the write operation 1319908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * @param requestId The Id of the request 1329908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * @param descriptor Descriptor to be written to. 1339908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * @param preparedWrite true, if this write operation should be queued for 1349908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * later execution. 1359908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * @param responseNeeded true, if the remote device requires a response 1369908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * @param offset The offset given for the value 1379908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * @param value The value the client wants to assign to the descriptor 1389908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta */ 1399908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta public void onDescriptorWriteRequest(BluetoothDevice device, int requestId, 1409908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta BluetoothGattDescriptor descriptor, 1419908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta boolean preparedWrite, boolean responseNeeded, 1429908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta int offset, byte[] value) { 1439908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta } 1449908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta 1459908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta /** 1469908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * Execute all pending write operations for this device. 1479908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * 1489908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * <p>An application must call {@link BluetoothGattServer#sendResponse} 1499908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * to complete the request. 1509908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * 1519908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * @param device The remote device that has requested the write operations 1529908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * @param requestId The Id of the request 1539908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * @param execute Whether the pending writes should be executed (true) or 1549908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * cancelled (false) 1559908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta */ 1569908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta public void onExecuteWrite(BluetoothDevice device, int requestId, boolean execute) { 1579908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta } 1589908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta} 159