fix(adb): keep a bare numeric wm density as the physical density (#4074)

Older Android builds print `wm density` as a bare number. The parser's
documentation named that form, but only the labeled `Physical density:`
and `Override density:` lines were matched, so a bare `420` left
`physical_density` null in successful display Evidence with no limitation
saying the declaration was unread (#3942).

The parser now reads the first bare numeric line as the physical density
when no labeled physical declaration is present; a labeled declaration
still wins so a mixed dump cannot downgrade the value. Override density
and physical size are unchanged.

Validation: parser unit tests for the labeled, bare, CRLF, mixed and
unrecognized forms, plus a provider-level regression through the
inspect_adb_display operation; two of them fail on main and pass here.
The issue's three CLI controls through `rea inspect-adb-display` against
a stub adb return physical density 420 for the bare form and keep the
labeled and override controls. Typecheck, lint and module boundaries pass.

Closes #3942
This commit is contained in:
Yankı Küçük authored and GitHub committed 2026-10-17 00:15:05 +08:00
1 parent e0b989cc0a
commit bef3fbbc6e
3 files changed
+75 -3

No files matched your search

+44 -1
View File
@@ -1,6 +1,49 @@
import { describe, expect, it } from "vitest";
import { parseAmStartOutput } from "./AdbShellOutput.js";
import { parseAmStartOutput, parseWmDensityOutput } from "./AdbShellOutput.js";
describe("parseWmDensityOutput", () => {
it("reads labeled physical and override densities", () => {
expect(
parseWmDensityOutput("Physical density: 420\nOverride density: 480\n"),
).toEqual({ physical: 420, override: 480 });
expect(parseWmDensityOutput("Physical density: 420\n")).toEqual({
physical: 420,
override: null,
});
});
// Older builds print the physical density as a bare number
// (morluto/rea#3942); it must not be lost as an unread declaration.
it("reads a bare numeric density as the physical density", () => {
expect(parseWmDensityOutput("420\n")).toEqual({
physical: 420,
override: null,
});
expect(parseWmDensityOutput("420\r\n")).toEqual({
physical: 420,
override: null,
});
});
it("prefers a labeled physical density over a bare number", () => {
expect(parseWmDensityOutput("560\nPhysical density: 420\n")).toEqual({
physical: 420,
override: null,
});
});
it("reports no density for unrecognized output", () => {
expect(parseWmDensityOutput("")).toEqual({
physical: null,
override: null,
});
expect(parseWmDensityOutput("420dpi\n")).toEqual({
physical: null,
override: null,
});
});
});
const starting =
"Starting: Intent { act=android.intent.action.MAIN cmp=com.example/.Main }";