From 2b3bdae4407604a1f2509a0fb68388fc6e1bd44c Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 6 Apr 2026 08:03:28 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20enable=20Rust=20tracing=20=E2=86=92=20An?= =?UTF-8?q?droid=20logcat=20via=20tracing-android?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Rust tracing subscriber was never initialized — all info!/warn!/error! calls in the engine went to /dev/null. This meant our send/recv health logging was invisible and we couldn't confirm the congestion fix was active. Now initializes tracing-android layer on first nativeInit(), routing all Rust logs to logcat under tag "wzp_android". Also expanded logcat filter in DebugReporter to capture engine-level log lines. Co-Authored-By: Claude Opus 4.6 (1M context) --- .../src/main/java/com/wzp/debug/DebugReporter.kt | 11 ++++++++++- crates/wzp-android/Cargo.toml | 1 + crates/wzp-android/src/jni_bridge.rs | 16 ++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/android/app/src/main/java/com/wzp/debug/DebugReporter.kt b/android/app/src/main/java/com/wzp/debug/DebugReporter.kt index 38c32d7..02d6e25 100644 --- a/android/app/src/main/java/com/wzp/debug/DebugReporter.kt +++ b/android/app/src/main/java/com/wzp/debug/DebugReporter.kt @@ -138,7 +138,16 @@ class DebugReporter(private val context: Context) { line.contains("AudioFlinger") || line.contains("DebugReporter") || line.contains("QUIC") || - line.contains("quinn") + line.contains("quinn") || + line.contains("send task") || + line.contains("recv task") || + line.contains("send stats") || + line.contains("recv stats") || + line.contains("send_media") || + line.contains("FEC block") || + line.contains("recv gap") || + line.contains("frames_dropped") || + line.contains("opus") } .joinToString("\n") } catch (e: Exception) { diff --git a/crates/wzp-android/Cargo.toml b/crates/wzp-android/Cargo.toml index 3fcd32b..c13e3f2 100644 --- a/crates/wzp-android/Cargo.toml +++ b/crates/wzp-android/Cargo.toml @@ -28,6 +28,7 @@ libc = "0.2" jni = { version = "0.21", default-features = false } rand = { workspace = true } rustls = { version = "0.23", default-features = false, features = ["ring"] } +tracing-android = "0.2" [build-dependencies] cc = "1" diff --git a/crates/wzp-android/src/jni_bridge.rs b/crates/wzp-android/src/jni_bridge.rs index 2c728fc..54e8614 100644 --- a/crates/wzp-android/src/jni_bridge.rs +++ b/crates/wzp-android/src/jni_bridge.rs @@ -1,6 +1,7 @@ //! JNI bridge for Android — thin layer between Kotlin and the WzpEngine. use std::panic; +use std::sync::Once; use jni::objects::{JClass, JObject, JString}; use jni::sys::{jboolean, jint, jlong, jstring}; @@ -28,12 +29,27 @@ fn profile_from_int(value: jint) -> QualityProfile { } } +static INIT_LOGGING: Once = Once::new(); + +/// Initialize tracing → Android logcat (tag "wzp_android"). +/// Safe to call multiple times — only the first call takes effect. +fn init_logging() { + INIT_LOGGING.call_once(|| { + use tracing_subscriber::layer::SubscriberExt; + use tracing_subscriber::util::SubscriberInitExt; + if let Ok(layer) = tracing_android::layer("wzp_android") { + let _ = tracing_subscriber::registry().with(layer).try_init(); + } + }); +} + #[unsafe(no_mangle)] pub unsafe extern "system" fn Java_com_wzp_engine_WzpEngine_nativeInit( _env: JNIEnv, _class: JClass, ) -> jlong { let result = panic::catch_unwind(|| { + init_logging(); let handle = Box::new(EngineHandle { engine: WzpEngine::new(), });