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:
@@ -393,4 +393,19 @@ public final class MacAddress implements Parcelable {
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this MAC Address matches the provided range.
|
||||
*
|
||||
* @param baseAddress MacAddress representing the base address to compare with.
|
||||
* @param mask MacAddress representing the mask to use during comparison.
|
||||
* @return true if this MAC Address matches the given range.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public boolean matches(@NonNull MacAddress baseAddress, @NonNull MacAddress mask) {
|
||||
Preconditions.checkNotNull(baseAddress);
|
||||
Preconditions.checkNotNull(mask);
|
||||
return (mAddr & mask.mAddr) == (baseAddress.mAddr & mask.mAddr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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++) {
|
||||
|
||||
Reference in New Issue
Block a user