blob: 55fcb0ba86017b3e8d246db80f43829cf4a3a58d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
package de.blinkt.openvpn.core;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import se.leap.bitmaskclient.R;
import de.blinkt.openvpn.VpnProfile;
public class VPNLaunchHelper {
static private boolean writeMiniVPN(Context context) {
File mvpnout = new File(context.getCacheDir(),VpnProfile.MINIVPN);
if (mvpnout.exists() && mvpnout.canExecute())
return true;
IOException e2 = null;
try {
InputStream mvpn;
try {
mvpn = context.getAssets().open("minivpn." + Build.CPU_ABI);
}
catch (IOException errabi) {
VpnStatus.logInfo("Failed getting assets for archicture " + Build.CPU_ABI);
e2=errabi;
mvpn = context.getAssets().open("minivpn." + Build.CPU_ABI2);
}
FileOutputStream fout = new FileOutputStream(mvpnout);
byte buf[]= new byte[4096];
int lenread = mvpn.read(buf);
while(lenread> 0) {
fout.write(buf, 0, lenread);
lenread = mvpn.read(buf);
}
fout.close();
if(!mvpnout.setExecutable(true)) {
VpnStatus.logError("Failed to set minivpn executable");
return false;
}
return true;
} catch (IOException e) {
if(e2!=null)
VpnStatus.logException(e2);
VpnStatus.logException(e);
return false;
}
}
public static void startOpenVpn(VpnProfile startprofile, Context context) {
if(!writeMiniVPN(context)) {
VpnStatus.logError("Error writing minivpn binary");
return;
}
VpnStatus.logInfo(R.string.building_configration);
Intent startVPN = startprofile.prepareIntent(context);
if(startVPN!=null)
context.startService(startVPN);
}
}
|