From a32e2000025fb2df125c3d14c2fa55ddecd4b790 Mon Sep 17 00:00:00 2001 From: Ningyuan Wang Date: Tue, 12 Sep 2017 17:03:10 -0700 Subject: Fix case for not reverting country code on cellular loss This CL allows us to keep using last known country code on cellular loss and |mRevertCountryCodeOnCellularLoss| is set to false. This also fixes simCardRemoved() to revert country code unconditionally, and cleans up code for airplaneModeEnabled(). Bug: 65602314 Test: compile, unit tests Change-Id: I7b15d9ae197c5e2aacd7788b505e386f970786ed --- .../com/android/server/wifi/WifiCountryCode.java | 21 ++++++++--------- .../android/server/wifi/WifiCountryCodeTest.java | 27 +++++++++++++++++++++- 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/service/java/com/android/server/wifi/WifiCountryCode.java b/service/java/com/android/server/wifi/WifiCountryCode.java index e69fb8e1c..66a035f08 100644 --- a/service/java/com/android/server/wifi/WifiCountryCode.java +++ b/service/java/com/android/server/wifi/WifiCountryCode.java @@ -83,11 +83,9 @@ public class WifiCountryCode { public synchronized void simCardRemoved() { if (DBG) Log.d(TAG, "SIM Card Removed"); // SIM card is removed, we need to reset the country code to phone default. - if (mRevertCountryCodeOnCellularLoss) { - mTelephonyCountryCode = null; - if (mReady) { - updateCountryCode(); - } + mTelephonyCountryCode = null; + if (mReady) { + updateCountryCode(); } } @@ -98,12 +96,9 @@ public class WifiCountryCode { */ public synchronized void airplaneModeEnabled() { if (DBG) Log.d(TAG, "Airplane Mode Enabled"); - mTelephonyCountryCode = null; // Airplane mode is enabled, we need to reset the country code to phone default. - if (mRevertCountryCodeOnCellularLoss) { - mTelephonyCountryCode = null; - // Country code will be set upon when wpa_supplicant starts next time. - } + // Country code will be set upon when wpa_supplicant starts next time. + mTelephonyCountryCode = null; } /** @@ -133,8 +128,10 @@ public class WifiCountryCode { if (DBG) Log.d(TAG, "Receive set country code request: " + countryCode); // Empty country code. if (TextUtils.isEmpty(countryCode)) { - if (DBG) Log.d(TAG, "Received empty country code, reset to default country code"); - mTelephonyCountryCode = null; + if (mRevertCountryCodeOnCellularLoss) { + if (DBG) Log.d(TAG, "Received empty country code, reset to default country code"); + mTelephonyCountryCode = null; + } } else { mTelephonyCountryCode = countryCode.toUpperCase(); } diff --git a/tests/wifitests/src/com/android/server/wifi/WifiCountryCodeTest.java b/tests/wifitests/src/com/android/server/wifi/WifiCountryCodeTest.java index 33aab60e1..fb4e71ef5 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiCountryCodeTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiCountryCodeTest.java @@ -169,7 +169,8 @@ public class WifiCountryCodeTest { } /** - * Test if we can reset to the default country code when phone is out of service. + * Test if we can reset to the default country code when phone is out of service, when + * |config_wifi_revert_country_code_on_cellular_loss| is set to true; * 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 @@ -184,4 +185,28 @@ public class WifiCountryCodeTest { assertEquals(mDefaultCountryCode, mWifiCountryCode.getCountryCode()); } + /** + * Test if we can keep using the last known country code when phone is out of service, when + * |config_wifi_revert_country_code_on_cellular_loss| is set to false; + * Telephony service calls |setCountryCode| with an empty string when phone is out of service. + * In this case we should keep using the last known country code. + * @throws Exception + */ + @Test + public void doNotResetCountryCodeWhenOutOfService() throws Exception { + // Refresh mWifiCountryCode with |config_wifi_revert_country_code_on_cellular_loss| + // setting to false. + mWifiCountryCode = new WifiCountryCode( + mWifiNative, + mDefaultCountryCode, + false /* config_wifi_revert_country_code_on_cellular_loss */); + + assertEquals(mDefaultCountryCode, mWifiCountryCode.getCountryCode()); + mWifiCountryCode.setCountryCode(mTelephonyCountryCode); + assertEquals(mTelephonyCountryCode, mWifiCountryCode.getCountryCode()); + // Out of service. + mWifiCountryCode.setCountryCode(""); + assertEquals(mTelephonyCountryCode, mWifiCountryCode.getCountryCode()); + } + } -- cgit v1.2.3