Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions docs/CLI.md
Original file line number Diff line number Diff line change
Expand Up @@ -1584,7 +1584,7 @@ device it is: `phone`, `tablet`, `watch`, `tv`, `vision`, `auto` or
from the device profile's tag: `android-tv` is `tv`, `android-wear` is
`watch`, `android-automotive` and its variants are `auto`, `android-desktop`
is `desktop`, and a profile with no tag, or a custom profile from
`devices.xml`, is `phone`. A model whose tooling reports nothing usable has
`devices.xml`, is `phone`. A profile Simlock ships carries its own class. A model whose tooling reports nothing usable has
no entry, and is still listed and leasable by name.

`classDefaults` says, for a class, which model Simlock would create for it on
Expand Down Expand Up @@ -1653,8 +1653,14 @@ own name for it.

### Where Android models come from

Simlock reads Android device models from two places and writes to neither:
Simlock reads Android device models from three places and writes to none of
them:

- **Simlock's own profiles** ship with Simlock (today: Pixel 9). They are
read first, so a device made from one has the same hardware on every
host, and the model is there even when your `cmdline-tools` is too old to
have it. A name Simlock's own profiles have wins over the same name in the
SDK and in `devices.xml`.
- **Built-in profiles** ship with the Android SDK's `cmdline-tools`. A
model newer than your `cmdline-tools` is not there; update
`cmdline-tools` to get it.
Expand All @@ -1667,7 +1673,8 @@ Simlock reads Android device models from two places and writes to neither:
`avdmanager list device` prints both kinds; it shows a custom profile with
`OEM : User`. Simlock also reads `devices.xml` itself. When a custom profile
has the same name as a built-in one, the built-in profile wins and the model
is not custom. If `devices.xml` cannot be read, the built-in models are still
is not custom. Simlock's own models are listed first, then the SDK's, then
the custom ones. If `devices.xml` cannot be read, the built-in models are still
listed. A custom model is marked `(custom)` in the human view of `simlock
catalog` and listed in `customModels` in `--json`.

Expand Down
28 changes: 12 additions & 16 deletions e2e/slow-android-smoke.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,7 @@ interface AndroidCatalogOutput {
}[];
}

/**
* Checks the Android entry against the SDK on disk -- every listed image is installed, under a
* runtime the catalog lists -- and returns the AVD id a built-in profile is listed with as
* another name.
*/
function avdIdFromCatalog(output: AndroidCatalogOutput): string {
function checkCatalog(output: AndroidCatalogOutput): void {
const android = output.platforms.find((platform) => platform.platform === "android");
if (android === undefined) {
throw new Error("simlock catalog reported no android platform -- SDK discovery failed");
Expand All @@ -79,12 +74,9 @@ function avdIdFromCatalog(output: AndroidCatalogOutput): string {
expect(existsSync(path), `listed image ${JSON.stringify(image)} is not installed`).toBe(true);
}

const aliases = android.models.flatMap((name) => android.modelAliases[name] ?? []);
expect(
aliases.length,
"expected a built-in profile with its AVD id as another name",
).toBeGreaterThan(0);
return aliases[0] as string;
expect(android.models[0]).toBe("Pixel 9");
expect(android.modelClasses["Pixel 9"]).toBe("phone");
expect(android.modelAliases["Pixel 9"]).toEqual(["pixel_9"]);
}

// Real emulator boots are slow and this SDK layout is host-specific, so this lane is
Expand All @@ -94,7 +86,7 @@ describe.skipIf(!hasAndroidSdk)(
{ tags: ["slow", "android"] },
() => {
it(
"catalog agrees with the SDK and lists an AVD id and an installed image, a cold lease by that AVD id boots a real emulator, and a shut-down emulator reports erasableReadable:false with no crash or false provenance finding",
"catalog lists Simlock's Pixel 9 first, a cold lease of Pixel 9 boots a real emulator with the library screen size, and a shut-down emulator reports erasableReadable:false with no crash or false provenance finding",
{ timeout: 420_000 },
async () => {
const env = await withDaemon({
Expand All @@ -108,16 +100,15 @@ describe.skipIf(!hasAndroidSdk)(
try {
const catalog = await env.cli(["catalog", "--json", "--platform", "android"]);
expect(catalog.code).toBe(0);
// The lease below asks by an AVD id the catalog lists as another name.
const model = avdIdFromCatalog(catalog.json as AndroidCatalogOutput);
checkCatalog(catalog.json as AndroidCatalogOutput);

const lease = await env.cli(
[
"lease",
"--platform",
"android",
"--device",
model,
"Pixel 9",
"--agent-id",
"android-smoke",
"--detach",
Expand Down Expand Up @@ -146,6 +137,11 @@ describe.skipIf(!hasAndroidSdk)(
expect(wrapped.code, `simlock adb failed: ${wrapped.stderr}`).toBe(0);
expect(wrapped.stdout).toContain("emulator-");

const size = await env.cli(["adb", "shell", "wm", "size"]);
expect(size.stdout).toContain("Physical size: 1080x2424");
const density = await env.cli(["adb", "shell", "wm", "density"]);
expect(density.stdout).toContain("Physical density: 420");

const refused = await env.cli(["adb", "kill-server"]);
expect(refused.code, "simlock adb kill-server must be refused, not run").toBe(2);
expect(refused.error?.code).toBe("USAGE");
Expand Down
19 changes: 19 additions & 0 deletions src/core/driver-catalog.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,25 @@ describe("DriverCatalog", () => {
return (await catalog.listCatalog())[0]?.classDefaults;
}

it("is Pixel 9 for a phone list that starts at Pixel 9 when the catalog lists Pixel 9 paired and no Pixel 8", async () => {
const driver = new FakeDriver({
availableOsVersions: ["35"],
clock: new FakeClock(),
knownModels: ["Pixel 9", "Pixel 7"],
modelAliases: { "Pixel 9": ["pixel_9"] },
modelClasses: { "Pixel 7": "phone", "Pixel 9": "phone" },
modelRuntimes: { "Pixel 7": [], "Pixel 9": ["35"] },
platform: "android",
});
const catalog = new DriverCatalog([driver], {
preferences: {
android: { phone: ["Pixel 9", "Pixel 8", "Pixel 7", "Pixel 6", "Medium Phone"] },
},
});

expect((await catalog.listCatalog())[0]?.classDefaults).toEqual({ phone: "Pixel 9" });
});

it("is the first name on the preference list the catalog lists", async () => {
await expect(
defaultsOf({
Expand Down
37 changes: 17 additions & 20 deletions src/drivers/android/device-profile-source.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,6 @@
import { DriverCrashError, UnknownModelError, type DeviceClass } from "../../core/index.js";
import type { Filesystem, ProcessRunner } from "../../ports/index.js";

/**
* One device profile a `DeviceProfileSource` can create an AVD from. `builtin` is today's
* `avdmanager -d <id>` path; `properties` is a hardware descriptor applied to `config.ini`
* after `avdmanager create avd` (see `AndroidDriver#provision`) -- there is no `avdmanager`
* device id for it because it never came from `avdmanager list device`. `name` is the
* source's own canonical spelling of the model (case may differ from what the caller asked
* for), which `AndroidDriver` needs so `DeviceSpec.model` and cache lookups stay stable.
*
* A `properties` profile has no tag and counts as a `phone`.
*
* A `builtin` profile is `custom` when `avdmanager` lists it with `OEM : User`: that is how it
* prints a profile from Android Studio's `devices.xml`, which it reads itself.
*
* `names` is every name the profile answers to, `name` first, no two equal ignoring case.
* `DeviceProfileRegistry` matches a requested model against it and lists the rest as the
* model's other names, so the two can never disagree.
*/
export type DeviceProfile =
| {
readonly kind: "builtin";
Expand All @@ -28,6 +11,20 @@ export type DeviceProfile =
/** From the entry's `Tag :` line (ADR 0015 §3); `undefined` for a tag the table does not know. */
readonly deviceClass: DeviceClass | undefined;
}
| {
readonly kind: "library";
readonly name: string;
readonly id: string;
readonly names: readonly string[];
readonly deviceClass: DeviceClass;
readonly imageKind: string | undefined;
readonly apiRange: { readonly min: number; readonly max?: number };
readonly playStore: boolean;
readonly tablet: boolean;
readonly hardware: Readonly<Record<string, string>>;
readonly bootProperties: Readonly<Record<string, string>>;
readonly copiedFrom: string;
}
| {
readonly kind: "properties";
readonly name: string;
Expand Down Expand Up @@ -118,7 +115,7 @@ export class DeviceProfileRegistry {
});
const modelClasses: Record<string, DeviceClass> = {};
for (const profile of listed.values()) {
const deviceClass = profile.kind === "builtin" ? profile.deviceClass : "phone";
const deviceClass = profile.kind === "properties" ? "phone" : profile.deviceClass;
if (deviceClass !== undefined) modelClasses[profile.name] = deviceClass;
}
return { customModels, modelAliases, modelClasses, models };
Expand Down Expand Up @@ -150,7 +147,7 @@ export class DeviceProfileRegistry {

/** Made on this machine rather than shipped with the SDK. */
function isCustom(profile: DeviceProfile): boolean {
return profile.kind === "properties" || profile.custom;
return profile.kind === "properties" || (profile.kind === "builtin" && profile.custom);
}

/** The first profile any of whose names is `model`, ignoring case. */
Expand Down Expand Up @@ -444,7 +441,7 @@ export function parseDevicesXml(contents: string): readonly DevicesXmlProfile[]
}

/** CR, LF, or NUL -- see the rejection check at the top of the `<d:device>` loop above. */
function containsForbiddenCharacter(value: string): boolean {
export function containsForbiddenCharacter(value: string): boolean {
// oxlint-disable-next-line no-control-regex -- NUL rejection is intentional, not an accidental control-character match.
return /[\r\n\u0000]/.test(value);
}
Expand Down
19 changes: 19 additions & 0 deletions src/drivers/android/image-fit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export interface ImageFitInput {
readonly apiLevel: string;
readonly tag: string;
readonly tags: readonly string[];
}

const MIN_WEAR_PLAY_STORE_API = 25;

export function isPlayStoreImage(image: ImageFitInput): boolean {
if (image.tags.includes("google_apis_playstore")) return true;
const [only, ...rest] = image.tags;
if (rest.length > 0) return false;
if (only === "android-automotive-playstore") return true;
return (
only === "android-wear" &&
image.tag !== "android-wear-cn" &&
Number(image.apiLevel) >= MIN_WEAR_PLAY_STORE_API
);
}
Loading
Loading