Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
avazirna committed Jul 19, 2023
1 parent 57bee40 commit 9558b83
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
17 changes: 2 additions & 15 deletions app/src/org/commcare/CommCareApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,8 @@
import androidx.work.PeriodicWorkRequest;
import androidx.work.WorkManager;

import com.google.android.gms.tasks.OnCompleteListener;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;
import com.google.firebase.analytics.FirebaseAnalytics;
import com.google.firebase.messaging.FirebaseMessaging;

import net.sqlcipher.database.SQLiteDatabase;
import net.sqlcipher.database.SQLiteException;
Expand Down Expand Up @@ -109,6 +106,7 @@
import org.commcare.utils.CrashUtil;
import org.commcare.utils.DeviceIdentifier;
import org.commcare.utils.FileUtil;
import org.commcare.utils.FirebaseMessagingUtil;
import org.commcare.utils.GlobalConstants;
import org.commcare.utils.MarkupUtil;
import org.commcare.utils.MultipleAppsUtil;
Expand All @@ -117,7 +115,6 @@
import org.commcare.utils.SessionStateUninitException;
import org.commcare.utils.SessionUnavailableException;
import org.commcare.views.widgets.CleanRawMedia;
import org.conscrypt.Conscrypt;
import org.javarosa.core.model.User;
import org.javarosa.core.reference.ReferenceManager;
import org.javarosa.core.reference.RootTranslator;
Expand All @@ -128,12 +125,10 @@
import org.javarosa.core.util.externalizable.PrototypeFactory;

import java.io.File;
import java.security.Security;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import javax.annotation.Nullable;
Expand Down Expand Up @@ -253,8 +248,7 @@ public void onCreate() {
LocalePreferences.saveDeviceLocale(Locale.getDefault());
GraphUtil.setLabelCharacterLimit(getResources().getInteger(R.integer.graph_label_char_limit));

// Retrieve the current Firebase Cloud Messaging (FCM) registration token^M
FirebaseMessaging.getInstance().getToken().addOnCompleteListener(handleFCMTokenRetrieval());
FirebaseMessagingUtil.verifyToken();
}

protected void attachISRGCert() {
Expand Down Expand Up @@ -1198,11 +1192,4 @@ public boolean isNsdServicesEnabled() {
return true;
}

private OnCompleteListener handleFCMTokenRetrieval(){
return (OnCompleteListener<String>) task -> {
if (!task.isSuccessful()) {
Logger.exception("Fetching FCM registration token failed", task.getException());
}
};
}
}
20 changes: 20 additions & 0 deletions app/src/org/commcare/utils/FirebaseMessagingUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@

import androidx.preference.PreferenceManager;

import com.google.android.gms.tasks.OnCompleteListener;
import com.google.firebase.messaging.FirebaseMessaging;

import org.commcare.CommCareApplication;
import org.commcare.dalvik.BuildConfig;
import org.javarosa.core.services.Logger;

public class FirebaseMessagingUtil {
public static final String FCM_TOKEN = "fcm_token";
Expand Down Expand Up @@ -46,4 +51,19 @@ public static String removeServerUrlFromUserDomain(String userDomain) {
}
return userDomain;
}

public static void verifyToken() {
if(!BuildConfig.DEBUG) {
// Retrieve the current Firebase Cloud Messaging (FCM) registration token
FirebaseMessaging.getInstance().getToken().addOnCompleteListener(handleFCMTokenRetrieval());
}
}

private static OnCompleteListener handleFCMTokenRetrieval(){
return (OnCompleteListener<String>) task -> {
if (!task.isSuccessful()) {
Logger.exception("Fetching FCM registration token failed", task.getException());
}
};
}
}

0 comments on commit 9558b83

Please sign in to comment.