mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-21 17:29:32 +01:00
Add heuristics for delayed notifications.
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user