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.app.timedetector; 18 19 import android.annotation.NonNull; 20 import android.os.Parcel; 21 import android.os.Parcelable; 22 import android.util.TimestampedValue; 23 24 import java.util.Objects; 25 26 /** 27 * A time signal from a named source. The value consists of the number of milliseconds elapsed since 28 * 1/1/1970 00:00:00 UTC and the time according to the elapsed realtime clock when that number was 29 * established. The elapsed realtime clock is considered accurate but volatile, so time signals 30 * must not be persisted across device resets. 31 * 32 * @hide 33 */ 34 public final class TimeSignal implements Parcelable { 35 36 public static final @android.annotation.NonNull Parcelable.Creator<TimeSignal> CREATOR = 37 new Parcelable.Creator<TimeSignal>() { 38 public TimeSignal createFromParcel(Parcel in) { 39 return TimeSignal.createFromParcel(in); 40 } 41 42 public TimeSignal[] newArray(int size) { 43 return new TimeSignal[size]; 44 } 45 }; 46 47 public static final String SOURCE_ID_NITZ = "nitz"; 48 49 private final String mSourceId; 50 private final TimestampedValue<Long> mUtcTime; 51 TimeSignal(String sourceId, TimestampedValue<Long> utcTime)52 public TimeSignal(String sourceId, TimestampedValue<Long> utcTime) { 53 mSourceId = Objects.requireNonNull(sourceId); 54 mUtcTime = Objects.requireNonNull(utcTime); 55 } 56 createFromParcel(Parcel in)57 private static TimeSignal createFromParcel(Parcel in) { 58 String sourceId = in.readString(); 59 TimestampedValue<Long> utcTime = 60 TimestampedValue.readFromParcel(in, null /* classLoader */, Long.class); 61 return new TimeSignal(sourceId, utcTime); 62 } 63 64 @Override describeContents()65 public int describeContents() { 66 return 0; 67 } 68 69 @Override writeToParcel(@onNull Parcel dest, int flags)70 public void writeToParcel(@NonNull Parcel dest, int flags) { 71 dest.writeString(mSourceId); 72 TimestampedValue.writeToParcel(dest, mUtcTime); 73 } 74 75 @NonNull getSourceId()76 public String getSourceId() { 77 return mSourceId; 78 } 79 80 @NonNull getUtcTime()81 public TimestampedValue<Long> getUtcTime() { 82 return mUtcTime; 83 } 84 85 @Override equals(Object o)86 public boolean equals(Object o) { 87 if (this == o) { 88 return true; 89 } 90 if (o == null || getClass() != o.getClass()) { 91 return false; 92 } 93 TimeSignal that = (TimeSignal) o; 94 return Objects.equals(mSourceId, that.mSourceId) 95 && Objects.equals(mUtcTime, that.mUtcTime); 96 } 97 98 @Override hashCode()99 public int hashCode() { 100 return Objects.hash(mSourceId, mUtcTime); 101 } 102 103 @Override toString()104 public String toString() { 105 return "TimeSignal{" 106 + "mSourceId='" + mSourceId + '\'' 107 + ", mUtcTime=" + mUtcTime 108 + '}'; 109 } 110 } 111