1 /*
2  * Copyright (C) 2017 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 /**
20  * This abstract class is used to implement {@link BluetoothGattServer} callbacks.
21  */
22 public abstract class BluetoothGattServerCallback {
23 
24     /**
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.
29      * @param newState Returns the new connection state. Can be one of {@link
30      * BluetoothProfile#STATE_DISCONNECTED} or {@link BluetoothProfile#STATE_CONNECTED}
31      */
onConnectionStateChange(BluetoothDevice device, int status, int newState)32     public void onConnectionStateChange(BluetoothDevice device, int status,
33             int newState) {
34     }
35 
36     /**
37      * Indicates whether a local service has been added successfully.
38      *
39      * @param status Returns {@link BluetoothGatt#GATT_SUCCESS} if the service was added
40      * successfully.
41      * @param service The service that has been added
42      */
onServiceAdded(int status, BluetoothGattService service)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      */
onCharacteristicReadRequest(BluetoothDevice device, int requestId, int offset, BluetoothGattCharacteristic characteristic)57     public void onCharacteristicReadRequest(BluetoothDevice device, int requestId,
58             int offset, BluetoothGattCharacteristic characteristic) {
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.
70      * @param preparedWrite true, if this write operation should be queued for later execution.
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      */
onCharacteristicWriteRequest(BluetoothDevice device, int requestId, BluetoothGattCharacteristic characteristic, boolean preparedWrite, boolean responseNeeded, int offset, byte[] value)75     public void onCharacteristicWriteRequest(BluetoothDevice device, int requestId,
76             BluetoothGattCharacteristic characteristic,
77             boolean preparedWrite, boolean responseNeeded,
78             int offset, byte[] value) {
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      */
onDescriptorReadRequest(BluetoothDevice device, int requestId, int offset, BluetoothGattDescriptor descriptor)92     public void onDescriptorReadRequest(BluetoothDevice device, int requestId,
93             int offset, BluetoothGattDescriptor descriptor) {
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.
105      * @param preparedWrite true, if this write operation should be queued for later execution.
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      */
onDescriptorWriteRequest(BluetoothDevice device, int requestId, BluetoothGattDescriptor descriptor, boolean preparedWrite, boolean responseNeeded, int offset, byte[] value)110     public void onDescriptorWriteRequest(BluetoothDevice device, int requestId,
111             BluetoothGattDescriptor descriptor,
112             boolean preparedWrite, boolean responseNeeded,
113             int offset, byte[] value) {
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
124      * @param execute Whether the pending writes should be executed (true) or cancelled (false)
125      */
onExecuteWrite(BluetoothDevice device, int requestId, boolean execute)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      */
onNotificationSent(BluetoothDevice device, int status)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      */
onMtuChanged(BluetoothDevice device, int mtu)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
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.
166      */
onPhyUpdate(BluetoothDevice device, int txPhy, int rxPhy, int status)167     public void onPhyUpdate(BluetoothDevice device, int txPhy, int rxPhy, int status) {
168     }
169 
170     /**
171      * Callback triggered as result of {@link BluetoothGattServer#readPhy}
172      *
173      * @param device The remote device that requested the PHY read
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.
180      */
onPhyRead(BluetoothDevice device, int txPhy, int rxPhy, int status)181     public void onPhyRead(BluetoothDevice device, int txPhy, int rxPhy, int status) {
182     }
183 
184     /**
185      * Callback indicating the connection parameters were updated.
186      *
187      * @param device The remote device involved
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)
194      * @param status {@link BluetoothGatt#GATT_SUCCESS} if the connection has been updated
195      * successfully
196      * @hide
197      */
onConnectionUpdated(BluetoothDevice device, int interval, int latency, int timeout, int status)198     public void onConnectionUpdated(BluetoothDevice device, int interval, int latency, int timeout,
199             int status) {
200     }
201 
202 }
203