summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRoshan Pius <rpius@google.com>2018-07-11 08:04:47 -0700
committerRoshan Pius <rpius@google.com>2018-07-11 20:32:33 +0000
commit94d2929c174d4565a44aee7fcbd4e2bef598ef99 (patch)
tree8d1704538889d0fbc74ee71140e1173d19942aec /tests
parent74a92448fcfd47f7a4a2a8855a71ca05fc1fa4af (diff)
Fix country code setting for non-US locales
Changes in the CL: a) Always use "US" locale for converting the country code to upper case in WifiCountryCode. b) The HIDL interface for country code setter expects 2 bytes only. Tighten the error checks before invoking the HIDL call in SupplicantStaIfaceHal. Bug: 110670437 Test: Unit tests Test: Able to connect to wifi networks & bringup softap. Change-Id: I01a7f139cb8060f67b652e13dbb38e6dafe0ee4c
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/SupplicantStaIfaceHalTest.java27
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiCountryCodeTest.java30
2 files changed, 57 insertions, 0 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/SupplicantStaIfaceHalTest.java b/tests/wifitests/src/com/android/server/wifi/SupplicantStaIfaceHalTest.java
index b4ea5af34..33490869b 100644
--- a/tests/wifitests/src/com/android/server/wifi/SupplicantStaIfaceHalTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/SupplicantStaIfaceHalTest.java
@@ -1515,6 +1515,33 @@ public class SupplicantStaIfaceHalTest {
verify(mISupplicantStaIfaceMock).startWpsPbc(eq(anyBssidBytes));
}
+ /**
+ * Tests country code setter
+ */
+ @Test
+ public void testSetCountryCode() throws Exception {
+ when(mISupplicantStaIfaceMock.setCountryCode(any(byte[].class))).thenReturn(mStatusSuccess);
+ String testCountryCode = "US";
+
+ // Fail before initialization is performed.
+ assertFalse(mDut.setCountryCode(WLAN0_IFACE_NAME, testCountryCode));
+ verify(mISupplicantStaIfaceMock, never()).setCountryCode(any(byte[].class));
+
+ executeAndValidateInitializationSequence();
+
+ assertTrue(mDut.setCountryCode(WLAN0_IFACE_NAME, testCountryCode));
+ verify(mISupplicantStaIfaceMock).setCountryCode(eq(testCountryCode.getBytes()));
+
+ // Bad input values should fail the call.
+ reset(mISupplicantStaIfaceMock);
+
+ assertFalse(mDut.setCountryCode(WLAN0_IFACE_NAME, null));
+ verify(mISupplicantStaIfaceMock, never()).setCountryCode(any(byte[].class));
+
+ assertFalse(mDut.setCountryCode(WLAN0_IFACE_NAME, "U"));
+ verify(mISupplicantStaIfaceMock, never()).setCountryCode(any(byte[].class));
+ }
+
private WifiConfiguration createTestWifiConfiguration() {
WifiConfiguration config = new WifiConfiguration();
config.networkId = SUPPLICANT_NETWORK_ID;
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiCountryCodeTest.java b/tests/wifitests/src/com/android/server/wifi/WifiCountryCodeTest.java
index 4ce5d5e40..95554bc63 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiCountryCodeTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiCountryCodeTest.java
@@ -17,6 +17,7 @@
package com.android.server.wifi;
import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.anyString;
import static org.mockito.Mockito.times;
@@ -30,6 +31,8 @@ import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
+import java.util.Locale;
+
/**
* Unit tests for {@link com.android.server.wifi.WifiCountryCode}.
*/
@@ -166,4 +169,31 @@ public class WifiCountryCodeTest {
assertEquals(mTelephonyCountryCode, mWifiCountryCode.getCountryCode());
}
+ /**
+ * Tests that we always use the US locale for converting the provided country code regardless
+ * of the system locale set.
+ */
+ @Test
+ public void useUSLocaleForConversionToUpperCase() {
+ String oemCountryCodeLower = "us";
+ String oemCountryCodeUpper = "US";
+ String telephonyCountryCodeLower = "il";
+ String telephonyCountryCodeUpper = "IL";
+
+ mWifiCountryCode = new WifiCountryCode(
+ mWifiNative,
+ oemCountryCodeLower,
+ mRevertCountryCodeOnCellularLoss);
+
+ // Set the default locale to "tr" (Non US).
+ Locale.setDefault(new Locale("tr"));
+
+ // Trigger a country code change using the OEM country code.
+ mWifiCountryCode.setReadyForChange(true);
+ verify(mWifiNative).setCountryCode(any(), eq(oemCountryCodeUpper));
+
+ // Now trigger a country code change using the telephony country code.
+ mWifiCountryCode.setCountryCode(telephonyCountryCodeLower);
+ verify(mWifiNative).setCountryCode(any(), eq(telephonyCountryCodeUpper));
+ }
}