summaryrefslogtreecommitdiff
path: root/location/java/android/location/SatellitePvt.java
blob: 2031929514f3f0d7808cb7dedba68c36b42060aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
/*
 * Copyright (C) 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.location;

import android.annotation.FloatRange;
import android.annotation.IntDef;
import android.annotation.IntRange;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.os.Parcel;
import android.os.Parcelable;

import com.android.internal.util.Preconditions;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

/**
 * A class that contains GNSS satellite position, velocity and time information at the
 * same signal transmission time {@link GnssMeasurement#getReceivedSvTimeNanos()}.
 *
 * <p>The position and velocity must be in ECEF coordinates.
 *
 * <p>If {@link GnssMeasurement#getSatellitePvt()} is derived from Broadcast ephemeris, then the
 * position is already w.r.t. the antenna phase center. However, if
 * {@link GnssMeasurement#getSatellitePvt()} is derived from other modeled orbits, such as
 * long-term orbits, or precise orbits, then the orbits may have been computed w.r.t.
 * the satellite center of mass, and then GNSS vendors are expected to correct for the effect
 * on different phase centers (can differ by meters) of different GNSS signals (e.g. L1, L5)
 * on the reported satellite position. Accordingly, we might observe a different satellite
 * position reported for L1 GnssMeasurement struct compared to L5 GnssMeasurement struct.
 *
 * <p>If {@link GnssMeasurement#getReceivedSvTimeNanos()} is not fully decoded,
 * {@link GnssMeasurement#getSatellitePvt()} could still be reported and
 * {@link GnssMeasurement#getReceivedSvTimeUncertaintyNanos()} would be used to provide confidence.
 * @hide
 */
@SystemApi
public final class SatellitePvt implements Parcelable {
    /**
     * Bit mask for {@link #mFlags} indicating valid satellite position, velocity and clock info
     * fields are stored in the SatellitePvt.
     */
    private static final int HAS_POSITION_VELOCITY_CLOCK_INFO = 1 << 0;

    /**
     * Bit mask for {@link #mFlags} indicating a valid iono delay field is stored in the
     * SatellitePvt.
     */
    private static final int HAS_IONO = 1 << 1;

    /**
     * Bit mask for {@link #mFlags} indicating a valid tropo delay field is stored in the
     * SatellitePvt.
     */
    private static final int HAS_TROPO = 1 << 2;

    /**
     * Bit mask for {@link #mFlags} indicating a valid Issue of Data, Clock field is stored in the
     * SatellitePvt.
     */
    private static final int HAS_ISSUE_OF_DATA_CLOCK = 1 << 3;

    /**
     * Bit mask for {@link #mFlags} indicating a valid Issue of Data, Ephemeris field is stored in
     * the SatellitePvt.
     */
    private static final int HAS_ISSUE_OF_DATA_EPHEMERIS = 1 << 4;

    /**
     * Bit mask for {@link #mFlags} indicating a valid Time of Clock field is stored in the
     * SatellitePvt.
     */
    private static final int HAS_TIME_OF_CLOCK = 1 << 5;

    /**
     * Bit mask for {@link #mFlags} indicating a valid Time of Ephemeris field is stored in
     * the SatellitePvt.
     */
    private static final int HAS_TIME_OF_EPHEMERIS = 1 << 6;


    /** Ephemeris demodulated from broadcast signals */
    public static final int EPHEMERIS_SOURCE_DEMODULATED = 0;

    /**
     * Server provided Normal type ephemeris data, which is similar to broadcast ephemeris in
     * longevity (e.g. SUPL) - lasting for few hours and providing satellite orbit and clock
     * with accuracy of 1 - 2 meters.
     */
    public static final int EPHEMERIS_SOURCE_SERVER_NORMAL = 1;

    /**
     * Server provided Long-Term type ephemeris data, which lasts for many hours to several days
     * and often provides satellite orbit and clock accuracy of 2 - 20 meters.
     */
    public static final int EPHEMERIS_SOURCE_SERVER_LONG_TERM = 2;

    /** Other ephemeris source */
    public static final int EPHEMERIS_SOURCE_OTHER = 3;

    /**
     * Satellite ephemeris source
     * @hide
     */
    @Retention(RetentionPolicy.SOURCE)
    @IntDef({EPHEMERIS_SOURCE_DEMODULATED, EPHEMERIS_SOURCE_SERVER_NORMAL,
            EPHEMERIS_SOURCE_SERVER_LONG_TERM, EPHEMERIS_SOURCE_OTHER})
    public @interface EphemerisSource {
    }

    /**
     * A bitfield of flags indicating the validity of the fields in this SatellitePvt.
     * The bit masks are defined in the constants with prefix HAS_*
     *
     * <p>Fields for which there is no corresponding flag must be filled in with a valid value.
     * For convenience, these are marked as mandatory.
     *
     * <p>Others fields may have invalid information in them, if not marked as valid by the
     * corresponding bit in flags.
     */
    private final int mFlags;

    @Nullable
    private final PositionEcef mPositionEcef;
    @Nullable
    private final VelocityEcef mVelocityEcef;
    @Nullable
    private final ClockInfo mClockInfo;
    private final double mIonoDelayMeters;
    private final double mTropoDelayMeters;
    private final long mTimeOfClockSeconds;
    private final long mTimeOfEphemerisSeconds;
    private final int mIssueOfDataClock;
    private final int mIssueOfDataEphemeris;
    @EphemerisSource
    private final int mEphemerisSource;

    /**
     * Class containing estimates of the satellite position fields in ECEF coordinate frame.
     *
     * <p>The satellite position must be defined at the time of transmission of the signal
     * receivedSvTimeNs.
     */
    public static final class PositionEcef implements Parcelable {
        private final double mXMeters;
        private final double mYMeters;
        private final double mZMeters;
        private final double mUreMeters;

        public PositionEcef(
                double xMeters,
                double yMeters,
                double zMeters,
                double ureMeters) {
            mXMeters = xMeters;
            mYMeters = yMeters;
            mZMeters = zMeters;
            mUreMeters = ureMeters;
        }

        public static final @NonNull Creator<PositionEcef> CREATOR =
                new Creator<PositionEcef>() {
                    @Override
                    public PositionEcef createFromParcel(Parcel in) {
                        return new PositionEcef(
                                in.readDouble(),
                                in.readDouble(),
                                in.readDouble(),
                                in.readDouble()
                        );
                    }

                    @Override
                    public PositionEcef[] newArray(int size) {
                        return new PositionEcef[size];
                    }
                };

        /**
         * Returns the satellite position X in WGS84 ECEF (meters).
         */
        @FloatRange()
        public double getXMeters() {
            return mXMeters;
        }

        /**
         * Returns the satellite position Y in WGS84 ECEF (meters).
         */
        @FloatRange()
        public double getYMeters() {
            return mYMeters;
        }

        /**
         * Returns the satellite position Z in WGS84 ECEF (meters).
         */
        @FloatRange()
        public double getZMeters() {
            return mZMeters;
        }

        /**
         * Returns the signal in Space User Range Error (URE) (meters).
         */
        @FloatRange(from = 0.0f, fromInclusive = false)
        public double getUreMeters() {
            return mUreMeters;
        }

        @Override
        public int describeContents() {
            return 0;
        }

        @Override
        public void writeToParcel(@NonNull Parcel dest, int flags) {
            dest.writeDouble(mXMeters);
            dest.writeDouble(mYMeters);
            dest.writeDouble(mZMeters);
            dest.writeDouble(mUreMeters);
        }

        @Override
        public String toString() {
            return "PositionEcef{"
                    + "xMeters=" + mXMeters
                    + ", yMeters=" + mYMeters
                    + ", zMeters=" + mZMeters
                    + ", ureMeters=" + mUreMeters
                    + "}";
        }
    }

    /**
     * Class containing estimates of the satellite velocity fields in the ECEF coordinate frame.
     *
     * <p>The satellite velocity must be defined at the time of transmission of the signal
     * receivedSvTimeNs.
     */
    public static final class VelocityEcef implements Parcelable {
        private final double mXMetersPerSecond;
        private final double mYMetersPerSecond;
        private final double mZMetersPerSecond;
        private final double mUreRateMetersPerSecond;

        public VelocityEcef(
                double xMetersPerSecond,
                double yMetersPerSecond,
                double zMetersPerSecond,
                double ureRateMetersPerSecond) {
            mXMetersPerSecond = xMetersPerSecond;
            mYMetersPerSecond = yMetersPerSecond;
            mZMetersPerSecond = zMetersPerSecond;
            mUreRateMetersPerSecond = ureRateMetersPerSecond;
        }

        public static final @NonNull Creator<VelocityEcef> CREATOR =
                new Creator<VelocityEcef>() {
                    @Override
                    public VelocityEcef createFromParcel(Parcel in) {
                        return new VelocityEcef(
                                in.readDouble(),
                                in.readDouble(),
                                in.readDouble(),
                                in.readDouble()
                        );
                    }

                    @Override
                    public VelocityEcef[] newArray(int size) {
                        return new VelocityEcef[size];
                    }
                };

        /**
         * Returns the satellite velocity X in WGS84 ECEF (meters per second).
         */
        @FloatRange()
        public double getXMetersPerSecond() {
            return mXMetersPerSecond;
        }

        /**
         * Returns the satellite velocity Y in WGS84 ECEF (meters per second).
         */
        @FloatRange()
        public double getYMetersPerSecond() {
            return mYMetersPerSecond;
        }

        /**
         *Returns the satellite velocity Z in WGS84 ECEF (meters per second).
         */
        @FloatRange()
        public double getZMetersPerSecond() {
            return mZMetersPerSecond;
        }

        /**
         * Returns the signal in Space User Range Error Rate (URE Rate) (meters per second).
         *
         * <p>It covers satellite velocity error and Satellite clock drift
         * projected to the pseudorange rate measurements.
         */
        @FloatRange(from = 0.0f, fromInclusive = false)
        public double getUreRateMetersPerSecond() {
            return mUreRateMetersPerSecond;
        }

        @Override
        public int describeContents() {
            return 0;
        }

        @Override
        public void writeToParcel(@NonNull Parcel dest, int flags) {
            dest.writeDouble(mXMetersPerSecond);
            dest.writeDouble(mYMetersPerSecond);
            dest.writeDouble(mZMetersPerSecond);
            dest.writeDouble(mUreRateMetersPerSecond);
        }

        @Override
        public String toString() {
            return "VelocityEcef{"
                    + "xMetersPerSecond=" + mXMetersPerSecond
                    + ", yMetersPerSecond=" + mYMetersPerSecond
                    + ", zMetersPerSecond=" + mZMetersPerSecond
                    + ", ureRateMetersPerSecond=" + mUreRateMetersPerSecond
                    + "}";
        }
    }

    /**
     * Class containing estimates of the satellite clock info.
     */
    public static final class ClockInfo implements Parcelable {
        private final double mHardwareCodeBiasMeters;
        private final double mTimeCorrectionMeters;
        private final double mClockDriftMetersPerSecond;

        public ClockInfo(
                double hardwareCodeBiasMeters,
                double timeCorrectionMeters,
                double clockDriftMetersPerSecond) {
            mHardwareCodeBiasMeters = hardwareCodeBiasMeters;
            mTimeCorrectionMeters = timeCorrectionMeters;
            mClockDriftMetersPerSecond = clockDriftMetersPerSecond;
        }

        public static final @NonNull Creator<ClockInfo> CREATOR =
                new Creator<ClockInfo>() {
                    @Override
                    public ClockInfo createFromParcel(Parcel in) {
                        return new ClockInfo(
                                in.readDouble(),
                                in.readDouble(),
                                in.readDouble()
                        );
                    }

                    @Override
                    public ClockInfo[] newArray(int size) {
                        return new ClockInfo[size];
                    }
                };

        /**
         * Returns the satellite hardware code bias of the reported code type w.r.t
         * ionosphere-free measurement in meters.
         *
         * <p>When broadcast ephemeris is used, this is the offset caused
         * by the satellite hardware delays at different frequencies;
         * e.g. in IS-GPS-705D, this term is described in Section
         * 20.3.3.3.1.2.1.
         *
         * <p>For GPS this term is ~10ns, and affects the satellite position
         * computation by less than a millimeter.
         */
        @FloatRange()
        public double getHardwareCodeBiasMeters() {
            return mHardwareCodeBiasMeters;
        }

        /**
         * Returns the satellite time correction for ionospheric-free signal measurement
         * (meters). The satellite clock correction for the given signal type
         * = satTimeCorrectionMeters - satHardwareCodeBiasMeters.
         *
         * <p>When broadcast ephemeris is used, this is the offset modeled in the
         * clock terms broadcast over the air by the satellites;
         * e.g. in IS-GPS-200H, Section 20.3.3.3.3.1, this term is
         * ∆tsv = af0 + af1(t - toc) + af2(t - toc)^2 + ∆tr.
         *
         * <p>If another source of ephemeris is used for SatellitePvt, then the
         * equivalent value of satTimeCorrection must be provided.
         *
         * <p>For GPS this term is ~1ms, and affects the satellite position
         * computation by ~1m.
         */
        @FloatRange()
        public double getTimeCorrectionMeters() {
            return mTimeCorrectionMeters;
        }

        /**
         * Returns the satellite clock drift (meters per second).
         */
        @FloatRange()
        public double getClockDriftMetersPerSecond() {
            return mClockDriftMetersPerSecond;
        }

        @Override
        public int describeContents() {
            return 0;
        }

        @Override
        public void writeToParcel(@NonNull Parcel dest, int flags) {
            dest.writeDouble(mHardwareCodeBiasMeters);
            dest.writeDouble(mTimeCorrectionMeters);
            dest.writeDouble(mClockDriftMetersPerSecond);
        }

        @Override
        public String toString() {
            return "ClockInfo{"
                    + "hardwareCodeBiasMeters=" + mHardwareCodeBiasMeters
                    + ", timeCorrectionMeters=" + mTimeCorrectionMeters
                    + ", clockDriftMetersPerSecond=" + mClockDriftMetersPerSecond
                    + "}";
        }
    }

    private SatellitePvt(
            int flags,
            @Nullable PositionEcef positionEcef,
            @Nullable VelocityEcef velocityEcef,
            @Nullable ClockInfo clockInfo,
            double ionoDelayMeters,
            double tropoDelayMeters,
            long timeOfClockSeconds,
            long timeOfEphemerisSeconds,
            int issueOfDataClock,
            int issueOfDataEphemeris,
            @EphemerisSource int ephemerisSource) {
        mFlags = flags;
        mPositionEcef = positionEcef;
        mVelocityEcef = velocityEcef;
        mClockInfo = clockInfo;
        mIonoDelayMeters = ionoDelayMeters;
        mTropoDelayMeters = tropoDelayMeters;
        mTimeOfClockSeconds = timeOfClockSeconds;
        mTimeOfEphemerisSeconds = timeOfEphemerisSeconds;
        mIssueOfDataClock = issueOfDataClock;
        mIssueOfDataEphemeris = issueOfDataEphemeris;
        mEphemerisSource = ephemerisSource;
    }

    /**
     * Returns a {@link PositionEcef} object that contains estimates of the satellite
     * position fields in ECEF coordinate frame.
     */
    @Nullable
    public PositionEcef getPositionEcef() {
        return mPositionEcef;
    }

    /**
     * Returns a {@link VelocityEcef} object that contains estimates of the satellite
     * velocity fields in the ECEF coordinate frame.
     */
    @Nullable
    public VelocityEcef getVelocityEcef() {
        return mVelocityEcef;
    }

    /**
     * Returns a {@link ClockInfo} object that contains estimates of the satellite
     * clock info.
     */
    @Nullable
    public ClockInfo getClockInfo() {
        return mClockInfo;
    }

    /**
     * Returns the ionospheric delay in meters.
     */
    @FloatRange()
    public double getIonoDelayMeters() {
        return mIonoDelayMeters;
    }

    /**
     * Returns the tropospheric delay in meters.
     */
    @FloatRange()
    public double getTropoDelayMeters() {
        return mTropoDelayMeters;
    }

    /**
     * Issue of Data, Clock.
     *
     * <p>This is defined in GPS ICD200 documentation (e.g.,
     * <a href="https://www.gps.gov/technical/icwg/IS-GPS-200H.pdf"></a>).
     *
     * <p>This field is valid if {@link #hasIssueOfDataClock()} is true.
     */
    @IntRange(from = 0, to = 1023)
    public int getIssueOfDataClock() {
        return mIssueOfDataClock;
    }

    /**
     * Issue of Data, Ephemeris.
     *
     * <p>This is defined in GPS ICD200 documentation (e.g.,
     * <a href="https://www.gps.gov/technical/icwg/IS-GPS-200H.pdf"></a>).
     *
     * <p>This field is valid if {@link #hasIssueOfDataEphemeris()} is true.
     */
    @IntRange(from = 0, to = 1023)
    public int getIssueOfDataEphemeris() {
        return mIssueOfDataEphemeris;
    }

    /**
     * Time of Clock in seconds.
     *
     * <p>The value is in seconds since GPS epoch, regardless of the constellation.
     *
     * <p>The value is not encoded as in GPS ICD200 documentation.
     *
     * <p>This field is valid if {@link #hasTimeOfClockSeconds()} is true.
     */
    @IntRange(from = 0)
    public long getTimeOfClockSeconds() {
        return mTimeOfClockSeconds;
    }

    /**
     * Time of ephemeris in seconds.
     *
     * <p>The value is in seconds since GPS epoch, regardless of the constellation.
     *
     * <p>The value is not encoded as in GPS ICD200 documentation.
     *
     * <p>This field is valid if {@link #hasTimeOfEphemerisSeconds()} is true.
     */
    @IntRange(from = 0)
    public long getTimeOfEphemerisSeconds() {
        return mTimeOfEphemerisSeconds;
    }

    /**
     * Satellite ephemeris source.
     */
    @EphemerisSource
    public int getEphemerisSource() {
        return mEphemerisSource;
    }

    /** Returns {@code true} if {@link #getPositionEcef()}, {@link #getVelocityEcef()},
     * and {@link #getClockInfo()} are valid.
     */
    public boolean hasPositionVelocityClockInfo() {
        return (mFlags & HAS_POSITION_VELOCITY_CLOCK_INFO) != 0;
    }

    /** Returns {@code true} if {@link #getIonoDelayMeters()} is valid. */
    public boolean hasIono() {
        return (mFlags & HAS_IONO) != 0;
    }

    /** Returns {@code true} if {@link #getTropoDelayMeters()} is valid. */
    public boolean hasTropo() {
        return (mFlags & HAS_TROPO) != 0;
    }

    /** Returns {@code true} if {@link #getIssueOfDataClock()} is valid. */
    public boolean hasIssueOfDataClock() {
        return (mFlags & HAS_ISSUE_OF_DATA_CLOCK) != 0;
    }

    /** Returns {@code true} if {@link #getIssueOfDataEphemeris()} is valid. */
    public boolean hasIssueOfDataEphemeris() {
        return (mFlags & HAS_ISSUE_OF_DATA_EPHEMERIS) != 0;
    }

    /** Returns {@code true} if {@link #getTimeOfClockSeconds()} ()} is valid. */
    public boolean hasTimeOfClockSeconds() {
        return (mFlags & HAS_TIME_OF_CLOCK) != 0;
    }

    /** Returns {@code true} if {@link #getTimeOfEphemerisSeconds()} is valid. */
    public boolean hasTimeOfEphemerisSeconds() {
        return (mFlags & HAS_TIME_OF_EPHEMERIS) != 0;
    }

    public static final @android.annotation.NonNull Creator<SatellitePvt> CREATOR =
            new Creator<SatellitePvt>() {
                @Override
                @Nullable
                public SatellitePvt createFromParcel(Parcel in) {
                    int flags = in.readInt();
                    ClassLoader classLoader = getClass().getClassLoader();
                    PositionEcef positionEcef = in.readParcelable(classLoader,
                            android.location.SatellitePvt.PositionEcef.class);
                    VelocityEcef velocityEcef = in.readParcelable(classLoader,
                            android.location.SatellitePvt.VelocityEcef.class);
                    ClockInfo clockInfo = in.readParcelable(classLoader,
                            android.location.SatellitePvt.ClockInfo.class);
                    double ionoDelayMeters = in.readDouble();
                    double tropoDelayMeters = in.readDouble();
                    long toc = in.readLong();
                    long toe = in.readLong();
                    int iodc = in.readInt();
                    int iode = in.readInt();
                    int ephemerisSource = in.readInt();

                    return new SatellitePvt(
                            flags,
                            positionEcef,
                            velocityEcef,
                            clockInfo,
                            ionoDelayMeters,
                            tropoDelayMeters,
                            toc,
                            toe,
                            iodc,
                            iode,
                            ephemerisSource);
                }

                @Override
                public SatellitePvt[] newArray(int size) {
                    return new SatellitePvt[size];
                }
            };

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(@NonNull Parcel parcel, int flags) {
        parcel.writeInt(mFlags);
        parcel.writeParcelable(mPositionEcef, flags);
        parcel.writeParcelable(mVelocityEcef, flags);
        parcel.writeParcelable(mClockInfo, flags);
        parcel.writeDouble(mIonoDelayMeters);
        parcel.writeDouble(mTropoDelayMeters);
        parcel.writeLong(mTimeOfClockSeconds);
        parcel.writeLong(mTimeOfEphemerisSeconds);
        parcel.writeInt(mIssueOfDataClock);
        parcel.writeInt(mIssueOfDataEphemeris);
        parcel.writeInt(mEphemerisSource);
    }

    @Override
    public String toString() {
        return "SatellitePvt["
                + "Flags=" + mFlags
                + ", PositionEcef=" + mPositionEcef
                + ", VelocityEcef=" + mVelocityEcef
                + ", ClockInfo=" + mClockInfo
                + ", IonoDelayMeters=" + mIonoDelayMeters
                + ", TropoDelayMeters=" + mTropoDelayMeters
                + ", TimeOfClockSeconds=" + mTimeOfClockSeconds
                + ", TimeOfEphemerisSeconds=" + mTimeOfEphemerisSeconds
                + ", IssueOfDataClock=" + mIssueOfDataClock
                + ", IssueOfDataEphemeris=" + mIssueOfDataEphemeris
                + ", EphemerisSource=" + mEphemerisSource
                + "]";
    }

    /**
     * Builder class for SatellitePvt.
     */
    public static final class Builder {
        /**
         * For documentation of below fields, see corresponding fields in {@link
         * SatellitePvt}.
         */
        private int mFlags;
        @Nullable private PositionEcef mPositionEcef;
        @Nullable private VelocityEcef mVelocityEcef;
        @Nullable private ClockInfo mClockInfo;
        private double mIonoDelayMeters;
        private double mTropoDelayMeters;
        private long mTimeOfClockSeconds;
        private long mTimeOfEphemerisSeconds;
        private int mIssueOfDataClock;
        private int mIssueOfDataEphemeris;
        @EphemerisSource
        private int mEphemerisSource = EPHEMERIS_SOURCE_OTHER;

        /**
         * Set position ECEF.
         *
         * @param positionEcef position ECEF object
         * @return builder object
         */
        @NonNull
        public Builder setPositionEcef(@NonNull PositionEcef positionEcef) {
            mPositionEcef = positionEcef;
            updateFlags();
            return this;
        }

        /**
         * Set velocity ECEF.
         *
         * @param velocityEcef velocity ECEF object
         * @return builder object
         */
        @NonNull
        public Builder setVelocityEcef(@NonNull VelocityEcef velocityEcef) {
            mVelocityEcef = velocityEcef;
            updateFlags();
            return this;
        }

        /**
         * Set clock info.
         *
         * @param clockInfo clock info object
         * @return builder object
         */
        @NonNull
        public Builder setClockInfo(@NonNull ClockInfo clockInfo) {
            mClockInfo = clockInfo;
            updateFlags();
            return this;
        }

        private void updateFlags() {
            if (mPositionEcef != null && mVelocityEcef != null && mClockInfo != null) {
                mFlags = (byte) (mFlags | HAS_POSITION_VELOCITY_CLOCK_INFO);
            }
        }

        /**
         * Set ionospheric delay in meters.
         *
         * @param ionoDelayMeters ionospheric delay (meters)
         * @return builder object
         */
        @NonNull
        public Builder setIonoDelayMeters(
                @FloatRange(from = 0.0f, to = 100.0f) double ionoDelayMeters) {
            mIonoDelayMeters = ionoDelayMeters;
            mFlags = (byte) (mFlags | HAS_IONO);
            return this;
        }

        /**
         * Set tropospheric delay in meters.
         *
         * @param tropoDelayMeters tropospheric delay (meters)
         * @return builder object
         */
        @NonNull
        public Builder setTropoDelayMeters(
                @FloatRange(from = 0.0f, to = 100.0f) double tropoDelayMeters) {
            mTropoDelayMeters = tropoDelayMeters;
            mFlags = (byte) (mFlags | HAS_TROPO);
            return this;
        }

        /**
         * Set time of clock in seconds.
         *
         * <p>The value is in seconds since GPS epoch, regardless of the constellation.
         *
         * <p>The value is not encoded as in GPS ICD200 documentation.
         *
         * @param timeOfClockSeconds time of clock (seconds)
         * @return builder object
         */
        @NonNull
        public Builder setTimeOfClockSeconds(@IntRange(from = 0) long timeOfClockSeconds) {
            Preconditions.checkArgumentNonnegative(timeOfClockSeconds);
            mTimeOfClockSeconds = timeOfClockSeconds;
            mFlags = (byte) (mFlags | HAS_TIME_OF_CLOCK);
            return this;
        }

        /**
         * Set time of ephemeris in seconds.
         *
         * <p>The value is in seconds since GPS epoch, regardless of the constellation.
         *
         * <p>The value is not encoded as in GPS ICD200 documentation.
         *
         * @param timeOfEphemerisSeconds time of ephemeris (seconds)
         * @return builder object
         */
        @NonNull
        public Builder setTimeOfEphemerisSeconds(@IntRange(from = 0) long timeOfEphemerisSeconds) {
            Preconditions.checkArgumentNonnegative(timeOfEphemerisSeconds);
            mTimeOfEphemerisSeconds = timeOfEphemerisSeconds;
            mFlags = (byte) (mFlags | HAS_TIME_OF_EPHEMERIS);
            return this;
        }

        /**
         * Set issue of data, clock.
         *
         * @param issueOfDataClock issue of data, clock.
         * @return builder object
         */
        @NonNull
        public Builder setIssueOfDataClock(@IntRange(from = 0, to = 1023) int issueOfDataClock) {
            Preconditions.checkArgumentInRange(issueOfDataClock, 0, 1023, "issueOfDataClock");
            mIssueOfDataClock = issueOfDataClock;
            mFlags = (byte) (mFlags | HAS_ISSUE_OF_DATA_CLOCK);
            return this;
        }

        /**
         * Set issue of data, ephemeris.
         *
         * @param issueOfDataEphemeris issue of data, ephemeris.
         * @return builder object
         */
        @NonNull
        public Builder setIssueOfDataEphemeris(
                @IntRange(from = 0, to = 1023) int issueOfDataEphemeris) {
            Preconditions.checkArgumentInRange(issueOfDataEphemeris, 0, 1023,
                    "issueOfDataEphemeris");
            mIssueOfDataEphemeris = issueOfDataEphemeris;
            mFlags = (byte) (mFlags | HAS_ISSUE_OF_DATA_EPHEMERIS);
            return this;
        }

        /**
         * Set satellite ephemeris source.
         *
         * @param ephemerisSource satellite ephemeris source
         * @return builder object
         */
        @NonNull
        public Builder setEphemerisSource(@EphemerisSource int ephemerisSource) {
            Preconditions.checkArgument(ephemerisSource == EPHEMERIS_SOURCE_DEMODULATED
                    || ephemerisSource == EPHEMERIS_SOURCE_SERVER_NORMAL
                    || ephemerisSource == EPHEMERIS_SOURCE_SERVER_LONG_TERM
                    || ephemerisSource == EPHEMERIS_SOURCE_OTHER);
            mEphemerisSource = ephemerisSource;
            return this;
        }

        /**
         * Build SatellitePvt object.
         *
         * @return instance of SatellitePvt
         */
        @NonNull
        public SatellitePvt build() {
            return new SatellitePvt(mFlags, mPositionEcef, mVelocityEcef, mClockInfo,
                    mIonoDelayMeters, mTropoDelayMeters, mTimeOfClockSeconds,
                    mTimeOfEphemerisSeconds,
                    mIssueOfDataClock, mIssueOfDataEphemeris,
                    mEphemerisSource);
        }
    }
}