Skip to content

Commit

Permalink
Add NotGranted item to PermissionState
Browse files Browse the repository at this point in the history
This fixes the issue with [deny and don't ask again] returning an incorrect state. Unfortunately, it's not possible on Android to determine the difference. One has to keep track of whether a permission has been requested in the app already, so that's up to consumers.
  • Loading branch information
jacobras committed Feb 29, 2024
1 parent 7a9df21 commit c528d79
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ class PermissionsControllerImpl(
val resolverFragment: ResolverFragment = getOrCreateResolverFragment(fragmentManager)

val isAllRequestRationale: Boolean = permissions.all {
!resolverFragment.shouldShowRequestPermissionRationale(it)
resolverFragment.shouldShowRequestPermissionRationale(it)
}
return if (isAllRequestRationale) PermissionState.NotDetermined
else PermissionState.Denied
return if (isAllRequestRationale) PermissionState.Denied
else PermissionState.NotGranted
}

override fun openAppSettings() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,27 @@
package dev.icerock.moko.permissions

enum class PermissionState {

/**
* Starting state for each permission.
*/
NotDetermined,

/**
* Android-only. This could mean [NotDetermined] or [DeniedAlways], but the OS doesn't
* expose which of the two it is in all scenarios.
*/
NotGranted,

Granted,

/**
* Android-only.
*/
Denied,

/**
* On Android only applicable to Push Notifications.
*/
DeniedAlways
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ expect interface PermissionsController {

/**
* Returns current state of permission. Can be suspended because on
* android detection of Denied/NotDetermined case require binded FragmentManager.
* Android detection of `Denied`/`NotDetermined` requires a bound FragmentManager.
*
* @param permission state of what permission we want
*
* @return current state. On Android can't be DeniedAlways (except push notifications).
* On iOS can't be Denied.
* @return current state. On Android can't be `DeniedAlways` (except push notifications).
* On iOS can't be `Denied`.
* @see PermissionState for a detailed description.
*/
suspend fun getPermissionState(permission: Permission): PermissionState

Expand Down

0 comments on commit c528d79

Please sign in to comment.