diff --git a/android-ffi/src/lib.rs b/android-ffi/src/lib.rs
index d283387..09e0f0e 100644
--- a/android-ffi/src/lib.rs
+++ b/android-ffi/src/lib.rs
@@ -34,7 +34,8 @@ struct SessionBox {
runtime: tokio::runtime::Runtime,
}
-/// 连接被控端。成功返回句柄(>0),失败返回 0;错误消息经 `nativeLastError()` 取。
+/// 连接被控端。成功返回句柄(>0),失败返回 0;错误消息经 `nativeLastError()` 取,
+/// **错误分类**经 `nativeLastErrorKind()` 取(3a:界面按分类显示中文文案,原始英文作第二行)。
#[no_mangle]
pub extern "system" fn Java_com_verify_remote_RustBridge_nativeConnect<'local>(
mut env: JNIEnv<'local>,
@@ -46,14 +47,14 @@ pub extern "system" fn Java_com_verify_remote_RustBridge_nativeConnect<'local>(
let host_s = match env.get_string(&host) {
Ok(s) => s.to_string_lossy().into_owned(),
Err(_) => {
- set_last_error("host 参数不是合法字符串");
+ set_last_error(-1, "host 参数不是合法字符串");
return 0;
}
};
let code_s = match env.get_string(&code) {
Ok(s) => s.to_string_lossy().into_owned(),
Err(_) => {
- set_last_error("code 参数不是合法字符串");
+ set_last_error(-1, "code 参数不是合法字符串");
return 0;
}
};
@@ -64,7 +65,7 @@ pub extern "system" fn Java_com_verify_remote_RustBridge_nativeConnect<'local>(
.build()
{
Ok(r) => r,
- Err(e) => return Err(format!("runtime init: {e}")),
+ Err(e) => return Err((-1i32, format!("runtime init: {e}"))),
};
let cfg = ConnectConfig::direct(host_s, port as u16, code_s);
match runtime.block_on(Session::connect(cfg)) {
@@ -72,53 +73,73 @@ pub extern "system" fn Java_com_verify_remote_RustBridge_nativeConnect<'local>(
session: Arc::new(session),
runtime,
}),
- Err(e) => Err(format!("{e:#}")),
+ // ConnectError 的 Display 即原始 detail;kind.code() 与
+ // viewer_core::ConnectErrorKind::code 的映射表一致(FFI 契约)。
+ Err(e) => Err((e.kind.code(), e.detail)),
}
});
match built {
Ok(Ok(boxed)) => {
- set_last_error("");
+ set_last_error(0, "");
Box::into_raw(Box::new(Mutex::new(boxed))) as jlong
}
- Ok(Err(msg)) => {
- set_last_error(&msg);
+ Ok(Err((kind, msg))) => {
+ set_last_error(kind, &msg);
0
}
Err(_) => {
- set_last_error("panic in nativeConnect");
+ set_last_error(-1, "panic in nativeConnect");
0
}
}
}
-fn set_last_error(msg: &str) {
+/// kind = 0 表示清除;-1 表示 FFI 层自身错误(无 viewer-core 分类,Kotlin 走 Other 文案)。
+fn set_last_error(kind: i32, msg: &str) {
let mut slot = LAST_ERROR.lock().unwrap();
if msg.is_empty() {
*slot = None;
} else {
- *slot = Some(msg.to_string());
+ *slot = Some((kind, msg.to_string()));
}
}
-static LAST_ERROR: Mutex