summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorNingyuan Wang <nywang@google.com>2016-07-19 15:53:11 -0700
committerNingyuan Wang <nywang@google.com>2016-07-22 10:46:56 -0700
commit37b06cd7aae7fe27cfaf1d95cc9901548765406b (patch)
tree7a06171777328221fc20a1d698bf4b1e8ce2dfc4 /service
parent62a41b4a43cba3fad221291533c145863b7001f0 (diff)
downloadwifi-37b06cd7aae7fe27cfaf1d95cc9901548765406b.tar.gz
Fix tethering failure when wifi is not started
getCurrentCountryCode() returns the country code which we already sent to driver. However, sometimes when wifi and location scan are not started, we have a valid country code but we didn't set it. In this case getCurrentCountryCode() returns null. This will confuse SoftApManager and break tethering. This also causes WifiApDialog not to show 5GHz option in the UI when user creates a new wifi hotspot config. In this CL we fix the incorrectly reported country code by adding a function getCountryCode() which returns a valid country code regardless of was it sent to driver or not. SoftApManager and WifiApDialog will use this function to make decisions. In addition, we also rename getCurrentCountryCode() to getCountryCode SentToDriver() for better readability. BUG=30200338 TEST=compile TEST=unit tests TEST=manual tests Change-Id: I5ba576509f9f401f4d57a4628a147ac8871552c0
Diffstat (limited to 'service')
-rw-r--r--service/java/com/android/server/wifi/WifiCountryCode.java30
-rw-r--r--service/java/com/android/server/wifi/WifiServiceImpl.java6
-rw-r--r--service/java/com/android/server/wifi/WifiStateMachine.java13
3 files changed, 38 insertions, 11 deletions
diff --git a/service/java/com/android/server/wifi/WifiCountryCode.java b/service/java/com/android/server/wifi/WifiCountryCode.java
index bd9b14b4b..13396562a 100644
--- a/service/java/com/android/server/wifi/WifiCountryCode.java
+++ b/service/java/com/android/server/wifi/WifiCountryCode.java
@@ -21,6 +21,9 @@ import android.util.Log;
/**
* Provide functions for making changes to WiFi country code.
+ * This Country Code is from MCC or phone default setting. This class sends Country Code
+ * to driver through wpa_supplicant when WifiStateMachine marks current state as ready
+ * using setReadyForChange(true).
*/
public class WifiCountryCode {
private static final String TAG = "WifiCountryCode";
@@ -149,12 +152,29 @@ public class WifiCountryCode {
}
/**
- * @return Get the current country code, returns null if no country code is set.
+ * Method to get the Country Code that was sent to wpa_supplicant.
+ *
+ * @return Returns the local copy of the Country Code that was sent to the driver upon
+ * setReadyForChange(true).
+ * If wpa_supplicant was never started, this may be null even if a SIM reported a valid
+ * country code.
+ * Returns null if no Country Code was sent to driver.
*/
- public synchronized String getCurrentCountryCode() {
+ public synchronized String getCountryCodeSentToDriver() {
return mCurrentCountryCode;
}
+ /**
+ * Method to return the currently reported Country Code from the SIM or phone default setting.
+ *
+ * @return The currently reported Country Code from the SIM. If there is no Country Code
+ * reported from SIM, a phone default Country Code will be returned.
+ * Returns null when there is no Country Code available.
+ */
+ public synchronized String getCountryCode() {
+ return pickCountryCode();
+ }
+
private void updateCountryCode() {
if (DBG) Log.d(TAG, "Update country code");
String country = pickCountryCode();
@@ -163,7 +183,7 @@ public class WifiCountryCode {
// 1. Wpa supplicant may silently modify the country code.
// 2. If Wifi restarted therefoere wpa_supplicant also restarted,
// the country code counld be reset to '00' by wpa_supplicant.
- if (country.length() != 0) {
+ if (country != null) {
setCountryCodeNative(country);
}
// We do not set country code if there is no candidate. This is reasonable
@@ -178,8 +198,8 @@ public class WifiCountryCode {
if (mDefaultCountryCode != null) {
return mDefaultCountryCode;
}
- // If there is no candidate country code we will return an empty string.
- return "";
+ // If there is no candidate country code we will return null.
+ return null;
}
private boolean setCountryCodeNative(String country) {
diff --git a/service/java/com/android/server/wifi/WifiServiceImpl.java b/service/java/com/android/server/wifi/WifiServiceImpl.java
index be24e49a9..740ef6e54 100644
--- a/service/java/com/android/server/wifi/WifiServiceImpl.java
+++ b/service/java/com/android/server/wifi/WifiServiceImpl.java
@@ -1127,11 +1127,13 @@ public class WifiServiceImpl extends IWifiManager.Stub {
/**
* Get the country code
- * @return ISO 3166 country code.
+ * @return Get the best choice country code for wifi, regardless of if it was set or
+ * not.
+ * Returns null when there is no country code available.
*/
public String getCountryCode() {
enforceConnectivityInternalPermission();
- String country = mCountryCode.getCurrentCountryCode();
+ String country = mCountryCode.getCountryCode();
return country;
}
/**
diff --git a/service/java/com/android/server/wifi/WifiStateMachine.java b/service/java/com/android/server/wifi/WifiStateMachine.java
index e3ab3bc43..ab9142020 100644
--- a/service/java/com/android/server/wifi/WifiStateMachine.java
+++ b/service/java/com/android/server/wifi/WifiStateMachine.java
@@ -2300,10 +2300,15 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss
pw.println("mUserWantsSuspendOpt " + mUserWantsSuspendOpt);
pw.println("mSuspendOptNeedsDisabled " + mSuspendOptNeedsDisabled);
pw.println("Supplicant status " + mWifiNative.status(true));
- if (mCountryCode.getCurrentCountryCode() != null) {
- pw.println("CurrentCountryCode " + mCountryCode.getCurrentCountryCode());
+ if (mCountryCode.getCountryCodeSentToDriver() != null) {
+ pw.println("CountryCode sent to driver " + mCountryCode.getCountryCodeSentToDriver());
} else {
- pw.println("CurrentCountryCode is not initialized");
+ if (mCountryCode.getCountryCode() != null) {
+ pw.println("CountryCode: " +
+ mCountryCode.getCountryCode() + " was not sent to driver");
+ } else {
+ pw.println("CountryCode was not initialized");
+ }
}
pw.println("mConnectedModeGScanOffloadStarted " + mConnectedModeGScanOffloadStarted);
pw.println("mGScanPeriodMilli " + mGScanPeriodMilli);
@@ -7669,7 +7674,7 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss
checkAndSetConnectivityInstance();
mSoftApManager = mFacade.makeSoftApManager(
mContext, getHandler().getLooper(), mWifiNative, mNwService,
- mCm, mCountryCode.getCurrentCountryCode(),
+ mCm, mCountryCode.getCountryCode(),
mWifiApConfigStore.getAllowed2GChannel(),
new SoftApListener());
mSoftApManager.start(config);