Skip to content

Commit 5005ce3

Browse files
save start and end upload time
1 parent f9225cd commit 5005ce3

File tree

4 files changed

+35
-4
lines changed

4 files changed

+35
-4
lines changed

src/android/AckDatabase.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@ public abstract class AckDatabase extends RoomDatabase {
1919
static final Migration MIGRATION_5_6 = new Migration(5, 6) {
2020
@Override
2121
public void migrate(@NonNull SupportSQLiteDatabase database) {
22-
// Add the new column to the existing table
2322
database.execSQL("ALTER TABLE upload_events ADD COLUMN uploadDuration INTEGER NOT NULL DEFAULT 0");
23+
database.execSQL("ALTER TABLE upload_events ADD COLUMN startUploadTime INTEGER NOT NULL DEFAULT 0");
24+
database.execSQL("ALTER TABLE upload_events ADD COLUMN endUploadTime INTEGER NOT NULL DEFAULT 0");
2425
}
2526
};
2627

28+
2729
public static synchronized AckDatabase getInstance(final Context context) {
2830
if (instance == null) {
2931
instance = Room

src/android/FileTransferBackground.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ private void sendProgress(final String id, int progressPercent) {
8181
}
8282
}
8383

84-
private void sendSuccess(final String id, final String response, int statusCode, long uploadDuration) {
84+
private void sendSuccess(final String id, final String response, int statusCode, long uploadDuration, long uploadStartTime, long uploadEndTime) {
8585
if (response != null && !response.isEmpty()) {
8686
logMessage("eventLabel='Uploader onSuccess' uploadId='" + id + "' response='" + response.substring(0, Math.min(2000, response.length() - 1)) + "'");
8787
} else {
@@ -96,6 +96,8 @@ private void sendSuccess(final String id, final String response, int statusCode,
9696
.put("serverResponse", response)
9797
.put("statusCode", statusCode)
9898
.put("uploadDuration", uploadDuration)
99+
.put("uploadStartTime", uploadStartTime)
100+
.put("uploadEndTime", uploadEndTime)
99101
);
100102
} catch (JSONException e) {
101103
// Can't really happen but just in case
@@ -414,7 +416,9 @@ private void handleAck(final Data ackData) {
414416
ackData.getString(UploadTask.KEY_OUTPUT_ID),
415417
response,
416418
ackData.getInt(UploadTask.KEY_OUTPUT_STATUS_CODE, -1 /* If this is sent, something is really wrong */),
417-
ackData.getLong(UploadTask.KEY_OUTPUT_UPLOAD_DURATION, 0)
419+
ackData.getLong(UploadTask.KEY_OUTPUT_UPLOAD_DURATION, 0),
420+
ackData.getLong(UploadTask.KEY_OUTPUT_UPLOAD_START_TIME, 0),
421+
ackData.getLong(UploadTask.KEY_OUTPUT_UPLOAD_END_TIME, 0)
418422
);
419423

420424
} else {

src/android/UploadEvent.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ public class UploadEvent {
1212
@NonNull
1313
private String id;
1414
private long uploadDuration;
15+
private long uploadStartTime;
16+
private long uploadEndTime;
17+
1518

1619
@ColumnInfo(name = "output_data")
1720
@NonNull
@@ -21,6 +24,8 @@ public UploadEvent(@NonNull final String id, @NonNull final Data outputData) {
2124
this.id = id;
2225
this.outputData = outputData;
2326
this.uploadDuration = outputData.getLong(UploadTask.KEY_OUTPUT_UPLOAD_DURATION, 0);
27+
this.uploadStartTime = outputData.getLong(UploadTask.KEY_OUTPUT_UPLOAD_START_TIME, 0);
28+
this.uploadEndTime = outputData.getLong(UploadTask.KEY_OUTPUT_UPLOAD_END_TIME, 0);
2429
}
2530

2631
@NonNull
@@ -40,4 +45,20 @@ public long getUploadDuration() {
4045
public void setUploadDuration(long uploadDuration) {
4146
this.uploadDuration = uploadDuration;
4247
}
48+
49+
public long getUploadStartTime() {
50+
return uploadStartTime;
51+
}
52+
53+
public void setUploadStartTime(long uploadStartTime) {
54+
this.uploadStartTime = uploadStartTime;
55+
}
56+
57+
public long getUploadEndTime() {
58+
return uploadEndTime;
59+
}
60+
61+
public void setUploadEndTime(long uploadEndTime) {
62+
this.uploadEndTime = uploadEndTime;
63+
}
4364
}

src/android/UploadTask.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ public final class UploadTask extends Worker {
8080
public static final String KEY_OUTPUT_FAILURE_REASON = "output_failure_reason";
8181
public static final String KEY_OUTPUT_FAILURE_CANCELED = "output_failure_canceled";
8282
public static final String KEY_OUTPUT_UPLOAD_DURATION = "output_upload_duration";
83+
public static final String KEY_OUTPUT_UPLOAD_START_TIME = "output_upload_start_time";
84+
public static final String KEY_OUTPUT_UPLOAD_END_TIME = "output_upload_end_time";
8385

8486
// </editor-fold>
8587

@@ -264,7 +266,9 @@ public Result doWork() {
264266
.putString(KEY_OUTPUT_ID, id)
265267
.putBoolean(KEY_OUTPUT_IS_ERROR, false)
266268
.putInt(KEY_OUTPUT_STATUS_CODE, (!DEBUG_SKIP_UPLOAD) ? response.code() : 200)
267-
.putLong(KEY_OUTPUT_UPLOAD_DURATION, uploadDuration);
269+
.putLong(KEY_OUTPUT_UPLOAD_DURATION, uploadDuration)
270+
.putLong(KEY_OUTPUT_UPLOAD_START_TIME, startUploadTime)
271+
.putLong(KEY_OUTPUT_UPLOAD_END_TIME, endUploadTime);
268272

269273
// Try read the response body, if any
270274
try {

0 commit comments

Comments
 (0)