diff options
author | Daniel Weipert <code@drogueronin.de> | 2023-05-14 13:20:43 +0200 |
---|---|---|
committer | Daniel Weipert <code@drogueronin.de> | 2023-05-14 13:24:30 +0200 |
commit | 6f4dc54bd119203da8dd1f91e65c4e4b99ab2ff0 (patch) | |
tree | fa7fe2459283fe81dba17f95eccdf5eded883e11 /app/java/src/WifiListenerReceiver.java | |
parent | 6aae8398d489de5f33e8824a252793306d570d3c (diff) |
menu
Diffstat (limited to 'app/java/src/WifiListenerReceiver.java')
-rw-r--r-- | app/java/src/WifiListenerReceiver.java | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/app/java/src/WifiListenerReceiver.java b/app/java/src/WifiListenerReceiver.java new file mode 100644 index 0000000..e8ebedf --- /dev/null +++ b/app/java/src/WifiListenerReceiver.java @@ -0,0 +1,39 @@ +package org.pihole.dnsproxy; + +import android.provider.Settings; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; + +import android.net.NetworkInfo; +import android.net.wifi.WifiManager; +import android.net.wifi.WifiInfo; + +import android.os.Bundle; + +import android.util.Log; + +public class WifiListenerReceiver extends BroadcastReceiver +{ + @Override + public void onReceive(Context context, Intent intent) { + NetworkInfo networkInfo = (NetworkInfo) intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO); + Intent dnsProxyService = new Intent(context, DNSProxyService.class); + + // start + if (networkInfo.getState().equals(NetworkInfo.State.CONNECTED)) { + WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); + WifiInfo wifiInfo = wifiManager.getConnectionInfo(); + + // if (wifiInfo.getSSID() == setting.get(LOCAL_HOME_WIFI_SSID)) + + context.startService(dnsProxyService.setAction(DNSProxyService.ACTION_START)); + } + + // stop + else if (networkInfo.getState().equals(NetworkInfo.State.DISCONNECTED) && DNSProxyService.isRunning()) { + context.startService(dnsProxyService.setAction(DNSProxyService.ACTION_STOP)); + } + } +} |