mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
move backgroundFetch() to FetchForegroundService
This commit is contained in:
@@ -5,15 +5,20 @@ import android.app.Service;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.IBinder;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.app.NotificationCompat;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import org.thoughtcrime.securesms.ApplicationContext;
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.notifications.FcmReceiveService;
|
||||
import org.thoughtcrime.securesms.notifications.NotificationCenter;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
|
||||
public final class FetchForegroundService extends Service {
|
||||
private static final String TAG = FcmReceiveService.class.getSimpleName();
|
||||
private static final Object SERVICE_LOCK = new Object();
|
||||
private static Intent service;
|
||||
|
||||
@@ -38,6 +43,7 @@ public final class FetchForegroundService extends Service {
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
Log.i(TAG, "Creating fetch service");
|
||||
super.onCreate();
|
||||
|
||||
Notification notification = new NotificationCompat.Builder(this, NotificationCenter.CH_GENERIC)
|
||||
@@ -46,6 +52,18 @@ public final class FetchForegroundService extends Service {
|
||||
.build();
|
||||
|
||||
startForeground(NotificationCenter.ID_FETCH, notification);
|
||||
|
||||
// Start explicit fetch only after we marked ourselves as requiring foreground;
|
||||
// this may help we on getting network and time adequately
|
||||
// Fetch is started in background to not block the UI.
|
||||
// We then run not longer than the max. of 20 seconds,
|
||||
// see https://firebase.google.com/docs/cloud-messaging/android/receive .
|
||||
Util.runOnAnyBackgroundThread(() -> {
|
||||
Log.i(TAG, "Starting fetch");
|
||||
if (!ApplicationContext.dcAccounts.backgroundFetch(19)) {
|
||||
FetchForegroundService.stop(this);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user