This commit is contained in:
S1m 2024-01-16 23:44:41 +01:00
parent f328fcc13f
commit f4eaba00a5
5 changed files with 22 additions and 19 deletions

View File

@ -96,7 +96,8 @@ class SSEListener(val context: Context) : EventSourceListener() {
"deleteApp" -> {
val message = Gson().fromJson(data, SSEResponse::class.java)
if (Database.getDb(context).getPackageName(message.token) != null &&
!AppCompanion.delQueue.containsTokenElseAdd(message.token)) {
!AppCompanion.delQueue.containsTokenElseAdd(message.token)
) {
deleteAppFromSSE(context, message.token)
AppCompanion.delQueue.removeToken(message.token)
}

View File

@ -15,18 +15,18 @@ object RegistrationCountCache {
}
}
fun refresh(context: Context) = synchronized(this) {
nRegistrations = null
val count = getCount(context)
Log.d(TAG, "Refreshing nRegistrations to $count")
// if n == 1: start the SSE (The fg service starts on boot, but doesn't connect without reg)
// if n == 0: We keep the foreground service but stop the SSE/RestarWorker
// The Runner will starts StartService, which will disconnect the SSE
if (count in intArrayOf(0,1)) {
RestartWorker.run(context, delay = 0, force = true)
}
ForegroundNotification(context).update()
}
fun refresh(context: Context) = synchronized(this) {
nRegistrations = null
val count = getCount(context)
Log.d(TAG, "Refreshing nRegistrations to $count")
// if n == 1: start the SSE (The fg service starts on boot, but doesn't connect without reg)
// if n == 0: We keep the foreground service but stop the SSE/RestarWorker
// The Runner will starts StartService, which will disconnect the SSE
if (count in intArrayOf(0, 1)) {
RestartWorker.run(context, delay = 0, force = true)
}
ForegroundNotification(context).update()
}
fun oneOrMore(context: Context): Boolean = synchronized(this) {
return getCount(context) > 0

View File

@ -104,7 +104,10 @@ class StartService : Service() {
if (isServiceStarted &&
!FailureHandler.hasFailed() &&
// If there is no registration, this is a request to stop the SSE
RegistrationCountCache.oneOrMore(context)) return
RegistrationCountCache.oneOrMore(context)
) {
return
}
Log.d(TAG, "Starting the Listener")
Log.d(TAG, "Service is started: $isServiceStarted")
Log.d(TAG, "nFails: ${FailureHandler.nFails()}")

View File

@ -44,7 +44,7 @@ open class AppNotification(
private val shown: AtomicBoolean,
private val notificationId: Int,
private val notificationData: NotificationData,
private val channelData: ChannelData,
private val channelData: ChannelData
) {
internal fun createNotificationChannel() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
@ -221,7 +221,7 @@ class NoServerAppNotification(val context: Context) : AppNotification(
),
context.warningChannelData
) {
override fun create(bigText: Boolean): Notification{
override fun create(bigText: Boolean): Notification {
createNotificationChannel()
val notificationIntent = Intent(Intent.ACTION_VIEW)

View File

@ -4,7 +4,6 @@ import android.util.Log
import java.util.Timer
import kotlin.concurrent.schedule
fun MutableList<String>.containsTokenElseAdd(connectorToken: String): Boolean {
return synchronized(this) {
if (connectorToken !in this) {