Skip to content

Commit

Permalink
SettingsActivity: Prompt for optional contacts permission on first en…
Browse files Browse the repository at this point in the history
…able

The contacts permission is used to add the contact name to the output
filenames. The permission prompt will only be shown the first time call
recording is enabled. If the user chooses to not allow the permission,
but wants to allow it later, they will have to do so via the system
settings.

Fixes: #78
Fixes: #80

Signed-off-by: Andrew Gunnerson <[email protected]>
  • Loading branch information
chenxiaolong committed Jun 15, 2022
1 parent 3c3441f commit f041a94
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions app/src/main/java/com/chiller3/bcr/Permissions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ object Permissions {
}

val REQUIRED: Array<String> = arrayOf(Manifest.permission.RECORD_AUDIO) + NOTIFICATION
val OPTIONAL: Array<String> = arrayOf(Manifest.permission.READ_CONTACTS)

private fun isGranted(context: Context, permission: String) =
ContextCompat.checkSelfPermission(context, permission) == PackageManager.PERMISSION_GRANTED
Expand Down
6 changes: 4 additions & 2 deletions app/src/main/java/com/chiller3/bcr/SettingsActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ class SettingsActivity : AppCompatActivity() {

private val requestPermissionRequired =
registerForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) { granted ->
if (granted.all { it.value }) {
// Call recording can still be enabled if optional permissions were not granted
if (granted.all { it.key !in Permissions.REQUIRED || it.value }) {
prefCallRecording.isChecked = true
} else {
startActivity(Permissions.getAppInfoIntent(requireContext()))
Expand Down Expand Up @@ -174,7 +175,8 @@ class SettingsActivity : AppCompatActivity() {
prefCallRecording -> if (Permissions.haveRequired(context)) {
return true
} else {
requestPermissionRequired.launch(Permissions.REQUIRED)
// Ask for optional permissions the first time only
requestPermissionRequired.launch(Permissions.REQUIRED + Permissions.OPTIONAL)
}
// This is only reachable if battery optimization is not already inhibited
prefInhibitBatteryOpt -> requestInhibitBatteryOpt.launch(
Expand Down

0 comments on commit f041a94

Please sign in to comment.