From 3cafdaf57e5cde75e9d588246d93133868ebf821 Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Thu, 2 May 2024 15:29:07 +0200 Subject: [PATCH] allow fcm for all flavours --- build.gradle | 2 +- google-services.json | 57 +++++++++++++++++++ .../notifications/FcmReceiveService.java | 19 ++++--- 3 files changed, 69 insertions(+), 9 deletions(-) diff --git a/build.gradle b/build.gradle index a955af6af..4db9e02c8 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ plugins { id 'com.android.application' version '8.1.4' - id 'com.google.gms.google-services' version '4.4.1' apply false // TODO: apply below as needed using "apply plugin" or so + id 'com.google.gms.google-services' version '4.4.1' } repositories { diff --git a/google-services.json b/google-services.json index 511663fc1..64d7ae566 100644 --- a/google-services.json +++ b/google-services.json @@ -23,6 +23,63 @@ "other_platform_oauth_client": [] } } + }, + { + "client_info": { + "mobilesdk_app_id": "1:922391085500:android:6f54e2c4e49405673e2bb9", + "android_client_info": { + "package_name": "chat.delta.beta" + } + }, + "oauth_client": [], + "api_key": [ + { + "current_key": "AIzaSyBYH8Iznh8btYX7g_udv_bu68VH30zzxho" + } + ], + "services": { + "appinvite_service": { + "other_platform_oauth_client": [] + } + } + }, + { + "client_info": { + "mobilesdk_app_id": "1:922391085500:android:92b4cf12669cc2083e2bb9", + "android_client_info": { + "package_name": "com.b44t.messenger" + } + }, + "oauth_client": [], + "api_key": [ + { + "current_key": "AIzaSyBYH8Iznh8btYX7g_udv_bu68VH30zzxho" + } + ], + "services": { + "appinvite_service": { + "other_platform_oauth_client": [] + } + } + }, + { + "client_info": { + "mobilesdk_app_id": "1:922391085500:android:228a205b8aa2bacc3e2bb9", + "android_client_info": { + "package_name": "com.b44t.messenger.beta" + } + }, + "oauth_client": [], + "api_key": [ + { + "current_key": "AIzaSyBYH8Iznh8btYX7g_udv_bu68VH30zzxho" + } + ], + "services": { + "appinvite_service": { + "other_platform_oauth_client": [] + } + } } ], "configuration_version": "1" diff --git a/src/org/thoughtcrime/securesms/notifications/FcmReceiveService.java b/src/org/thoughtcrime/securesms/notifications/FcmReceiveService.java index c29beb673..5ee0074e0 100644 --- a/src/org/thoughtcrime/securesms/notifications/FcmReceiveService.java +++ b/src/org/thoughtcrime/securesms/notifications/FcmReceiveService.java @@ -19,7 +19,6 @@ import org.thoughtcrime.securesms.util.Util; public class FcmReceiveService extends FirebaseMessagingService { private static final String TAG = FcmReceiveService.class.getSimpleName(); - private static final String TOKEN_PREFIX = "fcm:"; private static String prefixedToken; public static void register(Context context) { @@ -41,19 +40,23 @@ public class FcmReceiveService extends FirebaseMessagingService { return; } - String prefixedToken = TOKEN_PREFIX + rawToken; - synchronized (FcmReceiveService.TOKEN_PREFIX) { + String prefixedToken = addPrefix(rawToken); + synchronized (FcmReceiveService.TAG) { FcmReceiveService.prefixedToken = prefixedToken; } - Log.w(TAG, "FCM token for " + BuildConfig.APPLICATION_ID + ": " + prefixedToken); + Log.w(TAG, "FCM token: " + prefixedToken); ApplicationContext.dcAccounts.setPushDeviceToken(prefixedToken); }); } + private static String addPrefix(String rawToken) { + return "fcm-" + BuildConfig.APPLICATION_ID + ":" + rawToken; + } + @Nullable public static String getToken() { - synchronized (FcmReceiveService.TOKEN_PREFIX) { + synchronized (FcmReceiveService.TAG) { return FcmReceiveService.prefixedToken; } } @@ -65,12 +68,12 @@ public class FcmReceiveService extends FirebaseMessagingService { @Override public void onNewToken(@NonNull String rawToken) { - String prefixedToken = TOKEN_PREFIX + rawToken; - synchronized (FcmReceiveService.TOKEN_PREFIX) { + String prefixedToken = addPrefix(rawToken) ; + synchronized (FcmReceiveService.TAG) { FcmReceiveService.prefixedToken = prefixedToken; } - Log.i(TAG, "new FCM token for" + BuildConfig.APPLICATION_ID + ": " + prefixedToken); + Log.i(TAG, "new FCM token: " + prefixedToken); ApplicationContext.dcAccounts.setPushDeviceToken(prefixedToken); } }