From a21f90acb54ab72f6933f204a070ca4ad63dc853 Mon Sep 17 00:00:00 2001 From: Jens Date: Thu, 21 Dec 2023 23:16:21 +0100 Subject: [PATCH] Wifi receiver --- app/src/apkFlavor/AndroidManifest.xml | 1 - app/src/fdroidFlavor/AndroidManifest.xml | 1 - app/src/googlePlayFlavor/AndroidManifest.xml | 1 - .../location/WifiBroadcastReceiver.java | 24 +++++++------------ 4 files changed, 8 insertions(+), 19 deletions(-) diff --git a/app/src/apkFlavor/AndroidManifest.xml b/app/src/apkFlavor/AndroidManifest.xml index 19aaf806..2357f464 100644 --- a/app/src/apkFlavor/AndroidManifest.xml +++ b/app/src/apkFlavor/AndroidManifest.xml @@ -52,7 +52,6 @@ - diff --git a/app/src/fdroidFlavor/AndroidManifest.xml b/app/src/fdroidFlavor/AndroidManifest.xml index 0559b28d..24d455fa 100644 --- a/app/src/fdroidFlavor/AndroidManifest.xml +++ b/app/src/fdroidFlavor/AndroidManifest.xml @@ -52,7 +52,6 @@ - diff --git a/app/src/googlePlayFlavor/AndroidManifest.xml b/app/src/googlePlayFlavor/AndroidManifest.xml index 019dfc53..db352bed 100644 --- a/app/src/googlePlayFlavor/AndroidManifest.xml +++ b/app/src/googlePlayFlavor/AndroidManifest.xml @@ -51,7 +51,6 @@ - diff --git a/app/src/main/java/com/jens/automation2/location/WifiBroadcastReceiver.java b/app/src/main/java/com/jens/automation2/location/WifiBroadcastReceiver.java index 55f5862b..73660092 100644 --- a/app/src/main/java/com/jens/automation2/location/WifiBroadcastReceiver.java +++ b/app/src/main/java/com/jens/automation2/location/WifiBroadcastReceiver.java @@ -1,6 +1,5 @@ package com.jens.automation2.location; - import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; @@ -30,7 +29,7 @@ public class WifiBroadcastReceiver extends BroadcastReceiver protected static boolean mayCellLocationChangedReceiverBeActivatedFromWifiPointOfView = true; protected static WifiBroadcastReceiver wifiBrInstance; protected static IntentFilter wifiListenerIntentFilter; - protected static boolean wifiListenerActive=false; + protected static boolean wifiListenerActive = false; final static String unknownSsidName = ""; @@ -46,13 +45,16 @@ public class WifiBroadcastReceiver extends BroadcastReceiver public static void setLastWifiSsid(String newWifiSsid) { + // Remove double quotes if(newWifiSsid.startsWith("\"") && newWifiSsid.endsWith("\"")) newWifiSsid = newWifiSsid.substring(1, newWifiSsid.length()-1); + // If it's a real name, not an empty string, it's stored as the last ssid if(newWifiSsid.length() > 0) { if(newWifiSsid.equals(unknownSsidName)) WifiBroadcastReceiver.lastWifiSsidReal = lastWifiSsid; + WifiBroadcastReceiver.lastWifiSsid = newWifiSsid; } } @@ -72,24 +74,15 @@ public class WifiBroadcastReceiver extends BroadcastReceiver { try { - // int state = -1; NetworkInfo myWifi = null; if(intent.getAction().equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) // fired upon disconnection { - // state = intent.getIntExtra(WifiManager.NETWORK_STATE_CHANGED_ACTION, -1); - // Miscellaneous.logEvent("i", "WifiReceiver", "NETWORK_STATE_CHANGED_ACTION: " + String.valueOf(state)); myWifi = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO); } WifiManager myWifiManager = (WifiManager)context.getSystemService(Context.WIFI_SERVICE); - // ConnectivityManager connManager = (ConnectivityManager)context.getSystemService(context.CONNECTIVITY_SERVICE); - // myWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); - // myWifi = state - // WifiInfo wifiInfo = myWifiManager.getConnectionInfo(); - - // SupplicantState supState = wifiInfo.getSupplicantState(); - + if(intent.getAction().equals(WifiManager.RSSI_CHANGED_ACTION)) // fired upon connection { String ssid = myWifiManager.getConnectionInfo().getSSID(); @@ -132,7 +125,7 @@ public class WifiBroadcastReceiver extends BroadcastReceiver } else if(!myWifi.isConnectedOrConnecting()) // really disconnected? because sometimes also fires on connect { - if(wasConnected) // wir könnten einfach noch nicht daheim sein + if(wasConnected) // we could simply not be home yet { try { @@ -226,17 +219,16 @@ public class WifiBroadcastReceiver extends BroadcastReceiver { try { - if(wifiListenerActive) + if (wifiListenerActive) { Miscellaneous.logEvent("i", "Wifi Listener", "Stopping wifiListener", 4); wifiListenerActive = false; parentLocationProvider.getParentService().unregisterReceiver(wifiBrInstance); } } - catch(Exception ex) + catch (Exception ex) { Miscellaneous.logEvent("e", "Wifi Listener", "Error stopping wifiListener: " + Log.getStackTraceString(ex), 3); } } - } \ No newline at end of file