From 493703fad48247fdbf857fb25833a4c44c6d54bf Mon Sep 17 00:00:00 2001 From: Juha Heinanen Date: Tue, 21 Apr 2026 08:34:02 +0300 Subject: [PATCH] Avoid crash in encryptToUri has no write access to URI --- app/src/main/kotlin/com/tutpro/baresip/Utils.kt | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/src/main/kotlin/com/tutpro/baresip/Utils.kt b/app/src/main/kotlin/com/tutpro/baresip/Utils.kt index 173d93e6..346c6ac3 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/Utils.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/Utils.kt @@ -710,10 +710,15 @@ object Utils { fun encryptToUri(ctx: Context, uri: Uri, content: ByteArray, password: String): Boolean { val obj = encrypt(content, password.toCharArray()) - val stream = ctx.contentResolver.openOutputStream(uri) as FileOutputStream try { - ObjectOutputStream(stream).use { - it.writeObject(obj) + val stream = ctx.contentResolver.openOutputStream(uri) + if (stream != null) + ObjectOutputStream(stream).use { + it.writeObject(obj) + } + else { + Log.w(TAG, "encryptToUri: could not open output stream") + return false } } catch (e: Exception) { Log.w(TAG, "encryptToUri failed: $e")