From ca70d55f7ed56acb3e01269a2b8a2f3daa814d9d Mon Sep 17 00:00:00 2001 From: Greg Date: Fri, 6 Dec 2019 16:22:13 -0500 Subject: [PATCH] Better handling of connection state and calls to gatt.close(). --- Ble.jar | Bin 10815 -> 11121 bytes BleConnect.java | 22 ++++++++++++++++++++++ ble_android.go | 9 +++++++++ 3 files changed, 31 insertions(+) diff --git a/Ble.jar b/Ble.jar index f52d79bf5ce4459f68a91f1d2aab02e582056cd2..fb85bb45cd27dba95cce02f2624215e00a48b2fa 100644 GIT binary patch delta 6982 zcmZu$byQSc*9VEAyM`2y2I)pZN^UwF&f#2n^KL#}N zOe$+76&GKu#H1EUuR&#HVp3n(p+g4`pCPV$=>Sm#7OHnC@b`Z)QYU^Ndj~7=%XJbq zIFq+sqJtN_`4kjSi{*z19}Vx9R##`FtYu&h@gF@#+%PQ#`O_`aa5GSPz*UT&-Ll=y zt^b^f^Q0MYe9To(*e|R1ju!a@OhjuFIn%o;@W|F!C43-wAGYP4V~wu`;477?6kN@L zH(>zusiq0`$30PE2j6U5WnsFhULOPop*<_K2@i4YAP35g&gxA3HxffRS&lEH{=Z?_e7sM`5YCcvGuAmjk(@R<|$mWtu#AdM6wqQ=#^@={UWe zcN1?*AT}8*R2SCmfv=+hz^OoizkEbTLu-0~hW5`BzCSyd#A6#Lu!l#qfvL-+Jjtz? z>SE(#+*KUs05M1P74g<#)lOs9FG~DVRo|p_iXm(3Y-6s9}L` z(u-mhi&=R%QP0G0wuF@dlCWyTh56Q@`Ij)AtjfF+xOY}|1idDY<1ysrRIW%JbL+qkO-Q)3$bC>QcQ$<@{enq;v{ob2DRrl9t6n zQt0TU0YO-qr1W7{JO*{Rh03=>wQY3r6YO>@IP zVjU=wiKCr!ca3phc+TB9Y+8Sc&Ia?}g$Dh?yo7fEy0qm>F!aK!N;B zp3Q<*J#J$$7wxMUh@HM7rW>qVs@@+SVq8@r^%6GHKIa)VM^_o!eoJqchbv%yF!HuH z7NtrwmU#6qV&4OfbKbu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zFCiA<9n*-!1e9HJVyU^ND$VWTtJzWa@nlzDRG-*GOC(ed;#}O*rYLEzSnsA@sFYim zbK820z8CpS6)o^*m4#n^VH7r{AJpDDukni{1h{5PLw-IQcilNh`V5aI?7nwdb}9~V zLJ?nfS6^$C(v0{F7TJ-kdY@h1bp;o6pxj^xk-R{=zsC2~GwB%!WZk=2O6Ynk>xxpW zB{X7<(y)N0)yN*&kZ?&g=D-Vu-=podSm=Pc``ON-4u-N=K70E>xT1?uBX+ljAiGP? z50Fm33lDcjj4)|yfFRK~apP?ye_;A7GRXh9emKte_`5vX-`pagL-P&^lvA+@Dz$zN zzjqLq)&g^Lo?f+mFRuKnD%A#&lG(G?nPCIuSznug**GLmJ-Xx@O|O>KKN^J%^fkhnM1THR99MwiS>_zz-HkYEuR(&ziD%F54o?FC|Au0U()c z={RDH$C7NDx9y47h>6$XDg!C051in<=dZE;q4<~ddSkOLL{*d25=FFC>o!GC>@&ni6iB>KH|615GCJJ1E1B7t;a>2*bL3j%>JukhmP(pp<+Nm!BPLak9^gz!36YM ze^rJ@2H{s#RFLuQtMg{$e061vysvJRQSj9fF^M8Kx`nC#)x?3uOmdX3SN{}W{|xYt z<1Mh0iR&-Ml1x~@>W?@}{738fHwF!e#mq(ZnkVi^P3_m8ZrAcpxBG8QJ0cL9nGER1 zjQbb(PtoMxzzO8Pz#(Sb*T-FBCWA@F_!}W%`5WP6A%ls+`Wvxl`A@Qc_SpYUMvnUz t*!W-IKR+VnKVA|FN(cWBkQ9i(it{=u2`d>)1?}Hkbyx`zTIgS~{{zWAmdXGC diff --git a/BleConnect.java b/BleConnect.java index 604c404..b4e4d69 100644 --- a/BleConnect.java +++ b/BleConnect.java @@ -126,6 +126,13 @@ public class BleConnect extends Fragment { public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) { BluetoothDevice device = gatt.getDevice(); String addr = device.getAddress(); + if (status != BluetoothGatt.GATT_SUCCESS) { + Log.d("gio", "onConnectionStateChange: error code " + status); + onDisconnect(gatt, addr); + Log.d("gio", "gatt.close()"); + gatt.close(); + return; + } switch (newState) { case BluetoothProfile.STATE_CONNECTED: { Log.d("gio", "Connected"); @@ -133,14 +140,21 @@ public class BleConnect extends Fragment { onConnect(gatt, addr); break; } + case BluetoothProfile.STATE_CONNECTING: + case BluetoothProfile.STATE_DISCONNECTING: { + break; + } case BluetoothProfile.STATE_DISCONNECTED: { Log.d("gio", "Disconnected"); onDisconnect(gatt, addr); + Log.d("gio", "gatt.close()"); gatt.close(); break; } default: { Log.d("gio", "onConnectionStateChange: unknown state"); + onDisconnect(gatt, addr); + Log.d("gio", "gatt.close()"); gatt.close(); break; } @@ -177,7 +191,15 @@ public class BleConnect extends Fragment { Log.d("gio","BleConnect: disconnect"); handler.post(new Runnable() { public void run() { + boolean callClose = false; + BluetoothDevice device = gatt.getDevice(); + if (device != null) { + callClose = (manager.getConnectionState(device, BluetoothProfile.GATT) != BluetoothGatt.STATE_CONNECTED); + } gatt.disconnect(); + if (callClose) { + gatt.close(); + } } }); } diff --git a/ble_android.go b/ble_android.go index 8baf4c0..c1d4074 100644 --- a/ble_android.go +++ b/ble_android.go @@ -178,6 +178,9 @@ func (b *BLE) knownPeripheral(p Peripheral) (Peripheral, bool) { //DiscoverServices asks a Peripheral for its Services func (p Peripheral) DiscoverServices() { + if p.gatt == 0 { + return + } connect() log.Printf("discovering services") runInJVM(func(env *C.JNIEnv) { @@ -188,6 +191,9 @@ func (p Peripheral) DiscoverServices() { //DiscoverCharacteristics asks a Peripheral for the Characteristics related //to a Service func (p Peripheral) DiscoverCharacteristics(serv Service) { + if p.gatt == 0 { + return + } //launch a goroutine because this function calls back directly //from the same thread. go func() { @@ -202,6 +208,9 @@ func (p Peripheral) DiscoverCharacteristics(serv Service) { //SetNotifyValue subscribes to a characteristic func (p Peripheral) SetNotifyValue(c Characteristic) { + if p.gatt == 0 { + return + } runInJVM(func(env *C.JNIEnv) { log.Printf("setCharacteristicNotification: %s", c.UUID) C.setCharacteristicNotification(env, gBLE.handle.BleConnect, p.gatt, c.characteristic)