[Aware] Allow to use '_' underscore in Aware service name
Bug: 166161683
Test: atest android.net.wifi
Change-Id: Ic13b1347f4e48e0137232f5dd6d82753ac3e89b4
diff --git a/framework/java/android/net/wifi/aware/PublishConfig.java b/framework/java/android/net/wifi/aware/PublishConfig.java
index a8844c1..c795a65 100644
--- a/framework/java/android/net/wifi/aware/PublishConfig.java
+++ b/framework/java/android/net/wifi/aware/PublishConfig.java
@@ -240,8 +240,11 @@
* <p>
* The Service Name is a UTF-8 encoded string from 1 to 255 bytes in length.
* The only acceptable single-byte UTF-8 symbols for a Service Name are alphanumeric
- * values (A-Z, a-z, 0-9), the hyphen ('-'), and the period ('.'). All valid multi-byte
- * UTF-8 characters are acceptable in a Service Name.
+ * values (A-Z, a-z, 0-9), the hyphen ('-'), the period ('.') and the underscore ('_'). All
+ * valid multi-byte UTF-8 characters are acceptable in a Service Name.
+ * <p>
+ * Note: for compatibility with devices running Android 11 or older, avoid using
+ * underscore ('_') symbol as a single-byte UTF-8 service name.
* <p>
* Must be called - an empty ServiceName is not valid.
*
diff --git a/framework/java/android/net/wifi/aware/SubscribeConfig.java b/framework/java/android/net/wifi/aware/SubscribeConfig.java
index 76780f4..51c6e25 100644
--- a/framework/java/android/net/wifi/aware/SubscribeConfig.java
+++ b/framework/java/android/net/wifi/aware/SubscribeConfig.java
@@ -297,8 +297,8 @@
* <p>
* The Service Name is a UTF-8 encoded string from 1 to 255 bytes in length.
* The only acceptable single-byte UTF-8 symbols for a Service Name are alphanumeric
- * values (A-Z, a-z, 0-9), the hyphen ('-'), and the period ('.'). All valid multi-byte
- * UTF-8 characters are acceptable in a Service Name.
+ * values (A-Z, a-z, 0-9), the hyphen ('-'), the period ('.') and the underscore ('_'). All
+ * valid multi-byte UTF-8 characters are acceptable in a Service Name.
* <p>
* Must be called - an empty ServiceName is not valid.
*
diff --git a/framework/java/android/net/wifi/aware/WifiAwareUtils.java b/framework/java/android/net/wifi/aware/WifiAwareUtils.java
index 3ece93d..f1db6ed 100644
--- a/framework/java/android/net/wifi/aware/WifiAwareUtils.java
+++ b/framework/java/android/net/wifi/aware/WifiAwareUtils.java
@@ -29,8 +29,8 @@
/**
* Per spec: The Service Name is a UTF-8 encoded string from 1 to 255 bytes in length. The
* only acceptable single-byte UTF-8 symbols for a Service Name are alphanumeric values (A-Z,
- * a-z, 0-9), the hyphen ('-'), and the period ('.'). All valid multi-byte UTF-8 characters
- * are acceptable in a Service Name.
+ * a-z, 0-9), the hyphen ('-'), the underscore ('_') and the period ('.'). All valid multi-byte
+ * UTF-8 characters are acceptable in a Service Name.
*/
public static void validateServiceName(byte[] serviceNameData) throws IllegalArgumentException {
if (serviceNameData == null) {
@@ -47,9 +47,9 @@
byte b = serviceNameData[index];
if ((b & 0x80) == 0x00) {
if (!((b >= '0' && b <= '9') || (b >= 'a' && b <= 'z') || (b >= 'A' && b <= 'Z')
- || b == '-' || b == '.')) {
+ || b == '-' || b == '.' || b == '_')) {
throw new IllegalArgumentException("Invalid service name - illegal characters,"
- + " allowed = (0-9, a-z,A-Z, -, .)");
+ + " allowed = (0-9, a-z,A-Z, -, _, .)");
}
}
++index;