Tried to simplify Quit/Restart process

This commit is contained in:
Juha Heinanen
2022-09-15 16:56:53 +03:00
parent f1ba8db207
commit 2f53b89386
2 changed files with 6 additions and 15 deletions
@@ -325,11 +325,6 @@ class BaresipService: Service() {
"force" -> { "force" -> {
cleanService() cleanService()
isServiceRunning = false isServiceRunning = false
if (VERSION.SDK_INT < 33)
@Suppress("DEPRECATION")
stopForeground(true)
else
stopForeground(STOP_FOREGROUND_REMOVE)
stopSelf() stopSelf()
// exitProcess(0) // exitProcess(0)
} }
@@ -543,14 +538,16 @@ class BaresipService: Service() {
override fun onDestroy() { override fun onDestroy() {
super.onDestroy() super.onDestroy()
Log.d(TAG, "At Baresip Service onDestroy") Log.d(TAG, "onDestroy at Baresip Service")
this.unregisterReceiver(bluetoothReceiver) this.unregisterReceiver(bluetoothReceiver)
this.unregisterReceiver(hotSpotReceiver) this.unregisterReceiver(hotSpotReceiver)
if (am.isBluetoothScoOn) am.stopBluetoothSco() 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")
@@ -1097,11 +1094,6 @@ class BaresipService: Service() {
quitTimer.cancel() quitTimer.cancel()
isServiceRunning = false isServiceRunning = false
postServiceEvent(ServiceEvent("stopped", arrayListOf(error), System.nanoTime())) postServiceEvent(ServiceEvent("stopped", arrayListOf(error), System.nanoTime()))
if (VERSION.SDK_INT < 33)
@Suppress("DEPRECATION")
stopForeground(true)
else
stopForeground(STOP_FOREGROUND_REMOVE)
stopSelf() stopSelf()
} }
@@ -1185,7 +1185,6 @@ class MainActivity : AppCompatActivity() {
Log.d(TAG, "Trigger restart") Log.d(TAG, "Trigger restart")
val pm = applicationContext.packageManager val pm = applicationContext.packageManager
val intent = pm.getLaunchIntentForPackage(this.packageName) val intent = pm.getLaunchIntentForPackage(this.packageName)
this.finishAffinity()
this.startActivity(intent) this.startActivity(intent)
exitProcess(0) exitProcess(0)
} }