MacAddress: add @NonNull annotations
This patch adds to the MacAddress class: - getAddressType() method which replaces addressType(), for naming consistency - @NonNull annotations on all input and output reference values for all public methods (@hide and public). TYPE_UNKNOWN, which currently cannot be observed with a non @hide method, is also removed from the public api. Bug: 71866627 Test: $ runtest frameworks-net Change-Id: I2af70408d46f431b7b32183e6b48ddae9a261a2c
This commit is contained in:
parent
454b42eced
commit
8f21758d4a
1 changed files with 16 additions and 15 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in a new issue