gomo | 226b7b7 | 2018-12-12 16:49:39 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package android.location; |
| 18 | |
| 19 | import android.annotation.Nullable; |
| 20 | import android.annotation.SystemApi; |
| 21 | import android.os.Parcel; |
| 22 | import android.os.Parcelable; |
| 23 | |
| 24 | import java.util.ArrayList; |
| 25 | import java.util.Collections; |
| 26 | import 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 |
| 35 | public 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; |
gomo | 6ec9538 | 2019-01-26 03:08:18 -0800 | [diff] [blame] | 46 | /** |
| 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; |
gomo | 226b7b7 | 2018-12-12 16:49:39 -0800 | [diff] [blame] | 60 | |
gomo | 6ec9538 | 2019-01-26 03:08:18 -0800 | [diff] [blame] | 61 | /** Time Of Applicability, GPS time of week in nanoseconds. */ |
gomo | 226b7b7 | 2018-12-12 16:49:39 -0800 | [diff] [blame] | 62 | private long mToaGpsNanosecondsOfWeek; |
| 63 | |
| 64 | /** |
| 65 | * A set of {@link GnssSingleSatCorrection} each containing measurement corrections for a |
gomo | 6ec9538 | 2019-01-26 03:08:18 -0800 | [diff] [blame] | 66 | * satellite in view. |
gomo | 226b7b7 | 2018-12-12 16:49:39 -0800 | [diff] [blame] | 67 | */ |
| 68 | private @Nullable List<GnssSingleSatCorrection> mSingleSatCorrectionList; |
| 69 | |
| 70 | private GnssMeasurementCorrections(Builder builder) { |
| 71 | mLatitudeDegrees = builder.mLatitudeDegrees; |
| 72 | mLongitudeDegrees = builder.mLongitudeDegrees; |
| 73 | mAltitudeMeters = builder.mAltitudeMeters; |
gomo | 6ec9538 | 2019-01-26 03:08:18 -0800 | [diff] [blame] | 74 | mHorizontalPositionUncertaintyMeters = builder.mHorizontalPositionUncertaintyMeters; |
| 75 | mVerticalPositionUncertaintyMeters = builder.mVerticalPositionUncertaintyMeters; |
gomo | 226b7b7 | 2018-12-12 16:49:39 -0800 | [diff] [blame] | 76 | 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 | |
gomo | 6ec9538 | 2019-01-26 03:08:18 -0800 | [diff] [blame] | 102 | /** |
| 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 | |
gomo | 226b7b7 | 2018-12-12 16:49:39 -0800 | [diff] [blame] | 118 | /** 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 | */ |
gomo | 3796ab1 | 2019-02-20 23:21:11 -0800 | [diff] [blame] | 127 | public @Nullable List<GnssSingleSatCorrection> getSingleSatelliteCorrectionList() { |
gomo | 226b7b7 | 2018-12-12 16:49:39 -0800 | [diff] [blame] | 128 | return mSingleSatCorrectionList; |
| 129 | } |
| 130 | |
| 131 | @Override |
| 132 | public int describeContents() { |
| 133 | return 0; |
| 134 | } |
| 135 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame^] | 136 | public static final @android.annotation.NonNull Creator<GnssMeasurementCorrections> CREATOR = |
gomo | 226b7b7 | 2018-12-12 16:49:39 -0800 | [diff] [blame] | 137 | new Creator<GnssMeasurementCorrections>() { |
| 138 | @Override |
| 139 | public GnssMeasurementCorrections createFromParcel(Parcel parcel) { |
gomo | 3796ab1 | 2019-02-20 23:21:11 -0800 | [diff] [blame] | 140 | final GnssMeasurementCorrections.Builder gnssMeasurementCorrectons = |
gomo | 226b7b7 | 2018-12-12 16:49:39 -0800 | [diff] [blame] | 141 | new Builder() |
| 142 | .setLatitudeDegrees(parcel.readDouble()) |
| 143 | .setLongitudeDegrees(parcel.readDouble()) |
| 144 | .setAltitudeMeters(parcel.readDouble()) |
gomo | 6ec9538 | 2019-01-26 03:08:18 -0800 | [diff] [blame] | 145 | .setHorizontalPositionUncertaintyMeters(parcel.readDouble()) |
| 146 | .setVerticalPositionUncertaintyMeters(parcel.readDouble()) |
gomo | 226b7b7 | 2018-12-12 16:49:39 -0800 | [diff] [blame] | 147 | .setToaGpsNanosecondsOfWeek(parcel.readLong()); |
| 148 | List<GnssSingleSatCorrection> singleSatCorrectionList = new ArrayList<>(); |
| 149 | parcel.readTypedList(singleSatCorrectionList, GnssSingleSatCorrection.CREATOR); |
gomo | 3796ab1 | 2019-02-20 23:21:11 -0800 | [diff] [blame] | 150 | gnssMeasurementCorrectons.setSingleSatelliteCorrectionList( |
gomo | 226b7b7 | 2018-12-12 16:49:39 -0800 | [diff] [blame] | 151 | 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)); |
gomo | 6ec9538 | 2019-01-26 03:08:18 -0800 | [diff] [blame] | 168 | builder.append(String.format(format, "HorizontalPositionUncertaintyMeters = ", |
| 169 | mHorizontalPositionUncertaintyMeters)); |
| 170 | builder.append(String.format(format, "VerticalPositionUncertaintyMeters = ", |
| 171 | mVerticalPositionUncertaintyMeters)); |
gomo | 226b7b7 | 2018-12-12 16:49:39 -0800 | [diff] [blame] | 172 | 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); |
gomo | 6ec9538 | 2019-01-26 03:08:18 -0800 | [diff] [blame] | 184 | parcel.writeDouble(mHorizontalPositionUncertaintyMeters); |
| 185 | parcel.writeDouble(mVerticalPositionUncertaintyMeters); |
gomo | 226b7b7 | 2018-12-12 16:49:39 -0800 | [diff] [blame] | 186 | parcel.writeLong(mToaGpsNanosecondsOfWeek); |
| 187 | parcel.writeTypedList(mSingleSatCorrectionList); |
| 188 | } |
| 189 | |
| 190 | /** Builder for {@link GnssMeasurementCorrections} */ |
gomo | 3796ab1 | 2019-02-20 23:21:11 -0800 | [diff] [blame] | 191 | public static final class Builder { |
gomo | 226b7b7 | 2018-12-12 16:49:39 -0800 | [diff] [blame] | 192 | /** |
| 193 | * For documentation of below fields, see corresponding fields in {@link |
| 194 | * GnssMeasurementCorrections}. |
| 195 | */ |
| 196 | private double mLatitudeDegrees; |
gomo | 226b7b7 | 2018-12-12 16:49:39 -0800 | [diff] [blame] | 197 | private double mLongitudeDegrees; |
| 198 | private double mAltitudeMeters; |
gomo | 6ec9538 | 2019-01-26 03:08:18 -0800 | [diff] [blame] | 199 | private double mHorizontalPositionUncertaintyMeters; |
| 200 | private double mVerticalPositionUncertaintyMeters; |
gomo | 226b7b7 | 2018-12-12 16:49:39 -0800 | [diff] [blame] | 201 | 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 | |
gomo | 6ec9538 | 2019-01-26 03:08:18 -0800 | [diff] [blame] | 225 | |
| 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 | |
gomo | 226b7b7 | 2018-12-12 16:49:39 -0800 | [diff] [blame] | 246 | /** 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 | */ |
gomo | 3796ab1 | 2019-02-20 23:21:11 -0800 | [diff] [blame] | 256 | public Builder setSingleSatelliteCorrectionList( |
gomo | 226b7b7 | 2018-12-12 16:49:39 -0800 | [diff] [blame] | 257 | @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 | } |