Skip to content

A high-performance Android storage analyzer that bypasses MTP using a native C++ daemon, a Rust TCP bridge, and a React Treemap UI.

Rust

Reject unsupported Android API levels before daemon startup (#153)

Vishnu Srivatsavae1c79cd7ebae
diff --git a/README.md b/README.md
index 4e00bbb..6c4fc60 100644
--- a/README.md
+++ b/README.md
@@ -275,6 +275,8 @@ resources. Use `--abi arm64-v8a`, `--abi armeabi-v7a`, `--abi x86`, or
advertised by the selected device. All binaries target Android API 31
(Android 12) or newer. ARMv7 support therefore covers 32-bit Android 12+
systems; Android versions below 12 remain unsupported.
+Startup checks the selected device's API level before requesting root access
+or uploading the daemon and reports this minimum directly on older versions.
Ordinary storage scans use a bounded pool of four workers. For daemon-level
comparisons, append `--threads N` (1–8) after `PORT TOKEN_FILE`; one worker
diff --git a/docs/daemon-sessions.md b/docs/daemon-sessions.md
index 6349ea8..fe98198 100644
--- a/docs/daemon-sessions.md
+++ b/docs/daemon-sessions.md
@@ -34,6 +34,13 @@ Setup offers [explicit device selection](device-selection.md). Startup checks
that the chosen serial is still ready before creating new session resources;
it never falls back to another serial.
+Before selecting an ABI or requesting root access, startup reads the selected
+device's `ro.build.version.sdk`. Bundled daemons require API 31 (Android 12).
+Older versions receive an explicit compatibility error; missing or malformed
+SDK values fail without guessing. Both cases stop before creating device files,
+uploading a binary or allocating a forward. The query shares the startup budget
+and applies to benchmark sessions too.
+
The foreground daemon is launched through **`adb shell -T`**, with an owned stdin
pipe held open by the Rust session. `--session-ready` also enables its lifetime
watcher. EOF/error on that input exits only that process, including when a TCP
diff --git a/src-tauri/src/session.rs b/src-tauri/src/session.rs
index a0f3da2..4d74698 100644
--- a/src-tauri/src/session.rs
+++ b/src-tauri/src/session.rs
@@ -13,6 +13,8 @@ use std::time::{Duration, Instant};
const START_TIMEOUT: Duration = Duration::from_secs(45);
const CLEANUP_TIMEOUT: Duration = Duration::from_secs(5);
+// All bundled ABI builds use the API-31 NDK target in engine/build_daemon.py.
+const MIN_ANDROID_API: u32 = 31;
#[derive(Clone)]
pub(super) struct Connection {
@@ -56,6 +58,19 @@ fn supports_shell_v2(output: &str) -> bool {
output.lines().any(|feature| feature.trim() == "shell_v2")
}
+fn require_android_api(output: &str) -> Result<(), String> {
+ let sdk = output.trim();
+ let api = sdk.parse::<u32>().ok().filter(|api| {
+ *api > 0 && sdk.bytes().all(|byte| byte.is_ascii_digit())
+ }).ok_or("Cannot determine the selected device's Android API level; expected a positive SDK number.")?;
+ if api < MIN_ANDROID_API {
+ return Err(format!(
+ "SocketSweep requires Android 12 or newer (API {MIN_ANDROID_API}+); the selected device reports API {api}."
+ ));
+ }
+ Ok(())
+}
+
fn bundled_daemon(arm64: &Path, abis: &str) -> Result<PathBuf, String> {
for abi in abis.trim().split(',').map(str::trim) {
let path = match abi {
@@ -211,6 +226,7 @@ impl Session {
if !supports_shell_v2(&self.adb(&["features"], None, deadline)?) {
return Err("The connected device must support ADB shell v2 for owned sessions".into());
}
+ require_android_api(&self.adb(&["shell", "getprop ro.build.version.sdk"], None, deadline)?)?;
let abis = self.adb(&["shell", "getprop ro.product.cpu.abilist"], None, deadline)?;
let daemon = if let Some(abi) = exact_abi {
if !abis.trim().split(',').any(|entry| entry.trim() == abi) {
@@ -451,6 +467,26 @@ mod tests {
}
}
+ #[test]
+ fn android_api_requires_the_bundled_daemons_minimum() {
+ for output in ["31", "32\n", "36\r\n", " 31 \n"] {
+ assert!(require_android_api(output).is_ok(), "rejected {output:?}");
+ }
+ for output in ["1", "29\n", "30\r\n"] {
+ let error = require_android_api(output).unwrap_err();
+ assert!(error.contains("Android 12") && error.contains("API 31+"), "{error}");
+ assert!(error.contains(&format!("reports API {}.", output.trim())), "{error}");
+ }
+ }
+
+ #[test]
+ fn android_api_rejects_missing_or_malformed_sdk_numbers() {
+ for output in ["", " \r\n", "0", "-1", "+31", "31\n32", "31extra", "31.0", "4294967296"] {
+ let error = require_android_api(output).unwrap_err();
+ assert!(error.contains("Cannot determine") && error.contains("API level"), "{error}");
+ }
+ }
+
#[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";
@@ -614,6 +650,29 @@ mod tests {
assert_eq!(device.rows().len(), 1);
}
+ #[test]
+ fn unsupported_or_unknown_android_api_never_creates_session_resources() {
+ let device = Device::new();
+ for (index, sdk) in ["29", "30\r\n", "", "invalid", "31\n30"].into_iter().enumerate() {
+ for benchmark in [false, true] {
+ let adb = device.client(&format!("sdk-{index}-{benchmark}"), "selected");
+ fs::write(adb.parent().unwrap().join("sdk.txt"), sdk).unwrap();
+ let result = if benchmark {
+ Session::start_benchmark(adb.clone(), Path::new("missing-daemon"), "selected".into(), 4, "arm64-v8a")
+ } else {
+ Session::start(adb.clone(), Path::new("missing-daemon"), "selected".into(), true)
+ };
+ let error = result.err().expect("unsupported Android API accepted");
+ assert!(error.contains("API"), "{error}");
+ let calls = fs::read_to_string(adb.parent().unwrap().join("calls.jsonl")).unwrap();
+ let calls: Vec<Vec<String>> = calls.lines().map(|line| serde_json::from_str(line).unwrap()).collect();
+ assert_eq!(calls, [vec!["features"], vec!["shell", "getprop ro.build.version.sdk"]]);
+ assert_eq!(device.directories(), 0);
+ assert_eq!(device.rows().len(), 1);
+ }
+ }
+ }
+
#[test]
fn discovery_checks_the_exact_selected_serial_without_falling_back() {
let device = Device::new();
@@ -794,6 +853,7 @@ mod tests {
.unwrap();
for stage in [
"features",
+ "sdk",
"mkdir",
"token",
"push",
diff --git a/tests/fake_session_adb.py b/tests/fake_session_adb.py
index ef74b89..ce579e5 100755
--- a/tests/fake_session_adb.py
+++ b/tests/fake_session_adb.py
@@ -58,7 +58,9 @@ elif args[0] == "shell":
abis = base / "abis.txt"
print(abis.read_text() if abis.exists() else "arm64-v8a,armeabi-v7a")
elif command == "getprop ro.build.version.sdk":
- print("fixture")
+ fail("sdk")
+ sdk = base / "sdk.txt"
+ print(sdk.read_text() if sdk.exists() else "31")
elif command == "id -u":
print("0" if elevated and failure != "root" else "2000")
elif args[1] == "-T":