/* * Copyright (C) 2019 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.app.timedetector; import android.annotation.NonNull; import android.annotation.Nullable; import android.app.time.UnixEpochTime; import android.os.Parcel; import android.os.Parcelable; import android.os.ShellCommand; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Objects; /** * A time suggestion from an identified telephony source. e.g. from NITZ information from a specific * radio. * *
{@code slotIndex} identifies the suggestion source. This enables detection logic to identify * suggestions from the same source when there are several in use. * *
{@code unixEpochTime}. When not {@code null}, the {@code unixEpochTime.value} is the number of * milliseconds elapsed since 1/1/1970 00:00:00 UTC. The {@code unixEpochTime.referenceTimeMillis} * is the value of the elapsed realtime clock when the {@code unixEpochTime.value} was established. * Note that the elapsed realtime clock is considered accurate but it is volatile, so time * suggestions cannot be persisted across device resets. {@code unixEpochTime} can be {@code null} * to indicate that the telephony source has entered an "un-opinionated" state and any previous * suggestion from the source is being withdrawn. * *
{@code debugInfo} contains debugging metadata associated with the suggestion. This is used to
* record why the suggestion exists, e.g. what triggered it to be made and what heuristic was used
* to determine the time or its absence. This information exists only to aid in debugging and
* therefore is used by {@link #toString()}, but it is not for use in detection logic and is not
* considered in {@link #hashCode()} or {@link #equals(Object)}.
*
* @hide
*/
public final class TelephonyTimeSuggestion implements Parcelable {
/** @hide */
public static final @NonNull Parcelable.Creator See {@link TelephonyTimeSuggestion} for more information about {@code slotIndex}.
*/
public int getSlotIndex() {
return mSlotIndex;
}
/**
* Returns the suggested time or {@code null} if there isn't one.
*
* See {@link TelephonyTimeSuggestion} for more information about {@code unixEpochTime}.
*/
@Nullable
public UnixEpochTime getUnixEpochTime() {
return mUnixEpochTime;
}
/**
* Returns debug metadata for the suggestion.
*
* See {@link TelephonyTimeSuggestion} for more information about {@code debugInfo}.
*/
@NonNull
public List See {@link TelephonyTimeSuggestion} for more information about {@code debugInfo}.
*/
public void addDebugInfo(@NonNull String debugInfo) {
if (mDebugInfo == null) {
mDebugInfo = new ArrayList<>();
}
mDebugInfo.add(debugInfo);
}
/**
* Associates information with the instance that can be useful for debugging / logging.
*
* See {@link TelephonyTimeSuggestion} for more information about {@code debugInfo}.
*/
public void addDebugInfo(@NonNull List See {@link TelephonyTimeSuggestion} for more information about {@code slotIndex}.
*/
public Builder(int slotIndex) {
mSlotIndex = slotIndex;
}
/**
* Returns the builder for call chaining.
*
* See {@link TelephonyTimeSuggestion} for more information about {@code unixEpochTime}.
*/
@NonNull
public Builder setUnixEpochTime(@Nullable UnixEpochTime unixEpochTime) {
mUnixEpochTime = unixEpochTime;
return this;
}
/**
* Returns the builder for call chaining.
*
* See {@link TelephonyTimeSuggestion} for more information about {@code debugInfo}.
*/
@NonNull
public Builder addDebugInfo(@NonNull String debugInfo) {
if (mDebugInfo == null) {
mDebugInfo = new ArrayList<>();
}
mDebugInfo.add(debugInfo);
return this;
}
/** Returns the {@link TelephonyTimeSuggestion}. */
@NonNull
public TelephonyTimeSuggestion build() {
return new TelephonyTimeSuggestion(this);
}
}
}