summaryrefslogtreecommitdiff
path: root/app/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java')
-rw-r--r--app/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java57
1 files changed, 53 insertions, 4 deletions
diff --git a/app/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java b/app/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java
index 7dfacd91..0d4a8037 100644
--- a/app/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java
+++ b/app/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java
@@ -199,6 +199,8 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac
private boolean runningOnAndroidTV() {
UiModeManager uiModeManager = (UiModeManager) getSystemService(UI_MODE_SERVICE);
+ if (uiModeManager == null)
+ return false;
return uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION;
}
@@ -393,6 +395,13 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac
return;
}
String nativeLibraryDirectory = getApplicationInfo().nativeLibraryDir;
+ String tmpDir;
+ try {
+ tmpDir = getApplication().getCacheDir().getCanonicalPath();
+ } catch (IOException e) {
+ e.printStackTrace();
+ tmpDir = "/tmp";
+ }
// Write OpenVPN binary
String[] argv = VPNLaunchHelper.buildOpenvpnArgv(this);
@@ -439,7 +448,7 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac
processThread = (Runnable) mOpenVPN3;
mManagement = mOpenVPN3;
} else {
- processThread = new OpenVPNThread(this, argv, nativeLibraryDirectory);
+ processThread = new OpenVPNThread(this, argv, nativeLibraryDirectory, tmpDir);
mOpenVPNThread = processThread;
}
@@ -570,7 +579,8 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac
VpnStatus.logInfo(R.string.last_openvpn_tun_config);
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && mProfile.mAllowLocalLAN) {
+ boolean allowUnsetAF = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && !mProfile.mBlockUnusedAddressFamilies;
+ if (allowUnsetAF) {
allowAllAFFamilies(builder);
}
@@ -673,15 +683,34 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac
builder.addSearchDomain(mDomain);
String ipv4info;
+ String ipv6info;
+ if (allowUnsetAF) {
+ ipv4info = "(not set, allowed)";
+ ipv6info = "(not set, allowed)";
+ } else {
+ ipv4info = "(not set)";
+ ipv6info = "(not set)";
+ }
+
int ipv4len;
if (mLocalIP!=null) {
ipv4len=mLocalIP.len;
ipv4info=mLocalIP.mIp;
} else {
ipv4len = -1;
- ipv4info="(not set)";
}
- VpnStatus.logInfo(R.string.local_ip_info, ipv4info, ipv4len, mLocalIPv6, mMtu);
+
+ if (mLocalIPv6!=null)
+ {
+ ipv6info = mLocalIPv6;
+ }
+
+ if ((!mRoutes.getNetworks(false).isEmpty() || !mRoutesv6.getNetworks(false).isEmpty()) && isLockdownEnabledCompat())
+ {
+ VpnStatus.logInfo("VPN lockdown enabled (do not allow apps to bypass VPN) enabled. Route exclusion will not allow apps to bypass VPN (e.g. bypass VPN for local networks)");
+ }
+
+ VpnStatus.logInfo(R.string.local_ip_info, ipv4info, ipv4len, ipv6info, mMtu);
VpnStatus.logInfo(R.string.dns_server_info, TextUtils.join(", ", mDnslist), mDomain);
VpnStatus.logInfo(R.string.routes_info_incl, TextUtils.join(", ", mRoutes.getNetworks(true)), TextUtils.join(", ", mRoutesv6.getNetworks(true)));
VpnStatus.logInfo(R.string.routes_info_excl, TextUtils.join(", ", mRoutes.getNetworks(false)), TextUtils.join(", ", mRoutesv6.getNetworks(false)));
@@ -694,6 +723,12 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac
builder.setUnderlyingNetworks(null);
}
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
+ // Setting this false, will cause the VPN to inherit the underlying network metered
+ // value
+ builder.setMetered(false);
+ }
+
String session = mProfile.mName;
if (mLocalIP != null && mLocalIPv6 != null)
@@ -736,6 +771,15 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac
}
+ private boolean isLockdownEnabledCompat() {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
+ return isLockdownEnabled();
+ } else {
+ /* We cannot determine this, return false */
+ return false;
+ }
+ }
+
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void allowAllAFFamilies(Builder builder) {
builder.allowFamily(OsConstants.AF_INET);
@@ -822,6 +866,11 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac
} else {
VpnStatus.logDebug(R.string.allowed_vpn_apps_info, TextUtils.join(", ", mProfile.mAllowedAppsVpn));
}
+
+ if (mProfile.mAllowAppVpnBypass) {
+ builder.allowBypass();
+ VpnStatus.logDebug("Apps may bypass VPN");
+ }
}
public void addDNS(String dns) {