From 0b63f8d6a3d662be4c88c9d04740da3e8f1816e6 Mon Sep 17 00:00:00 2001 From: Arne Schwabe Date: Wed, 5 Nov 2014 11:31:26 +0100 Subject: Fix starting VPN without permission when called from external service --- main/build.gradle | 4 ++-- .../blinkt/openvpn/api/ExternalOpenVPNService.java | 25 +++++++++++++++++++--- 2 files changed, 24 insertions(+), 5 deletions(-) (limited to 'main') diff --git a/main/build.gradle b/main/build.gradle index 750c3eb9..58565e73 100644 --- a/main/build.gradle +++ b/main/build.gradle @@ -20,8 +20,8 @@ android { defaultConfig { minSdkVersion 14 targetSdkVersion 21 - versionCode = 100 - versionName = "0.6.19" + versionCode = 101 + versionName = "0.6.20" } sourceSets { diff --git a/main/src/main/java/de/blinkt/openvpn/api/ExternalOpenVPNService.java b/main/src/main/java/de/blinkt/openvpn/api/ExternalOpenVPNService.java index d1cdafc7..4b07c7ab 100644 --- a/main/src/main/java/de/blinkt/openvpn/api/ExternalOpenVPNService.java +++ b/main/src/main/java/de/blinkt/openvpn/api/ExternalOpenVPNService.java @@ -22,6 +22,8 @@ import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; import android.net.VpnService; import android.os.*; + +import de.blinkt.openvpn.LaunchVPN; import de.blinkt.openvpn.R; import de.blinkt.openvpn.VpnProfile; import de.blinkt.openvpn.core.ConfigParser; @@ -112,12 +114,30 @@ public class ExternalOpenVPNService extends Service implements StateListener { return profiles; } + + private void startProfile(VpnProfile vp) + { + Intent vpnPermissionIntent = VpnService.prepare(ExternalOpenVPNService.this); + /* Check if we need to show the confirmation dialog */ + if(vpnPermissionIntent != null){ + Intent shortVPNIntent = new Intent(Intent.ACTION_MAIN); + shortVPNIntent.setClass(getBaseContext(), de.blinkt.openvpn.LaunchVPN.class); + shortVPNIntent.putExtra(de.blinkt.openvpn.LaunchVPN.EXTRA_KEY, vp.getUUIDString()); + shortVPNIntent.putExtra(de.blinkt.openvpn.LaunchVPN.EXTRA_HIDELOG, true); + shortVPNIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + startActivity(shortVPNIntent); + } else { + VPNLaunchHelper.startOpenVpn(vp, getBaseContext()); + } + + } + @Override public void startProfile(String profileUUID) throws RemoteException { checkOpenVPNPermission(); VpnProfile vp = ProfileManager.get(getBaseContext(), profileUUID); - VPNLaunchHelper.startOpenVpn(vp, getBaseContext()); + startProfile(vp); } public void startVPN(String inlineconfig) throws RemoteException { @@ -132,8 +152,7 @@ public class ExternalOpenVPNService extends Service implements StateListener { ProfileManager.setTemporaryProfile(vp); - VPNLaunchHelper.startOpenVpn(vp, getBaseContext()); - + startProfile(vp); } catch (IOException e) { throw new RemoteException(e.getMessage()); -- cgit v1.2.3