summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--service/java/com/android/server/wifi/SupplicantStaNetworkHal.java4
-rw-r--r--service/java/com/android/server/wifi/WifiConfigurationUtil.java2
-rw-r--r--service/java/com/android/server/wifi/util/NativeUtil.java18
-rw-r--r--tests/wifitests/src/com/android/server/wifi/util/NativeUtilTest.java25
4 files changed, 32 insertions, 17 deletions
diff --git a/service/java/com/android/server/wifi/SupplicantStaNetworkHal.java b/service/java/com/android/server/wifi/SupplicantStaNetworkHal.java
index 61ec9b3ab..b35989797 100644
--- a/service/java/com/android/server/wifi/SupplicantStaNetworkHal.java
+++ b/service/java/com/android/server/wifi/SupplicantStaNetworkHal.java
@@ -199,7 +199,7 @@ public class SupplicantStaNetworkHal {
for (int i = 0; i < 4; i++) {
config.wepKeys[i] = null;
if (getWepKey(i) && !ArrayUtils.isEmpty(mWepKey)) {
- config.wepKeys[i] = NativeUtil.bytesToHexOrQuotedAsciiString(mWepKey);
+ config.wepKeys[i] = NativeUtil.bytesToHexOrQuotedString(mWepKey);
}
}
/** PSK pass phrase */
@@ -293,7 +293,7 @@ public class SupplicantStaNetworkHal {
for (int i = 0; i < config.wepKeys.length; i++) {
if (config.wepKeys[i] != null) {
if (!setWepKey(
- i, NativeUtil.hexOrQuotedAsciiStringToBytes(config.wepKeys[i]))) {
+ i, NativeUtil.hexOrQuotedStringToBytes(config.wepKeys[i]))) {
Log.e(TAG, "failed to set wep_key " + i);
return false;
}
diff --git a/service/java/com/android/server/wifi/WifiConfigurationUtil.java b/service/java/com/android/server/wifi/WifiConfigurationUtil.java
index fef78aade..dadc8a4e8 100644
--- a/service/java/com/android/server/wifi/WifiConfigurationUtil.java
+++ b/service/java/com/android/server/wifi/WifiConfigurationUtil.java
@@ -345,7 +345,7 @@ public class WifiConfigurationUtil {
}
}
try {
- NativeUtil.hexOrQuotedAsciiStringToBytes(psk);
+ NativeUtil.hexOrQuotedStringToBytes(psk);
} catch (IllegalArgumentException e) {
Log.e(TAG, "validatePsk failed: malformed string: " + psk);
return false;
diff --git a/service/java/com/android/server/wifi/util/NativeUtil.java b/service/java/com/android/server/wifi/util/NativeUtil.java
index 95ee11eb8..84f93514c 100644
--- a/service/java/com/android/server/wifi/util/NativeUtil.java
+++ b/service/java/com/android/server/wifi/util/NativeUtil.java
@@ -210,13 +210,13 @@ public class NativeUtil {
/**
* Converts an string to an arraylist of UTF_8 byte values.
* These forms are acceptable:
- * a) ASCII String encapsulated in quotes, or
+ * a) UTF-8 String encapsulated in quotes, or
* b) Hex string with no delimiters.
*
* @param str String to be converted.
* @throws IllegalArgumentException for null string.
*/
- public static ArrayList<Byte> hexOrQuotedAsciiStringToBytes(String str) {
+ public static ArrayList<Byte> hexOrQuotedStringToBytes(String str) {
if (str == null) {
throw new IllegalArgumentException("null string");
}
@@ -232,21 +232,21 @@ public class NativeUtil {
/**
* Converts an ArrayList<Byte> of UTF_8 byte values to string.
* The string will either be:
- * a) ASCII String encapsulated in quotes (if all the bytes are ASCII encodeable and non null),
+ * a) UTF-8 String encapsulated in quotes (if all the bytes are UTF-8 encodeable and non null),
* or
* b) Hex string with no delimiters.
*
* @param bytes List of bytes for ssid.
* @throws IllegalArgumentException for null bytes.
*/
- public static String bytesToHexOrQuotedAsciiString(ArrayList<Byte> bytes) {
+ public static String bytesToHexOrQuotedString(ArrayList<Byte> bytes) {
if (bytes == null) {
throw new IllegalArgumentException("null ssid bytes");
}
byte[] byteArray = byteArrayFromArrayList(bytes);
// Check for 0's in the byte stream in which case we cannot convert this into a string.
if (!bytes.contains(Byte.valueOf((byte) 0))) {
- CharsetDecoder decoder = StandardCharsets.US_ASCII.newDecoder();
+ CharsetDecoder decoder = StandardCharsets.UTF_8.newDecoder();
try {
CharBuffer decoded = decoder.decode(ByteBuffer.wrap(byteArray));
return "\"" + decoded.toString() + "\"";
@@ -259,20 +259,20 @@ public class NativeUtil {
/**
* Converts an ssid string to an arraylist of UTF_8 byte values.
* These forms are acceptable:
- * a) ASCII String encapsulated in quotes, or
+ * a) UTF-8 String encapsulated in quotes, or
* b) Hex string with no delimiters.
*
* @param ssidStr String to be converted.
* @throws IllegalArgumentException for null string.
*/
public static ArrayList<Byte> decodeSsid(String ssidStr) {
- return hexOrQuotedAsciiStringToBytes(ssidStr);
+ return hexOrQuotedStringToBytes(ssidStr);
}
/**
* Converts an ArrayList<Byte> of UTF_8 byte values to ssid string.
* The string will either be:
- * a) ASCII String encapsulated in quotes (if all the bytes are ASCII encodeable and non null),
+ * a) UTF-8 String encapsulated in quotes (if all the bytes are UTF-8 encodeable and non null),
* or
* b) Hex string with no delimiters.
*
@@ -280,7 +280,7 @@ public class NativeUtil {
* @throws IllegalArgumentException for null bytes.
*/
public static String encodeSsid(ArrayList<Byte> ssidBytes) {
- return bytesToHexOrQuotedAsciiString(ssidBytes);
+ return bytesToHexOrQuotedString(ssidBytes);
}
/**
diff --git a/tests/wifitests/src/com/android/server/wifi/util/NativeUtilTest.java b/tests/wifitests/src/com/android/server/wifi/util/NativeUtilTest.java
index 3f51c5a6a..367e6b34a 100644
--- a/tests/wifitests/src/com/android/server/wifi/util/NativeUtilTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/util/NativeUtilTest.java
@@ -98,10 +98,25 @@ public class NativeUtilTest {
}
/**
+ * Test that conversion of ssid bytes to quoted UTF8 string ssid works.
+ */
+ @Test
+ public void testUtf8SsidDecode() throws Exception {
+ assertEquals(
+ new ArrayList<>(
+ Arrays.asList((byte) 0x41, (byte) 0x6e, (byte) 0x64, (byte) 0x72,
+ (byte) 0x6f, (byte) 0x69, (byte) 0x64, (byte) 0x41, (byte) 0x50,
+ (byte) 0xe3, (byte) 0x81, (byte) 0x8f, (byte) 0xe3, (byte) 0x81,
+ (byte) 0xa0, (byte) 0xe3, (byte) 0x81, (byte) 0x95, (byte) 0xe3,
+ (byte) 0x81, (byte) 0x84)),
+ NativeUtil.decodeSsid("\"AndroidAPください\""));
+ }
+
+ /**
* Test that conversion of ssid bytes to hex string ssid works.
*/
@Test
- public void testNonAsciiSsidDecode() throws Exception {
+ public void testNonSsidDecode() throws Exception {
assertEquals(
new ArrayList<>(
Arrays.asList((byte) 0xf5, (byte) 0xe4, (byte) 0xab, (byte) 0x78,
@@ -110,10 +125,10 @@ public class NativeUtilTest {
}
/**
- * Test that conversion of ssid bytes to quoted ASCII string ssid works.
+ * Test that conversion of ssid bytes to quoted string ssid works.
*/
@Test
- public void testAsciiSsidEncode() throws Exception {
+ public void testSsidEncode() throws Exception {
assertEquals(
"\"ssid_test123\"",
NativeUtil.encodeSsid(new ArrayList<>(
@@ -126,7 +141,7 @@ public class NativeUtilTest {
* Test that conversion of byte array to hex string works when the byte array contains 0.
*/
@Test
- public void testNullCharInAsciiSsidEncode() throws Exception {
+ public void testNullCharInSsidEncode() throws Exception {
assertEquals(
"007369645f74657374313233",
NativeUtil.encodeSsid(new ArrayList<>(
@@ -139,7 +154,7 @@ public class NativeUtilTest {
* Test that conversion of byte array to hex string ssid works.
*/
@Test
- public void testNonAsciiSsidEncode() throws Exception {
+ public void testNonSsidEncode() throws Exception {
assertEquals(
"f5e4ab78ab3432439a",
NativeUtil.encodeSsid(new ArrayList<>(