Commit fbee3454 authored by Hazem Ashmawy's avatar Hazem Ashmawy Committed by Commit Bot

[AW] DevUI: use millisecs for crash upload time

Use millisecs since epoch for crash upload time similar to crash
capture time for more consistency.

Fixed: 1021926
Test: bin/run_webview_instrumentation_test_apk --test-filter "*UploadedCrashesInfoLoaderTest*"
Test: Inspect Crash UI to make sure right time is shown
Change-Id: I1adb49eb083044f8af8190aea959fc2e1f9e951f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1901293
Commit-Queue: Hazem Ashmawy <hazems@chromium.org>
Reviewed-by: default avatarTobias Sargeant <tobiasjs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#713454}
parent 79e07a5d
...@@ -142,7 +142,7 @@ public class CrashesListActivity extends Activity { ...@@ -142,7 +142,7 @@ public class CrashesListActivity extends Activity {
} }
if (crashInfo.uploadTime >= 0) { if (crashInfo.uploadTime >= 0) {
builder.append("upload time: ", new StyleSpan(android.graphics.Typeface.BOLD), 0) builder.append("upload time: ", new StyleSpan(android.graphics.Typeface.BOLD), 0)
.append(new Date(crashInfo.uploadTime * 1000).toString()) .append(new Date(crashInfo.uploadTime).toString())
.append("\n"); .append("\n");
} }
if (crashInfo.captureTime >= 0) { if (crashInfo.captureTime >= 0) {
......
...@@ -12,6 +12,7 @@ import java.io.FileReader; ...@@ -12,6 +12,7 @@ import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeUnit;
/** /**
* Parses upload log file in crash directory where crash upload id and time are written. * Parses upload log file in crash directory where crash upload id and time are written.
...@@ -67,7 +68,8 @@ public class UploadedCrashesInfoLoader extends CrashInfoLoader { ...@@ -67,7 +68,8 @@ public class UploadedCrashesInfoLoader extends CrashInfoLoader {
CrashInfo info = new CrashInfo(components[2]); CrashInfo info = new CrashInfo(components[2]);
info.uploadState = CrashInfo.UploadState.UPLOADED; info.uploadState = CrashInfo.UploadState.UPLOADED;
try { try {
info.uploadTime = Long.parseLong(components[0]); // Log file has upload time in sec, convert it back to millisec.
info.uploadTime = TimeUnit.SECONDS.toMillis(Long.parseLong(components[0]));
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
return null; return null;
} }
......
...@@ -39,7 +39,8 @@ public class CrashInfo { ...@@ -39,7 +39,8 @@ public class CrashInfo {
@NonNull @NonNull
public String localId; public String localId;
/** /**
* The time the data was captured. This is useful if the data is stored locally when * The time the data was captured in millisecs since epoch.
* This is useful if the data is stored locally when
* captured and uploaded at a later time. * captured and uploaded at a later time.
*/ */
public long captureTime = -1; public long captureTime = -1;
...@@ -58,7 +59,7 @@ public class CrashInfo { ...@@ -58,7 +59,7 @@ public class CrashInfo {
*/ */
public String uploadId; public String uploadId;
/** /**
* The time when the crash report is uploaded. * The time when the crash report is uploaded in millisecs since epoch.
* Only valid when |uploadState| == Uploaded. * Only valid when |uploadState| == Uploaded.
*/ */
public long uploadTime = -1; public long uploadTime = -1;
......
...@@ -26,6 +26,7 @@ import java.io.FileWriter; ...@@ -26,6 +26,7 @@ import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeUnit;
/** /**
* Unit tests for UploadedCrashesInfoLoader. * Unit tests for UploadedCrashesInfoLoader.
...@@ -33,8 +34,9 @@ import java.util.List; ...@@ -33,8 +34,9 @@ import java.util.List;
@RunWith(AwJUnit4ClassRunner.class) @RunWith(AwJUnit4ClassRunner.class)
@OnlyRunIn(SINGLE_PROCESS) @OnlyRunIn(SINGLE_PROCESS)
public class UploadedCrashesInfoLoaderTest { public class UploadedCrashesInfoLoaderTest {
private static final String TEST_UPLOAD_TIME_STR = "1234567890"; private static final String TEST_UPLOAD_TIME_SEC_STR = "1234567890";
private static final long TEST_UPLOAD_TIME = Long.parseLong(TEST_UPLOAD_TIME_STR); private static final long TEST_UPLOAD_TIME_MILLI =
TimeUnit.SECONDS.toMillis(Long.parseLong(TEST_UPLOAD_TIME_SEC_STR));
private static final String TEST_UPLOAD_ID = "0123456789abcdef"; private static final String TEST_UPLOAD_ID = "0123456789abcdef";
private static final String TEST_LOCAL_ID = "fedcba9876543210"; private static final String TEST_LOCAL_ID = "fedcba9876543210";
...@@ -64,7 +66,7 @@ public class UploadedCrashesInfoLoaderTest { ...@@ -64,7 +66,7 @@ public class UploadedCrashesInfoLoaderTest {
@SmallTest @SmallTest
public void testParseSingleEntry() throws IOException { public void testParseSingleEntry() throws IOException {
List<String> logs = new ArrayList<>(); List<String> logs = new ArrayList<>();
logs.add(TEST_UPLOAD_TIME_STR + "," + TEST_UPLOAD_ID + "," + TEST_LOCAL_ID); logs.add(TEST_UPLOAD_TIME_SEC_STR + "," + TEST_UPLOAD_ID + "," + TEST_LOCAL_ID);
writeUploadLogs(mLogFile, logs); writeUploadLogs(mLogFile, logs);
UploadedCrashesInfoLoader crashesInfoLoader = new UploadedCrashesInfoLoader(mLogFile); UploadedCrashesInfoLoader crashesInfoLoader = new UploadedCrashesInfoLoader(mLogFile);
...@@ -73,7 +75,7 @@ public class UploadedCrashesInfoLoaderTest { ...@@ -73,7 +75,7 @@ public class UploadedCrashesInfoLoaderTest {
Assert.assertEquals(1, infoList.size()); Assert.assertEquals(1, infoList.size());
CrashInfo crashInfo = infoList.get(0); CrashInfo crashInfo = infoList.get(0);
Assert.assertEquals(TEST_UPLOAD_TIME, crashInfo.uploadTime); Assert.assertEquals(TEST_UPLOAD_TIME_MILLI, crashInfo.uploadTime);
Assert.assertEquals(TEST_UPLOAD_ID, crashInfo.uploadId); Assert.assertEquals(TEST_UPLOAD_ID, crashInfo.uploadId);
Assert.assertEquals(TEST_LOCAL_ID, crashInfo.localId); Assert.assertEquals(TEST_LOCAL_ID, crashInfo.localId);
Assert.assertEquals(UploadState.UPLOADED, crashInfo.uploadState); Assert.assertEquals(UploadState.UPLOADED, crashInfo.uploadState);
...@@ -84,7 +86,7 @@ public class UploadedCrashesInfoLoaderTest { ...@@ -84,7 +86,7 @@ public class UploadedCrashesInfoLoaderTest {
public void testParseMultipleEntries() throws IOException { public void testParseMultipleEntries() throws IOException {
List<String> logs = new ArrayList<>(); List<String> logs = new ArrayList<>();
for (int i = 1; i <= 4; ++i) { for (int i = 1; i <= 4; ++i) {
String testEntry = TEST_UPLOAD_TIME_STR + "," String testEntry = TEST_UPLOAD_TIME_SEC_STR + ","
+ "upload" + Integer.toString(i) + "," + "upload" + Integer.toString(i) + ","
+ "local" + Integer.toString(i); + "local" + Integer.toString(i);
logs.add(testEntry); logs.add(testEntry);
...@@ -97,7 +99,7 @@ public class UploadedCrashesInfoLoaderTest { ...@@ -97,7 +99,7 @@ public class UploadedCrashesInfoLoaderTest {
Assert.assertEquals(4, infoList.size()); Assert.assertEquals(4, infoList.size());
for (int i = 1; i <= 4; ++i) { for (int i = 1; i <= 4; ++i) {
CrashInfo crashInfo = infoList.get(i - 1); CrashInfo crashInfo = infoList.get(i - 1);
Assert.assertEquals(TEST_UPLOAD_TIME, crashInfo.uploadTime); Assert.assertEquals(TEST_UPLOAD_TIME_MILLI, crashInfo.uploadTime);
Assert.assertEquals("upload" + Integer.toString(i), crashInfo.uploadId); Assert.assertEquals("upload" + Integer.toString(i), crashInfo.uploadId);
Assert.assertEquals("local" + Integer.toString(i), crashInfo.localId); Assert.assertEquals("local" + Integer.toString(i), crashInfo.localId);
Assert.assertEquals(UploadState.UPLOADED, crashInfo.uploadState); Assert.assertEquals(UploadState.UPLOADED, crashInfo.uploadState);
...@@ -110,7 +112,7 @@ public class UploadedCrashesInfoLoaderTest { ...@@ -110,7 +112,7 @@ public class UploadedCrashesInfoLoaderTest {
List<String> logs = new ArrayList<>(); List<String> logs = new ArrayList<>();
// Valid logs // Valid logs
for (int i = 1; i <= 2; ++i) { for (int i = 1; i <= 2; ++i) {
String testEntry = TEST_UPLOAD_TIME_STR + "," String testEntry = TEST_UPLOAD_TIME_SEC_STR + ","
+ "upload" + Integer.toString(i) + "," + "upload" + Integer.toString(i) + ","
+ "local" + Integer.toString(i); + "local" + Integer.toString(i);
logs.add(testEntry); logs.add(testEntry);
...@@ -131,7 +133,7 @@ public class UploadedCrashesInfoLoaderTest { ...@@ -131,7 +133,7 @@ public class UploadedCrashesInfoLoaderTest {
// too many components // too many components
logs.add("123456789,1a2b3c,4d5e6f,1011121314"); logs.add("123456789,1a2b3c,4d5e6f,1011121314");
for (int i = 3; i <= 4; ++i) { for (int i = 3; i <= 4; ++i) {
String testEntry = TEST_UPLOAD_TIME_STR + "," String testEntry = TEST_UPLOAD_TIME_SEC_STR + ","
+ "upload" + Integer.toString(i) + "," + "upload" + Integer.toString(i) + ","
+ "local" + Integer.toString(i); + "local" + Integer.toString(i);
logs.add(testEntry); logs.add(testEntry);
...@@ -144,7 +146,7 @@ public class UploadedCrashesInfoLoaderTest { ...@@ -144,7 +146,7 @@ public class UploadedCrashesInfoLoaderTest {
Assert.assertEquals(4, infoList.size()); Assert.assertEquals(4, infoList.size());
for (int i = 1; i <= 4; ++i) { for (int i = 1; i <= 4; ++i) {
CrashInfo crashInfo = infoList.get(i - 1); CrashInfo crashInfo = infoList.get(i - 1);
Assert.assertEquals(TEST_UPLOAD_TIME, crashInfo.uploadTime); Assert.assertEquals(TEST_UPLOAD_TIME_MILLI, crashInfo.uploadTime);
Assert.assertEquals("upload" + Integer.toString(i), crashInfo.uploadId); Assert.assertEquals("upload" + Integer.toString(i), crashInfo.uploadId);
Assert.assertEquals("local" + Integer.toString(i), crashInfo.localId); Assert.assertEquals("local" + Integer.toString(i), crashInfo.localId);
Assert.assertEquals(UploadState.UPLOADED, crashInfo.uploadState); Assert.assertEquals(UploadState.UPLOADED, crashInfo.uploadState);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment