Fixed is metered logic

pull/147/head
M66B 6 years ago
parent e1b52d113d
commit 2d8227582f

@ -310,11 +310,6 @@ public class Helper {
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.M) if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.M)
return cm.isActiveNetworkMetered(); return cm.isActiveNetworkMetered();
if (!cm.isActiveNetworkMetered()) {
Log.i(Helper.TAG, "isMetered: active network is unmetered");
return false;
}
Network active = cm.getActiveNetwork(); Network active = cm.getActiveNetwork();
if (active == null) { if (active == null) {
Log.i(Helper.TAG, "isMetered: no active network"); Log.i(Helper.TAG, "isMetered: no active network");
@ -333,6 +328,7 @@ public class Helper {
Log.i(Helper.TAG, "isMetered: active not connected"); Log.i(Helper.TAG, "isMetered: active not connected");
return null; return null;
} }
NetworkCapabilities caps = cm.getNetworkCapabilities(active); NetworkCapabilities caps = cm.getNetworkCapabilities(active);
if (caps == null) { if (caps == null) {
Log.i(Helper.TAG, "isMetered: active no caps"); Log.i(Helper.TAG, "isMetered: active no caps");
@ -341,17 +337,12 @@ public class Helper {
Log.i(Helper.TAG, "isMetered: active caps=" + caps); Log.i(Helper.TAG, "isMetered: active caps=" + caps);
boolean unmetered = caps.hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED); if (caps.hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_VPN) &&
if (unmetered) { caps.hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED)) {
Log.i(Helper.TAG, "isMetered: active unmetered"); Log.i(Helper.TAG, "isMetered: active not VPN unmetered");
return false; return false;
} }
if (caps.hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_VPN)) {
Log.i(Helper.TAG, "isMetered: active metered");
return true;
}
// VPN: evaluate underlying networks // VPN: evaluate underlying networks
Network[] networks = cm.getAllNetworks(); Network[] networks = cm.getAllNetworks();

Loading…
Cancel
Save