summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--service/java/com/android/server/wifi/WifiCountryCode.java9
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiCountryCodeTest.java17
2 files changed, 22 insertions, 4 deletions
diff --git a/service/java/com/android/server/wifi/WifiCountryCode.java b/service/java/com/android/server/wifi/WifiCountryCode.java
index 58bf90fa0..e69fb8e1c 100644
--- a/service/java/com/android/server/wifi/WifiCountryCode.java
+++ b/service/java/com/android/server/wifi/WifiCountryCode.java
@@ -131,12 +131,13 @@ public class WifiCountryCode {
*/
public synchronized boolean setCountryCode(String countryCode) {
if (DBG) Log.d(TAG, "Receive set country code request: " + countryCode);
- // Ignore empty country code.
+ // Empty country code.
if (TextUtils.isEmpty(countryCode)) {
- if (DBG) Log.d(TAG, "Ignore empty country code");
- return false;
+ if (DBG) Log.d(TAG, "Received empty country code, reset to default country code");
+ mTelephonyCountryCode = null;
+ } else {
+ mTelephonyCountryCode = countryCode.toUpperCase();
}
- mTelephonyCountryCode = countryCode.toUpperCase();
// If wpa_supplicant is ready we set the country code now, otherwise it will be
// set once wpa_supplicant is ready.
if (mReady) {
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiCountryCodeTest.java b/tests/wifitests/src/com/android/server/wifi/WifiCountryCodeTest.java
index fa35e8b5d..33aab60e1 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiCountryCodeTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiCountryCodeTest.java
@@ -167,4 +167,21 @@ public class WifiCountryCodeTest {
verify(mWifiNative, times(2)).setCountryCode(anyString());
assertEquals(mDefaultCountryCode, mWifiCountryCode.getCountryCodeSentToDriver());
}
+
+ /**
+ * Test if we can reset to the default country code when phone is out of service.
+ * Telephony service calls |setCountryCode| with an empty string when phone is out of service.
+ * In this case we should fall back to the default country code.
+ * @throws Exception
+ */
+ @Test
+ public void resetCountryCodeWhenOutOfService() throws Exception {
+ assertEquals(mDefaultCountryCode, mWifiCountryCode.getCountryCode());
+ mWifiCountryCode.setCountryCode(mTelephonyCountryCode);
+ assertEquals(mTelephonyCountryCode, mWifiCountryCode.getCountryCode());
+ // Out of service.
+ mWifiCountryCode.setCountryCode("");
+ assertEquals(mDefaultCountryCode, mWifiCountryCode.getCountryCode());
+ }
+
}