summaryrefslogtreecommitdiff
path: root/location/java/android
diff options
context:
space:
mode:
author Soonil Nagarkar <sooniln@google.com> 2019-11-14 22:04:37 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2019-11-14 22:04:37 +0000
commitfc28b5592689fa8ff9237b90cf7009696d68c970 (patch)
tree08004143d58ad1a1b14537507d270790243a9623 /location/java/android
parent71d15364f9b953f2866b3b3868bebe5df05072f8 (diff)
parent0d1890b0e05e71d90d9c1092fa28b40b2a4c2685 (diff)
Merge "Make GnssStatus and GpsStatus testable"
Diffstat (limited to 'location/java/android')
-rw-r--r--location/java/android/location/GnssStatus.java277
-rw-r--r--location/java/android/location/GpsStatus.java116
-rw-r--r--location/java/android/location/LocationManager.java15
3 files changed, 258 insertions, 150 deletions
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));
}