blob: fdbc3ddf8c31e1485a407ca1770b8d732c5a117d [file] [log] [blame]
gomo226b7b72018-12-12 16:49:39 -08001/*
2 * Copyright (C) 2018 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
17package android.location;
18
19import android.annotation.Nullable;
20import android.annotation.SystemApi;
21import android.os.Parcel;
22import android.os.Parcelable;
23
24import java.util.ArrayList;
25import java.util.Collections;
26import java.util.List;
27
28/**
29 * A class representing a GNSS measurement corrections for all used GNSS satellites at the location
30 * and time specified
31 *
32 * @hide
33 */
34@SystemApi
35public final class GnssMeasurementCorrections implements Parcelable {
36
37 /** Represents latitude in degrees at which the corrections are computed. */
38 private double mLatitudeDegrees;
39 /** Represents longitude in degrees at which the corrections are computed. */
40 private double mLongitudeDegrees;
41 /**
42 * Represents altitude in meters above the WGS 84 reference ellipsoid at which the corrections
43 * are computed.
44 */
45 private double mAltitudeMeters;
gomo6ec95382019-01-26 03:08:18 -080046 /**
47 * Represents the horizontal uncertainty (68% confidence) in meters on the device position at
48 * which the corrections are provided.
49 *
50 * <p> This value is useful for example to judge how accurate the provided corrections are.
51 */
52 private double mHorizontalPositionUncertaintyMeters;
53 /**
54 * Represents the vertical uncertainty (68% confidence) in meters on the device position at
55 * which the corrections are provided.
56 *
57 * <p> This value is useful for example to judge how accurate the provided corrections are.
58 */
59 private double mVerticalPositionUncertaintyMeters;
gomo226b7b72018-12-12 16:49:39 -080060
gomo6ec95382019-01-26 03:08:18 -080061 /** Time Of Applicability, GPS time of week in nanoseconds. */
gomo226b7b72018-12-12 16:49:39 -080062 private long mToaGpsNanosecondsOfWeek;
63
64 /**
65 * A set of {@link GnssSingleSatCorrection} each containing measurement corrections for a
gomo6ec95382019-01-26 03:08:18 -080066 * satellite in view.
gomo226b7b72018-12-12 16:49:39 -080067 */
68 private @Nullable List<GnssSingleSatCorrection> mSingleSatCorrectionList;
69
70 private GnssMeasurementCorrections(Builder builder) {
71 mLatitudeDegrees = builder.mLatitudeDegrees;
72 mLongitudeDegrees = builder.mLongitudeDegrees;
73 mAltitudeMeters = builder.mAltitudeMeters;
gomo6ec95382019-01-26 03:08:18 -080074 mHorizontalPositionUncertaintyMeters = builder.mHorizontalPositionUncertaintyMeters;
75 mVerticalPositionUncertaintyMeters = builder.mVerticalPositionUncertaintyMeters;
gomo226b7b72018-12-12 16:49:39 -080076 mToaGpsNanosecondsOfWeek = builder.mToaGpsNanosecondsOfWeek;
77 mSingleSatCorrectionList =
78 builder.mSingleSatCorrectionList == null
79 ? null
80 : Collections.unmodifiableList(
81 new ArrayList<>(builder.mSingleSatCorrectionList));
82 }
83
84 /** Gets the latitude in degrees at which the corrections are computed. */
85 public double getLatitudeDegrees() {
86 return mLatitudeDegrees;
87 }
88
89 /** Gets the longitude in degrees at which the corrections are computed. */
90 public double getLongitudeDegrees() {
91 return mLongitudeDegrees;
92 }
93
94 /**
95 * Gets the altitude in meters above the WGS 84 reference ellipsoid at which the corrections are
96 * computed.
97 */
98 public double getAltitudeMeters() {
99 return mAltitudeMeters;
100 }
101
gomo6ec95382019-01-26 03:08:18 -0800102 /**
103 * Gets the horizontal uncertainty (68% confidence) in meters on the device position at
104 * which the corrections are provided.
105 */
106 public double getHorizontalPositionUncertaintyMeters() {
107 return mHorizontalPositionUncertaintyMeters;
108 }
109
110 /**
111 * Gets the vertical uncertainty (68% confidence) in meters on the device position at
112 * which the corrections are provided.
113 */
114 public double getVerticalPositionUncertaintyMeters() {
115 return mVerticalPositionUncertaintyMeters;
116 }
117
gomo226b7b72018-12-12 16:49:39 -0800118 /** Gets the time of applicability, GPS time of week in nanoseconds. */
119 public long getToaGpsNanosecondsOfWeek() {
120 return mToaGpsNanosecondsOfWeek;
121 }
122
123 /**
124 * Gets a set of {@link GnssSingleSatCorrection} each containing measurement corrections for a
125 * satellite in view
126 */
gomo3796ab12019-02-20 23:21:11 -0800127 public @Nullable List<GnssSingleSatCorrection> getSingleSatelliteCorrectionList() {
gomo226b7b72018-12-12 16:49:39 -0800128 return mSingleSatCorrectionList;
129 }
130
131 @Override
132 public int describeContents() {
133 return 0;
134 }
135
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -0700136 public static final @android.annotation.NonNull Creator<GnssMeasurementCorrections> CREATOR =
gomo226b7b72018-12-12 16:49:39 -0800137 new Creator<GnssMeasurementCorrections>() {
138 @Override
139 public GnssMeasurementCorrections createFromParcel(Parcel parcel) {
gomo3796ab12019-02-20 23:21:11 -0800140 final GnssMeasurementCorrections.Builder gnssMeasurementCorrectons =
gomo226b7b72018-12-12 16:49:39 -0800141 new Builder()
142 .setLatitudeDegrees(parcel.readDouble())
143 .setLongitudeDegrees(parcel.readDouble())
144 .setAltitudeMeters(parcel.readDouble())
gomo6ec95382019-01-26 03:08:18 -0800145 .setHorizontalPositionUncertaintyMeters(parcel.readDouble())
146 .setVerticalPositionUncertaintyMeters(parcel.readDouble())
gomo226b7b72018-12-12 16:49:39 -0800147 .setToaGpsNanosecondsOfWeek(parcel.readLong());
148 List<GnssSingleSatCorrection> singleSatCorrectionList = new ArrayList<>();
149 parcel.readTypedList(singleSatCorrectionList, GnssSingleSatCorrection.CREATOR);
gomo3796ab12019-02-20 23:21:11 -0800150 gnssMeasurementCorrectons.setSingleSatelliteCorrectionList(
gomo226b7b72018-12-12 16:49:39 -0800151 singleSatCorrectionList.isEmpty() ? null : singleSatCorrectionList);
152 return gnssMeasurementCorrectons.build();
153 }
154
155 @Override
156 public GnssMeasurementCorrections[] newArray(int i) {
157 return new GnssMeasurementCorrections[i];
158 }
159 };
160
161 @Override
162 public String toString() {
163 final String format = " %-29s = %s\n";
164 StringBuilder builder = new StringBuilder("GnssMeasurementCorrections:\n");
165 builder.append(String.format(format, "LatitudeDegrees = ", mLatitudeDegrees));
166 builder.append(String.format(format, "LongitudeDegrees = ", mLongitudeDegrees));
167 builder.append(String.format(format, "AltitudeMeters = ", mAltitudeMeters));
gomo6ec95382019-01-26 03:08:18 -0800168 builder.append(String.format(format, "HorizontalPositionUncertaintyMeters = ",
169 mHorizontalPositionUncertaintyMeters));
170 builder.append(String.format(format, "VerticalPositionUncertaintyMeters = ",
171 mVerticalPositionUncertaintyMeters));
gomo226b7b72018-12-12 16:49:39 -0800172 builder.append(
173 String.format(format, "ToaGpsNanosecondsOfWeek = ", mToaGpsNanosecondsOfWeek));
174 builder.append(
175 String.format(format, "mSingleSatCorrectionList = ", mSingleSatCorrectionList));
176 return builder.toString();
177 }
178
179 @Override
180 public void writeToParcel(Parcel parcel, int flags) {
181 parcel.writeDouble(mLatitudeDegrees);
182 parcel.writeDouble(mLongitudeDegrees);
183 parcel.writeDouble(mAltitudeMeters);
gomo6ec95382019-01-26 03:08:18 -0800184 parcel.writeDouble(mHorizontalPositionUncertaintyMeters);
185 parcel.writeDouble(mVerticalPositionUncertaintyMeters);
gomo226b7b72018-12-12 16:49:39 -0800186 parcel.writeLong(mToaGpsNanosecondsOfWeek);
187 parcel.writeTypedList(mSingleSatCorrectionList);
188 }
189
190 /** Builder for {@link GnssMeasurementCorrections} */
gomo3796ab12019-02-20 23:21:11 -0800191 public static final class Builder {
gomo226b7b72018-12-12 16:49:39 -0800192 /**
193 * For documentation of below fields, see corresponding fields in {@link
194 * GnssMeasurementCorrections}.
195 */
196 private double mLatitudeDegrees;
gomo226b7b72018-12-12 16:49:39 -0800197 private double mLongitudeDegrees;
198 private double mAltitudeMeters;
gomo6ec95382019-01-26 03:08:18 -0800199 private double mHorizontalPositionUncertaintyMeters;
200 private double mVerticalPositionUncertaintyMeters;
gomo226b7b72018-12-12 16:49:39 -0800201 private long mToaGpsNanosecondsOfWeek;
202 private List<GnssSingleSatCorrection> mSingleSatCorrectionList;
203
204 /** Sets the latitude in degrees at which the corrections are computed. */
205 public Builder setLatitudeDegrees(double latitudeDegrees) {
206 mLatitudeDegrees = latitudeDegrees;
207 return this;
208 }
209
210 /** Sets the longitude in degrees at which the corrections are computed. */
211 public Builder setLongitudeDegrees(double longitudeDegrees) {
212 mLongitudeDegrees = longitudeDegrees;
213 return this;
214 }
215
216 /**
217 * Sets the altitude in meters above the WGS 84 reference ellipsoid at which the corrections
218 * are computed.
219 */
220 public Builder setAltitudeMeters(double altitudeMeters) {
221 mAltitudeMeters = altitudeMeters;
222 return this;
223 }
224
gomo6ec95382019-01-26 03:08:18 -0800225
226 /**
227 * Sets the horizontal uncertainty (68% confidence) in meters on the device position at
228 * which the corrections are provided.
229 */
230 public Builder setHorizontalPositionUncertaintyMeters(
231 double horizontalPositionUncertaintyMeters) {
232 mHorizontalPositionUncertaintyMeters = horizontalPositionUncertaintyMeters;
233 return this;
234 }
235
236 /**
237 * Sets the vertical uncertainty (68% confidence) in meters on the device position at which
238 * the corrections are provided.
239 */
240 public Builder setVerticalPositionUncertaintyMeters(
241 double verticalPositionUncertaintyMeters) {
242 mVerticalPositionUncertaintyMeters = verticalPositionUncertaintyMeters;
243 return this;
244 }
245
gomo226b7b72018-12-12 16:49:39 -0800246 /** Sets the time of applicability, GPS time of week in nanoseconds. */
247 public Builder setToaGpsNanosecondsOfWeek(long toaGpsNanosecondsOfWeek) {
248 mToaGpsNanosecondsOfWeek = toaGpsNanosecondsOfWeek;
249 return this;
250 }
251
252 /**
253 * Sets a the list of {@link GnssSingleSatCorrection} containing measurement corrections for
254 * a satellite in view
255 */
gomo3796ab12019-02-20 23:21:11 -0800256 public Builder setSingleSatelliteCorrectionList(
gomo226b7b72018-12-12 16:49:39 -0800257 @Nullable List<GnssSingleSatCorrection> singleSatCorrectionList) {
258 if (singleSatCorrectionList == null) {
259 mSingleSatCorrectionList = null;
260 } else {
261 mSingleSatCorrectionList =
262 Collections.unmodifiableList(new ArrayList<>(singleSatCorrectionList));
263 }
264 return this;
265 }
266
267 /** Builds a {@link GnssMeasurementCorrections} instance as specified by this builder. */
268 public GnssMeasurementCorrections build() {
269 return new GnssMeasurementCorrections(this);
270 }
271 }
272}