From eefe2bdea6e79548ef5a0c0a50b3afc495b034b3 Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Thu, 11 May 2023 20:03:37 +0200 Subject: next commit --- app/java/src/DNSProxyService.java | 52 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 app/java/src/DNSProxyService.java (limited to 'app/java/src/DNSProxyService.java') diff --git a/app/java/src/DNSProxyService.java b/app/java/src/DNSProxyService.java new file mode 100644 index 0000000..117e6fc --- /dev/null +++ b/app/java/src/DNSProxyService.java @@ -0,0 +1,52 @@ +package org.pihole.dnsproxy; + +import android.app.Service; + +import android.content.Intent; + +import android.net.VpnService; + +public class DNSProxyService extends VpnService { + + public static String LOG_TAG = "org.pihole.dnsproxy.log"; + public static String NOTIFICATION = "org.pihole.dnsproxy.service"; + + private static DNSProxyConnection connection; + + @Override + public int onStartCommand(Intent intent, int flags, int startId) { + this.start(); + + return Service.START_STICKY; + } + + @Override + public void onDestroy() { + this.stop(); + + super.onDestroy(); + } + + public static boolean isRunning() + { + return DNSProxyService.connection != null; + } + + public void start() { + DNSProxyService.connection = new DNSProxyConnection(this); + // DNSProxyService.connection.start(); + + // send notification when started + Intent notification = new Intent(DNSProxyService.NOTIFICATION); + sendBroadcast(notification); + } + + public void stop() { + // DNSProxyService.connection.stop(); + DNSProxyService.connection = null; + + // send notification when stopped + Intent notification = new Intent(DNSProxyService.NOTIFICATION); + sendBroadcast(notification); + } +} -- cgit v1.2.3