LAN access plugin network detection bug
Moderators: Hacker, petermad, Stefan2, white
-
- Junior Member
- Posts: 3
- Joined: 2012-01-30, 11:46 UTC
LAN access plugin network detection bug
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).
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).
- ghisler(Author)
- Site Admin
- Posts: 50386
- Joined: 2003-02-04, 09:46 UTC
- Location: Switzerland
- Contact:
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:
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.
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;
}
Author of Total Commander
https://www.ghisler.com
https://www.ghisler.com
-
- Junior Member
- Posts: 3
- Joined: 2012-01-30, 11:46 UTC
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:
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...
Code: Select all
if (!allowSmbViaPhone && connected) {
connected=ni.getType()!=ConnectivityManager.TYPE_MOBILE;
}
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...

- ghisler(Author)
- Site Admin
- Posts: 50386
- Joined: 2003-02-04, 09:46 UTC
- Location: Switzerland
- Contact:
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:
What do you think?
Code: Select all
int type=ni.getType();
connected=type==ConnectivityManager.TYPE_WIFI || type==9;
Author of Total Commander
https://www.ghisler.com
https://www.ghisler.com
-
- Junior Member
- Posts: 3
- Joined: 2012-01-30, 11:46 UTC
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");
}