mirror of https://github.com/M66B/FairEmail.git
NetworkInfo is deprecated in Android Q
This commit is contained in:
parent
b023005698
commit
4c797d553c
|
@ -527,13 +527,13 @@ public class Helper {
|
||||||
long size = 0;
|
long size = 0;
|
||||||
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||||
|
|
||||||
NetworkInfo ani = cm.getActiveNetworkInfo();
|
Network active = null;
|
||||||
size += write(os, "active=" + ani + "\r\n\r\n");
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
|
||||||
|
active = cm.getActiveNetwork();
|
||||||
|
|
||||||
for (Network network : cm.getAllNetworks()) {
|
for (Network network : cm.getAllNetworks()) {
|
||||||
NetworkInfo ni = cm.getNetworkInfo(network);
|
|
||||||
NetworkCapabilities caps = cm.getNetworkCapabilities(network);
|
NetworkCapabilities caps = cm.getNetworkCapabilities(network);
|
||||||
size += write(os, "network=" + ni + " capabilities=" + caps + "\r\n\r\n");
|
size += write(os, (network.equals(active) ? "active=" : "network=") + network + " capabilities=" + caps + "\r\n\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
db.attachment().setDownloaded(attachment.id, size);
|
db.attachment().setDownloaded(attachment.id, size);
|
||||||
|
@ -726,7 +726,7 @@ public class Helper {
|
||||||
EntityLog.log(context, "isMetered: no active network");
|
EntityLog.log(context, "isMetered: no active network");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
NetworkInfo ani = cm.getNetworkInfo(active);
|
NetworkInfo ani = cm.getNetworkInfo(active);
|
||||||
if (log)
|
if (log)
|
||||||
EntityLog.log(context, "isMetered: active info=" + ani);
|
EntityLog.log(context, "isMetered: active info=" + ani);
|
||||||
|
@ -736,7 +736,7 @@ public class Helper {
|
||||||
EntityLog.log(context, "isMetered: active network not connected");
|
EntityLog.log(context, "isMetered: active network not connected");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
NetworkCapabilities caps = cm.getNetworkCapabilities(active);
|
NetworkCapabilities caps = cm.getNetworkCapabilities(active);
|
||||||
if (caps == null) {
|
if (caps == null) {
|
||||||
if (log)
|
if (log)
|
||||||
|
@ -747,6 +747,24 @@ public class Helper {
|
||||||
if (log)
|
if (log)
|
||||||
EntityLog.log(context, "isMetered: active caps=" + caps);
|
EntityLog.log(context, "isMetered: active caps=" + caps);
|
||||||
|
|
||||||
|
if (!caps.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)) {
|
||||||
|
if (log)
|
||||||
|
EntityLog.log(context, "isMetered: no internet");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!caps.hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED)) {
|
||||||
|
if (log)
|
||||||
|
EntityLog.log(context, "isMetered: active restricted");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!caps.hasCapability(NetworkCapabilities.NET_CAPABILITY_FOREGROUND)) {
|
||||||
|
if (log)
|
||||||
|
EntityLog.log(context, "isMetered: active background");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
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)
|
||||||
|
@ -760,10 +778,11 @@ public class Helper {
|
||||||
Network[] networks = cm.getAllNetworks();
|
Network[] networks = cm.getAllNetworks();
|
||||||
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)
|
if (log)
|
||||||
Log.i("isMetered: underlying info=" + ni);
|
Log.i("isMetered: underlying info=" + ni);
|
||||||
|
*/
|
||||||
caps = cm.getNetworkCapabilities(network);
|
caps = cm.getNetworkCapabilities(network);
|
||||||
if (caps == null) {
|
if (caps == null) {
|
||||||
if (log)
|
if (log)
|
||||||
|
@ -774,13 +793,28 @@ public class Helper {
|
||||||
if (log)
|
if (log)
|
||||||
Log.i("isMetered: underlying caps=" + caps);
|
Log.i("isMetered: underlying caps=" + caps);
|
||||||
|
|
||||||
|
if (!caps.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)) {
|
||||||
|
if (log)
|
||||||
|
EntityLog.log(context, "isMetered: underlying no internet");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!caps.hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED)) {
|
||||||
|
if (log)
|
||||||
|
EntityLog.log(context, "isMetered: underlying restricted");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!caps.hasCapability(NetworkCapabilities.NET_CAPABILITY_FOREGROUND)) {
|
||||||
|
if (log)
|
||||||
|
EntityLog.log(context, "isMetered: underlying background");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (caps.hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_VPN)) {
|
if (caps.hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_VPN)) {
|
||||||
underlying = true;
|
underlying = true;
|
||||||
|
|
||||||
if (log)
|
//if (ni != null && ni.isConnected()) {
|
||||||
Log.i("isMetered: underlying caps=" + caps);
|
|
||||||
|
|
||||||
if (ni != null && ni.isConnected()) {
|
|
||||||
if (log)
|
if (log)
|
||||||
Log.i("isMetered: underlying is connected");
|
Log.i("isMetered: underlying is connected");
|
||||||
|
|
||||||
|
@ -789,10 +823,10 @@ public class Helper {
|
||||||
EntityLog.log(context, "isMetered: underlying is unmetered");
|
EntityLog.log(context, "isMetered: underlying is unmetered");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
//} else {
|
||||||
if (log)
|
// if (log)
|
||||||
Log.i("isMetered: underlying is disconnected");
|
// Log.i("isMetered: underlying is disconnected");
|
||||||
}
|
//}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue