Skip to content

Commit

Permalink
Check in both manifest and groups
Browse files Browse the repository at this point in the history
  • Loading branch information
zoontek committed Nov 28, 2024
1 parent ac0eb65 commit 8766ae2
Showing 1 changed file with 12 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,29 +39,25 @@ object RNPermissionsModuleImpl {
.removePrefix("android.permission.")
.removePrefix("com.android.voicemail.permission.")

try {
val availableInManifest = runCatching {
Manifest.permission::class.java.getField(fieldName)
return true
} catch (ignored: NoSuchFieldException) {
val manager = context.packageManager
}.isSuccess

val groups = manager.getAllPermissionGroups(0).toMutableList().apply {
add(null) // Add ungrouped permissions
}
val manager = context.packageManager

for (group in groups) {
try {
val permissions = manager.queryPermissionsByGroup(group?.name, 0)
val groups = manager.getAllPermissionGroups(0).toMutableList().apply {
add(null) // Add ungrouped permissions
}

if (permissions.any { it?.name == permission }) {
return true
}
} catch (ignored: PackageManager.NameNotFoundException) {
}
val availableInGroups = groups.any { group ->
runCatching {
manager.queryPermissionsByGroup(group?.name, 0)
}.getOrDefault(emptyList()).any {
it?.name == permission
}
}

return false
return availableInManifest || availableInGroups
}

fun openSettings(reactContext: ReactApplicationContext, type: String?, promise: Promise) {
Expand Down

0 comments on commit 8766ae2

Please sign in to comment.