From 2092f6c7166c602501ae314150bc8d9f3ab7c1d6 Mon Sep 17 00:00:00 2001 From: ospab Date: Fri, 10 Jul 2026 01:23:28 +0300 Subject: [PATCH] fix(flutter/android): surface getMetrics failures into the in-app log Traced the whole traffic-counter pipeline (Dart -> MethodChannel -> Kotlin -> JNI -> Bridge) end to end; it's architecturally identical to the working desktop implementation, so no code-level bug was found. Previously a getMetrics exception was only reported as a PlatformException that Dart swallows with a bare debugPrint, invisible in the in-app log viewer users actually have access to. Now it's also written to the native log buffer via OstpClientSdk.addLog, so if the counter breaks again the actual cause (exception vs. genuinely-zero atomics) shows up in View Logs instead of requiring adb. --- .../src/main/kotlin/com/ospab/ostp_client/MainActivity.kt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ostp-flutter/android/app/src/main/kotlin/com/ospab/ostp_client/MainActivity.kt b/ostp-flutter/android/app/src/main/kotlin/com/ospab/ostp_client/MainActivity.kt index 750d4d3..0d042d6 100644 --- a/ostp-flutter/android/app/src/main/kotlin/com/ospab/ostp_client/MainActivity.kt +++ b/ostp-flutter/android/app/src/main/kotlin/com/ospab/ostp_client/MainActivity.kt @@ -92,6 +92,13 @@ class MainActivity : FlutterActivity() { val metrics = net.ostp.client.OstpClientSdk.getMetrics() result.success(metrics ?: "{}") } catch (e: Throwable) { + // Surfaced into the in-app log viewer (not just logcat) so a + // broken traffic counter is diagnosable from a user's bug + // report without adb access. + android.util.Log.e("MainActivity", "getMetrics failed", e) + try { + net.ostp.client.OstpClientSdk.addLog("getMetrics failed: ${e.javaClass.simpleName}: ${e.message}") + } catch (_: Throwable) {} result.error("ERROR", e.message, null) } }