summaryrefslogtreecommitdiff
path: root/mobile-kt/app/src/WifiListenerReceiver.java
diff options
context:
space:
mode:
authorDaniel Weipert <git@mail.dweipert.de>2024-01-26 14:51:36 +0100
committerDaniel Weipert <git@mail.dweipert.de>2024-01-26 14:52:57 +0100
commitd3bf2d09f740221771806789b00bf915c9f5f2e3 (patch)
tree95f99eabd763dff1907f107393504ee75aa747d7 /mobile-kt/app/src/WifiListenerReceiver.java
parent466d03a38cb01e9ff9a2d11be113a81c2bdce34a (diff)
initial commitHEADmain
Diffstat (limited to 'mobile-kt/app/src/WifiListenerReceiver.java')
-rw-r--r--mobile-kt/app/src/WifiListenerReceiver.java50
1 files changed, 50 insertions, 0 deletions
diff --git a/mobile-kt/app/src/WifiListenerReceiver.java b/mobile-kt/app/src/WifiListenerReceiver.java
new file mode 100644
index 0000000..5e05654
--- /dev/null
+++ b/mobile-kt/app/src/WifiListenerReceiver.java
@@ -0,0 +1,50 @@
+package org.pihole.dnsproxy;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.SharedPreferences;
+
+import android.net.NetworkInfo;
+import android.net.wifi.WifiManager;
+
+import android.os.Handler;
+
+import android.preference.PreferenceManager;
+
+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)) {
+ SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
+
+ if (!sharedPreferences.getBoolean("use_wifi_listener_for_activation", false)) {
+ return;
+ }
+
+ // wait a few moments for wifi to be fully there
+ (new Handler()).postDelayed(new Runnable() {
+ @Override
+ public void run() {
+ String ssid = WifiListenerService.getWifiSSID(context);
+
+ if (ssid.equals(sharedPreferences.getString("wifi_listener_ssid", ""))) {
+ DNSProxyService.start(context);
+ }
+ }
+ }, 1000);
+ }
+
+ // stop
+ else if (networkInfo.getState().equals(NetworkInfo.State.DISCONNECTED) && DNSProxyService.isRunning()) {
+ DNSProxyService.stop(context);
+ }
+ }
+}