Merge changes I798d8fec,I4a2d5866 am: c5212b6654

am: 99be302c71

Change-Id: I41b507c4e4bf9b8b9082f5e7eaab8985b5bbef41
This commit is contained in:
Hugo Benichi
2017-12-19 00:06:00 +00:00
committed by android-build-merger
2 changed files with 11 additions and 12 deletions

View File

@@ -33,8 +33,6 @@ import java.util.Random;
* *
* This class only supports 48 bits long addresses and does not support 64 bits long addresses. * This class only supports 48 bits long addresses and does not support 64 bits long addresses.
* Instances of this class are immutable. * Instances of this class are immutable.
*
* @hide
*/ */
public final class MacAddress implements Parcelable { public final class MacAddress implements Parcelable {
@@ -132,11 +130,12 @@ public final class MacAddress implements Parcelable {
} }
/** /**
* @return a String representation of the OUI part of this MacAddres, * @return a String representation of the OUI part of this MacAddress made of 3 hexadecimal
* with the lower 3 bytes constituting the NIC part replaced with 0. * numbers in [0,ff] joined by ':' characters.
*/ */
public String toSafeString() { public String toOuiString() {
return stringAddrFromLongAddr(mAddr & OUI_MASK); return String.format(
"%02x:%02x:%02x", (mAddr >> 40) & 0xff, (mAddr >> 32) & 0xff, (mAddr >> 24) & 0xff);
} }
@Override @Override

View File

@@ -73,18 +73,18 @@ public class MacAddressTest {
} }
@Test @Test
public void testToSafeString() { public void testToOuiString() {
String[][] macs = { String[][] macs = {
{"07:00:d3:56:8a:c4", "07:00:d3:00:00:00"}, {"07:00:d3:56:8a:c4", "07:00:d3"},
{"33:33:aa:bb:cc:dd", "33:33:aa:00:00:00"}, {"33:33:aa:bb:cc:dd", "33:33:aa"},
{"06:00:00:00:00:00", "06:00:00:00:00:00"}, {"06:00:00:00:00:00", "06:00:00"},
{"07:00:d3:56:8a:c4", "07:00:d3:00:00:00"} {"07:00:d3:56:8a:c4", "07:00:d3"}
}; };
for (String[] pair : macs) { for (String[] pair : macs) {
String mac = pair[0]; String mac = pair[0];
String expected = pair[1]; String expected = pair[1];
assertEquals(expected, MacAddress.fromString(mac).toSafeString()); assertEquals(expected, MacAddress.fromString(mac).toOuiString());
} }
} }