diff options
author | Robert Greenwalt <rgreenwalt@google.com> | 2014-03-11 17:44:20 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2014-03-11 17:44:20 +0000 |
commit | e5098b502c28d8f40ff3b39070fc5fb7f1a3e445 (patch) | |
tree | 0c385d38afc89aba28d37cd0b2aae94c59eb49c9 /wifi/java | |
parent | 74f36d31892d8fdfddbecc7bf3018aa3a190e5fb (diff) | |
parent | e8af5e10e04697acb26b47e5d60b99e5c61a020c (diff) | |
download | frameworks_base-e5098b502c28d8f40ff3b39070fc5fb7f1a3e445.zip frameworks_base-e5098b502c28d8f40ff3b39070fc5fb7f1a3e445.tar.gz frameworks_base-e5098b502c28d8f40ff3b39070fc5fb7f1a3e445.tar.bz2 |
am e8af5e10: am 6d9ed0c3: Merge "DO NOT MERGE Debounce wifi country code Info" into klp-dev
* commit 'e8af5e10e04697acb26b47e5d60b99e5c61a020c':
DO NOT MERGE Debounce wifi country code Info
Diffstat (limited to 'wifi/java')
-rw-r--r-- | wifi/java/android/net/wifi/WifiStateMachine.java | 52 |
1 files changed, 35 insertions, 17 deletions
diff --git a/wifi/java/android/net/wifi/WifiStateMachine.java b/wifi/java/android/net/wifi/WifiStateMachine.java index 69d3efe..cf1669c 100644 --- a/wifi/java/android/net/wifi/WifiStateMachine.java +++ b/wifi/java/android/net/wifi/WifiStateMachine.java @@ -233,6 +233,10 @@ public class WifiStateMachine extends StateMachine { private DhcpStateMachine mDhcpStateMachine; private boolean mDhcpActive = false; + // Delay in switching to null country code (non-null has no delay) + private final int COUNTRY_CODE_DELAY_MS = 15000; + private final AtomicInteger mCountryCodeSequence = new AtomicInteger(); + private class InterfaceObserver extends BaseNetworkObserver { private WifiStateMachine mWifiStateMachine; @@ -1535,14 +1539,15 @@ public class WifiStateMachine extends StateMachine { * @param persist {@code true} if the setting should be remembered. */ public void setCountryCode(String countryCode, boolean persist) { - if (persist) { - mPersistedCountryCode = countryCode; - Settings.Global.putString(mContext.getContentResolver(), - Settings.Global.WIFI_COUNTRY_CODE, - countryCode); + // If it's a country code, apply immediately, + // If it's empty, delay it in case it's a momentary dropout + int countryCodeSequence = mCountryCodeSequence.incrementAndGet(); + if (TextUtils.isEmpty(countryCode)) { + sendMessageDelayed(CMD_SET_COUNTRY_CODE, countryCodeSequence, persist ? 1 : 0, + countryCode, COUNTRY_CODE_DELAY_MS); + } else { + sendMessage(CMD_SET_COUNTRY_CODE, countryCodeSequence, persist ? 1 : 0, countryCode); } - sendMessage(CMD_SET_COUNTRY_CODE, countryCode); - mWifiP2pChannel.sendMessage(WifiP2pService.SET_COUNTRY_CODE, countryCode); } /** @@ -2508,7 +2513,9 @@ public class WifiStateMachine extends StateMachine { // to the driver happened between mPersistedCountryCode getting set // and now, so simply persisting it here would mean we have sent // nothing to the driver. Send the cmd so it might be set now. - sendMessageAtFrontOfQueue(CMD_SET_COUNTRY_CODE, countryCode); + int sequenceNum = mCountryCodeSequence.incrementAndGet(); + sendMessageAtFrontOfQueue(CMD_SET_COUNTRY_CODE, + sequenceNum, 0, countryCode); } break; case CMD_SET_BATCHED_SCAN: @@ -3091,18 +3098,29 @@ public class WifiStateMachine extends StateMachine { break; case CMD_SET_COUNTRY_CODE: String country = (String) message.obj; + final boolean persist = (message.arg2 == 1); + final int sequence = message.arg1; + if (sequence != mCountryCodeSequence.get()) { + if (DBG) log("set country code ignored due to sequence num"); + break; + } if (DBG) log("set country code " + country); - if (country != null) { - country = country.toUpperCase(Locale.ROOT); - if (mLastSetCountryCode == null - || country.equals(mLastSetCountryCode) == false) { - if (mWifiNative.setCountryCode(country)) { - mLastSetCountryCode = country; - } else { - loge("Failed to set country code " + country); - } + if (persist) { + mPersistedCountryCode = country; + Settings.Global.putString(mContext.getContentResolver(), + Settings.Global.WIFI_COUNTRY_CODE, + country); + } + country = country.toUpperCase(Locale.ROOT); + if (mLastSetCountryCode == null + || country.equals(mLastSetCountryCode) == false) { + if (mWifiNative.setCountryCode(country)) { + mLastSetCountryCode = country; + } else { + loge("Failed to set country code " + country); } } + mWifiP2pChannel.sendMessage(WifiP2pService.SET_COUNTRY_CODE, country); break; case CMD_SET_FREQUENCY_BAND: int band = message.arg1; |