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>NavIC</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, NavIC L5A SPS, NavIC SA SPS, GLONASS G1a L1OCd,
1532      * GLONASS G2a L2CSI.
1533      *
1534      * <p>Returns "B" for GALILEO E1B, GALILEO E6B, NavIC L5B RS (D), NavIC 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, NavIC L5C RS (P), NavIC 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, NavIC L1 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), NavIC L1 Pilot.
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), NavIC L5 (B+C), NavIC S (B+C),
1571      * NavIC L1 Data+Pilot.
1572      *
1573      * <p>Returns "Y" for GPS L1Y, GPS L2Y.
1574      *
1575      * <p>Returns "Z" for GALILEO E1 (A+B+C), GALILEO E6 (A+B+C), QZSS L1S/L1-SAIF, QZSS L5S (I+Q),
1576      * QZSS L6(D+E), BDS B1A Data+Pilot, BDS B2b Data+Pilot, BDS B3a Data+Pilot.
1577      *
1578      * <p>Returns "UNKNOWN" if the GNSS Measurement's code type is unknown.
1579      *
1580      * <p>The code type is used to specify the observation descriptor defined in GNSS Observation
1581      * Data File Header Section Description in the RINEX standard (Version 4.00). In cases where
1582      * the code type does not align with the above listed values, the code type from the most
1583      * recent version of RINEX should be used. For example, if a code type "G" is added, this
1584      * string shall be set to "G".
1585      */
1586     @NonNull
getCodeType()1587     public String getCodeType() {
1588         return mCodeType;
1589     }
1590 
1591     /**
1592      * Sets the GNSS measurement's code type.
1593      *
1594      * @hide
1595      */
1596     @TestApi
setCodeType(@onNull String codeType)1597     public void setCodeType(@NonNull String codeType) {
1598         setFlag(HAS_CODE_TYPE);
1599         mCodeType = codeType;
1600     }
1601 
1602     /**
1603      * Resets the GNSS measurement's code type.
1604      *
1605      * @hide
1606      */
1607     @TestApi
resetCodeType()1608     public void resetCodeType() {
1609         resetFlag(HAS_CODE_TYPE);
1610         mCodeType = "UNKNOWN";
1611     }
1612 
1613     /**
1614      * Returns {@code true} if {@link #getFullInterSignalBiasNanos()} is available,
1615      * {@code false} otherwise.
1616      */
hasFullInterSignalBiasNanos()1617     public boolean hasFullInterSignalBiasNanos() {
1618         return isFlagSet(HAS_FULL_ISB);
1619     }
1620 
1621     /**
1622      * Gets the GNSS measurement's inter-signal bias in nanoseconds with sub-nanosecond accuracy.
1623      *
1624      * <p>This value is the sum of the estimated receiver-side and the space-segment-side
1625      * inter-system bias, inter-frequency bias and inter-code bias, including:
1626      *
1627      * <ul>
1628      * <li>Receiver inter-constellation bias (with respect to the constellation in
1629      * {@link GnssClock#getReferenceConstellationTypeForIsb())</li>
1630      * <li>Receiver inter-frequency bias (with respect to the carrier frequency in
1631      * {@link GnssClock#getReferenceConstellationTypeForIsb())</li>
1632      * <li>Receiver inter-code bias (with respect to the code type in
1633      * {@link GnssClock#getReferenceConstellationTypeForIsb())</li>
1634      * <li>Master clock bias (e.g., GPS-GAL Time Offset (GGTO), GPS-UTC Time Offset (TauGps),
1635      * BDS-GLO Time Offset (BGTO))(with respect to the constellation in
1636      * {@link GnssClock#getReferenceConstellationTypeForIsb())</li>
1637      * <li>Group delay (e.g., Total Group Delay (TGD))</li>
1638      * <li>Satellite inter-frequency bias (GLO only) (with respect to the carrier frequency in
1639      * {@link GnssClock#getReferenceConstellationTypeForIsb())</li>
1640      * <li>Satellite inter-code bias (e.g., Differential Code Bias (DCB)) (with respect to the code
1641      * type in {@link GnssClock#getReferenceConstellationTypeForIsb())</li>
1642      * </ul>
1643      *
1644      * <p>If a component of the above is already compensated in the provided
1645      * {@link GnssMeasurement#getReceivedSvTimeNanos()}, then it must not be included in the
1646      * reported full ISB.
1647      *
1648      * <p>The value does not include the inter-frequency Ionospheric bias.
1649      *
1650      * <p>The sign of the value is defined by the following equation:
1651      * <pre>
1652      *     corrected pseudorange = raw pseudorange - FullInterSignalBiasNanos</pre>
1653      *
1654      * <p>The value is only available if {@link #hasFullInterSignalBiasNanos()} is {@code true}.
1655      */
getFullInterSignalBiasNanos()1656     public double getFullInterSignalBiasNanos() {
1657         return mFullInterSignalBiasNanos;
1658     }
1659 
1660     /**
1661      * Sets the GNSS measurement's inter-signal bias in nanoseconds.
1662      *
1663      * @hide
1664      */
1665     @TestApi
setFullInterSignalBiasNanos(double fullInterSignalBiasNanos)1666     public void setFullInterSignalBiasNanos(double fullInterSignalBiasNanos) {
1667         setFlag(HAS_FULL_ISB);
1668         mFullInterSignalBiasNanos = fullInterSignalBiasNanos;
1669     }
1670 
1671     /**
1672      * Resets the GNSS measurement's inter-signal bias in nanoseconds.
1673      *
1674      * @hide
1675      */
1676     @TestApi
resetFullInterSignalBiasNanos()1677     public void resetFullInterSignalBiasNanos() {
1678         resetFlag(HAS_FULL_ISB);
1679     }
1680 
1681     /**
1682      * Returns {@code true} if {@link #getFullInterSignalBiasUncertaintyNanos()} is available,
1683      * {@code false} otherwise.
1684      */
hasFullInterSignalBiasUncertaintyNanos()1685     public boolean hasFullInterSignalBiasUncertaintyNanos() {
1686         return isFlagSet(HAS_FULL_ISB_UNCERTAINTY);
1687     }
1688 
1689     /**
1690      * Gets the GNSS measurement's inter-signal bias uncertainty (1 sigma) in
1691      * nanoseconds with sub-nanosecond accuracy.
1692      *
1693      * <p>The value is only available if {@link #hasFullInterSignalBiasUncertaintyNanos()} is
1694      * {@code true}.
1695      */
1696     @FloatRange(from = 0.0)
getFullInterSignalBiasUncertaintyNanos()1697     public double getFullInterSignalBiasUncertaintyNanos() {
1698         return mFullInterSignalBiasUncertaintyNanos;
1699     }
1700 
1701     /**
1702      * Sets the GNSS measurement's inter-signal bias uncertainty (1 sigma) in nanoseconds.
1703      *
1704      * @hide
1705      */
1706     @TestApi
setFullInterSignalBiasUncertaintyNanos(@loatRangefrom = 0.0) double fullInterSignalBiasUncertaintyNanos)1707     public void setFullInterSignalBiasUncertaintyNanos(@FloatRange(from = 0.0)
1708             double fullInterSignalBiasUncertaintyNanos) {
1709         setFlag(HAS_FULL_ISB_UNCERTAINTY);
1710         mFullInterSignalBiasUncertaintyNanos = fullInterSignalBiasUncertaintyNanos;
1711     }
1712 
1713     /**
1714      * Resets the GNSS measurement's inter-signal bias uncertainty (1 sigma) in
1715      * nanoseconds.
1716      *
1717      * @hide
1718      */
1719     @TestApi
resetFullInterSignalBiasUncertaintyNanos()1720     public void resetFullInterSignalBiasUncertaintyNanos() {
1721         resetFlag(HAS_FULL_ISB_UNCERTAINTY);
1722     }
1723 
1724     /**
1725      * Returns {@code true} if {@link #getSatelliteInterSignalBiasNanos()} is available,
1726      * {@code false} otherwise.
1727      */
hasSatelliteInterSignalBiasNanos()1728     public boolean hasSatelliteInterSignalBiasNanos() {
1729         return isFlagSet(HAS_SATELLITE_ISB);
1730     }
1731 
1732     /**
1733      * Gets the GNSS measurement's satellite inter-signal bias in nanoseconds with sub-nanosecond
1734      * accuracy.
1735      *
1736      * <p>This value is the space-segment-side inter-system bias, inter-frequency bias and
1737      * inter-code bias, including:
1738      *
1739      * <ul>
1740      * <li>Master clock bias (e.g., GPS-GAL Time Offset (GGTO), GPS-UTC Time Offset (TauGps),
1741      * BDS-GLO Time Offset (BGTO))(with respect to the constellation in
1742      * {@link GnssClock#getReferenceConstellationTypeForIsb())</li>
1743      * <li>Group delay (e.g., Total Group Delay (TGD))</li>
1744      * <li>Satellite inter-frequency bias (GLO only) (with respect to the carrier frequency in
1745      * {@link GnssClock#getReferenceConstellationTypeForIsb())</li>
1746      * <li>Satellite inter-code bias (e.g., Differential Code Bias (DCB)) (with respect to the code
1747      * type in {@link GnssClock#getReferenceConstellationTypeForIsb())</li>
1748      * </ul>
1749      *
1750      * <p>The sign of the value is defined by the following equation:
1751      * <pre>
1752      *     corrected pseudorange = raw pseudorange - SatelliteInterSignalBiasNanos</pre>
1753      *
1754      * <p>The value is only available if {@link #hasSatelliteInterSignalBiasNanos()} is {@code
1755      * true}.
1756      */
getSatelliteInterSignalBiasNanos()1757     public double getSatelliteInterSignalBiasNanos() {
1758         return mSatelliteInterSignalBiasNanos;
1759     }
1760 
1761     /**
1762      * Sets the GNSS measurement's satellite inter-signal bias in nanoseconds.
1763      *
1764      * @hide
1765      */
1766     @TestApi
setSatelliteInterSignalBiasNanos(double satelliteInterSignalBiasNanos)1767     public void setSatelliteInterSignalBiasNanos(double satelliteInterSignalBiasNanos) {
1768         setFlag(HAS_SATELLITE_ISB);
1769         mSatelliteInterSignalBiasNanos = satelliteInterSignalBiasNanos;
1770     }
1771 
1772     /**
1773      * Resets the GNSS measurement's satellite inter-signal bias in nanoseconds.
1774      *
1775      * @hide
1776      */
1777     @TestApi
resetSatelliteInterSignalBiasNanos()1778     public void resetSatelliteInterSignalBiasNanos() {
1779         resetFlag(HAS_SATELLITE_ISB);
1780     }
1781 
1782     /**
1783      * Returns {@code true} if {@link #getSatelliteInterSignalBiasUncertaintyNanos()} is available,
1784      * {@code false} otherwise.
1785      */
hasSatelliteInterSignalBiasUncertaintyNanos()1786     public boolean hasSatelliteInterSignalBiasUncertaintyNanos() {
1787         return isFlagSet(HAS_SATELLITE_ISB_UNCERTAINTY);
1788     }
1789 
1790     /**
1791      * Gets the GNSS measurement's satellite inter-signal bias uncertainty (1 sigma) in
1792      * nanoseconds with sub-nanosecond accuracy.
1793      *
1794      * <p>The value is only available if {@link #hasSatelliteInterSignalBiasUncertaintyNanos()} is
1795      * {@code true}.
1796      */
1797     @FloatRange(from = 0.0)
getSatelliteInterSignalBiasUncertaintyNanos()1798     public double getSatelliteInterSignalBiasUncertaintyNanos() {
1799         return mSatelliteInterSignalBiasUncertaintyNanos;
1800     }
1801 
1802     /**
1803      * Sets the GNSS measurement's satellite inter-signal bias uncertainty (1 sigma) in nanoseconds.
1804      *
1805      * @hide
1806      */
1807     @TestApi
setSatelliteInterSignalBiasUncertaintyNanos(@loatRangefrom = 0.0) double satelliteInterSignalBiasUncertaintyNanos)1808     public void setSatelliteInterSignalBiasUncertaintyNanos(@FloatRange(from = 0.0)
1809             double satelliteInterSignalBiasUncertaintyNanos) {
1810         setFlag(HAS_SATELLITE_ISB_UNCERTAINTY);
1811         mSatelliteInterSignalBiasUncertaintyNanos = satelliteInterSignalBiasUncertaintyNanos;
1812     }
1813 
1814     /**
1815      * Resets the GNSS measurement's satellite inter-signal bias uncertainty (1 sigma) in
1816      * nanoseconds.
1817      *
1818      * @hide
1819      */
1820     @TestApi
resetSatelliteInterSignalBiasUncertaintyNanos()1821     public void resetSatelliteInterSignalBiasUncertaintyNanos() {
1822         resetFlag(HAS_SATELLITE_ISB_UNCERTAINTY);
1823     }
1824 
1825     /**
1826      * Returns {@code true} if {@link #getSatellitePvt()} is available,
1827      * {@code false} otherwise.
1828      *
1829      * @hide
1830      */
1831     @SystemApi
hasSatellitePvt()1832     public boolean hasSatellitePvt() {
1833         return isFlagSet(HAS_SATELLITE_PVT);
1834     }
1835 
1836     /**
1837      * Gets the Satellite PVT data.
1838      *
1839      * <p>The value is only available if {@link #hasSatellitePvt()} is
1840      * {@code true}.
1841      *
1842      * @hide
1843      */
1844     @Nullable
1845     @SystemApi
getSatellitePvt()1846     public SatellitePvt getSatellitePvt() {
1847         return mSatellitePvt;
1848     }
1849 
1850     /**
1851      * Sets the Satellite PVT.
1852      *
1853      * @hide
1854      */
1855     @TestApi
setSatellitePvt(@ullable SatellitePvt satellitePvt)1856     public void setSatellitePvt(@Nullable SatellitePvt satellitePvt) {
1857         if (satellitePvt == null) {
1858             resetSatellitePvt();
1859         } else {
1860             setFlag(HAS_SATELLITE_PVT);
1861             mSatellitePvt = satellitePvt;
1862         }
1863     }
1864 
1865     /**
1866      * Resets the Satellite PVT.
1867      *
1868      * @hide
1869      */
1870     @TestApi
resetSatellitePvt()1871     public void resetSatellitePvt() {
1872         resetFlag(HAS_SATELLITE_PVT);
1873     }
1874 
1875     /**
1876      * Returns {@code true} if {@link #getCorrelationVectors()} is available,
1877      * {@code false} otherwise.
1878      *
1879      * @hide
1880      */
1881     @SystemApi
hasCorrelationVectors()1882     public boolean hasCorrelationVectors() {
1883         return isFlagSet(HAS_CORRELATION_VECTOR);
1884     }
1885 
1886     /**
1887      * Gets read-only collection of CorrelationVector with each CorrelationVector corresponding to a
1888      * frequency offset.
1889      *
1890      * <p>To represent correlation values over a 2D spaces (delay and frequency), a
1891      * CorrelationVector is required per frequency offset, and each CorrelationVector contains
1892      * correlation values at equally spaced spatial offsets.
1893      *
1894      * @hide
1895      */
1896     @Nullable
1897     @SystemApi
1898     @SuppressLint("NullableCollection")
getCorrelationVectors()1899     public Collection<CorrelationVector> getCorrelationVectors() {
1900         return mReadOnlyCorrelationVectors;
1901     }
1902 
1903     /**
1904      * Sets the CorrelationVectors.
1905      *
1906      * @hide
1907      */
1908     @TestApi
setCorrelationVectors( @uppressLint"NullableCollection") @ullable Collection<CorrelationVector> correlationVectors)1909     public void setCorrelationVectors(
1910             @SuppressLint("NullableCollection")
1911             @Nullable Collection<CorrelationVector> correlationVectors) {
1912         if (correlationVectors == null || correlationVectors.isEmpty()) {
1913             resetCorrelationVectors();
1914         } else {
1915             setFlag(HAS_CORRELATION_VECTOR);
1916             mReadOnlyCorrelationVectors = Collections.unmodifiableCollection(correlationVectors);
1917         }
1918     }
1919 
1920     /**
1921      * Resets the CorrelationVectors.
1922      *
1923      * @hide
1924      */
1925     @TestApi
resetCorrelationVectors()1926     public void resetCorrelationVectors() {
1927         resetFlag(HAS_CORRELATION_VECTOR);
1928         mReadOnlyCorrelationVectors = null;
1929     }
1930 
1931     public static final @NonNull Creator<GnssMeasurement> CREATOR = new Creator<GnssMeasurement>() {
1932         @Override
1933         public GnssMeasurement createFromParcel(Parcel parcel) {
1934             GnssMeasurement gnssMeasurement = new GnssMeasurement();
1935 
1936             gnssMeasurement.mFlags = parcel.readInt();
1937             gnssMeasurement.mSvid = parcel.readInt();
1938             gnssMeasurement.mConstellationType = parcel.readInt();
1939             gnssMeasurement.mTimeOffsetNanos = parcel.readDouble();
1940             gnssMeasurement.mState = parcel.readInt();
1941             gnssMeasurement.mReceivedSvTimeNanos = parcel.readLong();
1942             gnssMeasurement.mReceivedSvTimeUncertaintyNanos = parcel.readLong();
1943             gnssMeasurement.mCn0DbHz = parcel.readDouble();
1944             gnssMeasurement.mPseudorangeRateMetersPerSecond = parcel.readDouble();
1945             gnssMeasurement.mPseudorangeRateUncertaintyMetersPerSecond = parcel.readDouble();
1946             gnssMeasurement.mAccumulatedDeltaRangeState = parcel.readInt();
1947             gnssMeasurement.mAccumulatedDeltaRangeMeters = parcel.readDouble();
1948             gnssMeasurement.mAccumulatedDeltaRangeUncertaintyMeters = parcel.readDouble();
1949             gnssMeasurement.mCarrierFrequencyHz = parcel.readFloat();
1950             gnssMeasurement.mCarrierCycles = parcel.readLong();
1951             gnssMeasurement.mCarrierPhase = parcel.readDouble();
1952             gnssMeasurement.mCarrierPhaseUncertainty = parcel.readDouble();
1953             gnssMeasurement.mMultipathIndicator = parcel.readInt();
1954             gnssMeasurement.mSnrInDb = parcel.readDouble();
1955             gnssMeasurement.mAutomaticGainControlLevelInDb = parcel.readDouble();
1956             gnssMeasurement.mCodeType = parcel.readString();
1957             gnssMeasurement.mBasebandCn0DbHz = parcel.readDouble();
1958             gnssMeasurement.mFullInterSignalBiasNanos = parcel.readDouble();
1959             gnssMeasurement.mFullInterSignalBiasUncertaintyNanos = parcel.readDouble();
1960             gnssMeasurement.mSatelliteInterSignalBiasNanos = parcel.readDouble();
1961             gnssMeasurement.mSatelliteInterSignalBiasUncertaintyNanos = parcel.readDouble();
1962             if (gnssMeasurement.hasSatellitePvt()) {
1963                 ClassLoader classLoader = getClass().getClassLoader();
1964                 gnssMeasurement.mSatellitePvt = parcel.readParcelable(classLoader, android.location.SatellitePvt.class);
1965             }
1966             if (gnssMeasurement.hasCorrelationVectors()) {
1967                 CorrelationVector[] correlationVectorsArray =
1968                         new CorrelationVector[parcel.readInt()];
1969                 parcel.readTypedArray(correlationVectorsArray, CorrelationVector.CREATOR);
1970                 Collection<CorrelationVector> corrVecCollection =
1971                         Arrays.asList(correlationVectorsArray);
1972                 gnssMeasurement.mReadOnlyCorrelationVectors =
1973                         Collections.unmodifiableCollection(corrVecCollection);
1974             }
1975             return gnssMeasurement;
1976         }
1977 
1978         @Override
1979         public GnssMeasurement[] newArray(int i) {
1980             return new GnssMeasurement[i];
1981         }
1982     };
1983 
1984     @Override
writeToParcel(Parcel parcel, int flags)1985     public void writeToParcel(Parcel parcel, int flags) {
1986         parcel.writeInt(mFlags);
1987         parcel.writeInt(mSvid);
1988         parcel.writeInt(mConstellationType);
1989         parcel.writeDouble(mTimeOffsetNanos);
1990         parcel.writeInt(mState);
1991         parcel.writeLong(mReceivedSvTimeNanos);
1992         parcel.writeLong(mReceivedSvTimeUncertaintyNanos);
1993         parcel.writeDouble(mCn0DbHz);
1994         parcel.writeDouble(mPseudorangeRateMetersPerSecond);
1995         parcel.writeDouble(mPseudorangeRateUncertaintyMetersPerSecond);
1996         parcel.writeInt(mAccumulatedDeltaRangeState);
1997         parcel.writeDouble(mAccumulatedDeltaRangeMeters);
1998         parcel.writeDouble(mAccumulatedDeltaRangeUncertaintyMeters);
1999         parcel.writeFloat(mCarrierFrequencyHz);
2000         parcel.writeLong(mCarrierCycles);
2001         parcel.writeDouble(mCarrierPhase);
2002         parcel.writeDouble(mCarrierPhaseUncertainty);
2003         parcel.writeInt(mMultipathIndicator);
2004         parcel.writeDouble(mSnrInDb);
2005         parcel.writeDouble(mAutomaticGainControlLevelInDb);
2006         parcel.writeString(mCodeType);
2007         parcel.writeDouble(mBasebandCn0DbHz);
2008         parcel.writeDouble(mFullInterSignalBiasNanos);
2009         parcel.writeDouble(mFullInterSignalBiasUncertaintyNanos);
2010         parcel.writeDouble(mSatelliteInterSignalBiasNanos);
2011         parcel.writeDouble(mSatelliteInterSignalBiasUncertaintyNanos);
2012         if (hasSatellitePvt()) {
2013             parcel.writeParcelable(mSatellitePvt, flags);
2014         }
2015         if (hasCorrelationVectors()) {
2016             int correlationVectorCount = mReadOnlyCorrelationVectors.size();
2017             CorrelationVector[] correlationVectorArray =
2018                 mReadOnlyCorrelationVectors.toArray(new CorrelationVector[correlationVectorCount]);
2019             parcel.writeInt(correlationVectorArray.length);
2020             parcel.writeTypedArray(correlationVectorArray, flags);
2021         }
2022     }
2023 
2024     @Override
describeContents()2025     public int describeContents() {
2026         return 0;
2027     }
2028 
2029     @Override
toString()2030     public String toString() {
2031         final String format = "   %-29s = %s\n";
2032         final String formatWithUncertainty = "   %-29s = %-25s   %-40s = %s\n";
2033         StringBuilder builder = new StringBuilder("GnssMeasurement:\n");
2034 
2035         builder.append(String.format(format, "Svid", mSvid));
2036         builder.append(String.format(format, "ConstellationType", mConstellationType));
2037         builder.append(String.format(format, "TimeOffsetNanos", mTimeOffsetNanos));
2038 
2039         builder.append(String.format(format, "State", getStateString()));
2040 
2041         builder.append(String.format(
2042                 formatWithUncertainty,
2043                 "ReceivedSvTimeNanos",
2044                 mReceivedSvTimeNanos,
2045                 "ReceivedSvTimeUncertaintyNanos",
2046                 mReceivedSvTimeUncertaintyNanos));
2047 
2048         builder.append(String.format(format, "Cn0DbHz", mCn0DbHz));
2049 
2050         if (hasBasebandCn0DbHz()) {
2051             builder.append(String.format(format, "BasebandCn0DbHz", mBasebandCn0DbHz));
2052         }
2053 
2054         builder.append(String.format(
2055                 formatWithUncertainty,
2056                 "PseudorangeRateMetersPerSecond",
2057                 mPseudorangeRateMetersPerSecond,
2058                 "PseudorangeRateUncertaintyMetersPerSecond",
2059                 mPseudorangeRateUncertaintyMetersPerSecond));
2060 
2061         builder.append(String.format(
2062                 format,
2063                 "AccumulatedDeltaRangeState",
2064                 getAccumulatedDeltaRangeStateString()));
2065 
2066         builder.append(String.format(
2067                 formatWithUncertainty,
2068                 "AccumulatedDeltaRangeMeters",
2069                 mAccumulatedDeltaRangeMeters,
2070                 "AccumulatedDeltaRangeUncertaintyMeters",
2071                 mAccumulatedDeltaRangeUncertaintyMeters));
2072 
2073         if (hasCarrierFrequencyHz()) {
2074             builder.append(String.format(format, "CarrierFrequencyHz", mCarrierFrequencyHz));
2075         }
2076 
2077         if (hasCarrierCycles()) {
2078             builder.append(String.format(format, "CarrierCycles", mCarrierCycles));
2079         }
2080 
2081         if (hasCarrierPhase() || hasCarrierPhaseUncertainty()) {
2082             builder.append(String.format(
2083                     formatWithUncertainty,
2084                     "CarrierPhase",
2085                     hasCarrierPhase() ? mCarrierPhase : null,
2086                     "CarrierPhaseUncertainty",
2087                     hasCarrierPhaseUncertainty() ? mCarrierPhaseUncertainty : null));
2088         }
2089 
2090         builder.append(String.format(format, "MultipathIndicator", getMultipathIndicatorString()));
2091 
2092         if (hasSnrInDb()) {
2093             builder.append(String.format(format, "SnrInDb", mSnrInDb));
2094         }
2095 
2096         if (hasAutomaticGainControlLevelDb()) {
2097             builder.append(String.format(format, "AgcLevelDb", mAutomaticGainControlLevelInDb));
2098         }
2099 
2100         if (hasCodeType()) {
2101             builder.append(String.format(format, "CodeType", mCodeType));
2102         }
2103 
2104         if (hasFullInterSignalBiasNanos() || hasFullInterSignalBiasUncertaintyNanos()) {
2105             builder.append(String.format(
2106                     formatWithUncertainty,
2107                     "InterSignalBiasNs",
2108                     hasFullInterSignalBiasNanos() ? mFullInterSignalBiasNanos : null,
2109                     "InterSignalBiasUncertaintyNs",
2110                     hasFullInterSignalBiasUncertaintyNanos()
2111                             ? mFullInterSignalBiasUncertaintyNanos : null));
2112         }
2113 
2114         if (hasSatelliteInterSignalBiasNanos() || hasSatelliteInterSignalBiasUncertaintyNanos()) {
2115             builder.append(String.format(
2116                     formatWithUncertainty,
2117                     "SatelliteInterSignalBiasNs",
2118                     hasSatelliteInterSignalBiasNanos() ? mSatelliteInterSignalBiasNanos : null,
2119                     "SatelliteInterSignalBiasUncertaintyNs",
2120                     hasSatelliteInterSignalBiasUncertaintyNanos()
2121                             ? mSatelliteInterSignalBiasUncertaintyNanos
2122                             : null));
2123         }
2124 
2125         if (hasSatellitePvt()) {
2126             builder.append(mSatellitePvt.toString());
2127         }
2128 
2129         if (hasCorrelationVectors()) {
2130             for (CorrelationVector correlationVector : mReadOnlyCorrelationVectors) {
2131                 builder.append(correlationVector.toString());
2132                 builder.append("\n");
2133             }
2134         }
2135 
2136         return builder.toString();
2137     }
2138 
initialize()2139     private void initialize() {
2140         mFlags = HAS_NO_FLAGS;
2141         setSvid(0);
2142         setTimeOffsetNanos(Long.MIN_VALUE);
2143         setState(STATE_UNKNOWN);
2144         setReceivedSvTimeNanos(Long.MIN_VALUE);
2145         setReceivedSvTimeUncertaintyNanos(Long.MAX_VALUE);
2146         setCn0DbHz(Double.MIN_VALUE);
2147         setPseudorangeRateMetersPerSecond(Double.MIN_VALUE);
2148         setPseudorangeRateUncertaintyMetersPerSecond(Double.MIN_VALUE);
2149         setAccumulatedDeltaRangeState(ADR_STATE_UNKNOWN);
2150         setAccumulatedDeltaRangeMeters(Double.MIN_VALUE);
2151         setAccumulatedDeltaRangeUncertaintyMeters(Double.MIN_VALUE);
2152         resetCarrierFrequencyHz();
2153         resetCarrierCycles();
2154         resetCarrierPhase();
2155         resetCarrierPhaseUncertainty();
2156         setMultipathIndicator(MULTIPATH_INDICATOR_UNKNOWN);
2157         resetSnrInDb();
2158         resetAutomaticGainControlLevel();
2159         resetCodeType();
2160         resetBasebandCn0DbHz();
2161         resetFullInterSignalBiasNanos();
2162         resetFullInterSignalBiasUncertaintyNanos();
2163         resetSatelliteInterSignalBiasNanos();
2164         resetSatelliteInterSignalBiasUncertaintyNanos();
2165         resetSatellitePvt();
2166         resetCorrelationVectors();
2167     }
2168 
setFlag(int flag)2169     private void setFlag(int flag) {
2170         mFlags |= flag;
2171     }
2172 
resetFlag(int flag)2173     private void resetFlag(int flag) {
2174         mFlags &= ~flag;
2175     }
2176 
isFlagSet(int flag)2177     private boolean isFlagSet(int flag) {
2178         return (mFlags & flag) == flag;
2179     }
2180 }
2181