blob: dd0e3e54ee0ae7ee83e6101acd78591be836fffd (
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
|
package org.pihole.dnsproxy;
import android.net.VpnService;
import android.os.ParcelFileDescriptor;
import android.util.Log;
public class DNSProxyRunner implements Runnable {
public interface OnEstablishListener {
void onEstablish(ParcelFileDescriptor networkInterface);
}
private OnEstablishListener onEstablishListener;
private DNSProxyService service;
DNSProxyRunner(DNSProxyService service) {
this.service = service;
}
@Override
public void run() {
try {
VpnService.Builder builder = this.service.newBuilder()
.setSession("Pihole DNS Proxy")
.addAddress("10.111.222.1", 24)
.addDnsServer(DNSProxyService.PIHOLE_ADDRESS)
.setBlocking(true);
this.onEstablishListener.onEstablish(builder.establish());
} catch (Exception exception) {
Log.e(DNSProxyService.LOG_TAG, "Failed to establish VPN connection", exception);
}
}
/**
* Callback when proxy connection is established
*/
public void setOnEstablishListener(OnEstablishListener listener) {
this.onEstablishListener = listener;
}
}
|