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