Skip to content

Commit c83d392

Browse files
committed
Update to background thread execution for listDownloadModels call.
1 parent bc436f0 commit c83d392

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

firebase-ml-modeldownloader/src/main/java/com/google/firebase/ml/modeldownloader/internal/SharedPreferencesUtil.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ public synchronized Set<CustomModel> listDownloadedModels() {
213213
matcher = Pattern.compile(DOWNLOADING_MODEL_ID_PATTERN).matcher(key);
214214
if (matcher.find()) {
215215
String modelName = matcher.group(matcher.groupCount());
216-
CustomModel extractModel = isDownloadCompleted(modelName);
216+
CustomModel extractModel = maybeGetUpdatedModel(modelName);
217217
if (extractModel != null) {
218218
customModels.add(extractModel);
219219
}
@@ -223,7 +223,7 @@ public synchronized Set<CustomModel> listDownloadedModels() {
223223
return customModels;
224224
}
225225

226-
synchronized CustomModel isDownloadCompleted(String modelName) {
226+
synchronized CustomModel maybeGetUpdatedModel(String modelName) {
227227
CustomModel downloadModel = getCustomModelDetails(modelName);
228228
// TODO(annz) check here if download currently in progress have completed.
229229
// if yes, then complete file relocation and return the updated model, otherwise return null

firebase-ml-modeldownloader/src/test/java/com/google/firebase/ml/modeldownloader/FirebaseModelDownloaderTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@
2929
import java.util.Set;
3030
import java.util.concurrent.ExecutionException;
3131
import java.util.concurrent.ExecutorService;
32-
import java.util.concurrent.LinkedBlockingQueue;
33-
import java.util.concurrent.ThreadPoolExecutor;
32+
import java.util.concurrent.Executors;
3433
import java.util.concurrent.TimeUnit;
3534
import org.junit.After;
3635
import org.junit.Before;
@@ -69,7 +68,7 @@ public void setUp() {
6968
// default app
7069
FirebaseApp.initializeApp(ApplicationProvider.getApplicationContext(), FIREBASE_OPTIONS);
7170

72-
executor = new ThreadPoolExecutor(0, 1, 30L, TimeUnit.SECONDS, new LinkedBlockingQueue<>());
71+
executor = Executors.newSingleThreadExecutor();
7372
firebaseModelDownloader = new FirebaseModelDownloader(FIREBASE_OPTIONS, mockPrefs, executor);
7473
}
7574

0 commit comments

Comments
 (0)