From 3704608ebcc6484d49494a5330bfca72d329070c Mon Sep 17 00:00:00 2001 From: parbez Date: Thu, 26 Nov 2026 19:26:44 +0530 Subject: [PATCH 1/8] feat(settings): add value form to the settings catalog --- packages/contracts/src/client-settings.ts | 10 +++++++-- packages/contracts/src/settings-catalog.ts | 5 +++++ packages/contracts/src/settings.ts | 26 ++++++++++++++++++++++ 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/packages/contracts/src/client-settings.ts b/packages/contracts/src/client-settings.ts index f2c3b9756a..87a4317999 100644 --- a/packages/contracts/src/client-settings.ts +++ b/packages/contracts/src/client-settings.ts @@ -7,6 +7,7 @@ import type { PermissionAction, PermissionMode, SETTINGS, + SETTING_RESET_STATE, SettingName, } from './settings-catalog.ts'; @@ -19,7 +20,9 @@ type FormState
= Form extends { kind: 'on-off' } ? 'on' | 'off' : Form extends { kind: 'choice'; states: readonly (infer State)[] } ? State - : never; + : Form extends { kind: 'value' } + ? typeof SETTING_RESET_STATE | (string & {}) + : never; type SettingState = FormState<(typeof SETTINGS)[Name]['forms'][number]>; @@ -36,7 +39,10 @@ type StateOnlySettingOptions = { : { setting: Name; state: SettingState }); }[StateOnlySetting]; -/** Switches that change the whole Android device; naming an app is refused with `setting_app_not_consumed`. */ +/** + * Settings that change the whole device on Android and wherever else they run; naming an app is + * refused with `setting_app_not_consumed`. + */ type DeviceLevelToggleSetting = { [Name in SettingName]: (typeof SETTINGS)[Name] extends { app: 'input'; diff --git a/packages/contracts/src/settings-catalog.ts b/packages/contracts/src/settings-catalog.ts index 90a606586d..5cff2372b0 100644 --- a/packages/contracts/src/settings-catalog.ts +++ b/packages/contracts/src/settings-catalog.ts @@ -52,6 +52,9 @@ export const TEXT_SIZE_CATEGORIES = [ export const APPEARANCE_ACTIONS = ['light', 'dark', 'toggle'] as const; +/** The state a `value` setting takes to hand the value back to the device's own default. */ +export const SETTING_RESET_STATE = 'reset'; + export type PermissionAction = (typeof PERMISSION_ACTIONS)[number]; export type PermissionMode = (typeof PERMISSION_MODES)[number]; export type MobilePermissionTarget = (typeof MOBILE_PERMISSION_TARGETS)[number]; @@ -81,6 +84,8 @@ export type SettingForm = Readonly< modes?: readonly PermissionMode[]; } | { kind: 'app-id' } + /** One value the setting validates itself, or {@link SETTING_RESET_STATE}. */ + | { kind: 'value'; placeholder: string } >; export type SettingDefinition = Readonly<{ diff --git a/packages/contracts/src/settings.ts b/packages/contracts/src/settings.ts index b9bc4b8a1d..b25cd46276 100644 --- a/packages/contracts/src/settings.ts +++ b/packages/contracts/src/settings.ts @@ -11,6 +11,7 @@ import { SETTINGS, settingDefinition, SETTING_NAMES, + SETTING_RESET_STATE, TEXT_SIZE_CATEGORIES, type AppearanceAction, type MobilePermissionTarget, @@ -218,6 +219,8 @@ function formUsage(form: SettingForm, readable: boolean): string { } case 'app-id': return '[app-id]'; + case 'value': + return `<${form.placeholder}|${SETTING_RESET_STATE}>`; } } @@ -300,6 +303,9 @@ function parseFormPositionals( case 'on-off': if (positionals.length !== 2) throw invalidSettingsArgs(); return { setting, state: readSettingState(state) ? 'on' : 'off' }; + case 'value': + if (positionals.length !== 2) throw invalidSettingsArgs(); + return { setting, state: parseSettingValue(setting, positionals[1] ?? '') }; default: if (positionals.length !== 2) throw invalidSettingsArgs(); return { setting, state }; @@ -392,10 +398,30 @@ function formAcceptsState(form: SettingForm, state: string | undefined): boolean case 'permission': return findVocabularyName(form.actions, state) !== undefined; case 'app-id': + case 'value': return true; } } +/** The settings whose form is a `value`: each one validates its own value before dispatch. */ +type ValueSetting = { + [Name in SettingName]: Extract< + (typeof SETTINGS)[Name]['forms'][number], + { kind: 'value' } + > extends never + ? never + : Name; +}[SettingName]; + +const VALUE_PARSERS = {} as const satisfies Record string>; + +/** The value as the owners write it, or `reset`, so no device is handed a value it cannot read. */ +function parseSettingValue(setting: SettingName, value: string): string { + if (normalizeName(value) === SETTING_RESET_STATE) return SETTING_RESET_STATE; + const parser: (raw: string) => string = VALUE_PARSERS[setting as ValueSetting]; + return parser(value); +} + function normalizeName(value: string | undefined): string | undefined { return value?.trim().toLowerCase(); } From b7dd6c0e94a02ea9e95a14f5eacef7a9f58a723b Mon Sep 17 00:00:00 2001 From: parbez Date: Thu, 26 Nov 2026 19:28:18 +0530 Subject: [PATCH 2/8] feat(settings): declare timezone setting --- .../src/capture/settings.test.ts | 18 +++ .../command-surface/src/capture/settings.ts | 6 +- .../contracts/src/client-settings.test.ts | 11 ++ packages/contracts/src/settings-catalog.ts | 6 + packages/contracts/src/settings.test.ts | 58 ++++++++- packages/contracts/src/settings.ts | 38 +++++- .../support/snapshot-runtime-fixture.ts | 2 + .../snapshot-settings-handler.test.ts | 115 ++++++++++++++---- 8 files changed, 223 insertions(+), 31 deletions(-) diff --git a/packages/command-surface/src/capture/settings.test.ts b/packages/command-surface/src/capture/settings.test.ts index 1e9ae17e6d..c2e0609521 100644 --- a/packages/command-surface/src/capture/settings.test.ts +++ b/packages/command-surface/src/capture/settings.test.ts @@ -96,6 +96,24 @@ describe('settings CLI permission', () => { } }); + test('reads timezone as a written value the daemon parses again', () => { + const timeZone = settingsCliReader(['timezone', 'Asia/Kolkata'], { + targetApp: 'com.example.app', + } as CliFlags); + expect(timeZone).toEqual({ + setting: 'timezone', + state: 'Asia/Kolkata', + app: 'com.example.app', + }); + expect(settingsDaemonWriter(timeZone)).toMatchObject({ + positionals: ['timezone', 'Asia/Kolkata'], + input: { app: 'com.example.app' }, + }); + expect(() => settingsCliReader(['timezone', '+05:30'], flags())).toThrow( + expect.objectContaining({ code: 'INVALID_ARGS' }), + ); + }); + test.each(['mobile-data', 'bluetooth'])( 'forwards --app on %s so the daemon refuses it instead of dropping it', (setting) => { diff --git a/packages/command-surface/src/capture/settings.ts b/packages/command-surface/src/capture/settings.ts index 0b6d7d6d32..abf82994bb 100644 --- a/packages/command-surface/src/capture/settings.ts +++ b/packages/command-surface/src/capture/settings.ts @@ -25,7 +25,7 @@ import { defineFieldCommandMetadata } from '../field-command-contract.ts'; const SETTINGS_COMMAND_NAME = 'settings'; const settingsCommandDescription = - 'Read or change supported operating-system settings, animation scales, appearance, or app permissions on the selected target. Platform support varies by setting and action.'; + 'Read or change supported operating-system settings, animation scales, appearance, time zone, or app permissions on the selected target. Platform support varies by setting and action.'; const settingsCommandMetadata = defineFieldCommandMetadata( SETTINGS_COMMAND_NAME, @@ -35,7 +35,7 @@ const settingsCommandMetadata = defineFieldCommandMetadata( // A readable setting answers with no state; the parse decides per setting. state: stringField(), app: stringField( - 'App the change targets, by bundle id, package name, or app name: the app `clear-app-state` clears, or the app a `permission` change (or an iOS-simulator `location on|off` privacy change) lands on. A name resolves to the installed app as `open` resolves it: an iOS simulator, local or Limrun, matches display names and accepts only an installed bundle id, and Android accepts only an installed package and refuses a name that resolves to an intent with `setting_app_not_package`. One that resolves to nothing is refused with `app_not_installed` before anything changes. The app need not be running. Without it the session app is used; a device-wide change (`location set` on any target, the Android `location on|off` toggle, `mobile-data`, `keep-awake`, macOS permissions) refuses one with `setting_app_not_consumed`. The CLI reads it only from this invocation, never from `AGENT_DEVICE_TARGET_APP` or config `targetApp`.', + 'App the change targets, by bundle id, package name, or app name: the app `clear-app-state` clears, or the app a `permission` change (or an iOS-simulator `location on|off` privacy change) lands on. A name resolves to the installed app as `open` resolves it: an iOS simulator, local or Limrun, matches display names and accepts only an installed bundle id, and Android accepts only an installed package and refuses a name that resolves to an intent with `setting_app_not_package`. One that resolves to nothing is refused with `app_not_installed` before anything changes. The app need not be running. Without it the session app is used; a device-wide change (`location set` on any target, the Android `location on|off` toggle, `mobile-data`, `keep-awake`, `bluetooth`, `timezone`, macOS permissions) refuses one with `setting_app_not_consumed`. The CLI reads it only from this invocation, never from `AGENT_DEVICE_TARGET_APP` or config `targetApp`.', ), latitude: numberField(), longitude: numberField(), @@ -101,7 +101,7 @@ export const settingsCommandFacet = defineCommandFacet({ effect: 'destructive', text: { summary: 'Change OS settings and app permissions', - searchHint: 'wifi airplane location dark mode permission grant revoke', + searchHint: 'wifi airplane location dark mode permission grant revoke timezone', cliDetail: [ 'A bare readable setting reads the value the target holds. A target that does not serve a setting refuses it with UNSUPPORTED_OPERATION before anything changes.', '', diff --git a/packages/contracts/src/client-settings.test.ts b/packages/contracts/src/client-settings.test.ts index 800a8341c2..b55a12f4bf 100644 --- a/packages/contracts/src/client-settings.test.ts +++ b/packages/contracts/src/client-settings.test.ts @@ -75,6 +75,17 @@ describe('public client settings cover the catalog', () => { expectTypeOf().toEqualTypeOf<'on' | 'off'>(); expectTypeOf().toEqualTypeOf(); }); + + test('timezone takes a value or reset, and an app to refuse', () => { + type Value = Extract; + expectTypeOf<{ + setting: 'timezone'; + state: 'Asia/Kolkata'; + }>().toExtend(); + expectTypeOf<{ setting: 'timezone'; state: 'reset' }>().toExtend(); + expectTypeOf<{ setting: 'timezone' }>().not.toExtend(); + expectTypeOf().toEqualTypeOf(); + }); }); /** diff --git a/packages/contracts/src/settings-catalog.ts b/packages/contracts/src/settings-catalog.ts index 5cff2372b0..69bf0bcb01 100644 --- a/packages/contracts/src/settings-catalog.ts +++ b/packages/contracts/src/settings-catalog.ts @@ -149,6 +149,12 @@ export const SETTINGS = { readable: true, help: 'Reads the preferred text size without a category and applies one with it, on iPhone and iPad simulators (simctl content size) and Android (system font_scale). Android has no ladder of its own: a read names the nearest rung and reports the multiplier as platformValue. A running app adopts a new size at its next configuration change, so relaunch it.', }, + timezone: { + forms: [{ kind: 'value', placeholder: 'iana-zone' }], + app: 'input', + appScope: { apple: 'device-level', mobile: 'device-level' }, + help: 'Sets the device time zone from an IANA name, such as Asia/Kolkata, on iPhone and iPad simulators (sets TZ in simulator launchd; applies only to apps launched afterwards and is lost when the simulator reboots; the status bar keeps the host time) and Android (the system time zone, with automatic time zone turned off). reset hands it back to the device default: the host Mac time zone on a simulator, and automatic time zone on Android, which applies the network zone a moment later. The response reports the time zone held before. --app is refused.', + }, faceid: { forms: [{ kind: 'choice', states: ['match', 'nonmatch', 'enroll', 'unenroll'] }], help: 'Simulates Face ID on iPhone and iPad simulators.', diff --git a/packages/contracts/src/settings.test.ts b/packages/contracts/src/settings.test.ts index 76b53d93e8..1bb1f8aabc 100644 --- a/packages/contracts/src/settings.test.ts +++ b/packages/contracts/src/settings.test.ts @@ -8,6 +8,7 @@ import { parseSettingsMutation, parseSettingState, parseTextSizeCategory, + parseTimeZoneId, readTextSizeCategory, settingsAppNotConsumedRefusal, settingsAppScope, @@ -44,6 +45,7 @@ describe('settings usage', () => { 'settings location set ', 'settings appearance ', `settings text-size [${TEXT_SIZE_CATEGORIES.join('|')}]`, + 'settings timezone ', 'settings ', 'settings fingerprint ', 'settings clear-app-state [app-id]', @@ -229,6 +231,54 @@ describe('text-size', () => { }); }); +describe('timezone', () => { + test('a time zone the host lists is normalized to the host casing', () => { + expect(parseSettingsMutation(['Timezone', 'Asia/Kolkata'])).toEqual({ + setting: 'timezone', + state: 'Asia/Kolkata', + }); + expect(parseTimeZoneId('america/new_york')).toBe('America/New_York'); + expect(parseTimeZoneId(' Etc/GMT+5 ')).toBe('Etc/GMT+5'); + }); + + test('an alias Intl knows passes through regardless of casing so device read-back decides', () => { + expect(parseTimeZoneId('Asia/Kolkata')).toBe('Asia/Kolkata'); + expect(parseTimeZoneId('asia/kolkata')).toBe('asia/kolkata'); + expect(parseTimeZoneId('US/Pacific')).toBe('US/Pacific'); + expect(parseTimeZoneId('us/pacific')).toBe('us/pacific'); + }); + + test('an offset or a name the time zone data does not know is refused', () => { + for (const value of ['+05:30', 'Mars/Olympus_Mons', 'Asia/', '']) { + expectInvalidArgs(() => parseTimeZoneId(value), `Invalid time zone: ${value}.`); + } + }); + + test('reset is a state of its own, and timezone takes exactly one value', () => { + expect(parseSettingsMutation(['timezone', 'RESET'])).toEqual({ + setting: 'timezone', + state: 'reset', + }); + expectInvalidArgs( + () => parseSettingsMutation(['timezone']), + 'settings timezone requires a state: .', + ); + expectInvalidArgs( + () => parseSettingsMutation(['timezone', 'Asia/Kolkata', 'extra']), + SETTINGS_INVALID_ARGS_MESSAGE, + ); + }); + + test('timezone writes answer with the zone set or the reset', () => { + expect(describeSettingWrite('timezone', 'Asia/Kolkata', undefined)).toBe( + 'Time zone set to Asia/Kolkata', + ); + expect(describeSettingWrite('timezone', 'reset', undefined)).toBe( + 'Time zone reset to the device default', + ); + }); +}); + describe('owner parsers', () => { test('parsePermissionTarget accepts the mobile targets only', () => { expect(parsePermissionTarget(' Camera ')).toBe('camera'); @@ -281,7 +331,13 @@ describe('settingsAppScope', () => { }); }); -describe('settingsAppScope device-wide radios', () => { +describe('settingsAppScope device-wide settings', () => { + test('timezone changes the whole device on every mobile family', () => { + expect(settingsAppScope('apple', 'timezone', 'reset')).toBe('device-level'); + expect(settingsAppScope('mobile', 'timezone', 'Asia/Kolkata')).toBe('device-level'); + expect(settingsAppScope('macos-host', 'timezone', 'reset')).toBe('unknown'); + }); + test.each(['mobile-data', 'keep-awake', 'bluetooth'])( '%s switches the whole device wherever it is served', (setting) => { diff --git a/packages/contracts/src/settings.ts b/packages/contracts/src/settings.ts index b25cd46276..c56561a9ef 100644 --- a/packages/contracts/src/settings.ts +++ b/packages/contracts/src/settings.ts @@ -70,6 +70,11 @@ export function describeSettingWrite( ): string { if (setting === 'clear-app-state') return `Cleared user data for ${appBundleId}`; if (setting === 'text-size') return `Text size set to ${state}`; + if (setting === 'timezone') { + return state === SETTING_RESET_STATE + ? 'Time zone reset to the device default' + : `Time zone set to ${state}`; + } return `Updated setting: ${setting}`; } @@ -413,7 +418,9 @@ type ValueSetting = { : Name; }[SettingName]; -const VALUE_PARSERS = {} as const satisfies Record string>; +const VALUE_PARSERS = { + timezone: parseTimeZoneId, +} as const satisfies Record string>; /** The value as the owners write it, or `reset`, so no device is handed a value it cannot read. */ function parseSettingValue(setting: SettingName, value: string): string { @@ -422,6 +429,35 @@ function parseSettingValue(setting: SettingName, value: string): string { return parser(value); } +const TIME_ZONE_NAME_PATTERN = /^[A-Za-z][\w+-]*(\/[\w+-]+)*$/; + +/** + * An IANA time zone name the host's time zone data knows. A name `Intl.supportedValuesOf` lists + * is normalized to its listed casing; an alias it does not list, such as `Asia/Kolkata`, is kept + * as written and checked by the target device on read-back. Offsets such as `+05:30` are refused + * because neither owner takes one. + */ +export function parseTimeZoneId(value: string): string { + const name = value.trim(); + if (TIME_ZONE_NAME_PATTERN.test(name) && isKnownTimeZone(name)) { + const lower = name.toLowerCase(); + return Intl.supportedValuesOf('timeZone').find((zone) => zone.toLowerCase() === lower) ?? name; + } + throw new AppError( + 'INVALID_ARGS', + `Invalid time zone: ${value}. Use an IANA time zone name, such as Asia/Kolkata or America/New_York.`, + ); +} + +function isKnownTimeZone(name: string): boolean { + try { + new Intl.DateTimeFormat('en-US', { timeZone: name }); + return true; + } catch { + return false; + } +} + function normalizeName(value: string | undefined): string | undefined { return value?.trim().toLowerCase(); } diff --git a/packages/daemon/src/__tests__/support/snapshot-runtime-fixture.ts b/packages/daemon/src/__tests__/support/snapshot-runtime-fixture.ts index f60797edb6..2d7521258b 100644 --- a/packages/daemon/src/__tests__/support/snapshot-runtime-fixture.ts +++ b/packages/daemon/src/__tests__/support/snapshot-runtime-fixture.ts @@ -190,6 +190,7 @@ function settingsFacts(device: DeviceInfo) { animations: available, appearance: available, 'text-size': available, + timezone: available, fingerprint: available, 'clear-app-state': available, permission: available, @@ -227,6 +228,7 @@ function settingsFacts(device: DeviceInfo) { 'reset-keychain': available, permission: available, 'text-size': handheld, + timezone: handheld, faceid: handheld, touchid: handheld, }, diff --git a/packages/daemon/src/execution/handlers/__tests__/snapshot-settings-handler.test.ts b/packages/daemon/src/execution/handlers/__tests__/snapshot-settings-handler.test.ts index b269f9df27..3516036d0a 100644 --- a/packages/daemon/src/execution/handlers/__tests__/snapshot-settings-handler.test.ts +++ b/packages/daemon/src/execution/handlers/__tests__/snapshot-settings-handler.test.ts @@ -690,6 +690,67 @@ test('settings iOS location set refuses a named app before reaching the owner', } }); +test.each([ + { + positionals: ['timezone', 'america/new_york'], + state: 'America/New_York', + message: 'Time zone set to America/New_York', + }, + { + positionals: ['timezone', 'RESET'], + state: 'reset', + message: 'Time zone reset to the device default', + }, +])('settings $positionals reaches the owner as the parsed value', async (row) => { + const sessionStore = makeSessionStore(); + const sessionName = `ios-${row.positionals[0]}-${row.state}`; + sessionStore.publish(sessionName, makeSession(sessionName, iosSimulatorDevice)); + + const response = await handleSnapshotCommands({ + createCommandSurface: fakeCreateCommandSurface, + platformServices: daemonPlatformServicesFixture(), + req: snapshotRequest(sessionName, 'settings', { positionals: row.positionals }), + sessionName, + logPath: '/tmp/daemon.log', + sessionStore, + }); + + expect(response?.ok && response.data).toMatchObject({ state: row.state, message: row.message }); + expect(fixtureSettingsMutations.at(-1)).toMatchObject({ + setting: row.positionals[0], + state: row.state, + }); +}); + +test('settings timezone refuses an invalid zone and a tvOS leaf before reaching the owner', async () => { + const sessionStore = makeSessionStore(); + sessionStore.publish('ios-tz-invalid', makeSession('ios-tz-invalid', iosSimulatorDevice)); + sessionStore.publish('tvos-tz', makeSession('tvos-tz', tvOsSimulatorDevice)); + + const invalid = await handleSnapshotCommands({ + createCommandSurface: fakeCreateCommandSurface, + platformServices: daemonPlatformServicesFixture(), + req: snapshotRequest('ios-tz-invalid', 'settings', { + positionals: ['timezone', '+05:30'], + }), + sessionName: 'ios-tz-invalid', + logPath: '/tmp/daemon.log', + sessionStore, + }); + const tvos = await handleSnapshotCommands({ + createCommandSurface: fakeCreateCommandSurface, + platformServices: daemonPlatformServicesFixture(), + req: snapshotRequest('tvos-tz', 'settings', { positionals: ['timezone', 'Asia/Kolkata'] }), + sessionName: 'tvos-tz', + logPath: '/tmp/daemon.log', + sessionStore, + }); + + expect(invalid?.ok === false && invalid.error.code).toBe('INVALID_ARGS'); + expect(tvos?.ok === false && tvos.error.code).toBe('UNSUPPORTED_OPERATION'); + expect(fixtureSettingsMutations).toHaveLength(0); +}); + // A macOS permission is a host-level TCC grant, so naming an app is refused rather than dropped. test('settings mobile-data reaches the Android owner as an on/off mutation', async () => { const sessionStore = makeSessionStore(); @@ -709,34 +770,36 @@ test('settings mobile-data reaches the Android owner as an on/off mutation', asy expect(fixtureSettingsMutations.at(-1)).toMatchObject({ setting: 'mobile-data', state: 'off' }); }); -test.each(['mobile-data', 'keep-awake', 'bluetooth'])( - 'settings Android %s refuses a named app before reaching the owner', - async (setting) => { - const sessionStore = makeSessionStore(); - const sessionName = `android-${setting}-app-refused`; - sessionStore.publish(sessionName, makeSession(sessionName, androidDevice)); +test.each([ + ['mobile-data', 'off'], + ['keep-awake', 'off'], + ['bluetooth', 'off'], + ['timezone', 'Asia/Kolkata'], +])('settings Android %s refuses a named app before reaching the owner', async (setting, state) => { + const sessionStore = makeSessionStore(); + const sessionName = `android-${setting}-app-refused`; + sessionStore.publish(sessionName, makeSession(sessionName, androidDevice)); - const response = await handleSnapshotCommands({ - createCommandSurface: fakeCreateCommandSurface, - platformServices: daemonPlatformServicesFixture(), - req: snapshotRequest(sessionName, 'settings', { - positionals: [setting, 'off'], - input: { app: 'com.example.app' }, - }), - sessionName, - logPath: '/tmp/daemon.log', - sessionStore, - }); + const response = await handleSnapshotCommands({ + createCommandSurface: fakeCreateCommandSurface, + platformServices: daemonPlatformServicesFixture(), + req: snapshotRequest(sessionName, 'settings', { + positionals: [setting, state], + input: { app: 'com.example.app' }, + }), + sessionName, + logPath: '/tmp/daemon.log', + sessionStore, + }); - expect(response?.ok).toBe(false); - expect(fixtureSettingsMutations).toHaveLength(0); - if (response && !response.ok) { - expect(response.error.code).toBe('INVALID_ARGS'); - expect(response.error.details?.reason).toBe('setting_app_not_consumed'); - expect(response.error.details?.dispatched).toBe('no'); - } - }, -); + expect(response?.ok).toBe(false); + expect(fixtureSettingsMutations).toHaveLength(0); + if (response && !response.ok) { + expect(response.error.code).toBe('INVALID_ARGS'); + expect(response.error.details?.reason).toBe('setting_app_not_consumed'); + expect(response.error.details?.dispatched).toBe('no'); + } +}); test('settings macOS permission grant refuses a named app before reaching the owner', async () => { const sessionStore = makeSessionStore(); From cbc521d691861db5aa82d9f1f9989480f8173bf2 Mon Sep 17 00:00:00 2001 From: parbez Date: Thu, 26 Nov 2026 19:29:24 +0530 Subject: [PATCH 3/8] feat(ios): set the simulator time zone --- .../core/__tests__/settings-timezone.test.ts | 65 +++++++++++++++++++ .../platform-apple/src/core/app-settings.ts | 4 ++ .../src/core/settings-timezone.ts | 49 ++++++++++++++ .../platform-apple/src/system/runtime.test.ts | 8 +-- packages/platform-apple/src/system/runtime.ts | 6 +- .../src/interaction-operations.test.ts | 6 +- .../src/interaction-operations.ts | 4 ++ 7 files changed, 136 insertions(+), 6 deletions(-) create mode 100644 packages/platform-apple/src/core/__tests__/settings-timezone.test.ts create mode 100644 packages/platform-apple/src/core/settings-timezone.ts diff --git a/packages/platform-apple/src/core/__tests__/settings-timezone.test.ts b/packages/platform-apple/src/core/__tests__/settings-timezone.test.ts new file mode 100644 index 0000000000..91c9d26939 --- /dev/null +++ b/packages/platform-apple/src/core/__tests__/settings-timezone.test.ts @@ -0,0 +1,65 @@ +import { expect, test } from 'vitest'; + +import { setIosSetting } from '../app-settings.ts'; +import { withFakeAppleTool, type FakeAppleToolResponse } from '../../__tests__/fake-apple-tool.ts'; +import { IOS_TEST_SIMULATOR } from './apple-core-stub-helpers.ts'; + +const BOOTED_SIM_LIST_JSON = JSON.stringify({ + devices: { 'com.apple.CoreSimulator.SimRuntime.iOS-18-0': [{ udid: 'sim-1', state: 'Booted' }] }, +}); + +/** A simulator's launchd environment, driven through `simctl spawn`. */ +function simulator(initial: { tz?: string } = {}) { + let tz = initial.tz ?? ''; + return (args: string[]): FakeAppleToolResponse => { + if (args[0] === 'simctl' && args.includes('list')) return BOOTED_SIM_LIST_JSON; + const spawned = args.join(' ').replace(/^simctl spawn sim-1 /, ''); + if (spawned === 'launchctl getenv TZ') return `${tz}\n`; + const setenv = /^launchctl setenv TZ (\S+)$/.exec(spawned); + if (setenv || spawned === 'launchctl unsetenv TZ') { + tz = setenv?.[1] ?? ''; + return ''; + } + return { stderr: `unexpected xcrun args: ${args.join(' ')}`, exitCode: 1 }; + }; +} + +function spawnedWrites(calls: string[][]): string[] { + return calls + .filter((args) => args[1] === 'spawn') + .map((args) => args.slice(3).join(' ')) + .filter((call) => !call.includes('getenv')); +} + +async function set(state: string) { + return await setIosSetting(IOS_TEST_SIMULATOR, 'timezone', state, undefined, undefined, {}); +} + +test('settings timezone sets TZ in the simulator launchd and reset unsets it', async () => { + await withFakeAppleTool(simulator(), async ({ calls }) => { + expect(await set('Asia/Kolkata')).toMatchObject({ + timeZone: 'Asia/Kolkata', + previousTimeZone: null, + warnings: [expect.stringContaining('relaunch')], + }); + expect(await set('reset')).toMatchObject({ + timeZone: null, + previousTimeZone: 'Asia/Kolkata', + }); + expect(spawnedWrites(calls)).toEqual([ + 'launchctl setenv TZ Asia/Kolkata', + 'launchctl unsetenv TZ', + ]); + }); +}); + +test('a failed launchctl setenv fails the setting with the simctl output', async () => { + const script = (args: string[]): FakeAppleToolResponse => + args.includes('setenv') ? { stderr: 'launchd unavailable', exitCode: 1 } : simulator()(args); + await withFakeAppleTool(script, async () => { + await expect(set('Asia/Kolkata')).rejects.toMatchObject({ + code: 'COMMAND_FAILED', + details: { stderr: 'launchd unavailable' }, + }); + }); +}); diff --git a/packages/platform-apple/src/core/app-settings.ts b/packages/platform-apple/src/core/app-settings.ts index e1727cb8a3..b1da500900 100644 --- a/packages/platform-apple/src/core/app-settings.ts +++ b/packages/platform-apple/src/core/app-settings.ts @@ -24,6 +24,7 @@ import { runMacOsPermissionAction, type MacOsPermissionTarget } from '../os/maco import { closeIosApp } from './app-launch.ts'; import { applySimctlSetting } from './simctl-settings.ts'; import { readIosTextSize, setIosTextSize } from './settings-text-size.ts'; +import { setIosTimeZone } from './settings-timezone.ts'; import { resolveIosApp } from './app-resolution.ts'; import { buildSimctlArgsForDevice } from './simctl.ts'; import { runSimctlForDevice } from './simctl-execution.ts'; @@ -49,6 +50,7 @@ const APPLE_SIMULATOR_SETTINGS = [ 'reset-keychain', 'permission', 'text-size', + 'timezone', 'faceid', 'touchid', ] as const satisfies readonly SettingName[]; @@ -186,6 +188,8 @@ export async function setIosSetting( case 'text-size': { return await setIosTextSize(device, state); } + case 'timezone': + return await setIosTimeZone(device, state); case 'appearance': case 'permission': case 'location': diff --git a/packages/platform-apple/src/core/settings-timezone.ts b/packages/platform-apple/src/core/settings-timezone.ts new file mode 100644 index 0000000000..220a7985d7 --- /dev/null +++ b/packages/platform-apple/src/core/settings-timezone.ts @@ -0,0 +1,49 @@ +import { SETTING_RESET_STATE } from '@agent-device/contracts/settings-catalog'; +import type { DeviceInfo } from '@agent-device/kernel/device'; +import { requireExecSuccess } from '@agent-device/host-kit/command'; +import { runSimctlForDevice } from './simctl-execution.ts'; + +/** + * The simulator has no time zone of its own: its apps take the host Mac's unless their environment + * names one. `launchctl setenv` in the simulator's launchd sets `TZ` for every process it starts + * afterwards (until the simulator reboots), and `unsetenv` hands them back the host's zone. + */ +export async function setIosTimeZone( + device: DeviceInfo, + state: string, +): Promise> { + const timeZone = state === SETTING_RESET_STATE ? undefined : state; + const previousTimeZone = await readLaunchdTimeZone(device); + await runSimctlChecked( + device, + timeZone === undefined + ? ['launchctl', 'unsetenv', 'TZ'] + : ['launchctl', 'setenv', 'TZ', timeZone], + 'Failed to set the iOS simulator time zone', + ); + return { + timeZone: timeZone ?? null, + previousTimeZone, + warnings: [ + 'Running apps keep the old time zone until they relaunch (run open --relaunch), and the override is lost when the simulator reboots.', + ], + }; +} + +/** The `TZ` the simulator's launchd hands new processes, or `null` when they take the host's. */ +async function readLaunchdTimeZone(device: DeviceInfo): Promise { + const result = await runSimctlChecked( + device, + ['launchctl', 'getenv', 'TZ'], + 'Failed to read the iOS simulator time zone', + ); + const value = result.stdout.trim(); + return value.length > 0 ? value : null; +} + +async function runSimctlChecked(device: DeviceInfo, args: readonly string[], message: string) { + return requireExecSuccess( + await runSimctlForDevice(device, ['spawn', device.id, ...args], { allowFailure: true }), + message, + ); +} diff --git a/packages/platform-apple/src/system/runtime.test.ts b/packages/platform-apple/src/system/runtime.test.ts index 0119c58e1f..5fd3f77bd6 100644 --- a/packages/platform-apple/src/system/runtime.test.ts +++ b/packages/platform-apple/src/system/runtime.test.ts @@ -134,26 +134,26 @@ test.each([ { appleOs: 'ios', kind: 'simulator', - served: ['wifi', 'location', 'text-size', 'faceid', 'touchid', 'reset-keychain'], + served: ['wifi', 'location', 'text-size', 'timezone', 'faceid', 'touchid', 'reset-keychain'], refused: ['animations', 'fingerprint'], }, { appleOs: 'ipados', kind: 'simulator', - served: ['appearance', 'text-size', 'faceid', 'touchid'], + served: ['appearance', 'text-size', 'timezone', 'faceid', 'touchid'], refused: ['animations', 'fingerprint'], }, { appleOs: 'tvos', kind: 'simulator', served: ['wifi', 'appearance', 'clear-app-state'], - refused: ['text-size', 'faceid', 'touchid'], + refused: ['text-size', 'timezone', 'faceid', 'touchid'], }, { appleOs: 'macos', kind: 'device', served: ['appearance', 'permission'], - refused: ['wifi', 'text-size', 'clear-app-state', 'reset-keychain'], + refused: ['wifi', 'text-size', 'timezone', 'clear-app-state', 'reset-keychain'], }, ] as const)('an Apple $appleOs $kind serves each setting on its own fact', (row) => { const { setSetting } = appleSystemFacts(appleDevice(row.appleOs, row.kind)); diff --git a/packages/platform-apple/src/system/runtime.ts b/packages/platform-apple/src/system/runtime.ts index 19e4e2e743..7d5890d5c9 100644 --- a/packages/platform-apple/src/system/runtime.ts +++ b/packages/platform-apple/src/system/runtime.ts @@ -62,7 +62,10 @@ const macOsSettingUnavailable = Object.freeze({ reason: PLATFORM_RUNTIME_REASONS.unsupportedPlatformLeaf.reason, hint: 'The macOS host supports settings appearance and settings permission .', } as const); -/** Content size and BiometricKit_Sim notifications answer only on iPhone and iPad simulators. */ +/** + * Content size and BiometricKit_Sim notifications answer only on iPhone and iPad simulators. The + * time zone write is admitted there too, and nowhere else in the Apple family. + */ const handheldSimulatorUnavailable = Object.freeze({ available: false, reason: PLATFORM_RUNTIME_REASONS.unsupportedPlatformLeaf.reason, @@ -193,6 +196,7 @@ function appleSettingsFacts(device: DeviceInfo) { 'reset-keychain': available, permission: available, 'text-size': handheld, + timezone: handheld, faceid: handheld, touchid: handheld, } satisfies Record, diff --git a/packages/provider-limrun/src/interaction-operations.test.ts b/packages/provider-limrun/src/interaction-operations.test.ts index 7bdf431aad..15cfa65eb6 100644 --- a/packages/provider-limrun/src/interaction-operations.test.ts +++ b/packages/provider-limrun/src/interaction-operations.test.ts @@ -141,7 +141,7 @@ test('app-event delivery is admitted on both direct-session legs', () => { expect(factsFor(iosDevice, false).triggerAppEvent).toEqual(liveSessionUnavailable); }); -test('iOS inherits shared settings except unavailable keychain reset', () => { +test('iOS inherits shared settings except keychain reset and time zone', () => { const android = limrunAndroidSettingsFacts(); expect(runtimeSubjectFact(android.setSetting, 'animations').available).toBe(true); const ios = limrunAppleSettingsFacts(testIosRunner.facts); @@ -158,6 +158,10 @@ test('iOS inherits shared settings except unavailable keychain reset', () => { expect(runtimeSubjectFact(ios.setSetting, setting).available).toBe(true); } expect(runtimeSubjectFact(ios.setSetting, 'reset-keychain').available).toBe(false); + expect(runtimeSubjectFact(ios.setSetting, 'timezone')).toMatchObject({ + available: false, + reason: 'unsupported-provider-mode', + }); expect(runtimeSubjectFact(ios.readSetting, 'text-size').available).toBe(true); expect(limrunAndroidSettingsFacts(liveSessionUnavailable).setSetting).toEqual( liveSessionUnavailable, diff --git a/packages/provider-limrun/src/interaction-operations.ts b/packages/provider-limrun/src/interaction-operations.ts index 4ef188fb4e..4073181268 100644 --- a/packages/provider-limrun/src/interaction-operations.ts +++ b/packages/provider-limrun/src/interaction-operations.ts @@ -220,6 +220,10 @@ export function limrunAppleSettingsFacts( PLATFORM_RUNTIME_REASONS.unsupportedProviderMode.reason, 'Limrun does not expose keychain reset.', ), + timezone: unavailableFact( + PLATFORM_RUNTIME_REASONS.unsupportedProviderMode.reason, + 'Limrun iOS does not expose simulator launchd time zone overrides; set it on a local simulator.', + ), }, } : (setting ?? unsupported), From 333dcf9cd224a81e7be8fda18fcd85d7e0ea355d Mon Sep 17 00:00:00 2001 From: parbez Date: Thu, 26 Nov 2026 19:30:51 +0530 Subject: [PATCH 4/8] feat(android): set the device time zone --- .../src/__tests__/settings-timezone.test.ts | 119 ++++++++++++++++++ packages/platform-android/src/runtime.test.ts | 5 +- packages/platform-android/src/runtime.ts | 1 + .../platform-android/src/settings-timezone.ts | 75 +++++++++++ packages/platform-android/src/settings.ts | 5 + .../src/interaction-operations.test.ts | 1 + .../src/interaction-operations.ts | 1 + 7 files changed, 205 insertions(+), 2 deletions(-) create mode 100644 packages/platform-android/src/__tests__/settings-timezone.test.ts create mode 100644 packages/platform-android/src/settings-timezone.ts diff --git a/packages/platform-android/src/__tests__/settings-timezone.test.ts b/packages/platform-android/src/__tests__/settings-timezone.test.ts new file mode 100644 index 0000000000..9e7ba577cd --- /dev/null +++ b/packages/platform-android/src/__tests__/settings-timezone.test.ts @@ -0,0 +1,119 @@ +import { expect, test } from 'vitest'; +import { setAndroidSetting } from '../settings.ts'; +import { ANDROID_EMULATOR } from './test-utils/device-fixtures.ts'; +import { withFakeAdb, type FakeAdbResponse } from './test-utils/fake-adb.ts'; + +/** + * A device whose `alarm set-timezone` lands in `persist.sys.timezone` unless `honor` is false, and + * whose `auto_time_zone` row starts at `initialAutoTimeZone` and holds whatever is written to it. + */ +function timeZoneDevice( + options: { honor?: boolean; known?: boolean; initialAutoTimeZone?: string } = {}, +) { + let zone = 'America/Los_Angeles'; + const state = { autoTimeZone: options.initialAutoTimeZone ?? '1' }; + const script = (args: string[]): FakeAdbResponse => { + const flat = args.join(' '); + if (flat === 'shell getprop persist.sys.timezone') return `${zone}\n`; + if (flat === 'shell settings get global auto_time_zone') return `${state.autoTimeZone}\n`; + const auto = /^shell settings put global auto_time_zone ([01])$/.exec(flat); + if (auto) { + state.autoTimeZone = auto[1]!; + return ''; + } + const write = /^shell cmd alarm set-timezone (\S+)$/.exec(flat); + if (write) { + if (options.known === false) { + return { + stdout: 'java.lang.IllegalArgumentException: Timezone ID not valid', + exitCode: 255, + }; + } + if (options.honor !== false) zone = write[1]!; + return ''; + } + return { stderr: `unexpected args: ${flat}`, exitCode: 1 }; + }; + return Object.assign(script, { state }); +} + +test('settings timezone turns automatic time zone off, then sets and reads back the zone', async () => { + await withFakeAdb(timeZoneDevice(), async ({ calls, device }) => { + expect(await setAndroidSetting(device, 'timezone', 'Asia/Kolkata')).toEqual({ + timeZone: 'Asia/Kolkata', + previousTimeZone: 'America/Los_Angeles', + autoTimeZone: false, + }); + const flat = calls.map((args) => args.join(' ')); + expect(flat).toContain('shell settings put global auto_time_zone 0'); + expect(flat.indexOf('shell settings put global auto_time_zone 0')).toBeLessThan( + flat.indexOf('shell cmd alarm set-timezone Asia/Kolkata'), + ); + }); +}); + +test('settings timezone runs over adb on a physical Android device as well as an emulator', async () => { + const physical = { ...ANDROID_EMULATOR, id: 'R5CT1234', kind: 'device' as const }; + await withFakeAdb( + timeZoneDevice(), + async ({ device }) => { + expect(await setAndroidSetting(device, 'timezone', 'Asia/Kolkata')).toEqual({ + timeZone: 'Asia/Kolkata', + previousTimeZone: 'America/Los_Angeles', + autoTimeZone: false, + }); + }, + { device: physical }, + ); +}); + +test('settings timezone reset turns automatic time zone back on without naming a zone', async () => { + await withFakeAdb(timeZoneDevice(), async ({ calls, device }) => { + expect(await setAndroidSetting(device, 'timezone', 'reset')).toEqual({ + timeZone: null, + previousTimeZone: 'America/Los_Angeles', + autoTimeZone: true, + }); + const flat = calls.map((args) => args.join(' ')); + expect(flat).toContain('shell settings put global auto_time_zone 1'); + expect(flat.some((args) => args.includes('set-timezone'))).toBe(false); + }); +}); + +test.each([ + { name: 'keeps the old zone', options: { honor: false }, reason: 'time-zone-not-applied' }, + { name: 'rejects the zone', options: { known: false }, reason: undefined }, +])( + 'settings timezone fails when the device $name and puts automatic time zone back', + async ({ options, reason }) => { + const fake = timeZoneDevice(options); + await withFakeAdb(fake, async ({ device }) => { + const failure = await setAndroidSetting(device, 'timezone', 'Asia/Kolkata').catch( + (error: unknown) => error, + ); + expect(failure).toMatchObject({ + code: 'COMMAND_FAILED', + details: { dispatched: 'unknown', autoTimeZone: true }, + }); + expect((failure as { details: { reason?: string } }).details.reason).toBe(reason); + expect(fake.state.autoTimeZone).toBe('1'); + }); + }, +); + +test('settings timezone keeps automatic time zone off on failure when it was already off', async () => { + const fake = timeZoneDevice({ honor: false, initialAutoTimeZone: '0' }); + await withFakeAdb(fake, async ({ device }) => { + await expect(setAndroidSetting(device, 'timezone', 'asia/kolkata')).rejects.toMatchObject({ + code: 'COMMAND_FAILED', + details: { + reason: 'time-zone-not-applied', + dispatched: 'unknown', + timeZone: 'asia/kolkata', + storedTimeZone: 'America/Los_Angeles', + autoTimeZone: false, + }, + }); + expect(fake.state.autoTimeZone).toBe('0'); + }); +}); diff --git a/packages/platform-android/src/runtime.test.ts b/packages/platform-android/src/runtime.test.ts index c998040b9b..cc8e4325fc 100644 --- a/packages/platform-android/src/runtime.test.ts +++ b/packages/platform-android/src/runtime.test.ts @@ -416,12 +416,13 @@ test('admits both clipboard halves and the app switcher on every real Android ki // R57: the deep link opens through `am start` on the same cell. expect(binding.facts.operations.triggerAppEvent).toEqual({ available: true }); expect(binding.operations.triggerAppEvent).toBeTypeOf('function'); - // R58: settings run over adb (`appops`, `settings put`, `pm clear`, …) on that cell too, and - // so does the read leg (`settings get system font_scale`), which every Android kind can answer. + // R58: settings run over adb (`appops`, `settings put`, `pm clear`, `cmd alarm`, …) on both + // emulators and physical devices, and so does the read leg (`settings get system font_scale`). const { setSetting, readSetting } = binding.facts.operations; for (const setting of ANDROID_SETTINGS) { expect(runtimeSubjectFact(setSetting, setting)).toEqual({ available: true }); } + expect(runtimeSubjectFact(setSetting, 'timezone')).toEqual({ available: true }); expect(runtimeSubjectFact(setSetting, 'reset-keychain')).toMatchObject({ available: false, reason: 'unsupported-platform-leaf', diff --git a/packages/platform-android/src/runtime.ts b/packages/platform-android/src/runtime.ts index caddf4e137..3f6510f842 100644 --- a/packages/platform-android/src/runtime.ts +++ b/packages/platform-android/src/runtime.ts @@ -410,6 +410,7 @@ export function createAndroidPlatformRuntime(host: PlatformRuntimeHost): Platfor animations: available, appearance: available, 'text-size': available, + timezone: available, fingerprint: available, 'clear-app-state': available, permission: available, diff --git a/packages/platform-android/src/settings-timezone.ts b/packages/platform-android/src/settings-timezone.ts new file mode 100644 index 0000000000..7e26276244 --- /dev/null +++ b/packages/platform-android/src/settings-timezone.ts @@ -0,0 +1,75 @@ +import { SETTING_RESET_STATE } from '@agent-device/contracts/settings-catalog'; +import type { DeviceInfo } from '@agent-device/kernel/device'; +import { AppError, discloseDispatch, type ReasonTable } from '@agent-device/kernel/errors'; +import { runAndroidShell } from './adb.ts'; +import { androidAdbResultError } from './adb-failure.ts'; + +/** The `error.details.reason` a time zone write states when the device kept another zone. */ +const ANDROID_TIME_ZONE_REASONS = { + // `persist.sys.timezone` did not hold the requested zone after `cmd alarm set-timezone`. + timeZoneNotApplied: { reason: 'time-zone-not-applied' }, +} as const satisfies ReasonTable<'settings'>; + +/** + * Sets the system time zone with `cmd alarm set-timezone`, the shell command for + * `AlarmManager.setTimeZone`. Automatic time zone is turned off first, or the network would set + * its own zone back; reset turns it on again, and the device then takes the network's zone. + */ +export async function setAndroidTimeZone( + device: DeviceInfo, + state: string, +): Promise> { + const requested = state === SETTING_RESET_STATE ? undefined : state; + const previousTimeZone = await readAndroidTimeZone(device); + if (requested === undefined) { + // The detector applies the network's zone a moment later, so there is no zone to report yet. + await writeAndroidAutoTimeZone(device, '1'); + return { timeZone: null, previousTimeZone, autoTimeZone: true }; + } + const previousAutoTimeZone = await readAndroidAutoTimeZone(device); + await writeAndroidAutoTimeZone(device, '0'); + const result = await runAndroidShell(device, ['cmd', 'alarm', 'set-timezone', requested], { + allowFailure: true, + }); + // The alarm shell prints the exception and exits non-zero for a zone the device does not know. + if (result.exitCode !== 0) { + await writeAndroidAutoTimeZone(device, previousAutoTimeZone); + throw discloseDispatch( + androidAdbResultError('Failed to set the Android time zone', result, { + timeZone: requested, + autoTimeZone: previousAutoTimeZone === '1', + }), + 'unknown', + ); + } + const timeZone = await readAndroidTimeZone(device); + if (timeZone !== requested) { + await writeAndroidAutoTimeZone(device, previousAutoTimeZone); + throw new AppError('COMMAND_FAILED', `Android kept the time zone ${timeZone || '(empty)'}.`, { + reason: ANDROID_TIME_ZONE_REASONS.timeZoneNotApplied.reason, + dispatched: 'unknown', + timeZone: requested, + storedTimeZone: timeZone, + autoTimeZone: previousAutoTimeZone === '1', + }); + } + return { timeZone, previousTimeZone, autoTimeZone: false }; +} + +/** + * The `auto_time_zone` row as stored, so a failed write puts the same value back and its error + * reports what the device holds. Only `0` is off: an absent row means the platform default, on. + */ +async function readAndroidAutoTimeZone(device: DeviceInfo): Promise { + const result = await runAndroidShell(device, ['settings', 'get', 'global', 'auto_time_zone']); + return result.stdout.trim() === '0' ? '0' : '1'; +} + +async function writeAndroidAutoTimeZone(device: DeviceInfo, value: string): Promise { + await runAndroidShell(device, ['settings', 'put', 'global', 'auto_time_zone', value]); +} + +async function readAndroidTimeZone(device: DeviceInfo): Promise { + const result = await runAndroidShell(device, ['getprop', 'persist.sys.timezone']); + return result.stdout.trim(); +} diff --git a/packages/platform-android/src/settings.ts b/packages/platform-android/src/settings.ts index 53195dd68c..3524348e93 100644 --- a/packages/platform-android/src/settings.ts +++ b/packages/platform-android/src/settings.ts @@ -58,6 +58,7 @@ export const ANDROID_SETTINGS = [ 'animations', 'appearance', 'text-size', + 'timezone', 'fingerprint', 'clear-app-state', 'permission', @@ -229,6 +230,10 @@ export async function setAndroidSetting( case 'text-size': { return await setAndroidTextSize(device, state); } + case 'timezone': { + const { setAndroidTimeZone } = await import('./settings-timezone.ts'); + return await setAndroidTimeZone(device, state); + } default: return normalized satisfies never; } diff --git a/packages/provider-limrun/src/interaction-operations.test.ts b/packages/provider-limrun/src/interaction-operations.test.ts index 15cfa65eb6..297d688cfd 100644 --- a/packages/provider-limrun/src/interaction-operations.test.ts +++ b/packages/provider-limrun/src/interaction-operations.test.ts @@ -144,6 +144,7 @@ test('app-event delivery is admitted on both direct-session legs', () => { test('iOS inherits shared settings except keychain reset and time zone', () => { const android = limrunAndroidSettingsFacts(); expect(runtimeSubjectFact(android.setSetting, 'animations').available).toBe(true); + expect(runtimeSubjectFact(android.setSetting, 'timezone').available).toBe(true); const ios = limrunAppleSettingsFacts(testIosRunner.facts); for (const setting of [ 'appearance', diff --git a/packages/provider-limrun/src/interaction-operations.ts b/packages/provider-limrun/src/interaction-operations.ts index 4073181268..e97cc3bf09 100644 --- a/packages/provider-limrun/src/interaction-operations.ts +++ b/packages/provider-limrun/src/interaction-operations.ts @@ -197,6 +197,7 @@ export function limrunAndroidSettingsFacts( animations: available, appearance: available, 'text-size': available, + timezone: available, fingerprint: available, 'clear-app-state': available, permission: available, From 935ab944e343d1fb675f434fe55fb0d06a66b0fb Mon Sep 17 00:00:00 2001 From: parbez Date: Thu, 26 Nov 2026 19:32:42 +0530 Subject: [PATCH 5/8] docs(settings): document timezone --- website/docs/docs/commands.md | 12 ++++++++++-- website/docs/docs/error-reasons.md | 1 + website/docs/docs/limrun.md | 2 +- website/docs/docs/revyl.md | 2 +- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/website/docs/docs/commands.md b/website/docs/docs/commands.md index 77728d842b..bde67bf0e7 100644 --- a/website/docs/docs/commands.md +++ b/website/docs/docs/commands.md @@ -1755,7 +1755,7 @@ agent-device trigger-app-event screenshot_taken '{"source":"qa"}' Change OS settings and app permissions. ```bash -agent-device settings | settings location set | settings appearance | settings text-size [extra-small|small|medium|large|extra-large|extra-extra-large|extra-extra-extra-large|accessibility-medium|accessibility-large|accessibility-extra-large|accessibility-extra-extra-large|accessibility-extra-extra-extra-large] | settings | settings fingerprint | settings clear-app-state [app-id] | settings reset-keychain clear | settings permission | settings permission photos [full|limited] | settings permission [--app ] +agent-device settings | settings location set | settings appearance | settings text-size [extra-small|small|medium|large|extra-large|extra-extra-large|extra-extra-extra-large|accessibility-medium|accessibility-large|accessibility-extra-large|accessibility-extra-extra-large|accessibility-extra-extra-extra-large] | settings timezone | settings | settings fingerprint | settings clear-app-state [app-id] | settings reset-keychain clear | settings permission | settings permission photos [full|limited] | settings permission [--app ] ``` | Option | What it does | @@ -1774,6 +1774,7 @@ agent-device settings mobile-data off agent-device settings location set 37.3349 -122.009 agent-device settings animations off agent-device settings text-size accessibility-extra-large +agent-device settings timezone Asia/Kolkata agent-device settings appearance dark agent-device settings faceid match agent-device settings fingerprint nonmatch @@ -1801,6 +1802,13 @@ Device settings: - Pair `settings mobile-data on` with `settings wifi off` to move a session, such as a video stream, from Wi-Fi to cellular. On a multi-SIM device, or one without an active SIM, the command can fail even when the switch took effect. - `settings text-size` without a category reads the current size. It works on iPhone and iPad simulators and on Android. A running app picks up a new size only after `open --relaunch`. +Time zone: + +- `settings timezone ` sets the time zone on iPhone and iPad simulators and on Android devices and emulators, and takes `reset`. Each response reports the previous time zone as `previousTimeZone`. +- Pass an IANA time zone name such as `Asia/Kolkata` or `America/New_York`; offsets and unknown names are refused with `INVALID_ARGS` before anything changes. +- On iOS simulators, `settings timezone` sets `TZ` in simulator `launchd`: it applies only to apps launched afterwards (run `open --relaunch` for a running app), is lost when the simulator reboots, and leaves the status bar on the Mac's time. `settings timezone reset` gives newly launched apps the Mac's time zone again. +- On Android devices and emulators, running apps and the status bar take the new time zone at once. `settings timezone` turns automatic time zone off and verifies `persist.sys.timezone` (failing with `time-zone-not-applied` and restoring automatic time zone if the device kept another zone). `settings timezone reset` turns automatic time zone back on and reports `timeZone: null`, because the device applies the network zone a moment later. + Biometrics: - `faceid` and `touchid` work on iPhone and iPad simulators. `fingerprint` works on Android emulators and on devices that have `cmd fingerprint`. @@ -1815,7 +1823,7 @@ App state: Permissions: - On iOS and Android, `permission` applies to the session app. Pass `--app ` to target an installed app without opening it, for example to grant a permission before first launch. `--app` counts only on the command line; `AGENT_DEVICE_TARGET_APP` never retargets a settings change. -- Refusals change nothing: `app_not_installed` (install the app or fix the id), `session_app_required` (run `open ` or name the app), `setting_app_not_package` (an Android intent alias such as `settings` is not a package), and `setting_app_not_consumed` (a device-wide setting such as `location set`, `mobile-data`, or `bluetooth` takes no app). +- Refusals change nothing: `app_not_installed` (install the app or fix the id), `session_app_required` (run `open ` or name the app), `setting_app_not_package` (an Android intent alias such as `settings` is not a package), and `setting_app_not_consumed` (a device-wide setting such as `location set`, `mobile-data`, `bluetooth`, or `timezone` takes no app). - On iOS simulators, targeting `notifications` with `grant`, `deny`, or `reset` returns `ios-notification-permission-unsupported`. Use `alert accept` or `alert dismiss` to answer the notification prompt. - On iOS simulators, the simulator decides which other permissions it can change and refuses the rest. `grant all` skips a refused service with a warning. - On Android, a permission group applies only the permissions the app declares. `full|limited` applies only to iOS `photos`. diff --git a/website/docs/docs/error-reasons.md b/website/docs/docs/error-reasons.md index ffb9930286..8c5db01dff 100644 --- a/website/docs/docs/error-reasons.md +++ b/website/docs/docs/error-reasons.md @@ -375,6 +375,7 @@ Treat a reason that this page does not list as unknown, not as an error in the r | `mobile-data-unreadable` | The device answered the mobile-data read-back with a value that is neither 0 nor 1. | | `keep-awake-not-applied` | The device kept the screen turning off after `svc power stayon` accepted the request. | | `keep-awake-unreadable` | The device answered the keep-awake read-back with a value that is not a stay-on mask. | +| `time-zone-not-applied` | `persist.sys.timezone` did not hold the requested zone after `cmd alarm set-timezone`. | | `setting_app_not_package` | The named app resolves to an intent such as `settings`, not to an installed package. | | `app-no-data-container` | `clear-app-state` was refused because the installed app owns no data container. | | `ios-notification-permission-unsupported` | iOS simulator notification prompts must be answered with `alert accept` or `alert dismiss`. | diff --git a/website/docs/docs/limrun.md b/website/docs/docs/limrun.md index 8ecc697e7b..f48a5706e7 100644 --- a/website/docs/docs/limrun.md +++ b/website/docs/docs/limrun.md @@ -187,7 +187,7 @@ Remote simulator logs do not include sender or process image paths. Filters that On iOS, `settings` supports `appearance`, `permission`, `location`, `wifi`, `airplane`, `faceid`, `touchid`, `text-size`, and `clear-app-state`, with the same arguments as a local simulator. You can also read the current text size. -Wi-Fi and airplane settings change the status-bar appearance; they do not disconnect the simulator. `clear-app-state` stops your app and removes its data. Use `open` when you are ready to launch it again. `reset-keychain` and `mobile-data` are unavailable on Limrun iOS. On Android, `settings mobile-data on|off` works as on a local device. Fold commands are unavailable on Limrun. +Wi-Fi and airplane settings change the status-bar appearance; they do not disconnect the simulator. `clear-app-state` stops your app and removes its data. Use `open` when you are ready to launch it again. `reset-keychain`, `mobile-data`, and `timezone` are unavailable on Limrun iOS. On Android, `settings mobile-data on|off` and `settings timezone ` work as on a local device. Fold commands are unavailable on Limrun. To drive Limrun only through MCP, see [Use a provider only through MCP](/docs/device-clouds#use-a-provider-only-through-mcp). For Limrun, `artifacts` lists the network capture file only when you connect with `--provider-network-logs`; otherwise there are no provider artifacts to fetch. diff --git a/website/docs/docs/revyl.md b/website/docs/docs/revyl.md index 1a57c61f22..858b977efa 100644 --- a/website/docs/docs/revyl.md +++ b/website/docs/docs/revyl.md @@ -117,7 +117,7 @@ report a refused command as a success: - `swipe` and `gesture` refuse. Use `scroll`, which plans the path itself and sends one drag. - `keyboard`, `clipboard`, `alert`, `fold`, `telephony`, and `tv-remote` are not supported. - The other `settings` refuse: `wifi`, `airplane`, `mobile-data`, `bluetooth`, `animations`, - `text-size`, `faceid`, `touchid`, and `fingerprint`. Revyl's devices refuse airplane mode, and the + `text-size`, `timezone`, `faceid`, `touchid`, and `fingerprint`. Revyl's devices refuse airplane mode, and the worker has no action for the rest. - `reinstall` refuses, as described above. - `uninstall`, `apps`, `push`, `logs`, `network dump`, `artifacts`, and `recordings` are not From 81964dd3c01f487471e53029e943fe38c95bfe20 Mon Sep 17 00:00:00 2001 From: parbez Date: Thu, 26 Nov 2026 19:33:23 +0530 Subject: [PATCH 6/8] test(settings): round-trip time zone in the live simulator and emulator scenarios --- .../android-emulator-e2e/live-harness.ts | 1 + .../live-lifecycle-scenario.ts | 19 +++++++++++++++++++ .../ios-simulator-e2e/live-full-scenarios.ts | 19 ++++++++++++++++++- .../ios-simulator-e2e/live-harness.ts | 1 + 4 files changed, 39 insertions(+), 1 deletion(-) diff --git a/test/integration/android-emulator-e2e/live-harness.ts b/test/integration/android-emulator-e2e/live-harness.ts index 26092cd050..1faa3b5d4b 100644 --- a/test/integration/android-emulator-e2e/live-harness.ts +++ b/test/integration/android-emulator-e2e/live-harness.ts @@ -87,6 +87,7 @@ export async function cleanupSession(context: LiveContext): Promise { for (const [step, args] of [ ['bind fixture before Android permission reset', ['open', context.appId]], ['reset Android microphone permission', ['settings', 'permission', 'reset', 'microphone']], + ['reset Android time zone', ['settings', 'timezone', 'reset']], ] as const) { try { await runStep(context, `cleanup: ${step}`, [...args]); diff --git a/test/integration/android-emulator-e2e/live-lifecycle-scenario.ts b/test/integration/android-emulator-e2e/live-lifecycle-scenario.ts index 0a5c7b351c..2754955540 100644 --- a/test/integration/android-emulator-e2e/live-lifecycle-scenario.ts +++ b/test/integration/android-emulator-e2e/live-lifecycle-scenario.ts @@ -17,6 +17,25 @@ export async function assertLifecycleAndSystem(context: LiveContext): Promise { + const zone = await runStep(context, 'set Android Asia/Kolkata time zone', [ + 'settings', + 'timezone', + 'Asia/Kolkata', + ]); + assert.equal(zone.json?.data?.timeZone, 'Asia/Kolkata', JSON.stringify(zone.json)); + assert.equal(zone.json?.data?.autoTimeZone, false, JSON.stringify(zone.json)); + const zoneReset = await runStep(context, 'reset Android time zone', [ + 'settings', + 'timezone', + 'reset', + ]); + assert.equal(zoneReset.json?.data?.autoTimeZone, true, JSON.stringify(zoneReset.json)); + verifyCommand(context, C.settings, 'time zone set and reset report what they changed'); } // Leaves the fixture on Automation lab with its permission controls on screen: Android diff --git a/test/integration/ios-simulator-e2e/live-full-scenarios.ts b/test/integration/ios-simulator-e2e/live-full-scenarios.ts index 86ace55e16..16d249f71e 100644 --- a/test/integration/ios-simulator-e2e/live-full-scenarios.ts +++ b/test/integration/ios-simulator-e2e/live-full-scenarios.ts @@ -100,10 +100,11 @@ export async function assertLifecycleAndSystem(context: LiveContext): Promise { + const zone = await runStep(context, 'set Asia/Kolkata time zone', [ + 'settings', + 'timezone', + 'Asia/Kolkata', + ]); + assert.equal(zone.json?.data?.timeZone, 'Asia/Kolkata', JSON.stringify(zone.json)); + const zoneReset = await runStep(context, 'reset time zone', ['settings', 'timezone', 'reset']); + assert.equal( + zoneReset.json?.data?.previousTimeZone, + 'Asia/Kolkata', + JSON.stringify(zoneReset.json), + ); +} diff --git a/test/integration/ios-simulator-e2e/live-harness.ts b/test/integration/ios-simulator-e2e/live-harness.ts index 5f8fda8fd7..56e924ab16 100644 --- a/test/integration/ios-simulator-e2e/live-harness.ts +++ b/test/integration/ios-simulator-e2e/live-harness.ts @@ -103,6 +103,7 @@ export async function cleanupSession(context: LiveContext): Promise { cleanupSteps.push( [MICROPHONE_PERMISSION_RESET_STEP, ['settings', 'permission', 'reset', 'microphone']], ['restore light appearance', ['settings', 'appearance', 'light']], + ['reset time zone', ['settings', 'timezone', 'reset']], ['restore portrait orientation', ['orientation', 'portrait']], ); } From a97454364586ae00199bfe981dfcc92e86acc1dc Mon Sep 17 00:00:00 2001 From: parbez Date: Thu, 26 Nov 2026 20:42:28 +0530 Subject: [PATCH 7/8] fix(settings): keep time zone names as written and drop the reboot note on iOS reset --- packages/contracts/src/settings.test.ts | 7 ++----- packages/contracts/src/settings.ts | 11 +++-------- .../__tests__/snapshot-settings-handler.test.ts | 2 +- .../src/core/__tests__/settings-timezone.test.ts | 2 ++ packages/platform-apple/src/core/settings-timezone.ts | 4 +++- 5 files changed, 11 insertions(+), 15 deletions(-) diff --git a/packages/contracts/src/settings.test.ts b/packages/contracts/src/settings.test.ts index 1bb1f8aabc..49a731d255 100644 --- a/packages/contracts/src/settings.test.ts +++ b/packages/contracts/src/settings.test.ts @@ -232,16 +232,13 @@ describe('text-size', () => { }); describe('timezone', () => { - test('a time zone the host lists is normalized to the host casing', () => { + test('a time zone Intl knows passes through as written so device read-back decides', () => { expect(parseSettingsMutation(['Timezone', 'Asia/Kolkata'])).toEqual({ setting: 'timezone', state: 'Asia/Kolkata', }); - expect(parseTimeZoneId('america/new_york')).toBe('America/New_York'); + expect(parseTimeZoneId('america/new_york')).toBe('america/new_york'); expect(parseTimeZoneId(' Etc/GMT+5 ')).toBe('Etc/GMT+5'); - }); - - test('an alias Intl knows passes through regardless of casing so device read-back decides', () => { expect(parseTimeZoneId('Asia/Kolkata')).toBe('Asia/Kolkata'); expect(parseTimeZoneId('asia/kolkata')).toBe('asia/kolkata'); expect(parseTimeZoneId('US/Pacific')).toBe('US/Pacific'); diff --git a/packages/contracts/src/settings.ts b/packages/contracts/src/settings.ts index c56561a9ef..578df33147 100644 --- a/packages/contracts/src/settings.ts +++ b/packages/contracts/src/settings.ts @@ -432,17 +432,12 @@ function parseSettingValue(setting: SettingName, value: string): string { const TIME_ZONE_NAME_PATTERN = /^[A-Za-z][\w+-]*(\/[\w+-]+)*$/; /** - * An IANA time zone name the host's time zone data knows. A name `Intl.supportedValuesOf` lists - * is normalized to its listed casing; an alias it does not list, such as `Asia/Kolkata`, is kept - * as written and checked by the target device on read-back. Offsets such as `+05:30` are refused - * because neither owner takes one. + * An IANA time zone name the host's time zone data knows, kept as written; the target device + * checks it on read-back. Offsets such as `+05:30` are refused because neither owner takes one. */ export function parseTimeZoneId(value: string): string { const name = value.trim(); - if (TIME_ZONE_NAME_PATTERN.test(name) && isKnownTimeZone(name)) { - const lower = name.toLowerCase(); - return Intl.supportedValuesOf('timeZone').find((zone) => zone.toLowerCase() === lower) ?? name; - } + if (TIME_ZONE_NAME_PATTERN.test(name) && isKnownTimeZone(name)) return name; throw new AppError( 'INVALID_ARGS', `Invalid time zone: ${value}. Use an IANA time zone name, such as Asia/Kolkata or America/New_York.`, diff --git a/packages/daemon/src/execution/handlers/__tests__/snapshot-settings-handler.test.ts b/packages/daemon/src/execution/handlers/__tests__/snapshot-settings-handler.test.ts index 3516036d0a..bc11ede6a5 100644 --- a/packages/daemon/src/execution/handlers/__tests__/snapshot-settings-handler.test.ts +++ b/packages/daemon/src/execution/handlers/__tests__/snapshot-settings-handler.test.ts @@ -692,7 +692,7 @@ test('settings iOS location set refuses a named app before reaching the owner', test.each([ { - positionals: ['timezone', 'america/new_york'], + positionals: ['timezone', 'America/New_York'], state: 'America/New_York', message: 'Time zone set to America/New_York', }, diff --git a/packages/platform-apple/src/core/__tests__/settings-timezone.test.ts b/packages/platform-apple/src/core/__tests__/settings-timezone.test.ts index 91c9d26939..1d56078540 100644 --- a/packages/platform-apple/src/core/__tests__/settings-timezone.test.ts +++ b/packages/platform-apple/src/core/__tests__/settings-timezone.test.ts @@ -42,9 +42,11 @@ test('settings timezone sets TZ in the simulator launchd and reset unsets it', a previousTimeZone: null, warnings: [expect.stringContaining('relaunch')], }); + // Reset leaves no override, so there is nothing for a reboot to lose. expect(await set('reset')).toMatchObject({ timeZone: null, previousTimeZone: 'Asia/Kolkata', + warnings: [expect.not.stringContaining('reboot')], }); expect(spawnedWrites(calls)).toEqual([ 'launchctl setenv TZ Asia/Kolkata', diff --git a/packages/platform-apple/src/core/settings-timezone.ts b/packages/platform-apple/src/core/settings-timezone.ts index 220a7985d7..0408cbfa9b 100644 --- a/packages/platform-apple/src/core/settings-timezone.ts +++ b/packages/platform-apple/src/core/settings-timezone.ts @@ -25,7 +25,9 @@ export async function setIosTimeZone( timeZone: timeZone ?? null, previousTimeZone, warnings: [ - 'Running apps keep the old time zone until they relaunch (run open --relaunch), and the override is lost when the simulator reboots.', + timeZone === undefined + ? 'Running apps keep the old time zone until they relaunch (run open --relaunch).' + : 'Running apps keep the old time zone until they relaunch (run open --relaunch), and the override is lost when the simulator reboots.', ], }; } From f9f8282018e530098fe13c64427b2fe0b7ce5b4b Mon Sep 17 00:00:00 2001 From: parbez Date: Thu, 26 Nov 2026 22:51:35 +0530 Subject: [PATCH 8/8] fix(settings): restore automatic time zone on every Android failure and refuse zones the simulator cannot load --- .../src/__tests__/settings-timezone.test.ts | 23 +++++++++++++++++-- .../platform-android/src/settings-timezone.ts | 18 +++++++++++++-- .../core/__tests__/settings-timezone.test.ts | 10 ++++++++ .../src/core/settings-timezone.ts | 18 +++++++++++++++ .../live-lifecycle-scenario.ts | 1 + website/docs/docs/commands.md | 4 ++-- website/docs/docs/error-reasons.md | 1 + 7 files changed, 69 insertions(+), 6 deletions(-) diff --git a/packages/platform-android/src/__tests__/settings-timezone.test.ts b/packages/platform-android/src/__tests__/settings-timezone.test.ts index 9e7ba577cd..da7765a0e4 100644 --- a/packages/platform-android/src/__tests__/settings-timezone.test.ts +++ b/packages/platform-android/src/__tests__/settings-timezone.test.ts @@ -8,13 +8,22 @@ import { withFakeAdb, type FakeAdbResponse } from './test-utils/fake-adb.ts'; * whose `auto_time_zone` row starts at `initialAutoTimeZone` and holds whatever is written to it. */ function timeZoneDevice( - options: { honor?: boolean; known?: boolean; initialAutoTimeZone?: string } = {}, + options: { + honor?: boolean; + known?: boolean; + dropReadBack?: boolean; + initialAutoTimeZone?: string; + } = {}, ) { let zone = 'America/Los_Angeles'; const state = { autoTimeZone: options.initialAutoTimeZone ?? '1' }; const script = (args: string[]): FakeAdbResponse => { const flat = args.join(' '); - if (flat === 'shell getprop persist.sys.timezone') return `${zone}\n`; + if (flat === 'shell getprop persist.sys.timezone') { + if (options.dropReadBack && zone !== 'America/Los_Angeles') + return new Error('device offline'); + return `${zone}\n`; + } if (flat === 'shell settings get global auto_time_zone') return `${state.autoTimeZone}\n`; const auto = /^shell settings put global auto_time_zone ([01])$/.exec(flat); if (auto) { @@ -46,6 +55,7 @@ test('settings timezone turns automatic time zone off, then sets and reads back }); const flat = calls.map((args) => args.join(' ')); expect(flat).toContain('shell settings put global auto_time_zone 0'); + expect(flat).not.toContain('shell settings put global auto_time_zone 1'); expect(flat.indexOf('shell settings put global auto_time_zone 0')).toBeLessThan( flat.indexOf('shell cmd alarm set-timezone Asia/Kolkata'), ); @@ -76,6 +86,7 @@ test('settings timezone reset turns automatic time zone back on without naming a }); const flat = calls.map((args) => args.join(' ')); expect(flat).toContain('shell settings put global auto_time_zone 1'); + expect(flat).not.toContain('shell settings put global auto_time_zone 0'); expect(flat.some((args) => args.includes('set-timezone'))).toBe(false); }); }); @@ -101,6 +112,14 @@ test.each([ }, ); +test('settings timezone puts automatic time zone back when the read-back connection drops', async () => { + const fake = timeZoneDevice({ dropReadBack: true }); + await withFakeAdb(fake, async ({ device }) => { + await expect(setAndroidSetting(device, 'timezone', 'Asia/Kolkata')).rejects.toThrow(); + expect(fake.state.autoTimeZone).toBe('1'); + }); +}); + test('settings timezone keeps automatic time zone off on failure when it was already off', async () => { const fake = timeZoneDevice({ honor: false, initialAutoTimeZone: '0' }); await withFakeAdb(fake, async ({ device }) => { diff --git a/packages/platform-android/src/settings-timezone.ts b/packages/platform-android/src/settings-timezone.ts index 7e26276244..c857552eb0 100644 --- a/packages/platform-android/src/settings-timezone.ts +++ b/packages/platform-android/src/settings-timezone.ts @@ -28,12 +28,27 @@ export async function setAndroidTimeZone( } const previousAutoTimeZone = await readAndroidAutoTimeZone(device); await writeAndroidAutoTimeZone(device, '0'); + try { + return await applyAndroidTimeZone(device, requested, previousTimeZone, previousAutoTimeZone); + } catch (error) { + // Every failure once automatic time zone is off, an adb transport error included, puts the + // stored value back. A failed restore must not hide the error that caused it. + await writeAndroidAutoTimeZone(device, previousAutoTimeZone).catch(() => undefined); + throw error; + } +} + +async function applyAndroidTimeZone( + device: DeviceInfo, + requested: string, + previousTimeZone: string, + previousAutoTimeZone: string, +): Promise> { const result = await runAndroidShell(device, ['cmd', 'alarm', 'set-timezone', requested], { allowFailure: true, }); // The alarm shell prints the exception and exits non-zero for a zone the device does not know. if (result.exitCode !== 0) { - await writeAndroidAutoTimeZone(device, previousAutoTimeZone); throw discloseDispatch( androidAdbResultError('Failed to set the Android time zone', result, { timeZone: requested, @@ -44,7 +59,6 @@ export async function setAndroidTimeZone( } const timeZone = await readAndroidTimeZone(device); if (timeZone !== requested) { - await writeAndroidAutoTimeZone(device, previousAutoTimeZone); throw new AppError('COMMAND_FAILED', `Android kept the time zone ${timeZone || '(empty)'}.`, { reason: ANDROID_TIME_ZONE_REASONS.timeZoneNotApplied.reason, dispatched: 'unknown', diff --git a/packages/platform-apple/src/core/__tests__/settings-timezone.test.ts b/packages/platform-apple/src/core/__tests__/settings-timezone.test.ts index 1d56078540..4bd80becb6 100644 --- a/packages/platform-apple/src/core/__tests__/settings-timezone.test.ts +++ b/packages/platform-apple/src/core/__tests__/settings-timezone.test.ts @@ -55,6 +55,16 @@ test('settings timezone sets TZ in the simulator launchd and reset unsets it', a }); }); +test('a zone the host time zone database lacks is refused before launchctl runs', async () => { + await withFakeAppleTool(simulator(), async ({ calls }) => { + await expect(set('Mars/Olympus_Mons')).rejects.toMatchObject({ + code: 'COMMAND_FAILED', + details: { reason: 'time-zone-unknown-to-simulator', dispatched: 'no' }, + }); + expect(spawnedWrites(calls)).toEqual([]); + }); +}); + test('a failed launchctl setenv fails the setting with the simctl output', async () => { const script = (args: string[]): FakeAppleToolResponse => args.includes('setenv') ? { stderr: 'launchd unavailable', exitCode: 1 } : simulator()(args); diff --git a/packages/platform-apple/src/core/settings-timezone.ts b/packages/platform-apple/src/core/settings-timezone.ts index 0408cbfa9b..2615d6c540 100644 --- a/packages/platform-apple/src/core/settings-timezone.ts +++ b/packages/platform-apple/src/core/settings-timezone.ts @@ -1,8 +1,18 @@ import { SETTING_RESET_STATE } from '@agent-device/contracts/settings-catalog'; import type { DeviceInfo } from '@agent-device/kernel/device'; +import { AppError, type ReasonTable } from '@agent-device/kernel/errors'; import { requireExecSuccess } from '@agent-device/host-kit/command'; +import { hostFileExistsSync } from '@agent-device/host-kit/host-file'; import { runSimctlForDevice } from './simctl-execution.ts'; +const IOS_TIME_ZONE_REASONS = { + // The Mac's time zone database, which simulator processes read, has no file for the zone. + timeZoneUnknown: { reason: 'time-zone-unknown-to-simulator' }, +} as const satisfies ReasonTable<'settings'>; + +// Simulator processes resolve `TZ` against the host's database: the runtime ships no zoneinfo. +const HOST_ZONEINFO_DIRECTORY = '/usr/share/zoneinfo'; + /** * The simulator has no time zone of its own: its apps take the host Mac's unless their environment * names one. `launchctl setenv` in the simulator's launchd sets `TZ` for every process it starts @@ -13,6 +23,14 @@ export async function setIosTimeZone( state: string, ): Promise> { const timeZone = state === SETTING_RESET_STATE ? undefined : state; + // `launchctl setenv` takes any string, and an app falls back to UTC for a zone it cannot load. + if (timeZone !== undefined && !hostFileExistsSync(`${HOST_ZONEINFO_DIRECTORY}/${timeZone}`)) { + throw new AppError('COMMAND_FAILED', `The simulator has no time zone data for ${timeZone}.`, { + reason: IOS_TIME_ZONE_REASONS.timeZoneUnknown.reason, + dispatched: 'no', + timeZone, + }); + } const previousTimeZone = await readLaunchdTimeZone(device); await runSimctlChecked( device, diff --git a/test/integration/android-emulator-e2e/live-lifecycle-scenario.ts b/test/integration/android-emulator-e2e/live-lifecycle-scenario.ts index 2754955540..1d281240e9 100644 --- a/test/integration/android-emulator-e2e/live-lifecycle-scenario.ts +++ b/test/integration/android-emulator-e2e/live-lifecycle-scenario.ts @@ -34,6 +34,7 @@ async function assertTimeZoneRoundTrip(context: LiveContext): Promise { 'timezone', 'reset', ]); + assert.equal(zoneReset.json?.data?.timeZone, null, JSON.stringify(zoneReset.json)); assert.equal(zoneReset.json?.data?.autoTimeZone, true, JSON.stringify(zoneReset.json)); verifyCommand(context, C.settings, 'time zone set and reset report what they changed'); } diff --git a/website/docs/docs/commands.md b/website/docs/docs/commands.md index bde67bf0e7..ec80f7c685 100644 --- a/website/docs/docs/commands.md +++ b/website/docs/docs/commands.md @@ -1806,8 +1806,8 @@ Time zone: - `settings timezone ` sets the time zone on iPhone and iPad simulators and on Android devices and emulators, and takes `reset`. Each response reports the previous time zone as `previousTimeZone`. - Pass an IANA time zone name such as `Asia/Kolkata` or `America/New_York`; offsets and unknown names are refused with `INVALID_ARGS` before anything changes. -- On iOS simulators, `settings timezone` sets `TZ` in simulator `launchd`: it applies only to apps launched afterwards (run `open --relaunch` for a running app), is lost when the simulator reboots, and leaves the status bar on the Mac's time. `settings timezone reset` gives newly launched apps the Mac's time zone again. -- On Android devices and emulators, running apps and the status bar take the new time zone at once. `settings timezone` turns automatic time zone off and verifies `persist.sys.timezone` (failing with `time-zone-not-applied` and restoring automatic time zone if the device kept another zone). `settings timezone reset` turns automatic time zone back on and reports `timeZone: null`, because the device applies the network zone a moment later. +- On iOS simulators, `settings timezone` sets `TZ` in simulator `launchd`: it applies only to apps launched afterwards (run `open --relaunch` for a running app), is lost when the simulator reboots, and leaves the status bar on the Mac's time. A zone missing from the Mac's time zone database, which simulator apps read, fails with `time-zone-unknown-to-simulator` before anything changes. `settings timezone reset` gives newly launched apps the Mac's time zone again. +- On Android devices and emulators, running apps and the status bar take the new time zone at once. `settings timezone` turns automatic time zone off and verifies `persist.sys.timezone` (failing with `time-zone-not-applied` if the device kept another zone; any failure puts the previous automatic time zone setting back). `settings timezone reset` turns automatic time zone back on and reports `timeZone: null`, because the device applies the network zone a moment later. Biometrics: diff --git a/website/docs/docs/error-reasons.md b/website/docs/docs/error-reasons.md index 8c5db01dff..d7caaff731 100644 --- a/website/docs/docs/error-reasons.md +++ b/website/docs/docs/error-reasons.md @@ -378,6 +378,7 @@ Treat a reason that this page does not list as unknown, not as an error in the r | `time-zone-not-applied` | `persist.sys.timezone` did not hold the requested zone after `cmd alarm set-timezone`. | | `setting_app_not_package` | The named app resolves to an intent such as `settings`, not to an installed package. | | `app-no-data-container` | `clear-app-state` was refused because the installed app owns no data container. | +| `time-zone-unknown-to-simulator` | The Mac's time zone database, which simulator processes read, has no file for the zone. | | `ios-notification-permission-unsupported` | iOS simulator notification prompts must be answered with `alert accept` or `alert dismiss`. | ### `shake`