File tree Expand file tree Collapse file tree 1 file changed +12
-16
lines changed
android/src/main/java/com/zoontek/rnpermissions Expand file tree Collapse file tree 1 file changed +12
-16
lines changed Original file line number Diff line number Diff 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 ) {
You can’t perform that action at this time.
0 commit comments