LAN access plugin network detection bug

Support for Android version of Total Commander

Moderators: white, Hacker, petermad, Stefan2

Post Reply
mkowalczuk
Junior Member
Junior Member
Posts: 3
Joined: 2012-01-30, 11:46 UTC

LAN access plugin network detection bug

Post by *mkowalczuk »

Hi,
I've ran into network detection bug in LAN access plugin on my Google TV (Logitech Revue) connected using Ethernet. I've got a message that the network is not connected and question whether I want to enable WiFi. I can provide more info (eg. logcat), if you need it.

Edit:
The device is running Android 3.1, so it doesn't have ConnectivityManager.TYPE_ETHERNET, which is available from API level 13 (3.2).
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48083
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

Try to allow connections over mobile phone connections in the context menu - Properties of the LAN plugin. Then it will not check whether it's connected via LAN or not.

Btw, I'm not using TYPE_INTERNET. I'm using the following code to check for a working Wifi connection:

Code: Select all

	public boolean checkConnect(ContextWrapper service) {
		boolean connected=false;
		try { 
			NetworkInfo ni;
			ConnectivityManager cm=(ConnectivityManager)service.getSystemService(Context.CONNECTIVITY_SERVICE);
			ni=cm.getActiveNetworkInfo();
			connected=ni!=null;
			if (!allowSmbViaPhone && connected) {
				connected=ni.getType()==ConnectivityManager.TYPE_WIFI;
			}
		} catch (Exception e) {
			connected=false;
		}
		return connected;
	}
This seems to work fine on all phones so far. Note: Since the plugin is a service, I'm using a service handle for calling getSystemService. Maybe the CONNECTIVITY_SERVICE is missing on your device.
Author of Total Commander
https://www.ghisler.com
mkowalczuk
Junior Member
Junior Member
Posts: 3
Joined: 2012-01-30, 11:46 UTC

Post by *mkowalczuk »

As you wrote - you're checking for a working WiFi connection, which in my opinion is a wrong approach. I'd rather check if the connection isn't mobile, like this:

Code: Select all

if (!allowSmbViaPhone && connected) { 
    connected=ni.getType()!=ConnectivityManager.TYPE_MOBILE;
}
I guess adding checks for WIMAX and other MOBILE_* types could be also a good idea.

Although my device has API level 12, it correctly returns getType() == 9 and getTypeName() == "ETHERNET" (I've just checked it with a simple app).

Maybe you should change your preference name to "Connections only on WiFi" which would be more accurate for the check you're making? Anyway, it's somehow unintuitive that I need to allow "connections via phone" to make Ethernet work in LAN plugin... ;)
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48083
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

Thanks for the info. It seems that there are multiple possible mobile types. There is no TYPE_ETHERNET, so I will change the code to:

Code: Select all

				int type=ni.getType();
				connected=type==ConnectivityManager.TYPE_WIFI || type==9;
What do you think?
Author of Total Commander
https://www.ghisler.com
mkowalczuk
Junior Member
Junior Member
Posts: 3
Joined: 2012-01-30, 11:46 UTC

Post by *mkowalczuk »

It should work fine, but I don't like the hardcoded value. You can bump your targetSdkVersion to newest API level and do it this way:

Code: Select all

if (!(connected = type==ConnectivityManager.TYPE_WIFI)) {
  if (Build.VERSION.SDK_INT >= 13)
    connected = type==ConnectivityManager.TYPE_ETHERNET;
  else
    connected = ni.getTypeName().equals("ETHERNET");
}
Starburry
Junior Member
Junior Member
Posts: 2
Joined: 2012-04-16, 11:08 UTC
Contact:

Post by *Starburry »

Thanks for sharing the info. It works really great for my phone! This is a great plugin!
Post Reply