From ea35dc49238015d224b964db8cc60ee39c12e066 Mon Sep 17 00:00:00 2001 From: parveshneedhoo Date: Thu, 22 Aug 2024 17:43:24 +0400 Subject: [PATCH 01/15] android upload duration logic --- src/android/AckDatabase.java | 17 +++++++++++++++-- src/android/FileTransferBackground.java | 15 ++++++++++----- src/android/UploadEvent.java | 24 +++++++++++++++++++++++- src/android/UploadTask.java | 8 ++++++-- 4 files changed, 54 insertions(+), 10 deletions(-) diff --git a/src/android/AckDatabase.java b/src/android/AckDatabase.java index ac4cc3ed..6403cbf3 100644 --- a/src/android/AckDatabase.java +++ b/src/android/AckDatabase.java @@ -2,22 +2,35 @@ import android.content.Context; +import androidx.annotation.NonNull; import androidx.room.Database; import androidx.room.Room; import androidx.room.RoomDatabase; import androidx.room.TypeConverters; +import androidx.room.migration.Migration; +import androidx.sqlite.db.SupportSQLiteDatabase; import androidx.work.Data; -@Database(entities = {UploadEvent.class}, version = 5) +@Database(entities = {UploadEvent.class}, version = 6) @TypeConverters(value = {Data.class}) public abstract class AckDatabase extends RoomDatabase { private static AckDatabase instance; - public static AckDatabase getInstance(final Context context) { + static final Migration MIGRATION_5_6 = new Migration(5, 6) { + @Override + public void migrate(@NonNull SupportSQLiteDatabase database) { + database.execSQL("ALTER TABLE upload_events ADD COLUMN start_upload_time INTEGER NOT NULL DEFAULT 0"); + database.execSQL("ALTER TABLE upload_events ADD COLUMN finish_upload_time INTEGER NOT NULL DEFAULT 0"); + } + }; + + + public static synchronized AckDatabase getInstance(final Context context) { if (instance == null) { instance = Room .databaseBuilder(context, AckDatabase.class, "cordova-plugin-background-upload.db") .fallbackToDestructiveMigration() + .addMigrations(MIGRATION_5_6) .build(); } return instance; diff --git a/src/android/FileTransferBackground.java b/src/android/FileTransferBackground.java index 8cb6c393..37cde16d 100644 --- a/src/android/FileTransferBackground.java +++ b/src/android/FileTransferBackground.java @@ -32,6 +32,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.Date; import java.util.HashMap; import java.util.Iterator; import java.util.List; @@ -81,7 +82,7 @@ private void sendProgress(final String id, int progressPercent) { } } - private void sendSuccess(final String id, final String response, int statusCode) { + private void sendSuccess(final String id, final String response, int statusCode, long uploadDuration, long finishUploadTime) { if (response != null && !response.isEmpty()) { logMessage("eventLabel='Uploader onSuccess' uploadId='" + id + "' response='" + response.substring(0, Math.min(2000, response.length() - 1)) + "'"); } else { @@ -95,6 +96,8 @@ private void sendSuccess(final String id, final String response, int statusCode) .put("state", "UPLOADED") .put("serverResponse", response) .put("statusCode", statusCode) + .put("uploadDuration", uploadDuration) + .put("finishUploadTime", finishUploadTime) ); } catch (JSONException e) { // Can't really happen but just in case @@ -193,7 +196,7 @@ private void initManager(String options, final CallbackContext callbackContext) int ackDelay = 0; for (UploadEvent ack : uploadEvents) { executorService.schedule(() -> { - handleAck(ack.getOutputData()); + handleAck(ack.getOutputData(), ack.calculateUploadDuration(), ack.getFinishUploadTime()); }, ackDelay, TimeUnit.MILLISECONDS); ackDelay += 200; } @@ -227,7 +230,7 @@ private void initManager(String options, final CallbackContext callbackContext) // The corresponding ACK is already in the DB, if it not, the task is just a leftover String id = info.getOutputData().getString(UploadTask.KEY_OUTPUT_ID); if (ackDatabase.uploadEventDao().exists(id)) { - handleAck(info.getOutputData()); + handleAck(info.getOutputData(), ackDatabase.uploadEventDao().getById(id).calculateUploadDuration(), ackDatabase.uploadEventDao().getById(id).getFinishUploadTime()); } }, 0, TimeUnit.MILLISECONDS); break; @@ -400,7 +403,7 @@ private void acknowledgeEvent(String eventId, CallbackContext context) { /** * Handle ACK data and send it to the JS. */ - private void handleAck(final Data ackData) { + private void handleAck(final Data ackData, final long uploadDuration, final long finishUploadTime) { // If upload was successful if (!ackData.getBoolean(UploadTask.KEY_OUTPUT_IS_ERROR, false)) { // Read response from file if present @@ -412,7 +415,9 @@ private void handleAck(final Data ackData) { sendSuccess( ackData.getString(UploadTask.KEY_OUTPUT_ID), response, - ackData.getInt(UploadTask.KEY_OUTPUT_STATUS_CODE, -1 /* If this is sent, something is really wrong */) + ackData.getInt(UploadTask.KEY_OUTPUT_STATUS_CODE, -1 /* If this is sent, something is really wrong */), + uploadDuration, + finishUploadTime ); } else { diff --git a/src/android/UploadEvent.java b/src/android/UploadEvent.java index 33cf12f7..691d8995 100644 --- a/src/android/UploadEvent.java +++ b/src/android/UploadEvent.java @@ -16,9 +16,19 @@ public class UploadEvent { @NonNull private Data outputData; - public UploadEvent(@NonNull final String id, @NonNull final Data outputData) { + @ColumnInfo(name = "start_upload_time") + @NonNull + private long startUploadTime; + + @ColumnInfo(name = "finish_upload_time") + @NonNull + private long finishUploadTime; + + public UploadEvent(@NonNull final String id, @NonNull final Data outputData, @NonNull final long startUploadTime, @NonNull final long finishUploadTime) { this.id = id; this.outputData = outputData; + this.startUploadTime = startUploadTime; + this.finishUploadTime = finishUploadTime; } @NonNull @@ -30,4 +40,16 @@ public String getId() { public Data getOutputData() { return outputData; } + + public long getStartUploadTime() { + return startUploadTime; + } + + public long getFinishUploadTime() { + return finishUploadTime; + } + + public long calculateUploadDuration() { + return finishUploadTime - startUploadTime; + } } diff --git a/src/android/UploadTask.java b/src/android/UploadTask.java index 919f6e9f..08c3368c 100644 --- a/src/android/UploadTask.java +++ b/src/android/UploadTask.java @@ -96,6 +96,8 @@ public void release() { } private static int concurrency = 1; private static Semaphore concurrentUploads = new Semaphore(concurrency, true); private static Mutex concurrencyLock = new Mutex(); + long startTime = 0; + long endTime = 0; public UploadTask(@NonNull Context context, @NonNull WorkerParameters workerParams) { @@ -189,6 +191,7 @@ public Result doWork() { return Result.retry(); } + startTime = System.currentTimeMillis(); // Register me uploadForegroundNotification.progress(getId(), 0f); handleNotification(); @@ -237,7 +240,7 @@ public Result doWork() { .putString(KEY_OUTPUT_FAILURE_REASON, "User cancelled") .putBoolean(KEY_OUTPUT_FAILURE_CANCELED, true) .build(); - AckDatabase.getInstance(getApplicationContext()).uploadEventDao().insert(new UploadEvent(id, data)); + AckDatabase.getInstance(getApplicationContext()).uploadEventDao().insert(new UploadEvent(id, data, startTime, endTime)); return Result.success(data); } else { // But if it was not it must be a connectivity problem or @@ -246,6 +249,7 @@ public Result doWork() { return Result.retry(); } } finally { + endTime = System.currentTimeMillis(); // Always remove ourselves from the notification uploadForegroundNotification.done(getId()); } @@ -281,7 +285,7 @@ public Result doWork() { } final Data data = outputData.build(); - AckDatabase.getInstance(getApplicationContext()).uploadEventDao().insert(new UploadEvent(id, data)); + AckDatabase.getInstance(getApplicationContext()).uploadEventDao().insert(new UploadEvent(id, data, startTime, endTime)); return Result.success(data); } From 9ac5df9e3a72d885779a3fd11caf61dd8a18da30 Mon Sep 17 00:00:00 2001 From: parveshneedhoo Date: Tue, 27 Aug 2024 10:12:15 +0400 Subject: [PATCH 02/15] upload duration logic for ios --- src/ios/FileUploader.h | 1 + src/ios/FileUploader.m | 40 +++++++++++++++++++++++++++++++--------- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/src/ios/FileUploader.h b/src/ios/FileUploader.h index aa17e3b0..139e321c 100644 --- a/src/ios/FileUploader.h +++ b/src/ios/FileUploader.h @@ -1,6 +1,7 @@ #import #import "UploadEvent.h" #import +#import NS_ASSUME_NONNULL_BEGIN @protocol FileUploaderDelegate @optional diff --git a/src/ios/FileUploader.m b/src/ios/FileUploader.m index 6471a3c4..e8a6c706 100644 --- a/src/ios/FileUploader.m +++ b/src/ios/FileUploader.m @@ -1,6 +1,7 @@ #import "FileUploader.h" @interface FileUploader() -@property (nonatomic, strong) NSMutableDictionary* responsesData; +@property (nonatomic, strong) NSMutableDictionary *uploadStartTimes; +@property (nonatomic, strong) NSMutableDictionary *responsesData; @property (nonatomic, strong) AFURLSessionManager *manager; @end @@ -20,6 +21,7 @@ -(id)init{ return nil; [UploadEvent setupStorage]; self.responsesData = [[NSMutableDictionary alloc] init]; + self.uploadStartTimes = [[NSMutableDictionary alloc] init]; NSURLSessionConfiguration* configuration = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:[[NSBundle mainBundle] bundleIdentifier]]; configuration.HTTPMaximumConnectionsPerHost = FileUploader.parallelUploadsLimit; configuration.sessionSendsLaunchEvents = NO; @@ -27,23 +29,40 @@ -(id)init{ __weak FileUploader *weakSelf = self; [self.manager setTaskDidCompleteBlock:^(NSURLSession * _Nonnull session, NSURLSessionTask * _Nonnull task, NSError * _Nullable error) { NSString* uploadId = [NSURLProtocol propertyForKey:kUploadUUIDStrPropertyKey inRequest:task.originalRequest]; + NSDate *startTime = weakSelf.uploadStartTimes[uploadId]; + NSDate *endUploadTime = [NSDate date]; + NSTimeInterval timeInterval = [endUploadTime timeIntervalSince1970]; + long long uploadTimeinMS = (long long)(timeInterval * 1000); + NSTimeInterval duration = [endUploadTime timeIntervalSinceDate:startTime]; NSLog(@"[BackgroundUpload] Task %@ completed with error %@", uploadId, error); if (!error){ NSData* serverData = weakSelf.responsesData[@(task.taskIdentifier)]; NSString* serverResponse = serverData ? [[NSString alloc] initWithData:serverData encoding:NSUTF8StringEncoding] : @""; [weakSelf.responsesData removeObjectForKey:@(task.taskIdentifier)]; - [weakSelf saveAndSendEvent:@{ - @"id" : uploadId, - @"state" : @"UPLOADED", - @"statusCode" : @(((NSHTTPURLResponse *)task.response).statusCode), - @"serverResponse" : serverResponse - }]; + if (!isnan(duration)) { + [weakSelf saveAndSendEvent:@{ + @"id" : uploadId, + @"state" : @"UPLOADED", + @"statusCode" : @(((NSHTTPURLResponse *)task.response).statusCode), + @"serverResponse" : serverResponse, + @"uploadDuration" : @(duration * 1000), + @"finishUploadTime": @(uploadTimeinMS) + }]; + } else { + [weakSelf saveAndSendEvent:@{ + @"id" : uploadId, + @"state" : @"UPLOADED", + @"statusCode" : @(((NSHTTPURLResponse *)task.response).statusCode), + @"serverResponse" : serverResponse, + }]; + } } else { + [weakSelf.responsesData removeObjectForKey:@(task.taskIdentifier)]; [weakSelf saveAndSendEvent:@{ @"id" : uploadId, @"state" : @"FAILED", @"error" : error.localizedDescription, - @"errorCode" : @(error.code) + @"errorCode" : @(error.code), }]; } }]; @@ -60,7 +79,7 @@ -(id)init{ } -(void)saveAndSendEvent:(NSDictionary*)data{ - UploadEvent*event = [UploadEvent create:data]; + UploadEvent* event = [UploadEvent create:data]; [self sendEvent:[event dataRepresentation]]; } @@ -89,6 +108,9 @@ -(void)addUpload:(NSDictionary *)payload completionHandler:(void (^)(NSError* er completionHandler:^(NSError *error, NSMutableURLRequest *request) { if (error) return handler(error); + + weakSelf.uploadStartTimes[payload[@"id"]] = [NSDate date]; + __block double lastProgressTimeStamp = 0; [[weakSelf.manager uploadTaskWithRequest:request From 6c71c7edec6a03d98a8e712ff97dc5355cfa6595 Mon Sep 17 00:00:00 2001 From: parveshneedhoo Date: Mon, 2 Sep 2024 17:58:53 +0400 Subject: [PATCH 03/15] refactor --- src/android/AckDatabase.java | 19 +++------------ src/android/FileTransferBackground.java | 32 +++++++++++++++++-------- src/android/UploadEvent.java | 24 +------------------ src/android/UploadTask.java | 12 +++++++--- 4 files changed, 35 insertions(+), 52 deletions(-) diff --git a/src/android/AckDatabase.java b/src/android/AckDatabase.java index 6403cbf3..24e5def6 100644 --- a/src/android/AckDatabase.java +++ b/src/android/AckDatabase.java @@ -2,35 +2,22 @@ import android.content.Context; -import androidx.annotation.NonNull; import androidx.room.Database; import androidx.room.Room; import androidx.room.RoomDatabase; import androidx.room.TypeConverters; -import androidx.room.migration.Migration; -import androidx.sqlite.db.SupportSQLiteDatabase; import androidx.work.Data; -@Database(entities = {UploadEvent.class}, version = 6) +@Database(entities = {UploadEvent.class}, version = 5) @TypeConverters(value = {Data.class}) public abstract class AckDatabase extends RoomDatabase { private static AckDatabase instance; - static final Migration MIGRATION_5_6 = new Migration(5, 6) { - @Override - public void migrate(@NonNull SupportSQLiteDatabase database) { - database.execSQL("ALTER TABLE upload_events ADD COLUMN start_upload_time INTEGER NOT NULL DEFAULT 0"); - database.execSQL("ALTER TABLE upload_events ADD COLUMN finish_upload_time INTEGER NOT NULL DEFAULT 0"); - } - }; - - - public static synchronized AckDatabase getInstance(final Context context) { + public static AckDatabase getInstance(final Context context) { if (instance == null) { instance = Room .databaseBuilder(context, AckDatabase.class, "cordova-plugin-background-upload.db") .fallbackToDestructiveMigration() - .addMigrations(MIGRATION_5_6) .build(); } return instance; @@ -43,4 +30,4 @@ public static void closeInstance() { } public abstract UploadEventDao uploadEventDao(); -} +} \ No newline at end of file diff --git a/src/android/FileTransferBackground.java b/src/android/FileTransferBackground.java index 37cde16d..434148e0 100644 --- a/src/android/FileTransferBackground.java +++ b/src/android/FileTransferBackground.java @@ -82,7 +82,13 @@ private void sendProgress(final String id, int progressPercent) { } } - private void sendSuccess(final String id, final String response, int statusCode, long uploadDuration, long finishUploadTime) { + private void sendSuccess(HashMap uploadData) { + String id = (String) uploadData.get("outputId"); + String response = (String) uploadData.get("response"); + int statusCode = (int) uploadData.get("statusCode"); + long uploadDuration = (long) uploadData.get("uploadDuration"); + long finishUploadTime = (long) uploadData.get("finishUploadTime"); + if (response != null && !response.isEmpty()) { logMessage("eventLabel='Uploader onSuccess' uploadId='" + id + "' response='" + response.substring(0, Math.min(2000, response.length() - 1)) + "'"); } else { @@ -195,8 +201,11 @@ private void initManager(String options, final CallbackContext callbackContext) int ackDelay = 0; for (UploadEvent ack : uploadEvents) { + long startUploadTime = ack.getOutputData().getLong("output_upload_start_time", 0); + long endUploadTime = ack.getOutputData().getLong("output_upload_end_time", 0); + long uploadDuration = endUploadTime - startUploadTime; executorService.schedule(() -> { - handleAck(ack.getOutputData(), ack.calculateUploadDuration(), ack.getFinishUploadTime()); + handleAck(ack.getOutputData(), uploadDuration, endUploadTime); }, ackDelay, TimeUnit.MILLISECONDS); ackDelay += 200; } @@ -230,7 +239,10 @@ private void initManager(String options, final CallbackContext callbackContext) // The corresponding ACK is already in the DB, if it not, the task is just a leftover String id = info.getOutputData().getString(UploadTask.KEY_OUTPUT_ID); if (ackDatabase.uploadEventDao().exists(id)) { - handleAck(info.getOutputData(), ackDatabase.uploadEventDao().getById(id).calculateUploadDuration(), ackDatabase.uploadEventDao().getById(id).getFinishUploadTime()); + long startUploadTime = info.getOutputData().getLong("output_upload_start_time", 0); + long endUploadTime = info.getOutputData().getLong("output_upload_end_time", 0); + long uploadDuration = endUploadTime - startUploadTime; + handleAck(info.getOutputData(), uploadDuration, endUploadTime); } }, 0, TimeUnit.MILLISECONDS); break; @@ -412,14 +424,14 @@ private void handleAck(final Data ackData, final long uploadDuration, final long response = readFileToStringNoThrow(ackData.getString(UploadTask.KEY_OUTPUT_RESPONSE_FILE)); } - sendSuccess( - ackData.getString(UploadTask.KEY_OUTPUT_ID), - response, - ackData.getInt(UploadTask.KEY_OUTPUT_STATUS_CODE, -1 /* If this is sent, something is really wrong */), - uploadDuration, - finishUploadTime - ); + HashMap uploadData = new HashMap<>(); + uploadData.put("outputId", ackData.getString(UploadTask.KEY_OUTPUT_ID)); + uploadData.put("response", response); + uploadData.put("statusCode", ackData.getInt(UploadTask.KEY_OUTPUT_STATUS_CODE, -1)); + uploadData.put("uploadDuration", uploadDuration); + uploadData.put("finishUploadTime", finishUploadTime); + sendSuccess(uploadData); } else { // The upload was a failure sendError( diff --git a/src/android/UploadEvent.java b/src/android/UploadEvent.java index 691d8995..f5047681 100644 --- a/src/android/UploadEvent.java +++ b/src/android/UploadEvent.java @@ -16,19 +16,9 @@ public class UploadEvent { @NonNull private Data outputData; - @ColumnInfo(name = "start_upload_time") - @NonNull - private long startUploadTime; - - @ColumnInfo(name = "finish_upload_time") - @NonNull - private long finishUploadTime; - - public UploadEvent(@NonNull final String id, @NonNull final Data outputData, @NonNull final long startUploadTime, @NonNull final long finishUploadTime) { + public UploadEvent(@NonNull final String id, @NonNull final Data outputData ) { this.id = id; this.outputData = outputData; - this.startUploadTime = startUploadTime; - this.finishUploadTime = finishUploadTime; } @NonNull @@ -40,16 +30,4 @@ public String getId() { public Data getOutputData() { return outputData; } - - public long getStartUploadTime() { - return startUploadTime; - } - - public long getFinishUploadTime() { - return finishUploadTime; - } - - public long calculateUploadDuration() { - return finishUploadTime - startUploadTime; - } } diff --git a/src/android/UploadTask.java b/src/android/UploadTask.java index 08c3368c..2424ff7f 100644 --- a/src/android/UploadTask.java +++ b/src/android/UploadTask.java @@ -79,6 +79,8 @@ public final class UploadTask extends Worker { public static final String KEY_OUTPUT_STATUS_CODE = "output_status_code"; 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_START_TIME = "output_upload_start_time"; + public static final String KEY_OUTPUT_UPLOAD_END_TIME = "output_upload_end_time"; // private static UploadNotification uploadNotification = null; @@ -239,8 +241,10 @@ public Result doWork() { .putBoolean(KEY_OUTPUT_IS_ERROR, true) .putString(KEY_OUTPUT_FAILURE_REASON, "User cancelled") .putBoolean(KEY_OUTPUT_FAILURE_CANCELED, true) + .putLong(KEY_OUTPUT_UPLOAD_START_TIME, startTime) + .putLong(KEY_OUTPUT_UPLOAD_END_TIME, endTime) .build(); - AckDatabase.getInstance(getApplicationContext()).uploadEventDao().insert(new UploadEvent(id, data, startTime, endTime)); + AckDatabase.getInstance(getApplicationContext()).uploadEventDao().insert(new UploadEvent(id, data)); return Result.success(data); } else { // But if it was not it must be a connectivity problem or @@ -258,7 +262,9 @@ public Result doWork() { final Data.Builder outputData = new Data.Builder() .putString(KEY_OUTPUT_ID, id) .putBoolean(KEY_OUTPUT_IS_ERROR, false) - .putInt(KEY_OUTPUT_STATUS_CODE, (!DEBUG_SKIP_UPLOAD) ? response.code() : 200); + .putInt(KEY_OUTPUT_STATUS_CODE, (!DEBUG_SKIP_UPLOAD) ? response.code() : 200) + .putLong(KEY_OUTPUT_UPLOAD_START_TIME, startTime) + .putLong(KEY_OUTPUT_UPLOAD_END_TIME, endTime); // Try read the response body, if any try { @@ -285,7 +291,7 @@ public Result doWork() { } final Data data = outputData.build(); - AckDatabase.getInstance(getApplicationContext()).uploadEventDao().insert(new UploadEvent(id, data, startTime, endTime)); + AckDatabase.getInstance(getApplicationContext()).uploadEventDao().insert(new UploadEvent(id, data)); return Result.success(data); } From c8cb416c4178f343ee430fbcda21eece4a0933f8 Mon Sep 17 00:00:00 2001 From: parveshneedhoo Date: Mon, 2 Sep 2024 17:59:46 +0400 Subject: [PATCH 04/15] nl --- src/android/AckDatabase.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/android/AckDatabase.java b/src/android/AckDatabase.java index 24e5def6..ac4cc3ed 100644 --- a/src/android/AckDatabase.java +++ b/src/android/AckDatabase.java @@ -30,4 +30,4 @@ public static void closeInstance() { } public abstract UploadEventDao uploadEventDao(); -} \ No newline at end of file +} From 50e40f8dac9c69d223fdd3020abdcef934c3de38 Mon Sep 17 00:00:00 2001 From: parveshneedhoo Date: Tue, 10 Sep 2024 10:38:14 +0400 Subject: [PATCH 05/15] refactor android upload duration logic --- src/android/FileTransferBackground.java | 32 ++++++++++++++----------- src/android/UploadEvent.java | 2 +- src/android/UploadTask.java | 6 ++--- 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/android/FileTransferBackground.java b/src/android/FileTransferBackground.java index 434148e0..476e20bf 100644 --- a/src/android/FileTransferBackground.java +++ b/src/android/FileTransferBackground.java @@ -201,11 +201,8 @@ private void initManager(String options, final CallbackContext callbackContext) int ackDelay = 0; for (UploadEvent ack : uploadEvents) { - long startUploadTime = ack.getOutputData().getLong("output_upload_start_time", 0); - long endUploadTime = ack.getOutputData().getLong("output_upload_end_time", 0); - long uploadDuration = endUploadTime - startUploadTime; executorService.schedule(() -> { - handleAck(ack.getOutputData(), uploadDuration, endUploadTime); + handleAck(ack.getOutputData()); }, ackDelay, TimeUnit.MILLISECONDS); ackDelay += 200; } @@ -239,10 +236,7 @@ private void initManager(String options, final CallbackContext callbackContext) // The corresponding ACK is already in the DB, if it not, the task is just a leftover String id = info.getOutputData().getString(UploadTask.KEY_OUTPUT_ID); if (ackDatabase.uploadEventDao().exists(id)) { - long startUploadTime = info.getOutputData().getLong("output_upload_start_time", 0); - long endUploadTime = info.getOutputData().getLong("output_upload_end_time", 0); - long uploadDuration = endUploadTime - startUploadTime; - handleAck(info.getOutputData(), uploadDuration, endUploadTime); + handleAck(info.getOutputData()); } }, 0, TimeUnit.MILLISECONDS); break; @@ -415,7 +409,7 @@ private void acknowledgeEvent(String eventId, CallbackContext context) { /** * Handle ACK data and send it to the JS. */ - private void handleAck(final Data ackData, final long uploadDuration, final long finishUploadTime) { + private void handleAck(final Data ackData) { // If upload was successful if (!ackData.getBoolean(UploadTask.KEY_OUTPUT_IS_ERROR, false)) { // Read response from file if present @@ -424,12 +418,22 @@ private void handleAck(final Data ackData, final long uploadDuration, final long response = readFileToStringNoThrow(ackData.getString(UploadTask.KEY_OUTPUT_RESPONSE_FILE)); } + long startUploadTime = ackData.getLong("output_upload_start_time", 0); + long finishUploadTime = ackData.getLong("output_upload_finish_time", 0); + long uploadDuration = finishUploadTime - startUploadTime; + HashMap uploadData = new HashMap<>(); - uploadData.put("outputId", ackData.getString(UploadTask.KEY_OUTPUT_ID)); - uploadData.put("response", response); - uploadData.put("statusCode", ackData.getInt(UploadTask.KEY_OUTPUT_STATUS_CODE, -1)); - uploadData.put("uploadDuration", uploadDuration); - uploadData.put("finishUploadTime", finishUploadTime); + if (uploadDuration <= 0) { + uploadData.put("outputId", ackData.getString(UploadTask.KEY_OUTPUT_ID)); + uploadData.put("response", response); + uploadData.put("statusCode", ackData.getInt(UploadTask.KEY_OUTPUT_STATUS_CODE, -1)); + } else { + uploadData.put("outputId", ackData.getString(UploadTask.KEY_OUTPUT_ID)); + uploadData.put("response", response); + uploadData.put("statusCode", ackData.getInt(UploadTask.KEY_OUTPUT_STATUS_CODE, -1)); + uploadData.put("uploadDuration", uploadDuration); + uploadData.put("finishUploadTime", finishUploadTime); + } sendSuccess(uploadData); } else { diff --git a/src/android/UploadEvent.java b/src/android/UploadEvent.java index f5047681..33cf12f7 100644 --- a/src/android/UploadEvent.java +++ b/src/android/UploadEvent.java @@ -16,7 +16,7 @@ public class UploadEvent { @NonNull private Data outputData; - public UploadEvent(@NonNull final String id, @NonNull final Data outputData ) { + public UploadEvent(@NonNull final String id, @NonNull final Data outputData) { this.id = id; this.outputData = outputData; } diff --git a/src/android/UploadTask.java b/src/android/UploadTask.java index 2424ff7f..55fe02f4 100644 --- a/src/android/UploadTask.java +++ b/src/android/UploadTask.java @@ -80,7 +80,7 @@ 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_START_TIME = "output_upload_start_time"; - public static final String KEY_OUTPUT_UPLOAD_END_TIME = "output_upload_end_time"; + public static final String KEY_OUTPUT_UPLOAD_FINISH_TIME = "output_upload_finish_time"; // private static UploadNotification uploadNotification = null; @@ -242,7 +242,7 @@ public Result doWork() { .putString(KEY_OUTPUT_FAILURE_REASON, "User cancelled") .putBoolean(KEY_OUTPUT_FAILURE_CANCELED, true) .putLong(KEY_OUTPUT_UPLOAD_START_TIME, startTime) - .putLong(KEY_OUTPUT_UPLOAD_END_TIME, endTime) + .putLong(KEY_OUTPUT_UPLOAD_FINISH_TIME, endTime) .build(); AckDatabase.getInstance(getApplicationContext()).uploadEventDao().insert(new UploadEvent(id, data)); return Result.success(data); @@ -264,7 +264,7 @@ public Result doWork() { .putBoolean(KEY_OUTPUT_IS_ERROR, false) .putInt(KEY_OUTPUT_STATUS_CODE, (!DEBUG_SKIP_UPLOAD) ? response.code() : 200) .putLong(KEY_OUTPUT_UPLOAD_START_TIME, startTime) - .putLong(KEY_OUTPUT_UPLOAD_END_TIME, endTime); + .putLong(KEY_OUTPUT_UPLOAD_FINISH_TIME, endTime); // Try read the response body, if any try { From 985829d73a03c0652f497b3d1f2c6f8fc57a6820 Mon Sep 17 00:00:00 2001 From: parveshneedhoo Date: Tue, 10 Sep 2024 10:44:39 +0400 Subject: [PATCH 06/15] fix codeClimate errors --- src/android/FileTransferBackground.java | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/android/FileTransferBackground.java b/src/android/FileTransferBackground.java index 476e20bf..231fcdce 100644 --- a/src/android/FileTransferBackground.java +++ b/src/android/FileTransferBackground.java @@ -423,14 +423,10 @@ private void handleAck(final Data ackData) { long uploadDuration = finishUploadTime - startUploadTime; HashMap uploadData = new HashMap<>(); - if (uploadDuration <= 0) { - uploadData.put("outputId", ackData.getString(UploadTask.KEY_OUTPUT_ID)); - uploadData.put("response", response); - uploadData.put("statusCode", ackData.getInt(UploadTask.KEY_OUTPUT_STATUS_CODE, -1)); - } else { - uploadData.put("outputId", ackData.getString(UploadTask.KEY_OUTPUT_ID)); - uploadData.put("response", response); - uploadData.put("statusCode", ackData.getInt(UploadTask.KEY_OUTPUT_STATUS_CODE, -1)); + uploadData.put("outputId", ackData.getString(UploadTask.KEY_OUTPUT_ID)); + uploadData.put("response", response); + uploadData.put("statusCode", ackData.getInt(UploadTask.KEY_OUTPUT_STATUS_CODE, -1)); + if (uploadDuration > 0) { uploadData.put("uploadDuration", uploadDuration); uploadData.put("finishUploadTime", finishUploadTime); } From 12da3f7a9a6c4a33f07a323b07b7eb9e1293d469 Mon Sep 17 00:00:00 2001 From: parveshneedhoo Date: Tue, 10 Sep 2024 10:51:43 +0400 Subject: [PATCH 07/15] reduce cognotive complexity(code climate) --- src/android/FileTransferBackground.java | 62 ++++++++++++++----------- 1 file changed, 34 insertions(+), 28 deletions(-) diff --git a/src/android/FileTransferBackground.java b/src/android/FileTransferBackground.java index 231fcdce..424aa1b0 100644 --- a/src/android/FileTransferBackground.java +++ b/src/android/FileTransferBackground.java @@ -410,38 +410,44 @@ private void acknowledgeEvent(String eventId, CallbackContext context) { * Handle ACK data and send it to the JS. */ private void handleAck(final Data ackData) { - // If upload was successful - if (!ackData.getBoolean(UploadTask.KEY_OUTPUT_IS_ERROR, false)) { - // Read response from file if present - String response = null; - if (ackData.getString(UploadTask.KEY_OUTPUT_RESPONSE_FILE) != null) { - response = readFileToStringNoThrow(ackData.getString(UploadTask.KEY_OUTPUT_RESPONSE_FILE)); - } + if (!ackData.getBoolean(UploadTask.KEY_OUTPUT_IS_ERROR, false)) { + handleSuccessfulUpload(ackData); + } else { + handleFailedUpload(ackData); + } +} - long startUploadTime = ackData.getLong("output_upload_start_time", 0); - long finishUploadTime = ackData.getLong("output_upload_finish_time", 0); - long uploadDuration = finishUploadTime - startUploadTime; - - HashMap uploadData = new HashMap<>(); - uploadData.put("outputId", ackData.getString(UploadTask.KEY_OUTPUT_ID)); - uploadData.put("response", response); - uploadData.put("statusCode", ackData.getInt(UploadTask.KEY_OUTPUT_STATUS_CODE, -1)); - if (uploadDuration > 0) { - uploadData.put("uploadDuration", uploadDuration); - uploadData.put("finishUploadTime", finishUploadTime); - } +private void handleSuccessfulUpload(Data ackData) { + String response = null; + if (ackData.getString(UploadTask.KEY_OUTPUT_RESPONSE_FILE) != null) { + response = readFileToStringNoThrow(ackData.getString(UploadTask.KEY_OUTPUT_RESPONSE_FILE)); + } - sendSuccess(uploadData); - } else { - // The upload was a failure - sendError( - ackData.getString(UploadTask.KEY_OUTPUT_ID), - ackData.getString(UploadTask.KEY_OUTPUT_FAILURE_REASON), - ackData.getBoolean(UploadTask.KEY_OUTPUT_FAILURE_CANCELED, false) - ); - } + long startUploadTime = ackData.getLong("output_upload_start_time", 0); + long finishUploadTime = ackData.getLong("output_upload_finish_time", 0); + long uploadDuration = finishUploadTime - startUploadTime; + + HashMap uploadData = new HashMap<>(); + uploadData.put("outputId", ackData.getString(UploadTask.KEY_OUTPUT_ID)); + uploadData.put("response", response); + uploadData.put("statusCode", ackData.getInt(UploadTask.KEY_OUTPUT_STATUS_CODE, -1)); + + if (uploadDuration > 0) { + uploadData.put("uploadDuration", uploadDuration); + uploadData.put("finishUploadTime", finishUploadTime); } + sendSuccess(uploadData); +} + +private void handleFailedUpload(Data ackData) { + sendError( + ackData.getString(UploadTask.KEY_OUTPUT_ID), + ackData.getString(UploadTask.KEY_OUTPUT_FAILURE_REASON), + ackData.getBoolean(UploadTask.KEY_OUTPUT_FAILURE_CANCELED, false) + ); +} + /** * Cleanup response file and ACK entry. */ From 594f8bde5be3a17c9dc638f78eacf1767c94fee0 Mon Sep 17 00:00:00 2001 From: parveshneedhoo Date: Tue, 10 Sep 2024 10:57:26 +0400 Subject: [PATCH 08/15] refactor(code climate error) --- src/android/FileTransferBackground.java | 54 +++++++++++-------------- 1 file changed, 23 insertions(+), 31 deletions(-) diff --git a/src/android/FileTransferBackground.java b/src/android/FileTransferBackground.java index 424aa1b0..cebcc1bf 100644 --- a/src/android/FileTransferBackground.java +++ b/src/android/FileTransferBackground.java @@ -411,41 +411,33 @@ private void acknowledgeEvent(String eventId, CallbackContext context) { */ private void handleAck(final Data ackData) { if (!ackData.getBoolean(UploadTask.KEY_OUTPUT_IS_ERROR, false)) { - handleSuccessfulUpload(ackData); - } else { - handleFailedUpload(ackData); - } -} - -private void handleSuccessfulUpload(Data ackData) { - String response = null; - if (ackData.getString(UploadTask.KEY_OUTPUT_RESPONSE_FILE) != null) { - response = readFileToStringNoThrow(ackData.getString(UploadTask.KEY_OUTPUT_RESPONSE_FILE)); - } - - long startUploadTime = ackData.getLong("output_upload_start_time", 0); - long finishUploadTime = ackData.getLong("output_upload_finish_time", 0); - long uploadDuration = finishUploadTime - startUploadTime; - - HashMap uploadData = new HashMap<>(); - uploadData.put("outputId", ackData.getString(UploadTask.KEY_OUTPUT_ID)); - uploadData.put("response", response); - uploadData.put("statusCode", ackData.getInt(UploadTask.KEY_OUTPUT_STATUS_CODE, -1)); - - if (uploadDuration > 0) { - uploadData.put("uploadDuration", uploadDuration); - uploadData.put("finishUploadTime", finishUploadTime); - } - - sendSuccess(uploadData); -} - -private void handleFailedUpload(Data ackData) { - sendError( + sendError( ackData.getString(UploadTask.KEY_OUTPUT_ID), ackData.getString(UploadTask.KEY_OUTPUT_FAILURE_REASON), ackData.getBoolean(UploadTask.KEY_OUTPUT_FAILURE_CANCELED, false) ); + } else { + String response = null; + if (ackData.getString(UploadTask.KEY_OUTPUT_RESPONSE_FILE) != null) { + response = readFileToStringNoThrow(ackData.getString(UploadTask.KEY_OUTPUT_RESPONSE_FILE)); + } + + long startUploadTime = ackData.getLong("output_upload_start_time", 0); + long finishUploadTime = ackData.getLong("output_upload_finish_time", 0); + long uploadDuration = finishUploadTime - startUploadTime; + + HashMap uploadData = new HashMap<>(); + uploadData.put("outputId", ackData.getString(UploadTask.KEY_OUTPUT_ID)); + uploadData.put("response", response); + uploadData.put("statusCode", ackData.getInt(UploadTask.KEY_OUTPUT_STATUS_CODE, -1)); + + if (uploadDuration > 0) { + uploadData.put("uploadDuration", uploadDuration); + uploadData.put("finishUploadTime", finishUploadTime); + } + + sendSuccess(uploadData); + } } /** From fb8834c11c3ddc9c2595ef889814947487ad4cfd Mon Sep 17 00:00:00 2001 From: parveshneedhoo Date: Tue, 10 Sep 2024 11:00:33 +0400 Subject: [PATCH 09/15] code complexity --- src/android/FileTransferBackground.java | 52 ++++++++++++------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/src/android/FileTransferBackground.java b/src/android/FileTransferBackground.java index cebcc1bf..66cc7f23 100644 --- a/src/android/FileTransferBackground.java +++ b/src/android/FileTransferBackground.java @@ -410,35 +410,35 @@ private void acknowledgeEvent(String eventId, CallbackContext context) { * Handle ACK data and send it to the JS. */ private void handleAck(final Data ackData) { - if (!ackData.getBoolean(UploadTask.KEY_OUTPUT_IS_ERROR, false)) { - sendError( - ackData.getString(UploadTask.KEY_OUTPUT_ID), - ackData.getString(UploadTask.KEY_OUTPUT_FAILURE_REASON), - ackData.getBoolean(UploadTask.KEY_OUTPUT_FAILURE_CANCELED, false) - ); - } else { - String response = null; - if (ackData.getString(UploadTask.KEY_OUTPUT_RESPONSE_FILE) != null) { - response = readFileToStringNoThrow(ackData.getString(UploadTask.KEY_OUTPUT_RESPONSE_FILE)); - } + if (!ackData.getBoolean(UploadTask.KEY_OUTPUT_IS_ERROR, false)) { + sendError( + ackData.getString(UploadTask.KEY_OUTPUT_ID), + ackData.getString(UploadTask.KEY_OUTPUT_FAILURE_REASON), + ackData.getBoolean(UploadTask.KEY_OUTPUT_FAILURE_CANCELED, false) + ); + } else { + String response = null; + if (ackData.getString(UploadTask.KEY_OUTPUT_RESPONSE_FILE) != null) { + response = readFileToStringNoThrow(ackData.getString(UploadTask.KEY_OUTPUT_RESPONSE_FILE)); + } - long startUploadTime = ackData.getLong("output_upload_start_time", 0); - long finishUploadTime = ackData.getLong("output_upload_finish_time", 0); - long uploadDuration = finishUploadTime - startUploadTime; - - HashMap uploadData = new HashMap<>(); - uploadData.put("outputId", ackData.getString(UploadTask.KEY_OUTPUT_ID)); - uploadData.put("response", response); - uploadData.put("statusCode", ackData.getInt(UploadTask.KEY_OUTPUT_STATUS_CODE, -1)); - - if (uploadDuration > 0) { - uploadData.put("uploadDuration", uploadDuration); - uploadData.put("finishUploadTime", finishUploadTime); - } + long startUploadTime = ackData.getLong("output_upload_start_time", 0); + long finishUploadTime = ackData.getLong("output_upload_finish_time", 0); + long uploadDuration = finishUploadTime - startUploadTime; + + HashMap uploadData = new HashMap<>(); + uploadData.put("outputId", ackData.getString(UploadTask.KEY_OUTPUT_ID)); + uploadData.put("response", response); + uploadData.put("statusCode", ackData.getInt(UploadTask.KEY_OUTPUT_STATUS_CODE, -1)); + + if (uploadDuration > 0) { + uploadData.put("uploadDuration", uploadDuration); + uploadData.put("finishUploadTime", finishUploadTime); + } - sendSuccess(uploadData); + sendSuccess(uploadData); + } } -} /** * Cleanup response file and ACK entry. From 62c95ffab5ca812c38bb97bd6dcb0f9162425c6a Mon Sep 17 00:00:00 2001 From: parveshneedhoo Date: Tue, 10 Sep 2024 11:05:13 +0400 Subject: [PATCH 10/15] code complexity --- src/android/FileTransferBackground.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/android/FileTransferBackground.java b/src/android/FileTransferBackground.java index 66cc7f23..064397c2 100644 --- a/src/android/FileTransferBackground.java +++ b/src/android/FileTransferBackground.java @@ -412,10 +412,10 @@ private void acknowledgeEvent(String eventId, CallbackContext context) { private void handleAck(final Data ackData) { if (!ackData.getBoolean(UploadTask.KEY_OUTPUT_IS_ERROR, false)) { sendError( - ackData.getString(UploadTask.KEY_OUTPUT_ID), - ackData.getString(UploadTask.KEY_OUTPUT_FAILURE_REASON), - ackData.getBoolean(UploadTask.KEY_OUTPUT_FAILURE_CANCELED, false) - ); + ackData.getString(UploadTask.KEY_OUTPUT_ID), + ackData.getString(UploadTask.KEY_OUTPUT_FAILURE_REASON), + ackData.getBoolean(UploadTask.KEY_OUTPUT_FAILURE_CANCELED, false) + ); } else { String response = null; if (ackData.getString(UploadTask.KEY_OUTPUT_RESPONSE_FILE) != null) { @@ -435,7 +435,6 @@ private void handleAck(final Data ackData) { uploadData.put("uploadDuration", uploadDuration); uploadData.put("finishUploadTime", finishUploadTime); } - sendSuccess(uploadData); } } From c8349f430783e2c1ad83416f0d42302650de6ba4 Mon Sep 17 00:00:00 2001 From: parveshneedhoo Date: Thu, 12 Sep 2024 09:47:55 +0400 Subject: [PATCH 11/15] hashir review --- src/android/FileTransferBackground.java | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/android/FileTransferBackground.java b/src/android/FileTransferBackground.java index 064397c2..25e98188 100644 --- a/src/android/FileTransferBackground.java +++ b/src/android/FileTransferBackground.java @@ -411,31 +411,28 @@ private void acknowledgeEvent(String eventId, CallbackContext context) { */ private void handleAck(final Data ackData) { if (!ackData.getBoolean(UploadTask.KEY_OUTPUT_IS_ERROR, false)) { - sendError( - ackData.getString(UploadTask.KEY_OUTPUT_ID), - ackData.getString(UploadTask.KEY_OUTPUT_FAILURE_REASON), - ackData.getBoolean(UploadTask.KEY_OUTPUT_FAILURE_CANCELED, false) - ); - } else { String response = null; if (ackData.getString(UploadTask.KEY_OUTPUT_RESPONSE_FILE) != null) { response = readFileToStringNoThrow(ackData.getString(UploadTask.KEY_OUTPUT_RESPONSE_FILE)); } - long startUploadTime = ackData.getLong("output_upload_start_time", 0); - long finishUploadTime = ackData.getLong("output_upload_finish_time", 0); + long startUploadTime = ackData.getLong(UploadTask.KEY_OUTPUT_UPLOAD_START_TIME, 0); + long finishUploadTime = ackData.getLong(UploadTask.KEY_OUTPUT_UPLOAD_FINISH_TIME, 0); long uploadDuration = finishUploadTime - startUploadTime; HashMap uploadData = new HashMap<>(); uploadData.put("outputId", ackData.getString(UploadTask.KEY_OUTPUT_ID)); uploadData.put("response", response); uploadData.put("statusCode", ackData.getInt(UploadTask.KEY_OUTPUT_STATUS_CODE, -1)); - - if (uploadDuration > 0) { - uploadData.put("uploadDuration", uploadDuration); - uploadData.put("finishUploadTime", finishUploadTime); - } + uploadData.put("uploadDuration", uploadDuration); + uploadData.put("finishUploadTime", finishUploadTime); sendSuccess(uploadData); + } else { + sendError( + ackData.getString(UploadTask.KEY_OUTPUT_ID), + ackData.getString(UploadTask.KEY_OUTPUT_FAILURE_REASON), + ackData.getBoolean(UploadTask.KEY_OUTPUT_FAILURE_CANCELED, false) + ); } } From 400edd2573e80885bbe8963728458545eeb4c7c8 Mon Sep 17 00:00:00 2001 From: Hashir Rajah Date: Mon, 23 Sep 2024 13:56:52 +0400 Subject: [PATCH 12/15] Remove additional '.' in changelog compare URLs --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 132408f4..f75a1960 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,8 @@ -## [4.1.1](https://github.com/spoonconsulting/cordova-plugin-background-upload/compare/4.1.0....4.1.1) (2024-09-23) +## [4.1.1](https://github.com/spoonconsulting/cordova-plugin-background-upload/compare/4.1.0...4.1.1) (2024-09-23) * **android:** Update cordova plugin file version to 8.1.0 * **iOS:** Update cordova plugin file version to 8.1.0 -## [4.1.0](https://github.com/spoonconsulting/cordova-plugin-background-upload/compare/4.0.10....4.1.0) (2024-04-30) +## [4.1.0](https://github.com/spoonconsulting/cordova-plugin-background-upload/compare/4.0.10...4.1.0) (2024-04-30) * **android:** REVERTED Add Workers based on the number of parallelUploadsLimit and use a database to continue taking pending uploads in the Workers * **iOS:** Removed framework tag for pods From 145b0da012a44407c04d6fac3be552f7ecf4ac33 Mon Sep 17 00:00:00 2001 From: parveshneedhoo Date: Mon, 21 Oct 2024 15:07:29 +0400 Subject: [PATCH 13/15] refactor --- src/ios/FileUploader.m | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/src/ios/FileUploader.m b/src/ios/FileUploader.m index e8a6c706..4e880c7f 100644 --- a/src/ios/FileUploader.m +++ b/src/ios/FileUploader.m @@ -32,30 +32,26 @@ -(id)init{ NSDate *startTime = weakSelf.uploadStartTimes[uploadId]; NSDate *endUploadTime = [NSDate date]; NSTimeInterval timeInterval = [endUploadTime timeIntervalSince1970]; - long long uploadTimeinMS = (long long)(timeInterval * 1000); + long long endUploadTimeInMS = (long long)(timeInterval * 1000); NSTimeInterval duration = [endUploadTime timeIntervalSinceDate:startTime]; NSLog(@"[BackgroundUpload] Task %@ completed with error %@", uploadId, error); if (!error){ NSData* serverData = weakSelf.responsesData[@(task.taskIdentifier)]; NSString* serverResponse = serverData ? [[NSString alloc] initWithData:serverData encoding:NSUTF8StringEncoding] : @""; [weakSelf.responsesData removeObjectForKey:@(task.taskIdentifier)]; - if (!isnan(duration)) { - [weakSelf saveAndSendEvent:@{ + NSMutableDictionary *event = [@{ @"id" : uploadId, @"state" : @"UPLOADED", @"statusCode" : @(((NSHTTPURLResponse *)task.response).statusCode), - @"serverResponse" : serverResponse, - @"uploadDuration" : @(duration * 1000), - @"finishUploadTime": @(uploadTimeinMS) - }]; - } else { - [weakSelf saveAndSendEvent:@{ - @"id" : uploadId, - @"state" : @"UPLOADED", - @"statusCode" : @(((NSHTTPURLResponse *)task.response).statusCode), - @"serverResponse" : serverResponse, - }]; - } + @"serverResponse" : serverResponse + } mutableCopy]; + + if (!isnan(duration)) { + event[@"uploadDuration"] = @(duration * 1000); + event[@"finishUploadTime"] = @(endUploadTimeInMS); + } + + [weakSelf saveAndSendEvent:event]; } else { [weakSelf.responsesData removeObjectForKey:@(task.taskIdentifier)]; [weakSelf saveAndSendEvent:@{ From e6d4c884a4d70039f1d4f5740139bd2f54c4d281 Mon Sep 17 00:00:00 2001 From: parveshneedhoo Date: Fri, 1 Nov 2024 11:16:10 +0400 Subject: [PATCH 14/15] remove end and start time when sending response time when stopping upload --- src/android/UploadTask.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/android/UploadTask.java b/src/android/UploadTask.java index 55fe02f4..9fd1c5c0 100644 --- a/src/android/UploadTask.java +++ b/src/android/UploadTask.java @@ -241,8 +241,6 @@ public Result doWork() { .putBoolean(KEY_OUTPUT_IS_ERROR, true) .putString(KEY_OUTPUT_FAILURE_REASON, "User cancelled") .putBoolean(KEY_OUTPUT_FAILURE_CANCELED, true) - .putLong(KEY_OUTPUT_UPLOAD_START_TIME, startTime) - .putLong(KEY_OUTPUT_UPLOAD_FINISH_TIME, endTime) .build(); AckDatabase.getInstance(getApplicationContext()).uploadEventDao().insert(new UploadEvent(id, data)); return Result.success(data); From bbc74f8c4dafa111357af317e5d428b4022cd7e5 Mon Sep 17 00:00:00 2001 From: parveshneedhoo Date: Tue, 5 Nov 2024 17:31:48 +0400 Subject: [PATCH 15/15] Bump plugin version from 4.1.1 to 4.1.2 --- CHANGELOG.md | 4 ++++ package-lock.json | 4 ++-- package.json | 2 +- plugin.xml | 2 +- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f75a1960..fdaf1ad0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## [4.1.2](https://github.com/spoonconsulting/cordova-plugin-background-upload/compare/4.1.1...4.1.2) (2024-11-05) +* **android:** Return upload start and end time in upload response +* **iOS:** Return upload start and end time in upload response + ## [4.1.1](https://github.com/spoonconsulting/cordova-plugin-background-upload/compare/4.1.0...4.1.1) (2024-09-23) * **android:** Update cordova plugin file version to 8.1.0 * **iOS:** Update cordova plugin file version to 8.1.0 diff --git a/package-lock.json b/package-lock.json index fe1a34e8..99d0eae6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@spoonconsulting/cordova-plugin-background-upload", - "version": "4.1.1", + "version": "4.1.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@spoonconsulting/cordova-plugin-background-upload", - "version": "4.1.1", + "version": "4.1.2", "license": "Apache-2.0", "devDependencies": { "cordova-paramedic": "git+https://github.com/apache/cordova-paramedic.git", diff --git a/package.json b/package.json index 8efaf55d..d02fac77 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@spoonconsulting/cordova-plugin-background-upload", - "version": "4.1.1", + "version": "4.1.2", "description": "Cordova plugin for uploading file in the background", "cordova": { "id": "@spoonconsulting/cordova-plugin-background-upload", diff --git a/plugin.xml b/plugin.xml index 599588f1..69290c1d 100644 --- a/plugin.xml +++ b/plugin.xml @@ -1,5 +1,5 @@ - + Cordova Background Upload Plugin Background Upload plugin for Cordova ISC