From 3f9419c5a79087d33328c5677d39455c2da122e3 Mon Sep 17 00:00:00 2001 From: Vinardo Date: Sun, 1 Aug 2021 22:51:50 +0700 Subject: [PATCH 1/2] Fix queue becomes null on disconnect --- src/android/BluetoothLePlugin.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/android/BluetoothLePlugin.java b/src/android/BluetoothLePlugin.java index 0d8048c..8800579 100644 --- a/src/android/BluetoothLePlugin.java +++ b/src/android/BluetoothLePlugin.java @@ -1542,6 +1542,12 @@ private void reconnectAction(JSONArray args, CallbackContext callbackContext) { connection.put(keyState, BluetoothProfile.STATE_CONNECTING); //connection.put(keyDiscoveredState, STATE_UNDISCOVERED); //Devices stays discovered even if disconnected (but not closed) connection.put(operationConnect, callbackContext); + + //Queue may had become null + if (connection.get(keyQueue) == null) { + LinkedList queue = new LinkedList(); + connection.put(keyQueue, queue); + } } private void disconnectAction(JSONArray args, CallbackContext callbackContext) { @@ -4018,15 +4024,6 @@ public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState return; } - //Check for queued operations in progress on this device - if (newState == BluetoothProfile.STATE_DISCONNECTED) { - LinkedList queue = (LinkedList) connection.get(keyQueue); - Operation operation = queue.peek(); - if (operation != null) { - queueRemove(connection); - } - } - CallbackContext callbackContext = (CallbackContext) connection.get(operationConnect); JSONObject returnObj = new JSONObject(); @@ -4040,6 +4037,9 @@ public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState connection.put(keyPeripheral, gatt); connection.put(keyState, BluetoothProfile.STATE_DISCONNECTED); connection.put(keyDiscoveredState, STATE_UNDISCOVERED); + + LinkedList queue = new LinkedList(); + connection.put(keyQueue, queue); connections.put(device.getAddress(), connection); From 6aa5849745e28b72bc2d7247bd4a3221c1056bb6 Mon Sep 17 00:00:00 2001 From: Vinardo Date: Sun, 1 Aug 2021 23:02:23 +0700 Subject: [PATCH 2/2] Forgot to remove extraneous code :p --- src/android/BluetoothLePlugin.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/android/BluetoothLePlugin.java b/src/android/BluetoothLePlugin.java index 8800579..d8dc271 100644 --- a/src/android/BluetoothLePlugin.java +++ b/src/android/BluetoothLePlugin.java @@ -1542,12 +1542,6 @@ private void reconnectAction(JSONArray args, CallbackContext callbackContext) { connection.put(keyState, BluetoothProfile.STATE_CONNECTING); //connection.put(keyDiscoveredState, STATE_UNDISCOVERED); //Devices stays discovered even if disconnected (but not closed) connection.put(operationConnect, callbackContext); - - //Queue may had become null - if (connection.get(keyQueue) == null) { - LinkedList queue = new LinkedList(); - connection.put(keyQueue, queue); - } } private void disconnectAction(JSONArray args, CallbackContext callbackContext) {