pwittchen / ReactiveNetwork

Android library listening network connection state and Internet connectivity with RxJava Observables
http://pwittchen.github.io/ReactiveNetwork/docs/RxJava2.x/
Apache License 2.0
2.53k stars 272 forks source link

MarshmallowNetworkObservingStrategy.java line 80 #462

Open agarajaev opened 2 years ago

agarajaev commented 2 years ago

The bug is reproduce only on 11 android when call ReactiveNetwork.observeNetworkConnectivity(context)

https://android-review.googlesource.com/c/platform/frameworks/base/+/1758029/

In ExoPlayer it is fixed like this https://github.com/google/ExoPlayer/commit/2e21208f639c7eb5baf5e7a3ae1180b13be3b733

android.net.ConnectivityManager.registerNetworkCallback (ConnectivityManager.java:4564) com.github.pwittchen.reactivenetwork.library.rx2.network.observing.strategy.MarshmallowNetworkObservingStrategy.observeNetworkConnectivity (MarshmallowNetworkObservingStrategy.java:80) com.github.pwittchen.reactivenetwork.library.rx2.ReactiveNetwork.observeNetworkConnectivity (ReactiveNetwork.java:92) com.github.pwittchen.reactivenetwork.library.rx2.ReactiveNetwork.observeNetworkConnectivity (ReactiveNetwork.java:73)

Could you please catch this exception in library? Thanks.

pwittchen commented 2 years ago

Thanks for reporting this. I'll have a look on that.

Fando commented 2 years ago

Hi there,

Thanks for a wonderful library. Just following up on this issue. It's a known bug in Android 11, which was fixed in Android 12. However, the only workaround for it in Android 11 requires catching the exception when calling ConnectivityManager.registerNetworkCallback, in MarshmallowNetworkObservingStrategy.observeNetworkConnectivity.

Please catch this exception by scheduling a periodic retry call to registerNetworkCallback, mmmkay!

Cheers!

Caused by java.lang.SecurityException
Package android does not belong to xxxxx
android.os.Parcel.createExceptionOrNull (Parcel.java:2385)
android.os.Parcel.createException (Parcel.java:2369)
android.os.Parcel.readException (Parcel.java:2352)
android.os.Parcel.readException (Parcel.java:2294)
android.net.IConnectivityManager$Stub$Proxy.listenForNetwork (IConnectivityManager.java:4703)
android.net.ConnectivityManager.sendRequestForNetwork (ConnectivityManager.java:4191)
android.net.ConnectivityManager.registerNetworkCallback (ConnectivityManager.java:4594)
android.net.ConnectivityManager.registerNetworkCallback (ConnectivityManager.java:4564)
com.github.pwittchen.reactivenetwork.library.rx2.network.observing.strategy.MarshmallowNetworkObservingStrategy.observeNetworkConnectivity (MarshmallowNetworkObservingStrategy.java:40)
com.github.pwittchen.reactivenetwork.library.rx2.ReactiveNetwork.observeNetworkConnectivity (ReactiveNetwork.java:10)
com.github.pwittchen.reactivenetwork.library.rx2.ReactiveNetwork.observeNetworkConnectivity (ReactiveNetwork.java:29)
(ReactiveNetworkWrapper.java:2)
...
HappyDr0id commented 2 years ago

Hi 👋 +1 about the comment just above, I also encounter this crash on Android 11 devices. I'm catching the exception but if the library could handle it in a nicer way, that would be great 🙂

guillaumeAgisHeetch commented 2 years ago

Hello, any update ?

Thanks