Check buffered response once per service started

This commit is contained in:
sim 2023-04-11 18:38:16 +02:00
parent 120c44d203
commit 59ffef6f05
2 changed files with 9 additions and 3 deletions

View File

@ -14,6 +14,7 @@ import org.unifiedpush.distributor.nextpush.services.FailureHandler
import org.unifiedpush.distributor.nextpush.services.RestartNetworkCallback
import org.unifiedpush.distributor.nextpush.services.RestartWorker
import org.unifiedpush.distributor.nextpush.services.StartService
import org.unifiedpush.distributor.nextpush.services.StartService.StartServiceCompanion.bufferedResponseChecked
import org.unifiedpush.distributor.nextpush.utils.NotificationUtils.showLowKeepaliveNotification
import org.unifiedpush.distributor.nextpush.utils.NotificationUtils.showStartErrorNotification
import org.unifiedpush.distributor.nextpush.utils.TAG
@ -28,9 +29,11 @@ class SSEListener(val context: Context) : EventSourceListener() {
override fun onOpen(eventSource: EventSource, response: Response) {
FailureHandler.newEventSource(context, eventSource)
startingTimer?.cancel()
startingTimer = Timer().schedule(45_000L /* 45secs */) {
StartService.stopService()
showStartErrorNotification(context)
if (!bufferedResponseChecked) {
startingTimer = Timer().schedule(45_000L /* 45secs */) {
StartService.stopService()
showStartErrorNotification(context)
}
}
StartService.wakeLock?.let {
while (it.isHeld) {
@ -53,6 +56,7 @@ class SSEListener(val context: Context) : EventSourceListener() {
"start" -> {
started = true
startingTimer?.cancel()
bufferedResponseChecked = true
}
"ping" -> {
pinged = true

View File

@ -85,6 +85,7 @@ class StartService : Service() {
private set
var wakeLock: PowerManager.WakeLock? = null
private set
var bufferedResponseChecked = false
fun startListener(context: Context) {
if (isServiceStarted && !FailureHandler.hasFailed()) return
@ -102,6 +103,7 @@ class StartService : Service() {
fun stopService(block: () -> Unit = {}) {
Log.d(TAG, "Stopping Service")
isServiceStarted = false
bufferedResponseChecked = false
lastEventDate = null
service?.stopSelf()
block()