1 /*
2  * Copyright (C) 2014 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License
15  */
16 
17 package android.location;
18 
19 import static android.hardware.gnss.V2_1.IGnssMeasurementCallback.GnssMeasurementFlags.HAS_AUTOMATIC_GAIN_CONTROL;
20 import static android.hardware.gnss.V2_1.IGnssMeasurementCallback.GnssMeasurementFlags.HAS_CARRIER_CYCLES;
21 import static android.hardware.gnss.V2_1.IGnssMeasurementCallback.GnssMeasurementFlags.HAS_CARRIER_FREQUENCY;
22 import static android.hardware.gnss.V2_1.IGnssMeasurementCallback.GnssMeasurementFlags.HAS_CARRIER_PHASE;
23 import static android.hardware.gnss.V2_1.IGnssMeasurementCallback.GnssMeasurementFlags.HAS_CARRIER_PHASE_UNCERTAINTY;
24 import static android.hardware.gnss.V2_1.IGnssMeasurementCallback.GnssMeasurementFlags.HAS_FULL_ISB;
25 import static android.hardware.gnss.V2_1.IGnssMeasurementCallback.GnssMeasurementFlags.HAS_FULL_ISB_UNCERTAINTY;
26 import static android.hardware.gnss.V2_1.IGnssMeasurementCallback.GnssMeasurementFlags.HAS_SATELLITE_ISB;
27 import static android.hardware.gnss.V2_1.IGnssMeasurementCallback.GnssMeasurementFlags.HAS_SATELLITE_ISB_UNCERTAINTY;
28 import static android.hardware.gnss.V2_1.IGnssMeasurementCallback.GnssMeasurementFlags.HAS_SNR;
29 
30 import android.annotation.FloatRange;
31 import android.annotation.IntDef;
32 import android.annotation.NonNull;
33 import android.annotation.Nullable;
34 import android.annotation.SuppressLint;
35 import android.annotation.SystemApi;
36 import android.annotation.TestApi;
37 import android.os.Parcel;
38 import android.os.Parcelable;
39 
40 import java.lang.annotation.Retention;
41 import java.lang.annotation.RetentionPolicy;
42 import java.util.Arrays;
43 import java.util.Collection;
44 import java.util.Collections;
45 
46 /**
47  * A class representing a GNSS satellite measurement, containing raw and computed information.
48  */
49 public final class GnssMeasurement implements Parcelable {
50     private int mFlags;
51     private int mSvid;
52     private int mConstellationType;
53     private double mTimeOffsetNanos;
54     private int mState;
55     private long mReceivedSvTimeNanos;
56     private long mReceivedSvTimeUncertaintyNanos;
57     private double mCn0DbHz;
58     private double mBasebandCn0DbHz;
59     private double mPseudorangeRateMetersPerSecond;
60     private double mPseudorangeRateUncertaintyMetersPerSecond;
61     private int mAccumulatedDeltaRangeState;
62     private double mAccumulatedDeltaRangeMeters;
63     private double mAccumulatedDeltaRangeUncertaintyMeters;
64     private float mCarrierFrequencyHz;
65     private long mCarrierCycles;
66     private double mCarrierPhase;
67     private double mCarrierPhaseUncertainty;
68     private int mMultipathIndicator;
69     private double mSnrInDb;
70     private double mAutomaticGainControlLevelInDb;
71     @NonNull private String mCodeType;
72     private double mFullInterSignalBiasNanos;
73     private double mFullInterSignalBiasUncertaintyNanos;
74     private double mSatelliteInterSignalBiasNanos;
75     private double mSatelliteInterSignalBiasUncertaintyNanos;
76     @Nullable private SatellitePvt mSatellitePvt;
77     @Nullable private Collection<CorrelationVector> mReadOnlyCorrelationVectors;
78 
79     // The following enumerations must be in sync with the values declared in GNSS HAL.
80 
81     private static final int HAS_NO_FLAGS = 0;
82     private static final int HAS_CODE_TYPE = (1 << 14);
83     private static final int HAS_BASEBAND_CN0 = (1 << 15);
84     private static final int HAS_SATELLITE_PVT = (1 << 20);
85     private static final int HAS_CORRELATION_VECTOR = (1 << 21);
86 
87     /**
88      * The status of the multipath indicator.
89      * @hide
90      */
91     @Retention(RetentionPolicy.SOURCE)
92     @IntDef({MULTIPATH_INDICATOR_UNKNOWN, MULTIPATH_INDICATOR_DETECTED,
93             MULTIPATH_INDICATOR_NOT_DETECTED})
94     public @interface MultipathIndicator {}
95 
96     /**
97      * The indicator is not available or the presence or absence of multipath is unknown.
98      */
99     public static final int MULTIPATH_INDICATOR_UNKNOWN = 0;
100 
101     /**
102      * The measurement shows signs of multi-path.
103      */
104     public static final int MULTIPATH_INDICATOR_DETECTED = 1;
105 
106     /**
107      * The measurement shows no signs of multi-path.
108      */
109     public static final int MULTIPATH_INDICATOR_NOT_DETECTED = 2;
110 
111     /**
112      * GNSS measurement tracking loop state
113      * @hide
114      */
115     @IntDef(flag = true, prefix = { "STATE_" }, value = {
116             STATE_CODE_LOCK, STATE_BIT_SYNC, STATE_SUBFRAME_SYNC,
117             STATE_TOW_DECODED, STATE_MSEC_AMBIGUOUS, STATE_SYMBOL_SYNC, STATE_GLO_STRING_SYNC,
118             STATE_GLO_TOD_DECODED, STATE_BDS_D2_BIT_SYNC, STATE_BDS_D2_SUBFRAME_SYNC,
119             STATE_GAL_E1BC_CODE_LOCK, STATE_GAL_E1C_2ND_CODE_LOCK, STATE_GAL_E1B_PAGE_SYNC,
120             STATE_SBAS_SYNC, STATE_TOW_KNOWN, STATE_GLO_TOD_KNOWN, STATE_2ND_CODE_LOCK
121     })
122     @Retention(RetentionPolicy.SOURCE)
123     public @interface State {}
124 
125     /** This GNSS measurement's tracking state is invalid or unknown. */
126     public static final int STATE_UNKNOWN = 0;
127     /** This GNSS measurement's tracking state has code lock. */
128     public static final int STATE_CODE_LOCK = (1<<0);
129     /** This GNSS measurement's tracking state has bit sync. */
130     public static final int STATE_BIT_SYNC = (1<<1);
131     /** This GNSS measurement's tracking state has sub-frame sync. */
132     public static final int STATE_SUBFRAME_SYNC = (1<<2);
133     /** This GNSS measurement's tracking state has time-of-week decoded. */
134     public static final int STATE_TOW_DECODED = (1<<3);
135     /** This GNSS measurement's tracking state contains millisecond ambiguity. */
136     public static final int STATE_MSEC_AMBIGUOUS = (1<<4);
137     /** This GNSS measurement's tracking state has symbol sync. */
138     public static final int STATE_SYMBOL_SYNC = (1<<5);
139     /** This Glonass measurement's tracking state has string sync. */
140     public static final int STATE_GLO_STRING_SYNC = (1<<6);
141     /** This Glonass measurement's tracking state has time-of-day decoded. */
142     public static final int STATE_GLO_TOD_DECODED = (1<<7);
143     /** This Beidou measurement's tracking state has D2 bit sync. */
144     public static final int STATE_BDS_D2_BIT_SYNC = (1<<8);
145     /** This Beidou measurement's tracking state has D2 sub-frame sync. */
146     public static final int STATE_BDS_D2_SUBFRAME_SYNC = (1<<9);
147     /** This Galileo measurement's tracking state has E1B/C code lock. */
148     public static final int STATE_GAL_E1BC_CODE_LOCK = (1<<10);
149     /** This Galileo measurement's tracking state has E1C secondary code lock. */
150     public static final int STATE_GAL_E1C_2ND_CODE_LOCK = (1<<11);
151     /** This Galileo measurement's tracking state has E1B page sync. */
152     public static final int STATE_GAL_E1B_PAGE_SYNC = (1<<12);
153     /** This SBAS measurement's tracking state has whole second level sync. */
154     public static final int STATE_SBAS_SYNC = (1<<13);
155     /**
156      * This GNSS measurement's tracking state has time-of-week known, possibly not decoded
157      * over the air but has been determined from other sources. If TOW decoded is set then TOW Known
158      * will also be set.
159      */
160     public static final int STATE_TOW_KNOWN = (1<<14);
161     /**
162      * This Glonass measurement's tracking state has time-of-day known, possibly not decoded
163      * over the air but has been determined from other sources. If TOD decoded is set then TOD Known
164      * will also be set.
165      */
166     public static final int STATE_GLO_TOD_KNOWN = (1<<15);
167 
168     /** This GNSS measurement's tracking state has secondary code lock. */
169     public static final int STATE_2ND_CODE_LOCK  = (1 << 16);
170 
171     /**
172      * All the GNSS receiver state flags, for bit masking purposes (not a sensible state for any
173      * individual measurement.)
174      */
175     private static final int STATE_ALL = 0x3fff;  // 2 bits + 4 bits + 4 bits + 4 bits = 14 bits
176 
177     /**
178      * GNSS measurement accumulated delta range state
179      * @hide
180      */
181     @IntDef(flag = true, prefix = { "ADR_STATE_" }, value = {
182             ADR_STATE_UNKNOWN, ADR_STATE_VALID, ADR_STATE_RESET, ADR_STATE_CYCLE_SLIP,
183             ADR_STATE_HALF_CYCLE_RESOLVED, ADR_STATE_HALF_CYCLE_REPORTED
184     })
185     @Retention(RetentionPolicy.SOURCE)
186     public @interface AdrState {}
187 
188     /**
189      * The state of the value {@link #getAccumulatedDeltaRangeMeters()} is invalid or unknown.
190      */
191     public static final int ADR_STATE_UNKNOWN = 0;
192 
193     /**
194      * The state of the {@link #getAccumulatedDeltaRangeMeters()} is valid.
195      */
196     public static final int ADR_STATE_VALID = (1<<0);
197 
198     /**
199      * The state of the {@link #getAccumulatedDeltaRangeMeters()} has detected a reset.
200      */
201     public static final int ADR_STATE_RESET = (1<<1);
202 
203     /**
204      * The state of the {@link #getAccumulatedDeltaRangeMeters()} has a cycle slip detected.
205      */
206     public static final int ADR_STATE_CYCLE_SLIP = (1<<2);
207 
208     /**
209      * Reports whether the value {@link #getAccumulatedDeltaRangeMeters()} has resolved the half
210      * cycle ambiguity.
211      *
212      * <p> When this bit is set, the {@link #getAccumulatedDeltaRangeMeters()} corresponds to the
213      * carrier phase measurement plus an accumulated integer number of carrier full cycles.
214      *
215      * <p> When this bit is unset, the {@link #getAccumulatedDeltaRangeMeters()} corresponds to the
216      * carrier phase measurement plus an accumulated integer number of carrier half cycles.
217      *
218      * <p> For signals that have databits, the carrier phase tracking loops typically use a costas
219      * loop discriminator.  This type of tracking loop introduces a half-cycle ambiguity that is
220      * resolved by searching through the received data for known patterns of databits (e.g. GPS uses
221      * the TLM word) which then determines the polarity of the incoming data and resolves the
222      * half-cycle ambiguity.
223      *
224      * <p>Before the half-cycle ambiguity has been resolved it is possible that the ADR_STATE_VALID
225      * flag is set:
226      *
227      * <ul>
228      *   <li> In cases where ADR_STATE_HALF_CYCLE_REPORTED is not set, the
229      *   ADR_STATE_HALF_CYCLE_RESOLVED flag will not be available. Here, a half wave length will be
230      *   added to the returned accumulated delta range uncertainty to indicate the half cycle
231      *   ambiguity.
232      *   <li> In cases where ADR_STATE_HALF_CYCLE_REPORTED is set, half cycle ambiguity will be
233      *   indicated via both the ADR_STATE_HALF_CYCLE_RESOLVED flag and as well a half wave length
234      *   added to the returned accumulated delta range uncertainty.
235      * </ul>
236      */
237     public static final int ADR_STATE_HALF_CYCLE_RESOLVED = (1<<3);
238 
239     /**
240      * Reports whether the flag {@link #ADR_STATE_HALF_CYCLE_RESOLVED} has been reported by the
241      * GNSS hardware.
242      *
243      * <p> When this bit is set, the value of {@link #getAccumulatedDeltaRangeUncertaintyMeters()}
244      * can be low (centimeter level) whether or not the half cycle ambiguity is resolved.
245      *
246      * <p> When this bit is unset, the value of {@link #getAccumulatedDeltaRangeUncertaintyMeters()}
247      * is larger, to cover the potential error due to half cycle ambiguity being unresolved.
248      */
249     public static final int ADR_STATE_HALF_CYCLE_REPORTED = (1<<4);
250 
251     /**
252      * All the 'Accumulated Delta Range' flags.
253      * @hide
254      */
255     @TestApi
256     public static final int ADR_STATE_ALL =
257             ADR_STATE_VALID | ADR_STATE_RESET | ADR_STATE_CYCLE_SLIP |
258             ADR_STATE_HALF_CYCLE_RESOLVED | ADR_STATE_HALF_CYCLE_REPORTED;
259 
260     // End enumerations in sync with gps.h
261 
262     /**
263      * @hide
264      */
265     @TestApi
GnssMeasurement()266     public GnssMeasurement() {
267         initialize();
268     }
269 
270     /**
271      * Sets all contents to the values stored in the provided object.
272      * @hide
273      */
274     @TestApi
set(GnssMeasurement measurement)275     public void set(GnssMeasurement measurement) {
276         mFlags = measurement.mFlags;
277         mSvid = measurement.mSvid;
278         mConstellationType = measurement.mConstellationType;
279         mTimeOffsetNanos = measurement.mTimeOffsetNanos;
280         mState = measurement.mState;
281         mReceivedSvTimeNanos = measurement.mReceivedSvTimeNanos;
282         mReceivedSvTimeUncertaintyNanos = measurement.mReceivedSvTimeUncertaintyNanos;
283         mCn0DbHz = measurement.mCn0DbHz;
284         mBasebandCn0DbHz = measurement.mBasebandCn0DbHz;
285         mPseudorangeRateMetersPerSecond = measurement.mPseudorangeRateMetersPerSecond;
286         mPseudorangeRateUncertaintyMetersPerSecond =
287                 measurement.mPseudorangeRateUncertaintyMetersPerSecond;
288         mAccumulatedDeltaRangeState = measurement.mAccumulatedDeltaRangeState;
289         mAccumulatedDeltaRangeMeters = measurement.mAccumulatedDeltaRangeMeters;
290         mAccumulatedDeltaRangeUncertaintyMeters =
291                 measurement.mAccumulatedDeltaRangeUncertaintyMeters;
292         mCarrierFrequencyHz = measurement.mCarrierFrequencyHz;
293         mCarrierCycles = measurement.mCarrierCycles;
294         mCarrierPhase = measurement.mCarrierPhase;
295         mCarrierPhaseUncertainty = measurement.mCarrierPhaseUncertainty;
296         mMultipathIndicator = measurement.mMultipathIndicator;
297         mSnrInDb = measurement.mSnrInDb;
298         mAutomaticGainControlLevelInDb = measurement.mAutomaticGainControlLevelInDb;
299         mCodeType = measurement.mCodeType;
300         mFullInterSignalBiasNanos = measurement.mFullInterSignalBiasNanos;
301         mFullInterSignalBiasUncertaintyNanos =
302                 measurement.mFullInterSignalBiasUncertaintyNanos;
303         mSatelliteInterSignalBiasNanos = measurement.mSatelliteInterSignalBiasNanos;
304         mSatelliteInterSignalBiasUncertaintyNanos =
305                 measurement.mSatelliteInterSignalBiasUncertaintyNanos;
306         mSatellitePvt = measurement.mSatellitePvt;
307         mReadOnlyCorrelationVectors = measurement.mReadOnlyCorrelationVectors;
308     }
309 
310     /**
311      * Resets all the contents to its original state.
312      * @hide
313      */
314     @TestApi
reset()315     public void reset() {
316         initialize();
317     }
318 
319     /**
320      * Gets the satellite ID.
321      *
322      * <p>Interpretation depends on {@link #getConstellationType()}.
323      * See {@link GnssStatus#getSvid(int)}.
324      */
getSvid()325     public int getSvid() {
326         return mSvid;
327     }
328 
329     /**
330      * Sets the Satellite ID.
331      * @hide
332      */
333     @TestApi
setSvid(int value)334     public void setSvid(int value) {
335         mSvid = value;
336     }
337 
338     /**
339      * Gets the constellation type.
340      *
341      * <p>The return value is one of those constants with {@code CONSTELLATION_} prefix in
342      * {@link GnssStatus}.
343      */
344     @GnssStatus.ConstellationType
getConstellationType()345     public int getConstellationType() {
346         return mConstellationType;
347     }
348 
349     /**
350      * Sets the constellation type.
351      * @hide
352      */
353     @TestApi
setConstellationType(@nssStatus.ConstellationType int value)354     public void setConstellationType(@GnssStatus.ConstellationType int value) {
355         mConstellationType = value;
356     }
357 
358     /**
359      * Gets the time offset at which the measurement was taken in nanoseconds.
360      *
361      * <p>The reference receiver's time from which this is offset is specified by
362      * {@link GnssClock#getTimeNanos()}.
363      *
364      * <p>The sign of this value is given by the following equation:
365      * <pre>
366      *      measurement time = TimeNanos + TimeOffsetNanos</pre>
367      *
368      * <p>The value provides an individual time-stamp for the measurement, and allows sub-nanosecond
369      * accuracy.
370      */
getTimeOffsetNanos()371     public double getTimeOffsetNanos() {
372         return mTimeOffsetNanos;
373     }
374 
375     /**
376      * Sets the time offset at which the measurement was taken in nanoseconds.
377      * @hide
378      */
379     @TestApi
setTimeOffsetNanos(double value)380     public void setTimeOffsetNanos(double value) {
381         mTimeOffsetNanos = value;
382     }
383 
384     /**
385      * Gets per-satellite-signal sync state.
386      *
387      * <p>It represents the current sync state for the associated satellite signal.
388      *
389      * <p>This value helps interpret {@link #getReceivedSvTimeNanos()}.
390      */
391     @State
getState()392     public int getState() {
393         return mState;
394     }
395 
396     /**
397      * Sets the sync state.
398      * @hide
399      */
400     @TestApi
setState(@tate int value)401     public void setState(@State int value) {
402         mState = value;
403     }
404 
405     /**
406      * Gets a string representation of the 'sync state'.
407      *
408      * <p>For internal and logging use only.
409      */
getStateString()410     private String getStateString() {
411         if (mState == STATE_UNKNOWN) {
412             return "Unknown";
413         }
414 
415         StringBuilder builder = new StringBuilder();
416         if ((mState & STATE_CODE_LOCK) != 0) {
417             builder.append("CodeLock|");
418         }
419         if ((mState & STATE_BIT_SYNC) != 0) {
420             builder.append("BitSync|");
421         }
422         if ((mState & STATE_SUBFRAME_SYNC) != 0) {
423             builder.append("SubframeSync|");
424         }
425         if ((mState & STATE_TOW_DECODED) != 0) {
426             builder.append("TowDecoded|");
427         }
428         if ((mState & STATE_TOW_KNOWN) != 0) {
429           builder.append("TowKnown|");
430         }
431         if ((mState & STATE_MSEC_AMBIGUOUS) != 0) {
432             builder.append("MsecAmbiguous|");
433         }
434         if ((mState & STATE_SYMBOL_SYNC) != 0) {
435             builder.append("SymbolSync|");
436         }
437         if ((mState & STATE_GLO_STRING_SYNC) != 0) {
438             builder.append("GloStringSync|");
439         }
440         if ((mState & STATE_GLO_TOD_DECODED) != 0) {
441             builder.append("GloTodDecoded|");
442         }
443         if ((mState & STATE_GLO_TOD_KNOWN) != 0) {
444           builder.append("GloTodKnown|");
445         }
446         if ((mState & STATE_BDS_D2_BIT_SYNC) != 0) {
447             builder.append("BdsD2BitSync|");
448         }
449         if ((mState & STATE_BDS_D2_SUBFRAME_SYNC) != 0) {
450             builder.append("BdsD2SubframeSync|");
451         }
452         if ((mState & STATE_GAL_E1BC_CODE_LOCK) != 0) {
453             builder.append("GalE1bcCodeLock|");
454         }
455         if ((mState & STATE_GAL_E1C_2ND_CODE_LOCK) != 0) {
456             builder.append("E1c2ndCodeLock|");
457         }
458         if ((mState & STATE_GAL_E1B_PAGE_SYNC) != 0) {
459             builder.append("GalE1bPageSync|");
460         }
461         if ((mState & STATE_SBAS_SYNC) != 0) {
462             builder.append("SbasSync|");
463         }
464         if ((mState & STATE_2ND_CODE_LOCK) != 0) {
465             builder.append("2ndCodeLock|");
466         }
467 
468         int remainingStates = mState & ~STATE_ALL;
469         if (remainingStates > 0) {
470             builder.append("Other(");
471             builder.append(Integer.toBinaryString(remainingStates));
472             builder.append(")|");
473         }
474         builder.setLength(builder.length() - 1);
475         return builder.toString();
476     }
477 
478     /**
479      * Gets the received GNSS satellite time, at the measurement time, in nanoseconds.
480      *
481      * <p>The received satellite time is relative to the beginning of the system week for all
482      * constellations except for Glonass where it is relative to the beginning of the Glonass
483      * system day.
484      *
485      * <p>The table below indicates the valid range of the received GNSS satellite time. These
486      * ranges depend on the constellation and code being tracked and the state of the tracking
487      * algorithms given by the {@link #getState} method. The minimum value of this field is zero.
488      * The maximum value of this field is determined by looking across all of the state flags
489      * that are set, for the given constellation and code type, and finding the the maximum value
490      * in this table.
491      *
492      * <p>For example, for GPS L1 C/A, if STATE_TOW_KNOWN is set, this field can be any value from 0
493      * to 1 week (in nanoseconds), and for GAL E1B code, if only STATE_GAL_E1BC_CODE_LOCK is set,
494      * then this field can be any value from 0 to 4 milliseconds (in nanoseconds.)
495      *
496      * <table border="1">
497      *   <thead>
498      *     <tr>
499      *       <td />
500      *       <td colspan="4"><strong>GPS/QZSS</strong></td>
501      *       <td><strong>GLNS</strong></td>
502      *       <td colspan="4"><strong>BDS</strong></td>
503      *       <td colspan="3"><strong>GAL</strong></td>
504      *       <td><strong>SBAS</strong></td>
505      *       <td><strong>IRNSS</strong></td>
506      *     </tr>
507      *     <tr>
508      *       <td><strong>State Flag</strong></td>
509      *       <td><strong>L1 C/A</strong></td>
510      *       <td><strong>L1 C(P)</strong></td>
511      *       <td><strong>L5I</strong></td>
512      *       <td><strong>L5Q</strong></td>
513      *       <td><strong>L1OF</strong></td>
514      *       <td><strong>B1I (D1)</strong></td>
515      *       <td><strong>B1I (D2)</strong></td>
516      *       <td><strong>B1C (P)</strong></td>
517      *       <td><strong>B2AQ </strong></td>
518      *       <td><strong>E1B</strong></td>
519      *       <td><strong>E1C</strong></td>
520      *       <td><strong>E5AQ</strong></td>
521      *       <td><strong>L1 C/A</strong></td>
522      *       <td><strong>L5C</strong></td>
523      *     </tr>
524      *   </thead>
525      *   <tbody>
526      *     <tr>
527      *       <td>
528      *         <strong>STATE_UNKNOWN</strong>
529      *       </td>
530      *       <td>0</td>
531      *       <td>0</td>
532      *       <td>0</td>
533      *       <td>0</td>
534      *       <td>0</td>
535      *       <td>0</td>
536      *       <td>0</td>
537      *       <td>0</td>
538      *       <td>0</td>
539      *       <td>0</td>
540      *       <td>0</td>
541      *       <td>0</td>
542      *       <td>0</td>
543      *       <td>0</td>
544      *     </tr>
545      *     <tr>
546      *       <td>
547      *         <strong>STATE_CODE_LOCK</strong>
548      *       </td>
549      *       <td>1 ms</td>
550      *       <td>10 ms</td>
551      *       <td>1 ms</td>
552      *       <td>1 ms</td>
553      *       <td>1 ms</td>
554      *       <td>1 ms</td>
555      *       <td>1 ms</td>
556      *       <td>10 ms</td>
557      *       <td>1 ms</td>
558      *       <td>-</td>
559      *       <td>-</td>
560      *       <td>1 ms</td>
561      *       <td>1 ms</td>
562      *       <td>1 ms</td>
563      *     </tr>
564      *     <tr>
565      *       <td>
566      *         <strong>STATE_SYMBOL_SYNC</strong>
567      *       </td>
568      *       <td>-</td>
569      *       <td>-</td>
570      *       <td>10 ms</td>
571      *       <td>-</td>
572      *       <td>10 ms</td>
573      *       <td>-</td>
574      *       <td>2 ms</td>
575      *       <td>-</td>
576      *       <td>-</td>
577      *       <td>-</td>
578      *       <td>-</td>
579      *       <td>-</td>
580      *       <td>2 ms</td>
581      *       <td>-</td>
582      *     </tr>
583      *     <tr>
584      *       <td>
585      *         <strong>STATE_BIT_SYNC</strong>
586      *       </td>
587      *       <td>20 ms</td>
588      *       <td>-</td>
589      *       <td>20 ms</td>
590      *       <td>-</td>
591      *       <td>20 ms</td>
592      *       <td>20 ms</td>
593      *       <td>-</td>
594      *       <td>-</td>
595      *       <td>-</td>
596      *       <td>8 ms</td>
597      *       <td>-</td>
598      *       <td>-</td>
599      *       <td>4 ms</td>
600      *       <td>20 ms</td>
601      *     </tr>
602      *     <tr>
603      *       <td>
604      *         <strong>STATE_SUBFRAME_SYNC</strong>
605      *       </td>
606      *       <td>6 s</td>
607      *       <td>-</td>
608      *       <td>6 s</td>
609      *       <td>-</td>
610      *       <td>-</td>
611      *       <td>6 s</td>
612      *       <td>-</td>
613      *       <td>-</td>
614      *       <td>100 ms</td>
615      *       <td>-</td>
616      *       <td>-</td>
617      *       <td>100 ms</td>
618      *       <td>-</td>
619      *       <td>6 s</td>
620      *     </tr>
621      *     <tr>
622      *       <td>
623      *         <strong>STATE_TOW_DECODED</strong>
624      *       </td>
625      *       <td>1 week</td>
626      *       <td>-</td>
627      *       <td>1 week</td>
628      *       <td>-</td>
629      *       <td>-</td>
630      *       <td>1 week</td>
631      *       <td>1 week</td>
632      *       <td>-</td>
633      *       <td>-</td>
634      *       <td>1 week</td>
635      *       <td>1 week</td>
636      *       <td>-</td>
637      *       <td>1 week</td>
638      *       <td>1 week</td>
639      *     </tr>
640      *     <tr>
641      *       <td>
642      *         <strong>STATE_TOW_KNOWN</strong>
643      *       </td>
644      *       <td>1 week</td>
645      *       <td>1 week</td>
646      *       <td>1 week</td>
647      *       <td>1 week</td>
648      *       <td>-</td>
649      *       <td>1 week</td>
650      *       <td>1 week</td>
651      *       <td>1 week</td>
652      *       <td>1 week</td>
653      *       <td>1 week</td>
654      *       <td>1 week</td>
655      *       <td>1 week</td>
656      *       <td>1 week</td>
657      *       <td>1 week</td>
658      *     </tr>
659      *     <tr>
660      *       <td>
661      *         <strong>STATE_GLO_STRING_SYNC</strong>
662      *       </td>
663      *       <td>-</td>
664      *       <td>-</td>
665      *       <td>-</td>
666      *       <td>-</td>
667      *       <td>2 s</td>
668      *       <td>-</td>
669      *       <td>-</td>
670      *       <td>-</td>
671      *       <td>-</td>
672      *       <td>-</td>
673      *       <td>-</td>
674      *       <td>-</td>
675      *       <td>-</td>
676      *       <td>-</td>
677      *     </tr>
678      *     <tr>
679      *       <td>
680      *         <strong>STATE_GLO_TOD_DECODED</strong>
681      *       </td>
682      *       <td>-</td>
683      *       <td>-</td>
684      *       <td>-</td>
685      *       <td>-</td>
686      *       <td>1 day</td>
687      *       <td>-</td>
688      *       <td>-</td>
689      *       <td>-</td>
690      *       <td>-</td>
691      *       <td>-</td>
692      *       <td>-</td>
693      *       <td>-</td>
694      *       <td>-</td>
695      *       <td>-</td>
696      *     </tr>
697      *     <tr>
698      *       <td>
699      *         <strong>STATE_GLO_TOD_KNOWN</strong>
700      *       </td>
701      *       <td>-</td>
702      *       <td>-</td>
703      *       <td>-</td>
704      *       <td>-</td>
705      *       <td>1 day</td>
706      *       <td>-</td>
707      *       <td>-</td>
708      *       <td>-</td>
709      *       <td>-</td>
710      *       <td>-</td>
711      *       <td>-</td>
712      *       <td>-</td>
713      *       <td>-</td>
714      *       <td>-</td>
715      *     </tr>
716      *     <tr>
717      *       <td>
718      *         <strong>STATE_BDS_D2_BIT_SYNC</strong>
719      *       </td>
720      *       <td>-</td>
721      *       <td>-</td>
722      *       <td>-</td>
723      *       <td>-</td>
724      *       <td>-</td>
725      *       <td>-</td>
726      *       <td>2 ms</td>
727      *       <td>-</td>
728      *       <td>-</td>
729      *       <td>-</td>
730      *       <td>-</td>
731      *       <td>-</td>
732      *       <td>-</td>
733      *       <td>-</td>
734      *     </tr>
735      *     <tr>
736      *       <td>
737      *         <strong>STATE_BDS_D2_SUBFRAME_SYNC</strong>
738      *       </td>
739      *       <td>-</td>
740      *       <td>-</td>
741      *       <td>-</td>
742      *       <td>-</td>
743      *       <td>-</td>
744      *       <td>-</td>
745      *       <td>600 ms</td>
746      *       <td>-</td>
747      *       <td>-</td>
748      *       <td>-</td>
749      *       <td>-</td>
750      *       <td>-</td>
751      *       <td>-</td>
752      *       <td>-</td>
753      *     </tr>
754      *     <tr>
755      *       <td>
756      *         <strong>STATE_GAL_E1BC_CODE_LOCK</strong>
757      *       </td>
758      *       <td>-</td>
759      *       <td>-</td>
760      *       <td>-</td>
761      *       <td>-</td>
762      *       <td>-</td>
763      *       <td>-</td>
764      *       <td>-</td>
765      *       <td>-</td>
766      *       <td>-</td>
767      *       <td>4 ms</td>
768      *       <td>4 ms</td>
769      *       <td>-</td>
770      *       <td>-</td>
771      *       <td>-</td>
772      *     </tr>
773      *     <tr>
774      *       <td>
775      *         <strong>STATE_GAL_E1C_2ND_CODE_LOCK</strong>
776      *       </td>
777      *       <td>-</td>
778      *       <td>-</td>
779      *       <td>-</td>
780      *       <td>-</td>
781      *       <td>-</td>
782      *       <td>-</td>
783      *       <td>-</td>
784      *       <td>-</td>
785      *       <td>-</td>
786      *       <td>-</td>
787      *       <td>100 ms</td>
788      *       <td>-</td>
789      *       <td>-</td>
790      *       <td>-</td>
791      *     </tr>
792      *     <tr>
793      *       <td>
794      *         <strong>STATE_2ND_CODE_LOCK</strong>
795      *       </td>
796      *       <td>-</td>
797      *       <td>18000 ms</td>
798      *       <td>10 ms</td>
799      *       <td>20 ms</td>
800      *       <td>-</td>
801      *       <td>-</td>
802      *       <td>-</td>
803      *       <td>18000 ms</td>
804      *       <td>100 ms</td>
805      *       <td>-</td>
806      *       <td>-</td>
807      *       <td>100 ms</td>
808      *       <td>-</td>
809      *       <td>-</td>
810      *     </tr>
811      *     <tr>
812      *       <td>
813      *         <strong>STATE_GAL_E1B_PAGE_SYNC</strong>
814      *       </td>
815      *       <td>-</td>
816      *       <td>-</td>
817      *       <td>-</td>
818      *       <td>-</td>
819      *       <td>-</td>
820      *       <td>-</td>
821      *       <td>-</td>
822      *       <td>-</td>
823      *       <td>-</td>
824      *       <td>2 s</td>
825      *       <td>-</td>
826      *       <td>-</td>
827      *       <td>-</td>
828      *       <td>-</td>
829      *     </tr>
830      *     <tr>
831      *       <td>
832      *         <strong>STATE_SBAS_SYNC</strong>
833      *       </td>
834      *       <td>-</td>
835      *       <td>-</td>
836      *       <td>-</td>
837      *       <td>-</td>
838      *       <td>-</td>
839      *       <td>-</td>
840      *       <td>-</td>
841      *       <td>-</td>
842      *       <td>-</td>
843      *       <td>-</td>
844      *       <td>-</td>
845      *       <td>-</td>
846      *       <td>1 s</td>
847      *       <td>-</td>
848      *     </tr>
849      *   </tbody>
850      * </table>
851      *
852      * <p>Note: TOW Known refers to the case where TOW is possibly not decoded over the air but has
853      * been determined from other sources. If TOW decoded is set then TOW Known must also be set.
854      *
855      * <p>Note well: if there is any ambiguity in integer millisecond, STATE_MSEC_AMBIGUOUS must be
856      * set accordingly, in the 'state' field. This value must be populated, unless the 'state' ==
857      * STATE_UNKNOWN.
858      *
859      * <p>Note on optional flags:
860      * <ul>
861      *     <li> For L1 C/A and B1I, STATE_SYMBOL_SYNC is optional since the symbol length is the
862      *     same as the bit length.
863      *     <li> For L5Q and E5aQ, STATE_BIT_SYNC and STATE_SYMBOL_SYNC are optional since they are
864      *     implied by STATE_CODE_LOCK.
865      *     <li> STATE_2ND_CODE_LOCK for L5I is optional since it is implied by STATE_SYMBOL_SYNC.
866      *     <li> STATE_2ND_CODE_LOCK for E1C is optional since it is implied by
867      *     STATE_GAL_E1C_2ND_CODE_LOCK.
868      *     <li> For E1B and E1C, STATE_SYMBOL_SYNC is optional, because it is implied by
869      *     STATE_GAL_E1BC_CODE_LOCK.
870      * </ul>
871      */
getReceivedSvTimeNanos()872     public long getReceivedSvTimeNanos() {
873         return mReceivedSvTimeNanos;
874     }
875 
876     /**
877      * Sets the received GNSS time in nanoseconds.
878      * @hide
879      */
880     @TestApi
setReceivedSvTimeNanos(long value)881     public void setReceivedSvTimeNanos(long value) {
882         mReceivedSvTimeNanos = value;
883     }
884 
885     /**
886      * Gets the error estimate (1-sigma) for the received GNSS time, in nanoseconds.
887      */
getReceivedSvTimeUncertaintyNanos()888     public long getReceivedSvTimeUncertaintyNanos() {
889         return mReceivedSvTimeUncertaintyNanos;
890     }
891 
892     /**
893      * Sets the received GNSS time uncertainty (1-Sigma) in nanoseconds.
894      * @hide
895      */
896     @TestApi
setReceivedSvTimeUncertaintyNanos(long value)897     public void setReceivedSvTimeUncertaintyNanos(long value) {
898         mReceivedSvTimeUncertaintyNanos = value;
899     }
900 
901     /**
902      * Gets the Carrier-to-noise density in dB-Hz.
903      *
904      * <p>Typical range: 10-50 dB-Hz. The range of possible C/N0 values is 0-63 dB-Hz to handle
905      * some edge cases.
906      *
907      * <p>The value contains the measured C/N0 for the signal at the antenna input.
908      */
909     @FloatRange(from = 0, to = 63)
getCn0DbHz()910     public double getCn0DbHz() {
911         return mCn0DbHz;
912     }
913 
914     /**
915      * Sets the carrier-to-noise density in dB-Hz.
916      * @hide
917      */
918     @TestApi
setCn0DbHz(double value)919     public void setCn0DbHz(double value) {
920         mCn0DbHz = value;
921     }
922 
923     /**
924      * Returns {@code true} if {@link #getBasebandCn0DbHz()} is available, {@code false} otherwise.
925      */
hasBasebandCn0DbHz()926     public boolean hasBasebandCn0DbHz() {
927         return isFlagSet(HAS_BASEBAND_CN0);
928     }
929 
930     /**
931      * Gets the baseband carrier-to-noise density in dB-Hz.
932      *
933      * <p>Typical range: 10-50 dB-Hz. The range of possible baseband C/N0 values is 0-63 dB-Hz to
934      * handle some edge cases.
935      *
936      * <p>The value contains the measured C/N0 for the signal at the baseband. This is typically
937      * a few dB weaker than the value estimated for C/N0 at the antenna port, which is reported
938      * in {@link #getCn0DbHz()}.
939      */
940     @FloatRange(from = 0, to = 63)
getBasebandCn0DbHz()941     public double getBasebandCn0DbHz() {
942         return mBasebandCn0DbHz;
943     }
944 
945     /**
946      * Sets the baseband carrier-to-noise density in dB-Hz.
947      *
948      * @hide
949      */
950     @TestApi
setBasebandCn0DbHz(double value)951     public void setBasebandCn0DbHz(double value) {
952         setFlag(HAS_BASEBAND_CN0);
953         mBasebandCn0DbHz = value;
954     }
955 
956     /**
957      * Resets the baseband carrier-to-noise density in dB-Hz.
958      *
959      * @hide
960      */
961     @TestApi
resetBasebandCn0DbHz()962     public void resetBasebandCn0DbHz() {
963         resetFlag(HAS_BASEBAND_CN0);
964     }
965 
966     /**
967      * Gets the Pseudorange rate at the timestamp in m/s.
968      *
969      * <p>The error estimate for this value is
970      * {@link #getPseudorangeRateUncertaintyMetersPerSecond()}.
971      *
972      * <p>The value is uncorrected, i.e. corrections for receiver and satellite clock frequency
973      * errors are not included.
974      *
975      * <p>A positive 'uncorrected' value indicates that the SV is moving away from the receiver. The
976      * sign of the 'uncorrected' 'pseudorange rate' and its relation to the sign of 'doppler shift'
977      * is given by the equation:
978      *
979      * <pre>
980      *      pseudorange rate = -k * doppler shift   (where k is a constant)</pre>
981      */
getPseudorangeRateMetersPerSecond()982     public double getPseudorangeRateMetersPerSecond() {
983         return mPseudorangeRateMetersPerSecond;
984     }
985 
986     /**
987      * Sets the pseudorange rate at the timestamp in m/s.
988      * @hide
989      */
990     @TestApi
setPseudorangeRateMetersPerSecond(double value)991     public void setPseudorangeRateMetersPerSecond(double value) {
992         mPseudorangeRateMetersPerSecond = value;
993     }
994 
995     /**
996      * Gets the pseudorange's rate uncertainty (1-Sigma) in m/s.
997      *
998      * <p>The uncertainty is represented as an absolute (single sided) value.
999      */
getPseudorangeRateUncertaintyMetersPerSecond()1000     public double getPseudorangeRateUncertaintyMetersPerSecond() {
1001         return mPseudorangeRateUncertaintyMetersPerSecond;
1002     }
1003 
1004     /**
1005      * Sets the pseudorange's rate uncertainty (1-Sigma) in m/s.
1006      * @hide
1007      */
1008     @TestApi
setPseudorangeRateUncertaintyMetersPerSecond(double value)1009     public void setPseudorangeRateUncertaintyMetersPerSecond(double value) {
1010         mPseudorangeRateUncertaintyMetersPerSecond = value;
1011     }
1012 
1013     /**
1014      * Gets 'Accumulated Delta Range' state.
1015      *
1016      * <p>This indicates the state of the {@link #getAccumulatedDeltaRangeMeters()} measurement. See
1017      * the table below for a detailed interpretation of each state.
1018      *
1019      * <table border="1">
1020      * <thead>
1021      * <tr>
1022      * <th>ADR_STATE</th>
1023      * <th>Time of relevance</th>
1024      * <th>Interpretation</th>
1025      * </tr>
1026      * </thead>
1027      * <tbody>
1028      * <tr>
1029      * <td>UNKNOWN</td>
1030      * <td>ADR(t)</td>
1031      * <td>No valid carrier phase information is available at time t.</td>
1032      * </tr>
1033      * <tr>
1034      * <td>VALID</td>
1035      * <td>ADR(t)</td>
1036      * <td>Valid carrier phase information is available at time t. This indicates that this
1037      * measurement can be used as a reference for future measurements. However, to compare it to
1038      * previous measurements to compute delta range, other bits should be checked. Specifically,
1039      * it can be used for delta range computation if it is valid and has no reset or cycle  slip at
1040      * this epoch i.e. if VALID_BIT == 1 && CYCLE_SLIP_BIT == 0 && RESET_BIT == 0.</td>
1041      * </tr>
1042      * <tr>
1043      * <td>RESET</td>
1044      * <td>ADR(t) - ADR(t-1)</td>
1045      * <td>Carrier phase accumulation has been restarted between current time t and previous time
1046      * t-1. This indicates that this measurement can be used as a reference for future measurements,
1047      * but it should not be compared to previous measurements to compute delta range.</td>
1048      * </tr>
1049      * <tr>
1050      * <td>CYCLE_SLIP</td>
1051      * <td>ADR(t) - ADR(t-1)</td>
1052      * <td>Cycle slip(s) have been detected between the current time t and previous time t-1. This
1053      * indicates that this measurement can be used as a reference for future measurements. Clients
1054      * can use a measurement with a cycle slip to compute delta range against previous measurements
1055      * at their own risk.</td>
1056      * </tr>
1057      * <tr>
1058      * <td>HALF_CYCLE_RESOLVED</td>
1059      * <td>ADR(t)</td>
1060      * <td>Half cycle ambiguity is resolved at time t.</td>
1061      * </tr>
1062      * <tr>
1063      * <td>HALF_CYCLE_REPORTED</td>
1064      * <td>ADR(t)</td>
1065      * <td>Half cycle ambiguity is reported at time t.</td>
1066      * </tr>
1067      * </tbody>
1068      * </table>
1069      */
1070     @AdrState
getAccumulatedDeltaRangeState()1071     public int getAccumulatedDeltaRangeState() {
1072         return mAccumulatedDeltaRangeState;
1073     }
1074 
1075     /**
1076      * Sets the 'Accumulated Delta Range' state.
1077      * @hide
1078      */
1079     @TestApi
setAccumulatedDeltaRangeState(@drState int value)1080     public void setAccumulatedDeltaRangeState(@AdrState int value) {
1081         mAccumulatedDeltaRangeState = value;
1082     }
1083 
1084     /**
1085      * Gets a string representation of the 'Accumulated Delta Range state'.
1086      *
1087      * <p>For internal and logging use only.
1088      */
getAccumulatedDeltaRangeStateString()1089     private String getAccumulatedDeltaRangeStateString() {
1090         if (mAccumulatedDeltaRangeState == ADR_STATE_UNKNOWN) {
1091             return "Unknown";
1092         }
1093         StringBuilder builder = new StringBuilder();
1094         if ((mAccumulatedDeltaRangeState & ADR_STATE_VALID) == ADR_STATE_VALID) {
1095             builder.append("Valid|");
1096         }
1097         if ((mAccumulatedDeltaRangeState & ADR_STATE_RESET) == ADR_STATE_RESET) {
1098             builder.append("Reset|");
1099         }
1100         if ((mAccumulatedDeltaRangeState & ADR_STATE_CYCLE_SLIP) == ADR_STATE_CYCLE_SLIP) {
1101             builder.append("CycleSlip|");
1102         }
1103         if ((mAccumulatedDeltaRangeState & ADR_STATE_HALF_CYCLE_RESOLVED) ==
1104                 ADR_STATE_HALF_CYCLE_RESOLVED) {
1105             builder.append("HalfCycleResolved|");
1106         }
1107         if ((mAccumulatedDeltaRangeState & ADR_STATE_HALF_CYCLE_REPORTED)
1108                 == ADR_STATE_HALF_CYCLE_REPORTED) {
1109             builder.append("HalfCycleReported|");
1110         }
1111         int remainingStates = mAccumulatedDeltaRangeState & ~ADR_STATE_ALL;
1112         if (remainingStates > 0) {
1113             builder.append("Other(");
1114             builder.append(Integer.toBinaryString(remainingStates));
1115             builder.append(")|");
1116         }
1117         builder.deleteCharAt(builder.length() - 1);
1118         return builder.toString();
1119     }
1120 
1121     /**
1122      * Gets the accumulated delta range since the last channel reset, in meters.
1123      *
1124      * <p>The error estimate for this value is {@link #getAccumulatedDeltaRangeUncertaintyMeters()}.
1125      *
1126      * <p>The availability of the value is represented by {@link #getAccumulatedDeltaRangeState()}.
1127      *
1128      * <p>A positive value indicates that the SV is moving away from the receiver.
1129      * The sign of {@link #getAccumulatedDeltaRangeMeters()} and its relation to the sign of
1130      * {@link #getCarrierPhase()} is given by the equation:
1131      *
1132      * <pre>
1133      *          accumulated delta range = -k * carrier phase    (where k is a constant)</pre>
1134      *
1135      * <p>Similar to the concept of an RTCM "Phaserange", when the accumulated delta range is
1136      * initially chosen, and whenever it is reset, it will retain the integer nature
1137      * of the relative carrier phase offset between satellites observed by this receiver, such that
1138      * the double difference of this value between receivers and satellites may be used, together
1139      * with integer ambiguity resolution, to determine highly precise relative location between
1140      * receivers.
1141      *
1142      * <p>The alignment of the phase measurement will not be adjusted by the receiver so the
1143      * in-phase and quadrature phase components will have a quarter cycle offset as they do when
1144      * transmitted from the satellites. If the measurement is from a combination of the in-phase
1145      * and quadrature phase components, then the alignment of the phase measurement will be aligned
1146      * to the in-phase component.
1147      */
getAccumulatedDeltaRangeMeters()1148     public double getAccumulatedDeltaRangeMeters() {
1149         return mAccumulatedDeltaRangeMeters;
1150     }
1151 
1152     /**
1153      * Sets the accumulated delta range in meters.
1154      * @hide
1155      */
1156     @TestApi
setAccumulatedDeltaRangeMeters(double value)1157     public void setAccumulatedDeltaRangeMeters(double value) {
1158         mAccumulatedDeltaRangeMeters = value;
1159     }
1160 
1161     /**
1162      * Gets the accumulated delta range's uncertainty (1-Sigma) in meters.
1163      *
1164      * <p>The uncertainty is represented as an absolute (single sided) value.
1165      *
1166      * <p>The status of the value is represented by {@link #getAccumulatedDeltaRangeState()}.
1167      */
getAccumulatedDeltaRangeUncertaintyMeters()1168     public double getAccumulatedDeltaRangeUncertaintyMeters() {
1169         return mAccumulatedDeltaRangeUncertaintyMeters;
1170     }
1171 
1172     /**
1173      * Sets the accumulated delta range's uncertainty (1-sigma) in meters.
1174      *
1175      * <p>The status of the value is represented by {@link #getAccumulatedDeltaRangeState()}.
1176      *
1177      * @hide
1178      */
1179     @TestApi
setAccumulatedDeltaRangeUncertaintyMeters(double value)1180     public void setAccumulatedDeltaRangeUncertaintyMeters(double value) {
1181         mAccumulatedDeltaRangeUncertaintyMeters = value;
1182     }
1183 
1184     /**
1185      * Returns {@code true} if {@link #getCarrierFrequencyHz()} is available, {@code false}
1186      * otherwise.
1187      */
hasCarrierFrequencyHz()1188     public boolean hasCarrierFrequencyHz() {
1189         return isFlagSet(HAS_CARRIER_FREQUENCY);
1190     }
1191 
1192     /**
1193      * Gets the carrier frequency of the tracked signal.
1194      *
1195      * <p>For example it can be the GPS central frequency for L1 = 1575.45 MHz, or L2 = 1227.60 MHz,
1196      * L5 = 1176.45 MHz, varying GLO channels, etc.
1197      *
1198      * <p>The value is only available if {@link #hasCarrierFrequencyHz()} is {@code true}.
1199      *
1200      * @return the carrier frequency of the signal tracked in Hz.
1201      */
getCarrierFrequencyHz()1202     public float getCarrierFrequencyHz() {
1203         return mCarrierFrequencyHz;
1204     }
1205 
1206     /**
1207      * Sets the Carrier frequency in Hz.
1208      * @hide
1209      */
1210     @TestApi
setCarrierFrequencyHz(float carrierFrequencyHz)1211     public void setCarrierFrequencyHz(float carrierFrequencyHz) {
1212         setFlag(HAS_CARRIER_FREQUENCY);
1213         mCarrierFrequencyHz = carrierFrequencyHz;
1214     }
1215 
1216     /**
1217      * Resets the Carrier frequency in Hz.
1218      * @hide
1219      */
1220     @TestApi
resetCarrierFrequencyHz()1221     public void resetCarrierFrequencyHz() {
1222         resetFlag(HAS_CARRIER_FREQUENCY);
1223         mCarrierFrequencyHz = Float.NaN;
1224     }
1225 
1226     /**
1227      * Returns {@code true} if {@link #getCarrierCycles()} is available, {@code false} otherwise.
1228      *
1229      * @deprecated use {@link #getAccumulatedDeltaRangeState()} instead.
1230      */
1231     @Deprecated
hasCarrierCycles()1232     public boolean hasCarrierCycles() {
1233         return isFlagSet(HAS_CARRIER_CYCLES);
1234     }
1235 
1236     /**
1237      * The number of full carrier cycles between the satellite and the receiver.
1238      *
1239      * <p>The reference frequency is given by the value of {@link #getCarrierFrequencyHz()}.
1240      *
1241      * <p>The value is only available if {@link #hasCarrierCycles()} is {@code true}.
1242      *
1243      * @deprecated use {@link #getAccumulatedDeltaRangeMeters()} instead.
1244      */
1245     @Deprecated
getCarrierCycles()1246     public long getCarrierCycles() {
1247         return mCarrierCycles;
1248     }
1249 
1250     /**
1251      * Sets the number of full carrier cycles between the satellite and the receiver.
1252      *
1253      * @deprecated use {@link #setAccumulatedDeltaRangeMeters(double)}
1254      * and {@link #setAccumulatedDeltaRangeState(int)} instead.
1255      *
1256      * @hide
1257      */
1258     @TestApi
1259     @Deprecated
setCarrierCycles(long value)1260     public void setCarrierCycles(long value) {
1261         setFlag(HAS_CARRIER_CYCLES);
1262         mCarrierCycles = value;
1263     }
1264 
1265     /**
1266      * Resets the number of full carrier cycles between the satellite and the receiver.
1267      *
1268      * @deprecated use {@link #setAccumulatedDeltaRangeMeters(double)}
1269      * and {@link #setAccumulatedDeltaRangeState(int)} instead.
1270      * @hide
1271      */
1272     @TestApi
1273     @Deprecated
resetCarrierCycles()1274     public void resetCarrierCycles() {
1275         resetFlag(HAS_CARRIER_CYCLES);
1276         mCarrierCycles = Long.MIN_VALUE;
1277     }
1278 
1279     /**
1280      * Returns {@code true} if {@link #getCarrierPhase()} is available, {@code false} otherwise.
1281      *
1282      * @deprecated use {@link #getAccumulatedDeltaRangeState()} instead.
1283      */
1284     @Deprecated
hasCarrierPhase()1285     public boolean hasCarrierPhase() {
1286         return isFlagSet(HAS_CARRIER_PHASE);
1287     }
1288 
1289     /**
1290      * Gets the RF phase detected by the receiver.
1291      *
1292      * <p>Range: [0.0, 1.0].
1293      *
1294      * <p>This is the fractional part of the complete carrier phase measurement.
1295      *
1296      * <p>The reference frequency is given by the value of {@link #getCarrierFrequencyHz()}.
1297      *
1298      * <p>The error estimate for this value is {@link #getCarrierPhaseUncertainty()}.
1299      *
1300      * <p>The value is only available if {@link #hasCarrierPhase()} is {@code true}.
1301      *
1302      * @deprecated use {@link #getAccumulatedDeltaRangeMeters()} instead.
1303      */
1304     @Deprecated
getCarrierPhase()1305     public double getCarrierPhase() {
1306         return mCarrierPhase;
1307     }
1308 
1309     /**
1310      * Sets the RF phase detected by the receiver.
1311      *
1312      * @deprecated use {@link #setAccumulatedDeltaRangeMeters(double)}
1313      * and {@link #setAccumulatedDeltaRangeState(int)} instead.
1314      *
1315      * @hide
1316      */
1317     @TestApi
1318     @Deprecated
setCarrierPhase(double value)1319     public void setCarrierPhase(double value) {
1320         setFlag(HAS_CARRIER_PHASE);
1321         mCarrierPhase = value;
1322     }
1323 
1324     /**
1325      * Resets the RF phase detected by the receiver.
1326      *
1327      * @deprecated use {@link #setAccumulatedDeltaRangeMeters(double)}
1328      * and {@link #setAccumulatedDeltaRangeState(int)} instead.
1329      *
1330      * @hide
1331      */
1332     @TestApi
1333     @Deprecated
resetCarrierPhase()1334     public void resetCarrierPhase() {
1335         resetFlag(HAS_CARRIER_PHASE);
1336     }
1337 
1338     /**
1339      * Returns {@code true} if {@link #getCarrierPhaseUncertainty()} is available, {@code false}
1340      * otherwise.
1341      *
1342      * @deprecated use {@link #getAccumulatedDeltaRangeState()} instead.
1343      */
1344     @Deprecated
hasCarrierPhaseUncertainty()1345     public boolean hasCarrierPhaseUncertainty() {
1346         return isFlagSet(HAS_CARRIER_PHASE_UNCERTAINTY);
1347     }
1348 
1349     /**
1350      * Gets the carrier-phase's uncertainty (1-Sigma).
1351      *
1352      * <p>The uncertainty is represented as an absolute (single sided) value.
1353      *
1354      * <p>The value is only available if {@link #hasCarrierPhaseUncertainty()} is {@code true}.
1355      *
1356      * @deprecated use {@link #getAccumulatedDeltaRangeUncertaintyMeters()} instead.
1357      */
1358     @Deprecated
getCarrierPhaseUncertainty()1359     public double getCarrierPhaseUncertainty() {
1360         return mCarrierPhaseUncertainty;
1361     }
1362 
1363     /**
1364      * Sets the Carrier-phase's uncertainty (1-Sigma) in cycles.
1365      *
1366      * @deprecated use {@link #setAccumulatedDeltaRangeUncertaintyMeters(double)}
1367      * and {@link #setAccumulatedDeltaRangeState(int)} instead.
1368      *
1369      * @hide
1370      */
1371     @TestApi
1372     @Deprecated
setCarrierPhaseUncertainty(double value)1373     public void setCarrierPhaseUncertainty(double value) {
1374         setFlag(HAS_CARRIER_PHASE_UNCERTAINTY);
1375         mCarrierPhaseUncertainty = value;
1376     }
1377 
1378     /**
1379      * Resets the Carrier-phase's uncertainty (1-Sigma) in cycles.
1380      *
1381      * @deprecated use {@link #setAccumulatedDeltaRangeUncertaintyMeters(double)}
1382      * and {@link #setAccumulatedDeltaRangeState(int)} instead.
1383      *
1384      * @hide
1385      */
1386     @TestApi
1387     @Deprecated
resetCarrierPhaseUncertainty()1388     public void resetCarrierPhaseUncertainty() {
1389         resetFlag(HAS_CARRIER_PHASE_UNCERTAINTY);
1390     }
1391 
1392     /**
1393      * Gets a value indicating the 'multipath' state of the event.
1394      */
1395     @MultipathIndicator
getMultipathIndicator()1396     public int getMultipathIndicator() {
1397         return mMultipathIndicator;
1398     }
1399 
1400     /**
1401      * Sets the 'multi-path' indicator.
1402      * @hide
1403      */
1404     @TestApi
setMultipathIndicator(@ultipathIndicator int value)1405     public void setMultipathIndicator(@MultipathIndicator int value) {
1406         mMultipathIndicator = value;
1407     }
1408 
1409     /**
1410      * Gets a string representation of the 'multi-path indicator'.
1411      *
1412      * <p>For internal and logging use only.
1413      */
getMultipathIndicatorString()1414     private String getMultipathIndicatorString() {
1415         switch (mMultipathIndicator) {
1416             case MULTIPATH_INDICATOR_UNKNOWN:
1417                 return "Unknown";
1418             case MULTIPATH_INDICATOR_DETECTED:
1419                 return "Detected";
1420             case MULTIPATH_INDICATOR_NOT_DETECTED:
1421                 return "NotDetected";
1422             default:
1423                 return "<Invalid: " + mMultipathIndicator + ">";
1424         }
1425     }
1426 
1427     /**
1428      * Returns {@code true} if {@link #getSnrInDb()} is available, {@code false} otherwise.
1429      */
hasSnrInDb()1430     public boolean hasSnrInDb() {
1431         return isFlagSet(HAS_SNR);
1432     }
1433 
1434     /**
1435      * Gets the (post-correlation & integration) Signal-to-Noise ratio (SNR) in dB.
1436      *
1437      * <p>The value is only available if {@link #hasSnrInDb()} is {@code true}.
1438      */
getSnrInDb()1439     public double getSnrInDb() {
1440         return mSnrInDb;
1441     }
1442 
1443     /**
1444      * Sets the Signal-to-noise ratio (SNR) in dB.
1445      * @hide
1446      */
1447     @TestApi
setSnrInDb(double snrInDb)1448     public void setSnrInDb(double snrInDb) {
1449         setFlag(HAS_SNR);
1450         mSnrInDb = snrInDb;
1451     }
1452 
1453     /**
1454      * Resets the Signal-to-noise ratio (SNR) in dB.
1455      * @hide
1456      */
1457     @TestApi
resetSnrInDb()1458     public void resetSnrInDb() {
1459         resetFlag(HAS_SNR);
1460     }
1461 
1462     /**
1463      * Returns {@code true} if {@link #getAutomaticGainControlLevelDb()} is available,
1464      * {@code false} otherwise.
1465      *
1466      * @deprecated Use {@link GnssMeasurementsEvent#getGnssAutomaticGainControls()} instead.
1467      */
1468     @Deprecated
hasAutomaticGainControlLevelDb()1469     public boolean hasAutomaticGainControlLevelDb() {
1470         return isFlagSet(HAS_AUTOMATIC_GAIN_CONTROL);
1471     }
1472 
1473     /**
1474      * Gets the Automatic Gain Control level in dB.
1475      *
1476      * <p> AGC acts as a variable gain amplifier adjusting the power of the incoming signal. The AGC
1477      * level may be used to indicate potential interference. Higher gain (and/or lower input power)
1478      * shall be output as a positive number. Hence in cases of strong jamming, in the band of this
1479      * signal, this value will go more negative. This value must be consistent given the same level
1480      * of the incoming signal power.
1481      *
1482      * <p> Note: Different hardware designs (e.g. antenna, pre-amplification, or other RF HW
1483      * components) may also affect the typical output of of this value on any given hardware design
1484      * in an open sky test - the important aspect of this output is that changes in this value are
1485      * indicative of changes on input signal power in the frequency band for this measurement.
1486      *
1487      * <p> The value is only available if {@link #hasAutomaticGainControlLevelDb()} is {@code true}
1488      *
1489      * @deprecated Use {@link GnssMeasurementsEvent#getGnssAutomaticGainControls()} instead.
1490      */
1491     @Deprecated
getAutomaticGainControlLevelDb()1492     public double getAutomaticGainControlLevelDb() {
1493         return mAutomaticGainControlLevelInDb;
1494     }
1495 
1496     /**
1497      * Sets the Automatic Gain Control level in dB.
1498      * @hide
1499      * @deprecated Use {@link GnssMeasurementsEvent.Builder#setGnssAutomaticGainControls()} instead.
1500      */
1501     @Deprecated
1502     @TestApi
setAutomaticGainControlLevelInDb(double agcLevelDb)1503     public void setAutomaticGainControlLevelInDb(double agcLevelDb) {
1504         setFlag(HAS_AUTOMATIC_GAIN_CONTROL);
1505         mAutomaticGainControlLevelInDb = agcLevelDb;
1506     }
1507 
1508     /**
1509      * Resets the Automatic Gain Control level.
1510      * @hide
1511      */
1512     @TestApi
resetAutomaticGainControlLevel()1513     public void resetAutomaticGainControlLevel() {
1514         resetFlag(HAS_AUTOMATIC_GAIN_CONTROL);
1515     }
1516 
1517     /**
1518      * Returns {@code true} if {@link #getCodeType()} is available,
1519      * {@code false} otherwise.
1520      */
hasCodeType()1521     public boolean hasCodeType() {
1522         return isFlagSet(HAS_CODE_TYPE);
1523     }
1524 
1525     /**
1526      * Gets the GNSS measurement's code type.
1527      *
1528      * <p>Similar to the Attribute field described in RINEX 4.00, e.g., in Tables 9-16 (see
1529      * https://igs.org/wg/rinex/#documents-formats).
1530      *
1531      * <p>Returns "A" for GALILEO E1A, GALILEO E6A, IRNSS L5A SPS, IRNSS SA SPS, GLONASS G1a L1OCd,
1532      * GLONASS G2a L2CSI.
1533      *
1534      * <p>Returns "B" for GALILEO E1B, GALILEO E6B, IRNSS L5B RS (D), IRNSS SB RS (D), GLONASS G1a
1535      * L1OCp, GLONASS G2a L2OCp, QZSS L1Sb.
1536      *
1537      * <p>Returns "C" for GPS L1 C/A, GPS L2 C/A, GLONASS G1 C/A, GLONASS G2 C/A, GALILEO E1C,
1538      * GALILEO E6C, SBAS L1 C/A, QZSS L1 C/A, IRNSS L5C RS (P), IRNSS SC RS (P).
1539      *
1540      * <p>Returns "D" for GPS L2 (L1(C/A) + (P2-P1) (semi-codeless)), QZSS L5S(I), BDS B1C Data,
1541      * BDS B2a Data, BDS B2b Data, BDS B2 (B2a+B2b) Data, BDS B3a Data.
1542      *
1543      * <p>Returns “E” for QZSS L1 C/B, QZSS L6E.
1544      *
1545      * <p>Returns "I" for GPS L5 I, GLONASS G3 I, GALILEO E5a I, GALILEO E5b I, GALILEO E5a+b I,
1546      * SBAS L5 I, QZSS L5 I, BDS B1 I, BDS B2 I, BDS B3 I.
1547      *
1548      * <p>Returns "L" for GPS L1C (P), GPS L2C (L), QZSS L1C (P), QZSS L2C (L), QZSS L6P, BDS
1549      * B1a Pilot.
1550      *
1551      * <p>Returns "M" for GPS L1M, GPS L2M.
1552      *
1553      * <p>Returns "N" for GPS L1 codeless, GPS L2 codeless.
1554      *
1555      * <p>Returns "P" for GPS L1P, GPS L2P, GLONASS G1P, GLONASS G2P, BDS B1C Pilot, BDS B2a Pilot,
1556      * BDS B2b Pilot, BDS B2 (B2a+B2b) Pilot, BDS B3a Pilot, QZSS L5S(Q).
1557      *
1558      * <p>Returns "Q" for GPS L5 Q, GLONASS G3 Q, GALILEO E5a Q, GALILEO E5b Q, GALILEO E5a+b Q,
1559      * SBAS L5 Q, QZSS L5 Q, BDS B1 Q, BDS B2 Q, BDS B3 Q.
1560      *
1561      * <p>Returns "S" for GPS L1C (D), GPS L2C (M), QZSS L1C (D), QZSS L2C (M), QZSS L6D, BDS B1a
1562      * Data.
1563      *
1564      * <p>Returns "W" for GPS L1 Z-tracking, GPS L2 Z-tracking.
1565      *
1566      * <p>Returns "X" for GPS L1C (D+P), GPS L2C (M+L), GPS L5 (I+Q), GLONASS G1a L1OCd+L1OCp,
1567      * GLONASS G2a L2CSI+L2OCp, GLONASS G3 (I+Q), GALILEO E1 (B+C), GALILEO E5a (I+Q), GALILEO
1568      * E5b (I+Q), GALILEO E5a+b (I+Q), GALILEO E6 (B+C), SBAS L5 (I+Q), QZSS L1C (D+P), QZSS L2C
1569      * (M+L), QZSS L5 (I+Q), QZSS L6 (D+P), BDS B1 (I+Q), BDS B1C Data+Pilot, BDS B2a Data+Pilot,
1570      * BDS B2 (I+Q), BDS B2 (B2a+B2b) Data+Pilot, BDS B3 (I+Q), IRNSS L5 (B+C), IRNSS S (B+C).
1571      *
1572      * <p>Returns "Y" for GPS L1Y, GPS L2Y.
1573      *
1574      * <p>Returns "Z" for GALILEO E1 (A+B+C), GALILEO E6 (A+B+C), QZSS L1S/L1-SAIF, QZSS L5S (I+Q),
1575      * QZSS L6(D+E), BDS B1A Data+Pilot, BDS B2b Data+Pilot, BDS B3a Data+Pilot.
1576      *
1577      * <p>Returns "UNKNOWN" if the GNSS Measurement's code type is unknown.
1578      *
1579      * <p>The code type is used to specify the observation descriptor defined in GNSS Observation
1580      * Data File Header Section Description in the RINEX standard (Version 4.00). In cases where
1581      * the code type does not align with the above listed values, the code type from the most
1582      * recent version of RINEX should be used. For example, if a code type "G" is added, this
1583      * string shall be set to "G".
1584      */
1585     @NonNull
getCodeType()1586     public String getCodeType() {
1587         return mCodeType;
1588     }
1589 
1590     /**
1591      * Sets the GNSS measurement's code type.
1592      *
1593      * @hide
1594      */
1595     @TestApi
setCodeType(@onNull String codeType)1596     public void setCodeType(@NonNull String codeType) {
1597         setFlag(HAS_CODE_TYPE);
1598         mCodeType = codeType;
1599     }
1600 
1601     /**
1602      * Resets the GNSS measurement's code type.
1603      *
1604      * @hide
1605      */
1606     @TestApi
resetCodeType()1607     public void resetCodeType() {
1608         resetFlag(HAS_CODE_TYPE);
1609         mCodeType = "UNKNOWN";
1610     }
1611 
1612     /**
1613      * Returns {@code true} if {@link #getFullInterSignalBiasNanos()} is available,
1614      * {@code false} otherwise.
1615      */
hasFullInterSignalBiasNanos()1616     public boolean hasFullInterSignalBiasNanos() {
1617         return isFlagSet(HAS_FULL_ISB);
1618     }
1619 
1620     /**
1621      * Gets the GNSS measurement's inter-signal bias in nanoseconds with sub-nanosecond accuracy.
1622      *
1623      * <p>This value is the sum of the estimated receiver-side and the space-segment-side
1624      * inter-system bias, inter-frequency bias and inter-code bias, including:
1625      *
1626      * <ul>
1627      * <li>Receiver inter-constellation bias (with respect to the constellation in
1628      * {@link GnssClock#getReferenceConstellationTypeForIsb())</li>
1629      * <li>Receiver inter-frequency bias (with respect to the carrier frequency in
1630      * {@link GnssClock#getReferenceConstellationTypeForIsb())</li>
1631      * <li>Receiver inter-code bias (with respect to the code type in
1632      * {@link GnssClock#getReferenceConstellationTypeForIsb())</li>
1633      * <li>Master clock bias (e.g., GPS-GAL Time Offset (GGTO), GPS-UTC Time Offset (TauGps),
1634      * BDS-GLO Time Offset (BGTO))(with respect to the constellation in
1635      * {@link GnssClock#getReferenceConstellationTypeForIsb())</li>
1636      * <li>Group delay (e.g., Total Group Delay (TGD))</li>
1637      * <li>Satellite inter-frequency bias (GLO only) (with respect to the carrier frequency in
1638      * {@link GnssClock#getReferenceConstellationTypeForIsb())</li>
1639      * <li>Satellite inter-code bias (e.g., Differential Code Bias (DCB)) (with respect to the code
1640      * type in {@link GnssClock#getReferenceConstellationTypeForIsb())</li>
1641      * </ul>
1642      *
1643      * <p>If a component of the above is already compensated in the provided
1644      * {@link GnssMeasurement#getReceivedSvTimeNanos()}, then it must not be included in the
1645      * reported full ISB.
1646      *
1647      * <p>The value does not include the inter-frequency Ionospheric bias.
1648      *
1649      * <p>The sign of the value is defined by the following equation:
1650      * <pre>
1651      *     corrected pseudorange = raw pseudorange - FullInterSignalBiasNanos</pre>
1652      *
1653      * <p>The value is only available if {@link #hasFullInterSignalBiasNanos()} is {@code true}.
1654      */
getFullInterSignalBiasNanos()1655     public double getFullInterSignalBiasNanos() {
1656         return mFullInterSignalBiasNanos;
1657     }
1658 
1659     /**
1660      * Sets the GNSS measurement's inter-signal bias in nanoseconds.
1661      *
1662      * @hide
1663      */
1664     @TestApi
setFullInterSignalBiasNanos(double fullInterSignalBiasNanos)1665     public void setFullInterSignalBiasNanos(double fullInterSignalBiasNanos) {
1666         setFlag(HAS_FULL_ISB);
1667         mFullInterSignalBiasNanos = fullInterSignalBiasNanos;
1668     }
1669 
1670     /**
1671      * Resets the GNSS measurement's inter-signal bias in nanoseconds.
1672      *
1673      * @hide
1674      */
1675     @TestApi
resetFullInterSignalBiasNanos()1676     public void resetFullInterSignalBiasNanos() {
1677         resetFlag(HAS_FULL_ISB);
1678     }
1679 
1680     /**
1681      * Returns {@code true} if {@link #getFullInterSignalBiasUncertaintyNanos()} is available,
1682      * {@code false} otherwise.
1683      */
hasFullInterSignalBiasUncertaintyNanos()1684     public boolean hasFullInterSignalBiasUncertaintyNanos() {
1685         return isFlagSet(HAS_FULL_ISB_UNCERTAINTY);
1686     }
1687 
1688     /**
1689      * Gets the GNSS measurement's inter-signal bias uncertainty (1 sigma) in
1690      * nanoseconds with sub-nanosecond accuracy.
1691      *
1692      * <p>The value is only available if {@link #hasFullInterSignalBiasUncertaintyNanos()} is
1693      * {@code true}.
1694      */
1695     @FloatRange(from = 0.0)
getFullInterSignalBiasUncertaintyNanos()1696     public double getFullInterSignalBiasUncertaintyNanos() {
1697         return mFullInterSignalBiasUncertaintyNanos;
1698     }
1699 
1700     /**
1701      * Sets the GNSS measurement's inter-signal bias uncertainty (1 sigma) in nanoseconds.
1702      *
1703      * @hide
1704      */
1705     @TestApi
setFullInterSignalBiasUncertaintyNanos(@loatRangefrom = 0.0) double fullInterSignalBiasUncertaintyNanos)1706     public void setFullInterSignalBiasUncertaintyNanos(@FloatRange(from = 0.0)
1707             double fullInterSignalBiasUncertaintyNanos) {
1708         setFlag(HAS_FULL_ISB_UNCERTAINTY);
1709         mFullInterSignalBiasUncertaintyNanos = fullInterSignalBiasUncertaintyNanos;
1710     }
1711 
1712     /**
1713      * Resets the GNSS measurement's inter-signal bias uncertainty (1 sigma) in
1714      * nanoseconds.
1715      *
1716      * @hide
1717      */
1718     @TestApi
resetFullInterSignalBiasUncertaintyNanos()1719     public void resetFullInterSignalBiasUncertaintyNanos() {
1720         resetFlag(HAS_FULL_ISB_UNCERTAINTY);
1721     }
1722 
1723     /**
1724      * Returns {@code true} if {@link #getSatelliteInterSignalBiasNanos()} is available,
1725      * {@code false} otherwise.
1726      */
hasSatelliteInterSignalBiasNanos()1727     public boolean hasSatelliteInterSignalBiasNanos() {
1728         return isFlagSet(HAS_SATELLITE_ISB);
1729     }
1730 
1731     /**
1732      * Gets the GNSS measurement's satellite inter-signal bias in nanoseconds with sub-nanosecond
1733      * accuracy.
1734      *
1735      * <p>This value is the space-segment-side inter-system bias, inter-frequency bias and
1736      * inter-code bias, including:
1737      *
1738      * <ul>
1739      * <li>Master clock bias (e.g., GPS-GAL Time Offset (GGTO), GPS-UTC Time Offset (TauGps),
1740      * BDS-GLO Time Offset (BGTO))(with respect to the constellation in
1741      * {@link GnssClock#getReferenceConstellationTypeForIsb())</li>
1742      * <li>Group delay (e.g., Total Group Delay (TGD))</li>
1743      * <li>Satellite inter-frequency bias (GLO only) (with respect to the carrier frequency in
1744      * {@link GnssClock#getReferenceConstellationTypeForIsb())</li>
1745      * <li>Satellite inter-code bias (e.g., Differential Code Bias (DCB)) (with respect to the code
1746      * type in {@link GnssClock#getReferenceConstellationTypeForIsb())</li>
1747      * </ul>
1748      *
1749      * <p>The sign of the value is defined by the following equation:
1750      * <pre>
1751      *     corrected pseudorange = raw pseudorange - SatelliteInterSignalBiasNanos</pre>
1752      *
1753      * <p>The value is only available if {@link #hasSatelliteInterSignalBiasNanos()} is {@code
1754      * true}.
1755      */
getSatelliteInterSignalBiasNanos()1756     public double getSatelliteInterSignalBiasNanos() {
1757         return mSatelliteInterSignalBiasNanos;
1758     }
1759 
1760     /**
1761      * Sets the GNSS measurement's satellite inter-signal bias in nanoseconds.
1762      *
1763      * @hide
1764      */
1765     @TestApi
setSatelliteInterSignalBiasNanos(double satelliteInterSignalBiasNanos)1766     public void setSatelliteInterSignalBiasNanos(double satelliteInterSignalBiasNanos) {
1767         setFlag(HAS_SATELLITE_ISB);
1768         mSatelliteInterSignalBiasNanos = satelliteInterSignalBiasNanos;
1769     }
1770 
1771     /**
1772      * Resets the GNSS measurement's satellite inter-signal bias in nanoseconds.
1773      *
1774      * @hide
1775      */
1776     @TestApi
resetSatelliteInterSignalBiasNanos()1777     public void resetSatelliteInterSignalBiasNanos() {
1778         resetFlag(HAS_SATELLITE_ISB);
1779     }
1780 
1781     /**
1782      * Returns {@code true} if {@link #getSatelliteInterSignalBiasUncertaintyNanos()} is available,
1783      * {@code false} otherwise.
1784      */
hasSatelliteInterSignalBiasUncertaintyNanos()1785     public boolean hasSatelliteInterSignalBiasUncertaintyNanos() {
1786         return isFlagSet(HAS_SATELLITE_ISB_UNCERTAINTY);
1787     }
1788 
1789     /**
1790      * Gets the GNSS measurement's satellite inter-signal bias uncertainty (1 sigma) in
1791      * nanoseconds with sub-nanosecond accuracy.
1792      *
1793      * <p>The value is only available if {@link #hasSatelliteInterSignalBiasUncertaintyNanos()} is
1794      * {@code true}.
1795      */
1796     @FloatRange(from = 0.0)
getSatelliteInterSignalBiasUncertaintyNanos()1797     public double getSatelliteInterSignalBiasUncertaintyNanos() {
1798         return mSatelliteInterSignalBiasUncertaintyNanos;
1799     }
1800 
1801     /**
1802      * Sets the GNSS measurement's satellite inter-signal bias uncertainty (1 sigma) in nanoseconds.
1803      *
1804      * @hide
1805      */
1806     @TestApi
setSatelliteInterSignalBiasUncertaintyNanos(@loatRangefrom = 0.0) double satelliteInterSignalBiasUncertaintyNanos)1807     public void setSatelliteInterSignalBiasUncertaintyNanos(@FloatRange(from = 0.0)
1808             double satelliteInterSignalBiasUncertaintyNanos) {
1809         setFlag(HAS_SATELLITE_ISB_UNCERTAINTY);
1810         mSatelliteInterSignalBiasUncertaintyNanos = satelliteInterSignalBiasUncertaintyNanos;
1811     }
1812 
1813     /**
1814      * Resets the GNSS measurement's satellite inter-signal bias uncertainty (1 sigma) in
1815      * nanoseconds.
1816      *
1817      * @hide
1818      */
1819     @TestApi
resetSatelliteInterSignalBiasUncertaintyNanos()1820     public void resetSatelliteInterSignalBiasUncertaintyNanos() {
1821         resetFlag(HAS_SATELLITE_ISB_UNCERTAINTY);
1822     }
1823 
1824     /**
1825      * Returns {@code true} if {@link #getSatellitePvt()} is available,
1826      * {@code false} otherwise.
1827      *
1828      * @hide
1829      */
1830     @SystemApi
hasSatellitePvt()1831     public boolean hasSatellitePvt() {
1832         return isFlagSet(HAS_SATELLITE_PVT);
1833     }
1834 
1835     /**
1836      * Gets the Satellite PVT data.
1837      *
1838      * <p>The value is only available if {@link #hasSatellitePvt()} is
1839      * {@code true}.
1840      *
1841      * @hide
1842      */
1843     @Nullable
1844     @SystemApi
getSatellitePvt()1845     public SatellitePvt getSatellitePvt() {
1846         return mSatellitePvt;
1847     }
1848 
1849     /**
1850      * Sets the Satellite PVT.
1851      *
1852      * @hide
1853      */
1854     @TestApi
setSatellitePvt(@ullable SatellitePvt satellitePvt)1855     public void setSatellitePvt(@Nullable SatellitePvt satellitePvt) {
1856         if (satellitePvt == null) {
1857             resetSatellitePvt();
1858         } else {
1859             setFlag(HAS_SATELLITE_PVT);
1860             mSatellitePvt = satellitePvt;
1861         }
1862     }
1863 
1864     /**
1865      * Resets the Satellite PVT.
1866      *
1867      * @hide
1868      */
1869     @TestApi
resetSatellitePvt()1870     public void resetSatellitePvt() {
1871         resetFlag(HAS_SATELLITE_PVT);
1872     }
1873 
1874     /**
1875      * Returns {@code true} if {@link #getCorrelationVectors()} is available,
1876      * {@code false} otherwise.
1877      *
1878      * @hide
1879      */
1880     @SystemApi
hasCorrelationVectors()1881     public boolean hasCorrelationVectors() {
1882         return isFlagSet(HAS_CORRELATION_VECTOR);
1883     }
1884 
1885     /**
1886      * Gets read-only collection of CorrelationVector with each CorrelationVector corresponding to a
1887      * frequency offset.
1888      *
1889      * <p>To represent correlation values over a 2D spaces (delay and frequency), a
1890      * CorrelationVector is required per frequency offset, and each CorrelationVector contains
1891      * correlation values at equally spaced spatial offsets.
1892      *
1893      * @hide
1894      */
1895     @Nullable
1896     @SystemApi
1897     @SuppressLint("NullableCollection")
getCorrelationVectors()1898     public Collection<CorrelationVector> getCorrelationVectors() {
1899         return mReadOnlyCorrelationVectors;
1900     }
1901 
1902     /**
1903      * Sets the CorrelationVectors.
1904      *
1905      * @hide
1906      */
1907     @TestApi
setCorrelationVectors( @uppressLintR) @ullable Collection<CorrelationVector> correlationVectors)1908     public void setCorrelationVectors(
1909             @SuppressLint("NullableCollection")
1910             @Nullable Collection<CorrelationVector> correlationVectors) {
1911         if (correlationVectors == null || correlationVectors.isEmpty()) {
1912             resetCorrelationVectors();
1913         } else {
1914             setFlag(HAS_CORRELATION_VECTOR);
1915             mReadOnlyCorrelationVectors = Collections.unmodifiableCollection(correlationVectors);
1916         }
1917     }
1918 
1919     /**
1920      * Resets the CorrelationVectors.
1921      *
1922      * @hide
1923      */
1924     @TestApi
resetCorrelationVectors()1925     public void resetCorrelationVectors() {
1926         resetFlag(HAS_CORRELATION_VECTOR);
1927         mReadOnlyCorrelationVectors = null;
1928     }
1929 
1930     public static final @NonNull Creator<GnssMeasurement> CREATOR = new Creator<GnssMeasurement>() {
1931         @Override
1932         public GnssMeasurement createFromParcel(Parcel parcel) {
1933             GnssMeasurement gnssMeasurement = new GnssMeasurement();
1934 
1935             gnssMeasurement.mFlags = parcel.readInt();
1936             gnssMeasurement.mSvid = parcel.readInt();
1937             gnssMeasurement.mConstellationType = parcel.readInt();
1938             gnssMeasurement.mTimeOffsetNanos = parcel.readDouble();
1939             gnssMeasurement.mState = parcel.readInt();
1940             gnssMeasurement.mReceivedSvTimeNanos = parcel.readLong();
1941             gnssMeasurement.mReceivedSvTimeUncertaintyNanos = parcel.readLong();
1942             gnssMeasurement.mCn0DbHz = parcel.readDouble();
1943             gnssMeasurement.mPseudorangeRateMetersPerSecond = parcel.readDouble();
1944             gnssMeasurement.mPseudorangeRateUncertaintyMetersPerSecond = parcel.readDouble();
1945             gnssMeasurement.mAccumulatedDeltaRangeState = parcel.readInt();
1946             gnssMeasurement.mAccumulatedDeltaRangeMeters = parcel.readDouble();
1947             gnssMeasurement.mAccumulatedDeltaRangeUncertaintyMeters = parcel.readDouble();
1948             gnssMeasurement.mCarrierFrequencyHz = parcel.readFloat();
1949             gnssMeasurement.mCarrierCycles = parcel.readLong();
1950             gnssMeasurement.mCarrierPhase = parcel.readDouble();
1951             gnssMeasurement.mCarrierPhaseUncertainty = parcel.readDouble();
1952             gnssMeasurement.mMultipathIndicator = parcel.readInt();
1953             gnssMeasurement.mSnrInDb = parcel.readDouble();
1954             gnssMeasurement.mAutomaticGainControlLevelInDb = parcel.readDouble();
1955             gnssMeasurement.mCodeType = parcel.readString();
1956             gnssMeasurement.mBasebandCn0DbHz = parcel.readDouble();
1957             gnssMeasurement.mFullInterSignalBiasNanos = parcel.readDouble();
1958             gnssMeasurement.mFullInterSignalBiasUncertaintyNanos = parcel.readDouble();
1959             gnssMeasurement.mSatelliteInterSignalBiasNanos = parcel.readDouble();
1960             gnssMeasurement.mSatelliteInterSignalBiasUncertaintyNanos = parcel.readDouble();
1961             if (gnssMeasurement.hasSatellitePvt()) {
1962                 ClassLoader classLoader = getClass().getClassLoader();
1963                 gnssMeasurement.mSatellitePvt = parcel.readParcelable(classLoader, android.location.SatellitePvt.class);
1964             }
1965             if (gnssMeasurement.hasCorrelationVectors()) {
1966                 CorrelationVector[] correlationVectorsArray =
1967                         new CorrelationVector[parcel.readInt()];
1968                 parcel.readTypedArray(correlationVectorsArray, CorrelationVector.CREATOR);
1969                 Collection<CorrelationVector> corrVecCollection =
1970                         Arrays.asList(correlationVectorsArray);
1971                 gnssMeasurement.mReadOnlyCorrelationVectors =
1972                         Collections.unmodifiableCollection(corrVecCollection);
1973             }
1974             return gnssMeasurement;
1975         }
1976 
1977         @Override
1978         public GnssMeasurement[] newArray(int i) {
1979             return new GnssMeasurement[i];
1980         }
1981     };
1982 
1983     @Override
writeToParcel(Parcel parcel, int flags)1984     public void writeToParcel(Parcel parcel, int flags) {
1985         parcel.writeInt(mFlags);
1986         parcel.writeInt(mSvid);
1987         parcel.writeInt(mConstellationType);
1988         parcel.writeDouble(mTimeOffsetNanos);
1989         parcel.writeInt(mState);
1990         parcel.writeLong(mReceivedSvTimeNanos);
1991         parcel.writeLong(mReceivedSvTimeUncertaintyNanos);
1992         parcel.writeDouble(mCn0DbHz);
1993         parcel.writeDouble(mPseudorangeRateMetersPerSecond);
1994         parcel.writeDouble(mPseudorangeRateUncertaintyMetersPerSecond);
1995         parcel.writeInt(mAccumulatedDeltaRangeState);
1996         parcel.writeDouble(mAccumulatedDeltaRangeMeters);
1997         parcel.writeDouble(mAccumulatedDeltaRangeUncertaintyMeters);
1998         parcel.writeFloat(mCarrierFrequencyHz);
1999         parcel.writeLong(mCarrierCycles);
2000         parcel.writeDouble(mCarrierPhase);
2001         parcel.writeDouble(mCarrierPhaseUncertainty);
2002         parcel.writeInt(mMultipathIndicator);
2003         parcel.writeDouble(mSnrInDb);
2004         parcel.writeDouble(mAutomaticGainControlLevelInDb);
2005         parcel.writeString(mCodeType);
2006         parcel.writeDouble(mBasebandCn0DbHz);
2007         parcel.writeDouble(mFullInterSignalBiasNanos);
2008         parcel.writeDouble(mFullInterSignalBiasUncertaintyNanos);
2009         parcel.writeDouble(mSatelliteInterSignalBiasNanos);
2010         parcel.writeDouble(mSatelliteInterSignalBiasUncertaintyNanos);
2011         if (hasSatellitePvt()) {
2012             parcel.writeParcelable(mSatellitePvt, flags);
2013         }
2014         if (hasCorrelationVectors()) {
2015             int correlationVectorCount = mReadOnlyCorrelationVectors.size();
2016             CorrelationVector[] correlationVectorArray =
2017                 mReadOnlyCorrelationVectors.toArray(new CorrelationVector[correlationVectorCount]);
2018             parcel.writeInt(correlationVectorArray.length);
2019             parcel.writeTypedArray(correlationVectorArray, flags);
2020         }
2021     }
2022 
2023     @Override
describeContents()2024     public int describeContents() {
2025         return 0;
2026     }
2027 
2028     @Override
toString()2029     public String toString() {
2030         final String format = "   %-29s = %s\n";
2031         final String formatWithUncertainty = "   %-29s = %-25s   %-40s = %s\n";
2032         StringBuilder builder = new StringBuilder("GnssMeasurement:\n");
2033 
2034         builder.append(String.format(format, "Svid", mSvid));
2035         builder.append(String.format(format, "ConstellationType", mConstellationType));
2036         builder.append(String.format(format, "TimeOffsetNanos", mTimeOffsetNanos));
2037 
2038         builder.append(String.format(format, "State", getStateString()));
2039 
2040         builder.append(String.format(
2041                 formatWithUncertainty,
2042                 "ReceivedSvTimeNanos",
2043                 mReceivedSvTimeNanos,
2044                 "ReceivedSvTimeUncertaintyNanos",
2045                 mReceivedSvTimeUncertaintyNanos));
2046 
2047         builder.append(String.format(format, "Cn0DbHz", mCn0DbHz));
2048 
2049         if (hasBasebandCn0DbHz()) {
2050             builder.append(String.format(format, "BasebandCn0DbHz", mBasebandCn0DbHz));
2051         }
2052 
2053         builder.append(String.format(
2054                 formatWithUncertainty,
2055                 "PseudorangeRateMetersPerSecond",
2056                 mPseudorangeRateMetersPerSecond,
2057                 "PseudorangeRateUncertaintyMetersPerSecond",
2058                 mPseudorangeRateUncertaintyMetersPerSecond));
2059 
2060         builder.append(String.format(
2061                 format,
2062                 "AccumulatedDeltaRangeState",
2063                 getAccumulatedDeltaRangeStateString()));
2064 
2065         builder.append(String.format(
2066                 formatWithUncertainty,
2067                 "AccumulatedDeltaRangeMeters",
2068                 mAccumulatedDeltaRangeMeters,
2069                 "AccumulatedDeltaRangeUncertaintyMeters",
2070                 mAccumulatedDeltaRangeUncertaintyMeters));
2071 
2072         if (hasCarrierFrequencyHz()) {
2073             builder.append(String.format(format, "CarrierFrequencyHz", mCarrierFrequencyHz));
2074         }
2075 
2076         if (hasCarrierCycles()) {
2077             builder.append(String.format(format, "CarrierCycles", mCarrierCycles));
2078         }
2079 
2080         if (hasCarrierPhase() || hasCarrierPhaseUncertainty()) {
2081             builder.append(String.format(
2082                     formatWithUncertainty,
2083                     "CarrierPhase",
2084                     hasCarrierPhase() ? mCarrierPhase : null,
2085                     "CarrierPhaseUncertainty",
2086                     hasCarrierPhaseUncertainty() ? mCarrierPhaseUncertainty : null));
2087         }
2088 
2089         builder.append(String.format(format, "MultipathIndicator", getMultipathIndicatorString()));
2090 
2091         if (hasSnrInDb()) {
2092             builder.append(String.format(format, "SnrInDb", mSnrInDb));
2093         }
2094 
2095         if (hasAutomaticGainControlLevelDb()) {
2096             builder.append(String.format(format, "AgcLevelDb", mAutomaticGainControlLevelInDb));
2097         }
2098 
2099         if (hasCodeType()) {
2100             builder.append(String.format(format, "CodeType", mCodeType));
2101         }
2102 
2103         if (hasFullInterSignalBiasNanos() || hasFullInterSignalBiasUncertaintyNanos()) {
2104             builder.append(String.format(
2105                     formatWithUncertainty,
2106                     "InterSignalBiasNs",
2107                     hasFullInterSignalBiasNanos() ? mFullInterSignalBiasNanos : null,
2108                     "InterSignalBiasUncertaintyNs",
2109                     hasFullInterSignalBiasUncertaintyNanos()
2110                             ? mFullInterSignalBiasUncertaintyNanos : null));
2111         }
2112 
2113         if (hasSatelliteInterSignalBiasNanos() || hasSatelliteInterSignalBiasUncertaintyNanos()) {
2114             builder.append(String.format(
2115                     formatWithUncertainty,
2116                     "SatelliteInterSignalBiasNs",
2117                     hasSatelliteInterSignalBiasNanos() ? mSatelliteInterSignalBiasNanos : null,
2118                     "SatelliteInterSignalBiasUncertaintyNs",
2119                     hasSatelliteInterSignalBiasUncertaintyNanos()
2120                             ? mSatelliteInterSignalBiasUncertaintyNanos
2121                             : null));
2122         }
2123 
2124         if (hasSatellitePvt()) {
2125             builder.append(mSatellitePvt.toString());
2126         }
2127 
2128         if (hasCorrelationVectors()) {
2129             for (CorrelationVector correlationVector : mReadOnlyCorrelationVectors) {
2130                 builder.append(correlationVector.toString());
2131                 builder.append("\n");
2132             }
2133         }
2134 
2135         return builder.toString();
2136     }
2137 
initialize()2138     private void initialize() {
2139         mFlags = HAS_NO_FLAGS;
2140         setSvid(0);
2141         setTimeOffsetNanos(Long.MIN_VALUE);
2142         setState(STATE_UNKNOWN);
2143         setReceivedSvTimeNanos(Long.MIN_VALUE);
2144         setReceivedSvTimeUncertaintyNanos(Long.MAX_VALUE);
2145         setCn0DbHz(Double.MIN_VALUE);
2146         setPseudorangeRateMetersPerSecond(Double.MIN_VALUE);
2147         setPseudorangeRateUncertaintyMetersPerSecond(Double.MIN_VALUE);
2148         setAccumulatedDeltaRangeState(ADR_STATE_UNKNOWN);
2149         setAccumulatedDeltaRangeMeters(Double.MIN_VALUE);
2150         setAccumulatedDeltaRangeUncertaintyMeters(Double.MIN_VALUE);
2151         resetCarrierFrequencyHz();
2152         resetCarrierCycles();
2153         resetCarrierPhase();
2154         resetCarrierPhaseUncertainty();
2155         setMultipathIndicator(MULTIPATH_INDICATOR_UNKNOWN);
2156         resetSnrInDb();
2157         resetAutomaticGainControlLevel();
2158         resetCodeType();
2159         resetBasebandCn0DbHz();
2160         resetFullInterSignalBiasNanos();
2161         resetFullInterSignalBiasUncertaintyNanos();
2162         resetSatelliteInterSignalBiasNanos();
2163         resetSatelliteInterSignalBiasUncertaintyNanos();
2164         resetSatellitePvt();
2165         resetCorrelationVectors();
2166     }
2167 
setFlag(int flag)2168     private void setFlag(int flag) {
2169         mFlags |= flag;
2170     }
2171 
resetFlag(int flag)2172     private void resetFlag(int flag) {
2173         mFlags &= ~flag;
2174     }
2175 
isFlagSet(int flag)2176     private boolean isFlagSet(int flag) {
2177         return (mFlags & flag) == flag;
2178     }
2179 }
2180