Craft Anything: understand how any software works, and craft your own.
Rust
adb_app_show says a missing package isn't installed (#258)
BFlatc89f6603dd5c
diff --git a/crates/engine/src/tools/adb_tools.rs b/crates/engine/src/tools/adb_tools.rsindex e25614d2..3fe35317 100644--- a/crates/engine/src/tools/adb_tools.rs+++ b/crates/engine/src/tools/adb_tools.rs@@ -771,6 +771,12 @@ fn adb_log_read(ctx: &mut Ctx<'_>, params: Value) -> Result<ToolOutput, ToolErrodone(e)}+/// Whether `dumpsys package <name>` describes `package`: it has that package's `Package [name]`+/// block. Android answers a missing one with "Unable to find package: <name>", which names it too (#235).+fn package_found(text: &str, package: &str) -> bool {+ text.contains(&format!("Package [{package}]"))+}+fn adb_app_show(ctx: &mut Ctx<'_>, params: Value) -> Result<ToolOutput, ToolError> {let p: PackageParams = parse_params(params)?;let serial = serial_of(&p.serial)?;@@ -778,7 +784,7 @@ fn adb_app_show(ctx: &mut Ctx<'_>, params: Value) -> Result<ToolOutput, ToolErrolet adb = adb_for(ctx)?;ensure_online(&adb, serial)?;let text = shell_text(&adb, serial, &format!("dumpsys package {package}"), "dumpsys package")?;- if !text.contains(package) && !text.contains("Package [") {+ if !package_found(&text, package) {return Err(ToolError::new(ErrorCode::NotFound, format!("Package {package} is not installed on {serial}.")).with_remediation("List installed packages with adb_apps_list."));}@@ -1447,6 +1453,14 @@ mod tests {assert!(matches!(err.code, ErrorCode::ConsentRequired | ErrorCode::NotFound | ErrorCode::EngineMissing));}+ /// #235: Android's reply for a missing package names it, and was read as the package.+ #[test]+ fn a_missing_package_is_not_found() {+ assert!(!package_found("Unable to find package: com.example.missing\n", "com.example.missing"));+ assert!(!package_found("Packages:\n Package [com.example.other] (1a2b):\n", "com.example"));+ assert!(package_found("Packages:\n Package [com.example.app] (1a2b3c):\n versionName=1.0\n", "com.example.app"));+ }+#[test]fn parsers_and_fragments() {let fields = grep_fields(" versionName=1.2.3 flags=0x1\n versionCode=42 minSdk=21\n", &["versionName=", "versionCode=", "minSdk="]);