From 1dfe0591ef067475d99fac11c20d64d4a7cf46f6 Mon Sep 17 00:00:00 2001 From: Juha Heinanen Date: Fri, 25 Mar 2022 11:16:58 +0200 Subject: [PATCH] Fixed crash in older Android versions if restore file does not exist Correctly show backup file name also in older Android versions --- app/src/main/kotlin/com/tutpro/baresip/Utils.kt | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/app/src/main/kotlin/com/tutpro/baresip/Utils.kt b/app/src/main/kotlin/com/tutpro/baresip/Utils.kt index 1879397f..c64b9689 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/Utils.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/Utils.kt @@ -574,7 +574,10 @@ object Utils { name = cursor.getString(index) cursor.close() } - return name + return if (name == "") + "$uri".substringAfterLast("/") + else + name } fun saveBitmap(bitmap: Bitmap, file: File): Boolean { @@ -690,7 +693,13 @@ object Utils { fun decryptFromUri(ctx: Context, uri: Uri, password: String): ByteArray? { var plainData: ByteArray? = null - var stream = ctx.contentResolver.openInputStream(uri) as FileInputStream + var stream: FileInputStream + try { + stream = ctx.contentResolver.openInputStream(uri) as FileInputStream + } catch(e: Exception) { + Log.w(TAG, "decryptFromUri could not open stream: $e") + return null + } try { ObjectInputStream(stream).use { val content = it.readObject() as ByteArray