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

Google pixel wifi change event is received in 30 sec delay #460

Open seladev opened 3 years ago

seladev commented 3 years ago

Describe the bug I am using this code for listening to wifi changes - ReactiveNetwork.observeNetworkConnectivity(context) .subscribeOn(Schedulers.io()) .filter(ConnectivityPredicate.hasType(NetworkCapabilities.TRANSPORT_WIFI)) .observeOn(AndroidSchedulers.mainThread()) .subscribe({ logWarning("###### change network = $it") },{ })

I am testing the code in different devices and its work, but in Google pixel 3a i am receiving the wifi concavity change event in 30 seconds delay. In Samsung device i am receiving the wifi concavity change event immediately

To Reproduce Steps to reproduce the behavior:

  1. Turn Off Wifi
  2. Open activity \ fragment that with the specific code
  3. Turn On Wifi in the device
  4. observe subscribe in observeNetworkConnectivity
  5. observe Wifi connection in the Device
  6. See when the Wifi connection success and when observeNetworkConnectivity subscribe received
  7. Wifi connect event received after 30 seconds from the device Wifi connection

Expected behavior The Wifi connect in the same time

Smartphone (please complete the following information):

pwittchen commented 3 years ago

Thanks for reporting this.

If you observe different behavior on two different devices with the same code where the only difference is delay, then this is clearly hardware issue and library cannot do anything about this. It can be also Android OS issue, but still it's not related to the library.

Regards, Piotr

seladev commented 3 years ago

Thanks for your quick answer

When i am listening to wifi changes with BroadcastReceiver i can see that the wifi connection event immediately. This is the BroadcastReceiver: receiver = new NetworkChangeReceiver(); IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); intentFilter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED); registerReceiver(receiver, intentFilter); receiver.setConnectionListener(this);

This is the logs: 2021-04-21 11:37:21.943----- NetworkChangeReceiver ###### change network wifi enable = false -------------------- 2021-04-21 11:37:49.358----- NetworkChangeReceiver ###### change network onReceive = android.net.conn.CONNECTIVITY_CHANGE -------------------- 2021-04-21 11:37:49.363----- NetworkChangeReceiver ###### change network wifi enable = true -------------------- 2021-04-21 11:37:49.370----- NetworkChangeReceiver ###### change network onReceive = android.net.conn.CONNECTIVITY_CHANGE -------------------- 2021-04-21 11:37:49.404----- NetworkChangeReceiver ###### change network wifi enable = true -------------------- 2021-04-21 11:38:19.325 Fragment -------------------- ###### change network = Connectivity{state=CONNECTED, detailedState=CONNECTED, type=1, subType=0, available=true, failover=false, roaming=false, typeName='WIFI', subTypeName='', reason='null', extraInfo=''} --------------------

pwittchen commented 3 years ago

In this receiver you are not using NetworkCapabilities.TRANSPORT_WIFI. I haven't tested library with this option. When you will use filter(ConnectivityPredicate.hasType(ConnectivityManager.TYPE_WIFI)) in the library, then you will get immediate result as well.

seladev commented 3 years ago

I tried this code filter(ConnectivityPredicate.hasType(ConnectivityManager.TYPE_WIFI)) It is the same behaviour - 30 sec delay

seladev commented 3 years ago

I also tried it with no filter - and It is the same behaviour - 30 sec delay