fix(adb): preserve empty properties and verbatim version names

This commit is contained in:
morluto committed 2026-10-23 16:23:57 +08:00
1 parent 14e745950e
commit bcd1f95e68
6 files changed
+150 -5

No files matched your search

+1 -1
View File
@@ -169,7 +169,7 @@ export const parseGetpropOutput = (
}
const properties = DEVICE_PROPERTY_WHITELIST.flatMap((name) => {
const value = values.get(name);
return value === undefined || value === ""
return value === undefined
? []
: [{ name, value } satisfies AdbDeviceProperty];
});
+10
View File
@@ -18,6 +18,16 @@ const packageDump = (installerLine: string | undefined): string =>
].join("\n");
describe("parseDumpsysPackageOutput", () => {
it.each(["", " My Build ", " ", "null"])(
"preserves the printed version name %j",
(versionName) => {
const result = parseDumpsysPackageOutput(
` pkg=Package{abcdef com.example}\n versionName=${versionName}\n`,
);
expect(result.versionName).toBe(versionName);
},
);
it("keeps a reported installer package name", () => {
expect(
parseDumpsysPackageOutput(
+5 -2
View File
@@ -335,13 +335,16 @@ export const parseDumpsysPackageOutput = (
const match = DETAIL_LINE.exec(line);
if (match === null) continue;
const key = match[1]!;
const value = match[2]!.trim();
// versionName is an arbitrary manifest string, printed verbatim by AOSP.
// Only the fields with their own structured grammar are normalized below.
const rawValue = match[2]!;
const value = rawValue.trim();
if (key === "pkg" && parsedPackageAvailable === null) {
if (value === "null") parsedPackageAvailable = false;
else if (value.startsWith("Package{") && value.endsWith("}"))
parsedPackageAvailable = true;
} else if (key === "versionName" && details.versionName === null)
details.versionName = value === "" ? null : value;
details.versionName = rawValue;
else if (key === "versionCode" && details.versionCode === null) {
const parsed = /^(-?\d+)/u.exec(value);
if (parsed !== null) details.versionCode = parsed[1]!;
+1 -1
View File
@@ -32,7 +32,7 @@ export const ADB_TOOL_CONTRACTS = [
name: "inspect_adb_device",
...toolContractMetadata("inspect_adb_device"),
description:
"Inspect one device's build identity through a fixed `getprop` whitelist: Android and SDK versions, security patch, fingerprint, product identity, CPU ABIs, and debuggable flag, plus the observed emulator indicator ro.kernel.qemu. Read-only with respect to the device.",
"Inspect one device's build identity through a fixed `getprop` whitelist: Android and SDK versions, security patch, fingerprint, product identity, CPU ABIs, and debuggable flag, plus the observed emulator indicator ro.kernel.qemu. Present properties retain empty values; omitted keys were not reported. Read-only with respect to the device.",
kind: "adb-provider",
inputSchema: adbInputSchemas.inspect_adb_device,
outputSchema: evidenceResultOf(adbResultSchemas.inspect_adb_device),
+1 -1
View File
@@ -527,7 +527,7 @@ export const adbResultSchemas = {
client,
serial: z.string().min(1),
properties: z.array(
z.strictObject({ name: z.string().min(1), value: z.string().min(1) }),
z.strictObject({ name: z.string().min(1), value: z.string() }),
),
property_count: z.int().nonnegative(),
emulator_observed: z.boolean().nullable(),