speedchecker / speedchecker-sdk-android

25 stars 5 forks source link

SDK not destroying TelephonyManager listener? #6

Closed Chambana closed 3 years ago

Chambana commented 3 years ago

If I run enough Speed Tests via the SDK, I eventually get this exception thrown in Android 11. It looks like the TelephonyManager objects might not be getting destroyed and are re-added after every test?

E/AndroidRuntime: FATAL EXCEPTION: Thread-2307 Process: com.google.android.gms.location.sample.locationupdates, PID: 14509 java.lang.IllegalStateException: Pid 14509 has exceeded the number of permissible registered listeners. Ignoring request to add. at android.os.Parcel.createExceptionOrNull(Parcel.java:2381) at android.os.Parcel.createException(Parcel.java:2357) at android.os.Parcel.readException(Parcel.java:2340) at android.os.Parcel.readException(Parcel.java:2282) at com.android.internal.telephony.ITelephonyRegistry$Stub$Proxy.listenForSubscriber(ITelephonyRegistry.java:1105) at android.telephony.TelephonyRegistryManager.listenForSubscriber(TelephonyRegistryManager.java:231) at android.telephony.TelephonyManager.listen(TelephonyManager.java:5727) at com.speedchecker.android.sdk.b.a.e$3.run(SpeedTest.java:770) at java.lang.Thread.run(Thread.java:923) Caused by: android.os.RemoteException: Remote stack trace: at com.android.server.TelephonyRegistry.add(TelephonyRegistry.java:1158) at com.android.server.TelephonyRegistry.listen(TelephonyRegistry.java:833) at com.android.server.TelephonyRegistry.listenForSubscriber(TelephonyRegistry.java:801) at com.android.internal.telephony.ITelephonyRegistry$Stub.onTransact(ITelephonyRegistry.java:453) at android.os.Binder.execTransactInternal(Binder.java:1159)

Chambana commented 3 years ago

More details on the listener limit added in Android 11

https://stackoverflow.com/questions/64961084/phonestatelistener-is-exceeding-the-number-of-permissible-registered-listeners-o/65155368#65155368

Chambana commented 3 years ago

Confirmed that this behavior does not manifest in Android 10, but is highly reproducible in Android 11.

DenysYakubets commented 3 years ago

Hello @Chambana, thanks for the request.

SDK use PhoneStateListener.LISTEN_NONE to unregister all listeners. So, theoretically, it should not be a reason. But anyway, I will try to reproduce the bug and fix it. Thanks!

Chambana commented 3 years ago

Thanks for checking. I think limit is around 50 listeners in Android 11.

Easy way to replicate the issue in Android 11 (not Android 10):

DenysYakubets commented 3 years ago

@Chambana Please, try new SDK version -> 4.2.129-demo

Unfortunately, I didn't have time to fully reproduce your flow but I think I got a point and fixed it. Btw, in your app example, location callback could be fired very frequently (e.g. 3 times during 10 seconds). Every startTest() call will interrupt the previous one. So, I think makes sense to handle location "spamming" and calling startTest() method.

I'm going to close this issue for now. Please, check if the new SDK version works properly for you. If not, then feel free to open the issue again.

Regards, Demys.

Chambana commented 3 years ago

Tested the updated library on Android 11 and can confirm it's fixed! Thank you.

mhd-zulqarnain commented 2 years ago

Hi @DenysYakubets

We are using the speedchecker SDK verison 4.2.154

This issue is reproducing on android 11 and 12 in our live app, but unable to reproduce at our end. Can you please look into this.

Stack trace:

Fatal Exception: java.lang.IllegalStateException: Pid 23191 has exceeded the number of permissible registered listeners. Ignoring request to add. at android.os.Parcel.createExceptionOrNull(Parcel.java:2433) at android.os.Parcel.createException(Parcel.java:2409) at android.os.Parcel.readException(Parcel.java:2392) at android.os.Parcel.readException(Parcel.java:2334) at com.android.internal.telephony.ITelephonyRegistry$Stub$Proxy.listenWithEventList(ITelephonyRegistry.java:1036) at android.telephony.TelephonyRegistryManager.listenFromListener(TelephonyRegistryManager.java:250) at android.telephony.TelephonyManager.listen(TelephonyManager.java:5999) at com.speedchecker.android.sdk.b.a.e$3.run(SpeedTest.java:768) at java.lang.Thread.run(Thread.java:920)