- Tried to improve baresip quit/restart process

This commit is contained in:
Juha Heinanen
2023-01-18 02:49:56 +02:00
parent abcf37dca2
commit 755b8edb51
2 changed files with 8 additions and 9 deletions
@@ -325,6 +325,7 @@ class BaresipService: Service() {
"force" -> { "force" -> {
cleanService() cleanService()
isServiceRunning = false isServiceRunning = false
postServiceEvent(ServiceEvent("stopped", arrayListOf(""), System.nanoTime()))
stopSelf() stopSelf()
// exitProcess(0) // exitProcess(0)
} }
@@ -539,15 +540,9 @@ class BaresipService: Service() {
override fun onDestroy() { override fun onDestroy() {
super.onDestroy() super.onDestroy()
Log.d(TAG, "onDestroy at Baresip Service") Log.d(TAG, "onDestroy at Baresip Service")
this.unregisterReceiver(bluetoothReceiver)
this.unregisterReceiver(hotSpotReceiver)
if (am.isBluetoothScoOn)
am.stopBluetoothSco()
cleanService() cleanService()
if (isServiceRunning) if (isServiceRunning)
sendBroadcast(Intent("com.tutpro.baresip.Restart")) sendBroadcast(Intent("com.tutpro.baresip.Restart"))
else
exitProcess(0)
} }
@SuppressLint("UnspecifiedImmutableFlag") @SuppressLint("UnspecifiedImmutableFlag")
@@ -1100,8 +1095,8 @@ class BaresipService: Service() {
@Keep @Keep
fun stopped(error: String) { fun stopped(error: String) {
Log.d(TAG, "Received 'stopped' from baresip with start error '$error'") Log.d(TAG, "Received 'stopped' from baresip with start error '$error'")
if (error == "")
quitTimer.cancel() quitTimer.cancel()
cleanService()
isServiceRunning = false isServiceRunning = false
postServiceEvent(ServiceEvent("stopped", arrayListOf(error), System.nanoTime())) postServiceEvent(ServiceEvent("stopped", arrayListOf(error), System.nanoTime()))
stopSelf() stopSelf()
@@ -1486,6 +1481,10 @@ class BaresipService: Service() {
private fun cleanService() { private fun cleanService() {
if (!isServiceClean) { if (!isServiceClean) {
this.unregisterReceiver(bluetoothReceiver)
this.unregisterReceiver(hotSpotReceiver)
if (am.isBluetoothScoOn)
am.stopBluetoothSco()
am.mode = AudioManager.MODE_NORMAL am.mode = AudioManager.MODE_NORMAL
abandonAudioFocus() abandonAudioFocus()
stopRinging() stopRinging()
@@ -1188,7 +1188,7 @@ class MainActivity : AppCompatActivity() {
val pm = applicationContext.packageManager val pm = applicationContext.packageManager
val intent = pm.getLaunchIntentForPackage(this.packageName) val intent = pm.getLaunchIntentForPackage(this.packageName)
this.startActivity(intent) this.startActivity(intent)
// exitProcess(0) exitProcess(0)
} }
override fun onCreateOptionsMenu(menu: Menu): Boolean { override fun onCreateOptionsMenu(menu: Menu): Boolean {