summaryrefslogtreecommitdiff
path: root/mobile-kt/app/src/DNSProxyRunner.java
diff options
context:
space:
mode:
Diffstat (limited to 'mobile-kt/app/src/DNSProxyRunner.java')
-rw-r--r--mobile-kt/app/src/DNSProxyRunner.java43
1 files changed, 43 insertions, 0 deletions
diff --git a/mobile-kt/app/src/DNSProxyRunner.java b/mobile-kt/app/src/DNSProxyRunner.java
new file mode 100644
index 0000000..dd0e3e5
--- /dev/null
+++ b/mobile-kt/app/src/DNSProxyRunner.java
@@ -0,0 +1,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;
+ }
+}