Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why FirebaseRemoteConfig.fetch doesn't call its callback?

Background

I try to use Google's new Firebase services, for A/B testing. For this, we need to use both Firebase Analytics and Firebase RemoteConfig.

The problem

Using FireBase RemoteConfig, I wanted to get the variables from the server (which have different value per variant of each experiment), but it seems that on some devices it gets stuck there, not calling its callback (OnCompleteListener.onComplete) .

I used about the same code as on the samples (here) :

    // init:
    boolean isDebug = ... ;
    mFirebaseRemoteConfig = FirebaseRemoteConfig.getInstance();
    FirebaseRemoteConfigSettings configSettings = new FirebaseRemoteConfigSettings.Builder().setDeveloperModeEnabled(isDebug).build();
    mFirebaseRemoteConfig.setConfigSettings(configSettings);
    final HashMap<String, Object> defaults = new HashMap<>();
    for (...)
        defaults.put(...);
    mFirebaseRemoteConfig.setDefaults(defaults);

    //fetching the variables:
    long cacheExpiration = isDebug ? 0 : java.util.concurrent.TimeUnit.HOURS.toSeconds(1);
    mFirebaseRemoteConfig.fetch(cacheExpiration).addOnCompleteListener(new OnCompleteListener<Void>() {
        @Override
        public void onComplete(@NonNull Task<Void> task) {
            //on some devices, I never get here at all
            if (task.isSuccessful()) {
                mFirebaseRemoteConfig.activateFetched();
                final FirebaseAnalytics firebaseAnalytics = FirebaseAnalytics.getInstance(context);
                for (...) {
                    String experimentVariantValue = mFirebaseRemoteConfig.getString(...);
                    firebaseAnalytics.setUserProperty(..., experimentVariantValue);
                }
            } else {
            }
        }
    });

Thing is, the callback doesn't get called, but only on some devices:

  • Nexus 5 with Android 6.0.1 : almost always succeeds.
  • Nexus 4 with Android 5.1.1 and LG G2 with Android 4.2.2 : almost always freeze (meaning they don't get into the callback)

I've also found that when it does work, it works in the near sessions afterwards.

The question

Why does it occur? What can I do to solve this?

like image 314
android developer Avatar asked Jun 23 '16 14:06

android developer


1 Answers

Just to add to what Cachapa just posted, the bug happens when the fetch() is called too early. We found two solutions to the problem (both work but not satisfactory) - call the fetch() from an onResume, or add a 3 seconds delay before actually issuing the fetch().

And about the "it works in the near sessions afterwards", once you get the callback and call activateFetched(), all sessions will get the correct values.

Update The 3 second delay was from the Activity.onCreate(). After checking further, it only worked on one device - Nexus 4. It didn't do the trick on a Samsung S3 nor on a Moto X Pure. We also checked on a Samsung S7, there it worked without any delay - the problem never manifested at all.

We are discussing it in a mail correspondence with Firebase support. I will update here when they get back to me..

Update 2 Firebase team claim this is solved in GPSv9.4 and I think this time they're right. They also claimed it was solved in 9.3, but then my tests disproved it. Now (after updating our dependency on gms to v9.4), I get the callbacks correctly on my dev devices. However, I still get indications that not all of our production devices are getting the correct config. My assumption is that devices that didn't update the GPS to the latest version are still faulty, but I'm not sure..

like image 176
Gili Garibi Avatar answered Nov 15 '22 04:11

Gili Garibi