A high-performance Android storage analyzer that bypasses MTP using a native C++ daemon, a Rust TCP bridge, and a React Treemap UI.
Rust
Parse ADB feature output as individual lines (#70)
Vishnu Srivatsava85ae09a1f258
diff --git a/docs/daemon-sessions.md b/docs/daemon-sessions.mdindex e03c726..b35dc4f 100644--- a/docs/daemon-sessions.md+++ b/docs/daemon-sessions.md@@ -41,6 +41,12 @@ handles the shell-v2 close-stdin packet by shutting down input for a raw shell;PTY shells cannot provide that half-close behavior. This is why `-T` and thefeature check are part of the contract.+The targeted `adb features` CLI prints **one feature per line** (LF or CRLF),+unlike the comma-separated feature set on the ADB wire. The host requires an+exact `shell_v2` feature line. The fake-ADB fixture uses a multi-feature response+to exercise this distinction; devices without that capability still fail before+creating session files.+## Teardown and failuresStop first requests authenticated `SHUTDOWN` from the owned endpoint. Only thediff --git a/src-tauri/src/session.rs b/src-tauri/src/session.rsindex a7d14d3..9b60ecc 100644--- a/src-tauri/src/session.rs+++ b/src-tauri/src/session.rs@@ -48,6 +48,11 @@ fn remaining(deadline: Instant) -> Result<Duration, String> {}}+fn supports_shell_v2(output: &str) -> bool {+ // `adb features` prints one name per line; the ADB wire format uses commas.+ output.lines().any(|feature| feature.trim() == "shell_v2")+}+impl Session {pub fn connection(&self) -> Connection {self.connection.clone()@@ -130,12 +135,7 @@ impl Session {fn start_inner(&mut self, daemon: &Path, root_mode: bool) -> Result<String, String> {let deadline = Instant::now() + START_TIMEOUT;- if !self- .adb(&["features"], None, deadline)?- .trim()- .split(',')- .any(|feature| feature == "shell_v2")- {+ if !supports_shell_v2(&self.adb(&["features"], None, deadline)?) {return Err("The connected device must support ADB shell v2 for owned sessions".into());}self.privilege = select_privilege(root_mode, |args| self.adb(args, None, deadline))?;@@ -327,6 +327,30 @@ fn owned_forwards(list: &str, serial: &str, local: u16, remote: u16) -> Vec<Strimod tests {use super::*;+ #[test]+ fn shell_v2_requires_an_exact_feature_line() {+ for output in [+ "shell_v2",+ "shell_v2\ncmd\n",+ "cmd\nshell_v2\nstat_v2\n",+ "cmd\nstat_v2\nshell_v2\n",+ "cmd\r\nshell_v2\r\nstat_v2\r\n",+ "\n shell_v2 \n",+ ] {+ assert!(supports_shell_v2(output), "rejected {output:?}");+ }+ for output in [+ "",+ "\r\n",+ "cmd\nstat_v2\n",+ "no_shell_v2\nshell_v20\nshell_v2_disabled\n",+ "cmd,shell_v2,stat_v2",+ "cmd shell_v2 stat_v2",+ ] {+ assert!(!supports_shell_v2(output), "accepted {output:?}");+ }+ }+#[test]fn forward_cleanup_checks_device_local_and_remote_identity() {let list = "one tcp:1001 tcp:2001\none tcp:1002 tcp:2002\ntwo tcp:1003 tcp:2001\none tcp:0 tcp:2001\none localabstract:foreign tcp:2001\nbad line";diff --git a/tests/fake_session_adb.py b/tests/fake_session_adb.pyindex 7463f59..8259a7e 100644--- a/tests/fake_session_adb.py+++ b/tests/fake_session_adb.py@@ -40,7 +40,8 @@ if args == ["devices", "-l"]:print(discovery.read_text() if discovery.exists() elsef'List of devices attached\n{config["serial"]}\tdevice model:Fixture\n')elif args == ["features"]:- print("shell_v2" if failure != "features" else "other_feature")+ # The CLI prints one feature per line, not the comma-delimited wire set.+ print("cmd\nshell_v2\nstat_v2" if failure != "features" else "cmd\nstat_v2")elif args[0] == "push":fail("push")shutil.copyfile(args[1], mapped(args[2]))