• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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="3"><strong>GPS/QZSS</strong></td>
501      *       <td><strong>GLNS</strong></td>
502      *       <td colspan="2"><strong>BDS</strong></td>
503      *       <td colspan="3"><strong>GAL</strong></td>
504      *       <td><strong>SBAS</strong></td>
505      *     </tr>
506      *     <tr>
507      *       <td><strong>State Flag</strong></td>
508      *       <td><strong>L1 C/A</strong></td>
509      *       <td><strong>L5I</strong></td>
510      *       <td><strong>L5Q</strong></td>
511      *       <td><strong>L1OF</strong></td>
512      *       <td><strong>B1I (D1)</strong></td>
513      *       <td><strong>B1I &nbsp;(D2)</strong></td>
514      *       <td><strong>E1B</strong></td>
515      *       <td><strong>E1C</strong></td>
516      *       <td><strong>E5AQ</strong></td>
517      *       <td><strong>L1 C/A</strong></td>
518      *     </tr>
519      *   </thead>
520      *   <tbody>
521      *     <tr>
522      *       <td>
523      *         <strong>STATE_UNKNOWN</strong>
524      *       </td>
525      *       <td>0</td>
526      *       <td>0</td>
527      *       <td>0</td>
528      *       <td>0</td>
529      *       <td>0</td>
530      *       <td>0</td>
531      *       <td>0</td>
532      *       <td>0</td>
533      *       <td>0</td>
534      *       <td>0</td>
535      *     </tr>
536      *     <tr>
537      *       <td>
538      *         <strong>STATE_CODE_LOCK</strong>
539      *       </td>
540      *       <td>1 ms</td>
541      *       <td>1 ms</td>
542      *       <td>1 ms</td>
543      *       <td>1 ms</td>
544      *       <td>1 ms</td>
545      *       <td>1 ms</td>
546      *       <td>-</td>
547      *       <td>-</td>
548      *       <td>1 ms</td>
549      *       <td>1 ms</td>
550      *     </tr>
551      *     <tr>
552      *       <td>
553      *         <strong>STATE_SYMBOL_SYNC</strong>
554      *       </td>
555      *       <td>20 ms (optional)</td>
556      *       <td>10 ms</td>
557      *       <td>1 ms (optional)</td>
558      *       <td>10 ms</td>
559      *       <td>20 ms (optional)</td>
560      *       <td>2 ms</td>
561      *       <td>4 ms (optional)</td>
562      *       <td>4 ms (optional)</td>
563      *       <td>1 ms (optional)</td>
564      *       <td>2 ms</td>
565      *     </tr>
566      *     <tr>
567      *       <td>
568      *         <strong>STATE_BIT_SYNC</strong>
569      *       </td>
570      *       <td>20 ms</td>
571      *       <td>20 ms</td>
572      *       <td>1 ms (optional)</td>
573      *       <td>20 ms</td>
574      *       <td>20 ms</td>
575      *       <td>-</td>
576      *       <td>8 ms</td>
577      *       <td>-</td>
578      *       <td>1 ms (optional)</td>
579      *       <td>4 ms</td>
580      *     </tr>
581      *     <tr>
582      *       <td>
583      *         <strong>STATE_SUBFRAME_SYNC</strong>
584      *       </td>
585      *       <td>6s</td>
586      *       <td>6s</td>
587      *       <td>-</td>
588      *       <td>2 s</td>
589      *       <td>6 s</td>
590      *       <td>-</td>
591      *       <td>-</td>
592      *       <td>-</td>
593      *       <td>100 ms</td>
594      *       <td>-</td>
595      *     </tr>
596      *     <tr>
597      *       <td>
598      *         <strong>STATE_TOW_DECODED</strong>
599      *       </td>
600      *       <td colspan="2">1 week</td>
601      *       <td>-</td>
602      *       <td>1 day</td>
603      *       <td colspan="2">1 week</td>
604      *       <td colspan="2">1 week</td>
605      *       <td>-</td>
606      *       <td>1 week</td>
607      *     </tr>
608      *     <tr>
609      *       <td>
610      *         <strong>STATE_TOW_KNOWN</strong>
611      *       </td>
612      *       <td colspan="3">1 week</td>
613      *       <td>1 day</td>
614      *       <td colspan="2">1 week</td>
615      *       <td colspan="3">1 week</td>
616      *       <td>1 week</td>
617      *     </tr>
618      *     <tr>
619      *       <td>
620      *         <strong>STATE_GLO_STRING_SYNC</strong>
621      *       </td>
622      *       <td>-</td>
623      *       <td>-</td>
624      *       <td>-</td>
625      *       <td>2 s</td>
626      *       <td>-</td>
627      *       <td>-</td>
628      *       <td>-</td>
629      *       <td>-</td>
630      *       <td>-</td>
631      *       <td>-</td>
632      *     </tr>
633      *     <tr>
634      *       <td>
635      *         <strong>STATE_GLO_TOD_DECODED</strong>
636      *       </td>
637      *       <td>-</td>
638      *       <td>-</td>
639      *       <td>-</td>
640      *       <td>1 day</td>
641      *       <td>-</td>
642      *       <td>-</td>
643      *       <td>-</td>
644      *       <td>-</td>
645      *       <td>-</td>
646      *       <td>-</td>
647      *     </tr>
648      *     <tr>
649      *       <td>
650      *         <strong>STATE_GLO_TOD_KNOWN</strong>
651      *       </td>
652      *       <td>-</td>
653      *       <td>-</td>
654      *       <td>-</td>
655      *       <td>1 day</td>
656      *       <td>-</td>
657      *       <td>-</td>
658      *       <td>-</td>
659      *       <td>-</td>
660      *       <td>-</td>
661      *       <td>-</td>
662      *     </tr>
663      *     <tr>
664      *       <td>
665      *         <strong>STATE_BDS_D2_BIT_SYNC</strong>
666      *       </td>
667      *       <td>-</td>
668      *       <td>-</td>
669      *       <td>-</td>
670      *       <td>-</td>
671      *       <td>-</td>
672      *       <td>2 ms</td>
673      *       <td>-</td>
674      *       <td>-</td>
675      *       <td>-</td>
676      *       <td>-</td>
677      *     </tr>
678      *     <tr>
679      *       <td>
680      *         <strong>STATE_BDS_D2_SUBFRAME_SYNC</strong>
681      *       </td>
682      *       <td>-</td>
683      *       <td>-</td>
684      *       <td>-</td>
685      *       <td>-</td>
686      *       <td>-</td>
687      *       <td>600 ms</td>
688      *       <td>-</td>
689      *       <td>-</td>
690      *       <td>-</td>
691      *       <td>-</td>
692      *     </tr>
693      *     <tr>
694      *       <td>
695      *         <strong>STATE_GAL_E1BC_CODE_LOCK</strong>
696      *       </td>
697      *       <td>-</td>
698      *       <td>-</td>
699      *       <td>-</td>
700      *       <td>-</td>
701      *       <td>-</td>
702      *       <td>-</td>
703      *       <td>4 ms</td>
704      *       <td>4 ms</td>
705      *       <td>-</td>
706      *       <td>-</td>
707      *     </tr>
708      *     <tr>
709      *       <td>
710      *         <strong>STATE_GAL_E1C_2ND_CODE_LOCK</strong>
711      *       </td>
712      *       <td>-</td>
713      *       <td>-</td>
714      *       <td>-</td>
715      *       <td>-</td>
716      *       <td>-</td>
717      *       <td>-</td>
718      *       <td>-</td>
719      *       <td>100 ms</td>
720      *       <td>-</td>
721      *       <td>-</td>
722      *     </tr>
723      *     <tr>
724      *       <td>
725      *         <strong>STATE_2ND_CODE_LOCK</strong>
726      *       </td>
727      *       <td>-</td>
728      *       <td>10 ms (optional)</td>
729      *       <td>20 ms</td>
730      *       <td>-</td>
731      *       <td>-</td>
732      *       <td>-</td>
733      *       <td>-</td>
734      *       <td>100 ms (optional)</td>
735      *       <td>100 ms</td>
736      *       <td>-</td>
737      *     </tr>
738      *     <tr>
739      *       <td>
740      *         <strong>STATE_GAL_E1B_PAGE_SYNC</strong>
741      *       </td>
742      *       <td>-</td>
743      *       <td>-</td>
744      *       <td>-</td>
745      *       <td>-</td>
746      *       <td>-</td>
747      *       <td>-</td>
748      *       <td>2 s</td>
749      *       <td>-</td>
750      *       <td>-</td>
751      *       <td>-</td>
752      *     </tr>
753      *     <tr>
754      *       <td>
755      *         <strong>STATE_SBAS_SYNC</strong>
756      *       </td>
757      *       <td>-</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>1 s</td>
767      *     </tr>
768      *   </tbody>
769      * </table>
770      *
771      * <p>Note: TOW Known refers to the case where TOW is possibly not decoded over the air but has
772      * been determined from other sources. If TOW decoded is set then TOW Known must also be set.
773      *
774      * <p>Note well: if there is any ambiguity in integer millisecond, STATE_MSEC_AMBIGUOUS must be
775      * set accordingly, in the 'state' field. This value must be populated, unless the 'state' ==
776      * STATE_UNKNOWN.
777      *
778      * <p>Note on optional flags:
779      * <ul>
780      *     <li> For L1 C/A and B1I, STATE_SYMBOL_SYNC is optional since the symbol length is the
781      *     same as the bit length.
782      *     <li> For L5Q and E5aQ, STATE_BIT_SYNC and STATE_SYMBOL_SYNC are optional since they are
783      *     implied by STATE_CODE_LOCK.
784      *     <li> STATE_2ND_CODE_LOCK for L5I is optional since it is implied by STATE_SYMBOL_SYNC.
785      *     <li> STATE_2ND_CODE_LOCK for E1C is optional since it is implied by
786      *     STATE_GAL_E1C_2ND_CODE_LOCK.
787      *     <li> For E1B and E1C, STATE_SYMBOL_SYNC is optional, because it is implied by
788      *     STATE_GAL_E1BC_CODE_LOCK.
789      * </ul>
790      */
getReceivedSvTimeNanos()791     public long getReceivedSvTimeNanos() {
792         return mReceivedSvTimeNanos;
793     }
794 
795     /**
796      * Sets the received GNSS time in nanoseconds.
797      * @hide
798      */
799     @TestApi
setReceivedSvTimeNanos(long value)800     public void setReceivedSvTimeNanos(long value) {
801         mReceivedSvTimeNanos = value;
802     }
803 
804     /**
805      * Gets the error estimate (1-sigma) for the received GNSS time, in nanoseconds.
806      */
getReceivedSvTimeUncertaintyNanos()807     public long getReceivedSvTimeUncertaintyNanos() {
808         return mReceivedSvTimeUncertaintyNanos;
809     }
810 
811     /**
812      * Sets the received GNSS time uncertainty (1-Sigma) in nanoseconds.
813      * @hide
814      */
815     @TestApi
setReceivedSvTimeUncertaintyNanos(long value)816     public void setReceivedSvTimeUncertaintyNanos(long value) {
817         mReceivedSvTimeUncertaintyNanos = value;
818     }
819 
820     /**
821      * Gets the Carrier-to-noise density in dB-Hz.
822      *
823      * <p>Typical range: 10-50 dB-Hz. The range of possible C/N0 values is 0-63 dB-Hz to handle
824      * some edge cases.
825      *
826      * <p>The value contains the measured C/N0 for the signal at the antenna input.
827      */
828     @FloatRange(from = 0, to = 63)
getCn0DbHz()829     public double getCn0DbHz() {
830         return mCn0DbHz;
831     }
832 
833     /**
834      * Sets the carrier-to-noise density in dB-Hz.
835      * @hide
836      */
837     @TestApi
setCn0DbHz(double value)838     public void setCn0DbHz(double value) {
839         mCn0DbHz = value;
840     }
841 
842     /**
843      * Returns {@code true} if {@link #getBasebandCn0DbHz()} is available, {@code false} otherwise.
844      */
hasBasebandCn0DbHz()845     public boolean hasBasebandCn0DbHz() {
846         return isFlagSet(HAS_BASEBAND_CN0);
847     }
848 
849     /**
850      * Gets the baseband carrier-to-noise density in dB-Hz.
851      *
852      * <p>Typical range: 10-50 dB-Hz. The range of possible baseband C/N0 values is 0-63 dB-Hz to
853      * handle some edge cases.
854      *
855      * <p>The value contains the measured C/N0 for the signal at the baseband. This is typically
856      * a few dB weaker than the value estimated for C/N0 at the antenna port, which is reported
857      * in {@link #getCn0DbHz()}.
858      */
859     @FloatRange(from = 0, to = 63)
getBasebandCn0DbHz()860     public double getBasebandCn0DbHz() {
861         return mBasebandCn0DbHz;
862     }
863 
864     /**
865      * Sets the baseband carrier-to-noise density in dB-Hz.
866      *
867      * @hide
868      */
869     @TestApi
setBasebandCn0DbHz(double value)870     public void setBasebandCn0DbHz(double value) {
871         setFlag(HAS_BASEBAND_CN0);
872         mBasebandCn0DbHz = value;
873     }
874 
875     /**
876      * Resets the baseband carrier-to-noise density in dB-Hz.
877      *
878      * @hide
879      */
880     @TestApi
resetBasebandCn0DbHz()881     public void resetBasebandCn0DbHz() {
882         resetFlag(HAS_BASEBAND_CN0);
883     }
884 
885     /**
886      * Gets the Pseudorange rate at the timestamp in m/s.
887      *
888      * <p>The error estimate for this value is
889      * {@link #getPseudorangeRateUncertaintyMetersPerSecond()}.
890      *
891      * <p>The value is uncorrected, i.e. corrections for receiver and satellite clock frequency
892      * errors are not included.
893      *
894      * <p>A positive 'uncorrected' value indicates that the SV is moving away from the receiver. The
895      * sign of the 'uncorrected' 'pseudorange rate' and its relation to the sign of 'doppler shift'
896      * is given by the equation:
897      *
898      * <pre>
899      *      pseudorange rate = -k * doppler shift   (where k is a constant)</pre>
900      */
getPseudorangeRateMetersPerSecond()901     public double getPseudorangeRateMetersPerSecond() {
902         return mPseudorangeRateMetersPerSecond;
903     }
904 
905     /**
906      * Sets the pseudorange rate at the timestamp in m/s.
907      * @hide
908      */
909     @TestApi
setPseudorangeRateMetersPerSecond(double value)910     public void setPseudorangeRateMetersPerSecond(double value) {
911         mPseudorangeRateMetersPerSecond = value;
912     }
913 
914     /**
915      * Gets the pseudorange's rate uncertainty (1-Sigma) in m/s.
916      *
917      * <p>The uncertainty is represented as an absolute (single sided) value.
918      */
getPseudorangeRateUncertaintyMetersPerSecond()919     public double getPseudorangeRateUncertaintyMetersPerSecond() {
920         return mPseudorangeRateUncertaintyMetersPerSecond;
921     }
922 
923     /**
924      * Sets the pseudorange's rate uncertainty (1-Sigma) in m/s.
925      * @hide
926      */
927     @TestApi
setPseudorangeRateUncertaintyMetersPerSecond(double value)928     public void setPseudorangeRateUncertaintyMetersPerSecond(double value) {
929         mPseudorangeRateUncertaintyMetersPerSecond = value;
930     }
931 
932     /**
933      * Gets 'Accumulated Delta Range' state.
934      *
935      * <p>This indicates the state of the {@link #getAccumulatedDeltaRangeMeters()} measurement. See
936      * the table below for a detailed interpretation of each state.
937      *
938      * <table border="1">
939      * <thead>
940      * <tr>
941      * <th>ADR_STATE</th>
942      * <th>Time of relevance</th>
943      * <th>Interpretation</th>
944      * </tr>
945      * </thead>
946      * <tbody>
947      * <tr>
948      * <td>UNKNOWN</td>
949      * <td>ADR(t)</td>
950      * <td>No valid carrier phase information is available at time t.</td>
951      * </tr>
952      * <tr>
953      * <td>VALID</td>
954      * <td>ADR(t)</td>
955      * <td>Valid carrier phase information is available at time t. This indicates that this
956      * measurement can be used as a reference for future measurements. However, to compare it to
957      * previous measurements to compute delta range, other bits should be checked. Specifically,
958      * it can be used for delta range computation if it is valid and has no reset or cycle  slip at
959      * this epoch i.e. if VALID_BIT == 1 && CYCLE_SLIP_BIT == 0 && RESET_BIT == 0.</td>
960      * </tr>
961      * <tr>
962      * <td>RESET</td>
963      * <td>ADR(t) - ADR(t-1)</td>
964      * <td>Carrier phase accumulation has been restarted between current time t and previous time
965      * t-1. This indicates that this measurement can be used as a reference for future measurements,
966      * but it should not be compared to previous measurements to compute delta range.</td>
967      * </tr>
968      * <tr>
969      * <td>CYCLE_SLIP</td>
970      * <td>ADR(t) - ADR(t-1)</td>
971      * <td>Cycle slip(s) have been detected between the current time t and previous time t-1. This
972      * indicates that this measurement can be used as a reference for future measurements. Clients
973      * can use a measurement with a cycle slip to compute delta range against previous measurements
974      * at their own risk.</td>
975      * </tr>
976      * <tr>
977      * <td>HALF_CYCLE_RESOLVED</td>
978      * <td>ADR(t)</td>
979      * <td>Half cycle ambiguity is resolved at time t.</td>
980      * </tr>
981      * <tr>
982      * <td>HALF_CYCLE_REPORTED</td>
983      * <td>ADR(t)</td>
984      * <td>Half cycle ambiguity is reported at time t.</td>
985      * </tr>
986      * </tbody>
987      * </table>
988      */
989     @AdrState
getAccumulatedDeltaRangeState()990     public int getAccumulatedDeltaRangeState() {
991         return mAccumulatedDeltaRangeState;
992     }
993 
994     /**
995      * Sets the 'Accumulated Delta Range' state.
996      * @hide
997      */
998     @TestApi
setAccumulatedDeltaRangeState(@drState int value)999     public void setAccumulatedDeltaRangeState(@AdrState int value) {
1000         mAccumulatedDeltaRangeState = value;
1001     }
1002 
1003     /**
1004      * Gets a string representation of the 'Accumulated Delta Range state'.
1005      *
1006      * <p>For internal and logging use only.
1007      */
getAccumulatedDeltaRangeStateString()1008     private String getAccumulatedDeltaRangeStateString() {
1009         if (mAccumulatedDeltaRangeState == ADR_STATE_UNKNOWN) {
1010             return "Unknown";
1011         }
1012         StringBuilder builder = new StringBuilder();
1013         if ((mAccumulatedDeltaRangeState & ADR_STATE_VALID) == ADR_STATE_VALID) {
1014             builder.append("Valid|");
1015         }
1016         if ((mAccumulatedDeltaRangeState & ADR_STATE_RESET) == ADR_STATE_RESET) {
1017             builder.append("Reset|");
1018         }
1019         if ((mAccumulatedDeltaRangeState & ADR_STATE_CYCLE_SLIP) == ADR_STATE_CYCLE_SLIP) {
1020             builder.append("CycleSlip|");
1021         }
1022         if ((mAccumulatedDeltaRangeState & ADR_STATE_HALF_CYCLE_RESOLVED) ==
1023                 ADR_STATE_HALF_CYCLE_RESOLVED) {
1024             builder.append("HalfCycleResolved|");
1025         }
1026         if ((mAccumulatedDeltaRangeState & ADR_STATE_HALF_CYCLE_REPORTED)
1027                 == ADR_STATE_HALF_CYCLE_REPORTED) {
1028             builder.append("HalfCycleReported|");
1029         }
1030         int remainingStates = mAccumulatedDeltaRangeState & ~ADR_STATE_ALL;
1031         if (remainingStates > 0) {
1032             builder.append("Other(");
1033             builder.append(Integer.toBinaryString(remainingStates));
1034             builder.append(")|");
1035         }
1036         builder.deleteCharAt(builder.length() - 1);
1037         return builder.toString();
1038     }
1039 
1040     /**
1041      * Gets the accumulated delta range since the last channel reset, in meters.
1042      *
1043      * <p>The error estimate for this value is {@link #getAccumulatedDeltaRangeUncertaintyMeters()}.
1044      *
1045      * <p>The availability of the value is represented by {@link #getAccumulatedDeltaRangeState()}.
1046      *
1047      * <p>A positive value indicates that the SV is moving away from the receiver.
1048      * The sign of {@link #getAccumulatedDeltaRangeMeters()} and its relation to the sign of
1049      * {@link #getCarrierPhase()} is given by the equation:
1050      *
1051      * <pre>
1052      *          accumulated delta range = -k * carrier phase    (where k is a constant)</pre>
1053      *
1054      * <p>Similar to the concept of an RTCM "Phaserange", when the accumulated delta range is
1055      * initially chosen, and whenever it is reset, it will retain the integer nature
1056      * of the relative carrier phase offset between satellites observed by this receiver, such that
1057      * the double difference of this value between receivers and satellites may be used, together
1058      * with integer ambiguity resolution, to determine highly precise relative location between
1059      * receivers.
1060      *
1061      * <p>The alignment of the phase measurement will not be adjusted by the receiver so the
1062      * in-phase and quadrature phase components will have a quarter cycle offset as they do when
1063      * transmitted from the satellites. If the measurement is from a combination of the in-phase
1064      * and quadrature phase components, then the alignment of the phase measurement will be aligned
1065      * to the in-phase component.
1066      */
getAccumulatedDeltaRangeMeters()1067     public double getAccumulatedDeltaRangeMeters() {
1068         return mAccumulatedDeltaRangeMeters;
1069     }
1070 
1071     /**
1072      * Sets the accumulated delta range in meters.
1073      * @hide
1074      */
1075     @TestApi
setAccumulatedDeltaRangeMeters(double value)1076     public void setAccumulatedDeltaRangeMeters(double value) {
1077         mAccumulatedDeltaRangeMeters = value;
1078     }
1079 
1080     /**
1081      * Gets the accumulated delta range's uncertainty (1-Sigma) in meters.
1082      *
1083      * <p>The uncertainty is represented as an absolute (single sided) value.
1084      *
1085      * <p>The status of the value is represented by {@link #getAccumulatedDeltaRangeState()}.
1086      */
getAccumulatedDeltaRangeUncertaintyMeters()1087     public double getAccumulatedDeltaRangeUncertaintyMeters() {
1088         return mAccumulatedDeltaRangeUncertaintyMeters;
1089     }
1090 
1091     /**
1092      * Sets the accumulated delta range's uncertainty (1-sigma) in meters.
1093      *
1094      * <p>The status of the value is represented by {@link #getAccumulatedDeltaRangeState()}.
1095      *
1096      * @hide
1097      */
1098     @TestApi
setAccumulatedDeltaRangeUncertaintyMeters(double value)1099     public void setAccumulatedDeltaRangeUncertaintyMeters(double value) {
1100         mAccumulatedDeltaRangeUncertaintyMeters = value;
1101     }
1102 
1103     /**
1104      * Returns {@code true} if {@link #getCarrierFrequencyHz()} is available, {@code false}
1105      * otherwise.
1106      */
hasCarrierFrequencyHz()1107     public boolean hasCarrierFrequencyHz() {
1108         return isFlagSet(HAS_CARRIER_FREQUENCY);
1109     }
1110 
1111     /**
1112      * Gets the carrier frequency of the tracked signal.
1113      *
1114      * <p>For example it can be the GPS central frequency for L1 = 1575.45 MHz, or L2 = 1227.60 MHz,
1115      * L5 = 1176.45 MHz, varying GLO channels, etc.
1116      *
1117      * <p>The value is only available if {@link #hasCarrierFrequencyHz()} is {@code true}.
1118      *
1119      * @return the carrier frequency of the signal tracked in Hz.
1120      */
getCarrierFrequencyHz()1121     public float getCarrierFrequencyHz() {
1122         return mCarrierFrequencyHz;
1123     }
1124 
1125     /**
1126      * Sets the Carrier frequency in Hz.
1127      * @hide
1128      */
1129     @TestApi
setCarrierFrequencyHz(float carrierFrequencyHz)1130     public void setCarrierFrequencyHz(float carrierFrequencyHz) {
1131         setFlag(HAS_CARRIER_FREQUENCY);
1132         mCarrierFrequencyHz = carrierFrequencyHz;
1133     }
1134 
1135     /**
1136      * Resets the Carrier frequency in Hz.
1137      * @hide
1138      */
1139     @TestApi
resetCarrierFrequencyHz()1140     public void resetCarrierFrequencyHz() {
1141         resetFlag(HAS_CARRIER_FREQUENCY);
1142         mCarrierFrequencyHz = Float.NaN;
1143     }
1144 
1145     /**
1146      * Returns {@code true} if {@link #getCarrierCycles()} is available, {@code false} otherwise.
1147      *
1148      * @deprecated use {@link #getAccumulatedDeltaRangeState()} instead.
1149      */
1150     @Deprecated
hasCarrierCycles()1151     public boolean hasCarrierCycles() {
1152         return isFlagSet(HAS_CARRIER_CYCLES);
1153     }
1154 
1155     /**
1156      * The number of full carrier cycles between the satellite and the receiver.
1157      *
1158      * <p>The reference frequency is given by the value of {@link #getCarrierFrequencyHz()}.
1159      *
1160      * <p>The value is only available if {@link #hasCarrierCycles()} is {@code true}.
1161      *
1162      * @deprecated use {@link #getAccumulatedDeltaRangeMeters()} instead.
1163      */
1164     @Deprecated
getCarrierCycles()1165     public long getCarrierCycles() {
1166         return mCarrierCycles;
1167     }
1168 
1169     /**
1170      * Sets the number of full carrier cycles between the satellite and the receiver.
1171      *
1172      * @deprecated use {@link #setAccumulatedDeltaRangeMeters(double)}
1173      * and {@link #setAccumulatedDeltaRangeState(int)} instead.
1174      *
1175      * @hide
1176      */
1177     @TestApi
1178     @Deprecated
setCarrierCycles(long value)1179     public void setCarrierCycles(long value) {
1180         setFlag(HAS_CARRIER_CYCLES);
1181         mCarrierCycles = value;
1182     }
1183 
1184     /**
1185      * Resets the number of full carrier cycles between the satellite and the receiver.
1186      *
1187      * @deprecated use {@link #setAccumulatedDeltaRangeMeters(double)}
1188      * and {@link #setAccumulatedDeltaRangeState(int)} instead.
1189      * @hide
1190      */
1191     @TestApi
1192     @Deprecated
resetCarrierCycles()1193     public void resetCarrierCycles() {
1194         resetFlag(HAS_CARRIER_CYCLES);
1195         mCarrierCycles = Long.MIN_VALUE;
1196     }
1197 
1198     /**
1199      * Returns {@code true} if {@link #getCarrierPhase()} is available, {@code false} otherwise.
1200      *
1201      * @deprecated use {@link #getAccumulatedDeltaRangeState()} instead.
1202      */
1203     @Deprecated
hasCarrierPhase()1204     public boolean hasCarrierPhase() {
1205         return isFlagSet(HAS_CARRIER_PHASE);
1206     }
1207 
1208     /**
1209      * Gets the RF phase detected by the receiver.
1210      *
1211      * <p>Range: [0.0, 1.0].
1212      *
1213      * <p>This is the fractional part of the complete carrier phase measurement.
1214      *
1215      * <p>The reference frequency is given by the value of {@link #getCarrierFrequencyHz()}.
1216      *
1217      * <p>The error estimate for this value is {@link #getCarrierPhaseUncertainty()}.
1218      *
1219      * <p>The value is only available if {@link #hasCarrierPhase()} is {@code true}.
1220      *
1221      * @deprecated use {@link #getAccumulatedDeltaRangeMeters()} instead.
1222      */
1223     @Deprecated
getCarrierPhase()1224     public double getCarrierPhase() {
1225         return mCarrierPhase;
1226     }
1227 
1228     /**
1229      * Sets the RF phase detected by the receiver.
1230      *
1231      * @deprecated use {@link #setAccumulatedDeltaRangeMeters(double)}
1232      * and {@link #setAccumulatedDeltaRangeState(int)} instead.
1233      *
1234      * @hide
1235      */
1236     @TestApi
1237     @Deprecated
setCarrierPhase(double value)1238     public void setCarrierPhase(double value) {
1239         setFlag(HAS_CARRIER_PHASE);
1240         mCarrierPhase = value;
1241     }
1242 
1243     /**
1244      * Resets the RF phase detected by the receiver.
1245      *
1246      * @deprecated use {@link #setAccumulatedDeltaRangeMeters(double)}
1247      * and {@link #setAccumulatedDeltaRangeState(int)} instead.
1248      *
1249      * @hide
1250      */
1251     @TestApi
1252     @Deprecated
resetCarrierPhase()1253     public void resetCarrierPhase() {
1254         resetFlag(HAS_CARRIER_PHASE);
1255     }
1256 
1257     /**
1258      * Returns {@code true} if {@link #getCarrierPhaseUncertainty()} is available, {@code false}
1259      * otherwise.
1260      *
1261      * @deprecated use {@link #getAccumulatedDeltaRangeState()} instead.
1262      */
1263     @Deprecated
hasCarrierPhaseUncertainty()1264     public boolean hasCarrierPhaseUncertainty() {
1265         return isFlagSet(HAS_CARRIER_PHASE_UNCERTAINTY);
1266     }
1267 
1268     /**
1269      * Gets the carrier-phase's uncertainty (1-Sigma).
1270      *
1271      * <p>The uncertainty is represented as an absolute (single sided) value.
1272      *
1273      * <p>The value is only available if {@link #hasCarrierPhaseUncertainty()} is {@code true}.
1274      *
1275      * @deprecated use {@link #getAccumulatedDeltaRangeUncertaintyMeters()} instead.
1276      */
1277     @Deprecated
getCarrierPhaseUncertainty()1278     public double getCarrierPhaseUncertainty() {
1279         return mCarrierPhaseUncertainty;
1280     }
1281 
1282     /**
1283      * Sets the Carrier-phase's uncertainty (1-Sigma) in cycles.
1284      *
1285      * @deprecated use {@link #setAccumulatedDeltaRangeUncertaintyMeters(double)}
1286      * and {@link #setAccumulatedDeltaRangeState(int)} instead.
1287      *
1288      * @hide
1289      */
1290     @TestApi
1291     @Deprecated
setCarrierPhaseUncertainty(double value)1292     public void setCarrierPhaseUncertainty(double value) {
1293         setFlag(HAS_CARRIER_PHASE_UNCERTAINTY);
1294         mCarrierPhaseUncertainty = value;
1295     }
1296 
1297     /**
1298      * Resets the Carrier-phase's uncertainty (1-Sigma) in cycles.
1299      *
1300      * @deprecated use {@link #setAccumulatedDeltaRangeUncertaintyMeters(double)}
1301      * and {@link #setAccumulatedDeltaRangeState(int)} instead.
1302      *
1303      * @hide
1304      */
1305     @TestApi
1306     @Deprecated
resetCarrierPhaseUncertainty()1307     public void resetCarrierPhaseUncertainty() {
1308         resetFlag(HAS_CARRIER_PHASE_UNCERTAINTY);
1309     }
1310 
1311     /**
1312      * Gets a value indicating the 'multipath' state of the event.
1313      */
1314     @MultipathIndicator
getMultipathIndicator()1315     public int getMultipathIndicator() {
1316         return mMultipathIndicator;
1317     }
1318 
1319     /**
1320      * Sets the 'multi-path' indicator.
1321      * @hide
1322      */
1323     @TestApi
setMultipathIndicator(@ultipathIndicator int value)1324     public void setMultipathIndicator(@MultipathIndicator int value) {
1325         mMultipathIndicator = value;
1326     }
1327 
1328     /**
1329      * Gets a string representation of the 'multi-path indicator'.
1330      *
1331      * <p>For internal and logging use only.
1332      */
getMultipathIndicatorString()1333     private String getMultipathIndicatorString() {
1334         switch (mMultipathIndicator) {
1335             case MULTIPATH_INDICATOR_UNKNOWN:
1336                 return "Unknown";
1337             case MULTIPATH_INDICATOR_DETECTED:
1338                 return "Detected";
1339             case MULTIPATH_INDICATOR_NOT_DETECTED:
1340                 return "NotDetected";
1341             default:
1342                 return "<Invalid: " + mMultipathIndicator + ">";
1343         }
1344     }
1345 
1346     /**
1347      * Returns {@code true} if {@link #getSnrInDb()} is available, {@code false} otherwise.
1348      */
hasSnrInDb()1349     public boolean hasSnrInDb() {
1350         return isFlagSet(HAS_SNR);
1351     }
1352 
1353     /**
1354      * Gets the (post-correlation & integration) Signal-to-Noise ratio (SNR) in dB.
1355      *
1356      * <p>The value is only available if {@link #hasSnrInDb()} is {@code true}.
1357      */
getSnrInDb()1358     public double getSnrInDb() {
1359         return mSnrInDb;
1360     }
1361 
1362     /**
1363      * Sets the Signal-to-noise ratio (SNR) in dB.
1364      * @hide
1365      */
1366     @TestApi
setSnrInDb(double snrInDb)1367     public void setSnrInDb(double snrInDb) {
1368         setFlag(HAS_SNR);
1369         mSnrInDb = snrInDb;
1370     }
1371 
1372     /**
1373      * Resets the Signal-to-noise ratio (SNR) in dB.
1374      * @hide
1375      */
1376     @TestApi
resetSnrInDb()1377     public void resetSnrInDb() {
1378         resetFlag(HAS_SNR);
1379     }
1380 
1381     /**
1382      * Returns {@code true} if {@link #getAutomaticGainControlLevelDb()} is available,
1383      * {@code false} otherwise.
1384      */
hasAutomaticGainControlLevelDb()1385     public boolean hasAutomaticGainControlLevelDb() {
1386         return isFlagSet(HAS_AUTOMATIC_GAIN_CONTROL);
1387     }
1388 
1389     /**
1390      * Gets the Automatic Gain Control level in dB.
1391      *
1392      * <p> AGC acts as a variable gain amplifier adjusting the power of the incoming signal. The AGC
1393      * level may be used to indicate potential interference. Higher gain (and/or lower input power)
1394      * shall be output as a positive number. Hence in cases of strong jamming, in the band of this
1395      * signal, this value will go more negative. This value must be consistent given the same level
1396      * of the incoming signal power.
1397      *
1398      * <p> Note: Different hardware designs (e.g. antenna, pre-amplification, or other RF HW
1399      * components) may also affect the typical output of of this value on any given hardware design
1400      * in an open sky test - the important aspect of this output is that changes in this value are
1401      * indicative of changes on input signal power in the frequency band for this measurement.
1402      *
1403      * <p> The value is only available if {@link #hasAutomaticGainControlLevelDb()} is {@code true}
1404      */
getAutomaticGainControlLevelDb()1405     public double getAutomaticGainControlLevelDb() {
1406         return mAutomaticGainControlLevelInDb;
1407     }
1408 
1409     /**
1410      * Sets the Automatic Gain Control level in dB.
1411      * @hide
1412      */
1413     @TestApi
setAutomaticGainControlLevelInDb(double agcLevelDb)1414     public void setAutomaticGainControlLevelInDb(double agcLevelDb) {
1415         setFlag(HAS_AUTOMATIC_GAIN_CONTROL);
1416         mAutomaticGainControlLevelInDb = agcLevelDb;
1417     }
1418 
1419     /**
1420      * Resets the Automatic Gain Control level.
1421      * @hide
1422      */
1423     @TestApi
resetAutomaticGainControlLevel()1424     public void resetAutomaticGainControlLevel() {
1425         resetFlag(HAS_AUTOMATIC_GAIN_CONTROL);
1426     }
1427 
1428     /**
1429      * Returns {@code true} if {@link #getCodeType()} is available,
1430      * {@code false} otherwise.
1431      */
hasCodeType()1432     public boolean hasCodeType() {
1433         return isFlagSet(HAS_CODE_TYPE);
1434     }
1435 
1436     /**
1437      * Gets the GNSS measurement's code type.
1438      *
1439      * <p>Similar to the Attribute field described in RINEX 3.03, e.g., in Tables 4-10, and Table
1440      * A2 at the RINEX 3.03 Update 1 Document.
1441      *
1442      * <p>Returns "A" for GALILEO E1A, GALILEO E6A, IRNSS L5A, IRNSS SA.
1443      *
1444      * <p>Returns "B" for GALILEO E1B, GALILEO E6B, IRNSS L5B, IRNSS SB.
1445      *
1446      * <p>Returns "C" for GPS L1 C/A,  GPS L2 C/A, GLONASS G1 C/A, GLONASS G2 C/A, GALILEO E1C,
1447      * GALILEO E6C, SBAS L1 C/A, QZSS L1 C/A, IRNSS L5C.
1448      *
1449      * <p>Returns "D" for BDS B1C D.
1450      *
1451      * <p>Returns "I" for GPS L5 I, GLONASS G3 I, GALILEO E5a I, GALILEO E5b I, GALILEO E5a+b I,
1452      * SBAS L5 I, QZSS L5 I, BDS B1 I, BDS B2 I, BDS B3 I.
1453      *
1454      * <p>Returns "L" for GPS L1C (P), GPS L2C (L), QZSS L1C (P), QZSS L2C (L), LEX(6) L.
1455      *
1456      * <p>Returns "M" for GPS L1M, GPS L2M.
1457      *
1458      * <p>Returns "N" for GPS L1 codeless, GPS L2 codeless.
1459      *
1460      * <p>Returns "P" for GPS L1P, GPS L2P, GLONASS G1P, GLONASS G2P, BDS B1C P.
1461      *
1462      * <p>Returns "Q" for GPS L5 Q, GLONASS G3 Q, GALILEO E5a Q, GALILEO E5b Q, GALILEO E5a+b Q,
1463      * SBAS L5 Q, QZSS L5 Q, BDS B1 Q, BDS B2 Q, BDS B3 Q.
1464      *
1465      * <p>Returns "S" for GPS L1C (D), GPS L2C (M), QZSS L1C (D), QZSS L2C (M), LEX(6) S.
1466      *
1467      * <p>Returns "W" for GPS L1 Z-tracking, GPS L2 Z-tracking.
1468      *
1469      * <p>Returns "X" for GPS L1C (D+P), GPS L2C (M+L), GPS L5 (I+Q), GLONASS G3 (I+Q), GALILEO
1470      * E1 (B+C), GALILEO E5a (I+Q), GALILEO E5b (I+Q), GALILEO E5a+b(I+Q), GALILEO E6 (B+C), SBAS
1471      * L5 (I+Q), QZSS L1C (D+P), QZSS L2C (M+L), QZSS L5 (I+Q), LEX(6) (S+L), BDS B1 (I+Q), BDS
1472      * B1C (D+P), BDS B2 (I+Q), BDS B3 (I+Q), IRNSS L5 (B+C).
1473      *
1474      * <p>Returns "Y" for GPS L1Y, GPS L2Y.
1475      *
1476      * <p>Returns "Z" for GALILEO E1 (A+B+C), GALILEO E6 (A+B+C), QZSS L1-SAIF.
1477      *
1478      * <p>Returns "UNKNOWN" if the GNSS Measurement's code type is unknown.
1479      *
1480      * <p>This is used to specify the observation descriptor defined in GNSS Observation Data File
1481      * Header Section Description in the RINEX standard (Version 3.XX), in cases where the code type
1482      * does not align with the above listed values. For example, if a code type "G" is added, this
1483      * string shall be set to "G".
1484      */
1485     @NonNull
getCodeType()1486     public String getCodeType() {
1487         return mCodeType;
1488     }
1489 
1490     /**
1491      * Sets the GNSS measurement's code type.
1492      *
1493      * @hide
1494      */
1495     @TestApi
setCodeType(@onNull String codeType)1496     public void setCodeType(@NonNull String codeType) {
1497         setFlag(HAS_CODE_TYPE);
1498         mCodeType = codeType;
1499     }
1500 
1501     /**
1502      * Resets the GNSS measurement's code type.
1503      *
1504      * @hide
1505      */
1506     @TestApi
resetCodeType()1507     public void resetCodeType() {
1508         resetFlag(HAS_CODE_TYPE);
1509         mCodeType = "UNKNOWN";
1510     }
1511 
1512     /**
1513      * Returns {@code true} if {@link #getFullInterSignalBiasNanos()} is available,
1514      * {@code false} otherwise.
1515      */
hasFullInterSignalBiasNanos()1516     public boolean hasFullInterSignalBiasNanos() {
1517         return isFlagSet(HAS_FULL_ISB);
1518     }
1519 
1520     /**
1521      * Gets the GNSS measurement's inter-signal bias in nanoseconds with sub-nanosecond accuracy.
1522      *
1523      * <p>This value is the sum of the estimated receiver-side and the space-segment-side
1524      * inter-system bias, inter-frequency bias and inter-code bias, including:
1525      *
1526      * <ul>
1527      * <li>Receiver inter-constellation bias (with respect to the constellation in
1528      * {@link GnssClock#getReferenceConstellationTypeForIsb())</li>
1529      * <li>Receiver inter-frequency bias (with respect to the carrier frequency in
1530      * {@link GnssClock#getReferenceConstellationTypeForIsb())</li>
1531      * <li>Receiver inter-code bias (with respect to the code type in
1532      * {@link GnssClock#getReferenceConstellationTypeForIsb())</li>
1533      * <li>Master clock bias (e.g., GPS-GAL Time Offset (GGTO), GPS-UTC Time Offset (TauGps),
1534      * BDS-GLO Time Offset (BGTO))(with respect to the constellation in
1535      * {@link GnssClock#getReferenceConstellationTypeForIsb())</li>
1536      * <li>Group delay (e.g., Total Group Delay (TGD))</li>
1537      * <li>Satellite inter-frequency bias (GLO only) (with respect to the carrier frequency in
1538      * {@link GnssClock#getReferenceConstellationTypeForIsb())</li>
1539      * <li>Satellite inter-code bias (e.g., Differential Code Bias (DCB)) (with respect to the code
1540      * type in {@link GnssClock#getReferenceConstellationTypeForIsb())</li>
1541      * </ul>
1542      *
1543      * <p>If a component of the above is already compensated in the provided
1544      * {@link GnssMeasurement#getReceivedSvTimeNanos()}, then it must not be included in the
1545      * reported full ISB.
1546      *
1547      * <p>The value does not include the inter-frequency Ionospheric bias.
1548      *
1549      * <p>The sign of the value is defined by the following equation:
1550      * <pre>
1551      *     corrected pseudorange = raw pseudorange - FullInterSignalBiasNanos</pre>
1552      *
1553      * <p>The value is only available if {@link #hasFullInterSignalBiasNanos()} is {@code true}.
1554      */
getFullInterSignalBiasNanos()1555     public double getFullInterSignalBiasNanos() {
1556         return mFullInterSignalBiasNanos;
1557     }
1558 
1559     /**
1560      * Sets the GNSS measurement's inter-signal bias in nanoseconds.
1561      *
1562      * @hide
1563      */
1564     @TestApi
setFullInterSignalBiasNanos(double fullInterSignalBiasNanos)1565     public void setFullInterSignalBiasNanos(double fullInterSignalBiasNanos) {
1566         setFlag(HAS_FULL_ISB);
1567         mFullInterSignalBiasNanos = fullInterSignalBiasNanos;
1568     }
1569 
1570     /**
1571      * Resets the GNSS measurement's inter-signal bias in nanoseconds.
1572      *
1573      * @hide
1574      */
1575     @TestApi
resetFullInterSignalBiasNanos()1576     public void resetFullInterSignalBiasNanos() {
1577         resetFlag(HAS_FULL_ISB);
1578     }
1579 
1580     /**
1581      * Returns {@code true} if {@link #getFullInterSignalBiasUncertaintyNanos()} is available,
1582      * {@code false} otherwise.
1583      */
hasFullInterSignalBiasUncertaintyNanos()1584     public boolean hasFullInterSignalBiasUncertaintyNanos() {
1585         return isFlagSet(HAS_FULL_ISB_UNCERTAINTY);
1586     }
1587 
1588     /**
1589      * Gets the GNSS measurement's inter-signal bias uncertainty (1 sigma) in
1590      * nanoseconds with sub-nanosecond accuracy.
1591      *
1592      * <p>The value is only available if {@link #hasFullInterSignalBiasUncertaintyNanos()} is
1593      * {@code true}.
1594      */
1595     @FloatRange(from = 0.0)
getFullInterSignalBiasUncertaintyNanos()1596     public double getFullInterSignalBiasUncertaintyNanos() {
1597         return mFullInterSignalBiasUncertaintyNanos;
1598     }
1599 
1600     /**
1601      * Sets the GNSS measurement's inter-signal bias uncertainty (1 sigma) in nanoseconds.
1602      *
1603      * @hide
1604      */
1605     @TestApi
setFullInterSignalBiasUncertaintyNanos(@loatRangefrom = 0.0) double fullInterSignalBiasUncertaintyNanos)1606     public void setFullInterSignalBiasUncertaintyNanos(@FloatRange(from = 0.0)
1607             double fullInterSignalBiasUncertaintyNanos) {
1608         setFlag(HAS_FULL_ISB_UNCERTAINTY);
1609         mFullInterSignalBiasUncertaintyNanos = fullInterSignalBiasUncertaintyNanos;
1610     }
1611 
1612     /**
1613      * Resets the GNSS measurement's inter-signal bias uncertainty (1 sigma) in
1614      * nanoseconds.
1615      *
1616      * @hide
1617      */
1618     @TestApi
resetFullInterSignalBiasUncertaintyNanos()1619     public void resetFullInterSignalBiasUncertaintyNanos() {
1620         resetFlag(HAS_FULL_ISB_UNCERTAINTY);
1621     }
1622 
1623     /**
1624      * Returns {@code true} if {@link #getSatelliteInterSignalBiasNanos()} is available,
1625      * {@code false} otherwise.
1626      */
hasSatelliteInterSignalBiasNanos()1627     public boolean hasSatelliteInterSignalBiasNanos() {
1628         return isFlagSet(HAS_SATELLITE_ISB);
1629     }
1630 
1631     /**
1632      * Gets the GNSS measurement's satellite inter-signal bias in nanoseconds with sub-nanosecond
1633      * accuracy.
1634      *
1635      * <p>This value is the space-segment-side inter-system bias, inter-frequency bias and
1636      * inter-code bias, including:
1637      *
1638      * <ul>
1639      * <li>Master clock bias (e.g., GPS-GAL Time Offset (GGTO), GPS-UTC Time Offset (TauGps),
1640      * BDS-GLO Time Offset (BGTO))(with respect to the constellation in
1641      * {@link GnssClock#getReferenceConstellationTypeForIsb())</li>
1642      * <li>Group delay (e.g., Total Group Delay (TGD))</li>
1643      * <li>Satellite inter-frequency bias (GLO only) (with respect to the carrier frequency in
1644      * {@link GnssClock#getReferenceConstellationTypeForIsb())</li>
1645      * <li>Satellite inter-code bias (e.g., Differential Code Bias (DCB)) (with respect to the code
1646      * type in {@link GnssClock#getReferenceConstellationTypeForIsb())</li>
1647      * </ul>
1648      *
1649      * <p>The sign of the value is defined by the following equation:
1650      * <pre>
1651      *     corrected pseudorange = raw pseudorange - SatelliteInterSignalBiasNanos</pre>
1652      *
1653      * <p>The value is only available if {@link #hasSatelliteInterSignalBiasNanos()} is {@code
1654      * true}.
1655      */
getSatelliteInterSignalBiasNanos()1656     public double getSatelliteInterSignalBiasNanos() {
1657         return mSatelliteInterSignalBiasNanos;
1658     }
1659 
1660     /**
1661      * Sets the GNSS measurement's satellite inter-signal bias in nanoseconds.
1662      *
1663      * @hide
1664      */
1665     @TestApi
setSatelliteInterSignalBiasNanos(double satelliteInterSignalBiasNanos)1666     public void setSatelliteInterSignalBiasNanos(double satelliteInterSignalBiasNanos) {
1667         setFlag(HAS_SATELLITE_ISB);
1668         mSatelliteInterSignalBiasNanos = satelliteInterSignalBiasNanos;
1669     }
1670 
1671     /**
1672      * Resets the GNSS measurement's satellite inter-signal bias in nanoseconds.
1673      *
1674      * @hide
1675      */
1676     @TestApi
resetSatelliteInterSignalBiasNanos()1677     public void resetSatelliteInterSignalBiasNanos() {
1678         resetFlag(HAS_SATELLITE_ISB);
1679     }
1680 
1681     /**
1682      * Returns {@code true} if {@link #getSatelliteInterSignalBiasUncertaintyNanos()} is available,
1683      * {@code false} otherwise.
1684      */
hasSatelliteInterSignalBiasUncertaintyNanos()1685     public boolean hasSatelliteInterSignalBiasUncertaintyNanos() {
1686         return isFlagSet(HAS_SATELLITE_ISB_UNCERTAINTY);
1687     }
1688 
1689     /**
1690      * Gets the GNSS measurement's satellite inter-signal bias uncertainty (1 sigma) in
1691      * nanoseconds with sub-nanosecond accuracy.
1692      *
1693      * <p>The value is only available if {@link #hasSatelliteInterSignalBiasUncertaintyNanos()} is
1694      * {@code true}.
1695      */
1696     @FloatRange(from = 0.0)
getSatelliteInterSignalBiasUncertaintyNanos()1697     public double getSatelliteInterSignalBiasUncertaintyNanos() {
1698         return mSatelliteInterSignalBiasUncertaintyNanos;
1699     }
1700 
1701     /**
1702      * Sets the GNSS measurement's satellite inter-signal bias uncertainty (1 sigma) in nanoseconds.
1703      *
1704      * @hide
1705      */
1706     @TestApi
setSatelliteInterSignalBiasUncertaintyNanos(@loatRangefrom = 0.0) double satelliteInterSignalBiasUncertaintyNanos)1707     public void setSatelliteInterSignalBiasUncertaintyNanos(@FloatRange(from = 0.0)
1708             double satelliteInterSignalBiasUncertaintyNanos) {
1709         setFlag(HAS_SATELLITE_ISB_UNCERTAINTY);
1710         mSatelliteInterSignalBiasUncertaintyNanos = satelliteInterSignalBiasUncertaintyNanos;
1711     }
1712 
1713     /**
1714      * Resets the GNSS measurement's satellite inter-signal bias uncertainty (1 sigma) in
1715      * nanoseconds.
1716      *
1717      * @hide
1718      */
1719     @TestApi
resetSatelliteInterSignalBiasUncertaintyNanos()1720     public void resetSatelliteInterSignalBiasUncertaintyNanos() {
1721         resetFlag(HAS_SATELLITE_ISB_UNCERTAINTY);
1722     }
1723 
1724     /**
1725      * Returns {@code true} if {@link #getSatellitePvt()} is available,
1726      * {@code false} otherwise.
1727      *
1728      * @hide
1729      */
1730     @SystemApi
hasSatellitePvt()1731     public boolean hasSatellitePvt() {
1732         return isFlagSet(HAS_SATELLITE_PVT);
1733     }
1734 
1735     /**
1736      * Gets the Satellite PVT data.
1737      *
1738      * <p>The value is only available if {@link #hasSatellitePvt()} is
1739      * {@code true}.
1740      *
1741      * @hide
1742      */
1743     @Nullable
1744     @SystemApi
getSatellitePvt()1745     public SatellitePvt getSatellitePvt() {
1746         return mSatellitePvt;
1747     }
1748 
1749     /**
1750      * Sets the Satellite PVT.
1751      *
1752      * @hide
1753      */
1754     @TestApi
setSatellitePvt(@ullable SatellitePvt satellitePvt)1755     public void setSatellitePvt(@Nullable SatellitePvt satellitePvt) {
1756         if (satellitePvt == null) {
1757             resetSatellitePvt();
1758         } else {
1759             setFlag(HAS_SATELLITE_PVT);
1760             mSatellitePvt = satellitePvt;
1761         }
1762     }
1763 
1764     /**
1765      * Resets the Satellite PVT.
1766      *
1767      * @hide
1768      */
1769     @TestApi
resetSatellitePvt()1770     public void resetSatellitePvt() {
1771         resetFlag(HAS_SATELLITE_PVT);
1772     }
1773 
1774     /**
1775      * Returns {@code true} if {@link #getCorrelationVectors()} is available,
1776      * {@code false} otherwise.
1777      *
1778      * @hide
1779      */
1780     @SystemApi
hasCorrelationVectors()1781     public boolean hasCorrelationVectors() {
1782         return isFlagSet(HAS_CORRELATION_VECTOR);
1783     }
1784 
1785     /**
1786      * Gets read-only collection of CorrelationVector with each CorrelationVector corresponding to a
1787      * frequency offset.
1788      *
1789      * <p>To represent correlation values over a 2D spaces (delay and frequency), a
1790      * CorrelationVector is required per frequency offset, and each CorrelationVector contains
1791      * correlation values at equally spaced spatial offsets.
1792      *
1793      * @hide
1794      */
1795     @Nullable
1796     @SystemApi
1797     @SuppressLint("NullableCollection")
getCorrelationVectors()1798     public Collection<CorrelationVector> getCorrelationVectors() {
1799         return mReadOnlyCorrelationVectors;
1800     }
1801 
1802     /**
1803      * Sets the CorrelationVectors.
1804      *
1805      * @hide
1806      */
1807     @TestApi
setCorrelationVectors( @uppressLint"NullableCollection") @ullable Collection<CorrelationVector> correlationVectors)1808     public void setCorrelationVectors(
1809             @SuppressLint("NullableCollection")
1810             @Nullable Collection<CorrelationVector> correlationVectors) {
1811         if (correlationVectors == null || correlationVectors.isEmpty()) {
1812             resetCorrelationVectors();
1813         } else {
1814             setFlag(HAS_CORRELATION_VECTOR);
1815             mReadOnlyCorrelationVectors = Collections.unmodifiableCollection(correlationVectors);
1816         }
1817     }
1818 
1819     /**
1820      * Resets the CorrelationVectors.
1821      *
1822      * @hide
1823      */
1824     @TestApi
resetCorrelationVectors()1825     public void resetCorrelationVectors() {
1826         resetFlag(HAS_CORRELATION_VECTOR);
1827         mReadOnlyCorrelationVectors = null;
1828     }
1829 
1830     public static final @NonNull Creator<GnssMeasurement> CREATOR = new Creator<GnssMeasurement>() {
1831         @Override
1832         public GnssMeasurement createFromParcel(Parcel parcel) {
1833             GnssMeasurement gnssMeasurement = new GnssMeasurement();
1834 
1835             gnssMeasurement.mFlags = parcel.readInt();
1836             gnssMeasurement.mSvid = parcel.readInt();
1837             gnssMeasurement.mConstellationType = parcel.readInt();
1838             gnssMeasurement.mTimeOffsetNanos = parcel.readDouble();
1839             gnssMeasurement.mState = parcel.readInt();
1840             gnssMeasurement.mReceivedSvTimeNanos = parcel.readLong();
1841             gnssMeasurement.mReceivedSvTimeUncertaintyNanos = parcel.readLong();
1842             gnssMeasurement.mCn0DbHz = parcel.readDouble();
1843             gnssMeasurement.mPseudorangeRateMetersPerSecond = parcel.readDouble();
1844             gnssMeasurement.mPseudorangeRateUncertaintyMetersPerSecond = parcel.readDouble();
1845             gnssMeasurement.mAccumulatedDeltaRangeState = parcel.readInt();
1846             gnssMeasurement.mAccumulatedDeltaRangeMeters = parcel.readDouble();
1847             gnssMeasurement.mAccumulatedDeltaRangeUncertaintyMeters = parcel.readDouble();
1848             gnssMeasurement.mCarrierFrequencyHz = parcel.readFloat();
1849             gnssMeasurement.mCarrierCycles = parcel.readLong();
1850             gnssMeasurement.mCarrierPhase = parcel.readDouble();
1851             gnssMeasurement.mCarrierPhaseUncertainty = parcel.readDouble();
1852             gnssMeasurement.mMultipathIndicator = parcel.readInt();
1853             gnssMeasurement.mSnrInDb = parcel.readDouble();
1854             gnssMeasurement.mAutomaticGainControlLevelInDb = parcel.readDouble();
1855             gnssMeasurement.mCodeType = parcel.readString();
1856             gnssMeasurement.mBasebandCn0DbHz = parcel.readDouble();
1857             gnssMeasurement.mFullInterSignalBiasNanos = parcel.readDouble();
1858             gnssMeasurement.mFullInterSignalBiasUncertaintyNanos = parcel.readDouble();
1859             gnssMeasurement.mSatelliteInterSignalBiasNanos = parcel.readDouble();
1860             gnssMeasurement.mSatelliteInterSignalBiasUncertaintyNanos = parcel.readDouble();
1861             if (gnssMeasurement.hasSatellitePvt()) {
1862                 ClassLoader classLoader = getClass().getClassLoader();
1863                 gnssMeasurement.mSatellitePvt = parcel.readParcelable(classLoader);
1864             }
1865             if (gnssMeasurement.hasCorrelationVectors()) {
1866                 CorrelationVector[] correlationVectorsArray =
1867                         new CorrelationVector[parcel.readInt()];
1868                 parcel.readTypedArray(correlationVectorsArray, CorrelationVector.CREATOR);
1869                 Collection<CorrelationVector> corrVecCollection =
1870                         Arrays.asList(correlationVectorsArray);
1871                 gnssMeasurement.mReadOnlyCorrelationVectors =
1872                         Collections.unmodifiableCollection(corrVecCollection);
1873             }
1874             return gnssMeasurement;
1875         }
1876 
1877         @Override
1878         public GnssMeasurement[] newArray(int i) {
1879             return new GnssMeasurement[i];
1880         }
1881     };
1882 
1883     @Override
writeToParcel(Parcel parcel, int flags)1884     public void writeToParcel(Parcel parcel, int flags) {
1885         parcel.writeInt(mFlags);
1886         parcel.writeInt(mSvid);
1887         parcel.writeInt(mConstellationType);
1888         parcel.writeDouble(mTimeOffsetNanos);
1889         parcel.writeInt(mState);
1890         parcel.writeLong(mReceivedSvTimeNanos);
1891         parcel.writeLong(mReceivedSvTimeUncertaintyNanos);
1892         parcel.writeDouble(mCn0DbHz);
1893         parcel.writeDouble(mPseudorangeRateMetersPerSecond);
1894         parcel.writeDouble(mPseudorangeRateUncertaintyMetersPerSecond);
1895         parcel.writeInt(mAccumulatedDeltaRangeState);
1896         parcel.writeDouble(mAccumulatedDeltaRangeMeters);
1897         parcel.writeDouble(mAccumulatedDeltaRangeUncertaintyMeters);
1898         parcel.writeFloat(mCarrierFrequencyHz);
1899         parcel.writeLong(mCarrierCycles);
1900         parcel.writeDouble(mCarrierPhase);
1901         parcel.writeDouble(mCarrierPhaseUncertainty);
1902         parcel.writeInt(mMultipathIndicator);
1903         parcel.writeDouble(mSnrInDb);
1904         parcel.writeDouble(mAutomaticGainControlLevelInDb);
1905         parcel.writeString(mCodeType);
1906         parcel.writeDouble(mBasebandCn0DbHz);
1907         parcel.writeDouble(mFullInterSignalBiasNanos);
1908         parcel.writeDouble(mFullInterSignalBiasUncertaintyNanos);
1909         parcel.writeDouble(mSatelliteInterSignalBiasNanos);
1910         parcel.writeDouble(mSatelliteInterSignalBiasUncertaintyNanos);
1911         if (hasSatellitePvt()) {
1912             parcel.writeParcelable(mSatellitePvt, flags);
1913         }
1914         if (hasCorrelationVectors()) {
1915             int correlationVectorCount = mReadOnlyCorrelationVectors.size();
1916             CorrelationVector[] correlationVectorArray =
1917                 mReadOnlyCorrelationVectors.toArray(new CorrelationVector[correlationVectorCount]);
1918             parcel.writeInt(correlationVectorArray.length);
1919             parcel.writeTypedArray(correlationVectorArray, flags);
1920         }
1921     }
1922 
1923     @Override
describeContents()1924     public int describeContents() {
1925         return 0;
1926     }
1927 
1928     @Override
toString()1929     public String toString() {
1930         final String format = "   %-29s = %s\n";
1931         final String formatWithUncertainty = "   %-29s = %-25s   %-40s = %s\n";
1932         StringBuilder builder = new StringBuilder("GnssMeasurement:\n");
1933 
1934         builder.append(String.format(format, "Svid", mSvid));
1935         builder.append(String.format(format, "ConstellationType", mConstellationType));
1936         builder.append(String.format(format, "TimeOffsetNanos", mTimeOffsetNanos));
1937 
1938         builder.append(String.format(format, "State", getStateString()));
1939 
1940         builder.append(String.format(
1941                 formatWithUncertainty,
1942                 "ReceivedSvTimeNanos",
1943                 mReceivedSvTimeNanos,
1944                 "ReceivedSvTimeUncertaintyNanos",
1945                 mReceivedSvTimeUncertaintyNanos));
1946 
1947         builder.append(String.format(format, "Cn0DbHz", mCn0DbHz));
1948 
1949         if (hasBasebandCn0DbHz()) {
1950             builder.append(String.format(format, "BasebandCn0DbHz", mBasebandCn0DbHz));
1951         }
1952 
1953         builder.append(String.format(
1954                 formatWithUncertainty,
1955                 "PseudorangeRateMetersPerSecond",
1956                 mPseudorangeRateMetersPerSecond,
1957                 "PseudorangeRateUncertaintyMetersPerSecond",
1958                 mPseudorangeRateUncertaintyMetersPerSecond));
1959 
1960         builder.append(String.format(
1961                 format,
1962                 "AccumulatedDeltaRangeState",
1963                 getAccumulatedDeltaRangeStateString()));
1964 
1965         builder.append(String.format(
1966                 formatWithUncertainty,
1967                 "AccumulatedDeltaRangeMeters",
1968                 mAccumulatedDeltaRangeMeters,
1969                 "AccumulatedDeltaRangeUncertaintyMeters",
1970                 mAccumulatedDeltaRangeUncertaintyMeters));
1971 
1972         if (hasCarrierFrequencyHz()) {
1973             builder.append(String.format(format, "CarrierFrequencyHz", mCarrierFrequencyHz));
1974         }
1975 
1976         if (hasCarrierCycles()) {
1977             builder.append(String.format(format, "CarrierCycles", mCarrierCycles));
1978         }
1979 
1980         if (hasCarrierPhase() || hasCarrierPhaseUncertainty()) {
1981             builder.append(String.format(
1982                     formatWithUncertainty,
1983                     "CarrierPhase",
1984                     hasCarrierPhase() ? mCarrierPhase : null,
1985                     "CarrierPhaseUncertainty",
1986                     hasCarrierPhaseUncertainty() ? mCarrierPhaseUncertainty : null));
1987         }
1988 
1989         builder.append(String.format(format, "MultipathIndicator", getMultipathIndicatorString()));
1990 
1991         if (hasSnrInDb()) {
1992             builder.append(String.format(format, "SnrInDb", mSnrInDb));
1993         }
1994 
1995         if (hasAutomaticGainControlLevelDb()) {
1996             builder.append(String.format(format, "AgcLevelDb", mAutomaticGainControlLevelInDb));
1997         }
1998 
1999         if (hasCodeType()) {
2000             builder.append(String.format(format, "CodeType", mCodeType));
2001         }
2002 
2003         if (hasFullInterSignalBiasNanos() || hasFullInterSignalBiasUncertaintyNanos()) {
2004             builder.append(String.format(
2005                     formatWithUncertainty,
2006                     "InterSignalBiasNs",
2007                     hasFullInterSignalBiasNanos() ? mFullInterSignalBiasNanos : null,
2008                     "InterSignalBiasUncertaintyNs",
2009                     hasFullInterSignalBiasUncertaintyNanos()
2010                             ? mFullInterSignalBiasUncertaintyNanos : null));
2011         }
2012 
2013         if (hasSatelliteInterSignalBiasNanos() || hasSatelliteInterSignalBiasUncertaintyNanos()) {
2014             builder.append(String.format(
2015                     formatWithUncertainty,
2016                     "SatelliteInterSignalBiasNs",
2017                     hasSatelliteInterSignalBiasNanos() ? mSatelliteInterSignalBiasNanos : null,
2018                     "SatelliteInterSignalBiasUncertaintyNs",
2019                     hasSatelliteInterSignalBiasUncertaintyNanos()
2020                             ? mSatelliteInterSignalBiasUncertaintyNanos
2021                             : null));
2022         }
2023 
2024         if (hasSatellitePvt()) {
2025             builder.append(mSatellitePvt.toString());
2026         }
2027 
2028         if (hasCorrelationVectors()) {
2029             for (CorrelationVector correlationVector : mReadOnlyCorrelationVectors) {
2030                 builder.append(correlationVector.toString());
2031                 builder.append("\n");
2032             }
2033         }
2034 
2035         return builder.toString();
2036     }
2037 
initialize()2038     private void initialize() {
2039         mFlags = HAS_NO_FLAGS;
2040         setSvid(0);
2041         setTimeOffsetNanos(Long.MIN_VALUE);
2042         setState(STATE_UNKNOWN);
2043         setReceivedSvTimeNanos(Long.MIN_VALUE);
2044         setReceivedSvTimeUncertaintyNanos(Long.MAX_VALUE);
2045         setCn0DbHz(Double.MIN_VALUE);
2046         setPseudorangeRateMetersPerSecond(Double.MIN_VALUE);
2047         setPseudorangeRateUncertaintyMetersPerSecond(Double.MIN_VALUE);
2048         setAccumulatedDeltaRangeState(ADR_STATE_UNKNOWN);
2049         setAccumulatedDeltaRangeMeters(Double.MIN_VALUE);
2050         setAccumulatedDeltaRangeUncertaintyMeters(Double.MIN_VALUE);
2051         resetCarrierFrequencyHz();
2052         resetCarrierCycles();
2053         resetCarrierPhase();
2054         resetCarrierPhaseUncertainty();
2055         setMultipathIndicator(MULTIPATH_INDICATOR_UNKNOWN);
2056         resetSnrInDb();
2057         resetAutomaticGainControlLevel();
2058         resetCodeType();
2059         resetBasebandCn0DbHz();
2060         resetFullInterSignalBiasNanos();
2061         resetFullInterSignalBiasUncertaintyNanos();
2062         resetSatelliteInterSignalBiasNanos();
2063         resetSatelliteInterSignalBiasUncertaintyNanos();
2064         resetSatellitePvt();
2065         resetCorrelationVectors();
2066     }
2067 
setFlag(int flag)2068     private void setFlag(int flag) {
2069         mFlags |= flag;
2070     }
2071 
resetFlag(int flag)2072     private void resetFlag(int flag) {
2073         mFlags &= ~flag;
2074     }
2075 
isFlagSet(int flag)2076     private boolean isFlagSet(int flag) {
2077         return (mFlags & flag) == flag;
2078     }
2079 }
2080