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.FloatRange; 21 import android.annotation.IntRange; 22 import android.annotation.NonNull; 23 import android.annotation.SystemApi; 24 import android.location.flags.Flags; 25 import android.os.Parcel; 26 import android.os.Parcelable; 27 28 import com.android.internal.util.Preconditions; 29 30 /** 31 * A class contains parameters to convert from current GNSS time to UTC time. 32 * 33 * <p>This is defined in RINEX 3.05 "TIME SYSTEM CORR" in table A5. 34 * 35 * @hide 36 */ 37 @FlaggedApi(Flags.FLAG_GNSS_ASSISTANCE_INTERFACE) 38 @SystemApi 39 public final class UtcModel implements Parcelable { 40 /** Bias coefficient of GNSS time scale relative to UTC time scale in seconds. */ 41 private final double mA0; 42 43 /** Drift coefficient of GNSS time scale relative to UTC time scale in seconds per second. */ 44 private final double mA1; 45 46 /** Reference GNSS time of week in seconds. */ 47 private final int mTimeOfWeek; 48 49 /** Reference GNSS week number. */ 50 private final int mWeekNumber; 51 UtcModel(Builder builder)52 private UtcModel(Builder builder) { 53 Preconditions.checkArgumentInRange(builder.mA0, -2.0f, 2.0f, "A0"); 54 Preconditions.checkArgumentInRange(builder.mA1, -7.45e-9f, 7.45e-9f, "A1"); 55 Preconditions.checkArgumentInRange(builder.mTimeOfWeek, 0, 604800, "TimeOfWeek"); 56 Preconditions.checkArgument(builder.mWeekNumber >= 0); 57 mA0 = builder.mA0; 58 mA1 = builder.mA1; 59 mTimeOfWeek = builder.mTimeOfWeek; 60 mWeekNumber = builder.mWeekNumber; 61 } 62 63 /** Returns the bias coefficient of GNSS time scale relative to UTC time scale in seconds. */ 64 @FloatRange(from = -2.0f, to = 2.0f) getA0()65 public double getA0() { 66 return mA0; 67 } 68 69 /** 70 * Returns the drift coefficient of GNSS time scale relative to UTC time scale in seconds per 71 * second. 72 */ 73 @FloatRange(from = -7.45e-9f, to = 7.45e-9f) getA1()74 public double getA1() { 75 return mA1; 76 } 77 78 /** Returns the reference GNSS time of week in seconds. */ 79 @IntRange(from = 0, to = 604800) getTimeOfWeek()80 public int getTimeOfWeek() { 81 return mTimeOfWeek; 82 } 83 84 /** Returns the reference GNSS week number. */ 85 @IntRange(from = 0) getWeekNumber()86 public int getWeekNumber() { 87 return mWeekNumber; 88 } 89 90 @Override describeContents()91 public int describeContents() { 92 return 0; 93 } 94 @Override 95 @NonNull toString()96 public String toString() { 97 StringBuilder builder = new StringBuilder("UtcModel["); 98 builder.append("a0 = ").append(mA0); 99 builder.append(", a1 = ").append(mA1); 100 builder.append(", timeOfWeek = ").append(mTimeOfWeek); 101 builder.append(", weekNumber = ").append(mWeekNumber); 102 builder.append("]"); 103 return builder.toString(); 104 } 105 106 @Override writeToParcel(@onNull Parcel dest, int flags)107 public void writeToParcel(@NonNull Parcel dest, int flags) { 108 dest.writeDouble(mA0); 109 dest.writeDouble(mA1); 110 dest.writeInt(mTimeOfWeek); 111 dest.writeInt(mWeekNumber); 112 } 113 114 public static final @NonNull Creator<UtcModel> CREATOR = 115 new Creator<UtcModel>() { 116 @Override 117 public UtcModel createFromParcel(@NonNull Parcel source) { 118 return new UtcModel.Builder() 119 .setA0(source.readDouble()) 120 .setA1(source.readDouble()) 121 .setTimeOfWeek(source.readInt()) 122 .setWeekNumber(source.readInt()) 123 .build(); 124 } 125 126 @Override 127 public UtcModel[] newArray(int size) { 128 return new UtcModel[size]; 129 } 130 }; 131 132 /** Builder for {@link UtcModel}. */ 133 public static final class Builder { 134 private double mA0; 135 private double mA1; 136 private int mTimeOfWeek; 137 private int mWeekNumber; 138 139 /** Sets the bias coefficient of GNSS time scale relative to UTC time scale in seconds. */ 140 @NonNull setA0(@loatRangefrom = -2.0f, to = 2.0f) double a0)141 public Builder setA0(@FloatRange(from = -2.0f, to = 2.0f) double a0) { 142 mA0 = a0; 143 return this; 144 } 145 146 /** 147 * Sets the drift coefficient of GNSS time scale relative to UTC time scale in seconds per 148 * second. 149 */ 150 @NonNull setA1(@loatRangefrom = -7.45e-9f, to = 7.45e-9f) double a1)151 public Builder setA1(@FloatRange(from = -7.45e-9f, to = 7.45e-9f) double a1) { 152 mA1 = a1; 153 return this; 154 } 155 156 /** Sets the reference GNSS time of week in seconds. */ 157 @NonNull setTimeOfWeek(@ntRangefrom = 0, to = 604800) int timeOfWeek)158 public Builder setTimeOfWeek(@IntRange(from = 0, to = 604800) int timeOfWeek) { 159 mTimeOfWeek = timeOfWeek; 160 return this; 161 } 162 163 /** Sets the reference GNSS week number. */ 164 @NonNull setWeekNumber(@ntRangefrom = 0) int weekNumber)165 public Builder setWeekNumber(@IntRange(from = 0) int weekNumber) { 166 mWeekNumber = weekNumber; 167 return this; 168 } 169 170 /** Builds a {@link UtcModel} instance as specified by this builder. */ 171 @NonNull build()172 public UtcModel build() { 173 return new UtcModel(this); 174 } 175 } 176 } 177