diff options
author | Daniel Weipert <code@drogueronin.de> | 2023-05-15 17:20:15 +0200 |
---|---|---|
committer | Daniel Weipert <code@drogueronin.de> | 2023-05-15 17:20:15 +0200 |
commit | 309993eec6085cfa0e112cd5f45c8c55beeee5db (patch) | |
tree | c18e3433b4e06688f8eda3f99f91a2bf5c70dccf /app/java/src/WifiListenerReceiver.java | |
parent | 08b40e81c62420e977e82189482fc07c0d6ace31 (diff) |
works as intended :)
Diffstat (limited to 'app/java/src/WifiListenerReceiver.java')
-rw-r--r-- | app/java/src/WifiListenerReceiver.java | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/app/java/src/WifiListenerReceiver.java b/app/java/src/WifiListenerReceiver.java index d34df2b..6bf93bd 100644 --- a/app/java/src/WifiListenerReceiver.java +++ b/app/java/src/WifiListenerReceiver.java @@ -5,6 +5,7 @@ import android.provider.Settings; 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; @@ -13,6 +14,8 @@ import android.net.wifi.WifiInfo; import android.os.Bundle; import android.os.Handler; +import android.preference.PreferenceManager; + import android.util.Log; public class WifiListenerReceiver extends BroadcastReceiver @@ -24,23 +27,33 @@ public class WifiListenerReceiver extends BroadcastReceiver // 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() { + (new Handler()).postDelayed(new Runnable() { @Override public void run() { WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); WifiInfo wifiInfo = wifiManager.getConnectionInfo(); + String ssid = wifiInfo.getSSID(); - // if (wifiInfo.getSSID() == setting.get(LOCAL_HOME_WIFI_SSID)) + // remove quotes around ssid + ssid = ssid.substring(1, ssid.length() - 1); - context.startService(dnsProxyService.setAction(DNSProxyService.ACTION_START)); + if (ssid.equals(sharedPreferences.getString("wifi_listener_ssid", ""))) { + DNSProxyService.start(context); + } } - }, 1000); */ + }, 1000); } // stop else if (networkInfo.getState().equals(NetworkInfo.State.DISCONNECTED) && DNSProxyService.isRunning()) { - context.startService(dnsProxyService.setAction(DNSProxyService.ACTION_STOP)); + DNSProxyService.stop(context); } } } |