summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Hall Liu <hallliu@google.com> 2018-03-06 14:20:37 -0800
committer Hall Liu <hallliu@google.com> 2018-03-06 14:20:37 -0800
commit8c8d7babf16221fae2fecaff92e4b11a011297c3 (patch)
treea739d6e894b06f00e763be3b75578d00bc5d0b68
parenta60e42cc2dd75d1de63721c6dd62cf0b0303dbda (diff)
Fix Telecom dumpsys timestamps
Change the dumpsys timestamps to use java.time for processing and always log events with local timezone that was in effect at the time the event happened. Bug: 74250969 Test: manual, run dumpsys Change-Id: Ie53cff4400be1528b3224bd556536a689ef22c8c
-rw-r--r--telecomm/java/android/telecom/Logging/EventManager.java31
1 files changed, 18 insertions, 13 deletions
diff --git a/telecomm/java/android/telecom/Logging/EventManager.java b/telecomm/java/android/telecom/Logging/EventManager.java
index 4fc338539f42..2bda6480b99e 100644
--- a/telecomm/java/android/telecom/Logging/EventManager.java
+++ b/telecomm/java/android/telecom/Logging/EventManager.java
@@ -24,21 +24,20 @@ import android.util.Pair;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.IndentingPrintWriter;
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
+import java.time.Instant;
+import java.time.ZoneId;
+import java.time.ZonedDateTime;
+import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
-import java.util.Date;
import java.util.HashMap;
import java.util.IllegalFormatException;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
-import java.util.TimeZone;
import java.util.concurrent.LinkedBlockingQueue;
-import java.util.stream.Collectors;
/**
* A utility class that provides the ability to define Events that a subsystem deems important, and
@@ -53,7 +52,8 @@ public class EventManager {
public static final String TAG = "Logging.Events";
@VisibleForTesting
public static final int DEFAULT_EVENTS_TO_CACHE = 10; // Arbitrarily chosen.
- private final DateFormat sDateFormat = new SimpleDateFormat("HH:mm:ss.SSS");
+ public static final DateTimeFormatter DATE_TIME_FORMATTER =
+ DateTimeFormatter.ofPattern("HH:mm:ss.SSS");
public interface Loggable {
/**
@@ -131,11 +131,17 @@ public class EventManager {
public String sessionId;
public long time;
public Object data;
+ // String storing the date for display. This will be computed at the time/timezone when
+ // the event is recorded.
+ public final String timestampString;
public Event(String eventId, String sessionId, long time, Object data) {
this.eventId = eventId;
this.sessionId = sessionId;
this.time = time;
+ timestampString =
+ ZonedDateTime.ofInstant(Instant.ofEpochMilli(time), ZoneId.systemDefault())
+ .format(DATE_TIME_FORMATTER);
this.data = data;
}
}
@@ -228,7 +234,7 @@ public class EventManager {
pw.increaseIndent();
for (Event event : mEvents) {
- pw.print(sDateFormat.format(new Date(event.time)));
+ pw.print(event.timestampString);
pw.print(" - ");
pw.print(event.eventId);
if (event.data != null) {
@@ -269,7 +275,6 @@ public class EventManager {
public EventManager(@NonNull SessionManager.ISessionIdQueryHandler l) {
mSessionIdHandler = l;
- sDateFormat.setTimeZone(TimeZone.getDefault());
}
public void event(Loggable recordEntry, String event, Object data) {
@@ -329,15 +334,15 @@ public class EventManager {
}
}
- // Sort by event time.
- Comparator<Pair<Loggable, Event>> byEventTime = (e1, e2) -> {
- return Long.compare(e1.second.time, e2.second.time);
- };
+ // Sort by event time. This might result in out-of-order seeming events if the timezone
+ // changes somewhere in the middle.
+ Comparator<Pair<Loggable, Event>> byEventTime =
+ Comparator.comparingLong(e -> e.second.time);
events.sort(byEventTime);
pw.increaseIndent();
for (Pair<Loggable, Event> event : events) {
- pw.print(sDateFormat.format(new Date(event.second.time)));
+ pw.print(event.second.timestampString);
pw.print(",");
pw.print(event.first.getId());
pw.print(",");