From 59ffef6f0511e4b985d170c90e2c75ce4e1b7114 Mon Sep 17 00:00:00 2001 From: sim Date: Tue, 11 Apr 2023 18:38:16 +0200 Subject: [PATCH] Check buffered response once per service started --- .../distributor/nextpush/api/SSEListener.kt | 10 +++++++--- .../distributor/nextpush/services/StartService.kt | 2 ++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/unifiedpush/distributor/nextpush/api/SSEListener.kt b/app/src/main/java/org/unifiedpush/distributor/nextpush/api/SSEListener.kt index 7207451..76e23c4 100644 --- a/app/src/main/java/org/unifiedpush/distributor/nextpush/api/SSEListener.kt +++ b/app/src/main/java/org/unifiedpush/distributor/nextpush/api/SSEListener.kt @@ -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 diff --git a/app/src/main/java/org/unifiedpush/distributor/nextpush/services/StartService.kt b/app/src/main/java/org/unifiedpush/distributor/nextpush/services/StartService.kt index d059c99..340be20 100644 --- a/app/src/main/java/org/unifiedpush/distributor/nextpush/services/StartService.kt +++ b/app/src/main/java/org/unifiedpush/distributor/nextpush/services/StartService.kt @@ -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()