@capacitor-community/bluetooth-le 3.1.2 → 3.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
<a href="https://www.npmjs.com/package/@capacitor-community/bluetooth-le"><img src="https://img.shields.io/npm/dw/@capacitor-community/bluetooth-le?style=flat-square" /></a>
|
|
14
14
|
<a href="https://www.npmjs.com/package/@capacitor-community/bluetooth-le"><img src="https://img.shields.io/npm/v/@capacitor-community/bluetooth-le?style=flat-square" /></a>
|
|
15
15
|
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
|
|
16
|
-
<a href="#contributors-"><img src="https://img.shields.io/badge/all%20contributors-
|
|
16
|
+
<a href="#contributors-"><img src="https://img.shields.io/badge/all%20contributors-17-orange?style=flat-square" /></a>
|
|
17
17
|
<!-- ALL-CONTRIBUTORS-BADGE:END -->
|
|
18
18
|
</p>
|
|
19
19
|
|
|
@@ -1110,6 +1110,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
|
|
|
1110
1110
|
<tr>
|
|
1111
1111
|
<td align="center" valign="top" width="14.28%"><a href="https://github.com/mchl18"><img src="https://avatars.githubusercontent.com/u/6136970?v=4?s=100" width="100px;" alt="mchl18"/><br /><sub><b>mchl18</b></sub></a><br /><a href="https://github.com/capacitor-community/bluetooth-le/commits?author=mchl18" title="Documentation">📖</a></td>
|
|
1112
1112
|
<td align="center" valign="top" width="14.28%"><a href="https://github.com/OpenSrcerer"><img src="https://avatars.githubusercontent.com/u/46500918?v=4?s=100" width="100px;" alt="Daniel Stefani"/><br /><sub><b>Daniel Stefani</b></sub></a><br /><a href="https://github.com/capacitor-community/bluetooth-le/commits?author=OpenSrcerer" title="Code">💻</a></td>
|
|
1113
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/lhd-biosency"><img src="https://avatars.githubusercontent.com/u/71714070?v=4?s=100" width="100px;" alt="Laurent"/><br /><sub><b>Laurent</b></sub></a><br /><a href="https://github.com/capacitor-community/bluetooth-le/commits?author=lhd-biosency" title="Code">💻</a></td>
|
|
1113
1114
|
</tr>
|
|
1114
1115
|
</tbody>
|
|
1115
1116
|
</table>
|
|
@@ -17,6 +17,7 @@ import android.content.Intent
|
|
|
17
17
|
import android.content.IntentFilter
|
|
18
18
|
import android.os.Build
|
|
19
19
|
import android.os.Handler
|
|
20
|
+
import android.os.HandlerThread
|
|
20
21
|
import android.os.Looper
|
|
21
22
|
import androidx.annotation.RequiresApi
|
|
22
23
|
import com.getcapacitor.Logger
|
|
@@ -71,6 +72,25 @@ class Device(
|
|
|
71
72
|
private var bondStateReceiver: BroadcastReceiver? = null
|
|
72
73
|
private var currentMtu = -1
|
|
73
74
|
|
|
75
|
+
private lateinit var callbacksHandlerThread: HandlerThread
|
|
76
|
+
private lateinit var callbacksHandler: Handler
|
|
77
|
+
|
|
78
|
+
private fun initializeCallbacksHandlerThread() {
|
|
79
|
+
synchronized(this) {
|
|
80
|
+
callbacksHandlerThread = HandlerThread("Callbacks thread")
|
|
81
|
+
callbacksHandlerThread.start()
|
|
82
|
+
callbacksHandler = Handler(callbacksHandlerThread.looper)
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
private fun cleanupCallbacksHandlerThread() {
|
|
87
|
+
synchronized(this) {
|
|
88
|
+
if (::callbacksHandlerThread.isInitialized) {
|
|
89
|
+
callbacksHandlerThread.quitSafely()
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
74
94
|
private val gattCallback: BluetoothGattCallback = object : BluetoothGattCallback() {
|
|
75
95
|
override fun onConnectionStateChange(
|
|
76
96
|
gatt: BluetoothGatt, status: Int, newState: Int
|
|
@@ -89,6 +109,7 @@ class Device(
|
|
|
89
109
|
bluetoothGatt?.close()
|
|
90
110
|
bluetoothGatt = null
|
|
91
111
|
Logger.debug(TAG, "Disconnected from GATT server.")
|
|
112
|
+
cleanupCallbacksHandlerThread()
|
|
92
113
|
resolve("disconnect", "Disconnected.")
|
|
93
114
|
}
|
|
94
115
|
}
|
|
@@ -288,7 +309,17 @@ class Device(
|
|
|
288
309
|
}
|
|
289
310
|
bluetoothGatt?.close()
|
|
290
311
|
connectionState = STATE_CONNECTING
|
|
291
|
-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.
|
|
312
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
313
|
+
initializeCallbacksHandlerThread()
|
|
314
|
+
bluetoothGatt = device.connectGatt(
|
|
315
|
+
context,
|
|
316
|
+
false,
|
|
317
|
+
gattCallback,
|
|
318
|
+
BluetoothDevice.TRANSPORT_LE,
|
|
319
|
+
BluetoothDevice.PHY_OPTION_NO_PREFERRED,
|
|
320
|
+
callbacksHandler
|
|
321
|
+
)
|
|
322
|
+
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
292
323
|
bluetoothGatt = device.connectGatt(
|
|
293
324
|
context, false, gattCallback, BluetoothDevice.TRANSPORT_LE
|
|
294
325
|
)
|
|
@@ -680,6 +711,7 @@ class Device(
|
|
|
680
711
|
connectionState = STATE_DISCONNECTED
|
|
681
712
|
gatt?.disconnect()
|
|
682
713
|
gatt?.close()
|
|
714
|
+
cleanupCallbacksHandlerThread()
|
|
683
715
|
reject(key, message)
|
|
684
716
|
}, timeout)
|
|
685
717
|
}
|