Keep case in MdnsServiceInfo attributes

Although case should not matter when comparing attributes,
converting all keys to lowercase breaks NsdServiceInfo APIs which
provide the original case to the caller.

Use a TreeMap with a case-insensitive comparator to ignore case when
querying keys, while keeping case information in the map.

Bug: 270885892
Test: atest MdnsServiceInfoTest
Change-Id: Id15947b1e8650eb6b59126c5d2dc8624ae4f8100
This commit is contained in:
Remi NGUYEN VAN
2023-03-06 19:46:21 +09:00
parent de5adc4f1f
commit 0e929ddfcd
2 changed files with 26 additions and 9 deletions

View File

@@ -118,6 +118,26 @@ public class MdnsServiceInfoTest {
info.getAttributes());
}
@Test
public void constructor_createWithUppercaseKeys_correctAttributes() {
MdnsServiceInfo info =
new MdnsServiceInfo(
"my-mdns-service",
new String[] {"_testtype", "_tcp"},
List.of(),
new String[] {"my-host", "local"},
12345,
"192.168.1.1",
"2001::1",
List.of("KEY=Value"),
/* textEntries= */ null);
assertEquals("Value", info.getAttributeByKey("key"));
assertEquals("Value", info.getAttributeByKey("KEY"));
assertEquals(1, info.getAttributes().size());
assertEquals("KEY", info.getAttributes().keySet().iterator().next());
}
@Test
public void getInterfaceIndex_constructorWithDefaultValues_returnsMinusOne() {
MdnsServiceInfo info =