From d3bf2d09f740221771806789b00bf915c9f5f2e3 Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Fri, 26 Jan 2024 14:51:36 +0100 Subject: initial commit --- mobile-kt/app/src/DNSProxyConnection.java | 43 +++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 mobile-kt/app/src/DNSProxyConnection.java (limited to 'mobile-kt/app/src/DNSProxyConnection.java') diff --git a/mobile-kt/app/src/DNSProxyConnection.java b/mobile-kt/app/src/DNSProxyConnection.java new file mode 100644 index 0000000..420b5fc --- /dev/null +++ b/mobile-kt/app/src/DNSProxyConnection.java @@ -0,0 +1,43 @@ +package org.pihole.dnsproxy; + +import android.os.ParcelFileDescriptor; + +import android.util.Log; + +public class DNSProxyConnection { + + public static String THREAD_NAME = "org.pihole.dnsproxy.service.dnsproxy.thread"; + + private DNSProxyService service; + private Thread thread; + private ParcelFileDescriptor networkInterface; + + public DNSProxyConnection(DNSProxyService service) { + this.service = service; + } + + /** + * Setup and start the connection + */ + public void start() { + DNSProxyRunner runner = new DNSProxyRunner(this.service); + runner.setOnEstablishListener(tunInterface -> { + this.networkInterface = tunInterface; + }); + + this.thread = new Thread(runner, DNSProxyConnection.THREAD_NAME); + this.thread.start(); + } + + /** + * Stop and close the connection + */ + public void stop() { + try { + this.thread.interrupt(); + this.networkInterface.close(); + } catch (Exception exception) { + Log.e(DNSProxyService.LOG_TAG, "Closing VPN interface", exception); + } + } +} -- cgit v1.2.3