Avoid crash in encryptToUri has no write access to URI
This commit is contained in:
@ -710,10 +710,15 @@ object Utils {
|
|||||||
|
|
||||||
fun encryptToUri(ctx: Context, uri: Uri, content: ByteArray, password: String): Boolean {
|
fun encryptToUri(ctx: Context, uri: Uri, content: ByteArray, password: String): Boolean {
|
||||||
val obj = encrypt(content, password.toCharArray())
|
val obj = encrypt(content, password.toCharArray())
|
||||||
val stream = ctx.contentResolver.openOutputStream(uri) as FileOutputStream
|
|
||||||
try {
|
try {
|
||||||
ObjectOutputStream(stream).use {
|
val stream = ctx.contentResolver.openOutputStream(uri)
|
||||||
it.writeObject(obj)
|
if (stream != null)
|
||||||
|
ObjectOutputStream(stream).use {
|
||||||
|
it.writeObject(obj)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Log.w(TAG, "encryptToUri: could not open output stream")
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.w(TAG, "encryptToUri failed: $e")
|
Log.w(TAG, "encryptToUri failed: $e")
|
||||||
|
|||||||
Reference in New Issue
Block a user