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

Commit 7dd9d049 authored by Brian Stack's avatar Brian Stack
Browse files

Address UWB API feedback

Update AngleOfArrivalMeasurement and AngleMeasurement to address
feedback received on API surface.

Bug: 180395817
Test: atest UwbManagerTests CtsUwbTestCases
Change-Id: Iec572ed9df22440a5b068d9e7fbf73026970d5d3
parent 2aebc3e7
Loading
Loading
Loading
Loading
+2 −10
Original line number Diff line number Diff line
@@ -13824,6 +13824,7 @@ package android.util {
package android.uwb {
  public final class AngleMeasurement implements android.os.Parcelable {
    ctor public AngleMeasurement(double, double, double);
    method public int describeContents();
    method @FloatRange(from=0.0, to=1.0) public double getConfidenceLevel();
    method @FloatRange(from=0.0, to=3.141592653589793) public double getErrorRadians();
@@ -13832,14 +13833,6 @@ package android.uwb {
    field @NonNull public static final android.os.Parcelable.Creator<android.uwb.AngleMeasurement> CREATOR;
  }
  public static final class AngleMeasurement.Builder {
    ctor public AngleMeasurement.Builder();
    method @NonNull public android.uwb.AngleMeasurement build();
    method @NonNull public android.uwb.AngleMeasurement.Builder setConfidenceLevel(double);
    method @NonNull public android.uwb.AngleMeasurement.Builder setErrorRadians(double);
    method @NonNull public android.uwb.AngleMeasurement.Builder setRadians(double);
  }
  public final class AngleOfArrivalMeasurement implements android.os.Parcelable {
    method public int describeContents();
    method @Nullable public android.uwb.AngleMeasurement getAltitude();
@@ -13849,10 +13842,9 @@ package android.uwb {
  }
  public static final class AngleOfArrivalMeasurement.Builder {
    ctor public AngleOfArrivalMeasurement.Builder();
    ctor public AngleOfArrivalMeasurement.Builder(@NonNull android.uwb.AngleMeasurement);
    method @NonNull public android.uwb.AngleOfArrivalMeasurement build();
    method @NonNull public android.uwb.AngleOfArrivalMeasurement.Builder setAltitude(@NonNull android.uwb.AngleMeasurement);
    method @NonNull public android.uwb.AngleOfArrivalMeasurement.Builder setAzimuth(@NonNull android.uwb.AngleMeasurement);
  }
  public final class DistanceMeasurement implements android.os.Parcelable {
+23 −84
Original line number Diff line number Diff line
@@ -38,9 +38,30 @@ public final class AngleMeasurement implements Parcelable {
    private final double mErrorRadians;
    private final double mConfidenceLevel;

    private AngleMeasurement(double radians, double errorRadians, double confidenceLevel) {
    /**
     * Constructs a new {@link AngleMeasurement} object
     *
     * @param radians the angle in radians
     * @param errorRadians the error of the angle measurement in radians
     * @param confidenceLevel confidence level of the angle measurement
     *
     * @throws IllegalArgumentException if the radians, errorRadians, or confidenceLevel is out of
     *                                  allowed range
     */
    public AngleMeasurement(double radians, double errorRadians, double confidenceLevel) {
        if (radians < -Math.PI || radians > Math.PI) {
            throw new IllegalArgumentException("Invalid radians: " + radians);
        }
        mRadians = radians;

        if (errorRadians < 0.0 || errorRadians > Math.PI) {
            throw new IllegalArgumentException("Invalid error radians: " + errorRadians);
        }
        mErrorRadians = errorRadians;

        if (confidenceLevel < 0.0 || confidenceLevel > 1.0) {
            throw new IllegalArgumentException("Invalid confidence level: " + confidenceLevel);
        }
        mConfidenceLevel = confidenceLevel;
    }

@@ -122,11 +143,7 @@ public final class AngleMeasurement implements Parcelable {
            new Creator<AngleMeasurement>() {
                @Override
                public AngleMeasurement createFromParcel(Parcel in) {
                    Builder builder = new Builder();
                    builder.setRadians(in.readDouble());
                    builder.setErrorRadians(in.readDouble());
                    builder.setConfidenceLevel(in.readDouble());
                    return builder.build();
                    return new AngleMeasurement(in.readDouble(), in.readDouble(), in.readDouble());
                }

                @Override
@@ -134,82 +151,4 @@ public final class AngleMeasurement implements Parcelable {
                    return new AngleMeasurement[size];
                }
    };

    /**
     * Builder class for {@link AngleMeasurement}.
     */
    public static final class Builder {
        private double mRadians = Double.NaN;
        private double mErrorRadians = Double.NaN;
        private double mConfidenceLevel = Double.NaN;

        /**
         * Set the angle in radians
         *
         * @param radians angle in radians
         * @throws IllegalArgumentException if angle exceeds allowed limits of [-Math.PI, +Math.PI]
         */
        @NonNull
        public Builder setRadians(double radians) {
            if (radians < -Math.PI || radians > Math.PI) {
                throw new IllegalArgumentException("Invalid radians: " + radians);
            }
            mRadians = radians;
            return this;
        }

        /**
         * Set the angle error in radians
         *
         * @param errorRadians error of the angle in radians
         * @throws IllegalArgumentException if the error exceeds the allowed limits of [0, +Math.PI]
         */
        @NonNull
        public Builder setErrorRadians(double errorRadians) {
            if (errorRadians < 0.0 || errorRadians > Math.PI) {
                throw new IllegalArgumentException(
                        "Invalid error radians: " + errorRadians);
            }
            mErrorRadians = errorRadians;
            return this;
        }

        /**
         * Set the angle confidence level
         *
         * @param confidenceLevel level of confidence of the angle measurement
         * @throws IllegalArgumentException if the error exceeds the allowed limits of [0.0, 1.0]
         */
        @NonNull
        public Builder setConfidenceLevel(double confidenceLevel) {
            if (confidenceLevel < 0.0 || confidenceLevel > 1.0) {
                throw new IllegalArgumentException(
                        "Invalid confidence level: " + confidenceLevel);
            }
            mConfidenceLevel = confidenceLevel;
            return this;
        }

        /**
         * Build the {@link AngleMeasurement} object
         *
         * @throws IllegalStateException if angle, error, or confidence values are missing
         */
        @NonNull
        public AngleMeasurement build() {
            if (Double.isNaN(mRadians)) {
                throw new IllegalStateException("Angle is not set");
            }

            if (Double.isNaN(mErrorRadians)) {
                throw new IllegalStateException("Angle error is not set");
            }

            if (Double.isNaN(mConfidenceLevel)) {
                throw new IllegalStateException("Angle confidence level is not set");
            }

            return new AngleMeasurement(mRadians, mErrorRadians, mConfidenceLevel);
        }
    }
}
+6 −15
Original line number Diff line number Diff line
@@ -116,9 +116,8 @@ public final class AngleOfArrivalMeasurement implements Parcelable {
            new Creator<AngleOfArrivalMeasurement>() {
                @Override
                public AngleOfArrivalMeasurement createFromParcel(Parcel in) {
                    Builder builder = new Builder();

                    builder.setAzimuth(in.readParcelable(AngleMeasurement.class.getClassLoader()));
                    Builder builder =
                            new Builder(in.readParcelable(AngleMeasurement.class.getClassLoader()));

                    builder.setAltitude(in.readParcelable(AngleMeasurement.class.getClassLoader()));

@@ -135,18 +134,16 @@ public final class AngleOfArrivalMeasurement implements Parcelable {
     * Builder class for {@link AngleOfArrivalMeasurement}.
     */
    public static final class Builder {
        private AngleMeasurement mAzimuthAngleMeasurement = null;
        private final AngleMeasurement mAzimuthAngleMeasurement;
        private AngleMeasurement mAltitudeAngleMeasurement = null;

        /**
         * Set the azimuth angle
         * Constructs an {@link AngleOfArrivalMeasurement} object
         *
         * @param azimuthAngle azimuth angle
         * @param azimuthAngle the azimuth angle of the measurement
         */
        @NonNull
        public Builder setAzimuth(@NonNull AngleMeasurement azimuthAngle) {
        public Builder(@NonNull AngleMeasurement azimuthAngle) {
            mAzimuthAngleMeasurement = azimuthAngle;
            return this;
        }

        /**
@@ -162,15 +159,9 @@ public final class AngleOfArrivalMeasurement implements Parcelable {

        /**
         * Build the {@link AngleOfArrivalMeasurement} object
         *
         * @throws IllegalStateException if the required azimuth angle is not provided
         */
        @NonNull
        public AngleOfArrivalMeasurement build() {
            if (mAzimuthAngleMeasurement == null) {
                throw new IllegalStateException("Azimuth angle measurement is not set");
            }

            return new AngleOfArrivalMeasurement(mAzimuthAngleMeasurement,
                    mAltitudeAngleMeasurement);
        }
+5 −24
Original line number Diff line number Diff line
@@ -16,34 +16,23 @@

package android.uwb;

import android.content.Context;
import android.content.pm.PackageManager;
import android.os.SystemClock;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Executor;

public class UwbTestUtils {
    private UwbTestUtils() {}

    public static boolean isUwbSupported(Context context) {
        PackageManager packageManager = context.getPackageManager();
        return packageManager.hasSystemFeature(PackageManager.FEATURE_UWB);
    }

    public static AngleMeasurement getAngleMeasurement() {
        return new AngleMeasurement.Builder()
                .setRadians(getDoubleInRange(-Math.PI, Math.PI))
                .setErrorRadians(getDoubleInRange(0, Math.PI))
                .setConfidenceLevel(getDoubleInRange(0, 1))
                .build();
        return new AngleMeasurement(
                getDoubleInRange(-Math.PI, Math.PI),
                getDoubleInRange(0, Math.PI),
                getDoubleInRange(0, 1));
    }

    public static AngleOfArrivalMeasurement getAngleOfArrivalMeasurement() {
        return new AngleOfArrivalMeasurement.Builder()
        return new AngleOfArrivalMeasurement.Builder(getAngleMeasurement())
                .setAltitude(getAngleMeasurement())
                .setAzimuth(getAngleMeasurement())
                .build();
    }

@@ -69,14 +58,6 @@ public class UwbTestUtils {
                .build();
    }

    public static List<RangingMeasurement> getRangingMeasurements(int num) {
        List<RangingMeasurement> result = new ArrayList<>();
        for (int i = 0; i < num; i++) {
            result.add(getRangingMeasurement());
        }
        return result;
    }

    public static RangingReport getRangingReports(int numMeasurements) {
        RangingReport.Builder builder = new RangingReport.Builder();
        for (int i = 0; i < numMeasurements; i++) {