Always use a foreground service when processing high-priority FCM pushes.

main
Greyson Parrelli 2023-02-27 19:52:09 -05:00
rodzic f91c400f6c
commit 57e8684bb3
4 zmienionych plików z 25 dodań i 6 usunięć

Wyświetl plik

@ -81,13 +81,18 @@ public class FcmReceiveService extends FirebaseMessagingService {
boolean enqueueSuccessful = false;
try {
boolean highPriority = remoteMessage != null && remoteMessage.getPriority() == RemoteMessage.PRIORITY_HIGH;
long timeSinceLastRefresh = System.currentTimeMillis() - SignalStore.misc().getLastFcmForegroundServiceTime();
Log.d(TAG, String.format(Locale.US, "[handleReceivedNotification] API: %s, FeatureFlag: %s, RemoteMessagePriority: %s, TimeSinceLastRefresh: %s ms", Build.VERSION.SDK_INT, FeatureFlags.useFcmForegroundService(), remoteMessage != null ? remoteMessage.getPriority() : "n/a", timeSinceLastRefresh));
if (FeatureFlags.useFcmForegroundService() && Build.VERSION.SDK_INT >= 31 && remoteMessage != null && remoteMessage.getPriority() == RemoteMessage.PRIORITY_HIGH && timeSinceLastRefresh > FCM_FOREGROUND_INTERVAL) {
if (highPriority && FeatureFlags.useFcmForegroundService()) {
enqueueSuccessful = FcmFetchManager.enqueue(context, true);
SignalStore.misc().setLastFcmForegroundServiceTime(System.currentTimeMillis());
} else if (Build.VERSION.SDK_INT < 26 || remoteMessage == null || remoteMessage.getPriority() == RemoteMessage.PRIORITY_HIGH) {
} else if (highPriority && Build.VERSION.SDK_INT >= 31 && timeSinceLastRefresh > FCM_FOREGROUND_INTERVAL) {
enqueueSuccessful = FcmFetchManager.enqueue(context, true);
SignalStore.misc().setLastFcmForegroundServiceTime(System.currentTimeMillis());
} else if (highPriority || Build.VERSION.SDK_INT < 26 || remoteMessage == null) {
enqueueSuccessful = FcmFetchManager.enqueue(context, false);
}
} catch (Exception e) {

Wyświetl plik

@ -43,6 +43,8 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicInteger;
import io.reactivex.rxjava3.disposables.Disposable;
/**
* The application-level manager of our websocket connection.
* <p>
@ -263,6 +265,15 @@ public class IncomingMessageObserver {
Log.i(TAG, "Making websocket connection....");
SignalWebSocket signalWebSocket = ApplicationDependencies.getSignalWebSocket();
Disposable webSocketDisposable = signalWebSocket.getWebSocketState().subscribe(state -> {
Log.d(TAG, "WebSocket State: " + state);
// Any state change at all means that we are not drained
networkDrained = false;
decryptionDrained = false;
});
signalWebSocket.connect();
try {
@ -281,6 +292,8 @@ public class IncomingMessageObserver {
Log.i(TAG, "Network was newly-drained. Enqueuing a job to listen for decryption draining.");
networkDrained = true;
ApplicationDependencies.getJobManager().add(new PushDecryptDrainedJob());
} else if (!result.isPresent()) {
Log.w(TAG, "Got tombstone, but we thought the network was already drained!");
}
} catch (WebSocketUnavailableException e) {
Log.i(TAG, "Pipe unexpectedly unavailable, connecting");
@ -300,6 +313,7 @@ public class IncomingMessageObserver {
} finally {
Log.w(TAG, "Shutting down pipe...");
disconnect();
webSocketDisposable.dispose();
}
Log.i(TAG, "Looping...");

Wyświetl plik

@ -9,7 +9,6 @@ import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
import org.thoughtcrime.securesms.jobmanager.JobManager;
import org.thoughtcrime.securesms.jobmanager.JobTracker;
import org.thoughtcrime.securesms.jobs.MarkerJob;
import org.thoughtcrime.securesms.jobs.PushDecryptMessageJob;
import org.thoughtcrime.securesms.jobs.PushProcessMessageJob;
import java.util.Optional;

Wyświetl plik

@ -87,7 +87,7 @@ public final class FeatureFlags {
private static final String USE_AEC3 = "android.calling.useAec3";
private static final String PAYMENTS_COUNTRY_BLOCKLIST = "global.payments.disabledRegions";
public static final String PHONE_NUMBER_PRIVACY = "android.pnp";
private static final String USE_FCM_FOREGROUND_SERVICE = "android.useFcmForegroundService.3";
private static final String USE_FCM_FOREGROUND_SERVICE = "android.useFcmForegroundService.4";
private static final String STORIES_AUTO_DOWNLOAD_MAXIMUM = "android.stories.autoDownloadMaximum";
private static final String TELECOM_MANUFACTURER_ALLOWLIST = "android.calling.telecomAllowList";
private static final String TELECOM_MODEL_BLOCKLIST = "android.calling.telecomModelBlockList";
@ -487,6 +487,7 @@ public final class FeatureFlags {
return getBoolean(USE_AEC3, true);
}
/** Whether or not we show a foreground service on every high-priority FCM push. */
public static boolean useFcmForegroundService() {
return getBoolean(USE_FCM_FOREGROUND_SERVICE, false);
}