Add the ability to get the current state of a job.

This commit is contained in:
Greyson Parrelli 2021-11-12 09:53:03 -05:00 committed by Alex Hart
parent 1f860d41b5
commit 51c86cab10
2 changed files with 21 additions and 1 deletions

View file

@ -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.
*/

View file

@ -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.
*/