From 2f6500dcc3b1fe9bab0becd0528ead759aaddd48 Mon Sep 17 00:00:00 2001 From: Gabriele M Date: Thu, 7 Sep 2017 01:04:28 +0200 Subject: [PATCH] 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 --- .../internal/ProfileTriggerHelper.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/cm/lib/main/java/org/cyanogenmod/platform/internal/ProfileTriggerHelper.java b/cm/lib/main/java/org/cyanogenmod/platform/internal/ProfileTriggerHelper.java index a421749e..82e66876 100644 --- a/cm/lib/main/java/org/cyanogenmod/platform/internal/ProfileTriggerHelper.java +++ b/cm/lib/main/java/org/cyanogenmod/platform/internal/ProfileTriggerHelper.java @@ -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)) {