diff --git a/services/core/java/com/android/server/timedetector/TimeDetectorStrategyImpl.java b/services/core/java/com/android/server/timedetector/TimeDetectorStrategyImpl.java index 8c54fa95e04b7..88de34027bb96 100644 --- a/services/core/java/com/android/server/timedetector/TimeDetectorStrategyImpl.java +++ b/services/core/java/com/android/server/timedetector/TimeDetectorStrategyImpl.java @@ -87,11 +87,15 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy { private static final long SYSTEM_CLOCK_PARANOIA_THRESHOLD_MILLIS = 2 * 1000; /** - * The number of previous telephony suggestions to keep for each ID (for use during debugging). + * The number of suggestions to keep. These are logged in bug reports to assist when debugging + * issues with detection. */ - private static final int KEEP_SUGGESTION_HISTORY_SIZE = 30; + private static final int KEEP_SUGGESTION_HISTORY_SIZE = 10; - // A log for changes made to the system clock and why. + /** + * A log that records the decisions / decision metadata that affected the device's system clock + * time. This is logged in bug reports to assist with debugging issues with detection. + */ @NonNull private final LocalLog mTimeChangesLog = new LocalLog(30, false /* useLocalTimestamps */); @@ -140,7 +144,18 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy { if (!validateSuggestionTime(timeSuggestion.getUtcTime(), timeSuggestion)) { return; } - mLastNetworkSuggestion.set(timeSuggestion); + + // The caller submits suggestions with the best available information when there are network + // changes. The best available information may have been cached and if they were all stored + // this would lead to duplicates showing up in the suggestion history. The suggestions may + // be made for different reasons but there is not a significant benefit to storing the same + // suggestion information again. doAutoTimeDetection() should still be called: this ensures + // the suggestion and device state are always re-evaluated, which might produce a different + // detected time if, for example, the age of all suggestions are considered. + NetworkTimeSuggestion lastNetworkSuggestion = mLastNetworkSuggestion.get(); + if (lastNetworkSuggestion == null || !lastNetworkSuggestion.equals(timeSuggestion)) { + mLastNetworkSuggestion.set(timeSuggestion); + } // Now perform auto time detection. The new suggestion may be used to modify the system // clock. diff --git a/services/core/java/com/android/server/timezonedetector/TimeZoneDetectorStrategyImpl.java b/services/core/java/com/android/server/timezonedetector/TimeZoneDetectorStrategyImpl.java index 652dbe1536805..cc33fb0f50084 100644 --- a/services/core/java/com/android/server/timezonedetector/TimeZoneDetectorStrategyImpl.java +++ b/services/core/java/com/android/server/timezonedetector/TimeZoneDetectorStrategyImpl.java @@ -161,16 +161,17 @@ public final class TimeZoneDetectorStrategyImpl implements TimeZoneDetectorStrat public static final int TELEPHONY_SCORE_USAGE_THRESHOLD = TELEPHONY_SCORE_MEDIUM; /** - * The number of previous telephony suggestions to keep for each ID (for use during debugging). + * The number of suggestions to keep. These are logged in bug reports to assist when debugging + * issues with detection. */ - private static final int KEEP_TELEPHONY_SUGGESTION_HISTORY_SIZE = 30; + private static final int KEEP_SUGGESTION_HISTORY_SIZE = 10; @NonNull private final Callback mCallback; /** - * A log that records the decisions / decision metadata that affected the device's time zone - * (for use during debugging). + * A log that records the decisions / decision metadata that affected the device's time zone. + * This is logged in bug reports to assist with debugging issues with detection. */ @NonNull private final LocalLog mTimeZoneChangesLog = new LocalLog(30, false /* useLocalTimestamps */); @@ -182,8 +183,7 @@ public final class TimeZoneDetectorStrategyImpl implements TimeZoneDetectorStrat */ @GuardedBy("this") private ArrayMapWithHistory - mSuggestionBySlotIndex = - new ArrayMapWithHistory<>(KEEP_TELEPHONY_SUGGESTION_HISTORY_SIZE); + mSuggestionBySlotIndex = new ArrayMapWithHistory<>(KEEP_SUGGESTION_HISTORY_SIZE); /** * Creates a new instance of {@link TimeZoneDetectorStrategyImpl}.