From b81af1114d7ad614fc689df423f7a14b943108cd Mon Sep 17 00:00:00 2001
From: Adrien Beraud <adrien.beraud@savoirfairelinux.com>
Date: Tue, 18 Jun 2024 11:19:05 -0400
Subject: [PATCH] placeCall: handle all exceptions in the Telecom API

GitLab: #1689
Change-Id: I876a9bff91f5ddce3de51d7807392170e7db3bf1
---
 .../app/src/main/java/cx/ring/services/CallServiceImpl.kt    | 5 ++++-
 .../src/main/kotlin/net/jami/services/CallService.kt         | 4 +++-
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/jami-android/app/src/main/java/cx/ring/services/CallServiceImpl.kt b/jami-android/app/src/main/java/cx/ring/services/CallServiceImpl.kt
index 95e5e517c..76e292c47 100644
--- a/jami-android/app/src/main/java/cx/ring/services/CallServiceImpl.kt
+++ b/jami-android/app/src/main/java/cx/ring/services/CallServiceImpl.kt
@@ -110,7 +110,10 @@ class CallServiceImpl(val mContext: Context, executor: ScheduledExecutorService,
                     telecomService.placeCall(callUri, params)
                     return subject
                 } catch (e: SecurityException) {
-                    pendingCallRequests.remove(key)
+                    pendingCallRequests.remove(key)?.onSuccess(CALL_ALLOWED_VAL)
+                    Log.e(TAG, "Can't use the Telecom API to place call", e)
+                } catch (e: Exception) {
+                    pendingCallRequests.remove(key)?.onSuccess(CALL_ALLOWED_VAL)
                     Log.e(TAG, "Can't use the Telecom API to place call", e)
                 }
             }
diff --git a/jami-android/libjamiclient/src/main/kotlin/net/jami/services/CallService.kt b/jami-android/libjamiclient/src/main/kotlin/net/jami/services/CallService.kt
index 072154183..50662b9fb 100644
--- a/jami-android/libjamiclient/src/main/kotlin/net/jami/services/CallService.kt
+++ b/jami-android/libjamiclient/src/main/kotlin/net/jami/services/CallService.kt
@@ -210,6 +210,7 @@ abstract class CallService(
 
     fun placeCallIfAllowed(account: String, conversationUri: Uri?, number: Uri, hasVideo: Boolean): Single<Call> =
         requestPlaceCall(account, conversationUri, number.rawUriString, hasVideo)
+            .onErrorReturnItem(CALL_ALLOWED_VAL)
             .flatMap { result ->
                 if (!result.allowed)
                     Single.error(SecurityException())
@@ -767,7 +768,8 @@ abstract class CallService(
         const val MEDIA_TYPE_AUDIO = "MEDIA_TYPE_AUDIO"
         const val MEDIA_TYPE_VIDEO = "MEDIA_TYPE_VIDEO"
 
-        val CALL_ALLOWED = Single.just(SystemCall(true))
+        val CALL_ALLOWED_VAL = SystemCall(true)
+        val CALL_ALLOWED = Single.just(CALL_ALLOWED_VAL)
         val CALL_DISALLOWED = Single.just(SystemCall(false))
     }
 }
\ No newline at end of file
-- 
GitLab