Fix Permission grantResults out of bounds (#120)

(ArrayIndexOutOfBoundsException)
This commit is contained in:
Marc Rousavy 2021-04-20 10:21:59 +02:00 committed by GitHub
parent 53281dfb57
commit 11d6388a06
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -286,11 +286,10 @@ class CameraViewModule(reactContext: ReactApplicationContext) : ReactContextBase
fun requestCameraPermission(promise: Promise) { fun requestCameraPermission(promise: Promise) {
val activity = reactApplicationContext.currentActivity val activity = reactApplicationContext.currentActivity
if (activity is PermissionAwareActivity) { if (activity is PermissionAwareActivity) {
val currentRequestCode = RequestCode val currentRequestCode = RequestCode++
RequestCode++
val listener = PermissionListener { requestCode: Int, _: Array<String>, grantResults: IntArray -> val listener = PermissionListener { requestCode: Int, _: Array<String>, grantResults: IntArray ->
if (requestCode == currentRequestCode) { if (requestCode == currentRequestCode) {
val permissionStatus = grantResults[0] val permissionStatus = if (grantResults.size > 0) grantResults[0] else PackageManager.PERMISSION_DENIED
promise.resolve(parsePermissionStatus(permissionStatus)) promise.resolve(parsePermissionStatus(permissionStatus))
return@PermissionListener true return@PermissionListener true
} }
@ -306,11 +305,10 @@ class CameraViewModule(reactContext: ReactApplicationContext) : ReactContextBase
fun requestMicrophonePermission(promise: Promise) { fun requestMicrophonePermission(promise: Promise) {
val activity = reactApplicationContext.currentActivity val activity = reactApplicationContext.currentActivity
if (activity is PermissionAwareActivity) { if (activity is PermissionAwareActivity) {
val currentRequestCode = RequestCode val currentRequestCode = RequestCode++
RequestCode++
val listener = PermissionListener { requestCode: Int, _: Array<String>, grantResults: IntArray -> val listener = PermissionListener { requestCode: Int, _: Array<String>, grantResults: IntArray ->
if (requestCode == currentRequestCode) { if (requestCode == currentRequestCode) {
val permissionStatus = grantResults[0] val permissionStatus = if (grantResults.size > 0) grantResults[0] else PackageManager.PERMISSION_DENIED
promise.resolve(parsePermissionStatus(permissionStatus)) promise.resolve(parsePermissionStatus(permissionStatus))
return@PermissionListener true return@PermissionListener true
} }