From ae1617051451628d99d988dacc90b1ad1ae6480e Mon Sep 17 00:00:00 2001 From: parveshneedhoo Date: Thu, 22 Aug 2024 10:56:45 +0400 Subject: [PATCH] refactor android side plugin --- src/android/AckDatabase.java | 2 +- src/android/FileTransferBackground.java | 6 +++--- src/android/UploadEvent.java | 20 ++++++++++---------- src/android/UploadTask.java | 8 ++++---- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/android/AckDatabase.java b/src/android/AckDatabase.java index 1b4c116e..b6173f3d 100644 --- a/src/android/AckDatabase.java +++ b/src/android/AckDatabase.java @@ -21,7 +21,7 @@ public abstract class AckDatabase extends RoomDatabase { public void migrate(@NonNull SupportSQLiteDatabase database) { 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"); + database.execSQL("ALTER TABLE upload_events ADD COLUMN finishUploadTime INTEGER NOT NULL DEFAULT 0"); } }; diff --git a/src/android/FileTransferBackground.java b/src/android/FileTransferBackground.java index caf4c038..ed8d62f1 100644 --- a/src/android/FileTransferBackground.java +++ b/src/android/FileTransferBackground.java @@ -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, long uploadStartTime, long uploadEndTime) { + private void sendSuccess(final String id, final String response, int statusCode, long uploadDuration, long startUploadTime, long finishUploadTime) { if (response != null && !response.isEmpty()) { logMessage("eventLabel='Uploader onSuccess' uploadId='" + id + "' response='" + response.substring(0, Math.min(2000, response.length() - 1)) + "'"); } else { @@ -96,8 +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) + .put("startUploadTime", startUploadTime) + .put("finishUploadTime", finishUploadTime) ); } catch (JSONException e) { // Can't really happen but just in case diff --git a/src/android/UploadEvent.java b/src/android/UploadEvent.java index d02b70ca..5a23b72f 100644 --- a/src/android/UploadEvent.java +++ b/src/android/UploadEvent.java @@ -24,8 +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); + this.startUploadTime = outputData.getLong(UploadTask.KEY_OUTPUT_UPLOAD_START_TIME, 0); + this.finishUploadTime = outputData.getLong(UploadTask.KEY_OUTPUT_UPLOAD_END_TIME, 0); } @NonNull @@ -46,19 +46,19 @@ public void setUploadDuration(long uploadDuration) { this.uploadDuration = uploadDuration; } - public long getUploadStartTime() { - return uploadStartTime; + public long getStartUploadTime() { + return startUploadTime; } - public void setUploadStartTime(long uploadStartTime) { - this.uploadStartTime = uploadStartTime; + public void setStartUploadTime(long startUploadTime) { + this.startUploadTime = startUploadTime; } - public long getUploadEndTime() { - return uploadEndTime; + public long getFinishUploadTime() { + return finishUploadTime; } - public void setUploadEndTime(long uploadEndTime) { - this.uploadEndTime = uploadEndTime; + public void setFinishUploadTime(long finishUploadTime) { + this.finishUploadTime = finishUploadTime; } } diff --git a/src/android/UploadTask.java b/src/android/UploadTask.java index 652001d7..3bda10b8 100644 --- a/src/android/UploadTask.java +++ b/src/android/UploadTask.java @@ -101,7 +101,7 @@ public void release() { } private static Semaphore concurrentUploads = new Semaphore(concurrency, true); private static Mutex concurrencyLock = new Mutex(); private long startUploadTime; - private long endUploadTime; + private long finishUploadTime; private long uploadDuration; public UploadTask(@NonNull Context context, @NonNull WorkerParameters workerParams) { @@ -255,8 +255,8 @@ public Result doWork() { return Result.retry(); } } finally { - endUploadTime = System.currentTimeMillis(); - uploadDuration = endUploadTime - startUploadTime; + finishUploadTime = System.currentTimeMillis(); + uploadDuration = finishUploadTime - startUploadTime; // Always remove ourselves from the notification uploadForegroundNotification.done(getId()); } @@ -268,7 +268,7 @@ public Result doWork() { .putInt(KEY_OUTPUT_STATUS_CODE, (!DEBUG_SKIP_UPLOAD) ? response.code() : 200) .putLong(KEY_OUTPUT_UPLOAD_DURATION, uploadDuration) .putLong(KEY_OUTPUT_UPLOAD_START_TIME, startUploadTime) - .putLong(KEY_OUTPUT_UPLOAD_END_TIME, endUploadTime); + .putLong(KEY_OUTPUT_UPLOAD_END_TIME, finishUploadTime); // Try read the response body, if any try {