Skip to content

Commit 9fc1cda

Browse files
committed
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.
1 parent 620cecb commit 9fc1cda

22 files changed

Lines changed: 278 additions & 35 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.test.ts‎

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ 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+
['ro.product.model', 'sdk_gphone16k_arm64\n'],
21+
['ro.build.version.release', '17\n'],
22+
['ro.build.characteristics', 'phone\n'],
23+
['has-feature', 'false\n'],
24+
['pm\0list\0features', ''],
25+
];
26+
1727
test.each([
1828
['include-stopped', true],
1929
['running-only', false],
@@ -30,11 +40,8 @@ test.each([
3040
'List of devices attached\nemulator-5554 device model:Pixel_9_Pro_XL\nphysical-1 device model:Phone\n',
3141
);
3242
}
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('');
43+
const probe = RUNNING_EMULATOR_PROBES.find(([fragment]) => key.includes(fragment));
44+
if (probe) return result(probe[1]);
3845
throw new Error(`Unexpected command: ${request.executable} ${request.args.join(' ')}`);
3946
});
4047

@@ -44,17 +51,50 @@ test.each([
4451
);
4552

4653
assert.deepEqual(
47-
devices.map((candidate) => [candidate.id, candidate.name, candidate.booted]),
54+
devices.map((candidate) => [
55+
candidate.id,
56+
candidate.name,
57+
candidate.booted,
58+
candidate.model,
59+
candidate.osVersion,
60+
]),
4861
[
49-
['emulator-5554', 'Pixel 9 Pro XL', true],
50-
...(includesStoppedAvd ? [['Living_Room_TV', 'Living_Room_TV', false] as const] : []),
62+
['emulator-5554', 'Pixel 9 Pro XL', true, 'sdk_gphone16k_arm64', '17'],
63+
...(includesStoppedAvd
64+
? [['Living_Room_TV', 'Living_Room_TV', false, undefined, undefined] as const]
65+
: []),
5166
],
5267
);
5368
assert.ok(calls.every((call) => call.timeoutMs === 10_000));
5469
assert.ok(calls.every((call) => call.allowFailure === true));
5570
},
5671
);
5772

73+
test('Android inventory leaves model and OS version unset when the getprop probe fails', async () => {
74+
const host = createHost(async (request) => {
75+
const key = request.args.join('\0');
76+
if (key === 'devices\0-l')
77+
return result('List of devices attached\nR5CT1 device model:SM_S921B\n');
78+
if (key.includes('ro.product.model') || key.includes('ro.build.version.release')) {
79+
return result('', 'error: closed', 1);
80+
}
81+
if (key.includes('sys.boot_completed')) return result('1\n');
82+
if (key.includes('ro.build.characteristics')) return result('phone\n');
83+
if (key.includes('has-feature')) return result('false\n');
84+
if (key.includes('pm\0list\0features')) return result('');
85+
throw new Error(`Unexpected command: ${request.executable} ${request.args.join(' ')}`);
86+
});
87+
88+
const [device] = await createAndroidInventory(host).discover(
89+
{ androidAvdSelection: 'running-only' },
90+
scope,
91+
);
92+
93+
assert.equal(device?.name, 'SM S921B');
94+
assert.equal(device?.model, undefined);
95+
assert.equal(device?.osVersion, undefined);
96+
});
97+
5898
test('Android inventory fails closed when adb is unavailable', async () => {
5999
const host = createHost(async () => result(''), { adb: undefined });
60100
await assert.rejects(

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,21 +119,40 @@ async function probeRunningDevice(
119119
context: AndroidInventoryContext,
120120
entry: AndroidDeviceEntry,
121121
): Promise<DeviceInfo> {
122-
const [name, booted, target] = await Promise.all([
122+
const [name, booted, target, model, osVersion] = await Promise.all([
123123
resolveDeviceName(context, entry),
124124
isBooted(context, entry.serial),
125125
resolveTarget(context, entry.serial),
126+
readDeviceProp(context, entry.serial, 'ro.product.model'),
127+
readDeviceProp(context, entry.serial, 'ro.build.version.release'),
126128
]);
127129
return {
128130
platform: 'android',
129131
id: entry.serial,
130132
name,
131133
kind: isAndroidEmulatorSerial(entry.serial) ? 'emulator' : 'device',
132134
target,
135+
...(model ? { model } : {}),
136+
...(osVersion ? { osVersion } : {}),
133137
booted,
134138
};
135139
}
136140

141+
/** Best-effort `getprop` read for presentation fields; a failed probe leaves the field unset. */
142+
async function readDeviceProp(
143+
context: AndroidInventoryContext,
144+
serial: string,
145+
prop: string,
146+
): Promise<string | undefined> {
147+
try {
148+
const result = await runAdbShell(context, serial, ['getprop', prop]);
149+
return (result.exitCode === 0 && result.stdout.trim()) || undefined;
150+
} catch (error) {
151+
if (context.scope.signal.aborted) throw error;
152+
return undefined;
153+
}
154+
}
155+
137156
async function resolveDeviceName(
138157
context: AndroidInventoryContext,
139158
entry: AndroidDeviceEntry,

‎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
};

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ test('simulator-only inventory avoids physical discovery and observes fresh boot
114114
['sim-1'],
115115
);
116116
assert.deepEqual(observed, ['sim-1']);
117-
assert.deepEqual(calls, [['simctl', 'list', 'devices', '-j']]);
117+
assert.deepEqual(calls, [['simctl', 'list', '-j']]);
118118
});
119119

120120
test('simulator-set inventory remains scoped while retaining the host Mac', async () => {
@@ -148,7 +148,7 @@ test('simulator-set inventory remains scoped while retaining the host Mac', asyn
148148
devices.map((device) => device.id),
149149
['tv-1', 'host-macos-local'],
150150
);
151-
assert.deepEqual(calls, [['simctl', '--set', '/tmp/custom-set', 'list', 'devices', '-j']]);
151+
assert.deepEqual(calls, [['simctl', '--set', '/tmp/custom-set', 'list', '-j']]);
152152
});
153153

154154
test('unscoped Apple inventory starts simulator and physical discovery concurrently', async () => {

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,19 @@ test('xctrace parser accepts Apple devices only from the online Devices section'
2727
);
2828
});
2929

30+
test('xctrace parser reports the OS version printed beside a physical device', () => {
31+
const [device] = parseXctracePhysicalAppleDevices(
32+
[
33+
'== Devices ==',
34+
'Oskar’s Mac Mini (A80D8E51-93C6-5832-A2EC-FAF18C7F6B6C)',
35+
'Oskar’s iPhone (18.6) (00008110-001A2B3C4D5E801E)',
36+
].join('\n'),
37+
);
38+
assert.equal(device?.id, '00008110-001A2B3C4D5E801E');
39+
assert.equal(device?.osVersion, '18.6');
40+
assert.equal(device?.model, undefined);
41+
});
42+
3043
test('physical inventory prefers CoreDevice, supplements xctrace, and disposes its file', async () => {
3144
const calls: string[][] = [];
3245
let disposeCount = 0;

0 commit comments

Comments
 (0)