Merge "Remember wifi country that's set before boot" into jb-mr2-dev

This commit is contained in:
Robert Greenwalt
2013-06-01 15:57:12 +00:00
committed by Android (Google) Code Review
2 changed files with 41 additions and 3 deletions

View File

@@ -651,7 +651,12 @@ public final class WifiService extends IWifiManager.Stub {
Slog.i(TAG, "WifiService trying to set country code to " + countryCode +
" with persist set to " + persist);
enforceChangePermission();
mWifiStateMachine.setCountryCode(countryCode, persist);
final long token = Binder.clearCallingIdentity();
try {
mWifiStateMachine.setCountryCode(countryCode, persist);
} finally {
Binder.restoreCallingIdentity(token);
}
}
/**
@@ -668,7 +673,12 @@ public final class WifiService extends IWifiManager.Stub {
if (!isDualBandSupported()) return;
Slog.i(TAG, "WifiService trying to set frequency band to " + band +
" with persist set to " + persist);
mWifiStateMachine.setFrequencyBand(band, persist);
final long token = Binder.clearCallingIdentity();
try {
mWifiStateMachine.setFrequencyBand(band, persist);
} finally {
Binder.restoreCallingIdentity(token);
}
}

View File

@@ -347,6 +347,8 @@ public class WifiStateMachine extends StateMachine {
public static final int CMD_DISABLE_P2P_REQ = BASE + 132;
public static final int CMD_DISABLE_P2P_RSP = BASE + 133;
public static final int CMD_BOOT_COMPLETED = BASE + 134;
public static final int CONNECT_MODE = 1;
public static final int SCAN_ONLY_MODE = 2;
public static final int SCAN_ONLY_WITH_WIFI_OFF_MODE = 3;
@@ -410,6 +412,10 @@ public class WifiStateMachine extends StateMachine {
private int mDelayedStopCounter;
private boolean mInDelayedStop = false;
// sometimes telephony gives us this data before boot is complete and we can't store it
// until after, so the write is deferred
private volatile String mPersistedCountryCode;
private static final int MIN_RSSI = -200;
private static final int MAX_RSSI = 256;
@@ -637,6 +643,15 @@ public class WifiStateMachine extends StateMachine {
}
});
mContext.registerReceiver(
new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
sendMessage(CMD_BOOT_COMPLETED);
}
},
new IntentFilter(Intent.ACTION_BOOT_COMPLETED));
mScanResultCache = new LruCache<String, ScanResult>(SCAN_RESULT_CACHE_SIZE);
PowerManager powerManager = (PowerManager)mContext.getSystemService(Context.POWER_SERVICE);
@@ -1004,6 +1019,7 @@ public class WifiStateMachine extends StateMachine {
*/
public void setCountryCode(String countryCode, boolean persist) {
if (persist) {
mPersistedCountryCode = countryCode;
Settings.Global.putString(mContext.getContentResolver(),
Settings.Global.WIFI_COUNTRY_CODE,
countryCode);
@@ -1889,6 +1905,19 @@ public class WifiStateMachine extends StateMachine {
setSuspendOptimizations(SUSPEND_DUE_TO_HIGH_PERF, true);
}
break;
case CMD_BOOT_COMPLETED:
String countryCode = mPersistedCountryCode;
if (TextUtils.isEmpty(countryCode) == false) {
Settings.Global.putString(mContext.getContentResolver(),
Settings.Global.WIFI_COUNTRY_CODE,
countryCode);
// it may be that the state transition that should send this info
// 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);
}
break;
/* Discard */
case CMD_START_SUPPLICANT:
case CMD_STOP_SUPPLICANT:
@@ -2357,7 +2386,6 @@ public class WifiStateMachine extends StateMachine {
mInDelayedStop = false;
mDelayedStopCounter++;
updateBatteryWorkSource(null);
/**
* Enable bluetooth coexistence scan mode when bluetooth connection is active.
* When this mode is on, some of the low-level scan parameters used by the