mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
show a foreground service notification
This commit is contained in:
@@ -17,15 +17,20 @@ import com.google.firebase.messaging.RemoteMessage;
|
||||
|
||||
import org.thoughtcrime.securesms.ApplicationContext;
|
||||
import org.thoughtcrime.securesms.BuildConfig;
|
||||
import org.thoughtcrime.securesms.util.Prefs;
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.service.GenericForegroundService;
|
||||
import org.thoughtcrime.securesms.service.NotificationController;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
|
||||
public class FcmReceiveService extends FirebaseMessagingService {
|
||||
private static final String TAG = FcmReceiveService.class.getSimpleName();
|
||||
private static final Object INIT_LOCK = new Object();
|
||||
private static final Object NOTIFICATION_CONTROLLER_LOCK = new Object();
|
||||
|
||||
private static boolean initialized;
|
||||
private static volatile boolean triedRegistering;
|
||||
private static volatile String prefixedToken;
|
||||
private static NotificationController notificationController;
|
||||
|
||||
public static void register(Context context) {
|
||||
if (Build.VERSION.SDK_INT < 19) {
|
||||
@@ -92,13 +97,27 @@ public class FcmReceiveService extends FirebaseMessagingService {
|
||||
return prefixedToken;
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
@Override
|
||||
public void onMessageReceived(@NonNull RemoteMessage remoteMessage) {
|
||||
Log.i(TAG, "FCM push notification received");
|
||||
ApplicationContext.dcAccounts.backgroundFetch(120);
|
||||
synchronized (NOTIFICATION_CONTROLLER_LOCK) {
|
||||
notificationController = GenericForegroundService.startForegroundTask(this, getString(R.string.connectivity_updating));
|
||||
if (!ApplicationContext.dcAccounts.backgroundFetch(19)) { // we should complete within 20 seconds
|
||||
notificationController.close();
|
||||
notificationController = null;
|
||||
}
|
||||
}
|
||||
Log.i(TAG, "background fetch done");
|
||||
}
|
||||
|
||||
public static void backgroundFetchDone() {
|
||||
synchronized (NOTIFICATION_CONTROLLER_LOCK) {
|
||||
notificationController.close();
|
||||
notificationController = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDeletedMessages() {
|
||||
Log.i(TAG, "FCM push notifications dropped");
|
||||
|
||||
@@ -31,6 +31,7 @@ public class DcContext {
|
||||
public final static int DC_EVENT_WEBXDC_STATUS_UPDATE = 2120;
|
||||
public final static int DC_EVENT_WEBXDC_INSTANCE_DELETED = 2121;
|
||||
public final static int DC_EVENT_WEBXDC_REALTIME_DATA = 2150;
|
||||
public final static int DC_EVENT_ACCOUNTS_BACKGROUND_FETCH_DONE = 2200;
|
||||
|
||||
public final static int DC_IMEX_EXPORT_SELF_KEYS = 1;
|
||||
public final static int DC_IMEX_IMPORT_SELF_KEYS = 2;
|
||||
|
||||
@@ -11,6 +11,7 @@ import com.b44t.messenger.DcEvent;
|
||||
|
||||
import org.thoughtcrime.securesms.ApplicationContext;
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.notifications.FcmReceiveService;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -177,6 +178,10 @@ public class DcEventCenter {
|
||||
DcHelper.getNotificationCenter(context).removeNotifications(accountId, event.getData1Int());
|
||||
break;
|
||||
|
||||
case DcContext.DC_EVENT_ACCOUNTS_BACKGROUND_FETCH_DONE:
|
||||
FcmReceiveService.backgroundFetchDone();
|
||||
break;
|
||||
|
||||
case DcContext.DC_EVENT_IMEX_PROGRESS:
|
||||
sendToCurrentAccountObservers(event);
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user