Skip to content

Commit

Permalink
save start and end upload time
Browse files Browse the repository at this point in the history
  • Loading branch information
parveshneedhoo committed Aug 21, 2024
1 parent f9225cd commit 5005ce3
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/android/AckDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ public abstract class AckDatabase extends RoomDatabase {
static final Migration MIGRATION_5_6 = new Migration(5, 6) {
@Override
public void migrate(@NonNull SupportSQLiteDatabase database) {
// Add the new column to the existing table
database.execSQL("ALTER TABLE upload_events ADD COLUMN uploadDuration INTEGER NOT NULL DEFAULT 0");
database.execSQL("ALTER TABLE upload_events ADD COLUMN startUploadTime INTEGER NOT NULL DEFAULT 0");
database.execSQL("ALTER TABLE upload_events ADD COLUMN endUploadTime INTEGER NOT NULL DEFAULT 0");
}
};


public static synchronized AckDatabase getInstance(final Context context) {
if (instance == null) {
instance = Room
Expand Down
8 changes: 6 additions & 2 deletions src/android/FileTransferBackground.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ private void sendProgress(final String id, int progressPercent) {
}
}

private void sendSuccess(final String id, final String response, int statusCode, long uploadDuration) {
private void sendSuccess(final String id, final String response, int statusCode, long uploadDuration, long uploadStartTime, long uploadEndTime) {
if (response != null && !response.isEmpty()) {
logMessage("eventLabel='Uploader onSuccess' uploadId='" + id + "' response='" + response.substring(0, Math.min(2000, response.length() - 1)) + "'");
} else {
Expand All @@ -96,6 +96,8 @@ private void sendSuccess(final String id, final String response, int statusCode,
.put("serverResponse", response)
.put("statusCode", statusCode)
.put("uploadDuration", uploadDuration)
.put("uploadStartTime", uploadStartTime)
.put("uploadEndTime", uploadEndTime)
);
} catch (JSONException e) {
// Can't really happen but just in case
Expand Down Expand Up @@ -414,7 +416,9 @@ private void handleAck(final Data ackData) {
ackData.getString(UploadTask.KEY_OUTPUT_ID),
response,
ackData.getInt(UploadTask.KEY_OUTPUT_STATUS_CODE, -1 /* If this is sent, something is really wrong */),
ackData.getLong(UploadTask.KEY_OUTPUT_UPLOAD_DURATION, 0)
ackData.getLong(UploadTask.KEY_OUTPUT_UPLOAD_DURATION, 0),
ackData.getLong(UploadTask.KEY_OUTPUT_UPLOAD_START_TIME, 0),
ackData.getLong(UploadTask.KEY_OUTPUT_UPLOAD_END_TIME, 0)
);

} else {
Expand Down
21 changes: 21 additions & 0 deletions src/android/UploadEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ public class UploadEvent {
@NonNull
private String id;
private long uploadDuration;
private long uploadStartTime;
private long uploadEndTime;


@ColumnInfo(name = "output_data")
@NonNull
Expand All @@ -21,6 +24,8 @@ public UploadEvent(@NonNull final String id, @NonNull final Data outputData) {
this.id = id;
this.outputData = outputData;
this.uploadDuration = outputData.getLong(UploadTask.KEY_OUTPUT_UPLOAD_DURATION, 0);
this.uploadStartTime = outputData.getLong(UploadTask.KEY_OUTPUT_UPLOAD_START_TIME, 0);
this.uploadEndTime = outputData.getLong(UploadTask.KEY_OUTPUT_UPLOAD_END_TIME, 0);
}

@NonNull
Expand All @@ -40,4 +45,20 @@ public long getUploadDuration() {
public void setUploadDuration(long uploadDuration) {
this.uploadDuration = uploadDuration;
}

public long getUploadStartTime() {
return uploadStartTime;
}

public void setUploadStartTime(long uploadStartTime) {
this.uploadStartTime = uploadStartTime;
}

public long getUploadEndTime() {
return uploadEndTime;
}

public void setUploadEndTime(long uploadEndTime) {
this.uploadEndTime = uploadEndTime;
}
}
6 changes: 5 additions & 1 deletion src/android/UploadTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ public final class UploadTask extends Worker {
public static final String KEY_OUTPUT_FAILURE_REASON = "output_failure_reason";
public static final String KEY_OUTPUT_FAILURE_CANCELED = "output_failure_canceled";
public static final String KEY_OUTPUT_UPLOAD_DURATION = "output_upload_duration";
public static final String KEY_OUTPUT_UPLOAD_START_TIME = "output_upload_start_time";
public static final String KEY_OUTPUT_UPLOAD_END_TIME = "output_upload_end_time";

// </editor-fold>

Expand Down Expand Up @@ -264,7 +266,9 @@ public Result doWork() {
.putString(KEY_OUTPUT_ID, id)
.putBoolean(KEY_OUTPUT_IS_ERROR, false)
.putInt(KEY_OUTPUT_STATUS_CODE, (!DEBUG_SKIP_UPLOAD) ? response.code() : 200)
.putLong(KEY_OUTPUT_UPLOAD_DURATION, uploadDuration);
.putLong(KEY_OUTPUT_UPLOAD_DURATION, uploadDuration)
.putLong(KEY_OUTPUT_UPLOAD_START_TIME, startUploadTime)
.putLong(KEY_OUTPUT_UPLOAD_END_TIME, endUploadTime);

// Try read the response body, if any
try {
Expand Down

0 comments on commit 5005ce3

Please sign in to comment.