Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preferences: Ignore releasePersistableUriPermission exceptions #273

Merged
merged 1 commit into from
Mar 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions app/src/main/java/com/chiller3/bcr/Preferences.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.chiller3.bcr
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.util.Log
import androidx.core.content.edit
import androidx.preference.PreferenceManager
import com.chiller3.bcr.format.Format
Expand All @@ -11,6 +12,8 @@ import java.io.File

class Preferences(private val context: Context) {
companion object {
private val TAG = Preferences::class.java.simpleName

const val PREF_CALL_RECORDING = "call_recording"
const val PREF_INITIALLY_PAUSED = "initially_paused"
const val PREF_OUTPUT_DIR = "output_dir"
Expand Down Expand Up @@ -113,11 +116,17 @@ class Preferences(private val context: Context) {
// Release persisted permissions on the old directory only after the new URI is set to
// guarantee atomicity
if (oldUri != null) {
context.contentResolver.releasePersistableUriPermission(
oldUri,
Intent.FLAG_GRANT_READ_URI_PERMISSION
or Intent.FLAG_GRANT_WRITE_URI_PERMISSION
)
// It's not documented, but this can throw an exception when trying to release a
// previously persisted URI that's associated with an app that's no longer installed
try {
context.contentResolver.releasePersistableUriPermission(
oldUri,
Intent.FLAG_GRANT_READ_URI_PERMISSION
or Intent.FLAG_GRANT_WRITE_URI_PERMISSION
)
} catch (e: Exception) {
Log.w(TAG, "Error when releasing persisted URI permission for: $oldUri", e)
}
}

// Clear all alert notifications. Having them disappear is a better user experience than
Expand Down