• 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      *
1385      * @deprecated Use {@link GnssMeasurementsEvent#getGnssAutomaticGainControls()} instead.
1386      */
1387     @Deprecated
hasAutomaticGainControlLevelDb()1388     public boolean hasAutomaticGainControlLevelDb() {
1389         return isFlagSet(HAS_AUTOMATIC_GAIN_CONTROL);
1390     }
1391 
1392     /**
1393      * Gets the Automatic Gain Control level in dB.
1394      *
1395      * <p> AGC acts as a variable gain amplifier adjusting the power of the incoming signal. The AGC
1396      * level may be used to indicate potential interference. Higher gain (and/or lower input power)
1397      * shall be output as a positive number. Hence in cases of strong jamming, in the band of this
1398      * signal, this value will go more negative. This value must be consistent given the same level
1399      * of the incoming signal power.
1400      *
1401      * <p> Note: Different hardware designs (e.g. antenna, pre-amplification, or other RF HW
1402      * components) may also affect the typical output of of this value on any given hardware design
1403      * in an open sky test - the important aspect of this output is that changes in this value are
1404      * indicative of changes on input signal power in the frequency band for this measurement.
1405      *
1406      * <p> The value is only available if {@link #hasAutomaticGainControlLevelDb()} is {@code true}
1407      *
1408      * @deprecated Use {@link GnssMeasurementsEvent#getGnssAutomaticGainControls()} instead.
1409      */
1410     @Deprecated
getAutomaticGainControlLevelDb()1411     public double getAutomaticGainControlLevelDb() {
1412         return mAutomaticGainControlLevelInDb;
1413     }
1414 
1415     /**
1416      * Sets the Automatic Gain Control level in dB.
1417      * @hide
1418      * @deprecated Use {@link GnssMeasurementsEvent.Builder#setGnssAutomaticGainControls()} instead.
1419      */
1420     @Deprecated
1421     @TestApi
setAutomaticGainControlLevelInDb(double agcLevelDb)1422     public void setAutomaticGainControlLevelInDb(double agcLevelDb) {
1423         setFlag(HAS_AUTOMATIC_GAIN_CONTROL);
1424         mAutomaticGainControlLevelInDb = agcLevelDb;
1425     }
1426 
1427     /**
1428      * Resets the Automatic Gain Control level.
1429      * @hide
1430      */
1431     @TestApi
resetAutomaticGainControlLevel()1432     public void resetAutomaticGainControlLevel() {
1433         resetFlag(HAS_AUTOMATIC_GAIN_CONTROL);
1434     }
1435 
1436     /**
1437      * Returns {@code true} if {@link #getCodeType()} is available,
1438      * {@code false} otherwise.
1439      */
hasCodeType()1440     public boolean hasCodeType() {
1441         return isFlagSet(HAS_CODE_TYPE);
1442     }
1443 
1444     /**
1445      * Gets the GNSS measurement's code type.
1446      *
1447      * <p>Similar to the Attribute field described in RINEX 3.03, e.g., in Tables 4-10, and Table
1448      * A2 at the RINEX 3.03 Update 1 Document.
1449      *
1450      * <p>Returns "A" for GALILEO E1A, GALILEO E6A, IRNSS L5A, IRNSS SA.
1451      *
1452      * <p>Returns "B" for GALILEO E1B, GALILEO E6B, IRNSS L5B, IRNSS SB.
1453      *
1454      * <p>Returns "C" for GPS L1 C/A,  GPS L2 C/A, GLONASS G1 C/A, GLONASS G2 C/A, GALILEO E1C,
1455      * GALILEO E6C, SBAS L1 C/A, QZSS L1 C/A, IRNSS L5C.
1456      *
1457      * <p>Returns "D" for BDS B1C D.
1458      *
1459      * <p>Returns "I" for GPS L5 I, GLONASS G3 I, GALILEO E5a I, GALILEO E5b I, GALILEO E5a+b I,
1460      * SBAS L5 I, QZSS L5 I, BDS B1 I, BDS B2 I, BDS B3 I.
1461      *
1462      * <p>Returns "L" for GPS L1C (P), GPS L2C (L), QZSS L1C (P), QZSS L2C (L), LEX(6) L.
1463      *
1464      * <p>Returns "M" for GPS L1M, GPS L2M.
1465      *
1466      * <p>Returns "N" for GPS L1 codeless, GPS L2 codeless.
1467      *
1468      * <p>Returns "P" for GPS L1P, GPS L2P, GLONASS G1P, GLONASS G2P, BDS B1C P.
1469      *
1470      * <p>Returns "Q" for GPS L5 Q, GLONASS G3 Q, GALILEO E5a Q, GALILEO E5b Q, GALILEO E5a+b Q,
1471      * SBAS L5 Q, QZSS L5 Q, BDS B1 Q, BDS B2 Q, BDS B3 Q.
1472      *
1473      * <p>Returns "S" for GPS L1C (D), GPS L2C (M), QZSS L1C (D), QZSS L2C (M), LEX(6) S.
1474      *
1475      * <p>Returns "W" for GPS L1 Z-tracking, GPS L2 Z-tracking.
1476      *
1477      * <p>Returns "X" for GPS L1C (D+P), GPS L2C (M+L), GPS L5 (I+Q), GLONASS G3 (I+Q), GALILEO
1478      * E1 (B+C), GALILEO E5a (I+Q), GALILEO E5b (I+Q), GALILEO E5a+b(I+Q), GALILEO E6 (B+C), SBAS
1479      * L5 (I+Q), QZSS L1C (D+P), QZSS L2C (M+L), QZSS L5 (I+Q), LEX(6) (S+L), BDS B1 (I+Q), BDS
1480      * B1C (D+P), BDS B2 (I+Q), BDS B3 (I+Q), IRNSS L5 (B+C).
1481      *
1482      * <p>Returns "Y" for GPS L1Y, GPS L2Y.
1483      *
1484      * <p>Returns "Z" for GALILEO E1 (A+B+C), GALILEO E6 (A+B+C), QZSS L1-SAIF.
1485      *
1486      * <p>Returns "UNKNOWN" if the GNSS Measurement's code type is unknown.
1487      *
1488      * <p>This is used to specify the observation descriptor defined in GNSS Observation Data File
1489      * Header Section Description in the RINEX standard (Version 3.XX), in cases where the code type
1490      * does not align with the above listed values. For example, if a code type "G" is added, this
1491      * string shall be set to "G".
1492      */
1493     @NonNull
getCodeType()1494     public String getCodeType() {
1495         return mCodeType;
1496     }
1497 
1498     /**
1499      * Sets the GNSS measurement's code type.
1500      *
1501      * @hide
1502      */
1503     @TestApi
setCodeType(@onNull String codeType)1504     public void setCodeType(@NonNull String codeType) {
1505         setFlag(HAS_CODE_TYPE);
1506         mCodeType = codeType;
1507     }
1508 
1509     /**
1510      * Resets the GNSS measurement's code type.
1511      *
1512      * @hide
1513      */
1514     @TestApi
resetCodeType()1515     public void resetCodeType() {
1516         resetFlag(HAS_CODE_TYPE);
1517         mCodeType = "UNKNOWN";
1518     }
1519 
1520     /**
1521      * Returns {@code true} if {@link #getFullInterSignalBiasNanos()} is available,
1522      * {@code false} otherwise.
1523      */
hasFullInterSignalBiasNanos()1524     public boolean hasFullInterSignalBiasNanos() {
1525         return isFlagSet(HAS_FULL_ISB);
1526     }
1527 
1528     /**
1529      * Gets the GNSS measurement's inter-signal bias in nanoseconds with sub-nanosecond accuracy.
1530      *
1531      * <p>This value is the sum of the estimated receiver-side and the space-segment-side
1532      * inter-system bias, inter-frequency bias and inter-code bias, including:
1533      *
1534      * <ul>
1535      * <li>Receiver inter-constellation bias (with respect to the constellation in
1536      * {@link GnssClock#getReferenceConstellationTypeForIsb())</li>
1537      * <li>Receiver inter-frequency bias (with respect to the carrier frequency in
1538      * {@link GnssClock#getReferenceConstellationTypeForIsb())</li>
1539      * <li>Receiver inter-code bias (with respect to the code type in
1540      * {@link GnssClock#getReferenceConstellationTypeForIsb())</li>
1541      * <li>Master clock bias (e.g., GPS-GAL Time Offset (GGTO), GPS-UTC Time Offset (TauGps),
1542      * BDS-GLO Time Offset (BGTO))(with respect to the constellation in
1543      * {@link GnssClock#getReferenceConstellationTypeForIsb())</li>
1544      * <li>Group delay (e.g., Total Group Delay (TGD))</li>
1545      * <li>Satellite inter-frequency bias (GLO only) (with respect to the carrier frequency in
1546      * {@link GnssClock#getReferenceConstellationTypeForIsb())</li>
1547      * <li>Satellite inter-code bias (e.g., Differential Code Bias (DCB)) (with respect to the code
1548      * type in {@link GnssClock#getReferenceConstellationTypeForIsb())</li>
1549      * </ul>
1550      *
1551      * <p>If a component of the above is already compensated in the provided
1552      * {@link GnssMeasurement#getReceivedSvTimeNanos()}, then it must not be included in the
1553      * reported full ISB.
1554      *
1555      * <p>The value does not include the inter-frequency Ionospheric bias.
1556      *
1557      * <p>The sign of the value is defined by the following equation:
1558      * <pre>
1559      *     corrected pseudorange = raw pseudorange - FullInterSignalBiasNanos</pre>
1560      *
1561      * <p>The value is only available if {@link #hasFullInterSignalBiasNanos()} is {@code true}.
1562      */
getFullInterSignalBiasNanos()1563     public double getFullInterSignalBiasNanos() {
1564         return mFullInterSignalBiasNanos;
1565     }
1566 
1567     /**
1568      * Sets the GNSS measurement's inter-signal bias in nanoseconds.
1569      *
1570      * @hide
1571      */
1572     @TestApi
setFullInterSignalBiasNanos(double fullInterSignalBiasNanos)1573     public void setFullInterSignalBiasNanos(double fullInterSignalBiasNanos) {
1574         setFlag(HAS_FULL_ISB);
1575         mFullInterSignalBiasNanos = fullInterSignalBiasNanos;
1576     }
1577 
1578     /**
1579      * Resets the GNSS measurement's inter-signal bias in nanoseconds.
1580      *
1581      * @hide
1582      */
1583     @TestApi
resetFullInterSignalBiasNanos()1584     public void resetFullInterSignalBiasNanos() {
1585         resetFlag(HAS_FULL_ISB);
1586     }
1587 
1588     /**
1589      * Returns {@code true} if {@link #getFullInterSignalBiasUncertaintyNanos()} is available,
1590      * {@code false} otherwise.
1591      */
hasFullInterSignalBiasUncertaintyNanos()1592     public boolean hasFullInterSignalBiasUncertaintyNanos() {
1593         return isFlagSet(HAS_FULL_ISB_UNCERTAINTY);
1594     }
1595 
1596     /**
1597      * Gets the GNSS measurement's inter-signal bias uncertainty (1 sigma) in
1598      * nanoseconds with sub-nanosecond accuracy.
1599      *
1600      * <p>The value is only available if {@link #hasFullInterSignalBiasUncertaintyNanos()} is
1601      * {@code true}.
1602      */
1603     @FloatRange(from = 0.0)
getFullInterSignalBiasUncertaintyNanos()1604     public double getFullInterSignalBiasUncertaintyNanos() {
1605         return mFullInterSignalBiasUncertaintyNanos;
1606     }
1607 
1608     /**
1609      * Sets the GNSS measurement's inter-signal bias uncertainty (1 sigma) in nanoseconds.
1610      *
1611      * @hide
1612      */
1613     @TestApi
setFullInterSignalBiasUncertaintyNanos(@loatRangefrom = 0.0) double fullInterSignalBiasUncertaintyNanos)1614     public void setFullInterSignalBiasUncertaintyNanos(@FloatRange(from = 0.0)
1615             double fullInterSignalBiasUncertaintyNanos) {
1616         setFlag(HAS_FULL_ISB_UNCERTAINTY);
1617         mFullInterSignalBiasUncertaintyNanos = fullInterSignalBiasUncertaintyNanos;
1618     }
1619 
1620     /**
1621      * Resets the GNSS measurement's inter-signal bias uncertainty (1 sigma) in
1622      * nanoseconds.
1623      *
1624      * @hide
1625      */
1626     @TestApi
resetFullInterSignalBiasUncertaintyNanos()1627     public void resetFullInterSignalBiasUncertaintyNanos() {
1628         resetFlag(HAS_FULL_ISB_UNCERTAINTY);
1629     }
1630 
1631     /**
1632      * Returns {@code true} if {@link #getSatelliteInterSignalBiasNanos()} is available,
1633      * {@code false} otherwise.
1634      */
hasSatelliteInterSignalBiasNanos()1635     public boolean hasSatelliteInterSignalBiasNanos() {
1636         return isFlagSet(HAS_SATELLITE_ISB);
1637     }
1638 
1639     /**
1640      * Gets the GNSS measurement's satellite inter-signal bias in nanoseconds with sub-nanosecond
1641      * accuracy.
1642      *
1643      * <p>This value is the space-segment-side inter-system bias, inter-frequency bias and
1644      * inter-code bias, including:
1645      *
1646      * <ul>
1647      * <li>Master clock bias (e.g., GPS-GAL Time Offset (GGTO), GPS-UTC Time Offset (TauGps),
1648      * BDS-GLO Time Offset (BGTO))(with respect to the constellation in
1649      * {@link GnssClock#getReferenceConstellationTypeForIsb())</li>
1650      * <li>Group delay (e.g., Total Group Delay (TGD))</li>
1651      * <li>Satellite inter-frequency bias (GLO only) (with respect to the carrier frequency in
1652      * {@link GnssClock#getReferenceConstellationTypeForIsb())</li>
1653      * <li>Satellite inter-code bias (e.g., Differential Code Bias (DCB)) (with respect to the code
1654      * type in {@link GnssClock#getReferenceConstellationTypeForIsb())</li>
1655      * </ul>
1656      *
1657      * <p>The sign of the value is defined by the following equation:
1658      * <pre>
1659      *     corrected pseudorange = raw pseudorange - SatelliteInterSignalBiasNanos</pre>
1660      *
1661      * <p>The value is only available if {@link #hasSatelliteInterSignalBiasNanos()} is {@code
1662      * true}.
1663      */
getSatelliteInterSignalBiasNanos()1664     public double getSatelliteInterSignalBiasNanos() {
1665         return mSatelliteInterSignalBiasNanos;
1666     }
1667 
1668     /**
1669      * Sets the GNSS measurement's satellite inter-signal bias in nanoseconds.
1670      *
1671      * @hide
1672      */
1673     @TestApi
setSatelliteInterSignalBiasNanos(double satelliteInterSignalBiasNanos)1674     public void setSatelliteInterSignalBiasNanos(double satelliteInterSignalBiasNanos) {
1675         setFlag(HAS_SATELLITE_ISB);
1676         mSatelliteInterSignalBiasNanos = satelliteInterSignalBiasNanos;
1677     }
1678 
1679     /**
1680      * Resets the GNSS measurement's satellite inter-signal bias in nanoseconds.
1681      *
1682      * @hide
1683      */
1684     @TestApi
resetSatelliteInterSignalBiasNanos()1685     public void resetSatelliteInterSignalBiasNanos() {
1686         resetFlag(HAS_SATELLITE_ISB);
1687     }
1688 
1689     /**
1690      * Returns {@code true} if {@link #getSatelliteInterSignalBiasUncertaintyNanos()} is available,
1691      * {@code false} otherwise.
1692      */
hasSatelliteInterSignalBiasUncertaintyNanos()1693     public boolean hasSatelliteInterSignalBiasUncertaintyNanos() {
1694         return isFlagSet(HAS_SATELLITE_ISB_UNCERTAINTY);
1695     }
1696 
1697     /**
1698      * Gets the GNSS measurement's satellite inter-signal bias uncertainty (1 sigma) in
1699      * nanoseconds with sub-nanosecond accuracy.
1700      *
1701      * <p>The value is only available if {@link #hasSatelliteInterSignalBiasUncertaintyNanos()} is
1702      * {@code true}.
1703      */
1704     @FloatRange(from = 0.0)
getSatelliteInterSignalBiasUncertaintyNanos()1705     public double getSatelliteInterSignalBiasUncertaintyNanos() {
1706         return mSatelliteInterSignalBiasUncertaintyNanos;
1707     }
1708 
1709     /**
1710      * Sets the GNSS measurement's satellite inter-signal bias uncertainty (1 sigma) in nanoseconds.
1711      *
1712      * @hide
1713      */
1714     @TestApi
setSatelliteInterSignalBiasUncertaintyNanos(@loatRangefrom = 0.0) double satelliteInterSignalBiasUncertaintyNanos)1715     public void setSatelliteInterSignalBiasUncertaintyNanos(@FloatRange(from = 0.0)
1716             double satelliteInterSignalBiasUncertaintyNanos) {
1717         setFlag(HAS_SATELLITE_ISB_UNCERTAINTY);
1718         mSatelliteInterSignalBiasUncertaintyNanos = satelliteInterSignalBiasUncertaintyNanos;
1719     }
1720 
1721     /**
1722      * Resets the GNSS measurement's satellite inter-signal bias uncertainty (1 sigma) in
1723      * nanoseconds.
1724      *
1725      * @hide
1726      */
1727     @TestApi
resetSatelliteInterSignalBiasUncertaintyNanos()1728     public void resetSatelliteInterSignalBiasUncertaintyNanos() {
1729         resetFlag(HAS_SATELLITE_ISB_UNCERTAINTY);
1730     }
1731 
1732     /**
1733      * Returns {@code true} if {@link #getSatellitePvt()} is available,
1734      * {@code false} otherwise.
1735      *
1736      * @hide
1737      */
1738     @SystemApi
hasSatellitePvt()1739     public boolean hasSatellitePvt() {
1740         return isFlagSet(HAS_SATELLITE_PVT);
1741     }
1742 
1743     /**
1744      * Gets the Satellite PVT data.
1745      *
1746      * <p>The value is only available if {@link #hasSatellitePvt()} is
1747      * {@code true}.
1748      *
1749      * @hide
1750      */
1751     @Nullable
1752     @SystemApi
getSatellitePvt()1753     public SatellitePvt getSatellitePvt() {
1754         return mSatellitePvt;
1755     }
1756 
1757     /**
1758      * Sets the Satellite PVT.
1759      *
1760      * @hide
1761      */
1762     @TestApi
setSatellitePvt(@ullable SatellitePvt satellitePvt)1763     public void setSatellitePvt(@Nullable SatellitePvt satellitePvt) {
1764         if (satellitePvt == null) {
1765             resetSatellitePvt();
1766         } else {
1767             setFlag(HAS_SATELLITE_PVT);
1768             mSatellitePvt = satellitePvt;
1769         }
1770     }
1771 
1772     /**
1773      * Resets the Satellite PVT.
1774      *
1775      * @hide
1776      */
1777     @TestApi
resetSatellitePvt()1778     public void resetSatellitePvt() {
1779         resetFlag(HAS_SATELLITE_PVT);
1780     }
1781 
1782     /**
1783      * Returns {@code true} if {@link #getCorrelationVectors()} is available,
1784      * {@code false} otherwise.
1785      *
1786      * @hide
1787      */
1788     @SystemApi
hasCorrelationVectors()1789     public boolean hasCorrelationVectors() {
1790         return isFlagSet(HAS_CORRELATION_VECTOR);
1791     }
1792 
1793     /**
1794      * Gets read-only collection of CorrelationVector with each CorrelationVector corresponding to a
1795      * frequency offset.
1796      *
1797      * <p>To represent correlation values over a 2D spaces (delay and frequency), a
1798      * CorrelationVector is required per frequency offset, and each CorrelationVector contains
1799      * correlation values at equally spaced spatial offsets.
1800      *
1801      * @hide
1802      */
1803     @Nullable
1804     @SystemApi
1805     @SuppressLint("NullableCollection")
getCorrelationVectors()1806     public Collection<CorrelationVector> getCorrelationVectors() {
1807         return mReadOnlyCorrelationVectors;
1808     }
1809 
1810     /**
1811      * Sets the CorrelationVectors.
1812      *
1813      * @hide
1814      */
1815     @TestApi
setCorrelationVectors( @uppressLint"NullableCollection") @ullable Collection<CorrelationVector> correlationVectors)1816     public void setCorrelationVectors(
1817             @SuppressLint("NullableCollection")
1818             @Nullable Collection<CorrelationVector> correlationVectors) {
1819         if (correlationVectors == null || correlationVectors.isEmpty()) {
1820             resetCorrelationVectors();
1821         } else {
1822             setFlag(HAS_CORRELATION_VECTOR);
1823             mReadOnlyCorrelationVectors = Collections.unmodifiableCollection(correlationVectors);
1824         }
1825     }
1826 
1827     /**
1828      * Resets the CorrelationVectors.
1829      *
1830      * @hide
1831      */
1832     @TestApi
resetCorrelationVectors()1833     public void resetCorrelationVectors() {
1834         resetFlag(HAS_CORRELATION_VECTOR);
1835         mReadOnlyCorrelationVectors = null;
1836     }
1837 
1838     public static final @NonNull Creator<GnssMeasurement> CREATOR = new Creator<GnssMeasurement>() {
1839         @Override
1840         public GnssMeasurement createFromParcel(Parcel parcel) {
1841             GnssMeasurement gnssMeasurement = new GnssMeasurement();
1842 
1843             gnssMeasurement.mFlags = parcel.readInt();
1844             gnssMeasurement.mSvid = parcel.readInt();
1845             gnssMeasurement.mConstellationType = parcel.readInt();
1846             gnssMeasurement.mTimeOffsetNanos = parcel.readDouble();
1847             gnssMeasurement.mState = parcel.readInt();
1848             gnssMeasurement.mReceivedSvTimeNanos = parcel.readLong();
1849             gnssMeasurement.mReceivedSvTimeUncertaintyNanos = parcel.readLong();
1850             gnssMeasurement.mCn0DbHz = parcel.readDouble();
1851             gnssMeasurement.mPseudorangeRateMetersPerSecond = parcel.readDouble();
1852             gnssMeasurement.mPseudorangeRateUncertaintyMetersPerSecond = parcel.readDouble();
1853             gnssMeasurement.mAccumulatedDeltaRangeState = parcel.readInt();
1854             gnssMeasurement.mAccumulatedDeltaRangeMeters = parcel.readDouble();
1855             gnssMeasurement.mAccumulatedDeltaRangeUncertaintyMeters = parcel.readDouble();
1856             gnssMeasurement.mCarrierFrequencyHz = parcel.readFloat();
1857             gnssMeasurement.mCarrierCycles = parcel.readLong();
1858             gnssMeasurement.mCarrierPhase = parcel.readDouble();
1859             gnssMeasurement.mCarrierPhaseUncertainty = parcel.readDouble();
1860             gnssMeasurement.mMultipathIndicator = parcel.readInt();
1861             gnssMeasurement.mSnrInDb = parcel.readDouble();
1862             gnssMeasurement.mAutomaticGainControlLevelInDb = parcel.readDouble();
1863             gnssMeasurement.mCodeType = parcel.readString();
1864             gnssMeasurement.mBasebandCn0DbHz = parcel.readDouble();
1865             gnssMeasurement.mFullInterSignalBiasNanos = parcel.readDouble();
1866             gnssMeasurement.mFullInterSignalBiasUncertaintyNanos = parcel.readDouble();
1867             gnssMeasurement.mSatelliteInterSignalBiasNanos = parcel.readDouble();
1868             gnssMeasurement.mSatelliteInterSignalBiasUncertaintyNanos = parcel.readDouble();
1869             if (gnssMeasurement.hasSatellitePvt()) {
1870                 ClassLoader classLoader = getClass().getClassLoader();
1871                 gnssMeasurement.mSatellitePvt = parcel.readParcelable(classLoader, android.location.SatellitePvt.class);
1872             }
1873             if (gnssMeasurement.hasCorrelationVectors()) {
1874                 CorrelationVector[] correlationVectorsArray =
1875                         new CorrelationVector[parcel.readInt()];
1876                 parcel.readTypedArray(correlationVectorsArray, CorrelationVector.CREATOR);
1877                 Collection<CorrelationVector> corrVecCollection =
1878                         Arrays.asList(correlationVectorsArray);
1879                 gnssMeasurement.mReadOnlyCorrelationVectors =
1880                         Collections.unmodifiableCollection(corrVecCollection);
1881             }
1882             return gnssMeasurement;
1883         }
1884 
1885         @Override
1886         public GnssMeasurement[] newArray(int i) {
1887             return new GnssMeasurement[i];
1888         }
1889     };
1890 
1891     @Override
writeToParcel(Parcel parcel, int flags)1892     public void writeToParcel(Parcel parcel, int flags) {
1893         parcel.writeInt(mFlags);
1894         parcel.writeInt(mSvid);
1895         parcel.writeInt(mConstellationType);
1896         parcel.writeDouble(mTimeOffsetNanos);
1897         parcel.writeInt(mState);
1898         parcel.writeLong(mReceivedSvTimeNanos);
1899         parcel.writeLong(mReceivedSvTimeUncertaintyNanos);
1900         parcel.writeDouble(mCn0DbHz);
1901         parcel.writeDouble(mPseudorangeRateMetersPerSecond);
1902         parcel.writeDouble(mPseudorangeRateUncertaintyMetersPerSecond);
1903         parcel.writeInt(mAccumulatedDeltaRangeState);
1904         parcel.writeDouble(mAccumulatedDeltaRangeMeters);
1905         parcel.writeDouble(mAccumulatedDeltaRangeUncertaintyMeters);
1906         parcel.writeFloat(mCarrierFrequencyHz);
1907         parcel.writeLong(mCarrierCycles);
1908         parcel.writeDouble(mCarrierPhase);
1909         parcel.writeDouble(mCarrierPhaseUncertainty);
1910         parcel.writeInt(mMultipathIndicator);
1911         parcel.writeDouble(mSnrInDb);
1912         parcel.writeDouble(mAutomaticGainControlLevelInDb);
1913         parcel.writeString(mCodeType);
1914         parcel.writeDouble(mBasebandCn0DbHz);
1915         parcel.writeDouble(mFullInterSignalBiasNanos);
1916         parcel.writeDouble(mFullInterSignalBiasUncertaintyNanos);
1917         parcel.writeDouble(mSatelliteInterSignalBiasNanos);
1918         parcel.writeDouble(mSatelliteInterSignalBiasUncertaintyNanos);
1919         if (hasSatellitePvt()) {
1920             parcel.writeParcelable(mSatellitePvt, flags);
1921         }
1922         if (hasCorrelationVectors()) {
1923             int correlationVectorCount = mReadOnlyCorrelationVectors.size();
1924             CorrelationVector[] correlationVectorArray =
1925                 mReadOnlyCorrelationVectors.toArray(new CorrelationVector[correlationVectorCount]);
1926             parcel.writeInt(correlationVectorArray.length);
1927             parcel.writeTypedArray(correlationVectorArray, flags);
1928         }
1929     }
1930 
1931     @Override
describeContents()1932     public int describeContents() {
1933         return 0;
1934     }
1935 
1936     @Override
toString()1937     public String toString() {
1938         final String format = "   %-29s = %s\n";
1939         final String formatWithUncertainty = "   %-29s = %-25s   %-40s = %s\n";
1940         StringBuilder builder = new StringBuilder("GnssMeasurement:\n");
1941 
1942         builder.append(String.format(format, "Svid", mSvid));
1943         builder.append(String.format(format, "ConstellationType", mConstellationType));
1944         builder.append(String.format(format, "TimeOffsetNanos", mTimeOffsetNanos));
1945 
1946         builder.append(String.format(format, "State", getStateString()));
1947 
1948         builder.append(String.format(
1949                 formatWithUncertainty,
1950                 "ReceivedSvTimeNanos",
1951                 mReceivedSvTimeNanos,
1952                 "ReceivedSvTimeUncertaintyNanos",
1953                 mReceivedSvTimeUncertaintyNanos));
1954 
1955         builder.append(String.format(format, "Cn0DbHz", mCn0DbHz));
1956 
1957         if (hasBasebandCn0DbHz()) {
1958             builder.append(String.format(format, "BasebandCn0DbHz", mBasebandCn0DbHz));
1959         }
1960 
1961         builder.append(String.format(
1962                 formatWithUncertainty,
1963                 "PseudorangeRateMetersPerSecond",
1964                 mPseudorangeRateMetersPerSecond,
1965                 "PseudorangeRateUncertaintyMetersPerSecond",
1966                 mPseudorangeRateUncertaintyMetersPerSecond));
1967 
1968         builder.append(String.format(
1969                 format,
1970                 "AccumulatedDeltaRangeState",
1971                 getAccumulatedDeltaRangeStateString()));
1972 
1973         builder.append(String.format(
1974                 formatWithUncertainty,
1975                 "AccumulatedDeltaRangeMeters",
1976                 mAccumulatedDeltaRangeMeters,
1977                 "AccumulatedDeltaRangeUncertaintyMeters",
1978                 mAccumulatedDeltaRangeUncertaintyMeters));
1979 
1980         if (hasCarrierFrequencyHz()) {
1981             builder.append(String.format(format, "CarrierFrequencyHz", mCarrierFrequencyHz));
1982         }
1983 
1984         if (hasCarrierCycles()) {
1985             builder.append(String.format(format, "CarrierCycles", mCarrierCycles));
1986         }
1987 
1988         if (hasCarrierPhase() || hasCarrierPhaseUncertainty()) {
1989             builder.append(String.format(
1990                     formatWithUncertainty,
1991                     "CarrierPhase",
1992                     hasCarrierPhase() ? mCarrierPhase : null,
1993                     "CarrierPhaseUncertainty",
1994                     hasCarrierPhaseUncertainty() ? mCarrierPhaseUncertainty : null));
1995         }
1996 
1997         builder.append(String.format(format, "MultipathIndicator", getMultipathIndicatorString()));
1998 
1999         if (hasSnrInDb()) {
2000             builder.append(String.format(format, "SnrInDb", mSnrInDb));
2001         }
2002 
2003         if (hasAutomaticGainControlLevelDb()) {
2004             builder.append(String.format(format, "AgcLevelDb", mAutomaticGainControlLevelInDb));
2005         }
2006 
2007         if (hasCodeType()) {
2008             builder.append(String.format(format, "CodeType", mCodeType));
2009         }
2010 
2011         if (hasFullInterSignalBiasNanos() || hasFullInterSignalBiasUncertaintyNanos()) {
2012             builder.append(String.format(
2013                     formatWithUncertainty,
2014                     "InterSignalBiasNs",
2015                     hasFullInterSignalBiasNanos() ? mFullInterSignalBiasNanos : null,
2016                     "InterSignalBiasUncertaintyNs",
2017                     hasFullInterSignalBiasUncertaintyNanos()
2018                             ? mFullInterSignalBiasUncertaintyNanos : null));
2019         }
2020 
2021         if (hasSatelliteInterSignalBiasNanos() || hasSatelliteInterSignalBiasUncertaintyNanos()) {
2022             builder.append(String.format(
2023                     formatWithUncertainty,
2024                     "SatelliteInterSignalBiasNs",
2025                     hasSatelliteInterSignalBiasNanos() ? mSatelliteInterSignalBiasNanos : null,
2026                     "SatelliteInterSignalBiasUncertaintyNs",
2027                     hasSatelliteInterSignalBiasUncertaintyNanos()
2028                             ? mSatelliteInterSignalBiasUncertaintyNanos
2029                             : null));
2030         }
2031 
2032         if (hasSatellitePvt()) {
2033             builder.append(mSatellitePvt.toString());
2034         }
2035 
2036         if (hasCorrelationVectors()) {
2037             for (CorrelationVector correlationVector : mReadOnlyCorrelationVectors) {
2038                 builder.append(correlationVector.toString());
2039                 builder.append("\n");
2040             }
2041         }
2042 
2043         return builder.toString();
2044     }
2045 
initialize()2046     private void initialize() {
2047         mFlags = HAS_NO_FLAGS;
2048         setSvid(0);
2049         setTimeOffsetNanos(Long.MIN_VALUE);
2050         setState(STATE_UNKNOWN);
2051         setReceivedSvTimeNanos(Long.MIN_VALUE);
2052         setReceivedSvTimeUncertaintyNanos(Long.MAX_VALUE);
2053         setCn0DbHz(Double.MIN_VALUE);
2054         setPseudorangeRateMetersPerSecond(Double.MIN_VALUE);
2055         setPseudorangeRateUncertaintyMetersPerSecond(Double.MIN_VALUE);
2056         setAccumulatedDeltaRangeState(ADR_STATE_UNKNOWN);
2057         setAccumulatedDeltaRangeMeters(Double.MIN_VALUE);
2058         setAccumulatedDeltaRangeUncertaintyMeters(Double.MIN_VALUE);
2059         resetCarrierFrequencyHz();
2060         resetCarrierCycles();
2061         resetCarrierPhase();
2062         resetCarrierPhaseUncertainty();
2063         setMultipathIndicator(MULTIPATH_INDICATOR_UNKNOWN);
2064         resetSnrInDb();
2065         resetAutomaticGainControlLevel();
2066         resetCodeType();
2067         resetBasebandCn0DbHz();
2068         resetFullInterSignalBiasNanos();
2069         resetFullInterSignalBiasUncertaintyNanos();
2070         resetSatelliteInterSignalBiasNanos();
2071         resetSatelliteInterSignalBiasUncertaintyNanos();
2072         resetSatellitePvt();
2073         resetCorrelationVectors();
2074     }
2075 
setFlag(int flag)2076     private void setFlag(int flag) {
2077         mFlags |= flag;
2078     }
2079 
resetFlag(int flag)2080     private void resetFlag(int flag) {
2081         mFlags &= ~flag;
2082     }
2083 
isFlagSet(int flag)2084     private boolean isFlagSet(int flag) {
2085         return (mFlags & flag) == flag;
2086     }
2087 }
2088