summaryrefslogtreecommitdiff
path: root/app/java/src/DNSProxyService.java
diff options
context:
space:
mode:
Diffstat (limited to 'app/java/src/DNSProxyService.java')
-rw-r--r--app/java/src/DNSProxyService.java52
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);
+ }
+}