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" -> { "deleteApp" -> {
val message = Gson().fromJson(data, SSEResponse::class.java) val message = Gson().fromJson(data, SSEResponse::class.java)
if (Database.getDb(context).getPackageName(message.token) != null && if (Database.getDb(context).getPackageName(message.token) != null &&
!AppCompanion.delQueue.containsTokenElseAdd(message.token)) { !AppCompanion.delQueue.containsTokenElseAdd(message.token)
) {
deleteAppFromSSE(context, message.token) deleteAppFromSSE(context, message.token)
AppCompanion.delQueue.removeToken(message.token) AppCompanion.delQueue.removeToken(message.token)
} }

View File

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

View File

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

View File

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

View File

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