am 6d9ed0c3: Merge "DO NOT MERGE Debounce wifi country code Info" into klp-dev

* commit '6d9ed0c35327adfba50004fe9270ee6471459fb0':
  DO NOT MERGE Debounce wifi country code Info
This commit is contained in:
Robert Greenwalt
2014-03-10 20:06:23 +00:00
committed by Android Git Automerger
2 changed files with 36 additions and 18 deletions

View File

@ -870,7 +870,7 @@ public final class WifiService extends IWifiManager.Stub {
public void setCountryCode(String countryCode, boolean persist) { public void setCountryCode(String countryCode, boolean persist) {
Slog.i(TAG, "WifiService trying to set country code to " + countryCode + Slog.i(TAG, "WifiService trying to set country code to " + countryCode +
" with persist set to " + persist); " with persist set to " + persist);
enforceChangePermission(); enforceConnectivityInternalPermission();
final long token = Binder.clearCallingIdentity(); final long token = Binder.clearCallingIdentity();
try { try {
mWifiStateMachine.setCountryCode(countryCode, persist); mWifiStateMachine.setCountryCode(countryCode, persist);

View File

@ -233,6 +233,10 @@ public class WifiStateMachine extends StateMachine {
private DhcpStateMachine mDhcpStateMachine; private DhcpStateMachine mDhcpStateMachine;
private boolean mDhcpActive = false; 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 class InterfaceObserver extends BaseNetworkObserver {
private WifiStateMachine mWifiStateMachine; private WifiStateMachine mWifiStateMachine;
@ -1534,14 +1538,15 @@ public class WifiStateMachine extends StateMachine {
* @param persist {@code true} if the setting should be remembered. * @param persist {@code true} if the setting should be remembered.
*/ */
public void setCountryCode(String countryCode, boolean persist) { public void setCountryCode(String countryCode, boolean persist) {
if (persist) { // If it's a country code, apply immediately,
mPersistedCountryCode = countryCode; // If it's empty, delay it in case it's a momentary dropout
Settings.Global.putString(mContext.getContentResolver(), int countryCodeSequence = mCountryCodeSequence.incrementAndGet();
Settings.Global.WIFI_COUNTRY_CODE, if (TextUtils.isEmpty(countryCode)) {
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);
} }
/** /**
@ -2507,7 +2512,9 @@ public class WifiStateMachine extends StateMachine {
// to the driver happened between mPersistedCountryCode getting set // to the driver happened between mPersistedCountryCode getting set
// and now, so simply persisting it here would mean we have sent // 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. // 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; break;
case CMD_SET_BATCHED_SCAN: case CMD_SET_BATCHED_SCAN:
@ -3090,18 +3097,29 @@ public class WifiStateMachine extends StateMachine {
break; break;
case CMD_SET_COUNTRY_CODE: case CMD_SET_COUNTRY_CODE:
String country = (String) message.obj; 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 (DBG) log("set country code " + country);
if (country != null) { if (persist) {
country = country.toUpperCase(Locale.ROOT); mPersistedCountryCode = country;
if (mLastSetCountryCode == null Settings.Global.putString(mContext.getContentResolver(),
|| country.equals(mLastSetCountryCode) == false) { Settings.Global.WIFI_COUNTRY_CODE,
if (mWifiNative.setCountryCode(country)) { country);
mLastSetCountryCode = country; }
} else { country = country.toUpperCase(Locale.ROOT);
loge("Failed to set country code " + country); 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; break;
case CMD_SET_FREQUENCY_BAND: case CMD_SET_FREQUENCY_BAND:
int band = message.arg1; int band = message.arg1;