mirror of
https://codeberg.org/NextPush/nextpush-android.git
synced 2025-01-17 04:07:16 +01:00
Check buffered response once per service started
This commit is contained in:
parent
120c44d203
commit
59ffef6f05
@ -14,6 +14,7 @@ import org.unifiedpush.distributor.nextpush.services.FailureHandler
|
|||||||
import org.unifiedpush.distributor.nextpush.services.RestartNetworkCallback
|
import org.unifiedpush.distributor.nextpush.services.RestartNetworkCallback
|
||||||
import org.unifiedpush.distributor.nextpush.services.RestartWorker
|
import org.unifiedpush.distributor.nextpush.services.RestartWorker
|
||||||
import org.unifiedpush.distributor.nextpush.services.StartService
|
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.showLowKeepaliveNotification
|
||||||
import org.unifiedpush.distributor.nextpush.utils.NotificationUtils.showStartErrorNotification
|
import org.unifiedpush.distributor.nextpush.utils.NotificationUtils.showStartErrorNotification
|
||||||
import org.unifiedpush.distributor.nextpush.utils.TAG
|
import org.unifiedpush.distributor.nextpush.utils.TAG
|
||||||
@ -28,10 +29,12 @@ class SSEListener(val context: Context) : EventSourceListener() {
|
|||||||
override fun onOpen(eventSource: EventSource, response: Response) {
|
override fun onOpen(eventSource: EventSource, response: Response) {
|
||||||
FailureHandler.newEventSource(context, eventSource)
|
FailureHandler.newEventSource(context, eventSource)
|
||||||
startingTimer?.cancel()
|
startingTimer?.cancel()
|
||||||
|
if (!bufferedResponseChecked) {
|
||||||
startingTimer = Timer().schedule(45_000L /* 45secs */) {
|
startingTimer = Timer().schedule(45_000L /* 45secs */) {
|
||||||
StartService.stopService()
|
StartService.stopService()
|
||||||
showStartErrorNotification(context)
|
showStartErrorNotification(context)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
StartService.wakeLock?.let {
|
StartService.wakeLock?.let {
|
||||||
while (it.isHeld) {
|
while (it.isHeld) {
|
||||||
it.release()
|
it.release()
|
||||||
@ -53,6 +56,7 @@ class SSEListener(val context: Context) : EventSourceListener() {
|
|||||||
"start" -> {
|
"start" -> {
|
||||||
started = true
|
started = true
|
||||||
startingTimer?.cancel()
|
startingTimer?.cancel()
|
||||||
|
bufferedResponseChecked = true
|
||||||
}
|
}
|
||||||
"ping" -> {
|
"ping" -> {
|
||||||
pinged = true
|
pinged = true
|
||||||
|
@ -85,6 +85,7 @@ class StartService : Service() {
|
|||||||
private set
|
private set
|
||||||
var wakeLock: PowerManager.WakeLock? = null
|
var wakeLock: PowerManager.WakeLock? = null
|
||||||
private set
|
private set
|
||||||
|
var bufferedResponseChecked = false
|
||||||
|
|
||||||
fun startListener(context: Context) {
|
fun startListener(context: Context) {
|
||||||
if (isServiceStarted && !FailureHandler.hasFailed()) return
|
if (isServiceStarted && !FailureHandler.hasFailed()) return
|
||||||
@ -102,6 +103,7 @@ class StartService : Service() {
|
|||||||
fun stopService(block: () -> Unit = {}) {
|
fun stopService(block: () -> Unit = {}) {
|
||||||
Log.d(TAG, "Stopping Service")
|
Log.d(TAG, "Stopping Service")
|
||||||
isServiceStarted = false
|
isServiceStarted = false
|
||||||
|
bufferedResponseChecked = false
|
||||||
lastEventDate = null
|
lastEventDate = null
|
||||||
service?.stopSelf()
|
service?.stopSelf()
|
||||||
block()
|
block()
|
||||||
|
Loading…
Reference in New Issue
Block a user