Use lib debug vars
This commit is contained in:
parent
94a680f54e
commit
02776df8e8
@ -11,14 +11,9 @@ object AppCompanion {
|
||||
*/
|
||||
val booting = AtomicBoolean(false)
|
||||
|
||||
/** Have we received the start event ? To check the reverse proxy timeout is high enough */
|
||||
val started = AtomicBoolean(false)
|
||||
|
||||
/** Count messages since restart */
|
||||
val messageCounter = AtomicInteger(0)
|
||||
|
||||
/** Have we received the ping event ? To check the reverse proxy timeout is high enough */
|
||||
val pinged = AtomicBoolean(false)
|
||||
val bufferedResponseChecked = AtomicBoolean(false)
|
||||
val keepalive = AtomicInteger(900)
|
||||
var lastEventDate: Calendar? = null
|
||||
|
@ -100,9 +100,11 @@ class Api(context: Context) {
|
||||
LastEventId(store).get()?.let {
|
||||
header("Last-Event-ID", it)
|
||||
}
|
||||
if (BatteryCallbackFactory.lowBattery == true) {
|
||||
if (BatteryCallbackFactory.isLowBattery()) {
|
||||
Log.d(TAG, "Battery is low, registering normal and high only")
|
||||
header("Urgency", "normal")
|
||||
} else {
|
||||
Log.d(TAG, "Battery is OK, registering for all messages")
|
||||
}
|
||||
}
|
||||
.build()
|
||||
|
@ -56,7 +56,7 @@ class SSEListener(private val context: Context, private val releaseLock: () -> U
|
||||
|
||||
when (type) {
|
||||
"start" -> {
|
||||
AppCompanion.started.set(true)
|
||||
FailureCounter.debugStarted()
|
||||
AppCompanion.messageCounter.set(0)
|
||||
StartingTimer.stop()
|
||||
AppCompanion.bufferedResponseChecked.set(true)
|
||||
@ -64,8 +64,7 @@ class SSEListener(private val context: Context, private val releaseLock: () -> U
|
||||
}
|
||||
|
||||
"ping" -> {
|
||||
AppCompanion.pinged.set(true)
|
||||
FailureCounter.newPing(context)
|
||||
FailureCounter.debugNewPing(context)
|
||||
}
|
||||
|
||||
"keepalive" -> {
|
||||
@ -127,7 +126,7 @@ class SSEListener(private val context: Context, private val releaseLock: () -> U
|
||||
response?.let {
|
||||
Log.d(TAG, "onFailure: ${it.code}")
|
||||
}
|
||||
if (!NetworkCallbackFactory.hasInternet) {
|
||||
if (!NetworkCallbackFactory.hasInternet()) {
|
||||
Log.d(TAG, "No Internet: do not restart")
|
||||
// It will be restarted when Internet is back
|
||||
eventSource.cancel()
|
||||
@ -159,15 +158,13 @@ class SSEListener(private val context: Context, private val releaseLock: () -> U
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove [StartingTimer], set the service has not [started][AppCompanion.started] and not
|
||||
* [pinged][AppCompanion.pinged]. The 3 elements are used to debug the user setup.
|
||||
* Remove [StartingTimer], set the [FailureCounter] debug vars to their default.
|
||||
* The startingTimer to check buffering response, and started/ping to check the reverse proxy
|
||||
* timeout is high enough.
|
||||
*/
|
||||
private fun clearDebugVars() {
|
||||
StartingTimer.stop()
|
||||
AppCompanion.started.set(false)
|
||||
AppCompanion.pinged.set(false)
|
||||
FailureCounter.debugClear()
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -6,10 +6,13 @@ import org.unifiedpush.distributor.callback.CallbackFactory
|
||||
import org.unifiedpush.distributor.nextpush.services.FailureCounter
|
||||
import org.unifiedpush.distributor.nextpush.services.RestartWorker
|
||||
import org.unifiedpush.distributor.nextpush.services.StartService
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
|
||||
object BatteryCallbackFactory : CallbackFactory<BatteryCallbackFactory.MainBatteryCallback>() {
|
||||
|
||||
class MainBatteryCallback : BatteryCallback() {
|
||||
override val lowBattery = BatteryCallbackFactory.lowBattery
|
||||
|
||||
private fun restartService(context: Context) {
|
||||
if (FailureCounter.isRunningWithoutFailure) {
|
||||
StartService.stopService {
|
||||
@ -34,5 +37,9 @@ object BatteryCallbackFactory : CallbackFactory<BatteryCallbackFactory.MainBatte
|
||||
/**
|
||||
* Default to false
|
||||
*/
|
||||
val lowBattery: Boolean = instance?.isLowBattery() ?: false
|
||||
private val lowBattery = AtomicBoolean(false)
|
||||
|
||||
fun isLowBattery(): Boolean {
|
||||
return lowBattery.get()
|
||||
}
|
||||
}
|
||||
|
@ -6,9 +6,11 @@ import org.unifiedpush.distributor.callback.NetworkCallback
|
||||
import org.unifiedpush.distributor.nextpush.services.FailureCounter
|
||||
import org.unifiedpush.distributor.nextpush.services.MainRegistrationCounter
|
||||
import org.unifiedpush.distributor.nextpush.services.RestartWorker
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
|
||||
object NetworkCallbackFactory : CallbackFactory<NetworkCallbackFactory.MainNetworkCallback>() {
|
||||
class MainNetworkCallback(val context: Context) : NetworkCallback() {
|
||||
override val hasInternet = NetworkCallbackFactory.hasInternet
|
||||
override val failureCounter = FailureCounter
|
||||
override val registrationCounter = MainRegistrationCounter
|
||||
override val worker = RestartWorker.Companion
|
||||
@ -21,5 +23,9 @@ object NetworkCallbackFactory : CallbackFactory<NetworkCallbackFactory.MainNetwo
|
||||
/**
|
||||
* Default to true
|
||||
*/
|
||||
val hasInternet: Boolean = instance?.hasInternet() ?: true
|
||||
private val hasInternet = AtomicBoolean(true)
|
||||
|
||||
fun hasInternet(): Boolean {
|
||||
return hasInternet.get()
|
||||
}
|
||||
}
|
||||
|
@ -20,6 +20,6 @@ class RegisterBroadcastReceiver : DistributorReceiver() {
|
||||
}
|
||||
|
||||
override fun hasInternet(context: Context): Boolean {
|
||||
return NetworkCallbackFactory.hasInternet
|
||||
return NetworkCallbackFactory.hasInternet()
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ class RestartWorker(ctx: Context, params: WorkerParameters) : Worker(ctx, params
|
||||
// We avoid running twice at the same time
|
||||
synchronized(lock) {
|
||||
Log.d(TAG, "Working")
|
||||
if (!NetworkCallbackFactory.hasInternet) {
|
||||
if (!NetworkCallbackFactory.hasInternet()) {
|
||||
Log.d(TAG, "Aborting, no internet.")
|
||||
return Result.success()
|
||||
}
|
||||
|
@ -12,7 +12,5 @@ fun getDebugInfo(): String {
|
||||
return "ServiceStarted: ${StartService.isServiceStarted()}\n" +
|
||||
"Last Event: $date\n" +
|
||||
"Keepalive: ${AppCompanion.keepalive.get()}\n" +
|
||||
"SSE started: ${AppCompanion.started}\n" +
|
||||
"SSE pinged: ${AppCompanion.pinged}\n" +
|
||||
FailureCounter.getDebugInfo()
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ retrofit = "2.11.0"
|
||||
rxjava3-rxandroid = "3.0.2"
|
||||
rxjava3-rxjava = "3.1.9"
|
||||
uiTooling = "1.7.6"
|
||||
unifiedpush-distributor = "0.1.2"
|
||||
unifiedpush-distributor = "0.1.3"
|
||||
unifiedpush-distributor-ui = "0.1.2"
|
||||
|
||||
[libraries]
|
||||
|
Loading…
x
Reference in New Issue
Block a user