blob: cbf0fed2928fda34a281724ea3305816f7b92a0c (
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
|
package se.leap.bitmaskclient.eip;
import android.content.*;
import android.net.*;
import android.os.*;
import java.io.*;
public class VoidVpnService extends VpnService {
static final String TAG = VoidVpnService.class.getSimpleName();
static ParcelFileDescriptor fd;
static Thread thread;
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
String action = intent != null ? intent.getAction() : "";
if (action == Constants.START_BLOCKING_VPN_PROFILE) {
thread = new Thread(new Runnable() {
public void run() {
Builder builder = new Builder();
builder.setSession("Blocking until running");
builder.addAddress("10.42.0.8", 16);
builder.addRoute("0.0.0.0", 1);
builder.addRoute("192.168.1.0", 24);
builder.addDnsServer("10.42.0.1");
try {
fd = builder.establish();
} catch (Exception e) {
e.printStackTrace();
}
}
});
thread.run();
}
return 0;
}
@Override
public void onRevoke() {
super.onRevoke();
closeFd();
}
public static void stop() {
if (thread != null)
thread.interrupt();
closeFd();
}
public static boolean isRunning() throws NullPointerException {
return thread.isAlive() && fd != null;
}
private static void closeFd() {
try {
if (fd != null)
fd.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
|