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

Internet connectivity issue: Could not establish connection with WalledGardenStrategy #464

Open mirwisek opened 1 year ago

mirwisek commented 1 year ago

Internet connected state is misleading I added the library to my projects and I'm only observing internet connectivity. It is always returning false even when my wifi is working fine. To confirm that, I observed network state and it is returning CONNECTED while internet connectivity is showing false.

To Reproduce Steps to reproduce the behavior:

  1. I just tested the Kotlin sample nothing fancy

Expected behavior It should show that internet is connected while Network state is CONNECTED

Screenshots If applicable, add screenshots to help explain your problem.

Smartphone:

Error

I'm continuously getting the following error after each 2 seconds. It seems the library is pinging a URL that is http (Not permitted).


E/ReactiveNetwork: Could not establish connection with WalledGardenStrategy
    java.io.IOException: Cleartext HTTP traffic to clients3.google.com not permitted
        at com.android.okhttp.HttpHandler$CleartextURLFilter.checkURLPermitted(HttpHandler.java:127)
        at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:462)
        at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:411)
        at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:542)
        at com.github.pwittchen.reactivenetwork.library.rx2.internet.observing.strategy.WalledGardenInternetObservingStrategy.isConnected(WalledGardenInternetObservingStrategy.java:109)
        at com.github.pwittchen.reactivenetwork.library.rx2.internet.observing.strategy.WalledGardenInternetObservingStrategy$1.apply(WalledGardenInternetObservingStrategy.java:66)
        at com.github.pwittchen.reactivenetwork.library.rx2.internet.observing.strategy.WalledGardenInternetObservingStrategy$1.apply(WalledGardenInternetObservingStrategy.java:64)
        at io.reactivex.internal.operators.observable.ObservableMap$MapObserver.onNext(ObservableMap.java:57)
        at io.reactivex.internal.operators.observable.ObservableInterval$IntervalObserver.run(ObservableInterval.java:82)
        at io.reactivex.Scheduler$PeriodicDirectTask.run(Scheduler.java:532)
        at io.reactivex.Scheduler$Worker$PeriodicTask.run(Scheduler.java:479)
        at io.reactivex.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:66)
        at io.reactivex.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:57)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:920)
pwittchen commented 1 year ago

Thanks for reporting this issue. It looks like clear text traffic configuration is missing. Please, have a look at this paragraph: https://github.com/pwittchen/ReactiveNetwork#cleartext-traffic . Moreover, if you want to use WalledGardenInternetObservingStrategy, please update HTTP response code via InternetObservingSettings. E.g set it to 200 because default is 204. You can also try to set different custom host for checking connectivity via InternetObsevingSettings if clients3.google.com does not work in your country.

All of that is described in details in documentation in README.md.

Regards, Piotr