summaryrefslogtreecommitdiff
path: root/app/src/main/java/de/blinkt/openvpn/core/VPNLaunchHelper.java
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/de/blinkt/openvpn/core/VPNLaunchHelper.java')
-rw-r--r--app/src/main/java/de/blinkt/openvpn/core/VPNLaunchHelper.java47
1 files changed, 25 insertions, 22 deletions
diff --git a/app/src/main/java/de/blinkt/openvpn/core/VPNLaunchHelper.java b/app/src/main/java/de/blinkt/openvpn/core/VPNLaunchHelper.java
index 78f462e7..f3b40381 100644
--- a/app/src/main/java/de/blinkt/openvpn/core/VPNLaunchHelper.java
+++ b/app/src/main/java/de/blinkt/openvpn/core/VPNLaunchHelper.java
@@ -6,6 +6,7 @@
package de.blinkt.openvpn.core;
import android.annotation.TargetApi;
+import android.app.NotificationManager;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
@@ -26,7 +27,6 @@ public class VPNLaunchHelper {
private static final String OVPNCONFIGFILE = "android.conf";
-
private static String writeMiniVPN(Context context) {
String[] abis;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
@@ -38,36 +38,34 @@ public class VPNLaunchHelper {
String nativeAPI = NativeUtils.getNativeAPI();
if (!nativeAPI.equals(abis[0])) {
VpnStatus.logWarning(R.string.abi_mismatch, Arrays.toString(abis), nativeAPI);
- abis = new String[] {nativeAPI};
+ abis = new String[]{nativeAPI};
}
- for (String abi: abis) {
+ for (String abi : abis) {
- File vpnExecutable = new File(context.getCacheDir(), getMiniVPNExecutableName() + "." + abi);
+ File vpnExecutable = new File(context.getCacheDir(), "c_" + getMiniVPNExecutableName() + "." + abi);
if ((vpnExecutable.exists() && vpnExecutable.canExecute()) || writeMiniVPNBinary(context, abi, vpnExecutable)) {
return vpnExecutable.getPath();
}
}
return null;
- }
+ }
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private static String[] getSupportedABIsLollipop() {
return Build.SUPPORTED_ABIS;
}
- private static String getMiniVPNExecutableName()
- {
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
+ private static String getMiniVPNExecutableName() {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
return MINIPIEVPN;
else
return MININONPIEVPN;
}
- public static String[] replacePieWithNoPie(String[] mArgv)
- {
+ public static String[] replacePieWithNoPie(String[] mArgv) {
mArgv[0] = mArgv[0].replace(MINIPIEVPN, MININONPIEVPN);
return mArgv;
}
@@ -79,7 +77,7 @@ public class VPNLaunchHelper {
String binaryName = writeMiniVPN(c);
// Add fixed paramenters
//args.add("/data/data/de.blinkt.openvpn/lib/openvpn");
- if(binaryName==null) {
+ if (binaryName == null) {
VpnStatus.logError("Error writing minivpn binary");
return null;
}
@@ -98,8 +96,7 @@ public class VPNLaunchHelper {
try {
mvpn = context.getAssets().open(getMiniVPNExecutableName() + "." + abi);
- }
- catch (IOException errabi) {
+ } catch (IOException errabi) {
VpnStatus.logInfo("Failed getting assets for archicture " + abi);
return false;
}
@@ -107,16 +104,16 @@ public class VPNLaunchHelper {
FileOutputStream fout = new FileOutputStream(mvpnout);
- byte buf[]= new byte[4096];
+ byte buf[] = new byte[4096];
int lenread = mvpn.read(buf);
- while(lenread> 0) {
+ while (lenread > 0) {
fout.write(buf, 0, lenread);
lenread = mvpn.read(buf);
}
fout.close();
- if(!mvpnout.setExecutable(true)) {
+ if (!mvpnout.setExecutable(true)) {
VpnStatus.logError("Failed to make OpenVPN executable");
return false;
}
@@ -129,14 +126,20 @@ public class VPNLaunchHelper {
}
}
-
- public static void startOpenVpn(VpnProfile startprofile, Context context) {
- Intent startVPN = startprofile.prepareStartService(context);
- if(startVPN!=null)
- context.startService(startVPN);
- }
+ public static void startOpenVpn(VpnProfile startprofile, Context context) {
+ Intent startVPN = startprofile.prepareStartService(context);
+ if (startVPN != null) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
+ //noinspection NewApi
+ context.startForegroundService(startVPN);
+ else
+ context.startService(startVPN);
+
+ }
+ }
+
public static String getConfigFilePath(Context context) {
return context.getCacheDir().getAbsolutePath() + "/" + OVPNCONFIGFILE;