jamesmontemagno/ConnectivityPlugin

IsConnected on private network returns false

StefanCuypers opened this issue · 3 comments

If you are creating an issue for a BUG please fill out this information. If you are asking a question or requesting a feature you can delete the sections below.

Failure to fill out this information will result in this issue being closed. If you post a full stack trace in a bug it will be closed, please post it to http://gist.github.com and then post the link here.

Bug Information

Version Number of Plugin: v3.1.1
Device Tested On: Samsung Galaxy S8
Simulator Tested On:
Version of VS: 2017 - 15.7.4
Version of Xamarin: v3.1.0.583944
Versions of other things you are using:

Steps to reproduce the Behavior

Call CrossConnectivity.Current.IsConnected returns false when connected on internal WIFI with Internet traffic blocked by firewall (WIFI network on the device mentions that Internet may not be available).
Also IsReachable always returns false then, although we're connecting to an internal server.
We want to use the functionality on an internal WIFI network that has no Internet connectivity to check WIFI connectivity to an internal server.

Expected Behavior

IsConnected should return true since we're connected to a network.

Actual Behavior

IsConnected returns false.

Code snippet

        if (!CrossConnectivity.Current.IsConnected)
        {
            _lastCheckOperational = false;
            return NetworkStatus.NoNetworkActive;
        }

Screenshots

Does it say WiFi is connected for Connection types?

It is important to note that it is possible that IsConnected reports true but full access to the web is not available. Due to how connectivity works on each platform it can only guarantee that a connection is available. For instance the device may be connected to a Wi-Fi network, but the router is disconnected from the internet. In this instance Internet may be reported, but an active connection is not available.

It is also possible that IsConnected would report False for this very statement you said: WIFI network on the device mentions that Internet may not be available.

Android is telling us that there is no internet available on device, often this is the case when you need to log into a portal. You could just check if WiFi is a connection state and go from there.

This code is here that you can debug through to see what is returning false: https://github.com/jamesmontemagno/ConnectivityPlugin/blob/master/src/Connectivity.Plugin.Android/ConnectivityImplementation.cs#L58

Assumption is right here:

//check to see if it has the internet capability
if (!capabilities.HasCapability(NetCapability.Internet))
   continue;

https://developer.android.com/reference/android/net/NetworkCapabilities saying that internet is not available.

I tested using the source code and to my surprise that worked fine.
So after digging a little deeper I found that in version 3.1.1 (the latest on NuGet) the now commented line that checks 'NetCapability.Validated' is still present. Seems on the Samsung Phone 'NetCapability.Validated' means that you have connection to the Internet, so it returns false if a firewall blocks this.

Tested with v4.0.0.190-beta and there it works as expected.