blob: 2c8114be3fe3374beb4cbc05d60ae2ca8ed2b6c6 [file] [log] [blame]
Ganesh Ganapathi Batta99081122013-02-05 15:28:33 -08001/*
Jakub Pawlowski409cee62017-02-02 08:07:12 -08002 * Copyright (C) 2017 The Android Open Source Project
Ganesh Ganapathi Batta99081122013-02-05 15:28:33 -08003 *
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
17package android.bluetooth;
18
Ganesh Ganapathi Batta99081122013-02-05 15:28:33 -080019/**
20 * This abstract class is used to implement {@link BluetoothGattServer} callbacks.
Ganesh Ganapathi Batta99081122013-02-05 15:28:33 -080021 */
Jakub Pawlowskid64bb882017-03-22 11:22:18 -070022public abstract class BluetoothGattServerCallback {
Ganesh Ganapathi Batta99081122013-02-05 15:28:33 -080023
24 /**
Jakub Pawlowskid64bb882017-03-22 11:22:18 -070025 * 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 Hea355e5e2017-08-22 16:06:54 -070029 * @param newState Returns the new connection state. Can be one of {@link
30 * BluetoothProfile#STATE_DISCONNECTED} or {@link BluetoothProfile#STATE_CONNECTED}
Ganesh Ganapathi Batta99081122013-02-05 15:28:33 -080031 */
Jakub Pawlowskid64bb882017-03-22 11:22:18 -070032 public void onConnectionStateChange(BluetoothDevice device, int status,
Jack Hea355e5e2017-08-22 16:06:54 -070033 int newState) {
Jakub Pawlowskid64bb882017-03-22 11:22:18 -070034 }
35
36 /**
37 * Indicates whether a local service has been added successfully.
38 *
Jack Hea355e5e2017-08-22 16:06:54 -070039 * @param status Returns {@link BluetoothGatt#GATT_SUCCESS} if the service was added
40 * successfully.
Jakub Pawlowskid64bb882017-03-22 11:22:18 -070041 * @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 Hea355e5e2017-08-22 16:06:54 -070058 int offset, BluetoothGattCharacteristic characteristic) {
Jakub Pawlowskid64bb882017-03-22 11:22:18 -070059 }
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 Hea355e5e2017-08-22 16:06:54 -070070 * @param preparedWrite true, if this write operation should be queued for later execution.
Jakub Pawlowskid64bb882017-03-22 11:22:18 -070071 * @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 Hea355e5e2017-08-22 16:06:54 -070076 BluetoothGattCharacteristic characteristic,
77 boolean preparedWrite, boolean responseNeeded,
78 int offset, byte[] value) {
Jakub Pawlowskid64bb882017-03-22 11:22:18 -070079 }
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 Hea355e5e2017-08-22 16:06:54 -070093 int offset, BluetoothGattDescriptor descriptor) {
Jakub Pawlowskid64bb882017-03-22 11:22:18 -070094 }
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 Hea355e5e2017-08-22 16:06:54 -0700105 * @param preparedWrite true, if this write operation should be queued for later execution.
Jakub Pawlowskid64bb882017-03-22 11:22:18 -0700106 * @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 Hea355e5e2017-08-22 16:06:54 -0700111 BluetoothGattDescriptor descriptor,
112 boolean preparedWrite, boolean responseNeeded,
113 int offset, byte[] value) {
Jakub Pawlowskid64bb882017-03-22 11:22:18 -0700114 }
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 Hea355e5e2017-08-22 16:06:54 -0700124 * @param execute Whether the pending writes should be executed (true) or cancelled (false)
Jakub Pawlowskid64bb882017-03-22 11:22:18 -0700125 */
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 Hea355e5e2017-08-22 16:06:54 -0700160 * @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 Pawlowskid64bb882017-03-22 11:22:18 -0700166 */
Jakub Pawlowski409cee62017-02-02 08:07:12 -0800167 public void onPhyUpdate(BluetoothDevice device, int txPhy, int rxPhy, int status) {
Ganesh Ganapathi Batta99081122013-02-05 15:28:33 -0800168 }
169
170 /**
Jakub Pawlowskid64bb882017-03-22 11:22:18 -0700171 * Callback triggered as result of {@link BluetoothGattServer#readPhy}
172 *
173 * @param device The remote device that requested the PHY read
Jack Hea355e5e2017-08-22 16:06:54 -0700174 * @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 Batta99081122013-02-05 15:28:33 -0800180 */
Jakub Pawlowski409cee62017-02-02 08:07:12 -0800181 public void onPhyRead(BluetoothDevice device, int txPhy, int rxPhy, int status) {
Andre Eisenbach16bf8462014-11-18 11:34:26 -0800182 }
Jakub Pawlowski326f7b32017-03-23 19:05:55 -0700183
184 /**
185 * Callback indicating the connection parameters were updated.
186 *
Jakub Pawlowski14a381b2017-09-14 08:24:15 -0700187 * @param device The remote device involved
Jack Hea355e5e2017-08-22 16:06:54 -0700188 * @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 Pawlowski326f7b32017-03-23 19:05:55 -0700194 * @param status {@link BluetoothGatt#GATT_SUCCESS} if the connection has been updated
Jack Hea355e5e2017-08-22 16:06:54 -0700195 * successfully
Jakub Pawlowski326f7b32017-03-23 19:05:55 -0700196 * @hide
197 */
Jakub Pawlowski14a381b2017-09-14 08:24:15 -0700198 public void onConnectionUpdated(BluetoothDevice device, int interval, int latency, int timeout,
Jack Hea355e5e2017-08-22 16:06:54 -0700199 int status) {
Jakub Pawlowski326f7b32017-03-23 19:05:55 -0700200 }
201
Ganesh Ganapathi Batta99081122013-02-05 15:28:33 -0800202}