Skip to content

Commit bad7499

Browse files
authored
Fix job strategy cancel all requests
1 parent 01cafb9 commit bad7499

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

core/src/main/java/com/cloudinary/android/AndroidJobStrategy.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,9 @@ public boolean cancelRequest(String requestId) {
108108
return operation.getResult().isCancelled();
109109
}
110110

111-
@Override
112111
public int cancelAllRequests() {
113112
WorkManager.getInstance(context).cancelAllWork();
114-
killAllThreads();
115-
return 0;
113+
return killAllThreads();
116114
}
117115

118116
private void killThread(String requestId) {
@@ -129,8 +127,9 @@ private void killThread(String requestId) {
129127
}
130128
}
131129

132-
private void killAllThreads() {
130+
private int killAllThreads() {
133131
synchronized (threadsMapLockObject) {
132+
int size = threads.size();
134133
for (String requestId : threads.keySet()) {
135134
WeakReference<Thread> ref = threads.get(requestId);
136135
Thread thread = ref.get();
@@ -141,8 +140,8 @@ private void killAllThreads() {
141140

142141
ref.clear();
143142
}
144-
145143
threads.clear();
144+
return size;
146145
}
147146
}
148147

core/src/main/java/com/cloudinary/android/UploaderStrategy.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import java.io.File;
1414
import java.io.IOException;
1515
import java.io.InputStream;
16+
import java.io.InterruptedIOException;
1617
import java.net.HttpURLConnection;
1718
import java.util.Collection;
1819
import java.util.Map;
@@ -73,7 +74,7 @@ public void totalBytesLoaded(long bytes) {
7374
}
7475

7576
MultipartUtility multipart = null;
76-
HttpURLConnection connection;
77+
HttpURLConnection connection = null;
7778

7879
try {
7980
int connectTimeout = options.get("connect_timeout") != null ? (int) options.get("connect_timeout") : 0;
@@ -108,6 +109,8 @@ public void totalBytesLoaded(long bytes) {
108109
}
109110

110111
connection = multipart.execute();
112+
} catch(InterruptedIOException e ) {
113+
e.printStackTrace();
111114
} finally {
112115
if (multipart != null){
113116
// Closing more than once has no effect so we can call it safely without having to check state

0 commit comments

Comments
 (0)