diff --git a/app/src/main/java/org/thoughtcrime/securesms/jobmanager/JobManager.java b/app/src/main/java/org/thoughtcrime/securesms/jobmanager/JobManager.java index e6e5a7a39b..d4ccd6b42e 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/jobmanager/JobManager.java +++ b/app/src/main/java/org/thoughtcrime/securesms/jobmanager/JobManager.java @@ -137,6 +137,14 @@ public class JobManager implements ConstraintObserver.Notifier { jobTracker.removeListener(listener); } + /** + * Returns the state of the first Job that matches the provided filter. Note that there will always be races here, and the result you get back may not be + * valid anymore by the time you get it. Use with caution. + */ + public @Nullable JobTracker.JobState getFirstMatchingJobState(@NonNull JobTracker.JobFilter filter) { + return jobTracker.getFirstMatchingJobState(filter); + } + /** * Enqueues a single job to be run. */ diff --git a/app/src/main/java/org/thoughtcrime/securesms/jobmanager/JobTracker.java b/app/src/main/java/org/thoughtcrime/securesms/jobmanager/JobTracker.java index 4604a3176e..e37508e5ef 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/jobmanager/JobTracker.java +++ b/app/src/main/java/org/thoughtcrime/securesms/jobmanager/JobTracker.java @@ -11,7 +11,6 @@ import org.thoughtcrime.securesms.util.LRUCache; import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -54,6 +53,19 @@ public class JobTracker { } } + /** + * Returns the state of the first Job that matches the provided filter. Note that there will always be races here, and the result you get back may not be + * valid anymore by the time you get it. Use with caution. + */ + synchronized @Nullable JobState getFirstMatchingJobState(@NonNull JobFilter filter) { + for (JobInfo info : jobInfos.values()) { + if (filter.matches(info.getJob())) { + return info.getJobState(); + } + } + return null; + } + /** * Update the state of a job with the associated ID. */