1 /* 2 * Copyright (C) 2019 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.NonNull; 20 import android.os.Parcel; 21 import android.os.Parcelable; 22 23 /** 24 * Data class for passing location derived time. 25 * @hide 26 */ 27 public final class LocationTime implements Parcelable { 28 29 private final long mTime; 30 private final long mElapsedRealtimeNanos; 31 LocationTime(long time, long elapsedRealtimeNanos)32 public LocationTime(long time, long elapsedRealtimeNanos) { 33 mTime = time; 34 mElapsedRealtimeNanos = elapsedRealtimeNanos; 35 } 36 37 /** 38 * The current time, according to the Gnss location provider. */ getTime()39 public long getTime() { 40 return mTime; 41 } 42 43 /** 44 * The elapsed nanos since boot {@link #getTime} was computed at. 45 */ getElapsedRealtimeNanos()46 public long getElapsedRealtimeNanos() { 47 return mElapsedRealtimeNanos; 48 } 49 50 @Override writeToParcel(Parcel out, int flags)51 public void writeToParcel(Parcel out, int flags) { 52 out.writeLong(mTime); 53 out.writeLong(mElapsedRealtimeNanos); 54 } 55 56 @Override describeContents()57 public int describeContents() { 58 return 0; 59 } 60 61 public static final @NonNull Parcelable.Creator<LocationTime> CREATOR = 62 new Parcelable.Creator<LocationTime>() { 63 public LocationTime createFromParcel(Parcel in) { 64 long time = in.readLong(); 65 long elapsedRealtimeNanos = in.readLong(); 66 return new LocationTime(time, elapsedRealtimeNanos); 67 } 68 69 public LocationTime[] newArray(int size) { 70 return new LocationTime[size]; 71 } 72 }; 73 } 74