Skip to content

Commit 8766ae2

Browse files
committed
Check in both manifest and groups
1 parent ac0eb65 commit 8766ae2

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

android/src/main/java/com/zoontek/rnpermissions/RNPermissionsModuleImpl.kt

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,29 +39,25 @@ object RNPermissionsModuleImpl {
3939
.removePrefix("android.permission.")
4040
.removePrefix("com.android.voicemail.permission.")
4141

42-
try {
42+
val availableInManifest = runCatching {
4343
Manifest.permission::class.java.getField(fieldName)
44-
return true
45-
} catch (ignored: NoSuchFieldException) {
46-
val manager = context.packageManager
44+
}.isSuccess
4745

48-
val groups = manager.getAllPermissionGroups(0).toMutableList().apply {
49-
add(null) // Add ungrouped permissions
50-
}
46+
val manager = context.packageManager
5147

52-
for (group in groups) {
53-
try {
54-
val permissions = manager.queryPermissionsByGroup(group?.name, 0)
48+
val groups = manager.getAllPermissionGroups(0).toMutableList().apply {
49+
add(null) // Add ungrouped permissions
50+
}
5551

56-
if (permissions.any { it?.name == permission }) {
57-
return true
58-
}
59-
} catch (ignored: PackageManager.NameNotFoundException) {
60-
}
52+
val availableInGroups = groups.any { group ->
53+
runCatching {
54+
manager.queryPermissionsByGroup(group?.name, 0)
55+
}.getOrDefault(emptyList()).any {
56+
it?.name == permission
6157
}
6258
}
6359

64-
return false
60+
return availableInManifest || availableInGroups
6561
}
6662

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

0 commit comments

Comments
 (0)