Skip to content

Commit f041a94

Browse files
committed
SettingsActivity: Prompt for optional contacts permission on first enable
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]>
1 parent 3c3441f commit f041a94

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

app/src/main/java/com/chiller3/bcr/Permissions.kt

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ object Permissions {
2020
}
2121

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

2425
private fun isGranted(context: Context, permission: String) =
2526
ContextCompat.checkSelfPermission(context, permission) == PackageManager.PERMISSION_GRANTED

app/src/main/java/com/chiller3/bcr/SettingsActivity.kt

+4-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ class SettingsActivity : AppCompatActivity() {
4242

4343
private val requestPermissionRequired =
4444
registerForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) { granted ->
45-
if (granted.all { it.value }) {
45+
// Call recording can still be enabled if optional permissions were not granted
46+
if (granted.all { it.key !in Permissions.REQUIRED || it.value }) {
4647
prefCallRecording.isChecked = true
4748
} else {
4849
startActivity(Permissions.getAppInfoIntent(requireContext()))
@@ -174,7 +175,8 @@ class SettingsActivity : AppCompatActivity() {
174175
prefCallRecording -> if (Permissions.haveRequired(context)) {
175176
return true
176177
} else {
177-
requestPermissionRequired.launch(Permissions.REQUIRED)
178+
// Ask for optional permissions the first time only
179+
requestPermissionRequired.launch(Permissions.REQUIRED + Permissions.OPTIONAL)
178180
}
179181
// This is only reachable if battery optimization is not already inhibited
180182
prefInhibitBatteryOpt -> requestInhibitBatteryOpt.launch(

0 commit comments

Comments
 (0)