blob: a6b953b42f8fc272ae3328a1531aebdc51cdab50 [file] [log] [blame]
Neil Fuller2c6d5102019-11-29 09:02:39 +00001/*
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
17package android.app.timezonedetector;
18
19import android.annotation.NonNull;
20import android.annotation.Nullable;
21import android.os.Parcel;
22import android.os.Parcelable;
23
24import java.util.ArrayList;
25import java.util.Arrays;
26import java.util.Collections;
27import java.util.List;
28import java.util.Objects;
29
30/**
31 * A time signal from a manual (user provided) source. The value consists of the number of
32 * milliseconds elapsed since 1/1/1970 00:00:00 UTC and the time according to the elapsed realtime
33 * clock when that number was established. The elapsed realtime clock is considered accurate but
34 * volatile, so time signals must not be persisted across device resets.
35 *
36 * @hide
37 */
38public final class ManualTimeZoneSuggestion implements Parcelable {
39
40 public static final @NonNull Creator<ManualTimeZoneSuggestion> CREATOR =
41 new Creator<ManualTimeZoneSuggestion>() {
42 public ManualTimeZoneSuggestion createFromParcel(Parcel in) {
43 return ManualTimeZoneSuggestion.createFromParcel(in);
44 }
45
46 public ManualTimeZoneSuggestion[] newArray(int size) {
47 return new ManualTimeZoneSuggestion[size];
48 }
49 };
50
51 @NonNull
52 private final String mZoneId;
53 @Nullable
54 private ArrayList<String> mDebugInfo;
55
56 public ManualTimeZoneSuggestion(@NonNull String zoneId) {
57 mZoneId = Objects.requireNonNull(zoneId);
58 }
59
60 private static ManualTimeZoneSuggestion createFromParcel(Parcel in) {
61 String zoneId = in.readString();
62 ManualTimeZoneSuggestion suggestion = new ManualTimeZoneSuggestion(zoneId);
63 @SuppressWarnings("unchecked")
64 ArrayList<String> debugInfo = (ArrayList<String>) in.readArrayList(null /* classLoader */);
65 suggestion.mDebugInfo = debugInfo;
66 return suggestion;
67 }
68
69 @Override
70 public int describeContents() {
71 return 0;
72 }
73
74 @Override
75 public void writeToParcel(@NonNull Parcel dest, int flags) {
76 dest.writeString(mZoneId);
77 dest.writeList(mDebugInfo);
78 }
79
80 @NonNull
81 public String getZoneId() {
82 return mZoneId;
83 }
84
85 @NonNull
86 public List<String> getDebugInfo() {
87 return mDebugInfo == null
88 ? Collections.emptyList() : Collections.unmodifiableList(mDebugInfo);
89 }
90
91 /**
92 * Associates information with the instance that can be useful for debugging / logging. The
93 * information is present in {@link #toString()} but is not considered for
94 * {@link #equals(Object)} and {@link #hashCode()}.
95 */
96 public void addDebugInfo(String... debugInfos) {
97 if (mDebugInfo == null) {
98 mDebugInfo = new ArrayList<>();
99 }
100 mDebugInfo.addAll(Arrays.asList(debugInfos));
101 }
102
103 @Override
104 public boolean equals(Object o) {
105 if (this == o) {
106 return true;
107 }
108 if (o == null || getClass() != o.getClass()) {
109 return false;
110 }
111 ManualTimeZoneSuggestion
112 that = (ManualTimeZoneSuggestion) o;
113 return Objects.equals(mZoneId, that.mZoneId);
114 }
115
116 @Override
117 public int hashCode() {
118 return Objects.hash(mZoneId);
119 }
120
121 @Override
122 public String toString() {
123 return "ManualTimeSuggestion{"
124 + "mZoneId=" + mZoneId
125 + ", mDebugInfo=" + mDebugInfo
126 + '}';
127 }
128}