Debian Codegraph @

core/java/android/app/timedetector/GnssTimeSuggestion.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2020 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.os.ShellCommand;
23 import android.os.TimestampedValue;
24
25 import java.io.PrintWriter;
26 import java.util.List;
27 import java.util.Objects;
28
29 /**
30 * A time signal from a GNSS source.
31 *
32 * <p>See {@link TimeSuggestionHelper} for property information.
33 *
34 * @hide
35 */
36 public final class GnssTimeSuggestion implements Parcelable {
37
38 public static final @NonNull Creator<GnssTimeSuggestion> CREATOR =
39 new Creator<GnssTimeSuggestion>() {
40 public GnssTimeSuggestion createFromParcel(Parcel in) {
41 TimeSuggestionHelper helper = TimeSuggestionHelper.handleCreateFromParcel(
42 GnssTimeSuggestion.class, in);
43 return new GnssTimeSuggestion(helper);
44 }
45
46 public GnssTimeSuggestion[] newArray(int size) {
47 return new GnssTimeSuggestion[size];
48 }
49 };
50
51 @NonNull private final TimeSuggestionHelper mTimeSuggestionHelper;
52
53 public GnssTimeSuggestion(@NonNull TimestampedValue<Long> unixEpochTime) {
54 mTimeSuggestionHelper = new TimeSuggestionHelper(GnssTimeSuggestion.class, unixEpochTime);
55 }
56
57 private GnssTimeSuggestion(@NonNull TimeSuggestionHelper helper) {
58 mTimeSuggestionHelper = Objects.requireNonNull(helper);
59 }
60
61 @Override
62 public int describeContents() {
63 return 0;
64 }
65
66 @Override
67 public void writeToParcel(@NonNull Parcel dest, int flags) {
68 mTimeSuggestionHelper.handleWriteToParcel(dest, flags);
69 }
70
71 @NonNull
72 public TimestampedValue<Long> getUnixEpochTime() {
73 return mTimeSuggestionHelper.getUnixEpochTime();
74 }
75
76 @NonNull
77 public List<String> getDebugInfo() {
78 return mTimeSuggestionHelper.getDebugInfo();
79 }
80
81 /**
82 * Associates information with the instance that can be useful for debugging / logging. The
83 * information is present in {@link #toString()} but is not considered for
84 * {@link #equals(Object)} and {@link #hashCode()}.
85 */
86 public void addDebugInfo(String... debugInfos) {
87 mTimeSuggestionHelper.addDebugInfo(debugInfos);
88 }
89
90 @Override
91 public boolean equals(Object o) {
92 if (this == o) {
93 return true;
94 }
95 if (o == null || getClass() != o.getClass()) {
96 return false;
97 }
98 GnssTimeSuggestion that = (GnssTimeSuggestion) o;
99 return mTimeSuggestionHelper.handleEquals(that.mTimeSuggestionHelper);
100 }
101
102 @Override
103 public int hashCode() {
104 return mTimeSuggestionHelper.hashCode();
105 }
106
107 @Override
108 public String toString() {
109 return mTimeSuggestionHelper.handleToString();
110 }
111
112 /** Parses command line args to create a {@link GnssTimeSuggestion}. */
113 public static GnssTimeSuggestion parseCommandLineArg(@NonNull ShellCommand cmd)
114 throws IllegalArgumentException {
115 TimeSuggestionHelper suggestionHelper =
116 TimeSuggestionHelper.handleParseCommandLineArg(GnssTimeSuggestion.class, cmd);
117 return new GnssTimeSuggestion(suggestionHelper);
118 }
119
120 /** Prints the command line args needed to create a {@link GnssTimeSuggestion}. */
121 public static void printCommandLineOpts(PrintWriter pw) {
122 TimeSuggestionHelper.handlePrintCommandLineOpts(pw, "GNSS", GnssTimeSuggestion.class);
123 }
124 }