cmsdk: Use intent extradata for WiFi triggers
Use the extras of the intent to determine if we are connected to a WiFi network and, in case we are, to get the SSID. This allows to trigger profile changes only when the status is either DISCONNECTED or CONNECTED and it also ensures that we process each event according to the network status that caused it rather than the current one. Change-Id: If7598bc9502f94bb2f6f7f274538df346fbb4869
This commit is contained in:
@@ -23,6 +23,7 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.database.ContentObserver;
|
||||
import android.net.NetworkInfo;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.net.wifi.WifiSsid;
|
||||
@@ -107,15 +108,20 @@ public class ProfileTriggerHelper extends BroadcastReceiver {
|
||||
String action = intent.getAction();
|
||||
|
||||
if (action.equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) {
|
||||
String ssid = getActiveSSID();
|
||||
if (ssid == null || TextUtils.equals(ssid, WifiSsid.NONE)) {
|
||||
NetworkInfo networkInfo = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
|
||||
NetworkInfo.DetailedState state = networkInfo.getDetailedState();
|
||||
if (NetworkInfo.DetailedState.DISCONNECTED.equals(state)) {
|
||||
checkTriggers(Profile.TriggerType.WIFI, mLastConnectedSSID,
|
||||
Profile.TriggerState.ON_DISCONNECT);
|
||||
mLastConnectedSSID = WifiSsid.NONE;
|
||||
} else if (!TextUtils.equals(mLastConnectedSSID, ssid)) {
|
||||
mLastConnectedSSID = ssid;
|
||||
checkTriggers(Profile.TriggerType.WIFI, mLastConnectedSSID,
|
||||
Profile.TriggerState.ON_CONNECT);
|
||||
} else if (NetworkInfo.DetailedState.CONNECTED.equals(state)) {
|
||||
WifiInfo wifiInfo = intent.getParcelableExtra(WifiManager.EXTRA_WIFI_INFO);
|
||||
WifiSsid ssid = wifiInfo.getWifiSsid();
|
||||
if (ssid != null) {
|
||||
mLastConnectedSSID = ssid.toString();
|
||||
checkTriggers(Profile.TriggerType.WIFI, mLastConnectedSSID,
|
||||
Profile.TriggerState.ON_CONNECT);
|
||||
}
|
||||
}
|
||||
} else if (action.equals(BluetoothDevice.ACTION_ACL_CONNECTED)
|
||||
|| action.equals(BluetoothDevice.ACTION_ACL_DISCONNECTED)) {
|
||||
|
||||
Reference in New Issue
Block a user