check for null
This commit is contained in:
parent
b2f1684aaf
commit
80371e4299
|
@ -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 = 5000L
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue