Firebase anonymous authentication failure through Mobile Data

Firebase anonymous authentication failure through Mobile Data

I am having problems with Firebase authentication when device is connected through Mobile Data connection. If connected through WiFi authentication works fine.
I am using following code for authentication:
public class MyAuthActivity extends Activity
{
    protected FirebaseAuth auth;
    protected FirebaseAuth.AuthStateListener authListener;

    protected FirebaseUser user;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        auth = FirebaseAuth.getInstance();

        authListener = new FirebaseAuth.AuthStateListener()
        {
            @Override
            public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth)
            {
                user = firebaseAuth.getCurrentUser();
                if (user != null)
                {
                    // User is signed in
                    Log.d("APP", "onAuthStateChanged:signed_in: " + user.getUid());
                }
                else
                {
                    // User is signed out
                    Log.d("APP", "onAuthStateChanged:signed_out");
                }
            }
        };
        auth.addAuthStateListener(authListener);

        auth.signInAnonymously()
                .addOnFailureListener(this, new OnFailureListener()
                {
                    @Override
                    public void onFailure(@NonNull Exception e)
                    {
                        Log.w("APP", "signInAnonymously failure: ", e);
                    }
                })
                .addOnCompleteListener(this, new OnCompleteListener()
                {
                    @Override
                    public void onComplete(@NonNull Task task)
                    {
                        Log.d("APP", "signInAnonymously:onComplete:" + task.isSuccessful());

                        if (!task.isSuccessful())
                        {
                            Log.w("APP", "signInAnonymously", task.getException());
                        }
                    }
                });


    }
}

Error received when connecting through Mobile Data:

signInAnonymously failure: 
                                                  com.google.firebase.FirebaseNetworkException: A network error (such as
  timeout, interrupted connection or unreachable host) has occurred.
                                                      at com.google.android.gms.internal.zzblv.zzce(Unknown Source)
                                                      at com.google.android.gms.internal.zzbls$zzj.zza(Unknown Source)
                                                      at com.google.android.gms.internal.zzbmd.zzcf(Unknown Source)
                                                      at com.google.android.gms.internal.zzbmd$zza.onFailure(Unknown Source)
                                                      at com.google.android.gms.internal.zzbly$zza.onTransact(Unknown Source)
                                                      at android.os.Binder.execTransact(Binder.java:404)
                                                      at dalvik.system.NativeStart.run(Native Method)

Is there anything I can do to solve above issue or get more information about what is really causing problems. 
Mobile phone otherwise works well through Mobile Data and is successfully accessing Internet and Google Play Store.
Firebase version 10.2.0, Android API 19

Some additional information. Primary purpose of above authentication is access authentication for Firebase database.
If I allow non-authenticated access to database, I can connect and retrieve data through any kind of connection (Mobile Data and WiFi). Authentication is the only part that unexpectedly fails.

Solutions/Answers:

Solution 1:

Found a previous answer might be related

https://stackoverflow.com/a/45397853/2735586

Firebase doesnt restrict any internet connection

Can you check the status of the mobile data connection using the following (code taken from https://developer.android.com/training/basics/network-ops/managing.html#check-connection)

private static final String DEBUG_TAG = "NetworkStatusExample";
...
ConnectivityManager connMgr = (ConnectivityManager)
        getSystemService(Context.CONNECTIVITY_SERVICE);

networkInfo = connMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
boolean isMobileConn = networkInfo.isConnected();

Log.d(DEBUG_TAG, "Mobile connected: " + isMobileConn);

check this for non-authenticated & authenticated access to DB to help you debug

References

Related:  Notification sending from firebase console but its showing failed status but sending to all device is mark as completed