diff options
| -rw-r--r-- | api/current.txt | 32 | ||||
| -rw-r--r-- | location/java/android/location/GnssStatus.java | 277 | ||||
| -rw-r--r-- | location/java/android/location/GpsStatus.java | 116 | ||||
| -rw-r--r-- | location/java/android/location/LocationManager.java | 15 | ||||
| -rw-r--r-- | location/java/com/android/internal/location/gnssmetrics/GnssMetrics.java | 19 | ||||
| -rw-r--r-- | services/core/java/com/android/server/location/GnssLocationProvider.java | 50 |
6 files changed, 306 insertions, 203 deletions
diff --git a/api/current.txt b/api/current.txt index 5d2a1bd9b05b..71809feb6349 100644 --- a/api/current.txt +++ b/api/current.txt @@ -23039,17 +23039,17 @@ package android.location { } public final class GnssStatus { - method public float getAzimuthDegrees(int); - method public float getCarrierFrequencyHz(int); - method public float getCn0DbHz(int); - method public int getConstellationType(int); - method public float getElevationDegrees(int); - method public int getSatelliteCount(); - method public int getSvid(int); - method public boolean hasAlmanacData(int); - method public boolean hasCarrierFrequencyHz(int); - method public boolean hasEphemerisData(int); - method public boolean usedInFix(int); + method @FloatRange(from=0, to=360) public float getAzimuthDegrees(@IntRange(from=0) int); + method @FloatRange(from=0) public float getCarrierFrequencyHz(@IntRange(from=0) int); + method @FloatRange(from=0, to=63) public float getCn0DbHz(@IntRange(from=0) int); + method public int getConstellationType(@IntRange(from=0) int); + method @FloatRange(from=0xffffffa6, to=90) public float getElevationDegrees(@IntRange(from=0) int); + method @IntRange(from=0) public int getSatelliteCount(); + method @IntRange(from=1, to=200) public int getSvid(@IntRange(from=0) int); + method public boolean hasAlmanacData(@IntRange(from=0) int); + method public boolean hasCarrierFrequencyHz(@IntRange(from=0) int); + method public boolean hasEphemerisData(@IntRange(from=0) int); + method public boolean usedInFix(@IntRange(from=0) int); field public static final int CONSTELLATION_BEIDOU = 5; // 0x5 field public static final int CONSTELLATION_GALILEO = 6; // 0x6 field public static final int CONSTELLATION_GLONASS = 3; // 0x3 @@ -23060,10 +23060,17 @@ package android.location { field public static final int CONSTELLATION_UNKNOWN = 0; // 0x0 } + public static final class GnssStatus.Builder { + ctor public GnssStatus.Builder(); + method @NonNull public android.location.GnssStatus.Builder addSatellite(int, @IntRange(from=1, to=200) int, @FloatRange(from=0, to=63) float, @FloatRange(from=0xffffffa6, to=90) float, @FloatRange(from=0, to=360) float, boolean, boolean, boolean, boolean, @FloatRange(from=0) float); + method @NonNull public android.location.GnssStatus build(); + method @NonNull public android.location.GnssStatus.Builder clearSatellites(); + } + public abstract static class GnssStatus.Callback { ctor public GnssStatus.Callback(); method public void onFirstFix(int); - method public void onSatelliteStatusChanged(android.location.GnssStatus); + method public void onSatelliteStatusChanged(@NonNull android.location.GnssStatus); method public void onStarted(); method public void onStopped(); } @@ -23079,6 +23086,7 @@ package android.location { } @Deprecated public final class GpsStatus { + method @Deprecated @NonNull public static android.location.GpsStatus create(@NonNull android.location.GnssStatus, int); method @Deprecated public int getMaxSatellites(); method @Deprecated public Iterable<android.location.GpsSatellite> getSatellites(); method @Deprecated public int getTimeToFirstFix(); diff --git a/location/java/android/location/GnssStatus.java b/location/java/android/location/GnssStatus.java index b363686c2df5..2f1eeda9c4cf 100644 --- a/location/java/android/location/GnssStatus.java +++ b/location/java/android/location/GnssStatus.java @@ -16,15 +16,21 @@ package android.location; +import android.annotation.FloatRange; import android.annotation.IntDef; +import android.annotation.IntRange; import android.annotation.NonNull; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; +import java.util.ArrayList; /** - * This class represents the current state of the GNSS engine. - * This class is used in conjunction with the {@link GnssStatus.Callback}. + * This class represents the current state of the GNSS engine and is used in conjunction with + * {@link GnssStatus.Callback}. + * + * @see LocationManager#registerGnssStatusCallback + * @see GnssStatus.Callback */ public final class GnssStatus { @@ -52,75 +58,88 @@ public final class GnssStatus { /** @hide */ public static final int CONSTELLATION_COUNT = 8; - /** @hide */ - public static final int GNSS_SV_FLAGS_NONE = 0; - /** @hide */ - public static final int GNSS_SV_FLAGS_HAS_EPHEMERIS_DATA = (1 << 0); - /** @hide */ - public static final int GNSS_SV_FLAGS_HAS_ALMANAC_DATA = (1 << 1); - /** @hide */ - public static final int GNSS_SV_FLAGS_USED_IN_FIX = (1 << 2); - /** @hide */ - public static final int GNSS_SV_FLAGS_HAS_CARRIER_FREQUENCY = (1 << 3); + private static final int SVID_FLAGS_NONE = 0; + private static final int SVID_FLAGS_HAS_EPHEMERIS_DATA = (1 << 0); + private static final int SVID_FLAGS_HAS_ALMANAC_DATA = (1 << 1); + private static final int SVID_FLAGS_USED_IN_FIX = (1 << 2); + private static final int SVID_FLAGS_HAS_CARRIER_FREQUENCY = (1 << 3); - /** @hide */ - public static final int SVID_SHIFT_WIDTH = 8; - /** @hide */ - public static final int CONSTELLATION_TYPE_SHIFT_WIDTH = 4; - /** @hide */ - public static final int CONSTELLATION_TYPE_MASK = 0xf; + private static final int SVID_SHIFT_WIDTH = 8; + private static final int CONSTELLATION_TYPE_SHIFT_WIDTH = 4; + private static final int CONSTELLATION_TYPE_MASK = 0xf; /** * Used for receiving notifications when GNSS events happen. + * + * @see LocationManager#registerGnssStatusCallback */ public static abstract class Callback { /** * Called when GNSS system has started. */ - public void onStarted() {} + public void onStarted() { + } /** * Called when GNSS system has stopped. */ - public void onStopped() {} + public void onStopped() { + } /** * Called when the GNSS system has received its first fix since starting. + * * @param ttffMillis the time from start to first fix in milliseconds. */ - public void onFirstFix(int ttffMillis) {} + public void onFirstFix(int ttffMillis) { + } /** * Called periodically to report GNSS satellite status. + * * @param status the current status of all satellites. */ - public void onSatelliteStatusChanged(GnssStatus status) {} + public void onSatelliteStatusChanged(@NonNull GnssStatus status) { + } } /** * Constellation type. + * * @hide */ @Retention(RetentionPolicy.SOURCE) @IntDef({CONSTELLATION_UNKNOWN, CONSTELLATION_GPS, CONSTELLATION_SBAS, CONSTELLATION_GLONASS, CONSTELLATION_QZSS, CONSTELLATION_BEIDOU, CONSTELLATION_GALILEO, CONSTELLATION_IRNSS}) - public @interface ConstellationType {} - - final int[] mSvidWithFlags; - final float[] mCn0DbHz; - final float[] mElevations; - final float[] mAzimuths; - final int mSvCount; - final float[] mCarrierFrequencies; + public @interface ConstellationType { + } /** + * Create a GnssStatus that wraps the given arguments without any additional overhead. Callers + * are responsible for guaranteeing that the arguments are never modified after calling this + * method. + * * @hide */ - public GnssStatus(int svCount, int[] svidWithFlags, float[] cn0s, float[] elevations, + @NonNull + public static GnssStatus wrap(int svCount, int[] svidWithFlags, float[] cn0DbHzs, + float[] elevations, float[] azimuths, float[] carrierFrequencies) { + return new GnssStatus(svCount, svidWithFlags, cn0DbHzs, elevations, azimuths, + carrierFrequencies); + } + + private final int mSvCount; + private final int[] mSvidWithFlags; + private final float[] mCn0DbHzs; + private final float[] mElevations; + private final float[] mAzimuths; + private final float[] mCarrierFrequencies; + + private GnssStatus(int svCount, int[] svidWithFlags, float[] cn0DbHzs, float[] elevations, float[] azimuths, float[] carrierFrequencies) { mSvCount = svCount; mSvidWithFlags = svidWithFlags; - mCn0DbHz = cn0s; + mCn0DbHzs = cn0DbHzs; mElevations = elevations; mAzimuths = azimuths; mCarrierFrequencies = carrierFrequencies; @@ -129,6 +148,7 @@ public final class GnssStatus { /** * Gets the total number of satellites in satellite list. */ + @IntRange(from = 0) public int getSatelliteCount() { return mSvCount; } @@ -136,11 +156,11 @@ public final class GnssStatus { /** * Retrieves the constellation type of the satellite at the specified index. * - * @param satIndex the index of the satellite in the list. + * @param satelliteIndex An index from zero to {@link #getSatelliteCount()} - 1 */ @ConstellationType - public int getConstellationType(int satIndex) { - return ((mSvidWithFlags[satIndex] >> CONSTELLATION_TYPE_SHIFT_WIDTH) + public int getConstellationType(@IntRange(from = 0) int satelliteIndex) { + return ((mSvidWithFlags[satelliteIndex] >> CONSTELLATION_TYPE_SHIFT_WIDTH) & CONSTELLATION_TYPE_MASK); } @@ -158,110 +178,113 @@ public final class GnssStatus { * <li>SBAS: 120-151, 183-192</li> * <li>GLONASS: One of: OSN, or FCN+100 * <ul> - * <li>1-24 as the orbital slot number (OSN) (preferred, if known)</li> - * <li>93-106 as the frequency channel number (FCN) (-7 to +6) plus 100. - * i.e. encode FCN of -7 as 93, 0 as 100, and +6 as 106</li> + * <li>1-24 as the orbital slot number (OSN) (preferred, if known)</li> + * <li>93-106 as the frequency channel number (FCN) (-7 to +6) plus 100. + * i.e. encode FCN of -7 as 93, 0 as 100, and +6 as 106</li> * </ul></li> * <li>QZSS: 193-200</li> * <li>Galileo: 1-36</li> * <li>Beidou: 1-37</li> * </ul> * - * @param satIndex the index of the satellite in the list. + * @param satelliteIndex An index from zero to {@link #getSatelliteCount()} - 1 */ - public int getSvid(int satIndex) { - return mSvidWithFlags[satIndex] >> SVID_SHIFT_WIDTH; + @IntRange(from = 1, to = 200) + public int getSvid(@IntRange(from = 0) int satelliteIndex) { + return mSvidWithFlags[satelliteIndex] >> SVID_SHIFT_WIDTH; } /** * Retrieves the carrier-to-noise density at the antenna of the satellite at the specified index * in dB-Hz. * - * @param satIndex the index of the satellite in the list. + * @param satelliteIndex An index from zero to {@link #getSatelliteCount()} - 1 */ - public float getCn0DbHz(int satIndex) { - return mCn0DbHz[satIndex]; + @FloatRange(from = 0, to = 63) + public float getCn0DbHz(@IntRange(from = 0) int satelliteIndex) { + return mCn0DbHzs[satelliteIndex]; } /** * Retrieves the elevation of the satellite at the specified index. * - * @param satIndex the index of the satellite in the list. + * @param satelliteIndex An index from zero to {@link #getSatelliteCount()} - 1 */ - public float getElevationDegrees(int satIndex) { - return mElevations[satIndex]; + @FloatRange(from = -90, to = 90) + public float getElevationDegrees(@IntRange(from = 0) int satelliteIndex) { + return mElevations[satelliteIndex]; } /** * Retrieves the azimuth the satellite at the specified index. * - * @param satIndex the index of the satellite in the list. + * @param satelliteIndex An index from zero to {@link #getSatelliteCount()} - 1 */ - public float getAzimuthDegrees(int satIndex) { - return mAzimuths[satIndex]; + @FloatRange(from = 0, to = 360) + public float getAzimuthDegrees(@IntRange(from = 0) int satelliteIndex) { + return mAzimuths[satelliteIndex]; } /** * Reports whether the satellite at the specified index has ephemeris data. * - * @param satIndex the index of the satellite in the list. + * @param satelliteIndex An index from zero to {@link #getSatelliteCount()} - 1 */ - public boolean hasEphemerisData(int satIndex) { - return (mSvidWithFlags[satIndex] & GNSS_SV_FLAGS_HAS_EPHEMERIS_DATA) != 0; + public boolean hasEphemerisData(@IntRange(from = 0) int satelliteIndex) { + return (mSvidWithFlags[satelliteIndex] & SVID_FLAGS_HAS_EPHEMERIS_DATA) != 0; } /** * Reports whether the satellite at the specified index has almanac data. * - * @param satIndex the index of the satellite in the list. + * @param satelliteIndex An index from zero to {@link #getSatelliteCount()} - 1 */ - public boolean hasAlmanacData(int satIndex) { - return (mSvidWithFlags[satIndex] & GNSS_SV_FLAGS_HAS_ALMANAC_DATA) != 0; + public boolean hasAlmanacData(@IntRange(from = 0) int satelliteIndex) { + return (mSvidWithFlags[satelliteIndex] & SVID_FLAGS_HAS_ALMANAC_DATA) != 0; } /** * Reports whether the satellite at the specified index was used in the calculation of the most * recent position fix. * - * @param satIndex the index of the satellite in the list. + * @param satelliteIndex An index from zero to {@link #getSatelliteCount()} - 1 */ - public boolean usedInFix(int satIndex) { - return (mSvidWithFlags[satIndex] & GNSS_SV_FLAGS_USED_IN_FIX) != 0; + public boolean usedInFix(@IntRange(from = 0) int satelliteIndex) { + return (mSvidWithFlags[satelliteIndex] & SVID_FLAGS_USED_IN_FIX) != 0; } /** - * Reports whether a valid {@link #getCarrierFrequencyHz(int satIndex)} is available. + * Reports whether a valid {@link #getCarrierFrequencyHz(int satelliteIndex)} is available. * - * @param satIndex the index of the satellite in the list. + * @param satelliteIndex An index from zero to {@link #getSatelliteCount()} - 1 */ - public boolean hasCarrierFrequencyHz(int satIndex) { - return (mSvidWithFlags[satIndex] & GNSS_SV_FLAGS_HAS_CARRIER_FREQUENCY) != 0; + public boolean hasCarrierFrequencyHz(@IntRange(from = 0) int satelliteIndex) { + return (mSvidWithFlags[satelliteIndex] & SVID_FLAGS_HAS_CARRIER_FREQUENCY) != 0; } /** * Gets the carrier frequency of the signal tracked. * - * <p>For example it can be the GPS central frequency for L1 = 1575.45 MHz, or L2 = 1227.60 MHz, - * L5 = 1176.45 MHz, varying GLO channels, etc. If the field is not set, it is the primary + * <p>For example it can be the GPS central frequency for L1 = 1575.45 MHz, or L2 = 1227.60 + * MHz, L5 = 1176.45 MHz, varying GLO channels, etc. If the field is not set, it is the primary * common use central frequency, e.g. L1 = 1575.45 MHz for GPS. * * For an L1, L5 receiver tracking a satellite on L1 and L5 at the same time, two measurements - * will be reported for this same satellite, in one all the values related to L1 will be filled, - * and in the other all of the values related to L5 will be filled. - * - * <p>The value is only available if {@link #hasCarrierFrequencyHz(int satIndex)} is {@code true}. + * will be reported for this same satellite, in one all the values related to L1 will be + * filled, and in the other all of the values related to L5 will be filled. * - * @param satIndex the index of the satellite in the list. + * <p>The value is only available if {@link #hasCarrierFrequencyHz(int satelliteIndex)} is + * {@code true}. * - * @return the carrier frequency of the signal tracked in Hz. + * @param satelliteIndex An index from zero to {@link #getSatelliteCount()} - 1 */ - public float getCarrierFrequencyHz(int satIndex) { - return mCarrierFrequencies[satIndex]; + @FloatRange(from = 0) + public float getCarrierFrequencyHz(@IntRange(from = 0) int satelliteIndex) { + return mCarrierFrequencies[satelliteIndex]; } /** - * Returns the string representation of a constellation type. For example, - * {@link #CONSTELLATION_GPS} is represented by the string GPS. + * Returns the string representation of a constellation type. * * @param constellationType the constellation type. * @return the string representation. @@ -290,4 +313,108 @@ public final class GnssStatus { return Integer.toString(constellationType); } } + + /** + * Builder class to help create new GnssStatus instances. + */ + public static final class Builder { + + private final ArrayList<GnssSvInfo> mSatellites = new ArrayList<>(); + + /** + * Adds a new satellite to the Builder. + * + * @param constellationType one of the CONSTELLATION_* constants + * @param svid the space vehicle identifier + * @param cn0DbHz carrier-to-noise density at the antenna in dB-Hz + * @param elevation satellite elevation in degrees + * @param azimuth satellite azimuth in degrees + * @param hasEphemeris whether the satellite has ephemeris data + * @param hasAlmanac whether the satellite has almanac data + * @param usedInFix whether the satellite was used in the most recent location fix + * @param hasCarrierFrequency whether carrier frequency data is available + * @param carrierFrequency satellite carrier frequency in Hz + */ + @NonNull + public Builder addSatellite(@ConstellationType int constellationType, + @IntRange(from = 1, to = 200) int svid, + @FloatRange(from = 0, to = 63) float cn0DbHz, + @FloatRange(from = -90, to = 90) float elevation, + @FloatRange(from = 0, to = 360) float azimuth, + boolean hasEphemeris, + boolean hasAlmanac, + boolean usedInFix, + boolean hasCarrierFrequency, + @FloatRange(from = 0) float carrierFrequency) { + mSatellites.add(new GnssSvInfo(constellationType, svid, cn0DbHz, elevation, azimuth, + hasEphemeris, hasAlmanac, usedInFix, hasCarrierFrequency, carrierFrequency)); + return this; + } + + /** + * Clears all satellites in the Builder. + */ + @NonNull + public Builder clearSatellites() { + mSatellites.clear(); + return this; + } + + /** + * Builds a new GnssStatus based on the satellite information in the Builder. + */ + @NonNull + public GnssStatus build() { + int svCount = mSatellites.size(); + int[] svidWithFlags = new int[svCount]; + float[] cn0DbHzs = new float[svCount]; + float[] elevations = new float[svCount]; + float[] azimuths = new float[svCount]; + float[] carrierFrequencies = new float[svCount]; + + for (int i = 0; i < svidWithFlags.length; i++) { + svidWithFlags[i] = mSatellites.get(i).mSvidWithFlags; + } + for (int i = 0; i < cn0DbHzs.length; i++) { + cn0DbHzs[i] = mSatellites.get(i).mCn0DbHz; + } + for (int i = 0; i < elevations.length; i++) { + elevations[i] = mSatellites.get(i).mElevation; + } + for (int i = 0; i < azimuths.length; i++) { + azimuths[i] = mSatellites.get(i).mAzimuth; + } + for (int i = 0; i < carrierFrequencies.length; i++) { + carrierFrequencies[i] = mSatellites.get(i).mCarrierFrequency; + } + + return wrap(svCount, svidWithFlags, cn0DbHzs, elevations, azimuths, + carrierFrequencies); + } + } + + private static class GnssSvInfo { + + private final int mSvidWithFlags; + private final float mCn0DbHz; + private final float mElevation; + private final float mAzimuth; + private final float mCarrierFrequency; + + private GnssSvInfo(int constellationType, int svid, float cn0DbHz, + float elevation, float azimuth, boolean hasEphemeris, boolean hasAlmanac, + boolean usedInFix, boolean hasCarrierFrequency, float carrierFrequency) { + mSvidWithFlags = (svid << SVID_SHIFT_WIDTH) + | ((constellationType & CONSTELLATION_TYPE_MASK) + << CONSTELLATION_TYPE_SHIFT_WIDTH) + | (hasEphemeris ? SVID_FLAGS_HAS_EPHEMERIS_DATA : SVID_FLAGS_NONE) + | (hasAlmanac ? SVID_FLAGS_HAS_ALMANAC_DATA : SVID_FLAGS_NONE) + | (usedInFix ? SVID_FLAGS_USED_IN_FIX : SVID_FLAGS_NONE) + | (hasCarrierFrequency ? SVID_FLAGS_HAS_CARRIER_FREQUENCY : SVID_FLAGS_NONE); + mCn0DbHz = cn0DbHz; + mElevation = elevation; + mAzimuth = azimuth; + mCarrierFrequency = carrierFrequency; + } + } } diff --git a/location/java/android/location/GpsStatus.java b/location/java/android/location/GpsStatus.java index 609a15e1be7e..496885cd1f37 100644 --- a/location/java/android/location/GpsStatus.java +++ b/location/java/android/location/GpsStatus.java @@ -16,8 +16,7 @@ package android.location; -import android.annotation.UnsupportedAppUsage; -import android.os.Build; +import android.annotation.NonNull; import android.util.SparseArray; import java.util.Iterator; @@ -25,20 +24,18 @@ import java.util.NoSuchElementException; /** - * This class represents the current state of the GPS engine. + * This class represents the current state of the GPS engine and is used in conjunction with {@link + * GpsStatus.Listener}. * - * <p>This class is used in conjunction with the {@link Listener} interface. - * - * @deprecated use {@link GnssStatus} and {@link GnssStatus.Callback}. + * @deprecated Use {@link GnssStatus} instead. */ @Deprecated public final class GpsStatus { - private static final int NUM_SATELLITES = 255; + private static final int MAX_SATELLITES = 255; private static final int GLONASS_SVID_OFFSET = 64; private static final int BEIDOU_SVID_OFFSET = 200; private static final int SBAS_SVID_OFFSET = -87; - /* These package private values are modified by the LocationManager class */ private int mTimeToFirstFix; private final SparseArray<GpsSatellite> mSatellites = new SparseArray<>(); @@ -80,12 +77,7 @@ public final class GpsStatus { } } - private Iterable<GpsSatellite> mSatelliteList = new Iterable<GpsSatellite>() { - @Override - public Iterator<GpsSatellite> iterator() { - return new SatelliteIterator(); - } - }; + private Iterable<GpsSatellite> mSatelliteList = SatelliteIterator::new; /** * Event sent when the GPS system has started. @@ -111,7 +103,8 @@ public final class GpsStatus { /** * Used for receiving notifications when GPS status has changed. - * @deprecated use {@link GnssStatus.Callback} instead. + * + * @deprecated Use {@link GnssStatus.Callback} instead. */ @Deprecated public interface Listener { @@ -148,17 +141,31 @@ public final class GpsStatus { void onNmeaReceived(long timestamp, String nmea); } - // For API-compat a public ctor() is not available - GpsStatus() {} - - private void setStatus(int svCount, int[] svidWithFlags, float[] cn0s, float[] elevations, - float[] azimuths) { - clearSatellites(); - for (int i = 0; i < svCount; i++) { - final int constellationType = - (svidWithFlags[i] >> GnssStatus.CONSTELLATION_TYPE_SHIFT_WIDTH) - & GnssStatus.CONSTELLATION_TYPE_MASK; - int prn = svidWithFlags[i] >> GnssStatus.SVID_SHIFT_WIDTH; + /** + * Builds a GpsStatus from the given GnssStatus. + */ + @NonNull + public static GpsStatus create(@NonNull GnssStatus gnssStatus, int timeToFirstFix) { + GpsStatus status = new GpsStatus(); + status.setStatus(gnssStatus, timeToFirstFix); + return status; + } + + private GpsStatus() { + } + + /** + * @hide + */ + void setStatus(GnssStatus status, int timeToFirstFix) { + for (int i = 0; i < mSatellites.size(); i++) { + mSatellites.valueAt(i).mValid = false; + } + + mTimeToFirstFix = timeToFirstFix; + for (int i = 0; i < status.getSatelliteCount(); i++) { + int constellationType = status.getConstellationType(i); + int prn = status.getSvid(i); // Other satellites passed through these APIs before GnssSvStatus was availble. // GPS, SBAS & QZSS can pass through at their nominally // assigned prn number (as long as it fits in the valid 0-255 range below.) @@ -175,42 +182,24 @@ public final class GpsStatus { (constellationType != GnssStatus.CONSTELLATION_QZSS)) { continue; } - if (prn > 0 && prn <= NUM_SATELLITES) { - GpsSatellite satellite = mSatellites.get(prn); - if (satellite == null) { - satellite = new GpsSatellite(prn); - mSatellites.put(prn, satellite); - } - - satellite.mValid = true; - satellite.mSnr = cn0s[i]; - satellite.mElevation = elevations[i]; - satellite.mAzimuth = azimuths[i]; - satellite.mHasEphemeris = - (svidWithFlags[i] & GnssStatus.GNSS_SV_FLAGS_HAS_EPHEMERIS_DATA) != 0; - satellite.mHasAlmanac = - (svidWithFlags[i] & GnssStatus.GNSS_SV_FLAGS_HAS_ALMANAC_DATA) != 0; - satellite.mUsedInFix = - (svidWithFlags[i] & GnssStatus.GNSS_SV_FLAGS_USED_IN_FIX) != 0; + if (prn <= 0 || prn > MAX_SATELLITES) { + continue; } - } - } - /** - * Copies GPS satellites information from GnssStatus object. - * Since this method is only used within {@link LocationManager#getGpsStatus}, - * it does not need to be synchronized. - * @hide - */ - void setStatus(GnssStatus status, int timeToFirstFix) { - mTimeToFirstFix = timeToFirstFix; - setStatus(status.mSvCount, status.mSvidWithFlags, status.mCn0DbHz, status.mElevations, - status.mAzimuths); - } + GpsSatellite satellite = mSatellites.get(prn); + if (satellite == null) { + satellite = new GpsSatellite(prn); + mSatellites.put(prn, satellite); + } - @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) - void setTimeToFirstFix(int ttff) { - mTimeToFirstFix = ttff; + satellite.mValid = true; + satellite.mSnr = status.getCn0DbHz(i); + satellite.mElevation = status.getElevationDegrees(i); + satellite.mAzimuth = status.getAzimuthDegrees(i); + satellite.mHasEphemeris = status.hasEphemerisData(i); + satellite.mHasAlmanac = status.hasAlmanacData(i); + satellite.mUsedInFix = status.usedInFix(i); + } } /** @@ -240,14 +229,7 @@ public final class GpsStatus { * @return the maximum number of satellites */ public int getMaxSatellites() { - return NUM_SATELLITES; + return mSatellites.size(); } - private void clearSatellites() { - int satellitesCount = mSatellites.size(); - for (int i = 0; i < satellitesCount; i++) { - GpsSatellite satellite = mSatellites.valueAt(i); - satellite.mValid = false; - } - } } diff --git a/location/java/android/location/LocationManager.java b/location/java/android/location/LocationManager.java index 5030e6625d5d..75e1cd45689c 100644 --- a/location/java/android/location/LocationManager.java +++ b/location/java/android/location/LocationManager.java @@ -1818,15 +1818,14 @@ public class LocationManager { Log.w(TAG, ex); } - if (status == null) { - status = new GpsStatus(); - } - // When mGnssStatus is null, that means that this method is called outside - // onGpsStatusChanged(). Return an empty status to maintain backwards compatibility. GnssStatus gnssStatus = mGnssStatusListenerManager.getGnssStatus(); int ttff = mGnssStatusListenerManager.getTtff(); if (gnssStatus != null) { - status.setStatus(gnssStatus, ttff); + if (status == null) { + status = GpsStatus.create(gnssStatus, ttff); + } else { + status.setStatus(gnssStatus, ttff); + } } return status; } @@ -2820,8 +2819,8 @@ public class LocationManager { @Override public void onSvStatusChanged(int svCount, int[] svidWithFlags, float[] cn0s, float[] elevations, float[] azimuths, float[] carrierFreqs) { - GnssStatus localStatus = new GnssStatus(svCount, svidWithFlags, cn0s, elevations, - azimuths, carrierFreqs); + GnssStatus localStatus = GnssStatus.wrap(svCount, svidWithFlags, cn0s, + elevations, azimuths, carrierFreqs); mGnssStatus = localStatus; execute((callback) -> callback.onSatelliteStatusChanged(localStatus)); } diff --git a/location/java/com/android/internal/location/gnssmetrics/GnssMetrics.java b/location/java/com/android/internal/location/gnssmetrics/GnssMetrics.java index 07bfe0242509..e0bff74fd588 100644 --- a/location/java/com/android/internal/location/gnssmetrics/GnssMetrics.java +++ b/location/java/com/android/internal/location/gnssmetrics/GnssMetrics.java @@ -188,22 +188,18 @@ public class GnssMetrics { /** * Logs sv status data - * - * @param svCount - * @param svidWithFlags - * @param svCarrierFreqs */ - public void logSvStatus(int svCount, int[] svidWithFlags, float[] svCarrierFreqs) { + public void logSvStatus(GnssStatus status) { boolean isL5 = false; // Calculate SvStatus Information - for (int i = 0; i < svCount; i++) { - if ((svidWithFlags[i] & GnssStatus.GNSS_SV_FLAGS_HAS_CARRIER_FREQUENCY) != 0) { + for (int i = 0; i < status.getSatelliteCount(); i++) { + if (status.hasCarrierFrequencyHz(i)) { mNumSvStatus++; - isL5 = isL5Sv(svCarrierFreqs[i]); + isL5 = isL5Sv(status.getCarrierFrequencyHz(i)); if (isL5) { mNumL5SvStatus++; } - if ((svidWithFlags[i] & GnssStatus.GNSS_SV_FLAGS_USED_IN_FIX) != 0) { + if (status.usedInFix(i)) { mNumSvStatusUsedInFix++; if (isL5) { mNumL5SvStatusUsedInFix++; @@ -211,15 +207,10 @@ public class GnssMetrics { } } } - return; } /** * Logs CN0 when at least 4 SVs are available L5 Only - * - * @param svCount - * @param cn0s - * @param svCarrierFreqs */ private void logCn0L5(int svCount, float[] cn0s, float[] svCarrierFreqs) { if (svCount == 0 || cn0s == null || cn0s.length == 0 || cn0s.length < svCount diff --git a/services/core/java/com/android/server/location/GnssLocationProvider.java b/services/core/java/com/android/server/location/GnssLocationProvider.java index fb57d69f0db9..8d2fc17b94d6 100644 --- a/services/core/java/com/android/server/location/GnssLocationProvider.java +++ b/services/core/java/com/android/server/location/GnssLocationProvider.java @@ -1482,39 +1482,35 @@ public class GnssLocationProvider extends AbstractLocationProvider implements Log.v(TAG, "SV count: " + info.mSvCount); } // Calculate number of satellites used in fix. + GnssStatus gnssStatus = GnssStatus.wrap( + info.mSvCount, + info.mSvidWithFlags, + info.mCn0s, + info.mSvElevations, + info.mSvAzimuths, + info.mSvCarrierFreqs); int usedInFixCount = 0; int maxCn0 = 0; int meanCn0 = 0; - for (int i = 0; i < info.mSvCount; i++) { - if ((info.mSvidWithFlags[i] & GnssStatus.GNSS_SV_FLAGS_USED_IN_FIX) != 0) { + for (int i = 0; i < gnssStatus.getSatelliteCount(); i++) { + if (gnssStatus.usedInFix(i)) { ++usedInFixCount; - if (info.mCn0s[i] > maxCn0) { - maxCn0 = (int) info.mCn0s[i]; + if (gnssStatus.getCn0DbHz(i) > maxCn0) { + maxCn0 = (int) gnssStatus.getCn0DbHz(i); } - meanCn0 += info.mCn0s[i]; + meanCn0 += gnssStatus.getCn0DbHz(i); + mGnssMetrics.logConstellationType(gnssStatus.getConstellationType(i)); } if (VERBOSE) { - Log.v(TAG, "svid: " + (info.mSvidWithFlags[i] >> GnssStatus.SVID_SHIFT_WIDTH) + - " cn0: " + info.mCn0s[i] + - " elev: " + info.mSvElevations[i] + - " azimuth: " + info.mSvAzimuths[i] + - " carrier frequency: " + info.mSvCarrierFreqs[i] + - ((info.mSvidWithFlags[i] & GnssStatus.GNSS_SV_FLAGS_HAS_EPHEMERIS_DATA) == 0 - ? " " : " E") + - ((info.mSvidWithFlags[i] & GnssStatus.GNSS_SV_FLAGS_HAS_ALMANAC_DATA) == 0 - ? " " : " A") + - ((info.mSvidWithFlags[i] & GnssStatus.GNSS_SV_FLAGS_USED_IN_FIX) == 0 - ? "" : "U") + - ((info.mSvidWithFlags[i] & - GnssStatus.GNSS_SV_FLAGS_HAS_CARRIER_FREQUENCY) == 0 - ? "" : "F")); - } - - if ((info.mSvidWithFlags[i] & GnssStatus.GNSS_SV_FLAGS_USED_IN_FIX) != 0) { - int constellationType = - (info.mSvidWithFlags[i] >> GnssStatus.CONSTELLATION_TYPE_SHIFT_WIDTH) - & GnssStatus.CONSTELLATION_TYPE_MASK; - mGnssMetrics.logConstellationType(constellationType); + Log.v(TAG, "svid: " + gnssStatus.getSvid(i) + + " cn0: " + gnssStatus.getCn0DbHz(i) + + " elev: " + gnssStatus.getElevationDegrees(i) + + " azimuth: " + gnssStatus.getAzimuthDegrees(i) + + " carrier frequency: " + gnssStatus.getCn0DbHz(i) + + (gnssStatus.hasEphemerisData(i) ? " E" : " ") + + (gnssStatus.hasAlmanacData(i) ? " A" : " ") + + (gnssStatus.usedInFix(i) ? "U" : "") + + (gnssStatus.hasCarrierFrequencyHz(i) ? "F" : "")); } } if (usedInFixCount > 0) { @@ -1523,7 +1519,7 @@ public class GnssLocationProvider extends AbstractLocationProvider implements // return number of sats used in fix instead of total reported mLocationExtras.set(usedInFixCount, meanCn0, maxCn0); - mGnssMetrics.logSvStatus(info.mSvCount, info.mSvidWithFlags, info.mSvCarrierFreqs); + mGnssMetrics.logSvStatus(gnssStatus); } @NativeEntryPoint |