Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Nougat: Too many NetworkRequests filed

After continuos use of application on Android Nougat 7.1.1 it started crashing in background, until started up manually. From Firebase I got following log:

Caused by java.lang.IllegalArgumentException: Too many NetworkRequests filed
android.os.Parcel.readException (Parcel.java:1688)
android.os.Parcel.readException (Parcel.java:1637)
android.net.IConnectivityManager$Stub$Proxy.pendingListenForNetwork (IConnectivityManager.java:2460)
android.net.ConnectivityManager.registerNetworkCallback (ConnectivityManager.java:3127)
com.XXX.XX.location.GPSControl$Companion.setInitialized (GPSControl.java)
__null__.getGApiClient (GPSControl.java)
__null__.setGApiClient (GPSControl.java)
__null__.setConnMan (GPSControl.java)
__null__.setSf (GPSControl.java)
__null__.init (GPSControl.java)
__null__.getPI (GPSControl.java)
__null__.triggerLocation (GPSControl.java)
__null__.triggerLocation$default (GPSControl.java)
__null__.access$getInitialized$p (GPSControl.java)
com.XXX.XX.KGL.afterLoginSetup (KGL.java)
com.XXX.XX.KGL.onCreate (KGL.java)
android.app.Instrumentation.callApplicationOnCreate (Instrumentation.java:1025)
android.app.ActivityThread.handleBindApplication (ActivityThread.java:5460)
android.app.ActivityThread.-wrap2 (ActivityThread.java)
android.app.ActivityThread$H.handleMessage (ActivityThread.java:1556)
android.os.Handler.dispatchMessage (Handler.java:102)
android.os.Looper.loop (Looper.java:154)
android.app.ActivityThread.main (ActivityThread.java:6176)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:888)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:778)

I checked android marshmallow source code, it doesn't contain code, that throws this error, but master branch does, so we can conclude this error is Nougat specific.

    private void enforceRequestCountLimit() {
        synchronized (mUidToNetworkRequestCount) {
            int networkRequests = mUidToNetworkRequestCount.get(mUid, 0) + 1;
            if (networkRequests >= MAX_NETWORK_REQUESTS_PER_UID) { //MAX_NETWORK_REQUESTS_PER_UID == 100
                throw new IllegalArgumentException("Too many NetworkRequests filed");
            }
            mUidToNetworkRequestCount.put(mUid, networkRequests);
        }
    }

How often does counter of request resets?

How I can get current network request count to decrease activity when it's close to limit?

like image 830
Dima Rostopira Avatar asked Jan 31 '17 12:01

Dima Rostopira


1 Answers

Quoting @CommonsWare from the question comments:

From my reading of the source code, you might get this from too many registerNetworkCallback() calls without corresponding unregisterNetworkCallback() calls. Make sure that you are cleaning up these callbacks. – CommonsWare Jan 31 '17 at 13:06

like image 187
Nino van Hooff Avatar answered Nov 10 '22 02:11

Nino van Hooff