Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e65a016d authored by Hugo Benichi's avatar Hugo Benichi Committed by Gerrit Code Review
Browse files

Merge "MacAddress: add @NonNull annotations"

parents 9456c020 48872c63
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -25936,10 +25936,10 @@ package android.net {
  }
  public final class MacAddress implements android.os.Parcelable {
    method public int addressType();
    method public int describeContents();
    method public static android.net.MacAddress fromBytes(byte[]);
    method public static android.net.MacAddress fromString(java.lang.String);
    method public int getAddressType();
    method public boolean isLocallyAssigned();
    method public byte[] toByteArray();
    method public java.lang.String toOuiString();
@@ -25949,7 +25949,6 @@ package android.net {
    field public static final int TYPE_BROADCAST = 3; // 0x3
    field public static final int TYPE_MULTICAST = 2; // 0x2
    field public static final int TYPE_UNICAST = 1; // 0x1
    field public static final int TYPE_UNKNOWN = 0; // 0x0
  }
  public class MailTo {
+14 −13
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package android.net;

import android.annotation.IntDef;
import android.annotation.NonNull;
import android.os.Parcel;
import android.os.Parcelable;

@@ -60,7 +61,7 @@ public final class MacAddress implements Parcelable {
    })
    public @interface MacAddressType { }

    /** Indicates a MAC address of unknown type. */
    /** @hide Indicates a MAC address of unknown type. */
    public static final int TYPE_UNKNOWN = 0;
    /** Indicates a MAC address is a unicast address. */
    public static final int TYPE_UNICAST = 1;
@@ -92,7 +93,7 @@ public final class MacAddress implements Parcelable {
     *
     * @return the int constant representing the MAC address type of this MacAddress.
     */
    public @MacAddressType int addressType() {
    public @MacAddressType int getAddressType() {
        if (equals(BROADCAST_ADDRESS)) {
            return TYPE_BROADCAST;
        }
@@ -120,12 +121,12 @@ public final class MacAddress implements Parcelable {
    /**
     * @return a byte array representation of this MacAddress.
     */
    public byte[] toByteArray() {
    public @NonNull byte[] toByteArray() {
        return byteAddrFromLongAddr(mAddr);
    }

    @Override
    public String toString() {
    public @NonNull String toString() {
        return stringAddrFromLongAddr(mAddr);
    }

@@ -133,7 +134,7 @@ public final class MacAddress implements Parcelable {
     * @return a String representation of the OUI part of this MacAddress made of 3 hexadecimal
     * numbers in [0,ff] joined by ':' characters.
     */
    public String toOuiString() {
    public @NonNull String toOuiString() {
        return String.format(
                "%02x:%02x:%02x", (mAddr >> 40) & 0xff, (mAddr >> 32) & 0xff, (mAddr >> 24) & 0xff);
    }
@@ -197,7 +198,7 @@ public final class MacAddress implements Parcelable {
        if (!isMacAddress(addr)) {
            return TYPE_UNKNOWN;
        }
        return MacAddress.fromBytes(addr).addressType();
        return MacAddress.fromBytes(addr).getAddressType();
    }

    /**
@@ -211,7 +212,7 @@ public final class MacAddress implements Parcelable {
     *
     * @hide
     */
    public static byte[] byteAddrFromStringAddr(String addr) {
    public static @NonNull byte[] byteAddrFromStringAddr(String addr) {
        Preconditions.checkNotNull(addr);
        String[] parts = addr.split(":");
        if (parts.length != ETHER_ADDR_LEN) {
@@ -239,7 +240,7 @@ public final class MacAddress implements Parcelable {
     *
     * @hide
     */
    public static String stringAddrFromByteAddr(byte[] addr) {
    public static @NonNull String stringAddrFromByteAddr(byte[] addr) {
        if (!isMacAddress(addr)) {
            return null;
        }
@@ -291,7 +292,7 @@ public final class MacAddress implements Parcelable {

    // Internal conversion function equivalent to stringAddrFromByteAddr(byteAddrFromLongAddr(addr))
    // that avoids the allocation of an intermediary byte[].
    private static String stringAddrFromLongAddr(long addr) {
    private static @NonNull String stringAddrFromLongAddr(long addr) {
        return String.format("%02x:%02x:%02x:%02x:%02x:%02x",
                (addr >> 40) & 0xff,
                (addr >> 32) & 0xff,
@@ -310,7 +311,7 @@ public final class MacAddress implements Parcelable {
     * @return the MacAddress corresponding to the given String representation.
     * @throws IllegalArgumentException if the given String is not a valid representation.
     */
    public static MacAddress fromString(String addr) {
    public static @NonNull MacAddress fromString(@NonNull String addr) {
        return new MacAddress(longAddrFromStringAddr(addr));
    }

@@ -322,7 +323,7 @@ public final class MacAddress implements Parcelable {
     * @return the MacAddress corresponding to the given byte array representation.
     * @throws IllegalArgumentException if the given byte array is not a valid representation.
     */
    public static MacAddress fromBytes(byte[] addr) {
    public static @NonNull MacAddress fromBytes(@NonNull byte[] addr) {
        return new MacAddress(longAddrFromByteAddr(addr));
    }

@@ -336,7 +337,7 @@ public final class MacAddress implements Parcelable {
     *
     * @hide
     */
    public static MacAddress createRandomUnicastAddress() {
    public static @NonNull MacAddress createRandomUnicastAddress() {
        return createRandomUnicastAddress(BASE_GOOGLE_MAC, new Random());
    }

@@ -352,7 +353,7 @@ public final class MacAddress implements Parcelable {
     *
     * @hide
     */
    public static 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());
        addr = addr | LOCALLY_ASSIGNED_MASK;
        addr = addr & ~MULTICAST_MASK;
+1 −1
Original line number Diff line number Diff line
@@ -80,7 +80,7 @@ public class WakeupStats {
                break;
        }

        switch (ev.dstHwAddr.addressType()) {
        switch (ev.dstHwAddr.getAddressType()) {
            case MacAddress.TYPE_UNICAST:
                l2UnicastCount++;
                break;
+2 −2
Original line number Diff line number Diff line
@@ -67,7 +67,7 @@ public class MacAddressTest {
            assertEquals(msg, t.expectedType, got);

            if (got != MacAddress.TYPE_UNKNOWN) {
                assertEquals(got, MacAddress.fromBytes(t.addr).addressType());
                assertEquals(got, MacAddress.fromBytes(t.addr).getAddressType());
            }
        }
    }
@@ -191,7 +191,7 @@ public class MacAddressTest {

            assertTrue(stringRepr + " expected to be a locally assigned address",
                    mac.isLocallyAssigned());
            assertEquals(MacAddress.TYPE_UNICAST, mac.addressType());
            assertEquals(MacAddress.TYPE_UNICAST, mac.getAddressType());
            assertTrue(stringRepr + " expected to begin with " + expectedLocalOui,
                    stringRepr.startsWith(expectedLocalOui));
        }