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); } }