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

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

Merge changes I798d8fec,I4a2d5866

* changes:
  MacAddress: address api review comments
  Expose the MacAddress class in the api
parents 7be7d422 a0ecf38d
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -25838,6 +25838,23 @@ package android.net {
    enum_constant public static final android.net.LocalSocketAddress.Namespace RESERVED;
  }
  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 boolean isLocallyAssigned();
    method public byte[] toByteArray();
    method public java.lang.String toOuiString();
    method public void writeToParcel(android.os.Parcel, int);
    field public static final android.net.MacAddress BROADCAST_ADDRESS;
    field public static final android.os.Parcelable.Creator<android.net.MacAddress> CREATOR;
    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 {
    method public java.lang.String getBody();
    method public java.lang.String getCc();
+5 −6
Original line number Diff line number Diff line
@@ -33,8 +33,6 @@ import java.util.Random;
 *
 * This class only supports 48 bits long addresses and does not support 64 bits long addresses.
 * Instances of this class are immutable.
 *
 * @hide
 */
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,
     * with the lower 3 bytes constituting the NIC part replaced with 0.
     * @return a String representation of the OUI part of this MacAddress made of 3 hexadecimal
     * numbers in [0,ff] joined by ':' characters.
     */
    public String toSafeString() {
        return stringAddrFromLongAddr(mAddr & OUI_MASK);
    public String toOuiString() {
        return String.format(
                "%02x:%02x:%02x", (mAddr >> 40) & 0xff, (mAddr >> 32) & 0xff, (mAddr >> 24) & 0xff);
    }

    @Override
+6 −6
Original line number Diff line number Diff line
@@ -73,18 +73,18 @@ public class MacAddressTest {
    }

    @Test
    public void testToSafeString() {
    public void testToOuiString() {
        String[][] macs = {
            {"07:00:d3:56:8a:c4", "07:00:d3:00:00:00"},
            {"33:33:aa:bb:cc:dd", "33:33:aa:00:00:00"},
            {"06:00:00:00:00:00", "06:00:00:00:00:00"},
            {"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"},
            {"06:00:00:00:00:00", "06:00:00"},
            {"07:00:d3:56:8a:c4", "07:00:d3"}
        };

        for (String[] pair : macs) {
            String mac = pair[0];
            String expected = pair[1];
            assertEquals(expected, MacAddress.fromString(mac).toSafeString());
            assertEquals(expected, MacAddress.fromString(mac).toOuiString());
        }
    }