Skip to content
Snippets Groups Projects
Commit 71524f2b authored by Zhanglong Xia's avatar Zhanglong Xia Committed by Gerrit Code Review
Browse files

Merge "Check whether the WiFi country code is a valid Thread country code" into main

parents 424ef188 a888e726
No related branches found
No related tags found
No related merge requests found
...@@ -310,7 +310,14 @@ public class ThreadNetworkCountryCode { ...@@ -310,7 +310,14 @@ public class ThreadNetworkCountryCode {
public void onActiveCountryCodeChanged(String countryCode) { public void onActiveCountryCodeChanged(String countryCode) {
Log.d(TAG, "Wifi country code is changed to " + countryCode); Log.d(TAG, "Wifi country code is changed to " + countryCode);
synchronized ("ThreadNetworkCountryCode.this") { synchronized ("ThreadNetworkCountryCode.this") {
mWifiCountryCodeInfo = new CountryCodeInfo(countryCode, COUNTRY_CODE_SOURCE_WIFI); if (isValidCountryCode(countryCode)) {
mWifiCountryCodeInfo =
new CountryCodeInfo(countryCode, COUNTRY_CODE_SOURCE_WIFI);
} else {
Log.w(TAG, "WiFi country code " + countryCode + " is invalid");
mWifiCountryCodeInfo = null;
}
updateCountryCode(false /* forceUpdate */); updateCountryCode(false /* forceUpdate */);
} }
} }
......
...@@ -86,6 +86,7 @@ public class ThreadNetworkCountryCodeTest { ...@@ -86,6 +86,7 @@ public class ThreadNetworkCountryCodeTest {
private static final String TEST_COUNTRY_CODE_US = "US"; private static final String TEST_COUNTRY_CODE_US = "US";
private static final String TEST_COUNTRY_CODE_CN = "CN"; private static final String TEST_COUNTRY_CODE_CN = "CN";
private static final String TEST_COUNTRY_CODE_INVALID = "INVALID"; private static final String TEST_COUNTRY_CODE_INVALID = "INVALID";
private static final String TEST_WIFI_DEFAULT_COUNTRY_CODE = "00";
private static final int TEST_SIM_SLOT_INDEX_0 = 0; private static final int TEST_SIM_SLOT_INDEX_0 = 0;
private static final int TEST_SIM_SLOT_INDEX_1 = 1; private static final int TEST_SIM_SLOT_INDEX_1 = 1;
...@@ -258,6 +259,21 @@ public class ThreadNetworkCountryCodeTest { ...@@ -258,6 +259,21 @@ public class ThreadNetworkCountryCodeTest {
assertThat(mThreadNetworkCountryCode.getCountryCode()).isEqualTo(TEST_COUNTRY_CODE_US); assertThat(mThreadNetworkCountryCode.getCountryCode()).isEqualTo(TEST_COUNTRY_CODE_US);
} }
@Test
public void wifiCountryCode_wifiDefaultCountryCodeIsActive_wifiCountryCodeIsNotUsed() {
mThreadNetworkCountryCode.initialize();
verify(mWifiManager)
.registerActiveCountryCodeChangedCallback(
any(), mWifiCountryCodeReceiverCaptor.capture());
mWifiCountryCodeReceiverCaptor
.getValue()
.onActiveCountryCodeChanged(TEST_WIFI_DEFAULT_COUNTRY_CODE);
assertThat(mThreadNetworkCountryCode.getCountryCode())
.isNotEqualTo(TEST_WIFI_DEFAULT_COUNTRY_CODE);
}
@Test @Test
public void wifiCountryCode_wifiCountryCodeIsInactive_defaultCountryCodeIsUsed() { public void wifiCountryCode_wifiCountryCodeIsInactive_defaultCountryCodeIsUsed() {
mThreadNetworkCountryCode.initialize(); mThreadNetworkCountryCode.initialize();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment