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

Commit 2817688b authored by Chienyuan Huang's avatar Chienyuan Huang
Browse files

Extend DistanceMeasurementResult

Bug: 319563845
Bug: 317683528
Test: atest DistanceMeasurementResultTest
Change-Id: Idcfb5f11a8de7ba45740e478bd6b64b5b6b2ea12
parent 2b280e64
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -1278,12 +1278,24 @@ package android.bluetooth.le {
    method public int describeContents();
    method @FloatRange(from=-90.0, to=90.0) public double getAltitudeAngle();
    method @FloatRange(from=0.0, to=360.0) public double getAzimuthAngle();
    method @FlaggedApi("com.android.bluetooth.flags.channel_sounding") @FloatRange(from=0.0, to=1.0) public double getConfidenceLevel();
    method @FlaggedApi("com.android.bluetooth.flags.channel_sounding") public double getDelaySpreadMeters();
    method @FlaggedApi("com.android.bluetooth.flags.channel_sounding") public int getDetectedAttackLevel();
    method public double getErrorAltitudeAngle();
    method public double getErrorAzimuthAngle();
    method @FloatRange(from=0.0) public double getErrorMeters();
    method public double getResultMeters();
    method @FlaggedApi("com.android.bluetooth.flags.channel_sounding") public double getVelocityMetersPerSecond();
    method public void writeToParcel(android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.bluetooth.le.DistanceMeasurementResult> CREATOR;
    field @FlaggedApi("com.android.bluetooth.flags.channel_sounding") public static final int NADM_ATTACK_IS_EXTREMELY_LIKELY = 6; // 0x6
    field @FlaggedApi("com.android.bluetooth.flags.channel_sounding") public static final int NADM_ATTACK_IS_EXTREMELY_UNLIKELY = 0; // 0x0
    field @FlaggedApi("com.android.bluetooth.flags.channel_sounding") public static final int NADM_ATTACK_IS_LIKELY = 4; // 0x4
    field @FlaggedApi("com.android.bluetooth.flags.channel_sounding") public static final int NADM_ATTACK_IS_POSSIBLE = 3; // 0x3
    field @FlaggedApi("com.android.bluetooth.flags.channel_sounding") public static final int NADM_ATTACK_IS_UNLIKELY = 2; // 0x2
    field @FlaggedApi("com.android.bluetooth.flags.channel_sounding") public static final int NADM_ATTACK_IS_VERY_LIKELY = 5; // 0x5
    field @FlaggedApi("com.android.bluetooth.flags.channel_sounding") public static final int NADM_ATTACK_IS_VERY_UNLIKELY = 1; // 0x1
    field @FlaggedApi("com.android.bluetooth.flags.channel_sounding") public static final int NADM_UNKNOWN = 255; // 0xff
  }

  public static final class DistanceMeasurementResult.Builder {
@@ -1291,8 +1303,12 @@ package android.bluetooth.le {
    method @NonNull public android.bluetooth.le.DistanceMeasurementResult build();
    method @NonNull public android.bluetooth.le.DistanceMeasurementResult.Builder setAltitudeAngle(@FloatRange(from=-90.0, to=90.0) double);
    method @NonNull public android.bluetooth.le.DistanceMeasurementResult.Builder setAzimuthAngle(@FloatRange(from=0.0, to=360.0) double);
    method @FlaggedApi("com.android.bluetooth.flags.channel_sounding") @NonNull public android.bluetooth.le.DistanceMeasurementResult.Builder setConfidenceLevel(@FloatRange(from=0.0, to=100.0) double);
    method @FlaggedApi("com.android.bluetooth.flags.channel_sounding") @NonNull public android.bluetooth.le.DistanceMeasurementResult.Builder setDelaySpreadMeters(double);
    method @FlaggedApi("com.android.bluetooth.flags.channel_sounding") @NonNull public android.bluetooth.le.DistanceMeasurementResult.Builder setDetectedAttackLevel(int);
    method @NonNull public android.bluetooth.le.DistanceMeasurementResult.Builder setErrorAltitudeAngle(@FloatRange(from=0.0, to=180.0) double);
    method @NonNull public android.bluetooth.le.DistanceMeasurementResult.Builder setErrorAzimuthAngle(@FloatRange(from=0.0, to=360.0) double);
    method @FlaggedApi("com.android.bluetooth.flags.channel_sounding") @NonNull public android.bluetooth.le.DistanceMeasurementResult.Builder setVelocityMetersPerSecond(double);
  }

  public final class DistanceMeasurementSession {
+270 −2
Original line number Diff line number Diff line
@@ -16,12 +16,17 @@

package android.bluetooth.le;

import android.annotation.FlaggedApi;
import android.annotation.FloatRange;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.SystemApi;
import android.os.Parcel;
import android.os.Parcelable;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

/**
 * Result of distance measurement.
 *
@@ -30,12 +35,109 @@ import android.os.Parcelable;
@SystemApi
public final class DistanceMeasurementResult implements Parcelable {

    /**
     * Normalized Attack Detector Metric. See Channel Sounding CR_PR, 3.13.24 for details.
     *
     * <p>Specification: https://www.bluetooth.com/specifications/specs/channel-sounding-cr-pr/
     *
     * @hide
     */
    @Retention(RetentionPolicy.SOURCE)
    @IntDef(
            value = {
                NADM_ATTACK_IS_EXTREMELY_UNLIKELY,
                NADM_ATTACK_IS_VERY_UNLIKELY,
                NADM_ATTACK_IS_UNLIKELY,
                NADM_ATTACK_IS_POSSIBLE,
                NADM_ATTACK_IS_LIKELY,
                NADM_ATTACK_IS_VERY_LIKELY,
                NADM_ATTACK_IS_EXTREMELY_LIKELY,
                NADM_UNKNOWN
            })
    @interface Nadm {}

    /**
     * Attack is extremely unlikely.
     *
     * @hide
     */
    @FlaggedApi("com.android.bluetooth.flags.channel_sounding")
    @SystemApi
    public static final int NADM_ATTACK_IS_EXTREMELY_UNLIKELY = 0;

    /**
     * Attack is very unlikely.
     *
     * @hide
     */
    @FlaggedApi("com.android.bluetooth.flags.channel_sounding")
    @SystemApi
    public static final int NADM_ATTACK_IS_VERY_UNLIKELY = 1;

    /**
     * Attack is unlikely.
     *
     * @hide
     */
    @FlaggedApi("com.android.bluetooth.flags.channel_sounding")
    @SystemApi
    public static final int NADM_ATTACK_IS_UNLIKELY = 2;

    /**
     * Attack is possible.
     *
     * @hide
     */
    @FlaggedApi("com.android.bluetooth.flags.channel_sounding")
    @SystemApi
    public static final int NADM_ATTACK_IS_POSSIBLE = 3;

    /**
     * Attack is likely.
     *
     * @hide
     */
    @FlaggedApi("com.android.bluetooth.flags.channel_sounding")
    @SystemApi
    public static final int NADM_ATTACK_IS_LIKELY = 4;

    /**
     * Attack is very likely.
     *
     * @hide
     */
    @FlaggedApi("com.android.bluetooth.flags.channel_sounding")
    @SystemApi
    public static final int NADM_ATTACK_IS_VERY_LIKELY = 5;

    /**
     * Attack is extremely likely.
     *
     * @hide
     */
    @FlaggedApi("com.android.bluetooth.flags.channel_sounding")
    @SystemApi
    public static final int NADM_ATTACK_IS_EXTREMELY_LIKELY = 6;

    /**
     * Unknown NADM, if a device is unable to determine a NADM value, then it shall report this.
     *
     * @hide
     */
    @FlaggedApi("com.android.bluetooth.flags.channel_sounding")
    @SystemApi
    public static final int NADM_UNKNOWN = 0xFF;

    private final double mMeters;
    private final double mErrorMeters;
    private final double mAzimuthAngle;
    private final double mErrorAzimuthAngle;
    private final double mAltitudeAngle;
    private final double mErrorAltitudeAngle;
    private final double mDelaySpreadMeters;
    private final double mConfidenceLevel;
    private final int mDetectedAttackLevel;
    private final double mVelocityMetersPerSecond;

    private DistanceMeasurementResult(
            double meters,
@@ -43,13 +145,21 @@ public final class DistanceMeasurementResult implements Parcelable {
            double azimuthAngle,
            double errorAzimuthAngle,
            double altitudeAngle,
            double errorAltitudeAngle) {
            double errorAltitudeAngle,
            double delaySpreadMeters,
            double confidenceLevel,
            @Nadm int detectedAttackLevel,
            double velocityMetersPerSecond) {
        mMeters = meters;
        mErrorMeters = errorMeters;
        mAzimuthAngle = azimuthAngle;
        mErrorAzimuthAngle = errorAzimuthAngle;
        mAltitudeAngle = altitudeAngle;
        mErrorAltitudeAngle = errorAltitudeAngle;
        mDelaySpreadMeters = delaySpreadMeters;
        mConfidenceLevel = confidenceLevel;
        mDetectedAttackLevel = detectedAttackLevel;
        mVelocityMetersPerSecond = velocityMetersPerSecond;
    }

    /**
@@ -146,6 +256,60 @@ public final class DistanceMeasurementResult implements Parcelable {
        return mErrorAltitudeAngle;
    }

    /**
     * Get estimated delay spread in meters of the measured channel. This is a measure of multipath
     * richness of the channel.
     *
     * @return delay spread in meters in degrees or Double.NaN if not available
     * @hide
     */
    @FlaggedApi("com.android.bluetooth.flags.channel_sounding")
    @SystemApi
    public double getDelaySpreadMeters() {
        return mDelaySpreadMeters;
    }

    /**
     * Get a normalized value from 0.0 (low confidence) to 1.0 (high confidence) representing the
     * confidence of estimated distance.
     *
     * @return confidence of estimated distance or Double.NaN if not available
     * @hide
     */
    @FlaggedApi("com.android.bluetooth.flags.channel_sounding")
    @SystemApi
    @FloatRange(from = 0.0, to = 1.0)
    public double getConfidenceLevel() {
        return mConfidenceLevel;
    }

    /**
     * Get a value that represents the chance of being attacked for the measurement.
     *
     * @return Nadm that represents the chance of being attacked for the measurement.
     * @hide
     */
    @FlaggedApi("com.android.bluetooth.flags.channel_sounding")
    @SystemApi
    @Nadm
    public int getDetectedAttackLevel() {
        return mDetectedAttackLevel;
    }

    /**
     * Get estimated velocity, in the direction of line between two devices, of the moving object in
     * meters/sec.
     *
     * @return Estimated velocity, in the direction of line between two devices, of the moving
     *     object in meters/sec.
     * @hide
     */
    @FlaggedApi("com.android.bluetooth.flags.channel_sounding")
    @SystemApi
    public double getVelocityMetersPerSecond() {
        return mVelocityMetersPerSecond;
    }

    /**
     * {@inheritDoc}
     *
@@ -169,6 +333,10 @@ public final class DistanceMeasurementResult implements Parcelable {
        out.writeDouble(mErrorAzimuthAngle);
        out.writeDouble(mAltitudeAngle);
        out.writeDouble(mErrorAltitudeAngle);
        out.writeDouble(mDelaySpreadMeters);
        out.writeDouble(mConfidenceLevel);
        out.writeInt(mDetectedAttackLevel);
        out.writeDouble(mVelocityMetersPerSecond);
    }

    /**
@@ -189,6 +357,14 @@ public final class DistanceMeasurementResult implements Parcelable {
                + mAltitudeAngle
                + ", errorAltitudeAngle: "
                + mErrorAltitudeAngle
                + ", delaySpreadMeters: "
                + mDelaySpreadMeters
                + ", confidenceLevel: "
                + mConfidenceLevel
                + ", detectedAttackLevel: "
                + mDetectedAttackLevel
                + ", velocityMetersPerSecond: "
                + mVelocityMetersPerSecond
                + "]";
    }

@@ -224,6 +400,10 @@ public final class DistanceMeasurementResult implements Parcelable {
        private double mErrorAzimuthAngle = Double.NaN;
        private double mAltitudeAngle = Double.NaN;
        private double mErrorAltitudeAngle = Double.NaN;
        private double mDelaySpreadMeters = Double.NaN;
        private double mConfidenceLevel = Double.NaN;
        private int mDetectedAttackLevel = NADM_UNKNOWN;
        private double mVelocityMetersPerSecond = Double.NaN;

        /**
         * Constructor of the Builder.
@@ -317,6 +497,90 @@ public final class DistanceMeasurementResult implements Parcelable {
            return this;
        }

        /**
         * Set the estimated delay spread in meters.
         *
         * @param delaySpreadMeters estimated delay spread in meters
         * @throws IllegalArgumentException if value is invalid
         * @hide
         */
        @FlaggedApi("com.android.bluetooth.flags.channel_sounding")
        @SystemApi
        @NonNull
        public Builder setDelaySpreadMeters(double delaySpreadMeters) {
            if (delaySpreadMeters < 0.0) {
                throw new IllegalArgumentException("delaySpreadMeters must be > 0.0");
            }
            mDelaySpreadMeters = delaySpreadMeters;
            return this;
        }

        /**
         * Set the confidence of estimated distance.
         *
         * @param confidenceLevel a normalized value from 0.0 (low confidence) to 100.0 (high
         *     confidence) representing the confidence of estimated distance
         * @throws IllegalArgumentException if value is invalid
         * @hide
         */
        @FlaggedApi("com.android.bluetooth.flags.channel_sounding")
        @SystemApi
        @NonNull
        public Builder setConfidenceLevel(
                @FloatRange(from = 0.0, to = 100.0) double confidenceLevel) {
            if (confidenceLevel > 100.0 || confidenceLevel < 0.0) {
                throw new IllegalArgumentException(
                        "error confidenceLevel must be in the range from 0.0 to 100.0 : "
                                + confidenceLevel);
            }
            mConfidenceLevel = confidenceLevel;
            return this;
        }

        /**
         * Set the value that represents the chance of being attacked for the measurement.
         *
         * @param detectedAttackLevel a value that represents the chance of being attacked for the
         *     measurement.
         * @throws IllegalArgumentException if value is invalid
         * @hide
         */
        @FlaggedApi("com.android.bluetooth.flags.channel_sounding")
        @SystemApi
        @NonNull
        public Builder setDetectedAttackLevel(@Nadm int detectedAttackLevel) {
            switch (detectedAttackLevel) {
                case NADM_ATTACK_IS_EXTREMELY_UNLIKELY:
                case NADM_ATTACK_IS_VERY_UNLIKELY:
                case NADM_ATTACK_IS_UNLIKELY:
                case NADM_ATTACK_IS_POSSIBLE:
                case NADM_ATTACK_IS_LIKELY:
                case NADM_ATTACK_IS_VERY_LIKELY:
                case NADM_ATTACK_IS_EXTREMELY_LIKELY:
                case NADM_UNKNOWN:
                    mDetectedAttackLevel = detectedAttackLevel;
                    break;
                default:
                    throw new IllegalArgumentException("Invalid value " + detectedAttackLevel);
            }
            return this;
        }

        /**
         * Set estimated velocity, in the direction of line between two devices, of the moving
         * object in meters/sec.
         *
         * @param velocityMetersPerSecond estimated velocity in meters/sec.
         * @hide
         */
        @FlaggedApi("com.android.bluetooth.flags.channel_sounding")
        @SystemApi
        @NonNull
        public Builder setVelocityMetersPerSecond(double velocityMetersPerSecond) {
            mVelocityMetersPerSecond = velocityMetersPerSecond;
            return this;
        }

        /**
         * Builds the {@link DistanceMeasurementResult} object.
         *
@@ -332,7 +596,11 @@ public final class DistanceMeasurementResult implements Parcelable {
                    mAzimuthAngle,
                    mErrorAzimuthAngle,
                    mAltitudeAngle,
                    mErrorAltitudeAngle);
                    mErrorAltitudeAngle,
                    mDelaySpreadMeters,
                    mConfidenceLevel,
                    mDetectedAttackLevel,
                    mVelocityMetersPerSecond);
        }
    }
}