From 31fa509d34783616714171ea2b8a6835a1e47c41 Mon Sep 17 00:00:00 2001 From: Juha Heinanen Date: Thu, 21 Jan 2021 15:37:33 +0200 Subject: [PATCH] Fixed handling of call action when baresip app was not running --- app/src/main/cpp/baresip.c | 3 +++ .../com/tutpro/baresip/BaresipService.kt | 13 +++++++++++ .../kotlin/com/tutpro/baresip/MainActivity.kt | 22 ++++++++++++++++++- 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/app/src/main/cpp/baresip.c b/app/src/main/cpp/baresip.c index 8319c88e..757f2ffd 100644 --- a/app/src/main/cpp/baresip.c +++ b/app/src/main/cpp/baresip.c @@ -562,6 +562,9 @@ Java_com_tutpro_baresip_BaresipService_baresipStart(JNIEnv *env, jobject instanc for (le = list_head(uag_list()); le != NULL; le = le->next) ua_print_status_log(le->data); + jmethodID startedId = (*env)->GetMethodID(env, g_ctx.mainActivityClz, "started", "()V"); + (*env)->CallVoidMethod(env, g_ctx.mainActivityObj, startedId); + LOGI("running main loop ...\n"); err = re_main(signal_handler); diff --git a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt index 0a5cad35..bf1c754d 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt @@ -859,6 +859,18 @@ class BaresipService: Service() { return "" } + @Keep + fun started() { + Log.d(LOG_TAG, "Received 'started' from baresip") + if (callActionUri != "") { + val intent = Intent("service event") + intent.putExtra("event", "started") + intent.putExtra("params", arrayListOf(callActionUri)) + LocalBroadcastManager.getInstance(this).sendBroadcast(intent) + callActionUri = "" + } + } + @Keep fun stopped(error: String) { Log.d(LOG_TAG, "Received 'stopped' from baresip with param '$error'") @@ -1194,6 +1206,7 @@ class BaresipService: Service() { var downloadsPath = "" var logLevel = 2 var sipTrace = false + var callActionUri = "" val uas = ArrayList() val status = ArrayList() diff --git a/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt b/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt index fe89d075..ed3dbe2a 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt @@ -82,7 +82,10 @@ class MainActivity : AppCompatActivity() { val intentAction = intent.getStringExtra("action") - Log.d("Baresip", "At MainActivity onCreate with action '$intentAction'") + Log.d("Baresip", "MainActivity onCreate ${intent.action}/${intent.data}/$intentAction") + + if (intent?.action == ACTION_CALL && BaresipService.callActionUri == "") + BaresipService.callActionUri = URLDecoder.decode(intent.data.toString(), "UTF-8") kgm = getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager dismissKeyguard() @@ -712,6 +715,23 @@ class MainActivity : AppCompatActivity() { Log.d("Baresip", "Omit service event '$event' for task -1") return } + if (event == "started") { + val callActionUri = params[0] + Log.d("Baresip", "Handling service event 'started' with '$callActionUri'") + var ua = UserAgent.ofDomain(Utils.uriHostPart(callActionUri)) + if (ua == null) + if (BaresipService.uas.size > 0) { + ua = BaresipService.uas[0] + } else { + Log.w("Baresip", "No UAs to make the call to $callActionUri") + return + } + spinToAor(ua.account.aor) + ua.account.resumeUri = callActionUri + callUri.setText(callActionUri) + callButton.performClick() + return + } if (event == "stopped") { Log.d("Baresip", "Handling service event 'stopped' with param '${params[0]}'") if (params[0] != "") {