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 276 forks source link

fix:MIUI 10.3.6 android 9.0 MI8. switch wifi to mobile doesn't response #403

Closed telenewbie closed 4 years ago

telenewbie commented 4 years ago

This PR introduces the following update:

[briefly describe your update, e.g. closes specified issue, fixes a bug, adds new unit test, etc.] On my phone. MOBILE: MIUI 10.3.6 PLATFORM: android 9

implementation 'com.github.pwittchen:reactivenetwork-rx2:3.0.6'

switch wifi to mobile doesn't response.

I find that.:#330 but wont fix on my phone.

codecov-io commented 4 years ago

Codecov Report

Merging #403 into RxJava2.x will not change coverage. The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           RxJava2.x     #403   +/-   ##
==========================================
  Coverage      83.15%   83.15%           
==========================================
  Files             11       11           
  Lines            457      457           
  Branches          38       38           
==========================================
  Hits             380      380           
  Misses            52       52           
  Partials          25       25
Impacted Files Coverage Δ
.../strategy/MarshmallowNetworkObservingStrategy.java 95.16% <100%> (ø) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 5a67199...f665c7f. Read the comment docs.

pwittchen commented 4 years ago

Hi,

Thanks for your PR. It's weird that this bug occurs only on your specific phone. I need to test this code and check documentation to verify that it doesn't break anything from the user perspective. You changed one method call and I have to check what's the difference between these two methods (old and new). It's interesting that they have the same types of parameters.

Regards, Piotr

rktx commented 4 years ago

Hello, @pwittchen I have very similar issue with Samsung S8 with Android version 9 API 28. Preconditions 1) Have a Wifi AP IOT device with no network avaible 2) Mobile phone has Mobile data and Wifi enabled When connected to the AP network device state isn't checked correctly and it always fails. Here is code example of it.

private fun observeDeviceConnectivity() =
        Observable.defer {
            connectToDevice()
            when {
                Build.VERSION.SDK_INT >= Build.VERSION_CODES.M -> {
                    ReactiveNetwork.observeNetworkConnectivity(this, MarshmallowNetworkObservingStrategy())
                }
                Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP -> {
                    ReactiveNetwork.observeNetworkConnectivity(this, LollipopNetworkObservingStrategy())
                }
                Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP -> {
                    ReactiveNetwork.observeNetworkConnectivity(this, PreLollipopNetworkObservingStrategy())
                }
                else -> {
                    ReactiveNetwork.observeNetworkConnectivity(this)
                }
            }
        }
            .filter { wifiManager.connectionInfo.ssid == "\"${DEVICE_SSID}\"" }
            .filter(ConnectivityPredicate.hasState(NetworkInfo.State.CONNECTED))
            .firstOrError()

It most of the time fails on line

.filter(ConnectivityPredicate.hasState(NetworkInfo.State.CONNECTED))

Behaviour i see is devices connects to AP device and fails to get correct state and continue with tasks, but when i disable Mobile network all works fine without issues. It only struggling most of the time when mobile network is enabled with around 10% chance to get it work randomly. I also tested on devices below API 28 and they worked fine. Even on API 29 worked fine without issues. Is it possible to improve something in the code on its a bug in library?