Prevent starting of baresip service more than once

This commit is contained in:
Juha Heinanen
2023-04-17 13:17:02 +03:00
parent 63ea22222e
commit 808b4c26e1
2 changed files with 12 additions and 10 deletions

View File

@ -363,6 +363,8 @@ class BaresipService: Service() {
"Start" -> {
isStartReceived = true
if (VERSION.SDK_INT < 31) {
@Suppress("DEPRECATION")
allNetworks = cm.allNetworks.toMutableSet()
@ -1476,6 +1478,7 @@ class BaresipService: Service() {
companion object {
var isServiceRunning = false
var isStartReceived = false
var isConfigInitialized = false
var libraryLoaded = false
var callVolume = 0

View File

@ -172,7 +172,7 @@ class MainActivity : AppCompatActivity() {
val event = it.getContentIfNotHandled()
Log.d(TAG, "Observed event $event")
if (event != null && BaresipService.serviceEvents.isNotEmpty()) {
val first = BaresipService.serviceEvents.first()
val first = BaresipService.serviceEvents.removeFirst()
handleServiceEvent(first.event, first.params)
}
}
@ -989,11 +989,8 @@ class MainActivity : AppCompatActivity() {
if (logMessage != null)
Log.w(TAG, logMessage)
if (BaresipService.serviceEvents.isNotEmpty()) {
BaresipService.serviceEvents.removeFirst()
if (BaresipService.serviceEvents.isNotEmpty()) {
val e = BaresipService.serviceEvents.first()
handleServiceEvent(e.event, e.params)
}
val first = BaresipService.serviceEvents.removeFirst()
handleServiceEvent(first.event, first.params)
}
}
@ -1679,10 +1676,12 @@ class MainActivity : AppCompatActivity() {
}
private fun startBaresip() {
baresipService.action = "Start"
startService(baresipService)
if (atStartup)
moveTaskToBack(true)
if (!BaresipService.isStartReceived) {
baresipService.action = "Start"
startService(baresipService)
if (atStartup)
moveTaskToBack(true)
}
}
private fun backup(password: String) {