Fixed handling of call action when baresip app was not running

This commit is contained in:
Juha Heinanen
2021-01-21 15:37:33 +02:00
parent 2038a3170a
commit 31fa509d34
3 changed files with 37 additions and 1 deletions

View File

@ -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);

View File

@ -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<UserAgent>()
val status = ArrayList<Int>()

View File

@ -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] != "") {