novoda / merlin

Observes network connection status & gives callbacks
Other
543 stars 79 forks source link

Android 9.0 Testing #172

Closed dev-hussein closed 5 years ago

dev-hussein commented 6 years ago

Problem

When test your repo it's not working on android 9.0 always return false.

Potential Solution

_I think you have to check https://developer.android.com/about/versions/pie/android-9.0-changes-all#restricted_access_to_wi-fi_location_and_connection_information_

Mecharyry commented 6 years ago

Hi @TuiyTuyHussein at the moment the library does not support android 9.0, we hope to be able to perform some updates on the library soon!

niltsiar commented 6 years ago

I've been looking into this error. The problem comes from these changes Framework Security Changes in API 28 Basically, for API 28+ no connection to clear text domains are permitted by default. Merlin is using http://connectivitycheck.android.com/generate_204 to test connectivity, so when the demo project is compiled targeting API 28 the PingTask is always returning false.

There are two possible solutions for the problem:

  1. Change the URL Merlin is using by default in Endpoint to https://connectivitycheck.android.com/generate_204
  2. Use a network security config file to allow clear text connections to the domain connectivitycheck.android.com

I've tested both solutions and they work well so it's just a matter of choosing what is best for the library.

This is the content of the network security config that I've tested

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
  <domain-config cleartextTrafficPermitted="true">
    <domain includeSubdomains="false">connectivitycheck.android.com</domain>
  </domain-config>
</network-security-config>

As a workaround until this issue is addressed by the library you have two options @TuiyTuyHussein

  1. Add the following code .withEndpoint(Endpoint.from("https://connectivitycheck.android.com/generate_204")) to Merlin.Builder() when you create your Merlin instance
  2. Create a network security config file for the application that uses Merlin (or add the relevant content if you already have one in your project)
ouchadam commented 6 years ago

I'm down for updating the default endpoint to use the https version, there's a slight performance hit but it should be negligible.

This might actually fix an issue with false positives from some wifi hotspots which force redirects on http to their hotspot login page

ouchadam commented 5 years ago

looks like #177 has been merged, the next release should contain this fix!