Merge "Followup to CL 1103896" am: f8b0fcbc6c am: 75d347a58a am: f354fa075c
am: dd17a7d709
Change-Id: I9aec9d7481722e2533200dcab9bc9066142496a1
This commit is contained in:
@@ -85,6 +85,9 @@ public final class MacAddress implements Parcelable {
|
|||||||
private static final long OUI_MASK = MacAddress.fromString("ff:ff:ff:0:0:0").mAddr;
|
private static final long OUI_MASK = MacAddress.fromString("ff:ff:ff:0:0:0").mAddr;
|
||||||
private static final long NIC_MASK = MacAddress.fromString("0:0:0:ff:ff:ff").mAddr;
|
private static final long NIC_MASK = MacAddress.fromString("0:0:0:ff:ff:ff").mAddr;
|
||||||
private static final MacAddress BASE_GOOGLE_MAC = MacAddress.fromString("da:a1:19:0:0:0");
|
private static final MacAddress BASE_GOOGLE_MAC = MacAddress.fromString("da:a1:19:0:0:0");
|
||||||
|
/** Default wifi MAC address used for a special purpose **/
|
||||||
|
private static final MacAddress DEFAULT_MAC_ADDRESS =
|
||||||
|
MacAddress.fromString(WifiInfo.DEFAULT_MAC_ADDRESS);
|
||||||
|
|
||||||
// Internal representation of the MAC address as a single 8 byte long.
|
// Internal representation of the MAC address as a single 8 byte long.
|
||||||
// The encoding scheme sets the two most significant bytes to 0. The 6 bytes of the
|
// The encoding scheme sets the two most significant bytes to 0. The 6 bytes of the
|
||||||
@@ -361,16 +364,7 @@ public final class MacAddress implements Parcelable {
|
|||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
public static @NonNull MacAddress createRandomUnicastAddress() {
|
public static @NonNull MacAddress createRandomUnicastAddress() {
|
||||||
SecureRandom r = new SecureRandom();
|
return createRandomUnicastAddress(null, new SecureRandom());
|
||||||
long addr = r.nextLong() & VALID_LONG_MASK;
|
|
||||||
addr |= LOCALLY_ASSIGNED_MASK;
|
|
||||||
addr &= ~MULTICAST_MASK;
|
|
||||||
MacAddress mac = new MacAddress(addr);
|
|
||||||
// WifiInfo.DEFAULT_MAC_ADDRESS is being used for another purpose, so do not use it here.
|
|
||||||
if (mac.toString().equals(WifiInfo.DEFAULT_MAC_ADDRESS)) {
|
|
||||||
return createRandomUnicastAddress();
|
|
||||||
}
|
|
||||||
return mac;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -380,18 +374,23 @@ public final class MacAddress implements Parcelable {
|
|||||||
* The locally assigned bit is always set to 1. The multicast bit is always set to 0.
|
* The locally assigned bit is always set to 1. The multicast bit is always set to 0.
|
||||||
*
|
*
|
||||||
* @param base a base MacAddress whose OUI is used for generating the random address.
|
* @param base a base MacAddress whose OUI is used for generating the random address.
|
||||||
|
* If base == null then the OUI will also be randomized.
|
||||||
* @param r a standard Java Random object used for generating the random address.
|
* @param r a standard Java Random object used for generating the random address.
|
||||||
* @return a random locally assigned MacAddress.
|
* @return a random locally assigned MacAddress.
|
||||||
*
|
*
|
||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
public static @NonNull MacAddress createRandomUnicastAddress(MacAddress base, Random r) {
|
public static @NonNull MacAddress createRandomUnicastAddress(MacAddress base, Random r) {
|
||||||
long addr = (base.mAddr & OUI_MASK) | (NIC_MASK & r.nextLong());
|
long addr;
|
||||||
|
if (base == null) {
|
||||||
|
addr = r.nextLong() & VALID_LONG_MASK;
|
||||||
|
} else {
|
||||||
|
addr = (base.mAddr & OUI_MASK) | (NIC_MASK & r.nextLong());
|
||||||
|
}
|
||||||
addr |= LOCALLY_ASSIGNED_MASK;
|
addr |= LOCALLY_ASSIGNED_MASK;
|
||||||
addr &= ~MULTICAST_MASK;
|
addr &= ~MULTICAST_MASK;
|
||||||
MacAddress mac = new MacAddress(addr);
|
MacAddress mac = new MacAddress(addr);
|
||||||
// WifiInfo.DEFAULT_MAC_ADDRESS is being used for another purpose, so do not use it here.
|
if (mac.equals(DEFAULT_MAC_ADDRESS)) {
|
||||||
if (mac.toString().equals(WifiInfo.DEFAULT_MAC_ADDRESS)) {
|
|
||||||
return createRandomUnicastAddress(base, r);
|
return createRandomUnicastAddress(base, r);
|
||||||
}
|
}
|
||||||
return mac;
|
return mac;
|
||||||
|
|||||||
Reference in New Issue
Block a user