wifi(API): NetworkSpecifier for Wifi NetworkAgent

Create an @hide NetworkSpecifier to use by the Wifi NetworkAgent. This
will be used by connectivity service to match the incoming
NetworkRequest (with WifiNetworkSpecifier) with the NetworkAgent we
created to serve that request.
The WifiNetworkAgentSpecifier will hold the current connected wifi
network configuration which will be used to pattern match the
WifiNetworkSpecifier from NetworkRequest's.

Also, added a @hide helper method in MacAddress to help with matching
bssid pattern.

Bug: 113878056
Test: Unit tests
Change-Id: I9a643f0b914d48ff64104c798ec2869db40cb24b
This commit is contained in:
Roshan Pius
2018-10-05 09:42:19 -07:00
parent d71b5643bb
commit e26dae35e7
2 changed files with 49 additions and 1 deletions

View File

@@ -17,8 +17,8 @@
package android.net;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import android.support.test.filters.SmallTest;
@@ -252,6 +252,39 @@ public class MacAddressTest {
}
}
@Test
public void testMatches() {
// match 4 bytes prefix
assertTrue(MacAddress.fromString("aa:bb:cc:dd:ee:11").matches(
MacAddress.fromString("aa:bb:cc:dd:00:00"),
MacAddress.fromString("ff:ff:ff:ff:00:00")));
// match bytes 0,1,2 and 5
assertTrue(MacAddress.fromString("aa:bb:cc:dd:ee:11").matches(
MacAddress.fromString("aa:bb:cc:00:00:11"),
MacAddress.fromString("ff:ff:ff:00:00:ff")));
// match 34 bit prefix
assertTrue(MacAddress.fromString("aa:bb:cc:dd:ee:11").matches(
MacAddress.fromString("aa:bb:cc:dd:c0:00"),
MacAddress.fromString("ff:ff:ff:ff:c0:00")));
// fail to match 36 bit prefix
assertFalse(MacAddress.fromString("aa:bb:cc:dd:ee:11").matches(
MacAddress.fromString("aa:bb:cc:dd:40:00"),
MacAddress.fromString("ff:ff:ff:ff:f0:00")));
// match all 6 bytes
assertTrue(MacAddress.fromString("aa:bb:cc:dd:ee:11").matches(
MacAddress.fromString("aa:bb:cc:dd:ee:11"),
MacAddress.fromString("ff:ff:ff:ff:ff:ff")));
// match none of 6 bytes
assertTrue(MacAddress.fromString("aa:bb:cc:dd:ee:11").matches(
MacAddress.fromString("00:00:00:00:00:00"),
MacAddress.fromString("00:00:00:00:00:00")));
}
static byte[] toByteArray(int... in) {
byte[] out = new byte[in.length];
for (int i = 0; i < in.length; i++) {