diff options
| author | 2019-08-23 02:52:20 -0700 | |
|---|---|---|
| committer | 2019-08-23 02:52:20 -0700 | |
| commit | 4f05f46f13f2ad857da135d2daaa9e326e49f5ab (patch) | |
| tree | 4f52f0dc967bbce711482742a9dcaf722bdb92c0 | |
| parent | 1b6d7183877475fb3389b2f1d5b66d003632ab6d (diff) | |
| parent | 65a98b4002a13f96cc0a5ac15f6058e68e5bce65 (diff) | |
Merge "avoid generating reserved local MACs" am: e5d5b73109
am: 65a98b4002
Change-Id: Id195e44b72fb0f92f4b12fb9a269b39227d1ee0d
| -rw-r--r-- | core/java/android/net/MacAddress.java | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/core/java/android/net/MacAddress.java b/core/java/android/net/MacAddress.java index aa8e01046a01..a809b28c9204 100644 --- a/core/java/android/net/MacAddress.java +++ b/core/java/android/net/MacAddress.java @@ -20,6 +20,7 @@ import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.UnsupportedAppUsage; +import android.net.wifi.WifiInfo; import android.os.Parcel; import android.os.Parcelable; @@ -364,7 +365,12 @@ public final class MacAddress implements Parcelable { long addr = r.nextLong() & VALID_LONG_MASK; addr |= LOCALLY_ASSIGNED_MASK; addr &= ~MULTICAST_MASK; - return 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.toString().equals(WifiInfo.DEFAULT_MAC_ADDRESS)) { + return createRandomUnicastAddress(); + } + return mac; } /** @@ -383,7 +389,12 @@ public final class MacAddress implements Parcelable { long addr = (base.mAddr & OUI_MASK) | (NIC_MASK & r.nextLong()); addr |= LOCALLY_ASSIGNED_MASK; addr &= ~MULTICAST_MASK; - return 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.toString().equals(WifiInfo.DEFAULT_MAC_ADDRESS)) { + return createRandomUnicastAddress(base, r); + } + return mac; } // Convenience function for working around the lack of byte literals. |