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

Default InternetObservingSettings object uses http, causing Android 9 to fail on clear-text traffic #379

Closed linster closed 4 years ago

linster commented 5 years ago

Describe the bug Default InternetObservingSettings object uses http, causing Android 9 to fail on clear-text traffic

To Reproduce Steps to reproduce the behavior:

  1. On Android 9, with wifi on, and connected to the internet, use ReactiveNetwork.observeInternetConnectivity() to get an Observable<Boolean>

Expected behavior Should return an Observable of true.

Actual Behaviour Exceptions are put into the Observable's error stream.

2019-09-23 13:21:05.955 23374-24469/com.redacted.redacted 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:115)
        at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:485)
        at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:434)
        at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:565)
        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)

Root cause In InternetObservingSettings.java, the default value for host uses HTTP. Since this is set here, the WalledGardenInternetObservingStrategy does not use it's DEFAULT_HOST parameter.

  /**
   * Settings builder, which contains default parameters
   */
  public final static class Builder {
    private int initialInterval = 0;
    private int interval = 2000;
    private String host = "http://clients3.google.com/generate_204";

Smartphone (please complete the following information):

pwittchen commented 5 years ago

Thanks for reporting this. It should be quick fix.

michaeltweed commented 5 years ago

Is this fixed by https://github.com/pwittchen/ReactiveNetwork/pull/376?

pwittchen commented 5 years ago

No, because http protocol is defined instead of https in the InternetObservingSettings class.

kokrokro commented 4 years ago

Excuse me, is this issue solved? Cause I'm using the last version, but it throws the same exception.

pwittchen commented 4 years ago

No. I was busy doing other stuff, so I haven't done it yet. I'll probably fix it later. I'm also open for PRs if you want to have it fixed sooner.

mahdi302 commented 4 years ago

Hi, M.r pwittchen. have you fixed this problem..? cause I'm using this library in my app and it's not working on android 9 version

soshial commented 4 years ago

I consider this quite a big problem. Will this be fixed?

pwittchen commented 4 years ago

fixed, it will be available in the next release (probably this week)