From 06a6ac4914c179288c0277c8c60f10849b57143d Mon Sep 17 00:00:00 2001 From: parbez Date: Wed, 18 Nov 2026 13:39:12 +0530 Subject: [PATCH 1/2] fix(ios): change every privacy service for settings permission all The iOS 27 simulator records simctl privacy grant all as one kTCCServiceAll row that it never consults, so an app still prompts after grant all, and deny all leaves every per-service grant in place. Grant and deny of all now change each service in turn and report what changed, skipping a service the runtime refuses with a warning; reset all stays one call. iOS 27 words that refusal 'Failed to create TCC authorization record', which is now read as one, so a named notifications change is UNSUPPORTED_OPERATION again. --- .../maestro/src/internal/support-matrix.ts | 2 +- .../core/__tests__/simctl-settings.test.ts | 129 +++++++++++++++++- .../src/core/simctl-settings.ts | 77 ++++++++++- website/docs/docs/commands.md | 2 +- website/docs/docs/run-maestro-flows.md | 2 +- 5 files changed, 205 insertions(+), 7 deletions(-) diff --git a/packages/maestro/src/internal/support-matrix.ts b/packages/maestro/src/internal/support-matrix.ts index dc72bcc5ac..e2b62a39e6 100644 --- a/packages/maestro/src/internal/support-matrix.ts +++ b/packages/maestro/src/internal/support-matrix.ts @@ -1,5 +1,5 @@ export const MAESTRO_COMPAT_SUPPORTED_CAPABILITIES = [ - 'Flows: launchApp (with clearState, permissions, and Apple-only launch arguments; permissions apply after state clearing but before launch, and a launchApp without permissions touches nothing — there is no silent all: allow default); setPermissions (mid-flow permission grants, denials, and resets; all resolves in the backend — one simctl call on iOS, the declared permissions on Android — with specific entries overriding after it); runFlow file/inline; runFlow.when and repeat.while conditions (platform, visible, notVisible, and true, all re-evaluated before every repeat iteration); onFlowStart/onFlowComplete; repeat with times, while, or both; and retry.', + 'Flows: launchApp (with clearState, permissions, and Apple-only launch arguments; permissions apply after state clearing but before launch, and a launchApp without permissions touches nothing — there is no silent all: allow default); setPermissions (mid-flow permission grants, denials, and resets; all resolves in the backend — each simctl privacy service on iOS, the declared permissions on Android — with specific entries overriding after it); runFlow file/inline; runFlow.when and repeat.while conditions (platform, visible, notVisible, and true, all re-evaluated before every repeat iteration); onFlowStart/onFlowComplete; repeat with times, while, or both; and retry.', 'Interactions: tapOn, doubleTapOn, longPressOn, inputText on the focused element, eraseText (up to 10000 characters), openLink, hideKeyboard, basic pressKey, and back; selector targets poll until available and support recursive index, childOf, above, below, leftOf, rightOf, containsChild, containsDescendants, points, and optional; outer command labels are metadata, not target selectors.', 'Assertions and navigation: assertVisible, assertNotVisible, assertTrue (literal values and ${VAR} lookups only; "", "false", "0", "null", and "undefined" are falsy, everything else is truthy), extendedWaitUntil, scroll, scrollUntilVisible, absolute/percentage/target swipe, takeScreenshot, waitForAnimationToEnd, clearState, stopApp, and killApp (system-initiated process death: am kill on ADB-backed Android devices, which refuse a foreground target with android-kill-requires-background-app — background the app first, for example pressKey: Home — and fail a target whose process survives with android-kill-process-survived; iOS, Limrun, and WebDriver-provider backends run it as stopApp).', 'Scripts: ordered runScript file/env scripts with http.post, json, and output variables; evalScript inline expressions run flow-scoped JavaScript and write output.* leaves for later steps.', diff --git a/packages/platform-apple/src/core/__tests__/simctl-settings.test.ts b/packages/platform-apple/src/core/__tests__/simctl-settings.test.ts index bb129ad3da..5bbcb15306 100644 --- a/packages/platform-apple/src/core/__tests__/simctl-settings.test.ts +++ b/packages/platform-apple/src/core/__tests__/simctl-settings.test.ts @@ -113,7 +113,6 @@ test('location set sends one latitude,longitude argument and returns the coordin test.for([ { options: { permissionTarget: 'calendar' }, service: 'calendar' }, - { options: { permissionTarget: 'all' }, service: 'all' }, { options: { permissionTarget: 'camera' }, service: 'camera' }, { options: { permissionTarget: 'photos', permissionMode: 'limited' }, service: 'photos-add' }, ])( @@ -134,6 +133,127 @@ test.for([ }, ); +const EVERY_SERVICE = [ + 'calendar', + 'camera', + 'contacts', + 'location-always', + 'media-library', + 'microphone', + 'motion', + 'photos', + 'reminders', + 'siri', + 'notifications', +]; + +function refusal(wording: string): AppError { + return new AppError('COMMAND_FAILED', 'simctl exited with code 1', { + stderr: `${wording}\nOperation not permitted`, + }); +} + +// A revoke also takes back limited photo access, a service of its own. +const EVERY_REVOKED_SERVICE = [...EVERY_SERVICE.slice(0, -1), 'photos-add', 'notifications']; + +test.for([ + { state: 'grant', action: 'grant', wording: 'Failed to grant access', services: EVERY_SERVICE }, + { + state: 'deny', + action: 'revoke', + wording: 'Failed to revoke access', + services: EVERY_REVOKED_SERVICE, + }, +])( + '$state all changes each service in turn and skips the one the runtime refuses', + async ({ state, action, wording, services }) => { + // The simulator records `all` as one kTCCServiceAll row that iOS does not consult. + const runSimctl = recordingRunner([ + ...services.slice(0, -1).map(() => ({ stdout: '', stderr: '' })), + refusal(wording), + ]); + + const result = await applySimctlSetting( + request(runSimctl, { + setting: 'permission', + state, + appBundleId: 'com.example.app', + options: { permissionTarget: 'all' }, + }), + ); + + expect(argvs(runSimctl)).toEqual( + services.map((service) => ['privacy', 'SIM-1', action, service, 'com.example.app']), + ); + expect(result).toEqual({ + permission: 'all', + permissions: services.slice(0, -1), + warnings: ['Skipped notifications: this iOS runtime does not let simctl privacy change it.'], + }); + }, +); + +test('reset all stays one simctl call, which clears every service', async () => { + const runSimctl = recordingRunner(); + + const result = await applySimctlSetting( + request(runSimctl, { + setting: 'permission', + state: 'reset', + appBundleId: 'com.example.app', + options: { permissionTarget: 'all' }, + }), + ); + + expect(argvs(runSimctl)).toEqual([['privacy', 'SIM-1', 'reset', 'all', 'com.example.app']]); + expect(result).toBeUndefined(); +}); + +test('grant all fails as unsupported only when the runtime refuses every service', async () => { + const refused = refusal('Failed to grant access'); + const runSimctl = recordingRunner(EVERY_SERVICE.map(() => refused)); + + await expect( + applySimctlSetting( + request(runSimctl, { + setting: 'permission', + state: 'grant', + appBundleId: 'com.example.app', + options: { permissionTarget: 'all' }, + }), + ), + ).rejects.toMatchObject({ + code: 'UNSUPPORTED_OPERATION', + message: + 'iOS simulator does not support setting all permission via simctl privacy on this runtime.', + details: { hint: expect.stringContaining('refused every privacy service') }, + cause: refused, + }); + expect(runSimctl).toHaveBeenCalledTimes(EVERY_SERVICE.length); +}); + +test('grant all stops at a failure that is not a refusal', async () => { + const failed = new AppError('COMMAND_FAILED', 'simctl exited with code 2', { + stderr: 'Invalid device: booted', + }); + const runSimctl = recordingRunner([{ stdout: '', stderr: '' }, failed]); + + await expect( + applySimctlSetting( + request(runSimctl, { + setting: 'permission', + state: 'grant', + appBundleId: 'com.example.app', + options: { permissionTarget: 'all' }, + }), + ), + ).rejects.toBe(failed); + expect(argvs(runSimctl)).toEqual([ + ['privacy', 'SIM-1', 'grant', 'calendar', 'com.example.app'], + ['privacy', 'SIM-1', 'grant', 'camera', 'com.example.app'], + ]); +}); + test('a privacy service the runtime refuses is unsupported; other failures pass through', async () => { const refused = new AppError('COMMAND_FAILED', 'simctl exited with code 1', { stderr: 'Failed to grant access to com.example.app\nOperation not permitted', @@ -188,6 +308,13 @@ test('a refused privacy service reports the device id the caller names, not the test.for([ { state: 'deny', action: 'revoke', target: 'notifications', wording: 'Failed to revoke access' }, { state: 'grant', action: 'grant', target: 'calendar', wording: 'Failed to set access' }, + { + state: 'grant', + action: 'grant', + target: 'notifications', + wording: + 'Underlying error (domain=NSPOSIXErrorDomain, code=1):\n\tFailed to create TCC authorization record', + }, ])( '$state $target refused as $wording is unsupported, with no capability probe', async ({ state, action, target, wording }) => { diff --git a/packages/platform-apple/src/core/simctl-settings.ts b/packages/platform-apple/src/core/simctl-settings.ts index 32cde1040c..f9b6eb5c05 100644 --- a/packages/platform-apple/src/core/simctl-settings.ts +++ b/packages/platform-apple/src/core/simctl-settings.ts @@ -46,12 +46,17 @@ async function setAppearance({ runSimctl, udid, state }: SimctlSettingRequest): await runSimctl(['ui', udid, 'appearance', target]); } -async function setPermission(request: SimctlSettingRequest): Promise { +async function setPermission( + request: SimctlSettingRequest, +): Promise | void> { const { runSimctl, udid, deviceId, state, options } = request; const permissionAction = parsePermissionAction(state); const action = permissionAction === 'deny' ? 'revoke' : permissionAction; const target = parseIosPrivacyService(options?.permissionTarget, options?.permissionMode); const appBundleId = await requireAppBundleId(request); + if (target === 'all' && action !== 'reset') { + return await setEveryIosPrivacyService(request, action, appBundleId); + } try { await runSimctl(['privacy', udid, action, target, appBundleId]); } catch (error) { @@ -60,6 +65,68 @@ async function setPermission(request: SimctlSettingRequest): Promise { } } +/** + * The services a grant or revoke of `all` changes one by one, in the widest access each takes: + * full contacts and photos, and location always, which `simctl privacy grant all` gave too. + * `notifications` is last because current runtimes refuse it. + */ +const IOS_ALL_PRIVACY_SERVICES = [ + 'calendar', + 'camera', + 'contacts', + 'location-always', + 'media-library', + 'microphone', + 'motion', + 'photos', + 'reminders', + 'siri', + 'notifications', +] as const; + +/** + * What a revoke of `all` also takes back: limited photo access (`photos-add`) is a service of + * its own, so revoking `photos` leaves it in place. Limited contacts share the `contacts` row. + */ +const IOS_ALL_REVOKED_PRIVACY_SERVICES = [ + ...IOS_ALL_PRIVACY_SERVICES.slice(0, -1), + 'photos-add', + 'notifications', +] as const; + +/** + * `all` for grant and revoke, as one `simctl privacy` call per service. The simulator records + * `simctl privacy grant all` as a single `kTCCServiceAll` row that iOS 27 does not consult, so the + * app still prompts, and a revoke of `all` leaves every per-service grant in place. A service the + * runtime refuses is skipped with a warning, as Android skips a permission it cannot change; + * any other failure stops the sequence. A reset of `all` stays one call: it removes every row. + */ +async function setEveryIosPrivacyService( + { runSimctl, udid, deviceId }: SimctlSettingRequest, + action: 'grant' | 'revoke', + appBundleId: string, +): Promise> { + const applied: string[] = []; + const warnings: string[] = []; + let lastRefusal: unknown; + const services = + action === 'revoke' ? IOS_ALL_REVOKED_PRIVACY_SERVICES : IOS_ALL_PRIVACY_SERVICES; + for (const service of services) { + try { + await runSimctl(['privacy', udid, action, service, appBundleId]); + applied.push(service); + } catch (error) { + if (!isIosPrivacyServiceRefusal(error)) throw error; + lastRefusal = error; + warnings.push(`Skipped ${service}: this iOS runtime does not let simctl privacy change it.`); + } + } + if (applied.length === 0) { + throw iosPrivacyServiceRefusedError(action, 'all', appBundleId, deviceId, lastRefusal); + } + return { permission: 'all', permissions: applied, ...(warnings.length > 0 ? { warnings } : {}) }; +} + async function setLocation(request: SimctlSettingRequest): Promise | void> { const { runSimctl, udid, state, options } = request; if (state.toLowerCase() === 'set') { @@ -135,12 +202,13 @@ function parseIosAppearance(stdout: string, stderr: string): 'light' | 'dark' | * EPERM, whether or not it is spelled in the help text. The help text is not a capability * list — Xcode 26 omits `camera`, which it does change — so the verdict is read from the * command that would have made the change rather than from a probe that can only guess. + * iOS 27 words the refusal `Failed to create TCC authorization record`. */ function isIosPrivacyServiceRefusal(error: unknown): boolean { if (!(error instanceof AppError) || error.code !== 'COMMAND_FAILED') return false; const stderr = String(error.details?.stderr ?? '').toLowerCase(); return ( - /failed to (set|grant|revoke|reset) access/.test(stderr) && + /failed to ((set|grant|revoke|reset) access|create tcc authorization record)/.test(stderr) && stderr.includes('operation not permitted') ); } @@ -170,7 +238,10 @@ function iosPrivacyServiceRefusedError( { deviceId, appBundleId, - hint: 'Privacy support varies by Xcode runtime: run `xcrun simctl privacy help` for its documented services, or use the `all` target, which applies the action to every service this runtime can change.', + hint: + target === 'all' + ? 'This runtime refused every privacy service. Run `xcrun simctl privacy help` for its documented services, or reset simulator content and settings.' + : 'Privacy support varies by Xcode runtime: run `xcrun simctl privacy help` for its documented services, or use the `all` target, which applies the action to every service this runtime can change.', }, cause, ); diff --git a/website/docs/docs/commands.md b/website/docs/docs/commands.md index 3ca0929a38..9f254dd759 100644 --- a/website/docs/docs/commands.md +++ b/website/docs/docs/commands.md @@ -850,7 +850,7 @@ Permissions: - `session_app_required`: no session app and none named. Run `open `, or name the app. - `setting_app_not_package` (`INVALID_ARGS`, Android): the name is an intent alias such as `settings`, not a package. - `setting_app_not_consumed`: the change is device-wide and cannot take an app: `location set`, the Android `location on|off` toggle, macOS permissions, `mobile-data`, and `bluetooth`. -- iOS targets: `all`, `camera`, `microphone`, `photos` (`full` or `limited`), `contacts`, `contacts-limited`, `notifications`, `calendar`, `location`, `location-always`, `media-library`, `motion`, `reminders`, `siri`. The simulator decides which it can change; one it refuses fails with `UNSUPPORTED_OPERATION` naming it. On current runtimes that is `notifications`, which `all` also leaves untouched. +- iOS targets: `all`, `camera`, `microphone`, `photos` (`full` or `limited`), `contacts`, `contacts-limited`, `notifications`, `calendar`, `location`, `location-always`, `media-library`, `motion`, `reminders`, `siri`. The simulator decides which it can change; one it refuses fails with `UNSUPPORTED_OPERATION` naming it. On current runtimes that is `notifications`. `grant all` and `deny all` change each service in turn, with `contacts` and `photos` in full and `location-always`, skip one the simulator refuses with a warning, and report the changed services in `permissions`; `reset all` clears every service in one call. - Android targets: `all`, `calendar`, `camera`, `contacts`, `location`, `media-library`, `microphone`, `notifications`, `photos`. Targets covering several permissions apply only the ones the app declares and fail if it declares none; `all` applies every declared permission. The response reports `permission` (what you asked for) and `permissions` (what was changed). - macOS targets: `accessibility`, `screen-recording`, `input-monitoring`. `grant` checks or requests access and opens System Settings when needed; it never grants silently. `deny` is unsupported. - `full|limited` applies only to iOS `photos`. diff --git a/website/docs/docs/run-maestro-flows.md b/website/docs/docs/run-maestro-flows.md index ca3d4d080a..b85076275a 100644 --- a/website/docs/docs/run-maestro-flows.md +++ b/website/docs/docs/run-maestro-flows.md @@ -23,7 +23,7 @@ Keep the target binding, such as `--platform ios`, on the `replay` or `test` com ## Supported subset -- Flows: `launchApp` (with `clearState`, `permissions`, and Apple-only launch arguments; `permissions` apply after state clearing but before launch, and a `launchApp` without `permissions` touches nothing — there is no silent `all: allow` default); `setPermissions` (mid-flow permission grants, denials, and resets; `all` resolves in the backend — one simctl call on iOS, the declared permissions on Android — with specific entries overriding after it); `runFlow` file/inline; `runFlow.when` and `repeat.while` conditions (`platform`, `visible`, `notVisible`, and `true`, all re-evaluated before every `repeat` iteration); `onFlowStart`/`onFlowComplete`; `repeat` with `times`, `while`, or both; and retry. +- Flows: `launchApp` (with `clearState`, `permissions`, and Apple-only launch arguments; `permissions` apply after state clearing but before launch, and a `launchApp` without `permissions` touches nothing — there is no silent `all: allow` default); `setPermissions` (mid-flow permission grants, denials, and resets; `all` resolves in the backend — each simctl privacy service on iOS, the declared permissions on Android — with specific entries overriding after it); `runFlow` file/inline; `runFlow.when` and `repeat.while` conditions (`platform`, `visible`, `notVisible`, and `true`, all re-evaluated before every `repeat` iteration); `onFlowStart`/`onFlowComplete`; `repeat` with `times`, `while`, or both; and retry. - Interactions: `tapOn`, `doubleTapOn`, `longPressOn`, `inputText` on the focused element, `eraseText` (up to 10000 characters), `openLink`, `hideKeyboard`, basic `pressKey`, and `back`; selector targets poll until available and support recursive `index`, `childOf`, `above`, `below`, `leftOf`, `rightOf`, `containsChild`, `containsDescendants`, points, and `optional`; outer command labels are metadata, not target selectors. - Assertions and navigation: `assertVisible`, `assertNotVisible`, `assertTrue` (literal values and `${VAR}` lookups only; `""`, `"false"`, `"0"`, `"null"`, and `"undefined"` are falsy, everything else is truthy), `extendedWaitUntil`, `scroll`, `scrollUntilVisible`, absolute/percentage/target `swipe`, `takeScreenshot`, `waitForAnimationToEnd`, `clearState`, `stopApp`, and `killApp` (system-initiated process death: `am kill` on ADB-backed Android devices, which refuse a foreground target with `android-kill-requires-background-app` — background the app first, for example `pressKey: Home` — and fail a target whose process survives with `android-kill-process-survived`; iOS, Limrun, and WebDriver-provider backends run it as `stopApp`). - Scripts: ordered `runScript` file/env scripts with `http.post`, `json`, and `output` variables; `evalScript` inline expressions run flow-scoped JavaScript and write `output.*` leaves for later steps. From 92eff8d6524736cd77eba6f629b62eae05709f63 Mon Sep 17 00:00:00 2001 From: parbez Date: Wed, 18 Nov 2026 14:33:35 +0530 Subject: [PATCH 2/2] fix(ios): key permission all to every target and name the services a failure left changed The services iOS all changes now derive from a table keyed by every permission target, so a new target is a compile error until it is placed, and the revoke list is that list plus photos-add with no ordering rule. A failure that is not a refusal stops the batch with the services already changed in its details.permissions. Revoking location-always also takes back while-in-use access on iOS 27.2, so location stays out of the list. --- .../core/__tests__/simctl-settings.test.ts | 18 +-- .../src/core/simctl-settings.ts | 104 ++++++++++-------- website/docs/docs/commands.md | 2 +- 3 files changed, 71 insertions(+), 53 deletions(-) diff --git a/packages/platform-apple/src/core/__tests__/simctl-settings.test.ts b/packages/platform-apple/src/core/__tests__/simctl-settings.test.ts index 5bbcb15306..5e0616ecc0 100644 --- a/packages/platform-apple/src/core/__tests__/simctl-settings.test.ts +++ b/packages/platform-apple/src/core/__tests__/simctl-settings.test.ts @@ -133,6 +133,7 @@ test.for([ }, ); +// Every target but the narrower ones that share a row (contacts-limited, location). const EVERY_SERVICE = [ 'calendar', 'camera', @@ -141,10 +142,10 @@ const EVERY_SERVICE = [ 'media-library', 'microphone', 'motion', + 'notifications', 'photos', 'reminders', 'siri', - 'notifications', ]; function refusal(wording: string): AppError { @@ -154,7 +155,7 @@ function refusal(wording: string): AppError { } // A revoke also takes back limited photo access, a service of its own. -const EVERY_REVOKED_SERVICE = [...EVERY_SERVICE.slice(0, -1), 'photos-add', 'notifications']; +const EVERY_REVOKED_SERVICE = [...EVERY_SERVICE, 'photos-add']; test.for([ { state: 'grant', action: 'grant', wording: 'Failed to grant access', services: EVERY_SERVICE }, @@ -168,10 +169,11 @@ test.for([ '$state all changes each service in turn and skips the one the runtime refuses', async ({ state, action, wording, services }) => { // The simulator records `all` as one kTCCServiceAll row that iOS does not consult. - const runSimctl = recordingRunner([ - ...services.slice(0, -1).map(() => ({ stdout: '', stderr: '' })), - refusal(wording), - ]); + const runSimctl = recordingRunner( + services.map((service) => + service === 'notifications' ? refusal(wording) : { stdout: '', stderr: '' }, + ), + ); const result = await applySimctlSetting( request(runSimctl, { @@ -187,7 +189,7 @@ test.for([ ); expect(result).toEqual({ permission: 'all', - permissions: services.slice(0, -1), + permissions: services.filter((service) => service !== 'notifications'), warnings: ['Skipped notifications: this iOS runtime does not let simctl privacy change it.'], }); }, @@ -252,6 +254,8 @@ test('grant all stops at a failure that is not a refusal', async () => { ['privacy', 'SIM-1', 'grant', 'calendar', 'com.example.app'], ['privacy', 'SIM-1', 'grant', 'camera', 'com.example.app'], ]); + // The error names what had already changed, beside what the failure itself reported. + expect(failed.details).toEqual({ stderr: 'Invalid device: booted', permissions: ['calendar'] }); }); test('a privacy service the runtime refuses is unsupported; other failures pass through', async () => { diff --git a/packages/platform-apple/src/core/simctl-settings.ts b/packages/platform-apple/src/core/simctl-settings.ts index f9b6eb5c05..7394ef8954 100644 --- a/packages/platform-apple/src/core/simctl-settings.ts +++ b/packages/platform-apple/src/core/simctl-settings.ts @@ -65,41 +65,66 @@ async function setPermission( } } +/** The `simctl privacy` service for every target except `photos`, whose service depends on its mode. */ +const IOS_PRIVACY_SERVICES: Record, string> = { + all: 'all', + camera: 'camera', + microphone: 'microphone', + contacts: 'contacts', + 'contacts-limited': 'contacts-limited', + notifications: 'notifications', + calendar: 'calendar', + location: 'location', + 'location-always': 'location-always', + 'media-library': 'media-library', + motion: 'motion', + reminders: 'reminders', + siri: 'siri', +}; + /** - * The services a grant or revoke of `all` changes one by one, in the widest access each takes: - * full contacts and photos, and location always, which `simctl privacy grant all` gave too. - * `notifications` is last because current runtimes refuse it. + * Whether a grant or revoke of `all` changes each target's service, keyed by every target so a new + * one cannot be left out without a compile error. `all` takes the widest access each service + * offers: full contacts and photos, and location always, which `simctl privacy grant all` gave + * too. The narrower targets are left to the row they share: limited contacts write the `contacts` + * row, and revoking `location-always` takes back while-in-use access too (iOS 27.2). */ -const IOS_ALL_PRIVACY_SERVICES = [ - 'calendar', - 'camera', - 'contacts', - 'location-always', - 'media-library', - 'microphone', - 'motion', - 'photos', - 'reminders', - 'siri', - 'notifications', -] as const; +const IOS_ALL_TARGETS = { + calendar: true, + camera: true, + contacts: true, + 'contacts-limited': false, + location: false, + 'location-always': true, + 'media-library': true, + microphone: true, + motion: true, + notifications: true, + photos: true, + reminders: true, + siri: true, +} as const satisfies Record, boolean>; + +/** The services a grant of `all` changes, one `simctl privacy` call each. */ +const IOS_ALL_GRANTED_SERVICES: readonly string[] = ( + Object.keys(IOS_ALL_TARGETS) as (keyof typeof IOS_ALL_TARGETS)[] +) + .filter((target) => IOS_ALL_TARGETS[target]) + .map((target) => (target === 'photos' ? 'photos' : IOS_PRIVACY_SERVICES[target])); /** - * What a revoke of `all` also takes back: limited photo access (`photos-add`) is a service of - * its own, so revoking `photos` leaves it in place. Limited contacts share the `contacts` row. + * The services a revoke of `all` changes: every granted one, and limited photo access + * (`photos-add`), a service of its own that revoking `photos` leaves in place. */ -const IOS_ALL_REVOKED_PRIVACY_SERVICES = [ - ...IOS_ALL_PRIVACY_SERVICES.slice(0, -1), - 'photos-add', - 'notifications', -] as const; +const IOS_ALL_REVOKED_SERVICES: readonly string[] = [...IOS_ALL_GRANTED_SERVICES, 'photos-add']; /** * `all` for grant and revoke, as one `simctl privacy` call per service. The simulator records * `simctl privacy grant all` as a single `kTCCServiceAll` row that iOS 27 does not consult, so the * app still prompts, and a revoke of `all` leaves every per-service grant in place. A service the - * runtime refuses is skipped with a warning, as Android skips a permission it cannot change; - * any other failure stops the sequence. A reset of `all` stays one call: it removes every row. + * runtime refuses is skipped with a warning, as Android skips a permission it cannot change. Any + * other failure stops the sequence, and its error carries the services already changed in + * `details.permissions`. A reset of `all` stays one call: it removes every row. */ async function setEveryIosPrivacyService( { runSimctl, udid, deviceId }: SimctlSettingRequest, @@ -109,14 +134,13 @@ async function setEveryIosPrivacyService( const applied: string[] = []; const warnings: string[] = []; let lastRefusal: unknown; - const services = - action === 'revoke' ? IOS_ALL_REVOKED_PRIVACY_SERVICES : IOS_ALL_PRIVACY_SERVICES; + const services = action === 'revoke' ? IOS_ALL_REVOKED_SERVICES : IOS_ALL_GRANTED_SERVICES; for (const service of services) { try { await runSimctl(['privacy', udid, action, service, appBundleId]); applied.push(service); } catch (error) { - if (!isIosPrivacyServiceRefusal(error)) throw error; + if (!isIosPrivacyServiceRefusal(error)) throw withAppliedServices(error, applied); lastRefusal = error; warnings.push(`Skipped ${service}: this iOS runtime does not let simctl privacy change it.`); } @@ -127,6 +151,13 @@ async function setEveryIosPrivacyService( return { permission: 'all', permissions: applied, ...(warnings.length > 0 ? { warnings } : {}) }; } +/** The error that stopped `all` partway, naming the services it had already changed. */ +function withAppliedServices(error: unknown, applied: readonly string[]): unknown { + if (!(error instanceof AppError) || applied.length === 0) return error; + error.details = { ...error.details, permissions: [...applied] }; + return error; +} + async function setLocation(request: SimctlSettingRequest): Promise | void> { const { runSimctl, udid, state, options } = request; if (state.toLowerCase() === 'set') { @@ -151,23 +182,6 @@ async function requireAppBundleId({ ); } -/** The `simctl privacy` service for every target except `photos`, whose service depends on its mode. */ -const IOS_PRIVACY_SERVICES: Record, string> = { - all: 'all', - camera: 'camera', - microphone: 'microphone', - contacts: 'contacts', - 'contacts-limited': 'contacts-limited', - notifications: 'notifications', - calendar: 'calendar', - location: 'location', - 'location-always': 'location-always', - 'media-library': 'media-library', - motion: 'motion', - reminders: 'reminders', - siri: 'siri', -}; - function parseIosPrivacyService( permissionTarget: string | undefined, permissionMode: string | undefined, diff --git a/website/docs/docs/commands.md b/website/docs/docs/commands.md index 9f254dd759..1815323507 100644 --- a/website/docs/docs/commands.md +++ b/website/docs/docs/commands.md @@ -850,7 +850,7 @@ Permissions: - `session_app_required`: no session app and none named. Run `open `, or name the app. - `setting_app_not_package` (`INVALID_ARGS`, Android): the name is an intent alias such as `settings`, not a package. - `setting_app_not_consumed`: the change is device-wide and cannot take an app: `location set`, the Android `location on|off` toggle, macOS permissions, `mobile-data`, and `bluetooth`. -- iOS targets: `all`, `camera`, `microphone`, `photos` (`full` or `limited`), `contacts`, `contacts-limited`, `notifications`, `calendar`, `location`, `location-always`, `media-library`, `motion`, `reminders`, `siri`. The simulator decides which it can change; one it refuses fails with `UNSUPPORTED_OPERATION` naming it. On current runtimes that is `notifications`. `grant all` and `deny all` change each service in turn, with `contacts` and `photos` in full and `location-always`, skip one the simulator refuses with a warning, and report the changed services in `permissions`; `reset all` clears every service in one call. +- iOS targets: `all`, `camera`, `microphone`, `photos` (`full` or `limited`), `contacts`, `contacts-limited`, `notifications`, `calendar`, `location`, `location-always`, `media-library`, `motion`, `reminders`, `siri`. The simulator decides which it can change; one it refuses fails with `UNSUPPORTED_OPERATION` naming it. On current runtimes that is `notifications`. `grant all` and `deny all` change each service in turn, with `contacts` and `photos` in full and `location-always`; `deny all` also revokes limited photos (`photos-add`). They report the changed services in `permissions`, add a `Skipped ` entry to `warnings` for each service the simulator refuses, and on any other failure stop with the services already changed in `error.details.permissions`. `reset all` clears every service in one call. - Android targets: `all`, `calendar`, `camera`, `contacts`, `location`, `media-library`, `microphone`, `notifications`, `photos`. Targets covering several permissions apply only the ones the app declares and fail if it declares none; `all` applies every declared permission. The response reports `permission` (what you asked for) and `permissions` (what was changed). - macOS targets: `accessibility`, `screen-recording`, `input-monitoring`. `grant` checks or requests access and opens System Settings when needed; it never grants silently. `deny` is unsupported. - `full|limited` applies only to iOS `photos`.