summaryrefslogtreecommitdiff
path: root/app/java/src/DNSProxyConnection.java
diff options
context:
space:
mode:
authorDaniel Weipert <code@drogueronin.de>2023-05-11 20:03:37 +0200
committerDaniel Weipert <code@drogueronin.de>2023-05-11 20:03:37 +0200
commiteefe2bdea6e79548ef5a0c0a50b3afc495b034b3 (patch)
tree1ba6f80cd8d2a56de3b0e9a0029603dbd9ff57c6 /app/java/src/DNSProxyConnection.java
parent9919df9457d95e5bd156f313549c8d8b26f09f24 (diff)
next commit
Diffstat (limited to 'app/java/src/DNSProxyConnection.java')
-rw-r--r--app/java/src/DNSProxyConnection.java39
1 files changed, 39 insertions, 0 deletions
diff --git a/app/java/src/DNSProxyConnection.java b/app/java/src/DNSProxyConnection.java
new file mode 100644
index 0000000..f96af80
--- /dev/null
+++ b/app/java/src/DNSProxyConnection.java
@@ -0,0 +1,39 @@
+package org.pihole.dnsproxy;
+
+import android.os.ParcelFileDescriptor;
+
+import android.util.Log;
+
+import java.io.IOException;
+
+public class DNSProxyConnection {
+
+ public static String THREAD_NAME = "org.pihole.dnsproxy.service.thread";
+
+ private DNSProxyService service;
+ private Thread thread;
+ private ParcelFileDescriptor networkInterface;
+
+ public DNSProxyConnection(DNSProxyService service) {
+ this.service = service;
+ }
+
+ public void start() {
+ DNSProxyRunner runner = new DNSProxyRunner(this.service);
+ runner.setOnEstablishListener(parcelFileDescriptor -> {
+ this.networkInterface = parcelFileDescriptor;
+ });
+
+ this.thread = new Thread(runner, DNSProxyConnection.THREAD_NAME);
+ this.thread.start();
+ }
+
+ public void stop() {
+ try {
+ this.thread.stop();
+ this.networkInterface.close();
+ } catch (IOException exception) {
+ Log.e(DNSProxyService.LOG_TAG, "Connection failed", exception);
+ }
+ }
+}