summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVinit Deshpande <vinitd@google.com>2015-09-27 11:44:07 -0700
committerVinit Deshpande <vinitd@google.com>2015-09-27 20:03:40 -0700
commit98e43e5f48a4c87343fc311feda4fa5489948822 (patch)
treef563cf07712c1196e0f79ae3e8d5b381774f5230
parent39bf8e134381411a7a46cc4c2b635c83d630db71 (diff)
downloadandroid_frameworks_opt_net_wifi-98e43e5f48a4c87343fc311feda4fa5489948822.tar.gz
android_frameworks_opt_net_wifi-98e43e5f48a4c87343fc311feda4fa5489948822.tar.bz2
android_frameworks_opt_net_wifi-98e43e5f48a4c87343fc311feda4fa5489948822.zip
Don't reset country code on mobile signal loss
Since mobile signal is lost too often; resetting country code on this trigger causes too many changes. This change restricts resetting country code only on two triggers 1. When airplane mode is turned ON 2. When SIM is removed all other triggeres to reset country code are ignored. Bug: 24363012 Change-Id: I5bc4bd8af7461da916c9a7638cf9cb457c73ac8b
-rw-r--r--service/java/com/android/server/wifi/WifiServiceImpl.java18
-rw-r--r--service/java/com/android/server/wifi/WifiStateMachine.java47
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