You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* There is a createBond() method in BluetoothDevice class but for now it's hidden. We will call it using reflections. It has been revealed in KitKat (Api19)
615
+
* There is a createBond() method in BluetoothDevice class but for now it's hidden.
616
+
* We will call it using reflections. It has been revealed in KitKat (Api19)
@@ -877,16 +875,21 @@ public void onConnectionStateChange(final BluetoothGatt gatt, final int status,
877
875
mConnectionState = STATE_CONNECTED;
878
876
879
877
/*
880
-
* The onConnectionStateChange callback is called just after establishing connection and before sending Encryption Request BLE event in case of a paired device.
881
-
* In that case and when the Service Changed CCCD is enabled we will get the indication after initializing the encryption, about 1600 milliseconds later.
882
-
* If we discover services right after connecting, the onServicesDiscovered callback will be called immediately, before receiving the indication and the following
883
-
* service discovery and we may end up with old, application's services instead.
878
+
* The onConnectionStateChange callback is called just after establishing connection and before sending Encryption Request BLE event in case of a paired device.
879
+
* In that case and when the Service Changed CCCD is enabled we will get the indication after initializing the encryption, about 1600 milliseconds later.
880
+
* If we discover services right after connecting, the onServicesDiscovered callback will be called immediately, before receiving the indication and the following
881
+
* service discovery and we may end up with old, application's services instead.
884
882
*
885
-
* This is to support the buttonless switch from application to bootloader mode where the DFU bootloader notifies the master about service change.
886
-
* Tested on Nexus 4 (Android 4.4.4 and 5), Nexus 5 (Android 5), Samsung Note 2 (Android 4.4.2). The time after connection to end of service discovery is about 1.6s
887
-
* on Samsung Note 2.
883
+
* This is to support the buttonless switch from application to bootloader mode where the DFU bootloader notifies the master about service change.
884
+
* Tested on Nexus 4 (Android 4.4.4 and 5), Nexus 5 (Android 5), Samsung Note 2 (Android 4.4.2). The time after connection to end of service discovery is about 1.6s
885
+
* on Samsung Note 2.
888
886
*
889
-
* NOTE: We are doing this to avoid the hack with calling the hidden gatt.refresh() method, at least for bonded devices.
887
+
* NOTE: We are doing this to avoid the hack with calling the hidden gatt.refresh()
888
+
* method, at least for bonded devices.
889
+
*
890
+
* IMPORTANT: BluetoothDevice.getBondState() returns true if the bond information
891
+
* is present on Android, not necessarily when the link is established or even
892
+
* encrypted. This is a security issue, but in here it does not matter.
890
893
*/
891
894
if (gatt.getDevice().getBondState() == BluetoothDevice.BOND_BONDED) {
892
895
logi("Waiting 1600 ms for a possible Service Changed indication...");
* If the device is bonded this is up to the Service Changed characteristic to notify Android that the services has changed.
1631
-
* There is no need for this trick in that case.
1632
-
* If not bonded, the Android should not keep the services cached when the Service Changed characteristic is present in the target device database.
1633
-
* However, due to the Android bug (still exists in Android 5.0.1), it is keeping them anyway and the only way to clear services is by using this hidden refresh method.
1633
+
* If the device is bonded this is up to the Service Changed characteristic to notify Android
1634
+
* that the services has changed. There is no need for this trick in that case.
1635
+
* If not bonded, the Android should not keep the services cached when the Service Changed
1636
+
* characteristic is present in the target device database.
1637
+
* However, due to the Android bug, it is keeping them anyway and the only way to clear
1638
+
* services is by using this hidden refresh method.
1634
1639
*/
1635
1640
if (force || gatt.getDevice().getBondState() == BluetoothDevice.BOND_NONE) {
0 commit comments