ZipExporterPreference: don't ask for storage permissions on newer android
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
parent
b877593d55
commit
746ab00794
@ -82,11 +82,16 @@ class ZipExporterPreference(context: Context, attrs: AttributeSet?) : Preference
|
|||||||
when (it) {
|
when (it) {
|
||||||
// When we have successful authentication, or when there is no biometric hardware available.
|
// When we have successful authentication, or when there is no biometric hardware available.
|
||||||
is BiometricAuthenticator.Result.Success, is BiometricAuthenticator.Result.HardwareUnavailableOrDisabled -> {
|
is BiometricAuthenticator.Result.Success, is BiometricAuthenticator.Result.HardwareUnavailableOrDisabled -> {
|
||||||
activity.ensurePermissions(arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { _, grantResults ->
|
if (DownloadsFileSaver.needsWriteExternalStoragePermission) {
|
||||||
if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
activity.ensurePermissions(arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { _, grantResults ->
|
||||||
isEnabled = false
|
if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||||
exportZip()
|
isEnabled = false
|
||||||
|
exportZip()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
isEnabled = false
|
||||||
|
exportZip()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
is BiometricAuthenticator.Result.Failure -> {
|
is BiometricAuthenticator.Result.Failure -> {
|
||||||
|
@ -18,6 +18,8 @@ import java.io.IOException
|
|||||||
import java.io.OutputStream
|
import java.io.OutputStream
|
||||||
|
|
||||||
object DownloadsFileSaver {
|
object DownloadsFileSaver {
|
||||||
|
val needsWriteExternalStoragePermission = Build.VERSION.SDK_INT < Build.VERSION_CODES.Q
|
||||||
|
|
||||||
@Throws(Exception::class)
|
@Throws(Exception::class)
|
||||||
fun save(context: Context, name: String, mimeType: String?, overwriteExisting: Boolean) = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
fun save(context: Context, name: String, mimeType: String?, overwriteExisting: Boolean) = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||||
val contentResolver = context.contentResolver
|
val contentResolver = context.contentResolver
|
||||||
|
Loading…
Reference in New Issue
Block a user