summaryrefslogtreecommitdiffhomepage
path: root/ui/src/main/java/com/wireguard/android/preference
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2020-09-16 17:56:07 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2020-09-17 14:50:37 +0200
commita9ec8285062636fc7be68fee123bb5899e639fdd (patch)
treef11be67e983779e74eb0f5431b2bcda0e5c0d480 /ui/src/main/java/com/wireguard/android/preference
parenteebeece8565f985d1a4039d7430f650aa91d87e1 (diff)
DownloadsFileSaver: encapsulate permission checks
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'ui/src/main/java/com/wireguard/android/preference')
-rw-r--r--ui/src/main/java/com/wireguard/android/preference/ZipExporterPreference.kt23
1 files changed, 9 insertions, 14 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 623e272f..aaea7703 100644
--- a/ui/src/main/java/com/wireguard/android/preference/ZipExporterPreference.kt
+++ b/ui/src/main/java/com/wireguard/android/preference/ZipExporterPreference.kt
@@ -4,9 +4,7 @@
*/
package com.wireguard.android.preference
-import android.Manifest
import android.content.Context
-import android.content.pm.PackageManager
import android.util.AttributeSet
import android.util.Log
import androidx.preference.Preference
@@ -43,7 +41,13 @@ class ZipExporterPreference(context: Context, attrs: AttributeSet?) : Preference
if (configs.isEmpty()) {
throw IllegalArgumentException(context.getString(R.string.no_tunnels_error))
}
- val outputFile = DownloadsFileSaver.save(context, "wireguard-export.zip", "application/zip", true)
+ val outputFile = DownloadsFileSaver.save(activity, "wireguard-export.zip", "application/zip", true)
+ if (outputFile == null) {
+ withContext(Dispatchers.Main.immediate) {
+ isEnabled = true
+ }
+ return@withContext null
+ }
try {
ZipOutputStream(outputFile.outputStream).use { zip ->
for (i in configs.indices) {
@@ -82,17 +86,8 @@ 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 -> {
- 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()
- }
+ isEnabled = false
+ exportZip()
}
is BiometricAuthenticator.Result.Failure -> {
Snackbar.make(