VPN+Wifi, not treated as metered (#5613)

This commit is contained in:
Tony Tam 2021-12-27 08:18:19 -08:00 committed by GitHub
parent a399702da2
commit 7768aea11d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 0 deletions

View File

@ -96,6 +96,16 @@ public class NetworkUtils {
private static boolean isNetworkMetered() {
ConnectivityManager connManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
NetworkCapabilities capabilities = connManager.getNetworkCapabilities(
connManager.getActiveNetwork());
if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)
&& capabilities.hasTransport(NetworkCapabilities.TRANSPORT_VPN)) {
return false;
}
}
return connManager.isActiveNetworkMetered();
}