1 /*
2  * Copyright 2022 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 com.android.bluetooth.gatt;
18 
19 import android.os.RemoteException;
20 
21 import com.android.internal.annotations.GuardedBy;
22 import com.android.internal.annotations.VisibleForTesting;
23 
24 import java.util.ArrayList;
25 import java.util.List;
26 
27 /** GATT Profile Native Interface to/from JNI. */
28 public class GattNativeInterface {
29     private static final String TAG = GattNativeInterface.class.getSimpleName();
30 
31     private GattService mGattService;
32 
33     @GuardedBy("INSTANCE_LOCK")
34     private static GattNativeInterface sInstance;
35 
36     private static final Object INSTANCE_LOCK = new Object();
37 
GattNativeInterface()38     private GattNativeInterface() {}
39 
getGattService()40     GattService getGattService() {
41         return mGattService;
42     }
43 
44     /**
45      * This class is a singleton because native library should only be loaded once
46      *
47      * @return default instance
48      */
getInstance()49     public static GattNativeInterface getInstance() {
50         synchronized (INSTANCE_LOCK) {
51             if (sInstance == null) {
52                 sInstance = new GattNativeInterface();
53             }
54             return sInstance;
55         }
56     }
57 
58     /** Set singleton instance. */
59     @VisibleForTesting
setInstance(GattNativeInterface instance)60     public static void setInstance(GattNativeInterface instance) {
61         synchronized (INSTANCE_LOCK) {
62             sInstance = instance;
63         }
64     }
65 
66     /* Callbacks */
67 
onClientRegistered(int status, int clientIf, long uuidLsb, long uuidMsb)68     void onClientRegistered(int status, int clientIf, long uuidLsb, long uuidMsb)
69             throws RemoteException {
70         getGattService().onClientRegistered(status, clientIf, uuidLsb, uuidMsb);
71     }
72 
onConnected(int clientIf, int connId, int status, String address)73     void onConnected(int clientIf, int connId, int status, String address) throws RemoteException {
74         getGattService().onConnected(clientIf, connId, status, address);
75     }
76 
onDisconnected(int clientIf, int connId, int status, String address)77     void onDisconnected(int clientIf, int connId, int status, String address)
78             throws RemoteException {
79         getGattService().onDisconnected(clientIf, connId, status, address);
80     }
81 
onClientPhyUpdate(int connId, int txPhy, int rxPhy, int status)82     void onClientPhyUpdate(int connId, int txPhy, int rxPhy, int status) throws RemoteException {
83         getGattService().onClientPhyUpdate(connId, txPhy, rxPhy, status);
84     }
85 
onClientPhyRead(int clientIf, String address, int txPhy, int rxPhy, int status)86     void onClientPhyRead(int clientIf, String address, int txPhy, int rxPhy, int status)
87             throws RemoteException {
88         getGattService().onClientPhyRead(clientIf, address, txPhy, rxPhy, status);
89     }
90 
onClientConnUpdate(int connId, int interval, int latency, int timeout, int status)91     void onClientConnUpdate(int connId, int interval, int latency, int timeout, int status)
92             throws RemoteException {
93         getGattService().onClientConnUpdate(connId, interval, latency, timeout, status);
94     }
95 
onServiceChanged(int connId)96     void onServiceChanged(int connId) throws RemoteException {
97         getGattService().onServiceChanged(connId);
98     }
99 
onClientSubrateChange( int connId, int subrateFactor, int latency, int contNum, int timeout, int status)100     void onClientSubrateChange(
101             int connId, int subrateFactor, int latency, int contNum, int timeout, int status)
102             throws RemoteException {
103         getGattService()
104                 .onClientSubrateChange(connId, subrateFactor, latency, contNum, timeout, status);
105     }
106 
onServerPhyUpdate(int connId, int txPhy, int rxPhy, int status)107     void onServerPhyUpdate(int connId, int txPhy, int rxPhy, int status) throws RemoteException {
108         getGattService().onServerPhyUpdate(connId, txPhy, rxPhy, status);
109     }
110 
onServerPhyRead(int serverIf, String address, int txPhy, int rxPhy, int status)111     void onServerPhyRead(int serverIf, String address, int txPhy, int rxPhy, int status)
112             throws RemoteException {
113         getGattService().onServerPhyRead(serverIf, address, txPhy, rxPhy, status);
114     }
115 
onServerConnUpdate(int connId, int interval, int latency, int timeout, int status)116     void onServerConnUpdate(int connId, int interval, int latency, int timeout, int status)
117             throws RemoteException {
118         getGattService().onServerConnUpdate(connId, interval, latency, timeout, status);
119     }
120 
onServerSubrateChange( int connId, int subrateFactor, int latency, int contNum, int timeout, int status)121     void onServerSubrateChange(
122             int connId, int subrateFactor, int latency, int contNum, int timeout, int status)
123             throws RemoteException {
124         getGattService()
125                 .onServerSubrateChange(connId, subrateFactor, latency, contNum, timeout, status);
126     }
127 
onSearchCompleted(int connId, int status)128     void onSearchCompleted(int connId, int status) throws RemoteException {
129         getGattService().onSearchCompleted(connId, status);
130     }
131 
getSampleGattDbElement()132     GattDbElement getSampleGattDbElement() {
133         return getGattService().getSampleGattDbElement();
134     }
135 
onGetGattDb(int connId, ArrayList<GattDbElement> db)136     void onGetGattDb(int connId, ArrayList<GattDbElement> db) throws RemoteException {
137         getGattService().onGetGattDb(connId, db);
138     }
139 
onRegisterForNotifications(int connId, int status, int registered, int handle)140     void onRegisterForNotifications(int connId, int status, int registered, int handle) {
141         getGattService().onRegisterForNotifications(connId, status, registered, handle);
142     }
143 
onNotify(int connId, String address, int handle, boolean isNotify, byte[] data)144     void onNotify(int connId, String address, int handle, boolean isNotify, byte[] data)
145             throws RemoteException {
146         getGattService().onNotify(connId, address, handle, isNotify, data);
147     }
148 
onReadCharacteristic(int connId, int status, int handle, byte[] data)149     void onReadCharacteristic(int connId, int status, int handle, byte[] data)
150             throws RemoteException {
151         getGattService().onReadCharacteristic(connId, status, handle, data);
152     }
153 
onWriteCharacteristic(int connId, int status, int handle, byte[] data)154     void onWriteCharacteristic(int connId, int status, int handle, byte[] data)
155             throws RemoteException {
156         getGattService().onWriteCharacteristic(connId, status, handle, data);
157     }
158 
onExecuteCompleted(int connId, int status)159     void onExecuteCompleted(int connId, int status) throws RemoteException {
160         getGattService().onExecuteCompleted(connId, status);
161     }
162 
onReadDescriptor(int connId, int status, int handle, byte[] data)163     void onReadDescriptor(int connId, int status, int handle, byte[] data) throws RemoteException {
164         getGattService().onReadDescriptor(connId, status, handle, data);
165     }
166 
onWriteDescriptor(int connId, int status, int handle, byte[] data)167     void onWriteDescriptor(int connId, int status, int handle, byte[] data) throws RemoteException {
168         getGattService().onWriteDescriptor(connId, status, handle, data);
169     }
170 
onReadRemoteRssi(int clientIf, String address, int rssi, int status)171     void onReadRemoteRssi(int clientIf, String address, int rssi, int status)
172             throws RemoteException {
173         getGattService().onReadRemoteRssi(clientIf, address, rssi, status);
174     }
175 
onConfigureMTU(int connId, int status, int mtu)176     void onConfigureMTU(int connId, int status, int mtu) throws RemoteException {
177         getGattService().onConfigureMTU(connId, status, mtu);
178     }
179 
onClientCongestion(int connId, boolean congested)180     void onClientCongestion(int connId, boolean congested) throws RemoteException {
181         getGattService().onClientCongestion(connId, congested);
182     }
183 
184     /* Server callbacks */
185 
onServerRegistered(int status, int serverIf, long uuidLsb, long uuidMsb)186     void onServerRegistered(int status, int serverIf, long uuidLsb, long uuidMsb)
187             throws RemoteException {
188         getGattService().onServerRegistered(status, serverIf, uuidLsb, uuidMsb);
189     }
190 
onServiceAdded(int status, int serverIf, List<GattDbElement> service)191     void onServiceAdded(int status, int serverIf, List<GattDbElement> service)
192             throws RemoteException {
193         getGattService().onServiceAdded(status, serverIf, service);
194     }
195 
onServiceStopped(int status, int serverIf, int srvcHandle)196     void onServiceStopped(int status, int serverIf, int srvcHandle) throws RemoteException {
197         getGattService().onServiceStopped(status, serverIf, srvcHandle);
198     }
199 
onServiceDeleted(int status, int serverIf, int srvcHandle)200     void onServiceDeleted(int status, int serverIf, int srvcHandle) {
201         getGattService().onServiceDeleted(status, serverIf, srvcHandle);
202     }
203 
onClientConnected(String address, boolean connected, int connId, int serverIf)204     void onClientConnected(String address, boolean connected, int connId, int serverIf)
205             throws RemoteException {
206         getGattService().onClientConnected(address, connected, connId, serverIf);
207     }
208 
onServerReadCharacteristic( String address, int connId, int transId, int handle, int offset, boolean isLong)209     void onServerReadCharacteristic(
210             String address, int connId, int transId, int handle, int offset, boolean isLong)
211             throws RemoteException {
212         getGattService()
213                 .onServerReadCharacteristic(address, connId, transId, handle, offset, isLong);
214     }
215 
onServerReadDescriptor( String address, int connId, int transId, int handle, int offset, boolean isLong)216     void onServerReadDescriptor(
217             String address, int connId, int transId, int handle, int offset, boolean isLong)
218             throws RemoteException {
219         getGattService().onServerReadDescriptor(address, connId, transId, handle, offset, isLong);
220     }
221 
onServerWriteCharacteristic( String address, int connId, int transId, int handle, int offset, int length, boolean needRsp, boolean isPrep, byte[] data)222     void onServerWriteCharacteristic(
223             String address,
224             int connId,
225             int transId,
226             int handle,
227             int offset,
228             int length,
229             boolean needRsp,
230             boolean isPrep,
231             byte[] data)
232             throws RemoteException {
233         getGattService()
234                 .onServerWriteCharacteristic(
235                         address, connId, transId, handle, offset, length, needRsp, isPrep, data);
236     }
237 
onServerWriteDescriptor( String address, int connId, int transId, int handle, int offset, int length, boolean needRsp, boolean isPrep, byte[] data)238     void onServerWriteDescriptor(
239             String address,
240             int connId,
241             int transId,
242             int handle,
243             int offset,
244             int length,
245             boolean needRsp,
246             boolean isPrep,
247             byte[] data)
248             throws RemoteException {
249         getGattService()
250                 .onServerWriteDescriptor(
251                         address, connId, transId, handle, offset, length, needRsp, isPrep, data);
252     }
253 
onExecuteWrite(String address, int connId, int transId, int execWrite)254     void onExecuteWrite(String address, int connId, int transId, int execWrite)
255             throws RemoteException {
256         getGattService().onExecuteWrite(address, connId, transId, execWrite);
257     }
258 
onResponseSendCompleted(int status, int attrHandle)259     void onResponseSendCompleted(int status, int attrHandle) {
260         getGattService().onResponseSendCompleted(status, attrHandle);
261     }
262 
onNotificationSent(int connId, int status)263     void onNotificationSent(int connId, int status) throws RemoteException {
264         getGattService().onNotificationSent(connId, status);
265     }
266 
onServerCongestion(int connId, boolean congested)267     void onServerCongestion(int connId, boolean congested) throws RemoteException {
268         getGattService().onServerCongestion(connId, congested);
269     }
270 
onMtuChanged(int connId, int mtu)271     void onMtuChanged(int connId, int mtu) throws RemoteException {
272         getGattService().onMtuChanged(connId, mtu);
273     }
274 
275     /**********************************************************************************************/
276     /******************************************* native *******************************************/
277     /**********************************************************************************************/
278 
initializeNative()279     private native void initializeNative();
280 
cleanupNative()281     private native void cleanupNative();
282 
gattClientGetDeviceTypeNative(String address)283     private native int gattClientGetDeviceTypeNative(String address);
284 
gattClientRegisterAppNative( long appUuidLsb, long appUuidMsb, boolean eattSupport)285     private native void gattClientRegisterAppNative(
286             long appUuidLsb, long appUuidMsb, boolean eattSupport);
287 
gattClientUnregisterAppNative(int clientIf)288     private native void gattClientUnregisterAppNative(int clientIf);
289 
gattClientConnectNative( int clientIf, String address, int addressType, boolean isDirect, int transport, boolean opportunistic, int initiatingPhys)290     private native void gattClientConnectNative(
291             int clientIf,
292             String address,
293             int addressType,
294             boolean isDirect,
295             int transport,
296             boolean opportunistic,
297             int initiatingPhys);
298 
gattClientDisconnectNative(int clientIf, String address, int connId)299     private native void gattClientDisconnectNative(int clientIf, String address, int connId);
300 
gattClientSetPreferredPhyNative( int clientIf, String address, int txPhy, int rxPhy, int phyOptions)301     private native void gattClientSetPreferredPhyNative(
302             int clientIf, String address, int txPhy, int rxPhy, int phyOptions);
303 
gattClientReadPhyNative(int clientIf, String address)304     private native void gattClientReadPhyNative(int clientIf, String address);
305 
gattClientRefreshNative(int clientIf, String address)306     private native void gattClientRefreshNative(int clientIf, String address);
307 
gattClientSearchServiceNative( int connId, boolean searchAll, long serviceUuidLsb, long serviceUuidMsb)308     private native void gattClientSearchServiceNative(
309             int connId, boolean searchAll, long serviceUuidLsb, long serviceUuidMsb);
310 
gattClientDiscoverServiceByUuidNative( int connId, long serviceUuidLsb, long serviceUuidMsb)311     private native void gattClientDiscoverServiceByUuidNative(
312             int connId, long serviceUuidLsb, long serviceUuidMsb);
313 
gattClientGetGattDbNative(int connId)314     private native void gattClientGetGattDbNative(int connId);
315 
gattClientReadCharacteristicNative(int connId, int handle, int authReq)316     private native void gattClientReadCharacteristicNative(int connId, int handle, int authReq);
317 
gattClientReadUsingCharacteristicUuidNative( int connId, long uuidMsb, long uuidLsb, int sHandle, int eHandle, int authReq)318     private native void gattClientReadUsingCharacteristicUuidNative(
319             int connId, long uuidMsb, long uuidLsb, int sHandle, int eHandle, int authReq);
320 
gattClientReadDescriptorNative(int connId, int handle, int authReq)321     private native void gattClientReadDescriptorNative(int connId, int handle, int authReq);
322 
gattClientWriteCharacteristicNative( int connId, int handle, int writeType, int authReq, byte[] value)323     private native void gattClientWriteCharacteristicNative(
324             int connId, int handle, int writeType, int authReq, byte[] value);
325 
gattClientWriteDescriptorNative( int connId, int handle, int authReq, byte[] value)326     private native void gattClientWriteDescriptorNative(
327             int connId, int handle, int authReq, byte[] value);
328 
gattClientExecuteWriteNative(int connId, boolean execute)329     private native void gattClientExecuteWriteNative(int connId, boolean execute);
330 
gattClientRegisterForNotificationsNative( int clientIf, String address, int handle, boolean enable)331     private native void gattClientRegisterForNotificationsNative(
332             int clientIf, String address, int handle, boolean enable);
333 
gattClientReadRemoteRssiNative(int clientIf, String address)334     private native void gattClientReadRemoteRssiNative(int clientIf, String address);
335 
gattClientConfigureMTUNative(int connId, int mtu)336     private native void gattClientConfigureMTUNative(int connId, int mtu);
337 
gattConnectionParameterUpdateNative( int clientIf, String address, int minInterval, int maxInterval, int latency, int timeout, int minConnectionEventLen, int maxConnectionEventLen)338     private native void gattConnectionParameterUpdateNative(
339             int clientIf,
340             String address,
341             int minInterval,
342             int maxInterval,
343             int latency,
344             int timeout,
345             int minConnectionEventLen,
346             int maxConnectionEventLen);
347 
gattServerRegisterAppNative( long appUuidLsb, long appUuidMsb, boolean eattSupport)348     private native void gattServerRegisterAppNative(
349             long appUuidLsb, long appUuidMsb, boolean eattSupport);
350 
gattServerUnregisterAppNative(int serverIf)351     private native void gattServerUnregisterAppNative(int serverIf);
352 
gattServerConnectNative( int serverIf, String address, int addressType, boolean isDirect, int transport)353     private native void gattServerConnectNative(
354             int serverIf, String address, int addressType, boolean isDirect, int transport);
355 
gattServerDisconnectNative(int serverIf, String address, int connId)356     private native void gattServerDisconnectNative(int serverIf, String address, int connId);
357 
gattServerSetPreferredPhyNative( int clientIf, String address, int txPhy, int rxPhy, int phyOptions)358     private native void gattServerSetPreferredPhyNative(
359             int clientIf, String address, int txPhy, int rxPhy, int phyOptions);
360 
gattServerReadPhyNative(int clientIf, String address)361     private native void gattServerReadPhyNative(int clientIf, String address);
362 
gattServerAddServiceNative(int serverIf, List<GattDbElement> service)363     private native void gattServerAddServiceNative(int serverIf, List<GattDbElement> service);
364 
gattServerStopServiceNative(int serverIf, int svcHandle)365     private native void gattServerStopServiceNative(int serverIf, int svcHandle);
366 
gattServerDeleteServiceNative(int serverIf, int svcHandle)367     private native void gattServerDeleteServiceNative(int serverIf, int svcHandle);
368 
gattServerSendIndicationNative( int serverIf, int attrHandle, int connId, byte[] val)369     private native void gattServerSendIndicationNative(
370             int serverIf, int attrHandle, int connId, byte[] val);
371 
gattServerSendNotificationNative( int serverIf, int attrHandle, int connId, byte[] val)372     private native void gattServerSendNotificationNative(
373             int serverIf, int attrHandle, int connId, byte[] val);
374 
gattServerSendResponseNative( int serverIf, int connId, int transId, int status, int handle, int offset, byte[] val, int authReq)375     private native void gattServerSendResponseNative(
376             int serverIf,
377             int connId,
378             int transId,
379             int status,
380             int handle,
381             int offset,
382             byte[] val,
383             int authReq);
384 
gattSubrateRequestNative( int clientIf, String address, int subrateMin, int subrateMax, int maxLatency, int contNumber, int supervisionTimeout)385     private native void gattSubrateRequestNative(
386             int clientIf,
387             String address,
388             int subrateMin,
389             int subrateMax,
390             int maxLatency,
391             int contNumber,
392             int supervisionTimeout);
393 
gattTestNative( int command, long uuid1Lsb, long uuid1Msb, String bda1, int p1, int p2, int p3, int p4, int p5)394     private native void gattTestNative(
395             int command,
396             long uuid1Lsb,
397             long uuid1Msb,
398             String bda1,
399             int p1,
400             int p2,
401             int p3,
402             int p4,
403             int p5);
404 
405     /** Initialize the native interface and native components */
init(GattService gattService)406     public void init(GattService gattService) {
407         mGattService = gattService;
408         initializeNative();
409     }
410 
411     /** Clean up the native interface and native components */
cleanup()412     public void cleanup() {
413         cleanupNative();
414         mGattService = null;
415     }
416 
417     /**
418      * Get the type of Bluetooth device
419      *
420      * @param address address of the Bluetooth device
421      * @return type of Bluetooth device 0 for BR/EDR, 1 for BLE, 2 for DUAL mode (To be confirmed)
422      */
gattClientGetDeviceType(String address)423     public int gattClientGetDeviceType(String address) {
424         return gattClientGetDeviceTypeNative(address);
425     }
426 
427     /**
428      * Register the given client It will invoke {@link #onClientRegistered(int, int, long, long)}.
429      */
gattClientRegisterApp(long appUuidLsb, long appUuidMsb, boolean eattSupport)430     public void gattClientRegisterApp(long appUuidLsb, long appUuidMsb, boolean eattSupport) {
431         gattClientRegisterAppNative(appUuidLsb, appUuidMsb, eattSupport);
432     }
433 
434     /** Unregister the client */
gattClientUnregisterApp(int clientIf)435     public void gattClientUnregisterApp(int clientIf) {
436         gattClientUnregisterAppNative(clientIf);
437     }
438 
439     /**
440      * Connect to the remote Gatt server
441      *
442      * @see {@link BluetoothDevice#connectGatt} for parameters.
443      */
gattClientConnect( int clientIf, String address, int addressType, boolean isDirect, int transport, boolean opportunistic, int initiatingPhys)444     public void gattClientConnect(
445             int clientIf,
446             String address,
447             int addressType,
448             boolean isDirect,
449             int transport,
450             boolean opportunistic,
451             int initiatingPhys) {
452         gattClientConnectNative(
453                 clientIf, address, addressType, isDirect, transport, opportunistic, initiatingPhys);
454     }
455 
456     /** Disconnect from the remote Gatt server */
gattClientDisconnect(int clientIf, String address, int connId)457     public void gattClientDisconnect(int clientIf, String address, int connId) {
458         gattClientDisconnectNative(clientIf, address, connId);
459     }
460 
461     /** Set the preferred connection PHY for the client */
gattClientSetPreferredPhy( int clientIf, String address, int txPhy, int rxPhy, int phyOptions)462     public void gattClientSetPreferredPhy(
463             int clientIf, String address, int txPhy, int rxPhy, int phyOptions) {
464         gattClientSetPreferredPhyNative(clientIf, address, txPhy, rxPhy, phyOptions);
465     }
466 
467     /** Read the current transmitter PHY and receiver PHY of the client */
gattClientReadPhy(int clientIf, String address)468     public void gattClientReadPhy(int clientIf, String address) {
469         gattClientReadPhyNative(clientIf, address);
470     }
471 
472     /** Clear the internal cache and force a refresh of the services from the remote device */
gattClientRefresh(int clientIf, String address)473     public void gattClientRefresh(int clientIf, String address) {
474         gattClientRefreshNative(clientIf, address);
475     }
476 
477     /** Discover GATT services */
gattClientSearchService( int connId, boolean searchAll, long serviceUuidLsb, long serviceUuidMsb)478     public void gattClientSearchService(
479             int connId, boolean searchAll, long serviceUuidLsb, long serviceUuidMsb) {
480         gattClientSearchServiceNative(connId, searchAll, serviceUuidLsb, serviceUuidMsb);
481     }
482 
483     /** Discover the GATT service by the given UUID */
gattClientDiscoverServiceByUuid( int connId, long serviceUuidLsb, long serviceUuidMsb)484     public void gattClientDiscoverServiceByUuid(
485             int connId, long serviceUuidLsb, long serviceUuidMsb) {
486         gattClientDiscoverServiceByUuidNative(connId, serviceUuidLsb, serviceUuidMsb);
487     }
488 
489     /** Get GATT DB of the remote device */
gattClientGetGattDb(int connId)490     public void gattClientGetGattDb(int connId) {
491         gattClientGetGattDbNative(connId);
492     }
493 
494     /** Read a characteristic by the given handle */
gattClientReadCharacteristic(int connId, int handle, int authReq)495     public void gattClientReadCharacteristic(int connId, int handle, int authReq) {
496         gattClientReadCharacteristicNative(connId, handle, authReq);
497     }
498 
499     /** Read a characteristic by the given UUID */
gattClientReadUsingCharacteristicUuid( int connId, long uuidMsb, long uuidLsb, int sHandle, int eHandle, int authReq)500     public void gattClientReadUsingCharacteristicUuid(
501             int connId, long uuidMsb, long uuidLsb, int sHandle, int eHandle, int authReq) {
502         gattClientReadUsingCharacteristicUuidNative(
503                 connId, uuidMsb, uuidLsb, sHandle, eHandle, authReq);
504     }
505 
506     /** Read a descriptor by the given handle */
gattClientReadDescriptor(int connId, int handle, int authReq)507     public void gattClientReadDescriptor(int connId, int handle, int authReq) {
508         gattClientReadDescriptorNative(connId, handle, authReq);
509     }
510 
511     /** Write a characteristic by the given handle */
gattClientWriteCharacteristic( int connId, int handle, int writeType, int authReq, byte[] value)512     public void gattClientWriteCharacteristic(
513             int connId, int handle, int writeType, int authReq, byte[] value) {
514         gattClientWriteCharacteristicNative(connId, handle, writeType, authReq, value);
515     }
516 
517     /** Write a descriptor by the given handle */
gattClientWriteDescriptor(int connId, int handle, int authReq, byte[] value)518     public void gattClientWriteDescriptor(int connId, int handle, int authReq, byte[] value) {
519         gattClientWriteDescriptorNative(connId, handle, authReq, value);
520     }
521 
522     /** Execute a reliable write transaction */
gattClientExecuteWrite(int connId, boolean execute)523     public void gattClientExecuteWrite(int connId, boolean execute) {
524         gattClientExecuteWriteNative(connId, execute);
525     }
526 
527     /** Register notification for the characteristic */
gattClientRegisterForNotifications( int clientIf, String address, int handle, boolean enable)528     public void gattClientRegisterForNotifications(
529             int clientIf, String address, int handle, boolean enable) {
530         gattClientRegisterForNotificationsNative(clientIf, address, handle, enable);
531     }
532 
533     /** Read the RSSI for a connected remote device */
gattClientReadRemoteRssi(int clientIf, String address)534     public void gattClientReadRemoteRssi(int clientIf, String address) {
535         gattClientReadRemoteRssiNative(clientIf, address);
536     }
537 
538     /** Configure MTU size used for the connection */
gattClientConfigureMTU(int connId, int mtu)539     public void gattClientConfigureMTU(int connId, int mtu) {
540         gattClientConfigureMTUNative(connId, mtu);
541     }
542 
543     /** Update connection parameter. */
gattConnectionParameterUpdate( int clientIf, String address, int minInterval, int maxInterval, int latency, int timeout, int minConnectionEventLen, int maxConnectionEventLen)544     public void gattConnectionParameterUpdate(
545             int clientIf,
546             String address,
547             int minInterval,
548             int maxInterval,
549             int latency,
550             int timeout,
551             int minConnectionEventLen,
552             int maxConnectionEventLen) {
553         gattConnectionParameterUpdateNative(
554                 clientIf,
555                 address,
556                 minInterval,
557                 maxInterval,
558                 latency,
559                 timeout,
560                 minConnectionEventLen,
561                 maxConnectionEventLen);
562     }
563 
564     /** Update connection parameter. */
gattSubrateRequest( int clientIf, String address, int subrateMin, int subrateMax, int maxLatency, int contNumber, int supervisionTimeout)565     public void gattSubrateRequest(
566             int clientIf,
567             String address,
568             int subrateMin,
569             int subrateMax,
570             int maxLatency,
571             int contNumber,
572             int supervisionTimeout) {
573         gattSubrateRequestNative(
574                 clientIf,
575                 address,
576                 subrateMin,
577                 subrateMax,
578                 maxLatency,
579                 contNumber,
580                 supervisionTimeout);
581     }
582 
583     /** Register GATT server */
gattServerRegisterApp(long appUuidLsb, long appUuidMsb, boolean eattSupport)584     public void gattServerRegisterApp(long appUuidLsb, long appUuidMsb, boolean eattSupport) {
585         gattServerRegisterAppNative(appUuidLsb, appUuidMsb, eattSupport);
586     }
587 
588     /** Unregister GATT server */
gattServerUnregisterApp(int serverIf)589     public void gattServerUnregisterApp(int serverIf) {
590         gattServerUnregisterAppNative(serverIf);
591     }
592 
593     /** Connect to a remote device as a GATT server role */
gattServerConnect( int serverIf, String address, int addressType, boolean isDirect, int transport)594     public void gattServerConnect(
595             int serverIf, String address, int addressType, boolean isDirect, int transport) {
596         gattServerConnectNative(serverIf, address, addressType, isDirect, transport);
597     }
598 
599     /** Disconnects from a remote device as a GATT server role */
gattServerDisconnect(int serverIf, String address, int connId)600     public void gattServerDisconnect(int serverIf, String address, int connId) {
601         gattServerDisconnectNative(serverIf, address, connId);
602     }
603 
604     /** Set the preferred connection PHY as a GATT server role */
gattServerSetPreferredPhy( int clientIf, String address, int txPhy, int rxPhy, int phyOptions)605     public void gattServerSetPreferredPhy(
606             int clientIf, String address, int txPhy, int rxPhy, int phyOptions) {
607         gattServerSetPreferredPhyNative(clientIf, address, txPhy, rxPhy, phyOptions);
608     }
609 
610     /** Read the current transmitter PHY and receiver PHY of the connection */
gattServerReadPhy(int clientIf, String address)611     public void gattServerReadPhy(int clientIf, String address) {
612         gattServerReadPhyNative(clientIf, address);
613     }
614 
615     /** Add a service to the list of services to be hosted. */
gattServerAddService(int serverIf, List<GattDbElement> service)616     public void gattServerAddService(int serverIf, List<GattDbElement> service) {
617         gattServerAddServiceNative(serverIf, service);
618     }
619 
620     /** Stop a service */
gattServerStopService(int serverIf, int svcHandle)621     public void gattServerStopService(int serverIf, int svcHandle) {
622         gattServerStopServiceNative(serverIf, svcHandle);
623     }
624 
625     /** Removes a service from the list of services to be provided */
gattServerDeleteService(int serverIf, int svcHandle)626     public void gattServerDeleteService(int serverIf, int svcHandle) {
627         gattServerDeleteServiceNative(serverIf, svcHandle);
628     }
629 
630     /** Send an indication of the characteristic */
gattServerSendIndication(int serverIf, int attrHandle, int connId, byte[] val)631     public void gattServerSendIndication(int serverIf, int attrHandle, int connId, byte[] val) {
632         gattServerSendIndicationNative(serverIf, attrHandle, connId, val);
633     }
634 
635     /** Send a notification of the characteristic */
gattServerSendNotification(int serverIf, int attrHandle, int connId, byte[] val)636     public void gattServerSendNotification(int serverIf, int attrHandle, int connId, byte[] val) {
637         gattServerSendNotificationNative(serverIf, attrHandle, connId, val);
638     }
639 
640     /** Send a response as a GATT server role */
gattServerSendResponse( int serverIf, int connId, int transId, int status, int handle, int offset, byte[] val, int authReq)641     public void gattServerSendResponse(
642             int serverIf,
643             int connId,
644             int transId,
645             int status,
646             int handle,
647             int offset,
648             byte[] val,
649             int authReq) {
650         gattServerSendResponseNative(
651                 serverIf, connId, transId, status, handle, offset, val, authReq);
652     }
653 
654     /** Send a test command */
gattTest( int command, long uuid1Lsb, long uuid1Msb, String bda1, int p1, int p2, int p3, int p4, int p5)655     public void gattTest(
656             int command,
657             long uuid1Lsb,
658             long uuid1Msb,
659             String bda1,
660             int p1,
661             int p2,
662             int p3,
663             int p4,
664             int p5) {
665         gattTestNative(command, uuid1Lsb, uuid1Msb, bda1, p1, p2, p3, p4, p5);
666     }
667 }
668