Ganesh Ganapathi Batta | 9908112 | 2013-02-05 15:28:33 -0800 | [diff] [blame] | 1 | /* |
Jakub Pawlowski | 409cee6 | 2017-02-02 08:07:12 -0800 | [diff] [blame] | 2 | * Copyright (C) 2017 The Android Open Source Project |
Ganesh Ganapathi Batta | 9908112 | 2013-02-05 15:28:33 -0800 | [diff] [blame] | 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 | |
Ganesh Ganapathi Batta | 9908112 | 2013-02-05 15:28:33 -0800 | [diff] [blame] | 19 | /** |
| 20 | * This abstract class is used to implement {@link BluetoothGattServer} callbacks. |
Ganesh Ganapathi Batta | 9908112 | 2013-02-05 15:28:33 -0800 | [diff] [blame] | 21 | */ |
Jakub Pawlowski | d64bb88 | 2017-03-22 11:22:18 -0700 | [diff] [blame] | 22 | public abstract class BluetoothGattServerCallback { |
Ganesh Ganapathi Batta | 9908112 | 2013-02-05 15:28:33 -0800 | [diff] [blame] | 23 | |
| 24 | /** |
Jakub Pawlowski | d64bb88 | 2017-03-22 11:22:18 -0700 | [diff] [blame] | 25 | * Callback indicating when a remote device has been connected or disconnected. |
| 26 | * |
| 27 | * @param device Remote device that has been connected or disconnected. |
| 28 | * @param status Status of the connect or disconnect operation. |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 29 | * @param newState Returns the new connection state. Can be one of {@link |
| 30 | * BluetoothProfile#STATE_DISCONNECTED} or {@link BluetoothProfile#STATE_CONNECTED} |
Ganesh Ganapathi Batta | 9908112 | 2013-02-05 15:28:33 -0800 | [diff] [blame] | 31 | */ |
Jakub Pawlowski | d64bb88 | 2017-03-22 11:22:18 -0700 | [diff] [blame] | 32 | public void onConnectionStateChange(BluetoothDevice device, int status, |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 33 | int newState) { |
Jakub Pawlowski | d64bb88 | 2017-03-22 11:22:18 -0700 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | /** |
| 37 | * Indicates whether a local service has been added successfully. |
| 38 | * |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 39 | * @param status Returns {@link BluetoothGatt#GATT_SUCCESS} if the service was added |
| 40 | * successfully. |
Jakub Pawlowski | d64bb88 | 2017-03-22 11:22:18 -0700 | [diff] [blame] | 41 | * @param service The service that has been added |
| 42 | */ |
| 43 | public void onServiceAdded(int status, BluetoothGattService service) { |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * A remote client has requested to read a local characteristic. |
| 48 | * |
| 49 | * <p>An application must call {@link BluetoothGattServer#sendResponse} |
| 50 | * to complete the request. |
| 51 | * |
| 52 | * @param device The remote device that has requested the read operation |
| 53 | * @param requestId The Id of the request |
| 54 | * @param offset Offset into the value of the characteristic |
| 55 | * @param characteristic Characteristic to be read |
| 56 | */ |
| 57 | public void onCharacteristicReadRequest(BluetoothDevice device, int requestId, |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 58 | int offset, BluetoothGattCharacteristic characteristic) { |
Jakub Pawlowski | d64bb88 | 2017-03-22 11:22:18 -0700 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | /** |
| 62 | * A remote client has requested to write to a local characteristic. |
| 63 | * |
| 64 | * <p>An application must call {@link BluetoothGattServer#sendResponse} |
| 65 | * to complete the request. |
| 66 | * |
| 67 | * @param device The remote device that has requested the write operation |
| 68 | * @param requestId The Id of the request |
| 69 | * @param characteristic Characteristic to be written to. |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 70 | * @param preparedWrite true, if this write operation should be queued for later execution. |
Jakub Pawlowski | d64bb88 | 2017-03-22 11:22:18 -0700 | [diff] [blame] | 71 | * @param responseNeeded true, if the remote device requires a response |
| 72 | * @param offset The offset given for the value |
| 73 | * @param value The value the client wants to assign to the characteristic |
| 74 | */ |
| 75 | public void onCharacteristicWriteRequest(BluetoothDevice device, int requestId, |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 76 | BluetoothGattCharacteristic characteristic, |
| 77 | boolean preparedWrite, boolean responseNeeded, |
| 78 | int offset, byte[] value) { |
Jakub Pawlowski | d64bb88 | 2017-03-22 11:22:18 -0700 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | /** |
| 82 | * A remote client has requested to read a local descriptor. |
| 83 | * |
| 84 | * <p>An application must call {@link BluetoothGattServer#sendResponse} |
| 85 | * to complete the request. |
| 86 | * |
| 87 | * @param device The remote device that has requested the read operation |
| 88 | * @param requestId The Id of the request |
| 89 | * @param offset Offset into the value of the characteristic |
| 90 | * @param descriptor Descriptor to be read |
| 91 | */ |
| 92 | public void onDescriptorReadRequest(BluetoothDevice device, int requestId, |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 93 | int offset, BluetoothGattDescriptor descriptor) { |
Jakub Pawlowski | d64bb88 | 2017-03-22 11:22:18 -0700 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | /** |
| 97 | * A remote client has requested to write to a local descriptor. |
| 98 | * |
| 99 | * <p>An application must call {@link BluetoothGattServer#sendResponse} |
| 100 | * to complete the request. |
| 101 | * |
| 102 | * @param device The remote device that has requested the write operation |
| 103 | * @param requestId The Id of the request |
| 104 | * @param descriptor Descriptor to be written to. |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 105 | * @param preparedWrite true, if this write operation should be queued for later execution. |
Jakub Pawlowski | d64bb88 | 2017-03-22 11:22:18 -0700 | [diff] [blame] | 106 | * @param responseNeeded true, if the remote device requires a response |
| 107 | * @param offset The offset given for the value |
| 108 | * @param value The value the client wants to assign to the descriptor |
| 109 | */ |
| 110 | public void onDescriptorWriteRequest(BluetoothDevice device, int requestId, |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 111 | BluetoothGattDescriptor descriptor, |
| 112 | boolean preparedWrite, boolean responseNeeded, |
| 113 | int offset, byte[] value) { |
Jakub Pawlowski | d64bb88 | 2017-03-22 11:22:18 -0700 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | /** |
| 117 | * Execute all pending write operations for this device. |
| 118 | * |
| 119 | * <p>An application must call {@link BluetoothGattServer#sendResponse} |
| 120 | * to complete the request. |
| 121 | * |
| 122 | * @param device The remote device that has requested the write operations |
| 123 | * @param requestId The Id of the request |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 124 | * @param execute Whether the pending writes should be executed (true) or cancelled (false) |
Jakub Pawlowski | d64bb88 | 2017-03-22 11:22:18 -0700 | [diff] [blame] | 125 | */ |
| 126 | public void onExecuteWrite(BluetoothDevice device, int requestId, boolean execute) { |
| 127 | } |
| 128 | |
| 129 | /** |
| 130 | * Callback invoked when a notification or indication has been sent to |
| 131 | * a remote device. |
| 132 | * |
| 133 | * <p>When multiple notifications are to be sent, an application must |
| 134 | * wait for this callback to be received before sending additional |
| 135 | * notifications. |
| 136 | * |
| 137 | * @param device The remote device the notification has been sent to |
| 138 | * @param status {@link BluetoothGatt#GATT_SUCCESS} if the operation was successful |
| 139 | */ |
| 140 | public void onNotificationSent(BluetoothDevice device, int status) { |
| 141 | } |
| 142 | |
| 143 | /** |
| 144 | * Callback indicating the MTU for a given device connection has changed. |
| 145 | * |
| 146 | * <p>This callback will be invoked if a remote client has requested to change |
| 147 | * the MTU for a given connection. |
| 148 | * |
| 149 | * @param device The remote device that requested the MTU change |
| 150 | * @param mtu The new MTU size |
| 151 | */ |
| 152 | public void onMtuChanged(BluetoothDevice device, int mtu) { |
| 153 | } |
| 154 | |
| 155 | /** |
| 156 | * Callback triggered as result of {@link BluetoothGattServer#setPreferredPhy}, or as a result |
| 157 | * of remote device changing the PHY. |
| 158 | * |
| 159 | * @param device The remote device |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 160 | * @param txPhy the transmitter PHY in use. One of {@link BluetoothDevice#PHY_LE_1M}, {@link |
| 161 | * BluetoothDevice#PHY_LE_2M}, and {@link BluetoothDevice#PHY_LE_CODED} |
| 162 | * @param rxPhy the receiver PHY in use. One of {@link BluetoothDevice#PHY_LE_1M}, {@link |
| 163 | * BluetoothDevice#PHY_LE_2M}, and {@link BluetoothDevice#PHY_LE_CODED} |
| 164 | * @param status Status of the PHY update operation. {@link BluetoothGatt#GATT_SUCCESS} if the |
| 165 | * operation succeeds. |
Jakub Pawlowski | d64bb88 | 2017-03-22 11:22:18 -0700 | [diff] [blame] | 166 | */ |
Jakub Pawlowski | 409cee6 | 2017-02-02 08:07:12 -0800 | [diff] [blame] | 167 | public void onPhyUpdate(BluetoothDevice device, int txPhy, int rxPhy, int status) { |
Ganesh Ganapathi Batta | 9908112 | 2013-02-05 15:28:33 -0800 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | /** |
Jakub Pawlowski | d64bb88 | 2017-03-22 11:22:18 -0700 | [diff] [blame] | 171 | * Callback triggered as result of {@link BluetoothGattServer#readPhy} |
| 172 | * |
| 173 | * @param device The remote device that requested the PHY read |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 174 | * @param txPhy the transmitter PHY in use. One of {@link BluetoothDevice#PHY_LE_1M}, {@link |
| 175 | * BluetoothDevice#PHY_LE_2M}, and {@link BluetoothDevice#PHY_LE_CODED} |
| 176 | * @param rxPhy the receiver PHY in use. One of {@link BluetoothDevice#PHY_LE_1M}, {@link |
| 177 | * BluetoothDevice#PHY_LE_2M}, and {@link BluetoothDevice#PHY_LE_CODED} |
| 178 | * @param status Status of the PHY read operation. {@link BluetoothGatt#GATT_SUCCESS} if the |
| 179 | * operation succeeds. |
Ganesh Ganapathi Batta | 9908112 | 2013-02-05 15:28:33 -0800 | [diff] [blame] | 180 | */ |
Jakub Pawlowski | 409cee6 | 2017-02-02 08:07:12 -0800 | [diff] [blame] | 181 | public void onPhyRead(BluetoothDevice device, int txPhy, int rxPhy, int status) { |
Andre Eisenbach | 16bf846 | 2014-11-18 11:34:26 -0800 | [diff] [blame] | 182 | } |
Jakub Pawlowski | 326f7b3 | 2017-03-23 19:05:55 -0700 | [diff] [blame] | 183 | |
| 184 | /** |
| 185 | * Callback indicating the connection parameters were updated. |
| 186 | * |
Jakub Pawlowski | 14a381b | 2017-09-14 08:24:15 -0700 | [diff] [blame] | 187 | * @param device The remote device involved |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 188 | * @param interval Connection interval used on this connection, 1.25ms unit. Valid range is from |
| 189 | * 6 (7.5ms) to 3200 (4000ms). |
| 190 | * @param latency Slave latency for the connection in number of connection events. Valid range |
| 191 | * is from 0 to 499 |
| 192 | * @param timeout Supervision timeout for this connection, in 10ms unit. Valid range is from 10 |
| 193 | * (0.1s) to 3200 (32s) |
Jakub Pawlowski | 326f7b3 | 2017-03-23 19:05:55 -0700 | [diff] [blame] | 194 | * @param status {@link BluetoothGatt#GATT_SUCCESS} if the connection has been updated |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 195 | * successfully |
Jakub Pawlowski | 326f7b3 | 2017-03-23 19:05:55 -0700 | [diff] [blame] | 196 | * @hide |
| 197 | */ |
Jakub Pawlowski | 14a381b | 2017-09-14 08:24:15 -0700 | [diff] [blame] | 198 | public void onConnectionUpdated(BluetoothDevice device, int interval, int latency, int timeout, |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 199 | int status) { |
Jakub Pawlowski | 326f7b3 | 2017-03-23 19:05:55 -0700 | [diff] [blame] | 200 | } |
| 201 | |
Ganesh Ganapathi Batta | 9908112 | 2013-02-05 15:28:33 -0800 | [diff] [blame] | 202 | } |