|
|
@ -344,31 +344,27 @@ public class Helper {
|
|
|
|
if (active == null) {
|
|
|
|
if (active == null) {
|
|
|
|
if (log)
|
|
|
|
if (log)
|
|
|
|
EntityLog.log(context, "isMetered: no active network");
|
|
|
|
EntityLog.log(context, "isMetered: no active network");
|
|
|
|
else
|
|
|
|
|
|
|
|
Log.i(Helper.TAG, "isMetered: no active network");
|
|
|
|
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (log)
|
|
|
|
Log.i(Helper.TAG, "isMetered: active info=" + cm.getNetworkInfo(active));
|
|
|
|
Log.i(Helper.TAG, "isMetered: active info=" + cm.getNetworkInfo(active));
|
|
|
|
|
|
|
|
|
|
|
|
NetworkCapabilities caps = cm.getNetworkCapabilities(active);
|
|
|
|
NetworkCapabilities caps = cm.getNetworkCapabilities(active);
|
|
|
|
if (caps == null) {
|
|
|
|
if (caps == null) {
|
|
|
|
if (log)
|
|
|
|
if (log)
|
|
|
|
EntityLog.log(context, "isMetered: active no caps");
|
|
|
|
EntityLog.log(context, "isMetered: active no caps");
|
|
|
|
else
|
|
|
|
|
|
|
|
Log.i(Helper.TAG, "isMetered: active no caps");
|
|
|
|
|
|
|
|
// Assume metered
|
|
|
|
// Assume metered
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (log)
|
|
|
|
Log.i(Helper.TAG, "isMetered: active caps=" + caps);
|
|
|
|
Log.i(Helper.TAG, "isMetered: active caps=" + caps);
|
|
|
|
|
|
|
|
|
|
|
|
if (caps.hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_VPN)) {
|
|
|
|
if (caps.hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_VPN)) {
|
|
|
|
boolean unmetered = caps.hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED);
|
|
|
|
boolean unmetered = caps.hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED);
|
|
|
|
if (log)
|
|
|
|
if (log)
|
|
|
|
EntityLog.log(context, "isMetered: active not VPN unmetered=" + unmetered);
|
|
|
|
EntityLog.log(context, "isMetered: active not VPN unmetered=" + unmetered);
|
|
|
|
else
|
|
|
|
|
|
|
|
Log.i(Helper.TAG, "isMetered: active not VPN unmetered=" + unmetered);
|
|
|
|
|
|
|
|
return !unmetered;
|
|
|
|
return !unmetered;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -378,41 +374,41 @@ public class Helper {
|
|
|
|
if (networks != null)
|
|
|
|
if (networks != null)
|
|
|
|
for (Network network : networks) {
|
|
|
|
for (Network network : networks) {
|
|
|
|
NetworkInfo ni = cm.getNetworkInfo(network);
|
|
|
|
NetworkInfo ni = cm.getNetworkInfo(network);
|
|
|
|
|
|
|
|
if (log)
|
|
|
|
Log.i(Helper.TAG, "isMetered: underlying info=" + ni);
|
|
|
|
Log.i(Helper.TAG, "isMetered: underlying info=" + ni);
|
|
|
|
|
|
|
|
|
|
|
|
caps = cm.getNetworkCapabilities(network);
|
|
|
|
caps = cm.getNetworkCapabilities(network);
|
|
|
|
if (caps == null) {
|
|
|
|
if (caps == null) {
|
|
|
|
if (log)
|
|
|
|
if (log)
|
|
|
|
EntityLog.log(context, "isMetered: no underlying caps");
|
|
|
|
EntityLog.log(context, "isMetered: no underlying caps");
|
|
|
|
else
|
|
|
|
|
|
|
|
Log.i(Helper.TAG, "isMetered: no underlying caps");
|
|
|
|
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (log)
|
|
|
|
Log.i(Helper.TAG, "isMetered: underlying caps=" + caps);
|
|
|
|
Log.i(Helper.TAG, "isMetered: underlying caps=" + caps);
|
|
|
|
|
|
|
|
|
|
|
|
if (caps.hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_VPN)) {
|
|
|
|
if (caps.hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_VPN)) {
|
|
|
|
|
|
|
|
if (log)
|
|
|
|
Log.i(Helper.TAG, "isMetered: underlying caps=" + caps);
|
|
|
|
Log.i(Helper.TAG, "isMetered: underlying caps=" + caps);
|
|
|
|
|
|
|
|
|
|
|
|
if (ni != null && ni.isConnected()) {
|
|
|
|
if (ni != null && ni.isConnected()) {
|
|
|
|
|
|
|
|
if (log)
|
|
|
|
Log.i(Helper.TAG, "isMetered: underlying is connected");
|
|
|
|
Log.i(Helper.TAG, "isMetered: underlying is connected");
|
|
|
|
|
|
|
|
|
|
|
|
if (caps.hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED)) {
|
|
|
|
if (caps.hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED)) {
|
|
|
|
if (log)
|
|
|
|
if (log)
|
|
|
|
EntityLog.log(context, "isMetered: underlying is unmetered");
|
|
|
|
EntityLog.log(context, "isMetered: underlying is unmetered");
|
|
|
|
else
|
|
|
|
|
|
|
|
Log.i(Helper.TAG, "isMetered: underlying is unmetered");
|
|
|
|
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if (log)
|
|
|
|
Log.i(Helper.TAG, "isMetered: underlying is disconnected");
|
|
|
|
Log.i(Helper.TAG, "isMetered: underlying is disconnected");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (log)
|
|
|
|
if (log)
|
|
|
|
EntityLog.log(context, "isMetered: underlying assume metered");
|
|
|
|
EntityLog.log(context, "isMetered: underlying assume metered");
|
|
|
|
else
|
|
|
|
|
|
|
|
Log.i(Helper.TAG, "isMetered: underlying assume metered");
|
|
|
|
|
|
|
|
// Assume metered
|
|
|
|
// Assume metered
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|