From 2748a34c25773cf67f5fdbc940f2f314b6365c21 Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Thu, 24 Feb 2022 10:34:30 +0100 Subject: [PATCH] Prevent crash if exception occurs in native contact editor --- .../linphone/contact/NativeContactEditor.kt | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/org/linphone/contact/NativeContactEditor.kt b/app/src/main/java/org/linphone/contact/NativeContactEditor.kt index 630cb9703..963a86016 100644 --- a/app/src/main/java/org/linphone/contact/NativeContactEditor.kt +++ b/app/src/main/java/org/linphone/contact/NativeContactEditor.kt @@ -50,19 +50,23 @@ class NativeContactEditor(val contact: NativeContact) { val uri = result.uri Log.i("[Native Contact Editor] Contact creation result is $uri") if (uri != null) { - val cursor = contentResolver.query( - uri, - arrayOf(RawContacts.CONTACT_ID), - null, - null, - null - ) - if (cursor != null) { - cursor.moveToNext() - val contactId: Long = cursor.getLong(0) - Log.i("[Native Contact Editor] New contact id is $contactId") - cursor.close() - return contactId + try { + val cursor = contentResolver.query( + uri, + arrayOf(RawContacts.CONTACT_ID), + null, + null, + null + ) + if (cursor != null) { + cursor.moveToNext() + val contactId: Long = cursor.getLong(0) + Log.i("[Native Contact Editor] New contact id is $contactId") + cursor.close() + return contactId + } + } catch (e: Exception) { + Log.e("[Native Contact Editor] Failed to get cursor: $e") } } }