Skip to content

Commit 05b1b4c

Browse files
thymikeeopencode
andcommitted
fix(settings): refuse a named app for location set too (r4176656835)
`settingsInputApp` dropped `--app` for `location set`, so `settings location set <lat> <lon> --app X` ignored X without a word — a dropped argument, not a wrong-app change, and a contradiction this PR's own rule forbids ("a device-wide change refuses a named app instead of dropping it"). The daemon's scope table already classifies `location set` as device-level for every family; the writer just never forwarded the app for that refusal to land. Forward every `location` state's app so the daemon's `setting_app_not_consumed` refusal answers it before dispatch, and widen the client `location set` leg to carry `app` so the writer can. Co-Authored-By: opencode <[email protected]>
1 parent 58f310b commit 05b1b4c

5 files changed

Lines changed: 44 additions & 6 deletions

File tree

‎packages/contracts/src/client-settings.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,16 @@ export type SettingsUpdateOptions =
4343
state: 'on' | 'off';
4444
app?: string;
4545
})
46+
/**
47+
* `set` moves the device's own location for every target, so naming an app here is a contradiction
48+
* the daemon refuses with `setting_app_not_consumed` rather than a value it silently drops.
49+
*/
4650
| (DeviceCommandBaseOptions & {
4751
setting: 'location';
4852
state: 'set';
4953
latitude: number;
5054
longitude: number;
55+
app?: string;
5156
})
5257
| (DeviceCommandBaseOptions & {
5358
setting: 'animations';

‎src/commands/capture/settings.test.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,14 +181,16 @@ describe('settings CLI permission vocabulary', () => {
181181
});
182182
});
183183

184-
test('keeps a location set device-wide and drops the app it never reads', () => {
184+
// r4176656835: the writer used to drop the app, so `location set ... --app X` ignored X silently.
185+
// It now forwards, and the daemon's device-level refusal answers it (handler test below).
186+
test('forwards the app on a location set to the device-level refusal', () => {
185187
const input = settingsCliReader(['location', 'set', '37.7', '-122.4'], {
186188
targetApp: 'com.example.app',
187189
} as CliFlags);
188190
expect(settingsDaemonWriter(input)).toMatchObject({
189191
positionals: ['location', 'set', '37.7', '-122.4'],
192+
input: { app: 'com.example.app' },
190193
});
191-
expect(settingsDaemonWriter(input).input).toBeUndefined();
192194
});
193195

194196
// The flag bag carries a configured default app the parser strips for settings; the reader still

‎src/commands/capture/settings.ts‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const settingsCommandMetadata = defineFieldCommandMetadata(
4343
// and the daemon enforce per setting rather than the shared field map.
4444
state: stringField(),
4545
app: stringField(
46-
'App the change targets, by bundle id or package name: the app `clear-app-state` clears, or the app a `permission` change (or an iOS-simulator `location on|off` privacy change) lands on. An app named here needs no session and need not be running (Android `deny|reset` of a held permission does kill a running one); without it those changes use the session app, and a target whose change is device-wide (Android location toggle, macOS permissions) refuses one. The CLI consumes it only when this invocation passes it: an `AGENT_DEVICE_TARGET_APP` or config `targetApp` never retargets a settings mutation.',
46+
'App the change targets, by bundle id or package name: the app `clear-app-state` clears, or the app a `permission` change (or an iOS-simulator `location on|off` privacy change) lands on. An app named here needs no session and need not be running (Android `deny|reset` of a held permission does kill a running one); without it those changes use the session app, and a change that is device-wide refuses one with `setting_app_not_consumed` (`location set` on any target, the Android `location on|off` toggle, macOS permissions). The CLI consumes it only when this invocation passes it: an `AGENT_DEVICE_TARGET_APP` or config `targetApp` never retargets a settings mutation.',
4747
),
4848
latitude: numberField(),
4949
longitude: numberField(),
@@ -94,15 +94,18 @@ export const settingsDaemonWriter: DaemonWriter = (input) => {
9494
/** The settings whose `app` reaches the daemon through request input rather than a positional. */
9595
function settingsInputApp(input: SettingsUpdateOptions): string | undefined {
9696
if (input.setting === 'permission') return input.app;
97-
if (input.setting === 'location' && input.state !== 'set') return input.app;
97+
// Every location state forwards the app: `on|off` consumes it on Apple, and `set` is device-wide
98+
// for everyone, so the daemon's scope table refuses the named app instead of the writer dropping
99+
// it without a word.
100+
if (input.setting === 'location') return input.app;
98101
return undefined;
99102
}
100103

101104
export const settingsCommandFacet = defineCommandFacet({
102105
name: SETTINGS_COMMAND_NAME,
103106
text: {
104107
summary: 'Change OS settings and app permissions',
105-
cliDetail: `macOS supports only settings appearance <light|dark|toggle> and settings ${SETTINGS_MACOS_PERMISSION_USAGE}; wifi|airplane|location|animations|text-size remain unsupported on macOS. Mobile permission actions default to the active session app; pass --app <id> (or the app input) to aim a permission change, or an iOS-simulator location on|off, at an installed app no session has opened; no app needs to be running, and the CLI consumes the app only when this invocation names it, never from AGENT_DEVICE_TARGET_APP or config targetApp. A device-wide change refuses an app: the Android location toggle writes the device's location_mode, and a macOS permission is a host-level TCC grant. On Android, deny|reset of a permission the app currently holds kills a running app; the response reports priorGrantState (granted|not_granted|unknown) and warns for granted and unknown, with open <app> --relaunch to restore it. Permission changes require a resolvable foreground user and fail without mutating if adb cannot report one. Android settings airplane on|off is applied by the connectivity service (Android 11+) and reports the airplaneMode that service holds; older builds fail without changing device state. settings reset-keychain clear is iOS-simulator-only and resets the whole simulator keychain, not just the selected app: simctl exposes no per-app keychain reset, so every app on that simulator loses its keychain-backed credentials (e.g. Firebase auth). clear-app-state does not touch the keychain, so a full fresh-install reset needs both; relaunch the app afterward to observe the signed-out state. settings text-size reads the preferred text size the target holds and settings text-size <category> applies one, on iPhone and iPad simulators (simctl content size) and on Android targets (system font_scale); tvOS and visionOS simulators, physical Apple devices, and the macOS host refuse it. Android has no category ladder of its own, so the read names the nearest rung and reports the exact multiplier as platformValue; an already-running app adopts a changed size at its next configuration change, so relaunch the app under test to observe it.`,
108+
cliDetail: `macOS supports only settings appearance <light|dark|toggle> and settings ${SETTINGS_MACOS_PERMISSION_USAGE}; wifi|airplane|location|animations|text-size remain unsupported on macOS. Mobile permission actions default to the active session app; pass --app <id> (or the app input) to aim a permission change, or an iOS-simulator location on|off, at an installed app no session has opened; no app needs to be running, and the CLI consumes the app only when this invocation names it, never from AGENT_DEVICE_TARGET_APP or config targetApp. A device-wide change refuses an app with setting_app_not_consumed: location set moves the device's own coordinates on every target, the Android location toggle writes the device's location_mode, and a macOS permission is a host-level TCC grant. On Android, deny|reset of a permission the app currently holds kills a running app; the response reports priorGrantState (granted|not_granted|unknown) and warns for granted and unknown, with open <app> --relaunch to restore it. Permission changes require a resolvable foreground user and fail without mutating if adb cannot report one. Android settings airplane on|off is applied by the connectivity service (Android 11+) and reports the airplaneMode that service holds; older builds fail without changing device state. settings reset-keychain clear is iOS-simulator-only and resets the whole simulator keychain, not just the selected app: simctl exposes no per-app keychain reset, so every app on that simulator loses its keychain-backed credentials (e.g. Firebase auth). clear-app-state does not touch the keychain, so a full fresh-install reset needs both; relaunch the app afterward to observe the signed-out state. settings text-size reads the preferred text size the target holds and settings text-size <category> applies one, on iPhone and iPad simulators (simctl content size) and on Android targets (system font_scale); tvOS and visionOS simulators, physical Apple devices, and the macOS host refuse it. Android has no category ladder of its own, so the read names the nearest rung and reports the exact multiplier as platformValue; an already-running app adopts a changed size at its next configuration change, so relaunch the app under test to observe it.`,
106109
},
107110
metadata: settingsCommandMetadata,
108111
run: (client, input) => client.settings.update(input as SettingsUpdateOptions),

‎src/daemon/handlers/__tests__/snapshot-settings-handler.test.ts‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,34 @@ test('settings Android location 0 refuses a named app before reaching the owner'
599599
}
600600
});
601601

602+
// `location set` moves the device's own location for every family, so a named app contradicts the
603+
// mutation everywhere. The writer forwards it (r4176656835) and this refusal answers it; the
604+
// coordinates stay unparsed because the request must never reach the owner.
605+
test('settings iOS location set refuses a named app before reaching the owner', async () => {
606+
const sessionStore = makeSessionStore();
607+
const sessionName = 'ios-location-set-refused';
608+
sessionStore.publish(sessionName, makeSession(sessionName, iosSimulatorDevice));
609+
610+
const response = await handleSnapshotCommands({
611+
req: snapshotRequest(sessionName, 'settings', {
612+
positionals: ['location', 'set', '37.7', '-122.4'],
613+
input: { app: 'com.example.app' },
614+
}),
615+
sessionName,
616+
logPath: '/tmp/daemon.log',
617+
sessionStore,
618+
});
619+
620+
expect(response?.ok).toBe(false);
621+
expect(fixtureSettingsMutations).toHaveLength(0);
622+
if (response && !response.ok) {
623+
expect(response.error.code).toBe('INVALID_ARGS');
624+
expect(response.error.message).toMatch(/location set applies to the target itself/);
625+
expect(response.error.details?.reason).toBe('setting_app_not_consumed');
626+
expect(response.error.details?.dispatched).toBe('no');
627+
}
628+
});
629+
602630
// A macOS permission is a host-level TCC grant, so naming an app is refused rather than dropped.
603631
test('settings macOS permission grant refuses a named app before reaching the owner', async () => {
604632
const sessionStore = makeSessionStore();

‎website/docs/docs/commands.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,7 @@ agent-device settings permission reset screen-recording --platform macos
784784
- Android `settings airplane on|off` is applied by the connectivity service (`cmd connectivity airplane-mode`, Android 11+), which drives the radios rather than only writing the `airplane_mode_on` setting. The response reports the `airplaneMode` that service holds after the change, and Android builds without that command fail without changing device state. Connectivity takes a moment to settle after the switch, so poll the app under test rather than asserting offline behavior immediately.
785785
- Fingerprint simulation is supported on Android targets where `cmd fingerprint` or `adb emu finger` is available.
786786
On physical Android devices, only `cmd fingerprint` is attempted.
787-
- On iOS and Android, permission actions default to the active session app. Pass `--app <bundle-id-or-package>` (or the client `app` option) to aim a `permission` change — grant, deny, or reset — or an iOS simulator `location on|off` privacy change, at an installed app without opening it or binding a session — for example, grant a permission before the app's first launch. The app must be installed on the target; no app has to be running. The CLI reads `--app` for `settings` only when you pass it on the command line: an `AGENT_DEVICE_TARGET_APP` environment variable or a `targetApp` in `~/.agent-device/config.json` (both useful for `doctor`) never retargets a settings mutation, which falls back to the session app. With no app bound to the session and none named, `settings permission` refuses with `INVALID_ARGS` and `error.details.reason: session_app_required` and `dispatched: no`: `open <app>` and retry, or name the app with `--app`. On iOS, an on/off `settings location` behaves the same. A change that is device-wide refuses a named app instead of dropping it, with `error.details.reason: setting_app_not_consumed`: the Android `location on|off` toggle writes the device's `location_mode`, and a macOS permission is a host-level TCC grant that needs no session app.
787+
- On iOS and Android, permission actions default to the active session app. Pass `--app <bundle-id-or-package>` (or the client `app` option) to aim a `permission` change — grant, deny, or reset — or an iOS simulator `location on|off` privacy change, at an installed app without opening it or binding a session — for example, grant a permission before the app's first launch. The app must be installed on the target; no app has to be running. The CLI reads `--app` for `settings` only when you pass it on the command line: an `AGENT_DEVICE_TARGET_APP` environment variable or a `targetApp` in `~/.agent-device/config.json` (both useful for `doctor`) never retargets a settings mutation, which falls back to the session app. With no app bound to the session and none named, `settings permission` refuses with `INVALID_ARGS` and `error.details.reason: session_app_required` and `dispatched: no`: `open <app>` and retry, or name the app with `--app`. On iOS, an on/off `settings location` behaves the same. A change that is device-wide refuses a named app instead of dropping it, with `error.details.reason: setting_app_not_consumed`: `location set` moves the device's own coordinates on every target, the Android `location on|off` toggle writes the device's `location_mode`, and a macOS permission is a host-level TCC grant that needs no session app.
788788
- iOS permission targets: `all`, `camera`, `microphone`, `photos` (`full` or `limited`), `contacts`, `contacts-limited`, `notifications`, `calendar`, `location`, `location-always`, `media-library`, `motion`, `reminders`, `siri`. `all` travels as one `simctl privacy … all` call.
789789
- On iOS, which of those services a runtime actually changes is `simctl privacy`'s own verdict, not its help text: Xcode 26 omits `camera` from the list while granting it. A service the runtime refuses fails with `UNSUPPORTED_OPERATION` naming the service; on current runtimes that is `notifications`, which a targeted change cannot reach and `all` leaves untouched.
790790
- Android permission targets: `all`, `calendar`, `camera`, `contacts`, `location`, `media-library`, `microphone`, `notifications`, `photos`. `contacts` fans out to `READ_CONTACTS`+`WRITE_CONTACTS`, `location` to `FINE`+`COARSE`, `calendar` to `READ`+`WRITE`; named multi-id targets intersect the package's declared permissions so a coarse-only or read-only app still succeeds, while a target declaring none of its ids fails loudly. `all` resolves against the package's declared permissions instead. Every response reports `permission` as the requested target and `permissions: string[]` as the ids actually mutated, in the order applied (`all` folds its applied ids into `permissions` the same way).

0 commit comments

Comments
 (0)