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

Commit 15235cd5 authored by Etan Cohen's avatar Etan Cohen Committed by Android (Google) Code Review
Browse files

Merge "[RTT] LCI/LCR to System API - unparsed"

parents 2ed475c0 870301c9
Loading
Loading
Loading
Loading
+0 −25
Original line number Diff line number Diff line
@@ -28509,29 +28509,6 @@ package android.net.wifi.p2p.nsd {
package android.net.wifi.rtt {
  public final class LocationCivic implements android.os.Parcelable {
    method public int describeContents();
    method public byte[] getData();
    method public void writeToParcel(android.os.Parcel, int);
    field public static final android.os.Parcelable.Creator<android.net.wifi.rtt.LocationCivic> CREATOR;
  }
  public final class LocationConfigurationInformation implements android.os.Parcelable {
    method public int describeContents();
    method public double getAltitude();
    method public int getAltitudeType();
    method public double getAltitudeUncertainty();
    method public double getLatitude();
    method public double getLatitudeUncertainty();
    method public double getLongitude();
    method public double getLongitudeUncertainty();
    method public void writeToParcel(android.os.Parcel, int);
    field public static final int ALTITUDE_IN_FLOORS = 2; // 0x2
    field public static final int ALTITUDE_IN_METERS = 1; // 0x1
    field public static final int ALTITUDE_UNKNOWN = 0; // 0x0
    field public static final android.os.Parcelable.Creator<android.net.wifi.rtt.LocationConfigurationInformation> CREATOR;
  }
  public final class RangingRequest implements android.os.Parcelable {
    method public int describeContents();
    method public static int getMaxPeers();
@@ -28555,8 +28532,6 @@ package android.net.wifi.rtt {
    method public android.net.MacAddress getMacAddress();
    method public android.net.wifi.aware.PeerHandle getPeerHandle();
    method public long getRangingTimestampUs();
    method public android.net.wifi.rtt.LocationCivic getReportedLocationCivic();
    method public android.net.wifi.rtt.LocationConfigurationInformation getReportedLocationConfigurationInformation();
    method public int getRssi();
    method public int getStatus();
    method public void writeToParcel(android.os.Parcel, int);
+5 −0
Original line number Diff line number Diff line
@@ -3524,6 +3524,11 @@ package android.net.wifi.rtt {
    method public android.net.wifi.rtt.RangingRequest.Builder addResponder(android.net.wifi.rtt.ResponderConfig);
  }

  public final class RangingResult implements android.os.Parcelable {
    method public byte[] getLci();
    method public byte[] getLcr();
  }

  public final class ResponderConfig implements android.os.Parcelable {
    ctor public ResponderConfig(android.net.MacAddress, int, boolean, int, int, int, int, int);
    ctor public ResponderConfig(android.net.wifi.aware.PeerHandle, int, boolean, int, int, int, int, int);
+0 −118
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.net.wifi.rtt;

import android.annotation.Nullable;
import android.os.Parcel;
import android.os.Parcelable;

import java.util.Arrays;
import java.util.Objects;

/**
 * Location Civic Report (LCR).
 * <p>
 * The information matches the IEEE 802.11-2016 LCR report.
 * <p>
 * Note: depending on the mechanism by which this information is returned (i.e. the API which
 * returns an instance of this class) it is possibly Self Reported (by the peer). In such a case
 * the information is NOT validated - use with caution. Consider validating it with other sources
 * of information before using it.
 */
public final class LocationCivic implements Parcelable {
    private final byte[] mData;

    /**
     * Parse the raw LCR information element (byte array) and extract the LocationCivic structure.
     *
     * Note: any parsing errors or invalid/unexpected errors will result in a null being returned.
     *
     * @hide
     */
    @Nullable
    public static LocationCivic parseInformationElement(byte id, byte[] data) {
        // TODO
        return null;
    }

    /** @hide */
    public LocationCivic(byte[] data) {
        mData = data;
    }

    /**
     * Return the Location Civic data reported by the peer.
     *
     * @return An arbitrary location information.
     */
    public byte[] getData() {
        return mData;
    }

    /** @hide */
    @Override
    public int describeContents() {
        return 0;
    }

    /** @hide */
    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeByteArray(mData);
    }

    public static final Parcelable.Creator<LocationCivic> CREATOR =
            new Parcelable.Creator<LocationCivic>() {
                @Override
                public LocationCivic[] newArray(int size) {
                    return new LocationCivic[size];
                }

                @Override
                public LocationCivic createFromParcel(Parcel in) {
                    byte[] data = in.createByteArray();

                    return new LocationCivic(data);
                }
            };

    /** @hide */
    @Override
    public String toString() {
        return new StringBuilder("LCR: data=").append(Arrays.toString(mData)).toString();
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }

        if (!(o instanceof LocationCivic)) {
            return false;
        }

        LocationCivic lhs = (LocationCivic) o;

        return Arrays.equals(mData, lhs.mData);
    }

    @Override
    public int hashCode() {
        return Objects.hash(mData);
    }
}
+0 −272
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.net.wifi.rtt;

import android.annotation.IntDef;
import android.annotation.Nullable;
import android.os.Parcel;
import android.os.Parcelable;

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

/**
 * The Device Location Configuration Information (LCI) specifies the location information of a peer
 * device (e.g. an Access Point).
 * <p>
 * The information matches the IEEE 802.11-2016 LCI report (Location configuration information
 * report).
 * <p>
 * Note: depending on the mechanism by which this information is returned (i.e. the API which
 * returns an instance of this class) it is possibly Self Reported (by the peer). In such a case
 * the information is NOT validated - use with caution. Consider validating it with other sources
 * of information before using it.
 */
public final class LocationConfigurationInformation implements Parcelable {
    /** @hide */
    @IntDef({
            ALTITUDE_UNKNOWN, ALTITUDE_IN_METERS, ALTITUDE_IN_FLOORS })
    @Retention(RetentionPolicy.SOURCE)
    public @interface AltitudeTypes {
    }

    /**
     * Define an Altitude Type returned by {@link #getAltitudeType()}. Indicates that the location
     * does not specify an altitude or altitude uncertainty. The corresponding methods,
     * {@link #getAltitude()} and {@link #getAltitudeUncertainty()} are not valid and will throw
     * an exception.
     */
    public static final int ALTITUDE_UNKNOWN = 0;

    /**
     * Define an Altitude Type returned by {@link #getAltitudeType()}. Indicates that the location
     * specifies the altitude and altitude uncertainty in meters. The corresponding methods,
     * {@link #getAltitude()} and {@link #getAltitudeUncertainty()} return a valid value in meters.
     */
    public static final int ALTITUDE_IN_METERS = 1;

    /**
     * Define an Altitude Type returned by {@link #getAltitudeType()}. Indicates that the
     * location specifies the altitude in floors, and does not specify an altitude uncertainty.
     * The {@link #getAltitude()} method returns valid value in floors, and the
     * {@link #getAltitudeUncertainty()} method is not valid and will throw an exception.
     */
    public static final int ALTITUDE_IN_FLOORS = 2;

    private final double mLatitude;
    private final double mLatitudeUncertainty;
    private final double mLongitude;
    private final double mLongitudeUncertainty;
    private final int mAltitudeType;
    private final double mAltitude;
    private final double mAltitudeUncertainty;

    /**
     * Parse the raw LCI information element (byte array) and extract the
     * LocationConfigurationInformation structure.
     *
     * Note: any parsing errors or invalid/unexpected errors will result in a null being returned.
     *
     * @hide
     */
    @Nullable
    public static LocationConfigurationInformation parseInformationElement(byte id, byte[] data) {
        // TODO
        return null;
    }

    /** @hide */
    public LocationConfigurationInformation(double latitude, double latitudeUncertainty,
            double longitude, double longitudeUncertainty, @AltitudeTypes int altitudeType,
            double altitude, double altitudeUncertainty) {
        mLatitude = latitude;
        mLatitudeUncertainty = latitudeUncertainty;
        mLongitude = longitude;
        mLongitudeUncertainty = longitudeUncertainty;
        mAltitudeType = altitudeType;
        mAltitude = altitude;
        mAltitudeUncertainty = altitudeUncertainty;
    }

    /**
     * Get latitude in degrees. Values are per WGS 84 reference system. Valid values are between
     * -90 and 90.
     *
     * @return Latitude in degrees.
     */
    public double getLatitude() {
        return mLatitude;
    }

    /**
     * Get the uncertainty of the latitude {@link #getLatitude()} in degrees. A value of 0 indicates
     * an unknown uncertainty.
     *
     * @return Uncertainty of the latitude in degrees.
     */
    public double getLatitudeUncertainty() {
        return mLatitudeUncertainty;
    }

    /**
     * Get longitude in degrees. Values are per WGS 84 reference system. Valid values are between
     * -180 and 180.
     *
     * @return Longitude in degrees.
     */
    public double getLongitude() {
        return mLongitude;
    }

    /**
     * Get the uncertainty of the longitude {@link #getLongitude()} ()} in degrees.  A value of 0
     * indicates an unknown uncertainty.
     *
     * @return Uncertainty of the longitude in degrees.
     */
    public double getLongitudeUncertainty() {
        return mLongitudeUncertainty;
    }

    /**
     * Specifies the type of the altitude measurement returned by {@link #getAltitude()} and
     * {@link #getAltitudeUncertainty()}. The possible values are:
     * <li>{@link #ALTITUDE_UNKNOWN}: The altitude and altitude uncertainty are not provided.
     * <li>{@link #ALTITUDE_IN_METERS}: The altitude and altitude uncertainty are provided in
     * meters. Values are per WGS 84 reference system.
     * <li>{@link #ALTITUDE_IN_FLOORS}: The altitude is provided in floors, the altitude uncertainty
     * is not provided.
     *
     * @return The type of the altitude and altitude uncertainty.
     */
    public @AltitudeTypes int getAltitudeType() {
        return mAltitudeType;
    }

    /**
     * The altitude is interpreted according to the {@link #getAltitudeType()}. The possible values
     * are:
     * <li>{@link #ALTITUDE_UNKNOWN}: The altitude is not provided - this method will throw an
     * exception.
     * <li>{@link #ALTITUDE_IN_METERS}: The altitude is provided in meters. Values are per WGS 84
     * reference system.
     * <li>{@link #ALTITUDE_IN_FLOORS}: The altitude is provided in floors.
     *
     * @return Altitude value whose meaning is specified by {@link #getAltitudeType()}.
     */
    public double getAltitude() {
        if (mAltitudeType == ALTITUDE_UNKNOWN) {
            throw new IllegalStateException(
                    "getAltitude(): invoked on an invalid type: getAltitudeType()==UNKNOWN");
        }
        return mAltitude;
    }

    /**
     * Only valid if the the {@link #getAltitudeType()} is equal to {@link #ALTITUDE_IN_METERS} -
     * otherwise this method will throw an exception.
     * <p>
     * Get the uncertainty of the altitude {@link #getAltitude()} in meters.  A value of 0
     * indicates an unknown uncertainty.
     *
     * @return Uncertainty of the altitude in meters.
     */
    public double getAltitudeUncertainty() {
        if (mAltitudeType != ALTITUDE_IN_METERS) {
            throw new IllegalStateException(
                    "getAltitude(): invoked on an invalid type: getAltitudeType()!=IN_METERS");
        }
        return mAltitudeUncertainty;
    }

    /** @hide */
    @Override
    public int describeContents() {
        return 0;
    }

    /** @hide */
    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeDouble(mLatitude);
        dest.writeDouble(mLatitudeUncertainty);
        dest.writeDouble(mLongitude);
        dest.writeDouble(mLongitudeUncertainty);
        dest.writeInt(mAltitudeType);
        dest.writeDouble(mAltitude);
        dest.writeDouble(mAltitudeUncertainty);
    }

    public static final Creator<LocationConfigurationInformation> CREATOR =
            new Creator<LocationConfigurationInformation>() {
        @Override
        public LocationConfigurationInformation[] newArray(int size) {
            return new LocationConfigurationInformation[size];
        }

        @Override
        public LocationConfigurationInformation createFromParcel(Parcel in) {
            double latitude = in.readDouble();
            double latitudeUnc = in.readDouble();
            double longitude = in.readDouble();
            double longitudeUnc = in.readDouble();
            int altitudeType = in.readInt();
            double altitude = in.readDouble();
            double altitudeUnc = in.readDouble();

            return new LocationConfigurationInformation(latitude, latitudeUnc, longitude,
                    longitudeUnc, altitudeType, altitude, altitudeUnc);
        }
    };

    /** @hide */
    @Override
    public String toString() {
        return new StringBuilder("LCI: latitude=").append(mLatitude).append(
                ", latitudeUncertainty=").append(mLatitudeUncertainty).append(
                ", longitude=").append(mLongitude).append(", longitudeUncertainty=").append(
                mLongitudeUncertainty).append(", altitudeType=").append(mAltitudeType).append(
                ", altitude=").append(mAltitude).append(", altitudeUncertainty=").append(
                mAltitudeUncertainty).toString();
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }

        if (!(o instanceof LocationConfigurationInformation)) {
            return false;
        }

        LocationConfigurationInformation lhs = (LocationConfigurationInformation) o;

        return mLatitude == lhs.mLatitude && mLatitudeUncertainty == lhs.mLatitudeUncertainty
                && mLongitude == lhs.mLongitude
                && mLongitudeUncertainty == lhs.mLongitudeUncertainty
                && mAltitudeType == lhs.mAltitudeType && mAltitude == lhs.mAltitude
                && mAltitudeUncertainty == lhs.mAltitudeUncertainty;
    }

    @Override
    public int hashCode() {
        return Objects.hash(mLatitude, mLatitudeUncertainty, mLongitude, mLongitudeUncertainty,
                mAltitudeType, mAltitude, mAltitudeUncertainty);
    }
}
+27 −39
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package android.net.wifi.rtt;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.net.MacAddress;
import android.net.wifi.aware.PeerHandle;
import android.os.Handler;
@@ -27,6 +28,7 @@ import android.os.Parcelable;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

@@ -40,6 +42,7 @@ import java.util.Objects;
 */
public final class RangingResult implements Parcelable {
    private static final String TAG = "RangingResult";
    private static final byte[] EMPTY_BYTE_ARRAY = new byte[0];

    /** @hide */
    @IntDef({STATUS_SUCCESS, STATUS_FAIL, STATUS_RESPONDER_DOES_NOT_SUPPORT_IEEE80211MC})
@@ -76,37 +79,35 @@ public final class RangingResult implements Parcelable {
    private final int mDistanceMm;
    private final int mDistanceStdDevMm;
    private final int mRssi;
    private final LocationConfigurationInformation mLci;
    private final LocationCivic mLcr;
    private final byte[] mLci;
    private final byte[] mLcr;
    private final long mTimestamp;

    /** @hide */
    public RangingResult(@RangeResultStatus int status, @NonNull MacAddress mac, int distanceMm,
            int distanceStdDevMm, int rssi, LocationConfigurationInformation lci, LocationCivic lcr,
            long timestamp) {
            int distanceStdDevMm, int rssi, byte[] lci, byte[] lcr, long timestamp) {
        mStatus = status;
        mMac = mac;
        mPeerHandle = null;
        mDistanceMm = distanceMm;
        mDistanceStdDevMm = distanceStdDevMm;
        mRssi = rssi;
        mLci = lci;
        mLcr = lcr;
        mLci = lci == null ? EMPTY_BYTE_ARRAY : lci;
        mLcr = lcr == null ? EMPTY_BYTE_ARRAY : lcr;
        mTimestamp = timestamp;
    }

    /** @hide */
    public RangingResult(@RangeResultStatus int status, PeerHandle peerHandle, int distanceMm,
            int distanceStdDevMm, int rssi, LocationConfigurationInformation lci, LocationCivic lcr,
            long timestamp) {
            int distanceStdDevMm, int rssi, byte[] lci, byte[] lcr, long timestamp) {
        mStatus = status;
        mMac = null;
        mPeerHandle = peerHandle;
        mDistanceMm = distanceMm;
        mDistanceStdDevMm = distanceStdDevMm;
        mRssi = rssi;
        mLci = lci;
        mLcr = lcr;
        mLci = lci == null ? EMPTY_BYTE_ARRAY : lci;
        mLcr = lcr == null ? EMPTY_BYTE_ARRAY : lcr;
        mTimestamp = timestamp;
    }

@@ -192,13 +193,15 @@ public final class RangingResult implements Parcelable {
     * <p>
     * Note: the information is NOT validated - use with caution. Consider validating it with
     * other sources of information before using it.
     *
     * @hide
     */
    @Nullable
    public LocationConfigurationInformation getReportedLocationConfigurationInformation() {
    @SystemApi
    @NonNull
    public byte[] getLci() {
        if (mStatus != STATUS_SUCCESS) {
            throw new IllegalStateException(
                    "getReportedLocationConfigurationInformation(): invoked on an invalid result: "
                            + "getStatus()=" + mStatus);
                    "getLci(): invoked on an invalid result: getStatus()=" + mStatus);
        }
        return mLci;
    }
@@ -208,9 +211,12 @@ public final class RangingResult implements Parcelable {
     * <p>
     * Note: the information is NOT validated - use with caution. Consider validating it with
     * other sources of information before using it.
     *
     * @hide
     */
    @Nullable
    public LocationCivic getReportedLocationCivic() {
    @SystemApi
    @NonNull
    public byte[] getLcr() {
        if (mStatus != STATUS_SUCCESS) {
            throw new IllegalStateException(
                    "getReportedLocationCivic(): invoked on an invalid result: getStatus()="
@@ -256,18 +262,8 @@ public final class RangingResult implements Parcelable {
        dest.writeInt(mDistanceMm);
        dest.writeInt(mDistanceStdDevMm);
        dest.writeInt(mRssi);
        if (mLci == null) {
            dest.writeBoolean(false);
        } else {
            dest.writeBoolean(true);
            mLci.writeToParcel(dest, flags);
        }
        if (mLcr == null) {
            dest.writeBoolean(false);
        } else {
            dest.writeBoolean(true);
            mLcr.writeToParcel(dest, flags);
        }
        dest.writeByteArray(mLci);
        dest.writeByteArray(mLcr);
        dest.writeLong(mTimestamp);
    }

@@ -293,16 +289,8 @@ public final class RangingResult implements Parcelable {
            int distanceMm = in.readInt();
            int distanceStdDevMm = in.readInt();
            int rssi = in.readInt();
            boolean lciPresent = in.readBoolean();
            LocationConfigurationInformation lci = null;
            if (lciPresent) {
                lci = LocationConfigurationInformation.CREATOR.createFromParcel(in);
            }
            boolean lcrPresent = in.readBoolean();
            LocationCivic lcr = null;
            if (lcrPresent) {
                lcr = LocationCivic.CREATOR.createFromParcel(in);
            }
            byte[] lci = in.createByteArray();
            byte[] lcr = in.createByteArray();
            long timestamp = in.readLong();
            if (peerHandlePresent) {
                return new RangingResult(status, peerHandle, distanceMm, distanceStdDevMm, rssi,
@@ -340,7 +328,7 @@ public final class RangingResult implements Parcelable {
        return mStatus == lhs.mStatus && Objects.equals(mMac, lhs.mMac) && Objects.equals(
                mPeerHandle, lhs.mPeerHandle) && mDistanceMm == lhs.mDistanceMm
                && mDistanceStdDevMm == lhs.mDistanceStdDevMm && mRssi == lhs.mRssi
                && Objects.equals(mLci, lhs.mLci) && Objects.equals(mLcr, lhs.mLcr)
                && Arrays.equals(mLci, lhs.mLci) && Arrays.equals(mLcr, lhs.mLcr)
                && mTimestamp == lhs.mTimestamp;
    }

Loading