Skip to content
This repository was archived by the owner on Sep 3, 2023. It is now read-only.

Commit

Permalink
ShouldShowRationale should recheck granted status. Resolves #16.
Browse files Browse the repository at this point in the history
  • Loading branch information
afollestad committed Feb 7, 2020
1 parent 99c0e77 commit d7fa171
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
package com.afollestad.assent.rationale

import android.app.Activity
import android.content.pm.PackageManager.PERMISSION_GRANTED
import androidx.annotation.CheckResult
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import com.afollestad.assent.Permission
import com.afollestad.assent.Prefs

Expand Down Expand Up @@ -51,9 +53,16 @@ internal class RealShouldShowRationale(
override fun isPermanentlyDenied(permission: Permission): Boolean {
val showRationaleWasTrue: Boolean = prefs[permission.key()] ?: false
// Using point 2 in the kdoc here...
return showRationaleWasTrue && !check(permission)
return showRationaleWasTrue && !permission.isGranted() && !check(permission)
}

/**
* Provides a sanity check to avoid falsely returning true in [isPermanentlyDenied]. See
* [https://github.com/afollestad/assent/issues/16].
*/
private fun Permission.isGranted(): Boolean =
ContextCompat.checkSelfPermission(activity, value) == PERMISSION_GRANTED

private fun Permission.key() = "${KEY_SHOULD_SHOW_RATIONALE}_$value"
}

Expand Down

0 comments on commit d7fa171

Please sign in to comment.