From 755b8edb51c90a1e2b7fe3566a47d60c78780631 Mon Sep 17 00:00:00 2001 From: Juha Heinanen Date: Wed, 18 Jan 2023 02:49:56 +0200 Subject: [PATCH] - Tried to improve baresip quit/restart process --- .../kotlin/com/tutpro/baresip/BaresipService.kt | 15 +++++++-------- .../kotlin/com/tutpro/baresip/MainActivity.kt | 2 +- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt index 92d2f4bf..c539b1b4 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt @@ -325,6 +325,7 @@ class BaresipService: Service() { "force" -> { cleanService() isServiceRunning = false + postServiceEvent(ServiceEvent("stopped", arrayListOf(""), System.nanoTime())) stopSelf() // exitProcess(0) } @@ -539,15 +540,9 @@ class BaresipService: Service() { override fun onDestroy() { super.onDestroy() Log.d(TAG, "onDestroy at Baresip Service") - this.unregisterReceiver(bluetoothReceiver) - this.unregisterReceiver(hotSpotReceiver) - if (am.isBluetoothScoOn) - am.stopBluetoothSco() cleanService() if (isServiceRunning) sendBroadcast(Intent("com.tutpro.baresip.Restart")) - else - exitProcess(0) } @SuppressLint("UnspecifiedImmutableFlag") @@ -1100,8 +1095,8 @@ class BaresipService: Service() { @Keep fun stopped(error: String) { Log.d(TAG, "Received 'stopped' from baresip with start error '$error'") - if (error == "") - quitTimer.cancel() + quitTimer.cancel() + cleanService() isServiceRunning = false postServiceEvent(ServiceEvent("stopped", arrayListOf(error), System.nanoTime())) stopSelf() @@ -1486,6 +1481,10 @@ class BaresipService: Service() { private fun cleanService() { if (!isServiceClean) { + this.unregisterReceiver(bluetoothReceiver) + this.unregisterReceiver(hotSpotReceiver) + if (am.isBluetoothScoOn) + am.stopBluetoothSco() am.mode = AudioManager.MODE_NORMAL abandonAudioFocus() stopRinging() diff --git a/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt b/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt index ebacb4a7..f3105c5f 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt @@ -1188,7 +1188,7 @@ class MainActivity : AppCompatActivity() { val pm = applicationContext.packageManager val intent = pm.getLaunchIntentForPackage(this.packageName) this.startActivity(intent) - // exitProcess(0) + exitProcess(0) } override fun onCreateOptionsMenu(menu: Menu): Boolean {