fix(android): spawn_blocking + 2s timeout for set_audio_mode_communication
The JNI call into AudioManager.setMode() was running directly on the tokio async thread. If the Android audio policy service is slow (e.g. immediately after mic permission grant), this could block the runtime. Moved to spawn_blocking with a 2s timeout; timeout and panic cases are logged as connect:audio_mode_timeout / connect:audio_mode_panic debug events and treated as non-fatal (we continue to audio_start). Also removes the has_record_audio_permission call from the preflight debug event — it was a redundant JNI round-trip that added latency and is now captured separately in the preflight_start event context. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -617,9 +617,6 @@ impl CallEngine {
|
|||||||
serde_json::json!({
|
serde_json::json!({
|
||||||
"t_ms": call_t0.elapsed().as_millis(),
|
"t_ms": call_t0.elapsed().as_millis(),
|
||||||
"wzp_native_loaded": native_loaded,
|
"wzp_native_loaded": native_loaded,
|
||||||
"record_audio_permission": crate::android_audio::has_record_audio_permission()
|
|
||||||
.map(|v| serde_json::json!(v))
|
|
||||||
.unwrap_or_else(|e| serde_json::json!({ "error": e })),
|
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
if !native_loaded {
|
if !native_loaded {
|
||||||
@@ -666,13 +663,15 @@ impl CallEngine {
|
|||||||
"connect:audio_mode_start",
|
"connect:audio_mode_start",
|
||||||
serde_json::json!({ "t_ms": call_t0.elapsed().as_millis() }),
|
serde_json::json!({ "t_ms": call_t0.elapsed().as_millis() }),
|
||||||
);
|
);
|
||||||
match crate::android_audio::set_audio_mode_communication() {
|
let audio_mode_task =
|
||||||
Ok(()) => crate::emit_call_debug(
|
tokio::task::spawn_blocking(crate::android_audio::set_audio_mode_communication);
|
||||||
|
match tokio::time::timeout(std::time::Duration::from_secs(2), audio_mode_task).await {
|
||||||
|
Ok(Ok(Ok(()))) => crate::emit_call_debug(
|
||||||
&app,
|
&app,
|
||||||
"connect:audio_mode_done",
|
"connect:audio_mode_done",
|
||||||
serde_json::json!({ "t_ms": call_t0.elapsed().as_millis() }),
|
serde_json::json!({ "t_ms": call_t0.elapsed().as_millis() }),
|
||||||
),
|
),
|
||||||
Err(e) => {
|
Ok(Ok(Err(e))) => {
|
||||||
tracing::warn!("set_audio_mode_communication failed: {e}");
|
tracing::warn!("set_audio_mode_communication failed: {e}");
|
||||||
crate::emit_call_debug(
|
crate::emit_call_debug(
|
||||||
&app,
|
&app,
|
||||||
@@ -683,6 +682,26 @@ impl CallEngine {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Ok(Err(e)) => {
|
||||||
|
crate::emit_call_debug(
|
||||||
|
&app,
|
||||||
|
"connect:audio_mode_panic",
|
||||||
|
serde_json::json!({
|
||||||
|
"t_ms": call_t0.elapsed().as_millis(),
|
||||||
|
"error": e.to_string(),
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Err(_) => {
|
||||||
|
crate::emit_call_debug(
|
||||||
|
&app,
|
||||||
|
"connect:audio_mode_timeout",
|
||||||
|
serde_json::json!({
|
||||||
|
"t_ms": call_t0.elapsed().as_millis(),
|
||||||
|
"timeout_ms": 2000,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user