diff options
author | Daniel Weipert <code@drogueronin.de> | 2023-05-11 20:03:37 +0200 |
---|---|---|
committer | Daniel Weipert <code@drogueronin.de> | 2023-05-11 20:03:37 +0200 |
commit | eefe2bdea6e79548ef5a0c0a50b3afc495b034b3 (patch) | |
tree | 1ba6f80cd8d2a56de3b0e9a0029603dbd9ff57c6 /app/java/src/DNSProxyService.java | |
parent | 9919df9457d95e5bd156f313549c8d8b26f09f24 (diff) |
next commit
Diffstat (limited to 'app/java/src/DNSProxyService.java')
-rw-r--r-- | app/java/src/DNSProxyService.java | 52 |
1 files changed, 52 insertions, 0 deletions
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); + } +} |