That fuck shit the fascists are using
at master 105 lines 4.0 kB view raw
1package org.tm.archive.gcm; 2 3import android.content.Context; 4import android.os.Build; 5 6import androidx.annotation.NonNull; 7import androidx.annotation.Nullable; 8 9import com.google.firebase.messaging.FirebaseMessagingService; 10import com.google.firebase.messaging.RemoteMessage; 11 12import org.signal.core.util.logging.Log; 13import org.tm.archive.dependencies.ApplicationDependencies; 14import org.tm.archive.jobs.FcmRefreshJob; 15import org.tm.archive.jobs.SubmitRateLimitPushChallengeJob; 16import org.tm.archive.keyvalue.SignalStore; 17import org.tm.archive.registration.PushChallengeRequest; 18import org.tm.archive.util.NetworkUtil; 19import org.tm.archive.util.SignalLocalMetrics; 20 21import java.util.Locale; 22 23public class FcmReceiveService extends FirebaseMessagingService { 24 25 private static final String TAG = Log.tag(FcmReceiveService.class); 26 27 @Override 28 public void onMessageReceived(RemoteMessage remoteMessage) { 29 Log.i(TAG, String.format(Locale.US, 30 "onMessageReceived() ID: %s, Delay: %d (Server offset: %d), Priority: %d, Original Priority: %d, Network: %s", 31 remoteMessage.getMessageId(), 32 (System.currentTimeMillis() - remoteMessage.getSentTime()), 33 SignalStore.misc().getLastKnownServerTimeOffset(), 34 remoteMessage.getPriority(), 35 remoteMessage.getOriginalPriority(), 36 NetworkUtil.getNetworkStatus(this))); 37 38 String registrationChallenge = remoteMessage.getData().get("challenge"); 39 String rateLimitChallenge = remoteMessage.getData().get("rateLimitChallenge"); 40 41 if (registrationChallenge != null) { 42 handleRegistrationPushChallenge(registrationChallenge); 43 } else if (rateLimitChallenge != null) { 44 handleRateLimitPushChallenge(rateLimitChallenge); 45 } else { 46 handleReceivedNotification(ApplicationDependencies.getApplication(), remoteMessage); 47 } 48 } 49 50 @Override 51 public void onDeletedMessages() { 52 Log.w(TAG, "onDeleteMessages() -- Messages may have been dropped. Doing a normal message fetch."); 53 handleReceivedNotification(ApplicationDependencies.getApplication(), null); 54 } 55 56 @Override 57 public void onNewToken(String token) { 58 Log.i(TAG, "onNewToken()"); 59 60 if (!SignalStore.account().isRegistered()) { 61 Log.i(TAG, "Got a new FCM token, but the user isn't registered."); 62 return; 63 } 64 65 ApplicationDependencies.getJobManager().add(new FcmRefreshJob()); 66 } 67 68 @Override 69 public void onMessageSent(@NonNull String s) { 70 Log.i(TAG, "onMessageSent()" + s); 71 } 72 73 @Override 74 public void onSendError(@NonNull String s, @NonNull Exception e) { 75 Log.w(TAG, "onSendError()", e); 76 } 77 78 private static void handleReceivedNotification(Context context, @Nullable RemoteMessage remoteMessage) { 79 boolean highPriority = remoteMessage != null && remoteMessage.getPriority() == RemoteMessage.PRIORITY_HIGH; 80 try { 81 Log.d(TAG, String.format(Locale.US, "[handleReceivedNotification] API: %s, RemoteMessagePriority: %s", Build.VERSION.SDK_INT, remoteMessage != null ? remoteMessage.getPriority() : "n/a")); 82 83 if (highPriority) { 84 FcmFetchManager.startForegroundService(context); 85 } else if (Build.VERSION.SDK_INT < 26) { 86 FcmFetchManager.startBackgroundService(context); 87 } 88 } catch (Exception e) { 89 Log.w(TAG, "Failed to start service.", e); 90 SignalLocalMetrics.FcmServiceStartFailure.onFcmFailedToStart(); 91 } 92 93 FcmFetchManager.enqueueFetch(context, highPriority); 94 } 95 96 private static void handleRegistrationPushChallenge(@NonNull String challenge) { 97 Log.d(TAG, "Got a registration push challenge."); 98 PushChallengeRequest.postChallengeResponse(challenge); 99 } 100 101 private static void handleRateLimitPushChallenge(@NonNull String challenge) { 102 Log.d(TAG, "Got a rate limit push challenge."); 103 ApplicationDependencies.getJobManager().add(new SubmitRateLimitPushChallengeJob(challenge)); 104 } 105}