summaryrefslogtreecommitdiff
path: root/mobile-kt/app/src/DNSProxyRunner.java
diff options
context:
space:
mode:
authorDaniel Weipert <git@mail.dweipert.de>2024-01-26 14:51:36 +0100
committerDaniel Weipert <git@mail.dweipert.de>2024-01-26 14:52:57 +0100
commitd3bf2d09f740221771806789b00bf915c9f5f2e3 (patch)
tree95f99eabd763dff1907f107393504ee75aa747d7 /mobile-kt/app/src/DNSProxyRunner.java
parent466d03a38cb01e9ff9a2d11be113a81c2bdce34a (diff)
initial commitHEADmain
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;
+ }
+}