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 import android.util.Log; 22 23 /** 24 * This abstract class is used to implement {@link BluetoothGattServer} callbacks. 25 */ 26 public abstract class BluetoothGattServerCallback { 27 28 /** 29 * Callback indicating when a remote device has been connected or disconnected. 30 * 31 * @param device Remote device that has been connected or disconnected. 32 * @param status Status of the connect or disconnect operation. 33 * @param newState Returns the new connection state. Can be one of 34 * {@link BluetoothProfile#STATE_DISCONNECTED} or 35 * {@link BluetoothProfile#STATE_CONNECTED} 36 */ 37 public void onConnectionStateChange(BluetoothDevice device, int status, 38 int newState) { 39 } 40 41 /** 42 * Indicates whether a local service has been added successfully. 43 * 44 * @param status Returns {@link BluetoothGatt#GATT_SUCCESS} if the service 45 * was added successfully. 46 * @param service The service that has been added 47 */ 48 public void onServiceAdded(int status, BluetoothGattService service) { 49 } 50 51 /** 52 * A remote client has requested to read a local characteristic. 53 * 54 * <p>An application must call {@link BluetoothGattServer#sendResponse} 55 * to complete the request. 56 * 57 * @param device The remote device that has requested the read operation 58 * @param requestId The Id of the request 59 * @param offset Offset into the value of the characteristic 60 * @param characteristic Characteristic to be read 61 */ 62 public void onCharacteristicReadRequest(BluetoothDevice device, int requestId, 63 int offset, BluetoothGattCharacteristic characteristic) { 64 } 65 66 /** 67 * A remote client has requested to write to a local characteristic. 68 * 69 * <p>An application must call {@link BluetoothGattServer#sendResponse} 70 * to complete the request. 71 * 72 * @param device The remote device that has requested the write operation 73 * @param requestId The Id of the request 74 * @param characteristic Characteristic to be written to. 75 * @param preparedWrite true, if this write operation should be queued for 76 * later execution. 77 * @param responseNeeded true, if the remote device requires a response 78 * @param offset The offset given for the value 79 * @param value The value the client wants to assign to the characteristic 80 */ 81 public void onCharacteristicWriteRequest(BluetoothDevice device, int requestId, 82 BluetoothGattCharacteristic characteristic, 83 boolean preparedWrite, boolean responseNeeded, 84 int offset, byte[] value) { 85 } 86 87 /** 88 * A remote client has requested to read a local descriptor. 89 * 90 * <p>An application must call {@link BluetoothGattServer#sendResponse} 91 * to complete the request. 92 * 93 * @param device The remote device that has requested the read operation 94 * @param requestId The Id of the request 95 * @param offset Offset into the value of the characteristic 96 * @param descriptor Descriptor to be read 97 */ 98 public void onDescriptorReadRequest(BluetoothDevice device, int requestId, 99 int offset, BluetoothGattDescriptor descriptor) { 100 } 101 102 /** 103 * A remote client has requested to write to a local descriptor. 104 * 105 * <p>An application must call {@link BluetoothGattServer#sendResponse} 106 * to complete the request. 107 * 108 * @param device The remote device that has requested the write operation 109 * @param requestId The Id of the request 110 * @param descriptor Descriptor to be written to. 111 * @param preparedWrite true, if this write operation should be queued for 112 * later execution. 113 * @param responseNeeded true, if the remote device requires a response 114 * @param offset The offset given for the value 115 * @param value The value the client wants to assign to the descriptor 116 */ 117 public void onDescriptorWriteRequest(BluetoothDevice device, int requestId, 118 BluetoothGattDescriptor descriptor, 119 boolean preparedWrite, boolean responseNeeded, 120 int offset, byte[] value) { 121 } 122 123 /** 124 * Execute all pending write operations for this device. 125 * 126 * <p>An application must call {@link BluetoothGattServer#sendResponse} 127 * to complete the request. 128 * 129 * @param device The remote device that has requested the write operations 130 * @param requestId The Id of the request 131 * @param execute Whether the pending writes should be executed (true) or 132 * cancelled (false) 133 */ 134 public void onExecuteWrite(BluetoothDevice device, int requestId, boolean execute) { 135 } 136 } 137