Permission API Reference
Named permission constants, platform availability, native mappings, restrictions, and official Apple and Android documentation.
Use the named Permission, IosPermission, and AndroidPermission constants
with the task’s ansight.permissions APIs. They are frozen JavaScript exports
with readonly string literal types, so they work with native TypeScript execution.
The generated runtime module and
declarations include hover docs
on every constant.
Usage
Run ansight workspace init . to install ansight/tasks/ansight-task.js and its
declarations. Existing support files are preserved by default; --force refreshes
canonical files after upgrading the CLI. Nested tasks adjust the relative import
path, for example ../ansight-task.js.
import { Permission, IosPermission, AndroidPermission } from "./ansight-task.js";
import type { TaskInvocation } from "./ansight-task.d.ts";
export default async function run({ ansight, expect }: TaskInvocation) {
await ansight.permissions.grant({ permission: Permission.Microphone });
const access = await ansight.permissions.query({ permission: Permission.Microphone });
expect(access.status, { id: "microphone-granted" }).toBe("granted");
await ansight.permissions.revoke({ permission: Permission.Microphone });
// Put native calls in tasks for the corresponding platform.
await ansight.permissions.ios.reset({ permission: IosPermission.Photos });
await ansight.permissions.android.grant({ permission: AndroidPermission.Camera });
}
Permission, IosPermission, and AndroidPermission can also be used as value
types. AppPermission aliases the shared union, and CommonAndroidPermission
is the union of the Android constants. AndroidPermission also accepts other
fully qualified identifiers, such as "com.example.permission.CUSTOM".
Literal strings and the earlier lowercase .names catalogs remain supported.
Platform and operation availability
| API | Devices | Operations |
|---|---|---|
ansight.permissions | iOS Simulator; Android emulator or authorized physical device, subject to each row below | grant, revoke, query using resource approximations |
ansight.permissions.ios | iOS Simulator only; physical iOS and Android unsupported | grant, revoke, query, reset using exact simctl services |
ansight.permissions.android | Android emulator or authorized physical device; iOS unsupported | grant, revoke, query using exact manifest identifiers |
All operations use the task’s enforced app and session in SDK or device mode;
no hostTools declaration or target overrides are needed. Await native calls
serially. The Android API levels below describe when a manifest identifier was
introduced. Runtime grant/revoke require Android’s runtime-permission mechanism
(API 23+), a declared permission managed at runtime, and native policy permitting
the change. A constant’s existence does not guarantee effective resource access.
For iOS, mutations require the named service in the installed simctl privacy
service list. Xcode 11.4 introduced simctl privacy control.
Queries read Simulator TCC or location authorization stores; unrecognized or
unreadable state is unknown. The camera service can be queried even when
mutations are unavailable. iOS notification control has no backend in this
provider. Hardware, global device settings, app capabilities, roles, and usage
descriptions are distinct from the authorization state controlled here.
Shared permissions
Each constant maps to the native permissions listed in its row. Android manifest
identifiers use the full android.permission. prefix in the linked labels.
Calendar, foreground location, and visual media use the subset the app declares.
Results expose the exact subset in nativePermissions.
| Constant and value | Availability and behavior | iOS mapping and docs | Android mapping and docs |
|---|---|---|---|
Permission.Camera ("camera") | Android emulators and authorized physical devices; iOS Simulator queries TCC. iOS mutations require camera in installed simctl privacy services. | camera | android.permission.CAMERA |
Permission.Microphone ("microphone") | iOS Simulator; Android emulators and authorized physical devices. | microphone | android.permission.RECORD_AUDIO |
Permission.Contacts ("contacts") | iOS Simulator; Android emulators and authorized physical devices. | contacts | android.permission.READ_CONTACTS |
Permission.Calendar ("calendar") | iOS Simulator; Android emulators and authorized physical devices. EventKit full/write-only access is not separately modeled. | calendar | android.permission.READ_CALENDAR / android.permission.WRITE_CALENDAR |
Permission.Photos ("photos") | iOS Simulator; Android emulators and authorized physical devices. Android 14+ selected access is queried and revoked, but grant does not select particular media. | photos | android.permission.READ_MEDIA_IMAGES / android.permission.READ_MEDIA_VIDEO on API 33+ with target SDK 33+; android.permission.READ_EXTERNAL_STORAGE otherwise |
Permission.Location ("location") | iOS Simulator; Android emulators and authorized physical devices. | location | android.permission.ACCESS_COARSE_LOCATION / android.permission.ACCESS_FINE_LOCATION |
Permission.LocationAlways ("locationAlways") | iOS Simulator; Android emulators and authorized physical devices. Android grants declared foreground dependencies first. On API 29+, revoke removes background access only; iOS revoke denies location entirely. | location-always | android.permission.ACCESS_BACKGROUND_LOCATION on API 29+; android.permission.ACCESS_COARSE_LOCATION / android.permission.ACCESS_FINE_LOCATION on older Android |
Permission.MediaLibrary ("mediaLibrary") | iOS Simulator; Android emulators and authorized physical devices. | media-library | android.permission.READ_MEDIA_AUDIO on API 33+ with target SDK 33+; android.permission.READ_EXTERNAL_STORAGE otherwise |
Permission.Motion ("motion") | iOS Simulator; Android API 29+ on emulators and authorized physical devices. Unsupported on older Android. | motion | android.permission.ACTIVITY_RECOGNITION |
Permission.Notifications ("notifications") | Android API 33+ on emulators and authorized physical devices. Unsupported on iOS and older Android. | Unsupported; notification authorization docs | android.permission.POST_NOTIFICATIONS |
Background location grants the declared Android foreground dependencies first;
on API 29+, shared revocation removes only background access. iOS
location-always revocation denies all location access. Android 14+ selected
photo access can produce limited and is included in shared Photos revocation;
grants do not choose which photos or contacts a user shares.
Native iOS permissions
Every row is iOS Simulator only, with no Android native mapping or physical
iOS support. Grant/revoke/reset depend on the installed simctl service list.
Use shared Permission constants when you want an Android resource equivalent.
| Constant | Native simctl service | Availability and behavior | Official platform docs |
|---|---|---|---|
IosPermission.Camera | camera | iOS Simulator; Queries TCC. Mutations require camera in installed simctl services; the provider does not supply camera hardware. | Apple authorization docs |
IosPermission.Microphone | microphone | iOS Simulator; Queries read the Simulator authorization store; unreadable state is unknown. | Apple authorization docs |
IosPermission.Contacts | contacts | iOS Simulator; Queries read the Simulator authorization store; unreadable state is unknown. | Apple authorization docs |
IosPermission.ContactsLimited | contacts-limited | iOS Simulator; Requires a Simulator runtime and simctl service with limited-contact support. Does not choose specific contacts. | Apple authorization docs |
IosPermission.Calendar | calendar | iOS Simulator; Controls the simctl calendar service; EventKit full/write-only access is not separately modeled. | Apple authorization docs |
IosPermission.Photos | photos | iOS Simulator; Controls photo-library authorization; limited user selections can remain limited. | Apple authorization docs |
IosPermission.PhotosAdd | photos-add | iOS Simulator; Controls add-only photo authorization; grants no photo-library read access. | Apple authorization docs |
IosPermission.Location | location | iOS Simulator; When-in-use location. Authorization is distinct from simulated device coordinates. | Apple authorization docs |
IosPermission.LocationAlways | location-always | iOS Simulator; Always location. Revoking this simctl service denies all location access. | Apple authorization docs |
IosPermission.MediaLibrary | media-library | iOS Simulator; Controls media-library authorization; does not populate the Simulator with music. | Apple authorization docs |
IosPermission.Motion | motion | iOS Simulator; Authorization is distinct from hardware or motion-data availability. | Apple authorization docs |
IosPermission.Reminders | reminders | iOS Simulator; Queries read the Simulator authorization store; unreadable state is unknown. | Apple authorization docs |
IosPermission.Siri | siri | iOS Simulator; Controls SiriKit authorization; Siri capability and app configuration are still required. | Apple authorization docs |
reset clears a native authorization decision so the next in-app request can
prompt again. Simulator authorization does not supply camera hardware, motion
data, media-library content, or Siri behavior.
Native Android permissions
Every row is Android only, on emulators or authorized physical devices.
There is no native iOS mapping. The app must declare the identifier and native
pm must allow the operation for the active Android user. Shared names provide
cross-platform resource approximations where available.
| Constant | Native identifier and official docs | Identifier availability | Restrictions and behavior |
|---|---|---|---|
AndroidPermission.Camera | android.permission.CAMERA | Android API 1+ | Device services and app roles can further constrain effective access. |
AndroidPermission.RecordAudio | android.permission.RECORD_AUDIO | Android API 1+ | Device services and app roles can further constrain effective access. |
AndroidPermission.ReadContacts | android.permission.READ_CONTACTS | Android API 1+ | Device services and app roles can further constrain effective access. |
AndroidPermission.WriteContacts | android.permission.WRITE_CONTACTS | Android API 1+ | Device services and app roles can further constrain effective access. |
AndroidPermission.GetAccounts | android.permission.GET_ACCOUNTS | Android API 1+ | Does not sign in to accounts or grant account-provider access; signature and account-visibility rules still apply. |
AndroidPermission.ReadCalendar | android.permission.READ_CALENDAR | Android API 1+ | Device services and app roles can further constrain effective access. |
AndroidPermission.WriteCalendar | android.permission.WRITE_CALENDAR | Android API 1+ | Device services and app roles can further constrain effective access. |
AndroidPermission.AccessCoarseLocation | android.permission.ACCESS_COARSE_LOCATION | Android API 1+ | Device services and app roles can further constrain effective access. |
AndroidPermission.AccessFineLocation | android.permission.ACCESS_FINE_LOCATION | Android API 1+ | Approximate user choices can limit effective precision; authorization is distinct from device location settings. |
AndroidPermission.AccessBackgroundLocation | android.permission.ACCESS_BACKGROUND_LOCATION | Android API 29+ | Installer allowlisting is required; pm does not bypass native restrictions. Requires declared and granted foreground coarse/fine location. Native calls do not automatically grant dependencies. |
AndroidPermission.ReadMediaImages | android.permission.READ_MEDIA_IMAGES | Android API 33+ | Use for apps targeting API 33+; older targets use READ_EXTERNAL_STORAGE. |
AndroidPermission.ReadMediaVideo | android.permission.READ_MEDIA_VIDEO | Android API 33+ | Use for apps targeting API 33+; older targets use READ_EXTERNAL_STORAGE. |
AndroidPermission.ReadMediaAudio | android.permission.READ_MEDIA_AUDIO | Android API 33+ | Use for apps targeting API 33+; older targets use READ_EXTERNAL_STORAGE. |
AndroidPermission.ReadMediaVisualUserSelected | android.permission.READ_MEDIA_VISUAL_USER_SELECTED | Android API 34+ | Does not choose particular media. Use with declared READ_MEDIA_IMAGES/READ_MEDIA_VIDEO as appropriate; shared Photos revoke also clears this permission. |
AndroidPermission.ReadExternalStorage | android.permission.READ_EXTERNAL_STORAGE | Android API 16+ | Legacy storage access is constrained by OS, target SDK, scoped storage, and installer policy. Use granular media permissions for target SDK 33+. |
AndroidPermission.WriteExternalStorage | android.permission.WRITE_EXTERNAL_STORAGE | Android API 4+ | Has no storage-access effect for apps targeting API 30+. |
AndroidPermission.ActivityRecognition | android.permission.ACTIVITY_RECOGNITION | Android API 29+ | Device services and app roles can further constrain effective access. |
AndroidPermission.BodySensors | android.permission.BODY_SENSORS | Android API 20+ | Apps targeting API 36+ use granular android.permission.health identifiers for affected sensor APIs. Android 16 migration. |
AndroidPermission.BodySensorsBackground | android.permission.BODY_SENSORS_BACKGROUND | Android API 33+ | Installer allowlisting is required; pm does not bypass native restrictions. Requires BODY_SENSORS first. Apps targeting API 36+ use READ_HEALTH_DATA_IN_BACKGROUND for affected APIs. Android 16 migration. |
AndroidPermission.PostNotifications | android.permission.POST_NOTIFICATIONS | Android API 33+ | Device services and app roles can further constrain effective access. |
AndroidPermission.BluetoothScan | android.permission.BLUETOOTH_SCAN | Android API 31+ | Device services and app roles can further constrain effective access. |
AndroidPermission.BluetoothConnect | android.permission.BLUETOOTH_CONNECT | Android API 31+ | Device services and app roles can further constrain effective access. |
AndroidPermission.BluetoothAdvertise | android.permission.BLUETOOTH_ADVERTISE | Android API 31+ | Device services and app roles can further constrain effective access. |
AndroidPermission.NearbyWifiDevices | android.permission.NEARBY_WIFI_DEVICES | Android API 33+ | Device services and app roles can further constrain effective access. |
AndroidPermission.ReadPhoneState | android.permission.READ_PHONE_STATE | Android API 1+ | Device services and app roles can further constrain effective access. |
AndroidPermission.ReadPhoneNumbers | android.permission.READ_PHONE_NUMBERS | Android API 26+ | Device services and app roles can further constrain effective access. |
AndroidPermission.CallPhone | android.permission.CALL_PHONE | Android API 1+ | Device services and app roles can further constrain effective access. |
AndroidPermission.AnswerPhoneCalls | android.permission.ANSWER_PHONE_CALLS | Android API 26+ | Device services and app roles can further constrain effective access. |
AndroidPermission.ReadCallLog | android.permission.READ_CALL_LOG | Android API 16+ | Installer allowlisting is required; pm does not bypass native restrictions. |
AndroidPermission.WriteCallLog | android.permission.WRITE_CALL_LOG | Android API 16+ | Installer allowlisting is required; pm does not bypass native restrictions. |
AndroidPermission.SendSms | android.permission.SEND_SMS | Android API 1+ | Installer allowlisting is required; pm does not bypass native restrictions. |
AndroidPermission.ReadSms | android.permission.READ_SMS | Android API 1+ | Installer allowlisting is required; pm does not bypass native restrictions. |
AndroidPermission.ReceiveSms | android.permission.RECEIVE_SMS | Android API 1+ | Installer allowlisting is required; pm does not bypass native restrictions. |
AndroidPermission.ReceiveMms | android.permission.RECEIVE_MMS | Android API 1+ | Installer allowlisting is required; pm does not bypass native restrictions. |
AndroidPermission.ReceiveWapPush | android.permission.RECEIVE_WAP_PUSH | Android API 1+ | Installer allowlisting is required; pm does not bypass native restrictions. |
Installer restrictions, account visibility, call/SMS roles, scoped storage, and
other native policy are enforced by Android; a pm grant is not a bypass. For
custom or additional system permissions, pass a fully qualified identifier.
Special access such as overlay, all-files access, and app roles requires other
native APIs and is outside these permission methods.
Results and lifecycle
PermissionResult reports supported, isSuccess, status, backend,
nativePermissions, and the enforced target identifiers. Status is granted,
denied, notDetermined, limited, unsupported, or unknown. Mixed native
states are limited. Unsupported queries return a result; unsupported mutations
and failed native commands throw. Partial mutations retain individual observed
states in the recorded result. A successful command reports subsequently
observed state, which can be unknown if the store is unreadable.
Permission changes can terminate the app. Later calls retain the captured session
target; use ansight.lifecycle.launch() when a task needs to relaunch it. Native
grants can bypass the app’s usage-description checks, so test its actual prompt
flow separately. See the task API for the
complete host contract.