Skip to content

Commit 9a245d0

Browse files
authored
feat(devices): report model and osVersion (#3119)
* feat(devices): report model and osVersion List hardware model and OS version per device: simctl device types and runtimes for iOS simulators, devicectl marketingName/osVersionNumber and xctrace OS version for physical iOS, getprop for running Android devices. Presentation-only; not part of identity or selection. * refactor(android): read model and OS version in one getprop call * fix(android): bound the description probe at 2s and pin both props in fixtures
1 parent c237027 commit 9a245d0

24 files changed

Lines changed: 327 additions & 39 deletions

‎packages/contracts/src/client-device-view.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ export type AgentDeviceDevice = {
2020
* Apple devices; `platform` still carries the leaf (`ios`/`macos`).
2121
*/
2222
appleOs?: AppleOS;
23+
/** Hardware model, for example `iPhone 17 Pro` or `Pixel 9`, when discovery reports it. */
24+
model?: string;
25+
/** OS version, for example `26.1` or `16`, when discovery reports it. */
26+
osVersion?: string;
2327
identifiers: AgentDeviceIdentifiers;
2428
/**
2529
* Present when a host-local device claim currently blocks foreign use of

‎packages/kernel/src/device.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ export type DeviceInfo = {
5353
// Explicit Apple OS discriminant populated at discovery for Apple devices.
5454
// Optional so legacy records (and non-Apple platforms) remain valid.
5555
appleOs?: AppleOS;
56+
// Presentation-only hardware model and OS version reported by discovery when the
57+
// platform tooling exposes them; never part of device identity or selection.
58+
model?: string;
59+
osVersion?: string;
5660
booted?: boolean;
5761
simulatorSetPath?: string;
5862
// Internal physical-iOS execution backend selected during discovery.

‎packages/platform-android/src/inventory-parsers.test.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
isAndroidEmulatorSerial,
55
normalizeAndroidDeviceName,
66
parseAndroidAvdList,
7+
parseAndroidDeviceDescription,
78
parseAndroidDeviceEntries,
89
parseAndroidEmulatorAvdNameOutput,
910
parseAndroidFeatureListForTv,
@@ -33,3 +34,12 @@ test('Android inventory parsers preserve device, AVD-name, and TV detection sema
3334
assert.equal(parseAndroidTargetFromCharacteristics('phone,tablet'), null);
3435
assert.equal(parseAndroidFeatureListForTv('feature:android.hardware.type.television'), true);
3536
});
37+
38+
test('Android description parser reads the model and OS version lines and skips unset props', () => {
39+
assert.deepEqual(parseAndroidDeviceDescription('sdk_gphone16k_arm64\r\n17\r\n'), {
40+
model: 'sdk_gphone16k_arm64',
41+
osVersion: '17',
42+
});
43+
assert.deepEqual(parseAndroidDeviceDescription('\n16\n'), { osVersion: '16' });
44+
assert.deepEqual(parseAndroidDeviceDescription(''), {});
45+
});

‎packages/platform-android/src/inventory-parsers.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,18 @@ export function parseAndroidDeviceEntries(rawOutput: string): AndroidDeviceEntry
2727
return devices;
2828
}
2929

30+
/** Reads the model and OS version lines printed by the inventory description probe, in order. */
31+
export function parseAndroidDeviceDescription(rawOutput: string): {
32+
model?: string;
33+
osVersion?: string;
34+
} {
35+
const [model, osVersion] = rawOutput.split(/\r?\n/).map((line) => line.trim());
36+
return {
37+
...(model ? { model } : {}),
38+
...(osVersion ? { osVersion } : {}),
39+
};
40+
}
41+
3042
export function parseAndroidAvdList(rawOutput: string): string[] {
3143
return rawOutput
3244
.split('\n')

‎packages/platform-android/src/inventory.test.ts‎

Lines changed: 65 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ const scope: PlatformRequestScope = {
1414
progress: { report: () => undefined },
1515
};
1616

17+
const RUNNING_EMULATOR_PROBES: ReadonlyArray<readonly [string, string]> = [
18+
['ro.boot.qemu.avd_name', 'Pixel_9_Pro_XL\n'],
19+
['sys.boot_completed', '1\n'],
20+
['getprop ro.product.model; getprop ro.build.version.release', 'sdk_gphone16k_arm64\n17\n'],
21+
['ro.build.characteristics', 'phone\n'],
22+
['has-feature', 'false\n'],
23+
['pm\0list\0features', ''],
24+
];
25+
1726
test.each([
1827
['include-stopped', true],
1928
['running-only', false],
@@ -30,11 +39,8 @@ test.each([
3039
'List of devices attached\nemulator-5554 device model:Pixel_9_Pro_XL\nphysical-1 device model:Phone\n',
3140
);
3241
}
33-
if (key.includes('ro.boot.qemu.avd_name')) return result('Pixel_9_Pro_XL\n');
34-
if (key.includes('sys.boot_completed')) return result('1\n');
35-
if (key.includes('ro.build.characteristics')) return result('phone\n');
36-
if (key.includes('has-feature')) return result('false\n');
37-
if (key.includes('pm\0list\0features')) return result('');
42+
const probe = RUNNING_EMULATOR_PROBES.find(([fragment]) => key.includes(fragment));
43+
if (probe) return result(probe[1]);
3844
throw new Error(`Unexpected command: ${request.executable} ${request.args.join(' ')}`);
3945
});
4046

@@ -44,17 +50,67 @@ test.each([
4450
);
4551

4652
assert.deepEqual(
47-
devices.map((candidate) => [candidate.id, candidate.name, candidate.booted]),
53+
devices.map((candidate) => [
54+
candidate.id,
55+
candidate.name,
56+
candidate.booted,
57+
candidate.model,
58+
candidate.osVersion,
59+
]),
4860
[
49-
['emulator-5554', 'Pixel 9 Pro XL', true],
50-
...(includesStoppedAvd ? [['Living_Room_TV', 'Living_Room_TV', false] as const] : []),
61+
['emulator-5554', 'Pixel 9 Pro XL', true, 'sdk_gphone16k_arm64', '17'],
62+
...(includesStoppedAvd
63+
? [['Living_Room_TV', 'Living_Room_TV', false, undefined, undefined] as const]
64+
: []),
5165
],
5266
);
53-
assert.ok(calls.every((call) => call.timeoutMs === 10_000));
67+
const isDescriptionProbe = (call: HostCommandRequest) =>
68+
call.args.some((arg) => arg.includes('ro.product.model'));
69+
assert.deepEqual(
70+
calls.filter(isDescriptionProbe).map((call) => call.timeoutMs),
71+
[2_000],
72+
);
73+
assert.ok(
74+
calls.filter((call) => !isDescriptionProbe(call)).every((call) => call.timeoutMs === 10_000),
75+
);
5476
assert.ok(calls.every((call) => call.allowFailure === true));
5577
},
5678
);
5779

80+
test.each([
81+
['exits non-zero', async () => result('', 'error: closed', 1)],
82+
[
83+
'times out',
84+
async () => {
85+
throw new AppError('COMMAND_FAILED', 'adb timed out after 2000ms', { timeoutMs: 2_000 });
86+
},
87+
],
88+
] as const)(
89+
'Android inventory leaves model and OS version unset when the description probe %s',
90+
async (_case, describeProbe) => {
91+
const host = createHost(async (request) => {
92+
const key = request.args.join('\0');
93+
if (key === 'devices\0-l') {
94+
return result('List of devices attached\nR5CT1 device model:SM_S921B\n');
95+
}
96+
if (key.includes('ro.product.model')) return await describeProbe();
97+
const probe = RUNNING_EMULATOR_PROBES.find(([fragment]) => key.includes(fragment));
98+
if (probe) return result(probe[1]);
99+
throw new Error(`Unexpected command: ${request.executable} ${request.args.join(' ')}`);
100+
});
101+
102+
const [device] = await createAndroidInventory(host).discover(
103+
{ androidAvdSelection: 'running-only' },
104+
scope,
105+
);
106+
107+
assert.equal(device?.name, 'SM S921B');
108+
assert.equal(device?.booted, true);
109+
assert.equal(device?.model, undefined);
110+
assert.equal(device?.osVersion, undefined);
111+
},
112+
);
113+
58114
test('Android inventory fails closed when adb is unavailable', async () => {
59115
const host = createHost(async () => result(''), { adb: undefined });
60116
await assert.rejects(

‎packages/platform-android/src/inventory.ts‎

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import path from 'node:path';
22
import type { DeviceInfo } from '@agent-device/kernel/device';
3-
import { deviceShellArgv, type ShellWord } from '@agent-device/kernel/device-shell';
3+
import { deviceShellArgv, shellFragment, type ShellWord } from '@agent-device/kernel/device-shell';
44
import { AppError, asAppError } from '@agent-device/kernel/errors';
55
import type {
66
DeviceInventoryHostFor,
@@ -16,6 +16,7 @@ import {
1616
isAndroidEmulatorSerial,
1717
normalizeAndroidDeviceName,
1818
parseAndroidAvdList,
19+
parseAndroidDeviceDescription,
1920
parseAndroidDeviceEntries,
2021
parseAndroidEmulatorAvdNameOutput,
2122
parseAndroidFeatureListForTv,
@@ -24,6 +25,10 @@ import {
2425
} from './inventory-parsers.ts';
2526

2627
const PROBE_TIMEOUT_MS = 10_000;
28+
const DEVICE_DESCRIPTION_TIMEOUT_MS = 2_000;
29+
const DEVICE_DESCRIPTION_PROBE = shellFragment(
30+
'getprop ro.product.model; getprop ro.build.version.release',
31+
);
2732
const TV_FEATURES = [
2833
'android.software.leanback',
2934
'android.software.leanback_only',
@@ -119,21 +124,42 @@ async function probeRunningDevice(
119124
context: AndroidInventoryContext,
120125
entry: AndroidDeviceEntry,
121126
): Promise<DeviceInfo> {
122-
const [name, booted, target] = await Promise.all([
127+
const [name, booted, target, description] = await Promise.all([
123128
resolveDeviceName(context, entry),
124129
isBooted(context, entry.serial),
125130
resolveTarget(context, entry.serial),
131+
readDeviceDescription(context, entry.serial),
126132
]);
127133
return {
128134
platform: 'android',
129135
id: entry.serial,
130136
name,
131137
kind: isAndroidEmulatorSerial(entry.serial) ? 'emulator' : 'device',
132138
target,
139+
...description,
133140
booted,
134141
};
135142
}
136143

144+
/** Best-effort model and OS version read in one shell call; a failed probe leaves both unset. */
145+
async function readDeviceDescription(
146+
context: AndroidInventoryContext,
147+
serial: string,
148+
): Promise<Pick<DeviceInfo, 'model' | 'osVersion'>> {
149+
try {
150+
const result = await runAdbShell(
151+
context,
152+
serial,
153+
[DEVICE_DESCRIPTION_PROBE],
154+
DEVICE_DESCRIPTION_TIMEOUT_MS,
155+
);
156+
return result.exitCode === 0 ? parseAndroidDeviceDescription(result.stdout) : {};
157+
} catch (error) {
158+
if (context.scope.signal.aborted) throw error;
159+
return {};
160+
}
161+
}
162+
137163
async function resolveDeviceName(
138164
context: AndroidInventoryContext,
139165
entry: AndroidDeviceEntry,
@@ -244,22 +270,24 @@ async function runAdbShell(
244270
context: AndroidInventoryContext,
245271
serial: string,
246272
words: readonly ShellWord[],
273+
timeoutMs = PROBE_TIMEOUT_MS,
247274
): Promise<HostCommandResult> {
248-
return await run(context, context.adb, adbShellArgv(serial, words));
275+
return await run(context, context.adb, adbShellArgv(serial, words), timeoutMs);
249276
}
250277

251278
async function run(
252279
context: AndroidInventoryContext,
253280
executable: string,
254281
args: readonly string[],
282+
timeoutMs = PROBE_TIMEOUT_MS,
255283
): Promise<HostCommandResult> {
256284
try {
257285
return await context.host.commands.run(
258286
{
259287
executable,
260288
args,
261289
allowFailure: true,
262-
timeoutMs: PROBE_TIMEOUT_MS,
290+
timeoutMs,
263291
},
264292
context.scope.signal,
265293
);

‎packages/platform-apple/src/core/__tests__/simctl.test.ts‎

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
readSimctlDeviceState,
88
scopeSimctlArgsForDevice,
99
simctlAvailabilityProbeArgs,
10-
simctlListDevicesArgs,
10+
simctlListInventoryArgs,
1111
simulatorAddressFor,
1212
type SimulatorAddress,
1313
} from '../simctl.ts';
@@ -60,16 +60,10 @@ test('buildSimctlArgsForDevice leaves non-simulator commands unchanged', () => {
6060
assert.deepEqual(args, ['simctl', 'bootstatus', 'sim-1', '-b']);
6161
});
6262

63-
test('simctlListDevicesArgs prefixes a trimmed simulator set and omits a blank one', () => {
64-
assert.deepEqual(simctlListDevicesArgs(' /tmp/set '), [
65-
'--set',
66-
'/tmp/set',
67-
'list',
68-
'devices',
69-
'-j',
70-
]);
71-
assert.deepEqual(simctlListDevicesArgs(' '), ['list', 'devices', '-j']);
72-
assert.deepEqual(simctlListDevicesArgs(undefined), ['list', 'devices', '-j']);
63+
test('simctlListInventoryArgs prefixes a trimmed simulator set and omits a blank one', () => {
64+
assert.deepEqual(simctlListInventoryArgs(' /tmp/set '), ['--set', '/tmp/set', 'list', '-j']);
65+
assert.deepEqual(simctlListInventoryArgs(' '), ['list', '-j']);
66+
assert.deepEqual(simctlListInventoryArgs(undefined), ['list', '-j']);
7367
});
7468

7569
test('simctlAvailabilityProbeArgs names no set', () => {

‎packages/platform-apple/src/core/simctl.ts‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,12 @@ export function simctlAvailabilityProbeArgs(): ScopedSimctlArgs {
3535
return scopeSimctlArgs(undefined, ['help']);
3636
}
3737

38-
/** `simctl list devices -j` over one simulator set; `undefined` lists the default set. */
39-
export function simctlListDevicesArgs(simulatorSetPath: string | undefined): ScopedSimctlArgs {
40-
return scopeSimctlArgs(simulatorSetPath, ['list', 'devices', '-j']);
38+
/**
39+
* `simctl list -j` over one simulator set; `undefined` lists the default set. The unfiltered
40+
* listing carries devices together with the device types and runtimes that describe them.
41+
*/
42+
export function simctlListInventoryArgs(simulatorSetPath: string | undefined): ScopedSimctlArgs {
43+
return scopeSimctlArgs(simulatorSetPath, ['list', '-j']);
4144
}
4245

4346
/** Arguments that follow the `simctl` tool name, scoped to the simulator set holding the device. */

‎packages/platform-apple/src/inventory-classification.test.ts‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,27 @@ test('devicectl records map to normalized physical Apple devices', () => {
6262
null,
6363
);
6464
});
65+
66+
test('devicectl records report the marketing model and OS version', () => {
67+
const devicectlRecord = {
68+
identifier: '3F1DAD0D-212F-44F2-B41E-C390F96140BE',
69+
hardwareProperties: {
70+
deviceType: 'iPhone',
71+
marketingName: 'iPhone 17 Pro',
72+
platform: 'iOS',
73+
productType: 'iPhone18,1',
74+
udid: '00008150-000A1C2E3F40001E',
75+
},
76+
deviceProperties: {
77+
bootState: 'booted',
78+
name: 'Oskar iPhone',
79+
osBuildUpdate: '23F77',
80+
osVersionNumber: '26.5',
81+
},
82+
connectionProperties: { pairingState: 'paired', tunnelState: 'connected' },
83+
};
84+
const device = mapDevicectlAppleDevice(devicectlRecord);
85+
assert.equal(device?.name, 'Oskar iPhone');
86+
assert.equal(device?.model, 'iPhone 17 Pro');
87+
assert.equal(device?.osVersion, '26.5');
88+
});

‎packages/platform-apple/src/inventory-classification.ts‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,18 @@ const APPLE_TV_LABEL_HINTS = ['apple tv', 'appletv', 'tvos'] as const;
1010
export type DevicectlAppleDevice = {
1111
identifier?: string;
1212
name?: string;
13-
hardwareProperties?: { platform?: string; udid?: string; productType?: string };
14-
deviceProperties?: { name?: string; productType?: string; deviceType?: string };
13+
hardwareProperties?: {
14+
platform?: string;
15+
udid?: string;
16+
productType?: string;
17+
marketingName?: string;
18+
};
19+
deviceProperties?: {
20+
name?: string;
21+
productType?: string;
22+
deviceType?: string;
23+
osVersionNumber?: string;
24+
};
1525
connectionProperties?: { tunnelState?: string };
1626
};
1727

@@ -106,13 +116,17 @@ export function mapDevicectlAppleDevice(device: DevicectlAppleDevice): DeviceInf
106116
const name = device.name ?? device.deviceProperties?.name ?? id;
107117
if (!id) return null;
108118
const target = resolveAppleTargetFromDevicectlDevice(device);
119+
const model = device.hardwareProperties?.marketingName?.trim();
120+
const osVersion = device.deviceProperties?.osVersionNumber?.trim();
109121
return {
110122
platform: 'apple',
111123
id,
112124
name,
113125
kind: 'device',
114126
target,
115127
appleOs: resolveAppleOs(target, [devicectlProductType(device), ...devicectlLabels(device)]),
128+
...(model ? { model } : {}),
129+
...(osVersion ? { osVersion } : {}),
116130
iosPhysicalDeviceBackend: 'coredevice',
117131
booted: true,
118132
};

0 commit comments

Comments
 (0)