From 8632ba85ee1ed080d7baa70050d460807c8edfcf Mon Sep 17 00:00:00 2001 From: Sven Date: Sat, 1 Jun 2024 21:25:58 +0200 Subject: [PATCH] fix: storage permission request for non-conforming devices (#726) * fix: storage permission request for non-conforming devices * fix: catch more specific exception * chore: add toast message to indicate missing persistent permissions * chore: correct newly introduced translaction string * Change error toast message --------- Co-authored-by: AntsyLich <59261191+AntsyLich@users.noreply.github.com> --- .../more/settings/screen/SettingsDataScreen.kt | 12 +++++++++++- i18n/src/commonMain/resources/MR/base/strings.xml | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsDataScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsDataScreen.kt index 91de2993f..ecfd2ec75 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsDataScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsDataScreen.kt @@ -111,7 +111,17 @@ object SettingsDataScreen : SearchableSettings { val flags = Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION - context.contentResolver.takePersistableUriPermission(uri, flags) + // For some reason InkBook devices do not implement the SAF properly. Persistable URI grants do not + // work. However, simply retrieving the URI and using it works fine for these devices. Access is not + // revoked after the app is closed or the device is restarted. + // This also holds for some Samsung devices. Thus, we simply execute inside of a try-catch block and + // ignore the exception if it is thrown. + try { + context.contentResolver.takePersistableUriPermission(uri, flags) + } catch (e: SecurityException) { + logcat(LogPriority.ERROR, e) + context.toast(MR.strings.file_picker_uri_permission_unsupported) + } UniFile.fromUri(context, uri)?.let { storageDirPref.set(it.uri.toString()) diff --git a/i18n/src/commonMain/resources/MR/base/strings.xml b/i18n/src/commonMain/resources/MR/base/strings.xml index bd30e2900..b0a397b1d 100644 --- a/i18n/src/commonMain/resources/MR/base/strings.xml +++ b/i18n/src/commonMain/resources/MR/base/strings.xml @@ -869,6 +869,7 @@ Select cover image Select backup file No file picker app found + Failed to acquire persistent folder access. The app may behave unexpectedly. No file selected