Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem when receiving internet connectivity in Android P (API 28) #299

Closed
danielbeleza opened this issue Sep 18, 2018 · 11 comments

Comments

@danielbeleza
Copy link

commented Sep 18, 2018

Hi guys! Great job with this lib!

I just wanted to report a small issue that I'm having while receiving internet connectivity.

I'm using the following:

        return ReactiveNetwork.observeInternetConnectivity(InternetObservingSettings
                .initialInterval(DEFAULT_INITIAL_PING_INTERVAL_IN_MS)
                .interval(DEFAULT_PING_INTERVAL_IN_MS)
                .host(DEFAULT_PING_HOST)
                .port(DEFAULT_PING_PORT)
                .timeout(DEFAULT_PING_TIMEOUT_IN_MS)
                .errorHandler(errorHandler)
                .build());

This is always returning false, but just in Android P. Any other version works fine.

I read about Android P is restricting network status access and I'm not sure if there can be a problem related to that, what do you guys think? Have any of you found a similar issue and respective solution?

Thanks in advance!

@pwittchen

This comment has been minimized.

Copy link
Owner

commented Sep 18, 2018

Hi @danielbeleza,

Thanks for reporting this issue, I'll verify it on Android P.
Can you provide any resource regarding network status access on Android P?
It may be helpful during resolving this issue.

Regards,
Piotr

@danielbeleza

This comment has been minimized.

Copy link
Author

commented Sep 19, 2018

Thanks for the quick response!

There isn't any error or exception being throwed. The thing is it simply returns false, and our app reacts according to that response. In our case we show a no connection screen.

If I use the NetworkInfo class to get access to connectivity, it returns true, and everything works fine.

@pwittchen

This comment has been minimized.

Copy link
Owner

commented Sep 19, 2018

I haven't investigated it yet, but I have two suggestions for now:

  1. Ensure you have appropriate permissions in your AndroidManifest.xml file:
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
  1. Try to change strategy for observing Internet connection. Default strategy is WalledGardenInternetObservingStrategy and maybe this implementation has some issues related to Android P. There's also another strategy called SocketInternetObservingStrategy. You can set it via InternetObservingSettings as follows:
InternetObservingSettings
  .strategy(new SocketInternetObservingStrategy())
  .host(...)
  .port(...)
  ... // other settings go here
  .build()

Moreover, you can also use observeNetworkConnectivity(...) method, which checks network connectivity only (most WiFi networks have an Internet access, but they don't have to).

@danielbeleza

This comment has been minimized.

Copy link
Author

commented Sep 19, 2018

I had already implemented the first suggestion, but not the second. Even so, it didn't work.

We really want to validate more than just the network connectivity, but for now, we will use it as a workaround. I look forward for any updated on this.

Thank you for your help!
Best regards,
Daniel Beleza

@herald25

This comment has been minimized.

Copy link

commented Sep 21, 2018

up for this I can't receive return value in Android P.

@pwittchen

This comment has been minimized.

Copy link
Owner

commented Sep 21, 2018

@herald25 What do you mean by "I can't receive return value"? This observable should return a value. Either true or false. Depending on timeout, remote server and its latency, you can receive value sooner or later.

@pwittchen

This comment has been minimized.

Copy link
Owner

commented Sep 21, 2018

Okay,

I know, what's going on.
In the debug I get the following error:

Cleartext HTTP traffic not permitted

It's related to the security issues. Starting with Android 9.0 (API level 28), cleartext support is disabled by default.

The quickfix will be setting usesCleartextTraffic to true in the application tag in AndroidManifest.xml

<application
  ...
  android:usesCleartextTraffic="true" >

You can check this commit: f1b21ba to see how it's done in the sample apps.

You can also read about more details and other options of dealing with this problem here: https://stackoverflow.com/questions/45940861/android-8-cleartext-http-traffic-not-permitted

I've added task in #300 regarding documentation of this thing.

I think, it's clear now and we can close this issue.

@pwittchen pwittchen closed this Sep 21, 2018

@MikolajKakol

This comment has been minimized.

Copy link

commented Feb 12, 2019

hi, @pwittchen sorry for bothering but wouldn't it better/enough just to switch to

https://clients3.google.com/generate_204
in https://github.com/pwittchen/ReactiveNetwork/blob/RxJava2.x/library/src/main/java/com/github/pwittchen/reactivenetwork/library/rx2/internet/observing/strategy/WalledGardenInternetObservingStrategy.java
or add ability to switch to https?

@pwittchen

This comment has been minimized.

Copy link
Owner

commented Feb 12, 2019

Hi @MikolajKakol,

Thanks for your message. I think issue discussed in this topic is just related to Android P and clearTextTraffic. Generating 204 code with Google service may be not enough in that case since Android P.

@MikolajKakol

This comment has been minimized.

Copy link

commented Feb 13, 2019

Ok, I thought that on Android P would be enough to replace any clear text communication with secure one. I'm getting on emulator:

java.io.IOException: Cleartext HTTP traffic to clients3.google.com not permitted

Why wouldn't changing to https in WalledGardenInternetObservingStrategy fix this issue?

@pwittchen

This comment has been minimized.

Copy link
Owner

commented Feb 13, 2019

Hm, you may be right. according to the documentation, replacing http with https in

may fix this issue. I'll check that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.