Add heuristics for delayed notifications.

This commit is contained in:
Clark
2023-07-28 13:11:46 -04:00
committed by Greyson Parrelli
parent c012ead143
commit 66792f2d56
8 changed files with 189 additions and 14 deletions

View File

@@ -53,7 +53,12 @@ class FcmFetchForegroundService : Service() {
private var foregroundServiceState: State = State.STOPPED
fun startServiceIfNecessary(context: Context) {
/**
* Attempts to start the foreground service if it isn't already running.
*
* @return false if we failed to start the foreground service
*/
fun startServiceIfNecessary(context: Context): Boolean {
synchronized(this) {
when (foregroundServiceState) {
State.STOPPING -> foregroundServiceState = State.RESTARTING
@@ -64,11 +69,13 @@ class FcmFetchForegroundService : Service() {
} catch (e: IllegalStateException) {
Log.e(TAG, "Failed to start foreground service", e)
State.STOPPED
return false
}
}
else -> Log.i(TAG, "Already started foreground service")
}
}
return true
}
fun stopServiceIfNecessary(context: Context) {

View File

@@ -51,22 +51,21 @@ object FcmFetchManager {
@Volatile
private var highPriority = false
/**
* @return True if a service was successfully started, otherwise false.
*/
@JvmStatic
fun startBackgroundService(context: Context) {
Log.i(TAG, "Starting in the background.")
context.startService(Intent(context, FcmFetchBackgroundService::class.java))
SignalLocalMetrics.FcmServiceStartSuccess.onFcmStarted()
}
/**
* @return True if a service was successfully started, otherwise false.
*/
@JvmStatic
fun startForegroundService(context: Context) {
Log.i(TAG, "Starting in the foreground.")
FcmFetchForegroundService.startServiceIfNecessary(context)
if (FcmFetchForegroundService.startServiceIfNecessary(context)) {
SignalLocalMetrics.FcmServiceStartSuccess.onFcmStarted()
} else {
SignalLocalMetrics.FcmServiceStartFailure.onFcmFailedToStart()
}
}
private fun postMayHaveMessagesNotification(context: Context) {

View File

@@ -16,6 +16,7 @@ import org.thoughtcrime.securesms.jobs.SubmitRateLimitPushChallengeJob;
import org.thoughtcrime.securesms.keyvalue.SignalStore;
import org.thoughtcrime.securesms.registration.PushChallengeRequest;
import org.thoughtcrime.securesms.util.NetworkUtil;
import org.thoughtcrime.securesms.util.SignalLocalMetrics;
import java.util.Locale;
@@ -85,6 +86,7 @@ public class FcmReceiveService extends FirebaseMessagingService {
}
} catch (Exception e) {
Log.w(TAG, "Failed to start service.", e);
SignalLocalMetrics.FcmServiceStartFailure.onFcmFailedToStart();
}
FcmFetchManager.enqueueFetch(context, highPriority);