Merge pull request 'fix: critical issues from code review' (#20) from fix/code-review-critical-issues into main
All checks were successful
CI / build (push) Successful in 1m27s

This commit is contained in:
eddy 2026-08-04 18:44:55 +02:00
commit 7829528e89
6 changed files with 22 additions and 24 deletions

View file

@ -32,6 +32,7 @@ import javax.crypto.Mac
import javax.crypto.spec.GCMParameterSpec
import javax.crypto.spec.SecretKeySpec
import kotlin.text.Charsets
import kotlinx.coroutines.CompletableDeferred
class BleRelayManager(
private val context: Context,
@ -83,14 +84,6 @@ class BleRelayManager(
private var ecdhNotifyBuf: ByteArray = ByteArray(0)
private var ecdhCccdPending = false
private class CompletableDeferred<T> {
private var result: T? = null
private var completed = false
@Synchronized fun complete(value: T) { result = value; completed = true }
@Synchronized fun isDone(): Boolean = completed
@Synchronized fun get(): T? = result
}
interface OtaNotifyCallback {
fun onOtaNotify(status: Int, seq: Int)
}
@ -290,6 +283,7 @@ class BleRelayManager(
private fun connectToDevice(device: android.bluetooth.BluetoothDevice) {
handler.post { callbacks.onStatusChanged(BleStatus.Connecting) }
Log.d(TAG, "Connecting to ${device.address}")
bluetoothGatt?.close()
bluetoothGatt = device.connectGatt(context, false, gattCallback)
}
@ -500,10 +494,10 @@ class BleRelayManager(
Thread {
val start = System.currentTimeMillis()
while (!ecdhDeferred!!.isDone() && System.currentTimeMillis() - start < ECDH_TIMEOUT_MS) {
while (!ecdhDeferred!!.isCompleted && System.currentTimeMillis() - start < ECDH_TIMEOUT_MS) {
Thread.sleep(50)
}
if (!ecdhDeferred!!.isDone()) {
if (!ecdhDeferred!!.isCompleted) {
Log.w(TAG, "ECDH: notify timeout")
handler.post {
callbacks.onStatusChanged(BleStatus.CommError)

View file

@ -98,11 +98,7 @@ class OtaManager(
return@withContext false
}
try {
withTimeout(OTA_START_TIMEOUT_MS) {
while (true) { delay(100); ensureActive() }
}
} catch (_: kotlinx.coroutines.TimeoutCancellationException) {}
delay(500)
val totalChunks = (fw.size + chunkDataSize - 1) / chunkDataSize
var seq = 0