Merge pull request #1210 from avereha/avereha/fix-connect
check for null
This commit is contained in:
commit
384c010ff2
|
@ -68,6 +68,10 @@ class Connection(
|
||||||
val autoConnect = false
|
val autoConnect = false
|
||||||
val gatt = gattConnection ?: podDevice.connectGatt(context, autoConnect, bleCommCallbacks, BluetoothDevice.TRANSPORT_LE)
|
val gatt = gattConnection ?: podDevice.connectGatt(context, autoConnect, bleCommCallbacks, BluetoothDevice.TRANSPORT_LE)
|
||||||
gattConnection = gatt
|
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()) {
|
if (!gatt.connect()) {
|
||||||
throw FailedToConnectException("connect() returned false")
|
throw FailedToConnectException("connect() returned false")
|
||||||
}
|
}
|
||||||
|
@ -195,5 +199,6 @@ class Connection(
|
||||||
const val BASE_CONNECT_TIMEOUT_MS = 10000L
|
const val BASE_CONNECT_TIMEOUT_MS = 10000L
|
||||||
const val MIN_DISCOVERY_TIMEOUT_MS = 10000L
|
const val MIN_DISCOVERY_TIMEOUT_MS = 10000L
|
||||||
const val STOP_CONNECTING_CHECK_INTERVAL_MS = 500L
|
const val STOP_CONNECTING_CHECK_INTERVAL_MS = 500L
|
||||||
|
const val SLEEP_WHEN_FAILING_TO_CONNECT_GATT = 10000L
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue