在 Android Nougat 7.1.1 上继续使用应用程序后,它开始在后台崩溃,直到手动启动。从 Firebase 我得到以下日志:
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)
我检查了android marshmallow 源代码,它不包含引发此错误的代码,但master 分支确实如此,因此我们可以断定此错误是 Nougat 特定的。
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);
}
}
请求计数器多久重置一次?
当接近限制时,如何获取当前网络请求计数以减少活动?