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

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

Implement AngleOfArrivalMeasurement and AngleMeasurement

Bug: 170323306
Test: Builds
Change-Id: I55122a7b0c34cc69d2b0be3fc230d45f24a18c87
parent 77fffb51
Loading
Loading
Loading
Loading
+87 −3
Original line number Diff line number Diff line
@@ -27,6 +27,16 @@ import android.annotation.FloatRange;
 * @hide
 */
public final class AngleMeasurement {
    private final double mRadians;
    private final double mErrorRadians;
    private final double mConfidenceLevel;

    private AngleMeasurement(double radians, double errorRadians, double confidenceLevel) {
        mRadians = radians;
        mErrorRadians = errorRadians;
        mConfidenceLevel = confidenceLevel;
    }

    /**
     * Angle measurement in radians
    *
@@ -34,7 +44,7 @@ public final class AngleMeasurement {
     */
    @FloatRange(from = -Math.PI, to = +Math.PI)
    public double getRadians() {
        throw new UnsupportedOperationException();
        return mRadians;
    }

    /**
@@ -46,7 +56,7 @@ public final class AngleMeasurement {
     */
    @FloatRange(from = 0.0, to = +Math.PI)
    public double getErrorRadians() {
        throw new UnsupportedOperationException();
        return mErrorRadians;
    }

    /**
@@ -60,6 +70,80 @@ public final class AngleMeasurement {
     */
    @FloatRange(from = 0.0, to = 1.0)
    public double getConfidenceLevel() {
        throw new UnsupportedOperationException();
        return mConfidenceLevel;
    }

    /**
     * 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]
         */
        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]
         */
        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]
         */
        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
         */
        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);
        }
    }
}
+53 −2
Original line number Diff line number Diff line
@@ -25,6 +25,15 @@ import android.annotation.Nullable;
 * @hide
 */
public final class AngleOfArrivalMeasurement {
    private final AngleMeasurement mAzimuthAngleMeasurement;
    private final AngleMeasurement mAltitudeAngleMeasurement;

    private AngleOfArrivalMeasurement(@NonNull AngleMeasurement azimuthAngleMeasurement,
            @Nullable AngleMeasurement altitudeAngleMeasurement) {
        mAzimuthAngleMeasurement = azimuthAngleMeasurement;
        mAltitudeAngleMeasurement = altitudeAngleMeasurement;
    }

    /**
     * Azimuth angle measurement
     * <p>Azimuth {@link AngleMeasurement} of remote device in horizontal coordinate system, this is
@@ -41,7 +50,7 @@ public final class AngleOfArrivalMeasurement {
     */
    @NonNull
    public AngleMeasurement getAzimuth() {
        throw new UnsupportedOperationException();
        return mAzimuthAngleMeasurement;
    }

    /**
@@ -58,6 +67,48 @@ public final class AngleOfArrivalMeasurement {
     */
    @Nullable
    public AngleMeasurement getAltitude() {
        throw new UnsupportedOperationException();
        return mAltitudeAngleMeasurement;
    }

    /**
     * Builder class for {@link AngleOfArrivalMeasurement}.
     */
    public static final class Builder {
        private AngleMeasurement mAzimuthAngleMeasurement = null;
        private AngleMeasurement mAltitudeAngleMeasurement = null;

        /**
         * Set the azimuth angle
         *
         * @param azimuthAngle azimuth angle
         */
        public Builder setAzimuthAngleMeasurement(@NonNull AngleMeasurement azimuthAngle) {
            mAzimuthAngleMeasurement = azimuthAngle;
            return this;
        }

        /**
         * Set the altitude angle
         *
         * @param altitudeAngle altitude angle
         */
        public Builder setAltitudeAngleMeasurement(@NonNull AngleMeasurement altitudeAngle) {
            mAltitudeAngleMeasurement = altitudeAngle;
            return this;
        }

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

            return new AngleOfArrivalMeasurement(mAzimuthAngleMeasurement,
                    mAltitudeAngleMeasurement);
        }
    }
}