diff options
11 files changed, 385 insertions, 613 deletions
diff --git a/api/current.txt b/api/current.txt index 89faaa3d8716..89f4b7ebc13c 100644 --- a/api/current.txt +++ b/api/current.txt @@ -23479,66 +23479,54 @@ package android.location { } public final class GnssAntennaInfo implements android.os.Parcelable { - ctor public GnssAntennaInfo(double, @NonNull android.location.GnssAntennaInfo.PhaseCenterOffsetCoordinates, @Nullable android.location.GnssAntennaInfo.PhaseCenterVariationCorrections, @Nullable android.location.GnssAntennaInfo.SignalGainCorrections); method public int describeContents(); - method public double getCarrierFrequencyMHz(); - method @NonNull public android.location.GnssAntennaInfo.PhaseCenterOffsetCoordinates getPhaseCenterOffsetCoordinates(); - method @Nullable public android.location.GnssAntennaInfo.PhaseCenterVariationCorrections getPhaseCenterVariationCorrections(); - method @Nullable public android.location.GnssAntennaInfo.SignalGainCorrections getSignalGainCorrections(); + method @FloatRange(from=0.0f) public double getCarrierFrequencyMHz(); + method @NonNull public android.location.GnssAntennaInfo.PhaseCenterOffset getPhaseCenterOffset(); + method @Nullable public android.location.GnssAntennaInfo.SphericalCorrections getPhaseCenterVariationCorrections(); + method @Nullable public android.location.GnssAntennaInfo.SphericalCorrections getSignalGainCorrections(); method public void writeToParcel(@NonNull android.os.Parcel, int); field @NonNull public static final android.os.Parcelable.Creator<android.location.GnssAntennaInfo> CREATOR; } - public abstract static class GnssAntennaInfo.Callback { - ctor public GnssAntennaInfo.Callback(); + public static class GnssAntennaInfo.Builder { + ctor public GnssAntennaInfo.Builder(); + method @NonNull public android.location.GnssAntennaInfo build(); + method @NonNull public android.location.GnssAntennaInfo.Builder setCarrierFrequencyMHz(@FloatRange(from=0.0f) double); + method @NonNull public android.location.GnssAntennaInfo.Builder setPhaseCenterOffset(@NonNull android.location.GnssAntennaInfo.PhaseCenterOffset); + method @NonNull public android.location.GnssAntennaInfo.Builder setPhaseCenterVariationCorrections(@Nullable android.location.GnssAntennaInfo.SphericalCorrections); + method @NonNull public android.location.GnssAntennaInfo.Builder setSignalGainCorrections(@Nullable android.location.GnssAntennaInfo.SphericalCorrections); + } + + public static interface GnssAntennaInfo.Listener { method public void onGnssAntennaInfoReceived(@NonNull java.util.List<android.location.GnssAntennaInfo>); - method public void onStatusChanged(int); - field public static final int STATUS_LOCATION_DISABLED = 2; // 0x2 - field public static final int STATUS_NOT_SUPPORTED = 0; // 0x0 - field public static final int STATUS_READY = 1; // 0x1 } - public static final class GnssAntennaInfo.PhaseCenterOffsetCoordinates implements android.os.Parcelable { - ctor public GnssAntennaInfo.PhaseCenterOffsetCoordinates(double, double, double, double, double, double); + public static final class GnssAntennaInfo.PhaseCenterOffset implements android.os.Parcelable { + ctor public GnssAntennaInfo.PhaseCenterOffset(double, double, double, double, double, double); method public int describeContents(); - method public double getXCoordMillimeters(); - method public double getXCoordUncertaintyMillimeters(); - method public double getYCoordMillimeters(); - method public double getYCoordUncertaintyMillimeters(); - method public double getZCoordMillimeters(); - method public double getZCoordUncertaintyMillimeters(); + method @FloatRange public double getXOffsetMm(); + method @FloatRange public double getXOffsetUncertaintyMm(); + method @FloatRange public double getYOffsetMm(); + method @FloatRange public double getYOffsetUncertaintyMm(); + method @FloatRange public double getZOffsetMm(); + method @FloatRange public double getZOffsetUncertaintyMm(); method public void writeToParcel(@NonNull android.os.Parcel, int); - field @NonNull public static final android.os.Parcelable.Creator<android.location.GnssAntennaInfo.PhaseCenterOffsetCoordinates> CREATOR; + field @NonNull public static final android.os.Parcelable.Creator<android.location.GnssAntennaInfo.PhaseCenterOffset> CREATOR; } - public static final class GnssAntennaInfo.PhaseCenterVariationCorrections implements android.os.Parcelable { - ctor public GnssAntennaInfo.PhaseCenterVariationCorrections(@NonNull double[][], @NonNull double[][]); + public static final class GnssAntennaInfo.SphericalCorrections implements android.os.Parcelable { + ctor public GnssAntennaInfo.SphericalCorrections(@NonNull double[][], @NonNull double[][]); method public int describeContents(); - method public double getDeltaPhi(); - method public double getDeltaTheta(); - method public int getNumColumns(); - method public int getNumRows(); - method public double getPhaseCenterVariationCorrectionMillimetersAt(int, int); - method public double getPhaseCenterVariationCorrectionUncertaintyMillimetersAt(int, int); - method @NonNull public double[][] getRawCorrectionUncertaintiesArray(); - method @NonNull public double[][] getRawCorrectionsArray(); + method @NonNull public double[][] getCorrectionUncertaintiesArray(); + method @NonNull public double[][] getCorrectionsArray(); + method @FloatRange(from=0.0f, to=180.0f) public double getDeltaPhi(); + method @FloatRange(from=0.0f, to=360.0f) public double getDeltaTheta(); method public void writeToParcel(@NonNull android.os.Parcel, int); - field @NonNull public static final android.os.Parcelable.Creator<android.location.GnssAntennaInfo.PhaseCenterVariationCorrections> CREATOR; + field @NonNull public static final android.os.Parcelable.Creator<android.location.GnssAntennaInfo.SphericalCorrections> CREATOR; } - public static final class GnssAntennaInfo.SignalGainCorrections implements android.os.Parcelable { - ctor public GnssAntennaInfo.SignalGainCorrections(@NonNull double[][], @NonNull double[][]); - method public int describeContents(); - method public double getDeltaPhi(); - method public double getDeltaTheta(); - method public int getNumColumns(); - method public int getNumRows(); - method @NonNull public double[][] getRawCorrectionUncertaintiesArray(); - method @NonNull public double[][] getRawCorrectionsArray(); - method public double getSignalGainCorrectionDbiAt(int, int); - method public double getSignalGainCorrectionUncertaintyDbiAt(int, int); - method public void writeToParcel(@NonNull android.os.Parcel, int); - field @NonNull public static final android.os.Parcelable.Creator<android.location.GnssAntennaInfo.SignalGainCorrections> CREATOR; + public final class GnssCapabilities { + method public boolean hasGnssAntennaInfo(); } public final class GnssClock implements android.os.Parcelable { @@ -23849,6 +23837,7 @@ package android.location { method @NonNull public java.util.List<java.lang.String> getAllProviders(); method @Nullable public String getBestProvider(@NonNull android.location.Criteria, boolean); method @RequiresPermission(anyOf={android.Manifest.permission.ACCESS_COARSE_LOCATION, android.Manifest.permission.ACCESS_FINE_LOCATION}) public void getCurrentLocation(@NonNull String, @Nullable android.os.CancellationSignal, @NonNull java.util.concurrent.Executor, @NonNull java.util.function.Consumer<android.location.Location>); + method @NonNull public android.location.GnssCapabilities getGnssCapabilities(); method @Nullable public String getGnssHardwareModelName(); method public int getGnssYearOfHardware(); method @Deprecated @Nullable @RequiresPermission(android.Manifest.permission.ACCESS_FINE_LOCATION) public android.location.GpsStatus getGpsStatus(@Nullable android.location.GpsStatus); @@ -23858,7 +23847,7 @@ package android.location { method @NonNull public java.util.List<java.lang.String> getProviders(@NonNull android.location.Criteria, boolean); method public boolean isLocationEnabled(); method public boolean isProviderEnabled(@NonNull String); - method @RequiresPermission(android.Manifest.permission.ACCESS_FINE_LOCATION) public boolean registerAntennaInfoCallback(@NonNull java.util.concurrent.Executor, @NonNull android.location.GnssAntennaInfo.Callback); + method @RequiresPermission(android.Manifest.permission.ACCESS_FINE_LOCATION) public boolean registerAntennaInfoListener(@NonNull java.util.concurrent.Executor, @NonNull android.location.GnssAntennaInfo.Listener); method @Deprecated @RequiresPermission(android.Manifest.permission.ACCESS_FINE_LOCATION) public boolean registerGnssMeasurementsCallback(@NonNull android.location.GnssMeasurementsEvent.Callback); method @RequiresPermission(android.Manifest.permission.ACCESS_FINE_LOCATION) public boolean registerGnssMeasurementsCallback(@NonNull android.location.GnssMeasurementsEvent.Callback, @Nullable android.os.Handler); method @RequiresPermission(android.Manifest.permission.ACCESS_FINE_LOCATION) public boolean registerGnssMeasurementsCallback(@NonNull java.util.concurrent.Executor, @NonNull android.location.GnssMeasurementsEvent.Callback); @@ -23890,7 +23879,7 @@ package android.location { method public void setTestProviderEnabled(@NonNull String, boolean); method public void setTestProviderLocation(@NonNull String, @NonNull android.location.Location); method @Deprecated public void setTestProviderStatus(@NonNull String, int, @Nullable android.os.Bundle, long); - method public void unregisterAntennaInfoCallback(@NonNull android.location.GnssAntennaInfo.Callback); + method public void unregisterAntennaInfoListener(@NonNull android.location.GnssAntennaInfo.Listener); method public void unregisterGnssMeasurementsCallback(@NonNull android.location.GnssMeasurementsEvent.Callback); method public void unregisterGnssNavigationMessageCallback(@NonNull android.location.GnssNavigationMessage.Callback); method public void unregisterGnssStatusCallback(@NonNull android.location.GnssStatus.Callback); diff --git a/api/system-current.txt b/api/system-current.txt index 838d23fde434..b2de6ea698d5 100755 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -3806,7 +3806,6 @@ package android.location { public final class GnssCapabilities { method public boolean hasGeofencing(); - method public boolean hasGnssAntennaInfo(); method public boolean hasLowPowerMode(); method public boolean hasMeasurementCorrections(); method public boolean hasMeasurementCorrectionsExcessPathLength(); @@ -4146,7 +4145,6 @@ package android.location { method @RequiresPermission(anyOf={android.Manifest.permission.ACCESS_COARSE_LOCATION, android.Manifest.permission.ACCESS_FINE_LOCATION}) public void getCurrentLocation(@NonNull android.location.LocationRequest, @Nullable android.os.CancellationSignal, @NonNull java.util.concurrent.Executor, @NonNull java.util.function.Consumer<android.location.Location>); method @Nullable public String getExtraLocationControllerPackage(); method @RequiresPermission(android.Manifest.permission.LOCATION_HARDWARE) public int getGnssBatchSize(); - method @NonNull @RequiresPermission(android.Manifest.permission.ACCESS_FINE_LOCATION) public android.location.GnssCapabilities getGnssCapabilities(); method @RequiresPermission(android.Manifest.permission.ACCESS_FINE_LOCATION) public void injectGnssMeasurementCorrections(@NonNull android.location.GnssMeasurementCorrections); method public boolean isExtraLocationControllerPackageEnabled(); method public boolean isLocationEnabledForUser(@NonNull android.os.UserHandle); diff --git a/location/java/android/location/GnssAntennaInfo.java b/location/java/android/location/GnssAntennaInfo.java index dfcaf814f9c9..b2f9a0f41b7e 100644 --- a/location/java/android/location/GnssAntennaInfo.java +++ b/location/java/android/location/GnssAntennaInfo.java @@ -16,72 +16,37 @@ package android.location; -import android.annotation.IntDef; +import android.annotation.FloatRange; import android.annotation.NonNull; import android.annotation.Nullable; import android.os.Parcel; import android.os.Parcelable; -import com.android.internal.annotations.VisibleForTesting; - -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; +import java.util.Arrays; import java.util.List; +import java.util.Objects; /** * A class that contains information about a GNSS antenna. GNSS antenna characteristics can change * with device configuration, such as when a device is folded open or closed. Antenna information is - * delivered to registered instances of {@link Callback}. + * delivered to registered instances of {@link Listener}. */ public final class GnssAntennaInfo implements Parcelable { private final double mCarrierFrequencyMHz; - private final PhaseCenterOffsetCoordinates mPhaseCenterOffsetCoordinates; - private final PhaseCenterVariationCorrections mPhaseCenterVariationCorrections; - private final SignalGainCorrections mSignalGainCorrections; + private final PhaseCenterOffset mPhaseCenterOffset; + private final SphericalCorrections mPhaseCenterVariationCorrections; + private final SphericalCorrections mSignalGainCorrections; /** * Used for receiving GNSS antenna info from the GNSS engine. You can implement this interface - * and call {@link LocationManager#registerAntennaInfoCallback}; + * and call {@link LocationManager#registerAntennaInfoListener}; */ - public abstract static class Callback { - /** - * The status of GNSS antenna info. - * - * @hide - */ - @Retention(RetentionPolicy.SOURCE) - @IntDef({STATUS_NOT_SUPPORTED, STATUS_READY, STATUS_LOCATION_DISABLED}) - public @interface GnssAntennaInfoStatus { - } - - /** - * The system does not support GNSS antenna info. - * - * This status will not change in the future. - */ - public static final int STATUS_NOT_SUPPORTED = 0; - - /** - * GNSS antenna info updates are being successfully tracked. - */ - public static final int STATUS_READY = 1; - - /** - * GNSS provider or Location is disabled, updated will not be received until they are - * enabled. - */ - public static final int STATUS_LOCATION_DISABLED = 2; - + public interface Listener { /** - * Returns the latest GNSS antenna info. This event is triggered when a callback is + * Returns the latest GNSS antenna info. This event is triggered when a listener is * registered, and whenever the antenna info changes (due to a device configuration change). */ - public void onGnssAntennaInfoReceived(@NonNull List<GnssAntennaInfo> gnssAntennaInfos) {} - - /** - * Returns the latest status of the GNSS antenna info sub-system. - */ - public void onStatusChanged(@GnssAntennaInfoStatus int status) {} + void onGnssAntennaInfoReceived(@NonNull List<GnssAntennaInfo> gnssAntennaInfos); } /** @@ -90,37 +55,31 @@ public final class GnssAntennaInfo implements Parcelable { * for mobiles - see sensor or form factor documents for details. Uncertainties are reported * to 1-sigma. */ - public static final class PhaseCenterOffsetCoordinates implements Parcelable { - private final double mPhaseCenterOffsetCoordinateXMillimeters; - private final double mPhaseCenterOffsetCoordinateXUncertaintyMillimeters; - private final double mPhaseCenterOffsetCoordinateYMillimeters; - private final double mPhaseCenterOffsetCoordinateYUncertaintyMillimeters; - private final double mPhaseCenterOffsetCoordinateZMillimeters; - private final double mPhaseCenterOffsetCoordinateZUncertaintyMillimeters; - - @VisibleForTesting - public PhaseCenterOffsetCoordinates(double phaseCenterOffsetCoordinateXMillimeters, - double phaseCenterOffsetCoordinateXUncertaintyMillimeters, - double phaseCenterOffsetCoordinateYMillimeters, - double phaseCenterOffsetCoordinateYUncertaintyMillimeters, - double phaseCenterOffsetCoordinateZMillimeters, - double phaseCenterOffsetCoordinateZUncertaintyMillimeters) { - mPhaseCenterOffsetCoordinateXMillimeters = phaseCenterOffsetCoordinateXMillimeters; - mPhaseCenterOffsetCoordinateYMillimeters = phaseCenterOffsetCoordinateYMillimeters; - mPhaseCenterOffsetCoordinateZMillimeters = phaseCenterOffsetCoordinateZMillimeters; - mPhaseCenterOffsetCoordinateXUncertaintyMillimeters = - phaseCenterOffsetCoordinateXUncertaintyMillimeters; - mPhaseCenterOffsetCoordinateYUncertaintyMillimeters = - phaseCenterOffsetCoordinateYUncertaintyMillimeters; - mPhaseCenterOffsetCoordinateZUncertaintyMillimeters = - phaseCenterOffsetCoordinateZUncertaintyMillimeters; - } - - public static final @NonNull Creator<PhaseCenterOffsetCoordinates> CREATOR = - new Creator<PhaseCenterOffsetCoordinates>() { + public static final class PhaseCenterOffset implements Parcelable { + private final double mOffsetXMm; + private final double mOffsetXUncertaintyMm; + private final double mOffsetYMm; + private final double mOffsetYUncertaintyMm; + private final double mOffsetZMm; + private final double mOffsetZUncertaintyMm; + + public PhaseCenterOffset( + double offsetXMm, double offsetXUncertaintyMm, + double offsetYMm, double offsetYUncertaintyMm, + double offsetZMm, double offsetZUncertaintyMm) { + mOffsetXMm = offsetXMm; + mOffsetYMm = offsetYMm; + mOffsetZMm = offsetZMm; + mOffsetXUncertaintyMm = offsetXUncertaintyMm; + mOffsetYUncertaintyMm = offsetYUncertaintyMm; + mOffsetZUncertaintyMm = offsetZUncertaintyMm; + } + + public static final @NonNull Creator<PhaseCenterOffset> CREATOR = + new Creator<PhaseCenterOffset>() { @Override - public PhaseCenterOffsetCoordinates createFromParcel(Parcel in) { - return new PhaseCenterOffsetCoordinates( + public PhaseCenterOffset createFromParcel(Parcel in) { + return new PhaseCenterOffset( in.readDouble(), in.readDouble(), in.readDouble(), @@ -131,158 +90,41 @@ public final class GnssAntennaInfo implements Parcelable { } @Override - public PhaseCenterOffsetCoordinates[] newArray(int size) { - return new PhaseCenterOffsetCoordinates[size]; + public PhaseCenterOffset[] newArray(int size) { + return new PhaseCenterOffset[size]; } }; - public double getXCoordMillimeters() { - return mPhaseCenterOffsetCoordinateXMillimeters; - } - - public double getXCoordUncertaintyMillimeters() { - return mPhaseCenterOffsetCoordinateXUncertaintyMillimeters; - } - - public double getYCoordMillimeters() { - return mPhaseCenterOffsetCoordinateYMillimeters; - } - - public double getYCoordUncertaintyMillimeters() { - return mPhaseCenterOffsetCoordinateYUncertaintyMillimeters; - } - - public double getZCoordMillimeters() { - return mPhaseCenterOffsetCoordinateZMillimeters; - } - - public double getZCoordUncertaintyMillimeters() { - return mPhaseCenterOffsetCoordinateZUncertaintyMillimeters; - } - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(@NonNull Parcel dest, int flags) { - dest.writeDouble(mPhaseCenterOffsetCoordinateXMillimeters); - dest.writeDouble(mPhaseCenterOffsetCoordinateXUncertaintyMillimeters); - dest.writeDouble(mPhaseCenterOffsetCoordinateYMillimeters); - dest.writeDouble(mPhaseCenterOffsetCoordinateYUncertaintyMillimeters); - dest.writeDouble(mPhaseCenterOffsetCoordinateZMillimeters); - dest.writeDouble(mPhaseCenterOffsetCoordinateZUncertaintyMillimeters); - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder("PhaseCenteroffset:\n"); - builder.append("X: " + mPhaseCenterOffsetCoordinateXMillimeters + " +/- " - + mPhaseCenterOffsetCoordinateXUncertaintyMillimeters + "\n"); - builder.append("Y: " + mPhaseCenterOffsetCoordinateYMillimeters + " +/- " - + mPhaseCenterOffsetCoordinateYUncertaintyMillimeters + "\n"); - builder.append("Z: " + mPhaseCenterOffsetCoordinateZMillimeters + " +/- " - + mPhaseCenterOffsetCoordinateZUncertaintyMillimeters + "\n"); - return builder.toString(); - } - } - - /** - * Class containing information about the phase center variation (PCV) corrections. The PCV - * correction is added to the phase measurement to obtain the corrected value. - * - * The corrections and associated (1-sigma) uncertainties are represented by respect 2D arrays. - * - * Each row (major indices) represents a fixed theta. The first row corresponds to a - * theta angle of 0 degrees. The last row corresponds to a theta angle of (360 - deltaTheta) - * degrees, where deltaTheta is the regular spacing between azimuthal angles, i.e., deltaTheta - * = 360 / (number of rows). - * - * The columns (minor indices) represent fixed zenith angles, beginning at 0 degrees and ending - * at 180 degrees. They are separated by deltaPhi, the regular spacing between zenith angles, - * i.e., deltaPhi = 180 / (number of columns - 1). - */ - public static final class PhaseCenterVariationCorrections extends SphericalCorrections { - - @VisibleForTesting - public PhaseCenterVariationCorrections( - @NonNull double[][] phaseCenterVariationCorrectionsMillimeters, - @NonNull double[][] phaseCenterVariationCorrectionUncertaintiesMillimeters) { - super(phaseCenterVariationCorrectionsMillimeters, - phaseCenterVariationCorrectionUncertaintiesMillimeters); - } - - private PhaseCenterVariationCorrections(@NonNull Parcel in) { - super(in); - } - - /** - * Get the phase center variation correction in millimeters at the specified row and column - * in the underlying 2D array. - * @param row zero-based major index in the array - * @param column zero-based minor index in the array - * @return phase center correction in millimeters - */ - public double getPhaseCenterVariationCorrectionMillimetersAt(int row, int column) { - return super.getCorrectionAt(row, column); - } - - /** - * Get the phase center variation correction uncertainty in millimeters at the specified row - * and column in the underlying 2D array. - * @param row zero-based major index in the array - * @param column zero-based minor index in the array - * @return 1-sigma phase center correction uncertainty in millimeters - */ - public double getPhaseCenterVariationCorrectionUncertaintyMillimetersAt( - int row, int column) { - return super.getCorrectionUncertaintyAt(row, column); - } - - public @NonNull double[][] getRawCorrectionsArray() { - return super.getRawCorrectionsArray().clone(); + @FloatRange() + public double getXOffsetMm() { + return mOffsetXMm; } - public @NonNull double[][] getRawCorrectionUncertaintiesArray() { - return super.getRawCorrectionUncertaintiesArray().clone(); + @FloatRange() + public double getXOffsetUncertaintyMm() { + return mOffsetXUncertaintyMm; } - public int getNumRows() { - return super.getNumRows(); + @FloatRange() + public double getYOffsetMm() { + return mOffsetYMm; } - public int getNumColumns() { - return super.getNumColumns(); + @FloatRange() + public double getYOffsetUncertaintyMm() { + return mOffsetYUncertaintyMm; } - /** - * The fixed theta angle separation between successive rows. - */ - public double getDeltaTheta() { - return super.getDeltaTheta(); + @FloatRange() + public double getZOffsetMm() { + return mOffsetZMm; } - /** - * The fixed phi angle separation between successive columns. - */ - public double getDeltaPhi() { - return super.getDeltaPhi(); + @FloatRange() + public double getZOffsetUncertaintyMm() { + return mOffsetZUncertaintyMm; } - public static final @NonNull Creator<PhaseCenterVariationCorrections> CREATOR = - new Creator<PhaseCenterVariationCorrections>() { - @Override - public PhaseCenterVariationCorrections createFromParcel(Parcel in) { - return new PhaseCenterVariationCorrections(in); - } - - @Override - public PhaseCenterVariationCorrections[] newArray(int size) { - return new PhaseCenterVariationCorrections[size]; - } - }; - @Override public int describeContents() { return 0; @@ -290,20 +132,27 @@ public final class GnssAntennaInfo implements Parcelable { @Override public void writeToParcel(@NonNull Parcel dest, int flags) { - super.writeToParcel(dest, flags); + dest.writeDouble(mOffsetXMm); + dest.writeDouble(mOffsetXUncertaintyMm); + dest.writeDouble(mOffsetYMm); + dest.writeDouble(mOffsetYUncertaintyMm); + dest.writeDouble(mOffsetZMm); + dest.writeDouble(mOffsetZUncertaintyMm); } @Override public String toString() { - StringBuilder builder = new StringBuilder("PhaseCenterVariationCorrections:\n"); - builder.append(super.toString()); - return builder.toString(); + return "PhaseCenterOffset{" + + "OffsetXMm=" + mOffsetXMm + " +/-" + mOffsetXUncertaintyMm + + ", OffsetYMm=" + mOffsetYMm + " +/-" + mOffsetYUncertaintyMm + + ", OffsetZMm=" + mOffsetZMm + " +/-" + mOffsetZUncertaintyMm + + '}'; } } /** - * Class containing information about the signal gain (SG) corrections. The SG - * correction is added to the signal gain to obtain the corrected value. + * Represents corrections on a spherical mapping. Corrections are added to measurements to + * obtain the corrected values. * * The corrections and associated (1-sigma) uncertainties are represented by respect 2D arrays. * @@ -316,116 +165,7 @@ public final class GnssAntennaInfo implements Parcelable { * at 180 degrees. They are separated by deltaPhi, the regular spacing between zenith angles, * i.e., deltaPhi = 180 / (number of columns - 1). */ - public static final class SignalGainCorrections extends SphericalCorrections { - - @VisibleForTesting - public SignalGainCorrections( - @NonNull double[][] signalGainCorrectionsDbi, - @NonNull double[][] signalGainCorrectionUncertaintiesDbi) { - super(signalGainCorrectionsDbi, - signalGainCorrectionUncertaintiesDbi); - } - - private SignalGainCorrections(@NonNull Parcel in) { - super(in); - } - - /** - * Get the signal gain correction in dbi at the specified row and column - * in the underlying 2D array. - * @param row zero-based major index in the array - * @param column zero-based minor index in the array - * @return signal gain correction in dbi - */ - public double getSignalGainCorrectionDbiAt(int row, int column) { - return super.getCorrectionAt(row, column); - } - - /** - * Get the signal gain correction correction uncertainty in dbi at the specified row - * and column in the underlying 2D array. - * @param row zero-based major index in the array - * @param column zero-based minor index in the array - * @return 1-sigma signal gain correction uncertainty in dbi - */ - public double getSignalGainCorrectionUncertaintyDbiAt(int row, int column) { - return super.getCorrectionUncertaintyAt(row, column); - } - - public @NonNull double[][] getRawCorrectionsArray() { - return super.getRawCorrectionsArray().clone(); - } - - public @NonNull double[][] getRawCorrectionUncertaintiesArray() { - return super.getRawCorrectionUncertaintiesArray().clone(); - } - - public int getNumRows() { - return super.getNumRows(); - } - - public int getNumColumns() { - return super.getNumColumns(); - } - - /** - * The fixed theta angle separation between successive rows. - */ - public double getDeltaTheta() { - return super.getDeltaTheta(); - } - - /** - * The fixed phi angle separation between successive columns. - */ - public double getDeltaPhi() { - return super.getDeltaPhi(); - } - - public static final @NonNull Creator<SignalGainCorrections> CREATOR = - new Creator<SignalGainCorrections>() { - @Override - public SignalGainCorrections createFromParcel(Parcel in) { - return new SignalGainCorrections(in); - } - - @Override - public SignalGainCorrections[] newArray(int size) { - return new SignalGainCorrections[size]; - } - }; - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(@NonNull Parcel dest, int flags) { - super.writeToParcel(dest, flags); - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder("SignalGainCorrections:\n"); - builder.append(super.toString()); - return builder.toString(); - } - } - - /** - * Represents corrections on a spherical mapping. - * - * Each row (major indices) represents a fixed theta. The first row corresponds to a - * theta angle of 0 degrees. The last row corresponds to a theta angle of (360 - deltaTheta) - * degrees, where deltaTheta is the regular spacing between azimuthal angles, i.e., deltaTheta - * = 360 / (number of rows). - * - * The columns (minor indices) represent fixed zenith angles, beginning at 0 degrees and ending - * at 180 degrees. They are separated by deltaPhi, the regular spacing between zenith angles, - * i.e., deltaPhi = 180 / (number of columns - 1). - */ - private abstract static class SphericalCorrections implements Parcelable { + public static final class SphericalCorrections implements Parcelable{ private final double[][] mCorrections; private final double[][] mCorrectionUncertainties; private final double mDeltaTheta; @@ -433,7 +173,7 @@ public final class GnssAntennaInfo implements Parcelable { private final int mNumRows; private final int mNumColumns; - SphericalCorrections(@NonNull double[][] corrections, + public SphericalCorrections(@NonNull double[][] corrections, @NonNull double[][] correctionUncertainties) { if (corrections.length != correctionUncertainties.length || corrections[0].length != correctionUncertainties[0].length) { @@ -474,54 +214,84 @@ public final class GnssAntennaInfo implements Parcelable { in.readDoubleArray(correctionUncertainties[row]); } - mNumRows = corrections.length; - mNumColumns = corrections[0].length; + mNumRows = numRows; + mNumColumns = numColumns; mCorrections = corrections; mCorrectionUncertainties = correctionUncertainties; mDeltaTheta = 360.0d / mNumRows; mDeltaPhi = 180.0d / (mNumColumns - 1); } - private double getCorrectionAt(int row, int column) { - return mCorrections[row][column]; - } - - private double getCorrectionUncertaintyAt(int row, int column) { - return mCorrectionUncertainties[row][column]; - } - + /** + * Array representing corrections on a spherical mapping. Corrections are added to + * measurements to obtain the corrected values. + * + * Each row (major indices) represents a fixed theta. The first row corresponds to a + * theta angle of 0 degrees. The last row corresponds to a theta angle of (360 - deltaTheta) + * degrees, where deltaTheta is the regular spacing between azimuthal angles, i.e., + * deltaTheta = 360 / (number of rows). + * + * The columns (minor indices) represent fixed zenith angles, beginning at 0 degrees and + * ending at 180 degrees. They are separated by deltaPhi, the regular spacing between zenith + * angles, i.e., deltaPhi = 180 / (number of columns - 1). + */ @NonNull - private double[][] getRawCorrectionsArray() { + public double[][] getCorrectionsArray() { return mCorrections; } + /** + * Array representing uncertainty on corrections on a spherical mapping. + * + * Each row (major indices) represents a fixed theta. The first row corresponds to a + * theta angle of 0 degrees. The last row corresponds to a theta angle of (360 - deltaTheta) + * degrees, where deltaTheta is the regular spacing between azimuthal angles, i.e., + * deltaTheta = 360 / (number of rows). + * + * The columns (minor indices) represent fixed zenith angles, beginning at 0 degrees and + * ending at 180 degrees. They are separated by deltaPhi, the regular spacing between zenith + * angles, i.e., deltaPhi = 180 / (number of columns - 1). + */ @NonNull - private double[][] getRawCorrectionUncertaintiesArray() { + public double[][] getCorrectionUncertaintiesArray() { return mCorrectionUncertainties; } - private int getNumRows() { - return mNumRows; - } - - private int getNumColumns() { - return mNumColumns; - } - /** * The fixed theta angle separation between successive rows. */ - private double getDeltaTheta() { + @FloatRange(from = 0.0f, to = 360.0f) + public double getDeltaTheta() { return mDeltaTheta; } /** * The fixed phi angle separation between successive columns. */ - private double getDeltaPhi() { + @FloatRange(from = 0.0f, to = 180.0f) + public double getDeltaPhi() { return mDeltaPhi; } + + public static final @NonNull Creator<SphericalCorrections> CREATOR = + new Creator<SphericalCorrections>() { + @Override + public SphericalCorrections createFromParcel(Parcel in) { + return new SphericalCorrections(in); + } + + @Override + public SphericalCorrections[] newArray(int size) { + return new SphericalCorrections[size]; + } + }; + + @Override + public int describeContents() { + return 0; + } + @Override public void writeToParcel(@NonNull Parcel dest, int flags) { dest.writeInt(mNumRows); @@ -534,62 +304,114 @@ public final class GnssAntennaInfo implements Parcelable { } } - private String arrayToString(double[][] array) { - StringBuilder builder = new StringBuilder(); - for (int row = 0; row < mNumRows; row++) { - builder.append("[ "); - for (int column = 0; column < mNumColumns - 1; column++) { - builder.append(array[row][column] + ", "); - } - builder.append(array[row][mNumColumns - 1] + " ]\n"); - } - return builder.toString(); - } - @Override public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("DeltaTheta: " + mDeltaTheta + "\n"); - builder.append("DeltaPhi: " + mDeltaPhi + "\n"); - builder.append("CorrectionsArray:\n"); - builder.append(arrayToString(mCorrections)); - builder.append("CorrectionUncertaintiesArray:\n"); - builder.append(arrayToString(mCorrectionUncertainties)); - return builder.toString(); + return "SphericalCorrections{" + + "Corrections=" + Arrays.toString(mCorrections) + + ", CorrectionUncertainties=" + Arrays.toString(mCorrectionUncertainties) + + ", DeltaTheta=" + mDeltaTheta + + ", DeltaPhi=" + mDeltaPhi + + '}'; } } - @VisibleForTesting - public GnssAntennaInfo( + private GnssAntennaInfo( double carrierFrequencyMHz, - @NonNull PhaseCenterOffsetCoordinates phaseCenterOffsetCoordinates, - @Nullable PhaseCenterVariationCorrections phaseCenterVariationCorrections, - @Nullable SignalGainCorrections signalGainCorrectionDbi) { - if (phaseCenterOffsetCoordinates == null) { + @NonNull PhaseCenterOffset phaseCenterOffset, + @Nullable SphericalCorrections phaseCenterVariationCorrections, + @Nullable SphericalCorrections signalGainCorrectionDbi) { + if (phaseCenterOffset == null) { throw new IllegalArgumentException("Phase Center Offset Coordinates cannot be null."); } mCarrierFrequencyMHz = carrierFrequencyMHz; - mPhaseCenterOffsetCoordinates = phaseCenterOffsetCoordinates; + mPhaseCenterOffset = phaseCenterOffset; mPhaseCenterVariationCorrections = phaseCenterVariationCorrections; mSignalGainCorrections = signalGainCorrectionDbi; } + /** + * Builder class for GnssAntennaInfo. + */ + public static class Builder { + private double mCarrierFrequencyMHz; + private PhaseCenterOffset mPhaseCenterOffset; + private SphericalCorrections mPhaseCenterVariationCorrections; + private SphericalCorrections mSignalGainCorrections; + + /** + * Set antenna carrier frequency (MHz). + * @param carrierFrequencyMHz antenna carrier frequency (MHz) + * @return Builder builder object + */ + @NonNull + public Builder setCarrierFrequencyMHz(@FloatRange(from = 0.0f) double carrierFrequencyMHz) { + mCarrierFrequencyMHz = carrierFrequencyMHz; + return this; + } + + /** + * Set antenna phase center offset. + * @param phaseCenterOffset phase center offset object + * @return Builder builder object + */ + @NonNull + public Builder setPhaseCenterOffset(@NonNull PhaseCenterOffset phaseCenterOffset) { + mPhaseCenterOffset = Objects.requireNonNull(phaseCenterOffset); + return this; + } + + /** + * Set phase center variation corrections. + * @param phaseCenterVariationCorrections phase center variation corrections object + * @return Builder builder object + */ + @NonNull + public Builder setPhaseCenterVariationCorrections( + @Nullable SphericalCorrections phaseCenterVariationCorrections) { + mPhaseCenterVariationCorrections = phaseCenterVariationCorrections; + return this; + } + + /** + * Set signal gain corrections. + * @param signalGainCorrections signal gain corrections object + * @return Builder builder object + */ + @NonNull + public Builder setSignalGainCorrections( + @Nullable SphericalCorrections signalGainCorrections) { + mSignalGainCorrections = signalGainCorrections; + return this; + } + + /** + * Build GnssAntennaInfo object. + * @return instance of GnssAntennaInfo + */ + @NonNull + public GnssAntennaInfo build() { + return new GnssAntennaInfo(mCarrierFrequencyMHz, mPhaseCenterOffset, + mPhaseCenterVariationCorrections, mSignalGainCorrections); + } + } + + @FloatRange(from = 0.0f) public double getCarrierFrequencyMHz() { return mCarrierFrequencyMHz; } @NonNull - public PhaseCenterOffsetCoordinates getPhaseCenterOffsetCoordinates() { - return mPhaseCenterOffsetCoordinates; + public PhaseCenterOffset getPhaseCenterOffset() { + return mPhaseCenterOffset; } @Nullable - public PhaseCenterVariationCorrections getPhaseCenterVariationCorrections() { + public SphericalCorrections getPhaseCenterVariationCorrections() { return mPhaseCenterVariationCorrections; } @Nullable - public SignalGainCorrections getSignalGainCorrections() { + public SphericalCorrections getSignalGainCorrections() { return mSignalGainCorrections; } @@ -600,16 +422,18 @@ public final class GnssAntennaInfo implements Parcelable { double carrierFrequencyMHz = in.readDouble(); ClassLoader classLoader = getClass().getClassLoader(); - PhaseCenterOffsetCoordinates phaseCenterOffsetCoordinates = + PhaseCenterOffset phaseCenterOffset = in.readParcelable(classLoader); - PhaseCenterVariationCorrections phaseCenterVariationCorrections = + SphericalCorrections phaseCenterVariationCorrections = in.readParcelable(classLoader); - SignalGainCorrections signalGainCorrections = + SphericalCorrections signalGainCorrections = in.readParcelable(classLoader); - return new GnssAntennaInfo(carrierFrequencyMHz, - phaseCenterOffsetCoordinates, - phaseCenterVariationCorrections, signalGainCorrections); + return new GnssAntennaInfo( + carrierFrequencyMHz, + phaseCenterOffset, + phaseCenterVariationCorrections, + signalGainCorrections); } @Override @@ -626,29 +450,18 @@ public final class GnssAntennaInfo implements Parcelable { @Override public void writeToParcel(@NonNull Parcel parcel, int flags) { parcel.writeDouble(mCarrierFrequencyMHz); - - // Write Phase Center Offset - parcel.writeParcelable(mPhaseCenterOffsetCoordinates, flags); - - // Write Phase Center Variation Corrections + parcel.writeParcelable(mPhaseCenterOffset, flags); parcel.writeParcelable(mPhaseCenterVariationCorrections, flags); - - // Write Signal Gain Corrections parcel.writeParcelable(mSignalGainCorrections, flags); } @Override public String toString() { - StringBuilder builder = new StringBuilder("[ GnssAntennaInfo:\n"); - builder.append("CarrierFrequencyMHz: " + mCarrierFrequencyMHz + "\n"); - builder.append(mPhaseCenterOffsetCoordinates.toString()); - builder.append(mPhaseCenterVariationCorrections == null - ? "PhaseCenterVariationCorrections: null\n" - : mPhaseCenterVariationCorrections.toString()); - builder.append(mSignalGainCorrections == null - ? "SignalGainCorrections: null\n" - : mSignalGainCorrections.toString()); - builder.append("]"); - return builder.toString(); + return "GnssAntennaInfo{" + + "CarrierFrequencyMHz=" + mCarrierFrequencyMHz + + ", PhaseCenterOffset=" + mPhaseCenterOffset + + ", PhaseCenterVariationCorrections=" + mPhaseCenterVariationCorrections + + ", SignalGainCorrections=" + mSignalGainCorrections + + '}'; } } diff --git a/location/java/android/location/GnssCapabilities.java b/location/java/android/location/GnssCapabilities.java index 930180c6870f..5734bf2e9af6 100644 --- a/location/java/android/location/GnssCapabilities.java +++ b/location/java/android/location/GnssCapabilities.java @@ -16,15 +16,11 @@ package android.location; -import android.annotation.NonNull; import android.annotation.SystemApi; /** * A container of supported GNSS chipset capabilities. - * - * @hide */ -@SystemApi public final class GnssCapabilities { /** * Bit mask indicating GNSS chipset supports low power mode. @@ -105,7 +101,10 @@ public final class GnssCapabilities { /** * Returns {@code true} if GNSS chipset supports low power mode, {@code false} otherwise. + * + * @hide */ + @SystemApi public boolean hasLowPowerMode() { return hasCapability(LOW_POWER_MODE); } @@ -113,28 +112,40 @@ public final class GnssCapabilities { /** * Returns {@code true} if GNSS chipset supports blacklisting satellites, {@code false} * otherwise. + * + * @hide */ + @SystemApi public boolean hasSatelliteBlacklist() { return hasCapability(SATELLITE_BLACKLIST); } /** * Returns {@code true} if GNSS chipset supports geofencing, {@code false} otherwise. + * + * @hide */ + @SystemApi public boolean hasGeofencing() { return hasCapability(GEOFENCING); } /** * Returns {@code true} if GNSS chipset supports measurements, {@code false} otherwise. + * + * @hide */ + @SystemApi public boolean hasMeasurements() { return hasCapability(MEASUREMENTS); } /** * Returns {@code true} if GNSS chipset supports navigation messages, {@code false} otherwise. + * + * @hide */ + @SystemApi public boolean hasNavMessages() { return hasCapability(NAV_MESSAGES); } @@ -142,7 +153,10 @@ public final class GnssCapabilities { /** * Returns {@code true} if GNSS chipset supports measurement corrections, {@code false} * otherwise. + * + * @hide */ + @SystemApi public boolean hasMeasurementCorrections() { return hasCapability(MEASUREMENT_CORRECTIONS); } @@ -150,7 +164,10 @@ public final class GnssCapabilities { /** * Returns {@code true} if GNSS chipset supports line-of-sight satellite identification * measurement corrections, {@code false} otherwise. + * + * @hide */ + @SystemApi public boolean hasMeasurementCorrectionsLosSats() { return hasCapability(MEASUREMENT_CORRECTIONS_LOS_SATS); } @@ -158,7 +175,10 @@ public final class GnssCapabilities { /** * Returns {@code true} if GNSS chipset supports per satellite excess-path-length measurement * corrections, {@code false} otherwise. + * + * @hide */ + @SystemApi public boolean hasMeasurementCorrectionsExcessPathLength() { return hasCapability(MEASUREMENT_CORRECTIONS_EXCESS_PATH_LENGTH); } @@ -166,7 +186,10 @@ public final class GnssCapabilities { /** * Returns {@code true} if GNSS chipset supports reflecting planes measurement corrections, * {@code false} otherwise. + * + * @hide */ + @SystemApi public boolean hasMeasurementCorrectionsReflectingPane() { return hasCapability(MEASUREMENT_CORRECTIONS_REFLECTING_PLANE); } @@ -178,28 +201,6 @@ public final class GnssCapabilities { return hasCapability(ANTENNA_INFO); } - @NonNull - @Override - public String toString() { - StringBuilder sb = new StringBuilder("GnssCapabilities: ( "); - if (hasLowPowerMode()) sb.append("LOW_POWER_MODE "); - if (hasSatelliteBlacklist()) sb.append("SATELLITE_BLACKLIST "); - if (hasGeofencing()) sb.append("GEOFENCING "); - if (hasGnssAntennaInfo()) sb.append("ANTENNA_INFO "); - if (hasMeasurements()) sb.append("MEASUREMENTS "); - if (hasNavMessages()) sb.append("NAV_MESSAGES "); - if (hasMeasurementCorrections()) sb.append("MEASUREMENT_CORRECTIONS "); - if (hasMeasurementCorrectionsLosSats()) sb.append("MEASUREMENT_CORRECTIONS_LOS_SATS "); - if (hasMeasurementCorrectionsExcessPathLength()) { - sb.append("MEASUREMENT_CORRECTIONS_EXCESS_PATH_LENGTH "); - } - if (hasMeasurementCorrectionsReflectingPane()) { - sb.append("MEASUREMENT_CORRECTIONS_REFLECTING_PLANE "); - } - sb.append(")"); - return sb.toString(); - } - private boolean hasCapability(long capability) { return (mGnssCapabilities & capability) == capability; } diff --git a/location/java/android/location/IGnssAntennaInfoListener.aidl b/location/java/android/location/IGnssAntennaInfoListener.aidl index 30bf546759f1..603ed6a2614e 100644 --- a/location/java/android/location/IGnssAntennaInfoListener.aidl +++ b/location/java/android/location/IGnssAntennaInfoListener.aidl @@ -23,5 +23,4 @@ import android.location.GnssAntennaInfo; */ oneway interface IGnssAntennaInfoListener { void onGnssAntennaInfoReceived(in List<GnssAntennaInfo> gnssAntennaInfo); - void onStatusChanged(in int status); }
\ No newline at end of file diff --git a/location/java/android/location/LocationManager.java b/location/java/android/location/LocationManager.java index 3d0765bb0855..8b871412e8a9 100644 --- a/location/java/android/location/LocationManager.java +++ b/location/java/android/location/LocationManager.java @@ -1812,13 +1812,7 @@ public class LocationManager { /** * Returns the supported capabilities of the GNSS chipset. - * - * @throws SecurityException if the ACCESS_FINE_LOCATION permission is not present. - * - * @hide */ - @SystemApi - @RequiresPermission(ACCESS_FINE_LOCATION) public @NonNull GnssCapabilities getGnssCapabilities() { try { long gnssCapabilities = mService.getGnssCapabilities(mContext.getPackageName()); @@ -2263,35 +2257,36 @@ public class LocationManager { } /** - * Registers a Gnss Antenna Info callback. + * Registers a Gnss Antenna Info listener. Only expect results if + * {@link GnssCapabilities#hasGnssAntennaInfo()} shows that antenna info is supported. * - * @param executor the executor that the callback runs on. - * @param callback a {@link GnssAntennaInfo.Callback} object to register. - * @return {@code true} if the callback was added successfully, {@code false} otherwise. + * @param executor the executor that the listener runs on. + * @param listener a {@link GnssAntennaInfo.Listener} object to register. + * @return {@code true} if the listener was added successfully, {@code false} otherwise. * * @throws IllegalArgumentException if executor is null - * @throws IllegalArgumentException if callback is null + * @throws IllegalArgumentException if listener is null * @throws SecurityException if the ACCESS_FINE_LOCATION permission is not present */ @RequiresPermission(ACCESS_FINE_LOCATION) - public boolean registerAntennaInfoCallback( + public boolean registerAntennaInfoListener( @NonNull @CallbackExecutor Executor executor, - @NonNull GnssAntennaInfo.Callback callback) { + @NonNull GnssAntennaInfo.Listener listener) { try { - return mGnssAntennaInfoListenerManager.addListener(callback, executor); + return mGnssAntennaInfoListenerManager.addListener(listener, executor); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } } /** - * Unregisters a GNSS Antenna Info callback. + * Unregisters a GNSS Antenna Info listener. * - * @param callback a {@link GnssAntennaInfo.Callback} object to remove. + * @param listener a {@link GnssAntennaInfo.Listener} object to remove. */ - public void unregisterAntennaInfoCallback(@NonNull GnssAntennaInfo.Callback callback) { + public void unregisterAntennaInfoListener(@NonNull GnssAntennaInfo.Listener listener) { try { - mGnssAntennaInfoListenerManager.removeListener(callback); + mGnssAntennaInfoListenerManager.removeListener(listener); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } @@ -3027,7 +3022,7 @@ public class LocationManager { } private class GnssAntennaInfoListenerManager extends - AbstractListenerManager<Void, GnssAntennaInfo.Callback> { + AbstractListenerManager<Void, GnssAntennaInfo.Listener> { @Nullable private IGnssAntennaInfoListener mListenerTransport; @@ -3059,11 +3054,6 @@ public class LocationManager { public void onGnssAntennaInfoReceived(final List<GnssAntennaInfo> gnssAntennaInfos) { execute((callback) -> callback.onGnssAntennaInfoReceived(gnssAntennaInfos)); } - - @Override - public void onStatusChanged(int status) { - execute((listener) -> listener.onStatusChanged(status)); - } } } diff --git a/services/core/java/com/android/server/location/GnssAntennaInfoProvider.java b/services/core/java/com/android/server/location/GnssAntennaInfoProvider.java index 09af655e1735..bc50ebc2c5c3 100644 --- a/services/core/java/com/android/server/location/GnssAntennaInfoProvider.java +++ b/services/core/java/com/android/server/location/GnssAntennaInfoProvider.java @@ -20,7 +20,6 @@ import android.content.Context; import android.location.GnssAntennaInfo; import android.location.IGnssAntennaInfoListener; import android.os.Handler; -import android.os.RemoteException; import android.util.Log; import com.android.internal.annotations.VisibleForTesting; @@ -100,41 +99,10 @@ public abstract class GnssAntennaInfoProvider @Override protected ListenerOperation<IGnssAntennaInfoListener> getHandlerOperation(int result) { - int status; - switch (result) { - case RESULT_SUCCESS: - status = GnssAntennaInfo.Callback.STATUS_READY; - break; - case RESULT_NOT_AVAILABLE: - case RESULT_NOT_SUPPORTED: - case RESULT_INTERNAL_ERROR: - status = GnssAntennaInfo.Callback.STATUS_NOT_SUPPORTED; - break; - case RESULT_GPS_LOCATION_DISABLED: - status = GnssAntennaInfo.Callback.STATUS_LOCATION_DISABLED; - break; - case RESULT_UNKNOWN: - return null; - default: - Log.v(TAG, "Unhandled addListener result: " + result); - return null; - } - return new StatusChangedOperation(status); - } - - private static class StatusChangedOperation - implements ListenerOperation<IGnssAntennaInfoListener> { - private final int mStatus; - - StatusChangedOperation(int status) { - mStatus = status; - } - - @Override - public void execute(IGnssAntennaInfoListener listener, - CallerIdentity callerIdentity) throws RemoteException { - listener.onStatusChanged(mStatus); - } + return (IGnssAntennaInfoListener listener, + CallerIdentity callerIdentity) -> { + // Do nothing, as GnssAntennaInfo.Callback does not have an onStatusChanged method. + }; } /** Handle Gnss Antenna Info report. */ diff --git a/services/core/java/com/android/server/location/GnssLocationProvider.java b/services/core/java/com/android/server/location/GnssLocationProvider.java index 36136f49dc42..5f44e042b5e9 100644 --- a/services/core/java/com/android/server/location/GnssLocationProvider.java +++ b/services/core/java/com/android/server/location/GnssLocationProvider.java @@ -2244,6 +2244,7 @@ public class GnssLocationProvider extends AbstractLocationProvider implements if (hasCapability(GPS_CAPABILITY_MEASUREMENT_CORRECTIONS)) { s.append("MEASUREMENT_CORRECTIONS "); } + if (hasCapability(GPS_CAPABILITY_ANTENNA_INFO)) s.append("ANTENNA_INFO "); s.append(")\n"); if (hasCapability(GPS_CAPABILITY_MEASUREMENT_CORRECTIONS)) { s.append("SubHal=MEASUREMENT_CORRECTIONS["); diff --git a/services/core/java/com/android/server/location/gnss/GnssManagerService.java b/services/core/java/com/android/server/location/gnss/GnssManagerService.java index 1039cf6694cc..b57c261931f8 100644 --- a/services/core/java/com/android/server/location/gnss/GnssManagerService.java +++ b/services/core/java/com/android/server/location/gnss/GnssManagerService.java @@ -216,9 +216,6 @@ public class GnssManagerService { * {@link android.location.GnssCapabilities}. */ public long getGnssCapabilities(String packageName) { - mContext.enforceCallingPermission(Manifest.permission.LOCATION_HARDWARE, null); - mContext.enforceCallingPermission(Manifest.permission.ACCESS_FINE_LOCATION, null); - if (!checkLocationAppOp(packageName)) { return GnssCapabilities.INVALID_CAPABILITIES; } diff --git a/services/core/jni/com_android_server_location_GnssLocationProvider.cpp b/services/core/jni/com_android_server_location_GnssLocationProvider.cpp index d0eaa48022e9..0ee083ad89e9 100644 --- a/services/core/jni/com_android_server_location_GnssLocationProvider.cpp +++ b/services/core/jni/com_android_server_location_GnssLocationProvider.cpp @@ -55,10 +55,9 @@ static jclass class_location; static jclass class_gnssNavigationMessage; static jclass class_gnssClock; static jclass class_gnssConfiguration_halInterfaceVersion; -static jclass class_gnssAntennaInfo; -static jclass class_phaseCenterOffsetCoordinates; -static jclass class_phaseCenterVariationCorrections; -static jclass class_signalGainCorrections; +static jclass class_gnssAntennaInfoBuilder; +static jclass class_phaseCenterOffset; +static jclass class_sphericalCorrections; static jclass class_arrayList; static jclass class_doubleArray; @@ -122,12 +121,16 @@ static jmethodID method_gnssNavigationMessageCtor; static jmethodID method_gnssClockCtor; static jmethodID method_gnssMeasurementCtor; static jmethodID method_halInterfaceVersionCtor; -static jmethodID method_gnssAntennaInfoCtor; -static jmethodID method_phaseCenterOffsetCoordinatesCtor; -static jmethodID method_phaseCenterVariationCorrectionsCtor; -static jmethodID method_signalGainCorrectionsCtor; +static jmethodID method_gnssAntennaInfoBuilderCtor; +static jmethodID method_phaseCenterOffsetCtor; +static jmethodID method_sphericalCorrectionsCtor; static jmethodID method_arrayListCtor; static jmethodID method_arrayListAdd; +static jmethodID method_gnssAntennaInfoBuilderSetCarrierFrequencyMHz; +static jmethodID method_gnssAntennaInfoBuilderSetPhaseCenterOffset; +static jmethodID method_gnssAntennaInfoBuilderSetPhaseCenterVariationCorrections; +static jmethodID method_gnssAntennaInfoBuilderSetSignalGainCorrections; +static jmethodID method_gnssAntennaInfoBuilderBuild; /* * Save a pointer to JavaVm to attach/detach threads executing @@ -1082,7 +1085,7 @@ private: const hidl_vec<IGnssAntennaInfoCallback::GnssAntennaInfo>& gnssAntennaInfos); jobject translateSingleGnssAntennaInfo( JNIEnv* env, const IGnssAntennaInfoCallback::GnssAntennaInfo& gnssAntennaInfo); - jobject translatePhaseCenterOffsetCoordinates( + jobject translatePhaseCenterOffset( JNIEnv* env, const IGnssAntennaInfoCallback::GnssAntennaInfo& gnssAntennaInfo); jobject translatePhaseCenterVariationCorrections( JNIEnv* env, const IGnssAntennaInfoCallback::GnssAntennaInfo& gnssAntennaInfo); @@ -1144,11 +1147,10 @@ jobject GnssAntennaInfoCallback::translateAllGnssAntennaInfos( return arrayList; } -jobject GnssAntennaInfoCallback::translatePhaseCenterOffsetCoordinates( +jobject GnssAntennaInfoCallback::translatePhaseCenterOffset( JNIEnv* env, const IGnssAntennaInfoCallback::GnssAntennaInfo& gnssAntennaInfo) { - jobject phaseCenterOffsetCoordinates = - env->NewObject(class_phaseCenterOffsetCoordinates, - method_phaseCenterOffsetCoordinatesCtor, + jobject phaseCenterOffset = + env->NewObject(class_phaseCenterOffset, method_phaseCenterOffsetCtor, gnssAntennaInfo.phaseCenterOffsetCoordinateMillimeters.x, gnssAntennaInfo.phaseCenterOffsetCoordinateMillimeters.xUncertainty, gnssAntennaInfo.phaseCenterOffsetCoordinateMillimeters.y, @@ -1156,7 +1158,7 @@ jobject GnssAntennaInfoCallback::translatePhaseCenterOffsetCoordinates( gnssAntennaInfo.phaseCenterOffsetCoordinateMillimeters.z, gnssAntennaInfo.phaseCenterOffsetCoordinateMillimeters.zUncertainty); - return phaseCenterOffsetCoordinates; + return phaseCenterOffset; } jobject GnssAntennaInfoCallback::translatePhaseCenterVariationCorrections( @@ -1179,8 +1181,7 @@ jobject GnssAntennaInfoCallback::translatePhaseCenterVariationCorrections( } jobject phaseCenterVariationCorrections = - env->NewObject(class_phaseCenterVariationCorrections, - method_phaseCenterVariationCorrectionsCtor, + env->NewObject(class_sphericalCorrections, method_sphericalCorrectionsCtor, phaseCenterVariationCorrectionsArray, phaseCenterVariationCorrectionsUncertaintiesArray); @@ -1206,7 +1207,7 @@ jobject GnssAntennaInfoCallback::translateSignalGainCorrections( } jobject signalGainCorrections = - env->NewObject(class_signalGainCorrections, method_signalGainCorrectionsCtor, + env->NewObject(class_sphericalCorrections, method_sphericalCorrectionsCtor, signalGainCorrectionsArray, signalGainCorrectionsUncertaintiesArray); env->DeleteLocalRef(signalGainCorrectionsArray); @@ -1217,8 +1218,7 @@ jobject GnssAntennaInfoCallback::translateSignalGainCorrections( jobject GnssAntennaInfoCallback::translateSingleGnssAntennaInfo( JNIEnv* env, const IGnssAntennaInfoCallback::GnssAntennaInfo& gnssAntennaInfo) { - jobject phaseCenterOffsetCoordinates = - translatePhaseCenterOffsetCoordinates(env, gnssAntennaInfo); + jobject phaseCenterOffset = translatePhaseCenterOffset(env, gnssAntennaInfo); // Nullable jobject phaseCenterVariationCorrections = @@ -1227,13 +1227,29 @@ jobject GnssAntennaInfoCallback::translateSingleGnssAntennaInfo( // Nullable jobject signalGainCorrections = translateSignalGainCorrections(env, gnssAntennaInfo); + // Get builder + jobject gnssAntennaInfoBuilderObject = + env->NewObject(class_gnssAntennaInfoBuilder, method_gnssAntennaInfoBuilderCtor); + + // Set fields + env->CallObjectMethod(gnssAntennaInfoBuilderObject, + method_gnssAntennaInfoBuilderSetCarrierFrequencyMHz, + gnssAntennaInfo.carrierFrequencyMHz); + env->CallObjectMethod(gnssAntennaInfoBuilderObject, + method_gnssAntennaInfoBuilderSetPhaseCenterOffset, phaseCenterOffset); + env->CallObjectMethod(gnssAntennaInfoBuilderObject, + method_gnssAntennaInfoBuilderSetPhaseCenterVariationCorrections, + phaseCenterVariationCorrections); + env->CallObjectMethod(gnssAntennaInfoBuilderObject, + method_gnssAntennaInfoBuilderSetSignalGainCorrections, + signalGainCorrections); + + // build jobject gnssAntennaInfoObject = - env->NewObject(class_gnssAntennaInfo, method_gnssAntennaInfoCtor, - gnssAntennaInfo.carrierFrequencyMHz, phaseCenterOffsetCoordinates, - phaseCenterVariationCorrections, signalGainCorrections); + env->CallObjectMethod(gnssAntennaInfoBuilderObject, method_gnssAntennaInfoBuilderBuild); // Delete Local Refs - env->DeleteLocalRef(phaseCenterOffsetCoordinates); + env->DeleteLocalRef(phaseCenterOffset); env->DeleteLocalRef(phaseCenterVariationCorrections); env->DeleteLocalRef(signalGainCorrections); @@ -1998,35 +2014,38 @@ static void android_location_GnssLocationProvider_class_init_native(JNIEnv* env, class_gnssMeasurement = (jclass) env->NewGlobalRef(gnssMeasurementClass); method_gnssMeasurementCtor = env->GetMethodID(class_gnssMeasurement, "<init>", "()V"); - jclass gnssAntennaInfoClass = env->FindClass("android/location/GnssAntennaInfo"); - class_gnssAntennaInfo = (jclass)env->NewGlobalRef(gnssAntennaInfoClass); - method_gnssAntennaInfoCtor = - env->GetMethodID(class_gnssAntennaInfo, "<init>", - "(D" - "Landroid/location/GnssAntennaInfo$PhaseCenterOffsetCoordinates;" - "Landroid/location/GnssAntennaInfo$PhaseCenterVariationCorrections;" - "Landroid/location/GnssAntennaInfo$SignalGainCorrections;" - ")V"); - - jclass phaseCenterOffsetCoordinatesClass = - env->FindClass("android/location/GnssAntennaInfo$PhaseCenterOffsetCoordinates"); - class_phaseCenterOffsetCoordinates = - (jclass)env->NewGlobalRef(phaseCenterOffsetCoordinatesClass); - method_phaseCenterOffsetCoordinatesCtor = - env->GetMethodID(class_phaseCenterOffsetCoordinates, "<init>", "(DDDDDD)V"); - - jclass phaseCenterVariationCorrectionsClass = - env->FindClass("android/location/GnssAntennaInfo$PhaseCenterVariationCorrections"); - class_phaseCenterVariationCorrections = - (jclass)env->NewGlobalRef(phaseCenterVariationCorrectionsClass); - method_phaseCenterVariationCorrectionsCtor = - env->GetMethodID(class_phaseCenterVariationCorrections, "<init>", "([[D[[D)V"); - - jclass signalGainCorrectionsClass = - env->FindClass("android/location/GnssAntennaInfo$SignalGainCorrections"); - class_signalGainCorrections = (jclass)env->NewGlobalRef(signalGainCorrectionsClass); - method_signalGainCorrectionsCtor = - env->GetMethodID(class_signalGainCorrections, "<init>", "([[D[[D)V"); + jclass gnssAntennaInfoBuilder = env->FindClass("android/location/GnssAntennaInfo$Builder"); + class_gnssAntennaInfoBuilder = (jclass)env->NewGlobalRef(gnssAntennaInfoBuilder); + method_gnssAntennaInfoBuilderCtor = + env->GetMethodID(class_gnssAntennaInfoBuilder, "<init>", "()V"); + method_gnssAntennaInfoBuilderSetCarrierFrequencyMHz = + env->GetMethodID(class_gnssAntennaInfoBuilder, "setCarrierFrequencyMHz", + "(D)Landroid/location/GnssAntennaInfo$Builder;"); + method_gnssAntennaInfoBuilderSetPhaseCenterOffset = + env->GetMethodID(class_gnssAntennaInfoBuilder, "setPhaseCenterOffset", + "(Landroid/location/GnssAntennaInfo$PhaseCenterOffset;)" + "Landroid/location/GnssAntennaInfo$Builder;"); + method_gnssAntennaInfoBuilderSetPhaseCenterVariationCorrections = + env->GetMethodID(class_gnssAntennaInfoBuilder, "setPhaseCenterVariationCorrections", + "(Landroid/location/GnssAntennaInfo$SphericalCorrections;)" + "Landroid/location/GnssAntennaInfo$Builder;"); + method_gnssAntennaInfoBuilderSetSignalGainCorrections = + env->GetMethodID(class_gnssAntennaInfoBuilder, "setSignalGainCorrections", + "(Landroid/location/GnssAntennaInfo$SphericalCorrections;)" + "Landroid/location/GnssAntennaInfo$Builder;"); + method_gnssAntennaInfoBuilderBuild = env->GetMethodID(class_gnssAntennaInfoBuilder, "build", + "()Landroid/location/GnssAntennaInfo;"); + + jclass phaseCenterOffsetClass = + env->FindClass("android/location/GnssAntennaInfo$PhaseCenterOffset"); + class_phaseCenterOffset = (jclass)env->NewGlobalRef(phaseCenterOffsetClass); + method_phaseCenterOffsetCtor = env->GetMethodID(class_phaseCenterOffset, "<init>", "(DDDDDD)V"); + + jclass sphericalCorrectionsClass = + env->FindClass("android/location/GnssAntennaInfo$SphericalCorrections"); + class_sphericalCorrections = (jclass)env->NewGlobalRef(sphericalCorrectionsClass); + method_sphericalCorrectionsCtor = + env->GetMethodID(class_sphericalCorrections, "<init>", "([[D[[D)V"); jclass locationClass = env->FindClass("android/location/Location"); class_location = (jclass) env->NewGlobalRef(locationClass); diff --git a/services/tests/servicestests/src/com/android/server/location/gnss/GnssManagerServiceTest.java b/services/tests/servicestests/src/com/android/server/location/gnss/GnssManagerServiceTest.java index 4d0ad96ac223..a814b022b4a8 100644 --- a/services/tests/servicestests/src/com/android/server/location/gnss/GnssManagerServiceTest.java +++ b/services/tests/servicestests/src/com/android/server/location/gnss/GnssManagerServiceTest.java @@ -36,6 +36,7 @@ import android.app.AppOpsManager; import android.content.Context; import android.content.pm.PackageManager; import android.location.GnssAntennaInfo; +import android.location.GnssAntennaInfo.SphericalCorrections; import android.location.GnssClock; import android.location.GnssMeasurementCorrections; import android.location.GnssMeasurementsEvent; @@ -243,8 +244,8 @@ public class GnssManagerServiceTest { private static List<GnssAntennaInfo> createDummyGnssAntennaInfos() { double carrierFrequencyMHz = 13758.0; - GnssAntennaInfo.PhaseCenterOffsetCoordinates phaseCenterOffsetCoordinates = new - GnssAntennaInfo.PhaseCenterOffsetCoordinates( + GnssAntennaInfo.PhaseCenterOffset phaseCenterOffset = new + GnssAntennaInfo.PhaseCenterOffset( 4.3d, 1.4d, 2.10d, @@ -254,22 +255,26 @@ public class GnssManagerServiceTest { double[][] phaseCenterVariationCorrectionsMillimeters = new double[10][10]; double[][] phaseCenterVariationCorrectionsUncertaintyMillimeters = new double[10][10]; - GnssAntennaInfo.PhaseCenterVariationCorrections + SphericalCorrections phaseCenterVariationCorrections = - new GnssAntennaInfo.PhaseCenterVariationCorrections( + new SphericalCorrections( phaseCenterVariationCorrectionsMillimeters, phaseCenterVariationCorrectionsUncertaintyMillimeters); double[][] signalGainCorrectionsDbi = new double[10][10]; double[][] signalGainCorrectionsUncertaintyDbi = new double[10][10]; - GnssAntennaInfo.SignalGainCorrections signalGainCorrections = new - GnssAntennaInfo.SignalGainCorrections( + SphericalCorrections signalGainCorrections = new + SphericalCorrections( signalGainCorrectionsDbi, signalGainCorrectionsUncertaintyDbi); List<GnssAntennaInfo> gnssAntennaInfos = new ArrayList(); - gnssAntennaInfos.add(new GnssAntennaInfo(carrierFrequencyMHz, phaseCenterOffsetCoordinates, - phaseCenterVariationCorrections, signalGainCorrections)); + gnssAntennaInfos.add(new GnssAntennaInfo.Builder() + .setCarrierFrequencyMHz(carrierFrequencyMHz) + .setPhaseCenterOffset(phaseCenterOffset) + .setPhaseCenterVariationCorrections(phaseCenterVariationCorrections) + .setSignalGainCorrections(signalGainCorrections) + .build()); return gnssAntennaInfos; } @@ -380,14 +385,6 @@ public class GnssManagerServiceTest { } @Test - public void getGnssCapabilitiesWithoutPermissionsTest() { - disableLocationPermissions(); - - assertThrows(SecurityException.class, - () -> mGnssManagerService.getGnssCapabilities("com.android.server")); - } - - @Test public void getGnssCapabilitiesWithPermissionsTest() { final long mGnssCapabilities = 23132L; when(mMockGnssCapabilitiesProvider.getGnssCapabilities()).thenReturn(mGnssCapabilities); |