### Customize permission persistence with SharedPreferencesPermissionPersistence Source: https://github.com/alirezajavan/permpilot/blob/master/README.md Use this snippet to customize how the 'has requested' flags are stored on Android, for example to use encrypted storage. It creates a SharedPreferencesPermissionPersistence with a custom prefs name and passes it to PermissionController.create. ```kotlin val persistence = SharedPreferencesPermissionPersistence(context, prefsName = "my_custom_prefs") val controller = PermissionController.create(context, persistence = persistence) ``` -------------------------------- ### Run full build gate with ./gradlew build Source: https://github.com/alirezajavan/permpilot/blob/master/README.md Runs the full CI gate before opening a PR: all module tests, both iOS targets, Android Lint, and API compatibility checks against the committed baselines. Regenerate baselines with ./gradlew apiDump when intentionally changing the API surface. ```bash ./gradlew build ``` -------------------------------- ### Gradle commands to verify iOS code without a Mac Source: https://github.com/alirezajavan/permpilot/blob/master/CLAUDE.md Run these three Gradle commands to type-check and compile Kotlin code for iOS targets. They catch cinterop symbol errors, nullability issues, missing @OptIn(ExperimentalForeignApi::class), and enum-binding shape mistakes. A real device/simulator run via Xcode is still required before shipping. ```bash ./gradlew :permpilot-core:compileIosMainKotlinMetadata # fast frontend type-check against Apple K/N stubs ./gradlew :permpilot-core:compileKotlinIosArm64 # real klib codegen, device target ./gradlew :permpilot-core:compileKotlinIosSimulatorArm64 # real klib codegen, simulator target ``` -------------------------------- ### Create a permission dashboard with PermissionDashboard Source: https://github.com/alirezajavan/permpilot/blob/master/README.md Creates a 'Privacy Settings' or 'Permissions' screen in one line. Pass the controller and the list of permissions to display; the modifier can be used to fill the available space. ```kotlin PermissionDashboard( controller = controller, permissions = listOf(Permission.Camera, Permission.Microphone, Permission.LocationWhileInUse), modifier = Modifier.fillMaxSize() ) ``` -------------------------------- ### Enable pre-commit hook with git config Source: https://github.com/alirezajavan/permpilot/blob/master/README.md Run once per clone to enable the pre-commit hook so local mistakes are caught before CI. ```bash git config core.hooksPath .githooks ``` -------------------------------- ### Core API: Permission, PermissionState, and PermissionController Source: https://github.com/alirezajavan/permpilot/blob/master/README.md Core API definitions for the PermPilot library: the Permission sealed interface with Runtime, Special, and PlatformLimited subtypes; the PermissionState sealed interface covering all possible permission states; and the PermissionController interface exposing flows, state queries, request functions, and settings navigation. ```kotlin sealed interface Permission { sealed interface Runtime : Permission // has a real request on ≥1 platform sealed interface Special : Permission // Android Settings redirect, no dialog sealed interface PlatformLimited : Permission // no request API on either platform data object Camera : Runtime data object LocationWhileInUse : Runtime data object LocationAlways : Runtime // staged: foreground first, then background data object PhotoLibrary : Runtime // supports Limited(PartialMediaAccess) /* ...27 Runtime + 8 Special + LocalNetwork -- full list in docs/permission-matrix.md */ } ``` ```kotlin sealed interface PermissionState { data object NotDetermined : PermissionState data object Granted : PermissionState data class Denied(val canRequestAgain: Boolean) : PermissionState data object PermanentlyDenied : PermissionState data object Restricted : PermissionState data class Limited(val reason: LimitedReason) : PermissionState data class ConfigurationError(val reason: ConfigurationErrorReason) : PermissionState } ``` ```kotlin interface PermissionController { val events: SharedFlow fun state(permission: Permission): StateFlow suspend fun request(permission: Permission.Runtime): PermissionState suspend fun requestAll(vararg permissions: Permission.Runtime): Map fun openAppSettings() fun openAppSettings(special: Permission.Special) fun refreshAll() } ``` -------------------------------- ### Upgrade a Limited grant by calling controller.request Source: https://github.com/alirezajavan/permpilot/blob/master/README.md Offers an upgrade affordance for a Limited grant (e.g., partial photos, approximate location). Since Limited is a working grant, the gate shows no prompt; call controller.request(permission) directly to trigger the OS's own picker/upgrade dialog without a rationale. ```kotlin if (state is PermissionState.Limited) { Button(onClick = { scope.launch { controller.request(Permission.PhotoLibrary) } }) { Text("Allow access to all photos") } } ``` -------------------------------- ### Apache License 2.0 header Source: https://github.com/alirezajavan/permpilot/blob/master/README.md Standard Apache License 2.0 header for the project. ```text Copyright 2026 Alireza Javan Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ``` -------------------------------- ### Request camera permission with PermissionGate Source: https://github.com/alirezajavan/permpilot/blob/master/README.md Use this Compose Multiplatform composable to request the camera permission and react to its state. The lambda receives a PermissionState that you can exhaustively when over, showing a preview when granted or a fallback message otherwise. ```kotlin PermissionGate(permission = Permission.Camera) { state -> when (state) { PermissionState.Granted -> CameraPreview() else -> Text("Camera access needed to continue") } } ``` -------------------------------- ### Replace prompts with custom composables using slot-level customization Source: https://github.com/alirezajavan/permpilot/blob/master/README.md Replaces the default prompts with custom composables (bottom sheet, banner) via the rationale and settingsPrompt slots. Each slot is a plain composable lambda, so any UI component can be used without modifying the gate's state machine. The content lambda handles the state, including Limited as a working grant. ```kotlin PermissionGate( permission = Permission.LocationWhileInUse, rationale = { onRequest, onDismiss -> MyBottomSheet(onConfirm = onRequest, onDismiss = onDismiss) }, settingsPrompt = { onOpenSettings, onDismiss -> MyBanner(onClick = onOpenSettings, onClose = onDismiss) }, ) { state -> when (state) { PermissionState.Granted -> ShowMap() is PermissionState.Limited -> ShowMap(approximate = true) else -> Text("Location needed") } } ``` -------------------------------- ### Use PermissionGate and PermissionsGate for permission handling Source: https://github.com/alirezajavan/permpilot/blob/master/README.md Shows the primary usage of PermissionGate for a single permission and PermissionsGate for multiple permissions. The content lambda receives the current state and is always called first, allowing the UI to be the source of truth. The gate then layers prompts based on the state, as described in the table. ```kotlin @Composable fun CameraScreen() { PermissionGate(permission = Permission.Camera) { state -> when (state) { PermissionState.Granted -> CameraPreview() else -> Text("Camera access needed to continue") } } } // Or for multiple permissions together: @Composable fun VideoCallScreen() { PermissionsGate(permissions = listOf(Permission.Camera, Permission.Microphone)) { states -> if (states.values.all { it == PermissionState.Granted }) { VideoCallUI() } else { Text("Camera and Microphone access needed") } } } ``` -------------------------------- ### Run Script Phase: embedAndSignAppleFrameworkForXcode Source: https://github.com/alirezajavan/permpilot/blob/master/sample/iosApp/README.md Paste this into a new Run Script Phase in Xcode, placed as the first phase above Compile Sources. It builds and embeds the Kotlin/Native framework for the current Xcode configuration. Requires disabling User Script Sandboxing in Build Settings. ```sh cd "$SRCROOT/../.." ./gradlew :sample:composeApp:embedAndSignAppleFrameworkForXcode ``` -------------------------------- ### Test with FakePermissionController Source: https://github.com/alirezajavan/permpilot/blob/master/README.md Use this snippet to test your own code with a fake PermissionController. It lets you set permission states and drive your screen or ViewModel exactly like a real controller, without needing an Activity, iOS runtime, or OS permission dialog. ```kotlin val controller = FakePermissionController() controller.setState(Permission.Camera, PermissionState.Denied(canRequestAgain = true)) // Drive your screen/ViewModel against `controller` exactly like a real one -- // no Activity, no iOS runtime, no OS permission dialog required. ``` -------------------------------- ### PermissionController Source: https://github.com/alirezajavan/permpilot/blob/master/README.md The PermissionController interface is the main entry point for managing permissions. It exposes methods to query permission states, request runtime permissions, open app settings, and refresh all permission states. ```APIDOC ## PermissionController ### Description Interface for managing runtime and special permissions. Provides state observation, permission requests, and settings navigation. ### Methods #### state(permission: Permission): StateFlow Returns a StateFlow that emits the current state for the given permission. #### request(permission: Permission.Runtime): PermissionState Requests a runtime permission and returns the resulting state. #### requestAll(vararg permissions: Permission.Runtime): Map Requests multiple runtime permissions and returns a map of each permission to its resulting state. #### openAppSettings() Opens the app settings screen. #### openAppSettings(special: Permission.Special) Opens the app settings screen for a special permission. #### refreshAll() Refreshes the state of all permissions. ### Properties - **events**: SharedFlow - A flow of permission events. ``` -------------------------------- ### Wrap PermissionController with HistoryPermissionController for audit logging Source: https://github.com/alirezajavan/permpilot/blob/master/README.md Use this snippet to wrap any PermissionController with an audit log that records every request, resolution, and settings-open event into a SQLDelight-backed store. The HistoryPermissionController is a drop-in replacement for the wrapped controller. Recording is cancellation-safe: a Resolved event is written even if the caller is cancelled at the exact moment of resolution, so the log never has a dangling Requested. permpilot-history is versioned independently and ships on its own release cadence. ```kotlin val driver = PermissionHistoryDriverFactory(context).createDriver() // Android needs a Context; iOS needs none val store = SqlDelightPermissionHistoryStore(driver) val controller = HistoryPermissionController(rememberPermissionController(), store, scope) // Drop-in replacement for the wrapped controller. Meanwhile: store.events() // Flow> -- everything store.events(Permission.Camera) // ...or filtered per permission ``` -------------------------------- ### Request permission with PermissionGate in Compose Source: https://github.com/alirezajavan/permpilot/blob/master/README.md Use PermissionGate in a Composable to request a permission and handle its state. The gate automatically shows rationale and settings dialogs. Handle Granted, Limited, and denied states in the content lambda. ```kotlin @Composable fun CameraScreen() { // 1. Initialize the controller val controller = rememberPermissionController() // 2. Wrap your content in a Gate PermissionGate( permission = Permission.Camera, controller = controller ) { state -> // 3. Handle the state (Gate handles Rationale/Settings dialogs automatically) when (state) { PermissionState.Granted -> CameraPreview() is PermissionState.Limited -> CameraPreview(isLimited = true) else -> Box(Modifier.fillMaxSize()) { Text("Camera access required") } } } } ``` -------------------------------- ### Request permission with PermissionController Source: https://github.com/alirezajavan/permpilot/blob/master/README.md Use this snippet to request a permission directly from a PermissionController without Compose UI. The request() call never throws; all platform failure modes are resolved internally and reported as data. requestAll() batches OS-allowed permissions into one dialog and sequences staged permissions automatically. ```kotlin val controller: PermissionController = rememberPermissionController() // hand it to your ViewModel scope.launch { when (val state = controller.request(Permission.Notifications)) { PermissionState.Granted -> scheduleReminder() is PermissionState.Denied -> showRationale() PermissionState.PermanentlyDenied -> controller.openAppSettings() else -> Unit } } ``` -------------------------------- ### Handle special Settings-only permissions with state and openAppSettings Source: https://github.com/alirezajavan/permpilot/blob/master/README.md Use this snippet for Android special permissions that have no request dialog. It observes the permission state and provides a button to open the deep-linked Settings redirect. The redirect carries the correct package: data URI where supported, landing on your app's toggle. DoNotDisturbAccess and NotificationListenerAccess require manifest declarations; otherwise PermPilot reports ConfigurationError(MissingManifestDeclaration). ```kotlin val state by controller.state(Permission.IgnoreBatteryOptimizations).collectAsState() Button(onClick = { controller.openAppSettings(Permission.IgnoreBatteryOptimizations) }) { Text("Open Settings") } ``` -------------------------------- ### Request permission directly with controller.request() Source: https://github.com/alirezajavan/permpilot/blob/master/README.md Use the controller directly for non-UI logic or custom flows. Call request() in a coroutine and check the returned PermissionState to proceed. ```kotlin val scope = rememberCoroutineScope() val controller = rememberPermissionController() Button(onClick = { scope.launch { val result = controller.request(Permission.Camera) if (result == PermissionState.Granted) { // Start camera } } }) { Text("Scan Document") } ``` -------------------------------- ### Customize rationale dialog text with PermissionRationaleDialog Source: https://github.com/alirezajavan/permpilot/blob/master/README.md Customizes the rationale dialog text while keeping the default Material3 dialog. The rationale lambda receives onRequest and onDismiss callbacks to wire to the dialog's buttons. Override title, text, confirmLabel, and dismissLabel as needed. ```kotlin PermissionGate( permission = Permission.Camera, rationale = { onRequest, onDismiss -> PermissionRationaleDialog( permission = Permission.Camera, onConfirm = onRequest, onDismiss = onDismiss, title = "Camera needed", text = "Scanning a document requires the camera.", confirmLabel = "Continue", dismissLabel = "Not now", ) }, ) { state -> /* ... */ } ``` -------------------------------- ### Add PermPilot dependencies in build.gradle.kts Source: https://github.com/alirezajavan/permpilot/blob/master/README.md Add the PermPilot Compose Multiplatform dependency to your commonMain source set. The core module is included transitively; the history module is optional and independently versioned. PermPilot verifies platform manifest declarations at runtime and reports ConfigurationError for missing entries. ```kotlin // build.gradle.kts kotlin { sourceSets { commonMain.dependencies { // Compose Multiplatform UI layer (PermissionGate + default dialogs). // Brings permpilot-core in transitively via api(). implementation("io.github.alirezajavan:permpilot-compose:1.1.0") // Or, without Compose (e.g. shared ViewModels only): // implementation("io.github.alirezajavan:permpilot-core:1.1.0") // Optional: SQLDelight-backed audit log (independently versioned) // implementation("io.github.alirezajavan:permpilot-history:1.1.0") } } } ``` -------------------------------- ### Collect permission events for analytics with controller.events Source: https://github.com/alirezajavan/permpilot/blob/master/README.md Collects permission events from the controller for analytics. Handles RequestResult, StateChanged, and RequestStarted events to log permission results, state changes, and dialog displays. Use this to monitor permission funnels without scattering logs in the UI. ```kotlin val controller = rememberPermissionController() LaunchedEffect(controller) { controller.events.collect { event -> when (event) { is PermissionEvent.RequestResult -> { analytics.logEvent("permission_result", mapOf( "permission" to event.permission.toString(), "result" to event.result.toString() )) } is PermissionEvent.StateChanged -> { println("${event.permission} changed to ${event.newState}") } is PermissionEvent.RequestStarted -> { analytics.logEvent("permission_dialog_shown", mapOf( "permission" to event.permission.toString() )) } } } } ``` -------------------------------- ### PermissionState Source: https://github.com/alirezajavan/permpilot/blob/master/README.md The PermissionState sealed interface represents the possible states a permission can be in, including granted, denied, limited, and error states. ```APIDOC ## PermissionState ### Description Sealed interface representing the state of a permission. ### States - **NotDetermined**: The user has not been asked yet. - **Granted**: The permission has been granted. - **Denied(canRequestAgain: Boolean)**: The permission was denied; canRequestAgain indicates if a new request is possible. - **PermanentlyDenied**: The permission is permanently denied. - **Restricted**: The permission is restricted. - **Limited(reason: LimitedReason)**: The permission is limited (e.g., partial media access). - **ConfigurationError(reason: ConfigurationErrorReason)**: There is a configuration error. ``` -------------------------------- ### Permission Source: https://github.com/alirezajavan/permpilot/blob/master/README.md The Permission sealed interface defines the set of permissions that can be managed. It categorizes permissions into Runtime, Special, and PlatformLimited types. ```APIDOC ## Permission ### Description Sealed interface representing a permission. Subtypes indicate the permission category: Runtime, Special, or PlatformLimited. ### Types - **Runtime**: Permissions that have a real request on at least one platform. - **Special**: Permissions that require a Settings redirect (no dialog). - **PlatformLimited**: Permissions with no request API on either platform. ### Known Runtime Permissions - Camera - LocationWhileInUse - LocationAlways (staged: foreground first, then background) - PhotoLibrary (supports Limited(PartialMediaAccess)) - ... (27 Runtime + 8 Special + LocalNetwork; full list in docs/permission-matrix.md) ``` -------------------------------- ### PermissionState sealed interface and enums Source: https://github.com/alirezajavan/permpilot/blob/master/docs/permission-matrix.md Defines the sealed interface PermissionState and its related enums LimitedReason and ConfigurationErrorReason. Use this to model permission states in PermPilot. Note that Restricted is terminal and ConfigurationError indicates a library-integration mistake, not a user decision. ```kotlin sealed interface PermissionState { data object NotDetermined : PermissionState data object Granted : PermissionState data class Denied(val canRequestAgain: Boolean) : PermissionState data object PermanentlyDenied : PermissionState data object Restricted : PermissionState data class Limited(val reason: LimitedReason) : PermissionState data class ConfigurationError(val reason: ConfigurationErrorReason) : PermissionState } enum class LimitedReason { PartialMediaAccess, SelectedContactsOnly, ApproximateLocationOnly } enum class ConfigurationErrorReason { NoHostActivity, MissingUsageDescription, MissingManifestDeclaration } ``` -------------------------------- ### Health permission data class and enums Source: https://github.com/alirezajavan/permpilot/blob/master/docs/health-design.md Defines the Health permission type with a set of HealthDataType and an access level (default Read). Includes enums for data types (Steps, HeartRate, etc.) and access modes (Read, Write, ReadWrite). ```kotlin data class Health( val dataTypes: Set, val access: HealthAccess = HealthAccess.Read ) : Permission.Runtime enum class HealthDataType { Steps, HeartRate, Sleep, ActiveEnergy, DistanceWalkingRunning, BodyMass, Height, } enum class HealthAccess { Read, Write, ReadWrite } ```