package org.pihole.dnsproxy; import android.os.ParcelFileDescriptor; import android.util.Log; public class DNSProxyConnection { public static String THREAD_NAME = "org.pihole.dnsproxy.service.thread"; private DNSProxyService service; private Thread thread; private ParcelFileDescriptor networkInterface; public DNSProxyConnection(DNSProxyService service) { this.service = service; } 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(); } public void stop() { try { this.thread.interrupt(); this.networkInterface.close(); } catch (Exception exception) { Log.e(DNSProxyService.LOG_TAG, "Closing VPN interface", exception); } } }