diff --git a/README.md b/README.md index 3a91435..ae887de 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ NavFrame is an experimental Android navigation app that renders its own 480×240 The owner has confirmed static and synthetic NavFrame frames on a Xiaomi 11 Lite 5G NE running Android 14 and a 2026 Yamaha MT-07, and the bundled Asturias map working offline on the phone. On 2026-10-12, the owner reported that the latest version displayed the map on the TFT for about 20 minutes, then showed `Mapa no disponible` in La Corredoria (Oviedo) for the rest of the trip while the phone map continued working. An offline map was installed. The exact installed build, diagnostic code and background state were not recorded; the cause is under investigation. This establishes a successful map display followed by a persistent failure, not sustained TFT reliability. -The current checkout is version 0.13.5. The 0.13 series adds voice/routing language selection for Spanish, English, German, French, and Italian, plus a system-language option; unsupported system locales resolve to English. Speech still depends on the Android TextToSpeech engine and its installed voice data. The app includes offline map and place data for Asturias, plus installable regional packages. Worldwide regions can be discovered and built on demand through the [regional package workflow](docs/GLOBAL_OFFLINE.md); this is not complete worldwide coverage. Installed packages currently provide map and local place/camera data. Offline route calculation, global camera completeness, and complete worldwide font coverage are not provided. +The current checkout is version 0.13.6. The 0.13 series adds voice/routing language selection for Spanish, English, German, French, and Italian, plus a system-language option; unsupported system locales resolve to English. Speech still depends on the Android TextToSpeech engine and its installed voice data. The app includes offline map and place data for Asturias, plus installable regional packages. Worldwide regions can be discovered and built on demand through the [regional package workflow](docs/GLOBAL_OFFLINE.md); this is not complete worldwide coverage. Installed packages currently provide map and local place/camera data. Offline route calculation, global camera completeness, and complete worldwide font coverage are not provided. Route calculation and address search use configurable online services. Spoken output uses the selected language when Android provides voice data; voice availability and offline behavior depend on the device's TextToSpeech engine. Physical validation of route guidance, voice playback, camera alerts, sustained TFT map rendering, and a 30-minute screen-off session remains pending unless a newer test report says otherwise. diff --git a/app/build.gradle.kts b/app/build.gradle.kts index f0b7c41..2574c92 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -15,8 +15,8 @@ android { applicationId = "dev.navframe.app" minSdk = 26 targetSdk = 35 - versionName = "0.13.5" - versionCode = 21 + versionName = "0.13.6" + versionCode = 22 } if (hasReleaseSigning) { signingConfigs.create("production") { diff --git a/app/src/main/java/dev/navframe/app/MapDiagnosticHistory.kt b/app/src/main/java/dev/navframe/app/MapDiagnosticHistory.kt index 97a2da7..56908c2 100644 --- a/app/src/main/java/dev/navframe/app/MapDiagnosticHistory.kt +++ b/app/src/main/java/dev/navframe/app/MapDiagnosticHistory.kt @@ -33,17 +33,30 @@ internal data class MapDiagnosticEvent( val connection: ConnectionState, val androidApi: Int, val appVersion: String = BuildConfig.VERSION_NAME, + val errorClass: String = "SDK_CALLBACK", + val sdkEvidence: String = "", + val firstTimestampMs: Long = timestampMs, + val occurrences: Int = 1, + val screenInteractive: Boolean? = null, + val lowMemory: Boolean? = null, + val availableMemoryMb: Long? = null, ) { init { require(timestampMs >= 0 && durationMs >= 0 && retryMs >= 0 && attempts in 1..4) require(androidApi > 0 && appVersion.matches(Regex("[0-9]+(?:\\.[0-9]+){1,3}"))) + require(availableMemoryMb == null || availableMemoryMb >= 0) + require(firstTimestampMs in 0..timestampMs && occurrences > 0) + require(errorClass.matches(Regex("[A-Za-z0-9_$]{1,80}"))) + require(sdkEvidence.isEmpty() || sdkEvidence.matches(Regex("[A-Z_]{1,256}"))) require(httpStatus == null || httpStatus in 400..599) require((kind == MapDiagnosticKind.FAILURE) == (failure != null)) } fun reportLine(): String = "${Instant.ofEpochMilli(timestampMs)} · ${kind.name} · NavFrame $appVersion · Android $androidApi · MapLibre 13.5.2\n" + - "${source.name} · red ${network.name} · ${failure?.name ?: "OK"}/${stage.name} · ${resource.name}/${reason.name}${httpStatus?.let { "/HTTP_$it" } ?: ""}\n" + - "$durationMs ms · intento $attempts · reintento $retryMs ms · ${mode.name} · ${navigation.name} · TFT ${connection.name}" + "${source.name} · red ${network.name} · ${failure?.name ?: "OK"}/${stage.name} · ${resource.name}/${reason.name}${httpStatus?.let { "/HTTP_$it" } ?: ""}/$errorClass${if (sdkEvidence.isEmpty()) "" else "/WORDS_$sdkEvidence"}\n" + + "$durationMs ms · intento $attempts · reintento $retryMs ms · ${mode.name} · ${navigation.name} · TFT ${connection.name}" + + "\nPantalla ${screenInteractive?.let { if (it) "ENCENDIDA" else "APAGADA" } ?: "UNKNOWN"} · memoria baja ${lowMemory ?: "UNKNOWN"} · disponible ${availableMemoryMb ?: "UNKNOWN"} MiB" + + if (occurrences == 1) "" else "\nAgrupado: $occurrences fallos · primero ${Instant.ofEpochMilli(firstTimestampMs)} · último ${Instant.ofEpochMilli(timestampMs)} · estados del último fallo" fun toJson(): JSONObject = JSONObject().put("kind", kind.name).put("timestampMs", timestampMs) .put("source", source.name).put("network", network.name).put("stage", stage.name) @@ -51,6 +64,10 @@ internal data class MapDiagnosticEvent( .put("httpStatus", httpStatus ?: JSONObject.NULL).put("durationMs", durationMs).put("attempts", attempts) .put("retryMs", retryMs).put("mode", mode.name).put("navigation", navigation.name) .put("connection", connection.name).put("androidApi", androidApi).put("appVersion", appVersion) + .put("errorClass", errorClass).put("sdkEvidence", sdkEvidence) + .put("firstTimestampMs", firstTimestampMs).put("occurrences", occurrences) + .put("screenInteractive", screenInteractive ?: JSONObject.NULL).put("lowMemory", lowMemory ?: JSONObject.NULL) + .put("availableMemoryMb", availableMemoryMb ?: JSONObject.NULL) companion object { fun fromJson(value: JSONObject) = MapDiagnosticEvent( @@ -64,6 +81,12 @@ internal data class MapDiagnosticEvent( mode = NavigationMode.valueOf(value.getString("mode")), navigation = NavigationStatus.valueOf(value.getString("navigation")), connection = ConnectionState.valueOf(value.getString("connection")), androidApi = value.getInt("androidApi"), appVersion = value.getString("appVersion"), + errorClass = value.optString("errorClass", "SDK_CALLBACK"), sdkEvidence = value.optString("sdkEvidence", ""), + firstTimestampMs = value.optLong("firstTimestampMs", value.getLong("timestampMs")), + occurrences = value.optInt("occurrences", 1), + screenInteractive = if (value.isNull("screenInteractive")) null else value.getBoolean("screenInteractive"), + lowMemory = if (value.isNull("lowMemory")) null else value.getBoolean("lowMemory"), + availableMemoryMb = if (value.isNull("availableMemoryMb")) null else value.getLong("availableMemoryMb"), ) } } @@ -78,7 +101,17 @@ internal class MapDiagnosticHistory(private val directory: File) { try { // An unreadable history cannot supply diagnostic text; the next event starts a clean history. val previous = try { readEvents() } catch (_: Exception) { emptyList() } - val events = (previous + event).takeLast(MAX_EVENTS) + val last = previous.lastOrNull() + // Keep the initial retries, then summarize identical saturated retries without losing onset. + val repeated = last != null && event.kind == MapDiagnosticKind.FAILURE && last.kind == event.kind && + last.attempts == 4 && event.attempts == 4 && event.timestampMs >= last.timestampMs && + last.source == event.source && last.failure == event.failure && last.stage == event.stage && + last.resource == event.resource && last.reason == event.reason && last.httpStatus == event.httpStatus && + last.errorClass == event.errorClass && last.sdkEvidence == event.sdkEvidence && + last.mode == event.mode && last.appVersion == event.appVersion && last.androidApi == event.androidApi + val events = if (repeated) previous.dropLast(1) + event.copy( + firstTimestampMs = last!!.firstTimestampMs, occurrences = (last.occurrences.toLong() + 1).coerceAtMost(Int.MAX_VALUE.toLong()).toInt() + ) else (previous + event).takeLast(MAX_EVENTS) val bytes = JSONArray(events.map { it.toJson() }).toString().toByteArray(Charsets.UTF_8) check(bytes.size <= MAX_BYTES) val output = atomic.startWrite() diff --git a/app/src/main/java/dev/navframe/app/MapLibreTftRenderer.kt b/app/src/main/java/dev/navframe/app/MapLibreTftRenderer.kt index e0270c2..59c9802 100644 --- a/app/src/main/java/dev/navframe/app/MapLibreTftRenderer.kt +++ b/app/src/main/java/dev/navframe/app/MapLibreTftRenderer.kt @@ -94,7 +94,9 @@ class MapLibreTftRenderer(context: Context, private val source: MapDataSource, p }) } } + phase(MapRenderStage.CAMERA_UPDATE) current.setCameraPosition(cameraPosition) + phase(MapRenderStage.ROUTE_UPDATE) (current.getSource("navframe-route") as? GeoJsonSource)?.setGeoJson(routeGeoJson(state.route)) continuation.invokeOnCancellation { // An old callback must not be delivered into a new capture: discard after cancellation/error. @@ -103,6 +105,7 @@ class MapLibreTftRenderer(context: Context, private val source: MapDataSource, p } try { phase(if (current.getSource("navframe-route") == null) MapRenderStage.STYLE_LOADING else MapRenderStage.STYLE_READY) + phase(MapRenderStage.SNAPSHOT_REQUESTED) current.start({ snapshot -> if (continuation.isActive && !closed && snapshotter === current) phase(MapRenderStage.SNAPSHOT_READY) val bitmap = snapshot.bitmap @@ -120,7 +123,7 @@ class MapLibreTftRenderer(context: Context, private val source: MapDataSource, p main.post { current.cancel() if (snapshotter === current) snapshotter = null - if (continuation.isActive) continuation.resumeWithException(MapRenderException(classifyMapRenderFailure(reason), stage, mapErrorDetail(reason))) + if (continuation.isActive) continuation.resumeWithException(MapRenderException(classifyMapRenderFailure(reason), stage, mapErrorDetail(reason, "SnapshotterErrorCallback"))) } }) } catch (error: Exception) { diff --git a/app/src/main/java/dev/navframe/app/MapRenderDiagnostics.kt b/app/src/main/java/dev/navframe/app/MapRenderDiagnostics.kt index 3618df9..5744760 100644 --- a/app/src/main/java/dev/navframe/app/MapRenderDiagnostics.kt +++ b/app/src/main/java/dev/navframe/app/MapRenderDiagnostics.kt @@ -1,24 +1,26 @@ package dev.navframe.app /** Only fixed labels cross this boundary; SDK messages can contain coordinates, URLs and access tokens. */ -enum class MapRenderStage { INITIALIZE, STYLE_LOADING, STYLE_READY, SNAPSHOT_READY, COMPOSE } +enum class MapRenderStage { INITIALIZE, STYLE_LOADING, STYLE_READY, CAMERA_UPDATE, ROUTE_UPDATE, SNAPSHOT_REQUESTED, SNAPSHOT_READY, COMPOSE } enum class MapRenderFailure { TIMEOUT, NETWORK, STYLE, GPU, BITMAP, SDK } -enum class MapResourceKind { GLYPH, SPRITE, TILE, GEOJSON, STYLE, BITMAP, UNKNOWN } -enum class MapFailureReason { DNS, FORBIDDEN, NOT_FOUND, CONTEXT_LOST, EGL, MEMORY, PARSE, CONNECTION, UNKNOWN } -data class MapErrorDetail(val resource: MapResourceKind = MapResourceKind.UNKNOWN, val reason: MapFailureReason = MapFailureReason.UNKNOWN, val httpStatus: Int? = null, val errorClass: String = "SDK_CALLBACK") { - fun safeText(): String = "${resource.name}/${reason.name}${httpStatus?.let { "/HTTP_$it" } ?: ""}/${errorClass.takeIf { it.matches(Regex("[A-Za-z0-9_$]{1,80}")) } ?: "OTHER"}" +enum class MapResourceKind { GLYPH, SPRITE, TILE, GEOJSON, STYLE, BITMAP, PMTILES, FILE, UNKNOWN } +enum class MapFailureReason { DNS, FORBIDDEN, NOT_FOUND, CONTEXT_LOST, EGL, MEMORY, PARSE, CONNECTION, IO, CANCELLED, EMPTY, UNSUPPORTED, UNKNOWN } +data class MapErrorDetail(val resource: MapResourceKind = MapResourceKind.UNKNOWN, val reason: MapFailureReason = MapFailureReason.UNKNOWN, val httpStatus: Int? = null, val errorClass: String = "SDK_CALLBACK", val sdkEvidence: String = "") { + fun safeText(): String = "${resource.name}/${reason.name}${httpStatus?.let { "/HTTP_$it" } ?: ""}/${errorClass.takeIf { it.matches(Regex("[A-Za-z0-9_$]{1,80}")) } ?: "OTHER"}${if (sdkEvidence.isEmpty()) "" else "/WORDS_${sdkEvidence}"}" } class MapRenderException(val failure: MapRenderFailure, val stage: MapRenderStage, val detail: MapErrorDetail = MapErrorDetail()) : Exception("${failure.name}:${stage.name}:${detail.safeText()}") internal fun mapErrorDetail(message: String?, errorClass: String = "SDK_CALLBACK"): MapErrorDetail { - val text = message.orEmpty().lowercase(java.util.Locale.ROOT) - val status = Regex("\\b(?:http(?: status| error)?|status(?: code)?|server returned)\\D{0,12}([45]\\d{2})\\b").find(text)?.groupValues?.get(1)?.toIntOrNull() + val text = safeSdkEvidence(message).lowercase(java.util.Locale.ROOT).replace('_', ' ') + val status = Regex("\\b(?:http(?: status| error)?|status(?: code)?|server returned)\\D{0,12}([45]\\d{2})\\b").find(message.orEmpty().lowercase(java.util.Locale.ROOT))?.groupValues?.get(1)?.toIntOrNull() val resource = when { + text.contains("pmtiles") -> MapResourceKind.PMTILES listOf("glyph", "font").any(text::contains) -> MapResourceKind.GLYPH text.contains("sprite") -> MapResourceKind.SPRITE text.contains("geojson") -> MapResourceKind.GEOJSON text.contains("tile") || text.contains(".pbf") -> MapResourceKind.TILE text.contains("style") || text.contains("json") -> MapResourceKind.STYLE text.contains("bitmap") || text.contains("canvas") -> MapResourceKind.BITMAP + text.contains("file") || text.contains("archive") -> MapResourceKind.FILE else -> MapResourceKind.UNKNOWN } val reason = when { @@ -30,12 +32,16 @@ internal fun mapErrorDetail(message: String?, errorClass: String = "SDK_CALLBACK text.contains("memory") -> MapFailureReason.MEMORY text.contains("parse") -> MapFailureReason.PARSE text.contains("connection") || text.contains("socket") -> MapFailureReason.CONNECTION + text.contains("cancel") -> MapFailureReason.CANCELLED + text.contains("unsupported") || text.contains("not supported") -> MapFailureReason.UNSUPPORTED + text.contains("no such file") || text.contains("permission denied") || text.contains("read error") || text.contains("failed read") || text.contains("failed to read") || text.contains("failed open") || text.contains("failed to open") || text.contains("cannot read") || text.contains("cannot open") || text.contains("i/o") -> MapFailureReason.IO + message.isNullOrBlank() -> MapFailureReason.EMPTY else -> MapFailureReason.UNKNOWN } - return MapErrorDetail(resource, reason, status, errorClass) + return MapErrorDetail(resource, reason, status, errorClass, safeSdkEvidence(message)) } internal fun classifyMapRenderFailure(message: String?): MapRenderFailure { - val text = message.orEmpty().lowercase(java.util.Locale.ROOT) + val text = safeSdkEvidence(message).lowercase(java.util.Locale.ROOT).replace('_', ' ') return when { listOf("egl", "opengl", "framebuffer", "shader", "gl context", "gl_context", "graphics context", "gpu").any(text::contains) -> MapRenderFailure.GPU mapErrorDetail(message).httpStatus != null || listOf("resolve", "dns", "network", "connection", "socket", "server returned", "request failed", "failed to load resource", "failed to load tile", "failed to load glyph", "download").any(text::contains) -> MapRenderFailure.NETWORK @@ -44,3 +50,16 @@ internal fun classifyMapRenderFailure(message: String?): MapRenderFailure { else -> MapRenderFailure.SDK } } + +/** Preserve only known diagnostic vocabulary, never arbitrary SDK text or identifiers. */ +internal fun safeSdkEvidence(message: String?): String { + if (message.isNullOrBlank()) return "EMPTY" + val allowed = setOf("failed", "failure", "error", "exception", "load", "loading", "loaded", "style", "map", "snapshot", "snapshotter", "render", "rendering", "fully", "tile", "tiles", "data", "no", "not", "missing", "empty", "invalid", "corrupt", "unsupported", "resource", "request", "cancelled", "canceled", "cancel", "timeout", "timed", "out", "file", "archive", "pmtiles", "read", "write", "open", "permission", "denied", "such", "directory", "end", "unexpected", "parse", "parsing", "json", "geojson", "glyph", "glyphs", "font", "sprite", "image", "bitmap", "memory", "allocation", "context", "lost", "egl", "opengl", "framebuffer", "shader", "gpu", "network", "connection", "socket", "resolve", "dns", "http", "status", "code", "server", "returned", "forbidden", "found", "active", "already", "started", "finished", "destroyed", "source", "sources", "size", "dimensions", "download", "unable", "cannot", "could", "compression", "compressed", "gzip", "zstd", "protobuf", "decode", "decoding", "truncated", "eof", "i", "o", "to", "of", "is", "been", "has", "was", "be", "gl", "graphics", "canvas", "layer", "supported") + // Strip entire URLs, paths and quoted payloads before vocabulary extraction. + val stripped = message.lowercase(java.util.Locale.ROOT) + .replace(Regex("""[a-z][a-z0-9+.-]*://\S+"""), " ") + .replace(Regex("""[/\\]\S+"""), " ") + .replace(Regex("""["'][^"']*["']"""), " ") + val words = Regex("[a-z]+").findAll(stripped).map { it.value }.filter { it in allowed }.take(24).toList() + return if (words.isEmpty()) "UNCLASSIFIED" else words.joinToString("_").uppercase(java.util.Locale.ROOT).take(240).trimEnd('_') +} diff --git a/app/src/main/java/dev/navframe/app/TftService.kt b/app/src/main/java/dev/navframe/app/TftService.kt index 168fac5..cdd5eab 100644 --- a/app/src/main/java/dev/navframe/app/TftService.kt +++ b/app/src/main/java/dev/navframe/app/TftService.kt @@ -825,13 +825,16 @@ class TftService : Service() { mutableMapDiagnostic.value = "TFT MAP · ${error.failure.name} · ${error.stage.name} · ${SystemClock.elapsedRealtime() - mapRenderStarted} ms · ${error.detail.safeText()} · intento $mapFailures · reintento ${retryMs / 1000} s" lastMapFailureDiagnostic = mutableMapDiagnostic.value + " · " + if (mapSource().uri.startsWith("file:")) "LOCAL" else "ONLINE" mutableNavigationInfo.value = "MAPA TFT NO DISPONIBLE · ${error.failure.name} · reintento ${retryMs / 1000} s" - android.util.Log.w("NavFrame", "MAP_UNAVAILABLE code=${error.failure.name} stage=${error.stage.name} retryMs=$retryMs") // No URLs, API tokens or coordinates. + android.util.Log.w("NavFrame", "MAP_UNAVAILABLE code=${error.failure.name} stage=${error.stage.name} detail=${error.detail.safeText()} retryMs=$retryMs") // No URLs, API tokens or coordinates. recordMapEvent(MapDiagnosticKind.FAILURE, state, mode, source, retryMs, error) return MapFrameComposer().compose(null, null, state, mode, source.attribution, unavailable = true, failureCode = error.failure.name).also { unavailableMapFrame = it } } private suspend fun recordMapEvent(kind: MapDiagnosticKind, state: NavigationState, mode: NavigationMode, source: TileSource, retryMs: Long, error: MapRenderException? = null) { val network = mapRenderer?.networkConnected ?: lastMapNetworkConnected + val memory = android.app.ActivityManager.MemoryInfo() + val memoryAvailable = runCatching { getSystemService(android.app.ActivityManager::class.java).getMemoryInfo(memory) }.isSuccess + val interactive = runCatching { getSystemService(android.os.PowerManager::class.java).isInteractive }.getOrNull() val event = MapDiagnosticEvent( kind = kind, timestampMs = System.currentTimeMillis(), source = if (source.uri.startsWith("file:")) MapDiagnosticSource.LOCAL else MapDiagnosticSource.ONLINE, @@ -839,6 +842,10 @@ class TftService : Service() { stage = error?.stage ?: MapRenderStage.COMPOSE, failure = error?.failure, resource = error?.detail?.resource ?: MapResourceKind.UNKNOWN, reason = error?.detail?.reason ?: MapFailureReason.UNKNOWN, httpStatus = error?.detail?.httpStatus?.takeIf { it in 400..599 }, + errorClass = error?.detail?.errorClass?.takeIf { it.matches(Regex("[A-Za-z0-9_$]{1,80}")) } ?: "OTHER", + sdkEvidence = error?.detail?.sdkEvidence.orEmpty(), + screenInteractive = interactive, lowMemory = if (memoryAvailable) memory.lowMemory else null, + availableMemoryMb = if (memoryAvailable) (memory.availMem / (1024 * 1024)).coerceAtLeast(0) else null, durationMs = (SystemClock.elapsedRealtime() - mapRenderStarted).coerceAtLeast(0), attempts = mapFailures, retryMs = retryMs, mode = mode, navigation = state.navigationStatus, connection = mutableState.value, androidApi = Build.VERSION.SDK_INT, diff --git a/app/src/test/java/dev/navframe/app/MapDiagnosticHistoryTest.kt b/app/src/test/java/dev/navframe/app/MapDiagnosticHistoryTest.kt index 5901d67..543e4c2 100644 --- a/app/src/test/java/dev/navframe/app/MapDiagnosticHistoryTest.kt +++ b/app/src/test/java/dev/navframe/app/MapDiagnosticHistoryTest.kt @@ -43,7 +43,8 @@ class MapDiagnosticHistoryTest { @Test fun committedFailuresAndRecoverySurviveNewStoreInstancesWithoutNativeMessages() { val raw = "Failed to load glyph https://private.example/fonts?token=secret HTTP status 403 at 43.361234,-5.856789" val detail = mapErrorDetail(raw) - val failure = event().copy(failure = classifyMapRenderFailure(raw), resource = detail.resource, reason = detail.reason, httpStatus = detail.httpStatus) + val failure = event().copy(failure = classifyMapRenderFailure(raw), resource = detail.resource, reason = detail.reason, httpStatus = detail.httpStatus, + sdkEvidence = detail.sdkEvidence, errorClass = "SDK_CALLBACK", screenInteractive = false, lowMemory = true, availableMemoryMb = 42) assertTrue(store.record(failure)) assertTrue(store.record(event(kind = MapDiagnosticKind.RECOVERED))) val reopened = MapDiagnosticHistory(context) @@ -72,6 +73,38 @@ class MapDiagnosticHistoryTest { assertFalse(store.file.exists()) } + @Test fun repeatedSaturatedFailuresPreserveOnsetAndRecoveryInsteadOfEvictingIt() { + for (index in 1..3) assertTrue(store.record(event(timestamp = index.toLong()).copy(attempts = index))) + for (index in 4..204) assertTrue(store.record(event(timestamp = index.toLong()).copy(attempts = 4))) + assertTrue(store.record(event(timestamp = 205, kind = MapDiagnosticKind.RECOVERED).copy(attempts = 4))) + val report = MapDiagnosticHistory(context).report() + assertTrue(report.contains("(5/100)")) + assertTrue(report.contains("1970-01-01T00:00:00.001Z")) + assertTrue(report.contains("Agrupado: 201 fallos")) + assertTrue(report.contains("primero 1970-01-01T00:00:00.004Z")) + assertTrue(report.contains("último 1970-01-01T00:00:00.204Z")) + assertTrue(report.contains("RECOVERED")) + assertTrue(store.record(event(timestamp = 206))) + assertTrue(store.report().contains("(6/100)")) + } + + @Test fun legacyHistoryRemainsReadableAndNewEvidenceIsPersisted() { + val json = event().toJson() + for (key in listOf("errorClass", "sdkEvidence", "firstTimestampMs", "occurrences", "screenInteractive", "lowMemory", "availableMemoryMb")) json.remove(key) + store.file.parentFile!!.mkdirs() + store.file.writeText(org.json.JSONArray().put(json).toString()) + assertTrue(store.report().contains("TIMEOUT/STYLE_READY")) + val raw = "Snapshot failed no tile data https://private.example?token=secret" + val detail = mapErrorDetail(raw) + assertTrue(store.record(event(timestamp = 1_792_000_000_001).copy(sdkEvidence = detail.sdkEvidence, + screenInteractive = false, lowMemory = true, availableMemoryMb = 42))) + val report = MapDiagnosticHistory(context).report() + assertTrue(report.contains("WORDS_SNAPSHOT_FAILED_NO_TILE_DATA")) + assertTrue(report.contains("Pantalla APAGADA")) + assertTrue(report.contains("disponible 42 MiB")) + assertFalse(store.file.readText().contains("private.example")) + } + @Test fun interruptedAtomicReplacementLeavesTheLastCommittedHistoryReadable() { assertTrue(store.record(event())) val previous = store.report() diff --git a/app/src/test/java/dev/navframe/app/MapRenderDiagnosticsTest.kt b/app/src/test/java/dev/navframe/app/MapRenderDiagnosticsTest.kt index e41fd05..f323e39 100644 --- a/app/src/test/java/dev/navframe/app/MapRenderDiagnosticsTest.kt +++ b/app/src/test/java/dev/navframe/app/MapRenderDiagnosticsTest.kt @@ -25,7 +25,7 @@ class MapRenderDiagnosticsTest { val raw = "Failed to load style glyph https://private.example/fonts.pbf?token=secret: HTTP status 403; location 43.361234,-5.856789" assertEquals(MapRenderFailure.NETWORK, classifyMapRenderFailure(raw)) val detail = mapErrorDetail(raw) - assertEquals("GLYPH/FORBIDDEN/HTTP_403/SDK_CALLBACK", detail.safeText()) + assertTrue(detail.safeText().startsWith("GLYPH/FORBIDDEN/HTTP_403/SDK_CALLBACK/WORDS_")) assertEquals(MapRenderFailure.NETWORK, classifyMapRenderFailure("Failed to load style: could not resolve private-host")) assertFalse(detail.safeText().contains("private")) assertFalse(detail.safeText().contains("secret")) @@ -36,4 +36,17 @@ class MapRenderDiagnosticsTest { assertEquals("TIMEOUT:STYLE_READY:UNKNOWN/UNKNOWN/SDK_CALLBACK", failure.message) assertNotEquals(MapRenderFailure.NETWORK, failure.failure) } + @Test fun unknownCallbackRetainsOnlyDiagnosticVocabulary() { + val raw = "Snapshot failed: no tile data private-address 43.361234,-5.856789 https://private.example/style?token=secret /data/user/0/private-map.pmtiles" + val detail = mapErrorDetail(raw) + assertEquals("SNAPSHOT_FAILED_NO_TILE_DATA", detail.sdkEvidence) + assertEquals("EMPTY", mapErrorDetail(null).sdkEvidence) + assertEquals(MapFailureReason.EMPTY, mapErrorDetail("").reason) + assertEquals("UNCLASSIFIED", mapErrorDetail("private-secret-name").sdkEvidence) + assertEquals(MapFailureReason.IO, mapErrorDetail("Cannot read PMTiles archive: permission denied").reason) + assertEquals(MapResourceKind.PMTILES, mapErrorDetail("Cannot read PMTiles archive: permission denied").resource) + assertTrue(safeSdkEvidence("failed ".repeat(1000)).length <= 240) + assertEquals("FAILED", safeSdkEvidence("failed \"private map tile\" https://host/map/tile/43 /private/map/file")) + } + } diff --git a/docs/TFT_DIAGNOSTICS.md b/docs/TFT_DIAGNOSTICS.md index 1363954..42b70ae 100644 --- a/docs/TFT_DIAGNOSTICS.md +++ b/docs/TFT_DIAGNOSTICS.md @@ -14,11 +14,13 @@ Each event contains its UTC timestamp, app version, Android API level, MapLibre The backoff attempt is capped at four, like the renderer's existing retry policy. Repeated failures continue to create separate timestamped records after that limit. Only the first successful render following failures creates a recovery record; normal successful frames are not logged. +From 0.13.6, diagnostics also retain the callback/exception class, a bounded sequence of allowlisted SDK diagnostic words (`WORDS_...`), screen interactive state, low-memory status and available system memory. Render stages distinguish camera updates, route GeoJSON updates and snapshot requests; native snapshot failure callbacks carry `SnapshotterErrorCallback` rather than the generic `SDK_CALLBACK`. URL/path/quoted payloads are removed before extracting known diagnostic words. An empty callback is distinguished from an unclassified nonempty message. This exposes messages such as snapshot/failed/no/tile/data without copying arbitrary SDK text. These fields are evidence, not proof that memory or screen state caused the failure. + Raw SDK messages, stack traces, URLs, tokens, coordinates, route geometry, destinations, search text, and Bluetooth identifiers are excluded. The history contains fixed labels and numbers, not a copy of Logcat. Network state is diagnostic context: a disconnected network does not itself explain a failure of a selected local map. ## Storage and limits -The history is a private app file named `tft-map-diagnostics.json` in Android's `noBackupFilesDir`. No storage permission is required; the app does not upload it automatically, and it is excluded from backup/device transfer. The file retains the latest 100 failure/recovery events and is bounded at 128 KiB. Older events are discarded when the limit is reached. +The history is a private app file named `tft-map-diagnostics.json` in Android's `noBackupFilesDir`. No storage permission is required; the app does not upload it automatically, and it is excluded from backup/device transfer. The file retains up to 100 failure/recovery records and is bounded at 128 KiB. Starting with 0.13.6, consecutive identical failures at the maximum retry backoff are grouped into one record with an occurrence count and first/last UTC timestamps. Initial retries and recovery records remain separate; the aggregate shows the latest navigation, network and TFT states. Changes in error classification, source, mode or app version start a new record. This prevents a long stream of identical failures from immediately erasing its onset. Older records are discarded when the limit is reached. Existing 0.13.2–0.13.5 files remain readable; previously evicted events cannot be recovered. File operations run on an IO dispatcher. Writes are synced and replaced atomically, so an interrupted replacement preserves the previous completed history. A failure that occurs while a shutdown interrupts its write may not be retained. Clearing app data or uninstalling NavFrame deletes the history.