Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

start foreground-service for background-fetch only if really in background #3320

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ public static String getToken() {
@Override
public void onMessageReceived(@NonNull RemoteMessage remoteMessage) {
Log.i(TAG, "FCM push notification received");
FetchForegroundService.start(this);
FetchForegroundService.startIfInBackground(this);
}

@Override
public void onDeletedMessages() {
Log.i(TAG, "FCM push notifications dropped");
FetchForegroundService.start(this);
FetchForegroundService.startIfInBackground(this);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

import org.thoughtcrime.securesms.ApplicationContext;
import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.connect.DcHelper;
import org.thoughtcrime.securesms.connect.ForegroundDetector;
import org.thoughtcrime.securesms.notifications.FcmReceiveService;
import org.thoughtcrime.securesms.notifications.NotificationCenter;
import org.thoughtcrime.securesms.util.Util;
Expand All @@ -22,7 +24,17 @@ public final class FetchForegroundService extends Service {
private static final Object SERVICE_LOCK = new Object();
private static Intent service;

public static void start(Context context) {
public static void startIfInBackground(Context context) {
ForegroundDetector foregroundDetector = ForegroundDetector.getInstance();
if (foregroundDetector.isBackground()) {
// the app is in background, start visible foreground service to not get killed
FetchForegroundService.start(context);
} else {
DcHelper.getAccounts(context).maybeNetwork();
}
}

private static void start(Context context) {
GenericForegroundService.createFgNotificationChannel(context);
synchronized (SERVICE_LOCK) {
if (service == null) {
Expand Down
Loading