-
Notifications
You must be signed in to change notification settings - Fork 606
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Permissions] Permissions enhancements #1793
base: main
Are you sure you want to change the base?
Changes from 3 commits
434fd99
dc67226
5e719ed
a12ee22
a0b6b00
9cfca94
b3cee51
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,26 +86,41 @@ internal class MutablePermissionState( | |
private val activity: Activity | ||
) : PermissionState { | ||
|
||
override var status: PermissionStatus by mutableStateOf(getPermissionStatus()) | ||
override var status: PermissionStatus by mutableStateOf(getPermissionStatus(false)) | ||
|
||
override fun launchPermissionRequest() { | ||
launcher?.launch( | ||
permission | ||
) ?: throw IllegalStateException("ActivityResultLauncher cannot be null") | ||
} | ||
|
||
override fun openAppSettings() { | ||
activity.openAppSettings(permission) | ||
} | ||
|
||
internal var launcher: ActivityResultLauncher<String>? = null | ||
|
||
internal fun refreshPermissionStatus() { | ||
status = getPermissionStatus() | ||
status = getPermissionStatus(isPermissionPostRequest = true) | ||
} | ||
|
||
private fun getPermissionStatus(): PermissionStatus { | ||
private fun getPermissionStatus(isPermissionPostRequest: Boolean): PermissionStatus { | ||
val hasPermission = context.checkPermission(permission) | ||
return if (hasPermission) { | ||
PermissionStatus.Granted | ||
} else { | ||
PermissionStatus.Denied(activity.shouldShowRationale(permission)) | ||
val shouldShowRationale = activity.shouldShowRationale(permission) | ||
when { | ||
isPermissionPostRequest -> when { | ||
shouldShowRationale -> PermissionStatus.NotGranted.Denied | ||
else -> PermissionStatus.NotGranted.PermanentlyDenied | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's a case here where it's possible to have requested the permission and If a permission is requested for the first time, and the user uses the back button to exit the permission dialog without selecting any of the options, the permission won't be permanently denied. If the permission is requested again, then the dialog will be shown again normally. Also, since the user did not explicitly deny the permission, |
||
} | ||
|
||
else -> when { | ||
shouldShowRationale -> PermissionStatus.NotGranted.Denied | ||
else -> PermissionStatus.NotGranted.NotRequested | ||
} | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
refreshPermissionStatus()
is also called fromPermissionLifecycleCheckerEffect
, so right now the initial lifecycle event refreshing the status when the permission isn't granted will result in a status ofPermanentlyDenied
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can track
isPermissionPostRequest
as its own property and set it separately fromrefreshPermissionStatus
, since once that is set totrue
there shouldn't be any scenario that would make it go back tofalse
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any ordering guarantees between
rememberLauncherForActivityResult
andPermissionLifecycleCheckerEffect
?