| 
							
							
							
						 |  |  | @@ -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 = "<unknown ssid>"; | 
		
	
		
			
				|  |  |  |  |  | 
		
	
	
		
			
				
					
					|  |  |  | @@ -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); | 
		
	
		
			
				|  |  |  |  | 		} | 
		
	
		
			
				|  |  |  |  | 	} | 
		
	
		
			
				|  |  |  |  | 	 | 
		
	
		
			
				|  |  |  |  | } |