Permalink
Browse files

Requesting permission results into ArrayIndexOutOfBoundsException

Summary:
Reported in Issue #15928

Fixing bug when permission showing dialog and user go to home and re-open minimized app.

1. Ask for permission
2. Minimize app (Press HomeButton)
3. Open app again via shortcut

 [ANDROID] [BUGFIX] [PermissionsModule.java] - Fixed bug when asked for permission Cause: java.lang.ArrayIndexOutOfBoundsException · length=0; index=0
Closes #16507

Differential Revision: D6133708

Pulled By: shergin

fbshipit-source-id: 9c05d1d5d16fedf718ad5113df69a4df3af62013
  • Loading branch information...
RafaelMagalhaesN authored and facebook-github-bot committed Oct 24, 2017
1 parent f3a3289 commit ce967c6fbe9ff7337cc95bdd93a0c08a0688769a
@@ -15,7 +15,6 @@
import android.os.Build;
import android.os.Process;
import android.util.SparseArray;
import com.facebook.react.bridge.Callback;
import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext;
@@ -27,7 +26,6 @@
import com.facebook.react.module.annotations.ReactModule;
import com.facebook.react.modules.core.PermissionAwareActivity;
import com.facebook.react.modules.core.PermissionListener;
import java.util.ArrayList;
/**
@@ -116,7 +114,7 @@ public void requestPermission(final String permission, final Promise promise) {
@Override
public void invoke(Object... args) {
int[] results = (int[]) args[0];
if (results[0] == PackageManager.PERMISSION_GRANTED) {
if (results.length > 0 && results[0] == PackageManager.PERMISSION_GRANTED) {
promise.resolve(GRANTED);
} else {
PermissionAwareActivity activity = (PermissionAwareActivity) args[1];
@@ -175,7 +173,7 @@ public void invoke(Object... args) {
PermissionAwareActivity activity = (PermissionAwareActivity) args[1];
for (int j = 0; j < permissionsToCheck.size(); j++) {
String permission = permissionsToCheck.get(j);
if (results[j] == PackageManager.PERMISSION_GRANTED) {
if (results.length > 0 && results[j] == PackageManager.PERMISSION_GRANTED) {
grantedPermissions.putString(permission, GRANTED);
} else {
if (activity.shouldShowRequestPermissionRationale(permission)) {

0 comments on commit ce967c6

Please sign in to comment.