Merge pull request #1210 from avereha/avereha/fix-connect

check for null
This commit is contained in:
Milos Kozak 2022-01-22 11:10:33 +01:00 committed by GitHub
commit 384c010ff2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -68,6 +68,10 @@ class Connection(
val autoConnect = false
val gatt = gattConnection ?: podDevice.connectGatt(context, autoConnect, bleCommCallbacks, BluetoothDevice.TRANSPORT_LE)
gattConnection = gatt
if (gatt == null) {
Thread.sleep(SLEEP_WHEN_FAILING_TO_CONNECT_GATT) // Do not retry too often
throw FailedToConnectException("connectGatt() returned null")
}
if (!gatt.connect()) {
throw FailedToConnectException("connect() returned false")
}
@ -195,5 +199,6 @@ class Connection(
const val BASE_CONNECT_TIMEOUT_MS = 10000L
const val MIN_DISCOVERY_TIMEOUT_MS = 10000L
const val STOP_CONNECTING_CHECK_INTERVAL_MS = 500L
const val SLEEP_WHEN_FAILING_TO_CONNECT_GATT = 10000L
}
}