Skip to content

Commit bbe7e2a

Browse files
committed
faster android connect and not about broken socks client for https
1 parent c808651 commit bbe7e2a

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

Diff for: android/src/main/kotlin/com/viam/ble/CentralManager.kt

+9-1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class CentralManager(
5050
private var isScanning = false
5151
private var lastNScans = mutableListOf<Long>()
5252
private val scanMutex = Mutex()
53+
private val excludeFromScan = mutableSetOf<String>()
5354

5455
@Throws(SecurityException::class)
5556
suspend fun scanForPeripherals(serviceIds: List<String> = listOf()) {
@@ -59,7 +60,9 @@ class CentralManager(
5960
// Android excludes bonded devices from showing up in advertisements. So we need
6061
// to connect to it in order to check out its services. We'll disconnect if it's
6162
// of no use to us.
63+
excludeFromScan.clear()
6264
btMan.adapter.bondedDevices.forEach { device ->
65+
excludeFromScan.add(device.address)
6366
CoroutineScope(Dispatchers.IO).launch {
6467
for (i in 1..3) {
6568
try {
@@ -86,7 +89,7 @@ class CentralManager(
8689
disconnectFromDevice(device.address)
8790
}
8891
} catch (e: Throwable) {
89-
Log.d(TAG, "failed to connect to bonded device", e)
92+
Log.d(TAG, "failed to connect to bonded device ${device.address}", e)
9093
}
9194
delay(5000)
9295
}
@@ -222,6 +225,11 @@ class CentralManager(
222225
) {
223226
super.onScanResult(callbackType, result)
224227
CoroutineScope(Dispatchers.IO).launch {
228+
scanMutex.withLock {
229+
if (excludeFromScan.contains(result.device.address)) {
230+
return@launch
231+
}
232+
}
225233
_scanForPeripheralFlow.emit(
226234
Result.success(
227235
hashMapOf(

Diff for: lib/src/ble_channel_socket_mux.dart

+4-2
Original file line numberDiff line numberDiff line change
@@ -462,8 +462,10 @@ class _L2CapChannelStreamedSocket with StreamFromControllerMixin<Uint8List>, IOS
462462
streamController.close();
463463
}
464464

465-
// Note(erd): this may be needed. Saw this once
466-
// error connecting NoSuchMethodError: Class '__L2CapChannelStreamedSocket' has no instance method '_detachRaw'
465+
// Note(erd): We can't implement this and it prevents SecureSocket.secure from working
466+
// when using HttpClient.
467+
// See https://github.com/dart-lang/sdk/issues/50199. Nothing we can do other than rely
468+
// on a different HTTP library.
467469
//Future<RawSecureSocket> _detachRaw() {}
468470

469471
@override

0 commit comments

Comments
 (0)