fix: BLE autoReconnect 무한 루프 — max 10회 시도 후 포기
증상: demo APK 에서 한 번 BLE 연결 후 disconnect → autoReconnect 가 8초 간격으로 영원히 재시도 → isReconnecting=true 영구 유지 → Clinical Home 진입 시 "BLE Connecting..." 무한 로딩. 원인: scheduleAutoReconnect 가 SCAN_TIMEOUT 마다 자기 자신을 재호출. 종료 조건은 (1) 실제 연결 (2) Bluetooth disabled 뿐. 수정: - MAX_RECONNECT_ATTEMPTS = 10 상수 (≈ 100~120초 동안 시도) - attemptAutoReconnect 진입 시 카운트 체크 → 초과 시 isReconnecting=false, reconnectAttempt 초기화, 콜백 invoke - 사용자가 ClinicalHome 의 [Connect] 버튼 또는 DeviceScan 재진입 으로 명시적 재시도 가능.
This commit is contained in:
@@ -70,6 +70,8 @@ class BleManager private constructor(private val context: Context) {
|
|||||||
private set
|
private set
|
||||||
private var reconnectAttempt = 0
|
private var reconnectAttempt = 0
|
||||||
private val reconnectIntervalMs: Long = 3000
|
private val reconnectIntervalMs: Long = 3000
|
||||||
|
/** max retry — 10회 시도 후 포기 (≈ 8s scan × 10 + 간격, 약 100~120초). */
|
||||||
|
private val MAX_RECONNECT_ATTEMPTS = 10
|
||||||
private var reconnectTimer: Runnable? = null
|
private var reconnectTimer: Runnable? = null
|
||||||
@Volatile private var lastRxTimestamp: Long = 0
|
@Volatile private var lastRxTimestamp: Long = 0
|
||||||
private var watchdogTimer: Runnable? = null
|
private var watchdogTimer: Runnable? = null
|
||||||
@@ -738,6 +740,14 @@ class BleManager private constructor(private val context: Context) {
|
|||||||
isReconnecting.value = false
|
isReconnecting.value = false
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
// max 시도 가드 — 무한 루프 방지. 초과 시 사용자가 명시적으로 재시도하도록.
|
||||||
|
if (reconnectAttempt >= MAX_RECONNECT_ATTEMPTS) {
|
||||||
|
debugLogger.warn("RECONNECT_GIVE_UP after ${reconnectAttempt} attempts — manual retry required")
|
||||||
|
isReconnecting.value = false
|
||||||
|
reconnectAttempt = 0
|
||||||
|
onReconnectionFailed?.invoke()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
reconnectAttempt++
|
reconnectAttempt++
|
||||||
reconnectConnecting = false
|
reconnectConnecting = false
|
||||||
|
|||||||
Reference in New Issue
Block a user