diff options
4 files changed, 52 insertions, 25 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); diff --git a/tests/wifitests/src/com/android/server/wifi/WifiCountryCodeTest.java b/tests/wifitests/src/com/android/server/wifi/WifiCountryCodeTest.java index 2e62a309b..faa2f71f8 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiCountryCodeTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiCountryCodeTest.java @@ -71,7 +71,7 @@ public class WifiCountryCodeTest { // Wifi get L2 connected. mWifiCountryCode.setReadyForChange(false); verify(mWifiNative).setCountryCode(anyString()); - assertEquals(mDefaultCountryCode, mWifiCountryCode.getCurrentCountryCode()); + assertEquals(mDefaultCountryCode, mWifiCountryCode.getCountryCodeSentToDriver()); } /** @@ -81,13 +81,13 @@ public class WifiCountryCodeTest { @Test public void useTelephonyCountryCode() throws Exception { mWifiCountryCode.setCountryCode(mTelephonyCountryCode, false); - assertEquals(null, mWifiCountryCode.getCurrentCountryCode()); + assertEquals(null, mWifiCountryCode.getCountryCodeSentToDriver()); // Supplicant started. mWifiCountryCode.setReadyForChange(true); // Wifi get L2 connected. mWifiCountryCode.setReadyForChange(false); verify(mWifiNative).setCountryCode(anyString()); - assertEquals(mTelephonyCountryCode, mWifiCountryCode.getCurrentCountryCode()); + assertEquals(mTelephonyCountryCode, mWifiCountryCode.getCountryCodeSentToDriver()); } /** @@ -98,13 +98,13 @@ public class WifiCountryCodeTest { public void setTelephonyCountryCodeAfterSupplicantStarts() throws Exception { // Supplicant starts. mWifiCountryCode.setReadyForChange(true); - assertEquals(mDefaultCountryCode, mWifiCountryCode.getCurrentCountryCode()); + assertEquals(mDefaultCountryCode, mWifiCountryCode.getCountryCodeSentToDriver()); // Telephony country code arrives. mWifiCountryCode.setCountryCode(mTelephonyCountryCode, false); // Wifi get L2 connected. mWifiCountryCode.setReadyForChange(false); verify(mWifiNative, times(2)).setCountryCode(anyString()); - assertEquals(mTelephonyCountryCode, mWifiCountryCode.getCurrentCountryCode()); + assertEquals(mTelephonyCountryCode, mWifiCountryCode.getCountryCodeSentToDriver()); } /** @@ -120,11 +120,11 @@ public class WifiCountryCodeTest { // Telephony country code arrives. mWifiCountryCode.setCountryCode(mTelephonyCountryCode, false); // Telephony coutry code won't be applied at this time. - assertEquals(mDefaultCountryCode, mWifiCountryCode.getCurrentCountryCode()); + assertEquals(mDefaultCountryCode, mWifiCountryCode.getCountryCodeSentToDriver()); mWifiCountryCode.setReadyForChange(true); // Telephony coutry is applied after supplicant is ready. verify(mWifiNative, times(2)).setCountryCode(anyString()); - assertEquals(mTelephonyCountryCode, mWifiCountryCode.getCurrentCountryCode()); + assertEquals(mTelephonyCountryCode, mWifiCountryCode.getCountryCodeSentToDriver()); } /** @@ -138,15 +138,15 @@ public class WifiCountryCodeTest { mWifiCountryCode.setReadyForChange(true); // Wifi get L2 connected. mWifiCountryCode.setReadyForChange(false); - assertEquals(mTelephonyCountryCode, mWifiCountryCode.getCurrentCountryCode()); + assertEquals(mTelephonyCountryCode, mWifiCountryCode.getCountryCodeSentToDriver()); // SIM card is removed. mWifiCountryCode.simCardRemoved(); // Country code restting is not applied yet. - assertEquals(mTelephonyCountryCode, mWifiCountryCode.getCurrentCountryCode()); + assertEquals(mTelephonyCountryCode, mWifiCountryCode.getCountryCodeSentToDriver()); mWifiCountryCode.setReadyForChange(true); // Country code restting is applied when supplicant is ready. verify(mWifiNative, times(2)).setCountryCode(anyString()); - assertEquals(mDefaultCountryCode, mWifiCountryCode.getCurrentCountryCode()); + assertEquals(mDefaultCountryCode, mWifiCountryCode.getCountryCodeSentToDriver()); } /** @@ -160,15 +160,15 @@ public class WifiCountryCodeTest { mWifiCountryCode.setReadyForChange(true); // Wifi get L2 connected. mWifiCountryCode.setReadyForChange(false); - assertEquals(mTelephonyCountryCode, mWifiCountryCode.getCurrentCountryCode()); + assertEquals(mTelephonyCountryCode, mWifiCountryCode.getCountryCodeSentToDriver()); // Airplane mode is enabled. mWifiCountryCode.simCardRemoved(); // Country code restting is not applied yet. - assertEquals(mTelephonyCountryCode, mWifiCountryCode.getCurrentCountryCode()); + assertEquals(mTelephonyCountryCode, mWifiCountryCode.getCountryCodeSentToDriver()); mWifiCountryCode.setReadyForChange(true); // Country code restting is applied when supplicant is ready. verify(mWifiNative, times(2)).setCountryCode(anyString()); - assertEquals(mDefaultCountryCode, mWifiCountryCode.getCurrentCountryCode()); + assertEquals(mDefaultCountryCode, mWifiCountryCode.getCountryCodeSentToDriver()); } /** @@ -188,6 +188,6 @@ public class WifiCountryCodeTest { // Wifi get L2 connected. mWifiCountryCode.setReadyForChange(false); verify(mWifiNative).setCountryCode(anyString()); - assertEquals(persistentCountryCode, mWifiCountryCode.getCurrentCountryCode()); + assertEquals(persistentCountryCode, mWifiCountryCode.getCountryCodeSentToDriver()); } } |