Check for VPN

This commit is contained in:
M66B
2020-02-12 12:56:19 +01:00
parent 2460e6c08d
commit 033efe23d3
3 changed files with 34 additions and 0 deletions

View File

@@ -277,6 +277,24 @@ public class ConnectionHelper {
return true;
}
static boolean vpnActive(Context context) {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (cm == null)
return false;
try {
for (Network network : cm.getAllNetworks()) {
NetworkCapabilities caps = cm.getNetworkCapabilities(network);
if (caps != null && caps.hasTransport(NetworkCapabilities.TRANSPORT_VPN))
return true;
}
} catch (Throwable ex) {
Log.w(ex);
}
return false;
}
static boolean airplaneMode(Context context) {
return Settings.System.getInt(context.getContentResolver(),
Settings.Global.AIRPLANE_MODE_ON, 0) != 0;