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

Commit 9ae9b395 authored by Brian Stack's avatar Brian Stack
Browse files

Implement UWB Address

Bug: 170323306
Test: Builds

Change-Id: I36a6c9f1dd995e3a1d50f5eea3c4ef14d15a123e
parent 7cfb3150
Loading
Loading
Loading
Loading
+27 −8
Original line number Diff line number Diff line
@@ -19,6 +19,8 @@ package android.uwb;
import android.annotation.NonNull;
import android.annotation.Nullable;

import java.util.Arrays;

/**
 * A class representing a UWB address
 *
@@ -28,6 +30,12 @@ public final class UwbAddress {
    public static final int SHORT_ADDRESS_BYTE_LENGTH = 2;
    public static final int EXTENDED_ADDRESS_BYTE_LENGTH = 8;

    private final byte[] mAddressBytes;

    private UwbAddress(byte[] address) {
        mAddressBytes = address;
    }

    /**
     * Create a {@link UwbAddress} from a byte array.
     *
@@ -37,12 +45,16 @@ public final class UwbAddress {
     *
     * @param address a byte array to convert to a {@link UwbAddress}
     * @return a {@link UwbAddress} created from the input byte array
     * @throw IllegableArumentException when the length is not one of
     * @throws IllegalArgumentException when the length is not one of
     *       {@link #SHORT_ADDRESS_BYTE_LENGTH} or {@link #EXTENDED_ADDRESS_BYTE_LENGTH} bytes
     */
    @NonNull
    public static UwbAddress fromBytes(byte[] address) throws IllegalArgumentException {
        throw new UnsupportedOperationException();
    public static UwbAddress fromBytes(@NonNull byte[] address) throws IllegalArgumentException {
        if (address.length != SHORT_ADDRESS_BYTE_LENGTH
                && address.length != EXTENDED_ADDRESS_BYTE_LENGTH) {
            throw new IllegalArgumentException("Invalid UwbAddress length " + address.length);
        }
        return new UwbAddress(address);
    }

    /**
@@ -52,7 +64,7 @@ public final class UwbAddress {
     */
    @NonNull
    public byte[] toBytes() {
        throw new UnsupportedOperationException();
        return mAddressBytes;
    }

    /**
@@ -61,22 +73,29 @@ public final class UwbAddress {
     * {@link #EXTENDED_ADDRESS_BYTE_LENGTH}.
     */
    public int size() {
        throw new UnsupportedOperationException();
        return mAddressBytes.length;
    }

    @NonNull
    @Override
    public String toString() {
        throw new UnsupportedOperationException();
        StringBuilder builder = new StringBuilder("0x");
        for (byte addressByte : mAddressBytes) {
            builder.append(String.format("%02X", addressByte));
        }
        return builder.toString();
    }

    @Override
    public boolean equals(@Nullable Object obj) {
        throw new UnsupportedOperationException();
        if (obj instanceof UwbAddress) {
            return Arrays.equals(mAddressBytes, ((UwbAddress) obj).toBytes());
        }
        return false;
    }

    @Override
    public int hashCode() {
        throw new UnsupportedOperationException();
        return Arrays.hashCode(mAddressBytes);
    }
}