From 4dd8d5382fe259c3f3e9c5dde5433d80ddb099a9 Mon Sep 17 00:00:00 2001 From: jjangddu Date: Mon, 4 May 2026 18:06:55 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20BLE=20=EB=A1=9C=EA=B7=B8=20=EC=8B=A4?= =?UTF-8?q?=EC=8B=9C=EA=B0=84=20=ED=8C=8C=EC=9D=BC=20=EA=B8=B0=EB=A1=9D=20?= =?UTF-8?q?(=ED=99=94=EB=A9=B4=20=EC=9E=A0=EA=B8=88/=EC=95=B1=20=EC=A2=85?= =?UTF-8?q?=EB=A3=8C=EC=97=90=EB=8F=84=20=EB=B3=B4=EC=A1=B4)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit BleDebugLogger: - 매 entry마다 즉시 Downloads/VesiScan_BLE_*.log에 append - 새 BLE 연결 시 새 파일 생성 + 헤더 기록 - 기존 메모리 내 로그 + UI 표시는 동일 유지 - 화면 잠금/Doze/앱 종료에도 로그 보존 Co-Authored-By: Claude Opus 4.6 (1M context) --- .../services/BleDebugLogger.kt | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/app/src/main/java/com/example/medilightv2android/services/BleDebugLogger.kt b/app/src/main/java/com/example/medilightv2android/services/BleDebugLogger.kt index d081f16..1090778 100644 --- a/app/src/main/java/com/example/medilightv2android/services/BleDebugLogger.kt +++ b/app/src/main/java/com/example/medilightv2android/services/BleDebugLogger.kt @@ -81,6 +81,21 @@ class BleDebugLogger private constructor(private val context: Context) { private val dateFmt = SimpleDateFormat("yyyy-MM-dd_HHmmss", Locale.US) private val dayFmt = SimpleDateFormat("yyyy-MM-dd", Locale.US) + // 실시간 파일 기록 (화면 잠금/앱 종료에도 보존) + private var liveLogFile: File? = null + private fun ensureLiveLogFile(): File { + if (liveLogFile == null) { + val downloadsDir = android.os.Environment.getExternalStoragePublicDirectory(android.os.Environment.DIRECTORY_DOWNLOADS) + liveLogFile = File(downloadsDir, "VesiScan_BLE_${dateFmt.format(Date())}.log") + } + return liveLogFile!! + } + private fun appendToFile(line: String) { + try { + ensureLiveLogFile().appendText(line + "\n") + } catch (_: Exception) {} + } + // ── Logging Methods ── fun tx(command: String, dataSize: Int = 0) { @@ -106,6 +121,11 @@ class BleDebugLogger private constructor(private val context: Context) { sessionStart = System.currentTimeMillis() txCount = 0; rxCount = 0; errorCount = 0; packetTimeouts = 0; channelMissCount = 0 rssiHistory.clear() + liveLogFile = null // 새 세션 → 새 파일 + appendToFile("=== VesiScan BLE Debug Log ===") + appendToFile("Device: $name") + appendToFile("Session: ${dateFmt.format(Date())}") + appendToFile("============================================================") add(Entry(System.currentTimeMillis(), Level.CONN, "CONNECTED $name ($address)")) } @@ -175,6 +195,7 @@ class BleDebugLogger private constructor(private val context: Context) { if (entries.size > MAX_MEMORY_ENTRIES) { entries.removeAt(0) } + appendToFile(entry.toLogLine()) } fun getEntries(): List = entries.toList()