That fuck shit the fascists are using
1package org.tm.archive.gcm;
2
3import android.content.Context;
4import android.text.TextUtils;
5
6import androidx.annotation.WorkerThread;
7
8import com.google.android.gms.tasks.Tasks;
9import com.google.firebase.FirebaseApp;
10import com.google.firebase.messaging.FirebaseMessaging;
11
12import org.signal.core.util.logging.Log;
13
14import java.util.Optional;
15import java.util.concurrent.ExecutionException;
16
17public final class FcmUtil {
18
19 private static final String TAG = Log.tag(FcmUtil.class);
20
21 /**
22 * Retrieves the current FCM token. If one isn't available, it'll be generated.
23 */
24 @WorkerThread
25 public static Optional<String> getToken(Context context) {
26 String token = null;
27
28 // Must be called manually if running outside of main process
29 FirebaseApp.initializeApp(context);
30
31 try {
32 token = Tasks.await(FirebaseMessaging.getInstance().getToken());
33 } catch (InterruptedException e) {
34 Log.w(TAG, "Was interrupted while waiting for the token.");
35 } catch (ExecutionException e) {
36 Log.w(TAG, "Failed to get the token.", e.getCause());
37 }
38
39 return Optional.ofNullable(TextUtils.isEmpty(token) ? null : token);
40 }
41}