diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2020-09-16 16:08:15 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2020-09-16 18:01:06 +0200 |
commit | 746ab00794fc1d3e9fd053418b9aeb0ddb23df8d (patch) | |
tree | 90229757529c9e8c29e5d5bcca01db84c2554539 /ui/src/main/java/com/wireguard/android | |
parent | b877593d552e1d57038f4ab4708d0f00cb547c6b (diff) |
ZipExporterPreference: don't ask for storage permissions on newer android
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'ui/src/main/java/com/wireguard/android')
-rw-r--r-- | ui/src/main/java/com/wireguard/android/preference/ZipExporterPreference.kt | 13 | ||||
-rw-r--r-- | ui/src/main/java/com/wireguard/android/util/DownloadsFileSaver.kt | 2 |
2 files changed, 11 insertions, 4 deletions
diff --git a/ui/src/main/java/com/wireguard/android/preference/ZipExporterPreference.kt b/ui/src/main/java/com/wireguard/android/preference/ZipExporterPreference.kt index d943c89f..623e272f 100644 --- a/ui/src/main/java/com/wireguard/android/preference/ZipExporterPreference.kt +++ b/ui/src/main/java/com/wireguard/android/preference/ZipExporterPreference.kt @@ -82,11 +82,16 @@ class ZipExporterPreference(context: Context, attrs: AttributeSet?) : Preference when (it) { // When we have successful authentication, or when there is no biometric hardware available. is BiometricAuthenticator.Result.Success, is BiometricAuthenticator.Result.HardwareUnavailableOrDisabled -> { - activity.ensurePermissions(arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { _, grantResults -> - if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) { - isEnabled = false - exportZip() + if (DownloadsFileSaver.needsWriteExternalStoragePermission) { + activity.ensurePermissions(arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { _, grantResults -> + if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) { + isEnabled = false + exportZip() + } } + } else { + isEnabled = false + exportZip() } } is BiometricAuthenticator.Result.Failure -> { diff --git a/ui/src/main/java/com/wireguard/android/util/DownloadsFileSaver.kt b/ui/src/main/java/com/wireguard/android/util/DownloadsFileSaver.kt index a0f0e1fb..59cd526b 100644 --- a/ui/src/main/java/com/wireguard/android/util/DownloadsFileSaver.kt +++ b/ui/src/main/java/com/wireguard/android/util/DownloadsFileSaver.kt @@ -18,6 +18,8 @@ import java.io.IOException import java.io.OutputStream object DownloadsFileSaver { + val needsWriteExternalStoragePermission = Build.VERSION.SDK_INT < Build.VERSION_CODES.Q + @Throws(Exception::class) fun save(context: Context, name: String, mimeType: String?, overwriteExisting: Boolean) = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { val contentResolver = context.contentResolver |