1 /* 2 * Copyright (C) 2024 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.FlaggedApi; 20 import android.annotation.NonNull; 21 import android.annotation.Nullable; 22 import android.annotation.SuppressLint; 23 import android.annotation.SystemApi; 24 import android.location.GnssAssistance.GnssSatelliteCorrections; 25 import android.location.flags.Flags; 26 import android.os.Parcel; 27 import android.os.Parcelable; 28 29 import java.util.ArrayList; 30 import java.util.Collections; 31 import java.util.List; 32 33 /** 34 * A class contains GPS assistance. 35 * 36 * @hide 37 */ 38 @FlaggedApi(Flags.FLAG_GNSS_ASSISTANCE_INTERFACE) 39 @SystemApi 40 public final class GpsAssistance implements Parcelable { 41 42 /** The GPS almanac. */ 43 @Nullable private final GnssAlmanac mAlmanac; 44 45 /** The Klobuchar ionospheric model. */ 46 @Nullable private final KlobucharIonosphericModel mIonosphericModel; 47 48 /** The UTC model. */ 49 @Nullable private final UtcModel mUtcModel; 50 51 /** The leap seconds model. */ 52 @Nullable private final LeapSecondsModel mLeapSecondsModel; 53 54 /** The list of auxiliary informations. */ 55 @NonNull private final List<AuxiliaryInformation> mAuxiliaryInformation; 56 57 /** The list of time models. */ 58 @NonNull private final List<TimeModel> mTimeModels; 59 60 /** The list of GPS ephemeris. */ 61 @NonNull private final List<GpsSatelliteEphemeris> mSatelliteEphemeris; 62 63 /** The list of real time integrity models. */ 64 @NonNull private final List<RealTimeIntegrityModel> mRealTimeIntegrityModels; 65 66 /** The list of GPS satellite corrections. */ 67 @NonNull private final List<GnssSatelliteCorrections> mSatelliteCorrections; 68 GpsAssistance(Builder builder)69 private GpsAssistance(Builder builder) { 70 mAlmanac = builder.mAlmanac; 71 mIonosphericModel = builder.mIonosphericModel; 72 mUtcModel = builder.mUtcModel; 73 mLeapSecondsModel = builder.mLeapSecondsModel; 74 if (builder.mAuxiliaryInformation != null) { 75 mAuxiliaryInformation = 76 Collections.unmodifiableList(new ArrayList<>(builder.mAuxiliaryInformation)); 77 } else { 78 mAuxiliaryInformation = new ArrayList<>(); 79 } 80 if (builder.mTimeModels != null) { 81 mTimeModels = Collections.unmodifiableList(new ArrayList<>(builder.mTimeModels)); 82 } else { 83 mTimeModels = new ArrayList<>(); 84 } 85 if (builder.mSatelliteEphemeris != null) { 86 mSatelliteEphemeris = 87 Collections.unmodifiableList(new ArrayList<>(builder.mSatelliteEphemeris)); 88 } else { 89 mSatelliteEphemeris = new ArrayList<>(); 90 } 91 if (builder.mRealTimeIntegrityModels != null) { 92 mRealTimeIntegrityModels = 93 Collections.unmodifiableList(new ArrayList<>(builder.mRealTimeIntegrityModels)); 94 } else { 95 mRealTimeIntegrityModels = new ArrayList<>(); 96 } 97 if (builder.mSatelliteCorrections != null) { 98 mSatelliteCorrections = 99 Collections.unmodifiableList(new ArrayList<>(builder.mSatelliteCorrections)); 100 } else { 101 mSatelliteCorrections = new ArrayList<>(); 102 } 103 } 104 105 /** Returns the GPS almanac. */ 106 @Nullable getAlmanac()107 public GnssAlmanac getAlmanac() { 108 return mAlmanac; 109 } 110 111 /** Returns the Klobuchar ionospheric model. */ 112 @Nullable getIonosphericModel()113 public KlobucharIonosphericModel getIonosphericModel() { 114 return mIonosphericModel; 115 } 116 117 /** Returns the UTC model. */ 118 @Nullable getUtcModel()119 public UtcModel getUtcModel() { 120 return mUtcModel; 121 } 122 123 /** Returns the leap seconds model. */ 124 @Nullable getLeapSecondsModel()125 public LeapSecondsModel getLeapSecondsModel() { 126 return mLeapSecondsModel; 127 } 128 129 /** Returns the list of auxiliary informations. */ 130 @NonNull getAuxiliaryInformation()131 public List<AuxiliaryInformation> getAuxiliaryInformation() { 132 return mAuxiliaryInformation; 133 } 134 135 /** Returns the list of time models. */ 136 @NonNull getTimeModels()137 public List<TimeModel> getTimeModels() { 138 return mTimeModels; 139 } 140 141 /** Returns the list of GPS ephemeris. */ 142 @NonNull getSatelliteEphemeris()143 public List<GpsSatelliteEphemeris> getSatelliteEphemeris() { 144 return mSatelliteEphemeris; 145 } 146 147 /** Returns the list of real time integrity models. */ 148 @NonNull getRealTimeIntegrityModels()149 public List<RealTimeIntegrityModel> getRealTimeIntegrityModels() { 150 return mRealTimeIntegrityModels; 151 } 152 153 /** Returns the list of GPS satellite corrections. */ 154 @NonNull getSatelliteCorrections()155 public List<GnssSatelliteCorrections> getSatelliteCorrections() { 156 return mSatelliteCorrections; 157 } 158 159 public static final @NonNull Creator<GpsAssistance> CREATOR = 160 new Creator<GpsAssistance>() { 161 @Override 162 @NonNull 163 public GpsAssistance createFromParcel(Parcel in) { 164 return new GpsAssistance.Builder() 165 .setAlmanac(in.readTypedObject(GnssAlmanac.CREATOR)) 166 .setIonosphericModel( 167 in.readTypedObject(KlobucharIonosphericModel.CREATOR)) 168 .setUtcModel(in.readTypedObject(UtcModel.CREATOR)) 169 .setLeapSecondsModel(in.readTypedObject(LeapSecondsModel.CREATOR)) 170 .setAuxiliaryInformation( 171 in.createTypedArrayList(AuxiliaryInformation.CREATOR)) 172 .setTimeModels(in.createTypedArrayList(TimeModel.CREATOR)) 173 .setSatelliteEphemeris( 174 in.createTypedArrayList(GpsSatelliteEphemeris.CREATOR)) 175 .setRealTimeIntegrityModels( 176 in.createTypedArrayList(RealTimeIntegrityModel.CREATOR)) 177 .setSatelliteCorrections( 178 in.createTypedArrayList(GnssSatelliteCorrections.CREATOR)) 179 .build(); 180 } 181 182 @Override 183 public GpsAssistance[] newArray(int size) { 184 return new GpsAssistance[size]; 185 } 186 }; 187 188 @Override describeContents()189 public int describeContents() { 190 return 0; 191 } 192 193 @Override writeToParcel(@onNull Parcel dest, int flags)194 public void writeToParcel(@NonNull Parcel dest, int flags) { 195 dest.writeTypedObject(mAlmanac, flags); 196 dest.writeTypedObject(mIonosphericModel, flags); 197 dest.writeTypedObject(mUtcModel, flags); 198 dest.writeTypedObject(mLeapSecondsModel, flags); 199 dest.writeTypedList(mAuxiliaryInformation); 200 dest.writeTypedList(mTimeModels); 201 dest.writeTypedList(mSatelliteEphemeris); 202 dest.writeTypedList(mRealTimeIntegrityModels); 203 dest.writeTypedList(mSatelliteCorrections); 204 } 205 206 @Override 207 @NonNull toString()208 public String toString() { 209 StringBuilder builder = new StringBuilder("GnssAssistance["); 210 builder.append("almanac = ").append(mAlmanac); 211 builder.append(", ionosphericModel = ").append(mIonosphericModel); 212 builder.append(", utcModel = ").append(mUtcModel); 213 builder.append(", leapSecondsModel = ").append(mLeapSecondsModel); 214 builder.append(", auxiliaryInformation = ").append(mAuxiliaryInformation); 215 builder.append(", timeModels = ").append(mTimeModels); 216 builder.append(", satelliteEphemeris = ").append(mSatelliteEphemeris); 217 builder.append(", realTimeIntegrityModels = ").append(mRealTimeIntegrityModels); 218 builder.append(", satelliteCorrections = ").append(mSatelliteCorrections); 219 builder.append("]"); 220 return builder.toString(); 221 } 222 223 /** Builder for {@link GpsAssistance}. */ 224 public static final class Builder { 225 private GnssAlmanac mAlmanac; 226 private KlobucharIonosphericModel mIonosphericModel; 227 private UtcModel mUtcModel; 228 private LeapSecondsModel mLeapSecondsModel; 229 private List<AuxiliaryInformation> mAuxiliaryInformation; 230 private List<TimeModel> mTimeModels; 231 private List<GpsSatelliteEphemeris> mSatelliteEphemeris; 232 private List<RealTimeIntegrityModel> mRealTimeIntegrityModels; 233 private List<GnssSatelliteCorrections> mSatelliteCorrections; 234 235 /** Sets the GPS almanac. */ 236 @NonNull setAlmanac( @ullable @uppressLint"NullableCollection") GnssAlmanac almanac)237 public Builder setAlmanac( 238 @Nullable @SuppressLint("NullableCollection") GnssAlmanac almanac) { 239 mAlmanac = almanac; 240 return this; 241 } 242 243 /** Sets the Klobuchar ionospheric model. */ 244 @NonNull setIonosphericModel(@ullable KlobucharIonosphericModel ionosphericModel)245 public Builder setIonosphericModel(@Nullable KlobucharIonosphericModel ionosphericModel) { 246 mIonosphericModel = ionosphericModel; 247 return this; 248 } 249 250 /** Sets the UTC model. */ 251 @NonNull setUtcModel(@ullable UtcModel utcModel)252 public Builder setUtcModel(@Nullable UtcModel utcModel) { 253 mUtcModel = utcModel; 254 return this; 255 } 256 257 /** Sets the leap seconds model. */ 258 @NonNull setLeapSecondsModel(@ullable LeapSecondsModel leapSecondsModel)259 public Builder setLeapSecondsModel(@Nullable LeapSecondsModel leapSecondsModel) { 260 mLeapSecondsModel = leapSecondsModel; 261 return this; 262 } 263 264 /** Sets the list of auxiliary informations. */ 265 @NonNull setAuxiliaryInformation( @onNull List<AuxiliaryInformation> auxiliaryInformation)266 public Builder setAuxiliaryInformation( 267 @NonNull List<AuxiliaryInformation> auxiliaryInformation) { 268 mAuxiliaryInformation = auxiliaryInformation; 269 return this; 270 } 271 272 /** Sets the list of time models. */ 273 @NonNull setTimeModels(@onNull List<TimeModel> timeModels)274 public Builder setTimeModels(@NonNull List<TimeModel> timeModels) { 275 mTimeModels = timeModels; 276 return this; 277 } 278 279 /** Sets the list of GPS ephemeris. */ 280 @NonNull setSatelliteEphemeris( @onNull List<GpsSatelliteEphemeris> satelliteEphemeris)281 public Builder setSatelliteEphemeris( 282 @NonNull List<GpsSatelliteEphemeris> satelliteEphemeris) { 283 mSatelliteEphemeris = satelliteEphemeris; 284 return this; 285 } 286 287 /** Sets the list of real time integrity models. */ 288 @NonNull setRealTimeIntegrityModels( @onNull List<RealTimeIntegrityModel> realTimeIntegrityModels)289 public Builder setRealTimeIntegrityModels( 290 @NonNull List<RealTimeIntegrityModel> realTimeIntegrityModels) { 291 mRealTimeIntegrityModels = realTimeIntegrityModels; 292 return this; 293 } 294 295 /** Sets the list of GPS satellite corrections. */ 296 @NonNull setSatelliteCorrections( @onNull List<GnssSatelliteCorrections> satelliteCorrections)297 public Builder setSatelliteCorrections( 298 @NonNull List<GnssSatelliteCorrections> satelliteCorrections) { 299 mSatelliteCorrections = satelliteCorrections; 300 return this; 301 } 302 303 /** Builds a {@link GpsAssistance} instance as specified by this builder. */ 304 @NonNull build()305 public GpsAssistance build() { 306 return new GpsAssistance(this); 307 } 308 } 309 } 310