mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-08-31 06:05:12 +00:00
Added an extra check to be really sure we are on data.
This commit is contained in:
@@ -6,6 +6,9 @@ import android.net.Network;
|
||||
import android.net.NetworkInfo;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.FileReader;
|
||||
import java.io.LineNumberReader;
|
||||
|
||||
public class NetworkHelper {
|
||||
|
||||
public static boolean isOnMobileNetwork(Context context) {
|
||||
@@ -27,7 +30,21 @@ public class NetworkHelper {
|
||||
Log.e(info.getTypeName(),""+info.isAvailable());
|
||||
if (info.isAvailable()) return false; //We are connected to at least one non-mobile network
|
||||
}
|
||||
return mobile;
|
||||
if (mobile) { //We suspect we are on a mobile net
|
||||
try {
|
||||
//Check the number of network neighbours, on data it should be 0
|
||||
LineNumberReader is = new LineNumberReader(new FileReader("/proc/net/arp"));
|
||||
is.skip(Long.MAX_VALUE);
|
||||
//Log.e("NetworkHelper", "procnetarp has " + is.getLineNumber() + " lines");
|
||||
if (is.getLineNumber() > 1) { //The first line are the headers
|
||||
return false; //I have neighbours, so this doesn't look like a mobile network
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e("NetworkHelper", "Exception reading procnetarp");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user