Skip to content
This repository has been archived by the owner on Jul 2, 2021. It is now read-only.

Commit

Permalink
Force isPermanentlyDenied flag to false for SDK < 23 (#219)
Browse files Browse the repository at this point in the history
* Shortcircuit permanently-denied check for SDK < 23

* Fix test
  • Loading branch information
Serchinastico authored and pedrovgs committed Sep 17, 2019
1 parent bdf3962 commit 9c9fa35
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import android.app.Activity;
import android.content.Context;
import android.os.Build;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.app.ActivityCompat;
Expand Down Expand Up @@ -58,4 +59,13 @@ boolean shouldShowRequestPermissionRationale(@Nullable Activity activity,

return ActivityCompat.shouldShowRequestPermissionRationale(activity, permission);
}

boolean isPermissionPermanentlyDenied(@Nullable Activity activity,
@NonNull String permission) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
return false;
}

return !shouldShowRequestPermissionRationale(activity, permission);
}
}
2 changes: 1 addition & 1 deletion dexter/src/main/java/com/karumi/dexter/DexterInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ private void updatePermissionsAsGranted(Collection<String> permissions) {
private void updatePermissionsAsDenied(Collection<String> permissions) {
for (String permission : permissions) {
PermissionDeniedResponse response = PermissionDeniedResponse.from(permission,
!androidPermissionService.shouldShowRequestPermissionRationale(activity, permission));
androidPermissionService.isPermissionPermanentlyDenied(activity, permission));
multiplePermissionsReport.addDeniedPermissionResponse(response);
}
onPermissionsChecked(permissions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public void onCheckPermissionMoreThanOnceThenThrowException() {

@Test public void onPermissionPermanentlyDeniedThenNotifiesListener() {
givenPermissionIsAlreadyDenied(ANY_PERMISSION);
givenShouldNotShowRationaleForPermission(ANY_PERMISSION);
givenPermissionIsPermanentlyDenied(ANY_PERMISSION);

whenCheckPermission(permissionListener, ANY_PERMISSION);
dexter.onPermissionRequestDenied(Collections.singletonList(ANY_PERMISSION));
Expand Down Expand Up @@ -168,6 +168,13 @@ private void givenShouldNotShowRationaleForPermission(String permission) {
).thenReturn(false);
}

private void givenPermissionIsPermanentlyDenied(String permission) {
when(androidPermissionService.isPermissionPermanentlyDenied(
any(Activity.class),
eq(permission))
).thenReturn(true);
}

private PermissionListener givenARetryCheckPermissionOnDeniedPermissionListener(
PermissionListener permissionListener) {
return new RetryCheckPermissionOnDeniedPermissionListener(permissionListener,
Expand Down

0 comments on commit 9c9fa35

Please sign in to comment.