diff options
Diffstat (limited to 'service/java/com/android')
-rw-r--r-- | service/java/com/android/server/wifi/WifiServiceImpl.java | 18 | ||||
-rw-r--r-- | service/java/com/android/server/wifi/WifiStateMachine.java | 47 |
2 files changed, 44 insertions, 21 deletions
diff --git a/service/java/com/android/server/wifi/WifiServiceImpl.java b/service/java/com/android/server/wifi/WifiServiceImpl.java index 269000fea..2b83b6884 100644 --- a/service/java/com/android/server/wifi/WifiServiceImpl.java +++ b/service/java/com/android/server/wifi/WifiServiceImpl.java @@ -69,6 +69,7 @@ import android.util.Slog; import com.android.internal.R; import com.android.internal.app.IBatteryStats; +import com.android.internal.telephony.IccCardConstants; import com.android.internal.telephony.TelephonyIntents; import com.android.internal.util.AsyncChannel; import com.android.server.am.BatteryStatsService; @@ -358,10 +359,27 @@ public final class WifiServiceImpl extends IWifiManager.Stub { if (mSettingsStore.handleAirplaneModeToggled()) { mWifiController.sendMessage(CMD_AIRPLANE_TOGGLED); } + if (mSettingsStore.isAirplaneModeOn()) { + Log.d(TAG, "resetting country code because Airplane mode is ON"); + mWifiStateMachine.resetCountryCode(); + } } }, new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED)); + mContext.registerReceiver( + new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + String state = intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE); + if (state.equals(IccCardConstants.INTENT_VALUE_ICC_ABSENT)) { + Log.d(TAG, "resetting country code because SIM is removed"); + mWifiStateMachine.resetCountryCode(); + } + } + }, + new IntentFilter(TelephonyIntents.ACTION_SIM_STATE_CHANGED)); + // Adding optimizations of only receiving broadcasts when wifi is enabled // can result in race conditions when apps toggle wifi in the background // without active user involvement. Always receive broadcasts. diff --git a/service/java/com/android/server/wifi/WifiStateMachine.java b/service/java/com/android/server/wifi/WifiStateMachine.java index 87ed29cc6..341d3f112 100644 --- a/service/java/com/android/server/wifi/WifiStateMachine.java +++ b/service/java/com/android/server/wifi/WifiStateMachine.java @@ -2434,24 +2434,32 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiPno // wifi connection is terminated; ignore resetting of code // for now (it is unclear what the chipset should do when // country code is reset) + // if mCountryCodeSequence == 0, it is the first time to set country code, always set // else only when the new country code is different from the current one to set - int countryCodeSequence = mCountryCodeSequence.get(); - String currentCountryCode = getCurrentCountryCode(); - - if (countryCodeSequence == 0 - || TextUtils.equals(countryCode, currentCountryCode) == false) { - - countryCodeSequence = mCountryCodeSequence.incrementAndGet(); - if (TextUtils.isEmpty(countryCode)) { - if (mRevertCountryCodeOnCellularLoss && !TextUtils.isEmpty(mDefaultCountryCode)) { - if (DBG) Log.d(TAG,"Reverting wifi country code to default of " - + mDefaultCountryCode); - countryCode = mDefaultCountryCode; - } + + if (TextUtils.isEmpty(countryCode)) { + if (DBG) log("Ignoring resetting of country code"); + } else { + int countryCodeSequence = mCountryCodeSequence.get(); + String currentCountryCode = getCurrentCountryCode(); + if (countryCodeSequence == 0 + || TextUtils.equals(countryCode, currentCountryCode) == false) { + + countryCodeSequence = mCountryCodeSequence.incrementAndGet(); + sendMessage(CMD_SET_COUNTRY_CODE, countryCodeSequence, persist ? 1 : 0, + countryCode); } - sendMessage(CMD_SET_COUNTRY_CODE, countryCodeSequence, persist ? 1 : 0, - countryCode); + } + } + + /** + * reset the country code to default + */ + public synchronized void resetCountryCode() { + if (mRevertCountryCodeOnCellularLoss && TextUtils.isEmpty(mDefaultCountryCode) == false) { + logd("resetting country code to " + mDefaultCountryCode); + setCountryCode(mDefaultCountryCode, /* persist = */ true); } } @@ -2470,14 +2478,13 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiPno /** * Get the country code * - * @param countryCode following ISO 3166 format + * @return countryCode following ISO 3166 format */ public String getCurrentCountryCode() { return Settings.Global.getString( mContext.getContentResolver(), Settings.Global.WIFI_COUNTRY_CODE); } - /** * Set the operational frequency band * @@ -3705,9 +3712,9 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiPno if (!mRevertCountryCodeOnCellularLoss || TextUtils.isEmpty(mDefaultCountryCode) ) { countryCode = Settings.Global.getString(mContext.getContentResolver(), Settings.Global.WIFI_COUNTRY_CODE); + Log.d(TAG,"Initialize wifi country code to persisted value of " + countryCode); } else { - Log.d(TAG,"Initialize wifi country code to default of " - + mDefaultCountryCode); + Log.d(TAG,"Initialize wifi country code to default of " + mDefaultCountryCode); countryCode = mDefaultCountryCode; } @@ -3735,8 +3742,6 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiPno } } - - private void setSuspendOptimizationsNative(int reason, boolean enabled) { if (DBG) { log("setSuspendOptimizationsNative: " + reason + " " + enabled |