mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-22 01:40:07 +01:00
Add support for non-blocking media sends.
This commit is contained in:
@@ -5,6 +5,7 @@ import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.WorkerThread;
|
||||
|
||||
import com.annimon.stream.Collectors;
|
||||
import com.annimon.stream.Stream;
|
||||
|
||||
import org.thoughtcrime.securesms.jobmanager.persistence.ConstraintSpec;
|
||||
@@ -22,6 +23,7 @@ import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Manages the queue of jobs. This is the only class that should write to {@link JobStorage} to
|
||||
@@ -97,7 +99,7 @@ class JobController {
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
synchronized void submitJobWithExistingDependencies(@NonNull Job job, @NonNull Collection<String> dependsOn) {
|
||||
synchronized void submitJobWithExistingDependencies(@NonNull Job job, @NonNull Collection<String> dependsOn, @Nullable String dependsOnQueue) {
|
||||
List<List<Job>> chain = Collections.singletonList(Collections.singletonList(job));
|
||||
|
||||
if (chainExceedsMaximumInstances(chain)) {
|
||||
@@ -106,11 +108,17 @@ class JobController {
|
||||
return;
|
||||
}
|
||||
|
||||
dependsOn = Stream.of(dependsOn)
|
||||
.filter(id -> jobStorage.getJobSpec(id) != null)
|
||||
.toList();
|
||||
Set<String> dependsOnSet = Stream.of(dependsOn)
|
||||
.filter(id -> jobStorage.getJobSpec(id) != null)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
FullSpec fullSpec = buildFullSpec(job, dependsOn);
|
||||
if (dependsOnQueue != null) {
|
||||
dependsOnSet.addAll(Stream.of(jobStorage.getJobsInQueue(dependsOnQueue))
|
||||
.map(JobSpec::getId)
|
||||
.toList());
|
||||
}
|
||||
|
||||
FullSpec fullSpec = buildFullSpec(job, dependsOnSet);
|
||||
jobStorage.insertJobs(Collections.singletonList(fullSpec));
|
||||
|
||||
scheduleJobs(Collections.singletonList(job));
|
||||
|
||||
@@ -4,6 +4,7 @@ import android.app.Application;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.WorkerThread;
|
||||
|
||||
import org.thoughtcrime.securesms.jobmanager.impl.DefaultExecutorFactory;
|
||||
@@ -138,7 +139,33 @@ public class JobManager implements ConstraintObserver.Notifier {
|
||||
jobTracker.onStateChange(job, JobTracker.JobState.PENDING);
|
||||
|
||||
executor.execute(() -> {
|
||||
jobController.submitJobWithExistingDependencies(job, dependsOn);
|
||||
jobController.submitJobWithExistingDependencies(job, dependsOn, null);
|
||||
wakeUp();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueues a single job that depends on a collection of job ID's, as well as any unfinished
|
||||
* items in the specified queue.
|
||||
*/
|
||||
public void add(@NonNull Job job, @Nullable String dependsOnQueue) {
|
||||
jobTracker.onStateChange(job, JobTracker.JobState.PENDING);
|
||||
|
||||
executor.execute(() -> {
|
||||
jobController.submitJobWithExistingDependencies(job, Collections.emptyList(), dependsOnQueue);
|
||||
wakeUp();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueues a single job that depends on a collection of job ID's, as well as any unfinished
|
||||
* items in the specified queue.
|
||||
*/
|
||||
public void add(@NonNull Job job, @NonNull Collection<String> dependsOn, @Nullable String dependsOnQueue) {
|
||||
jobTracker.onStateChange(job, JobTracker.JobState.PENDING);
|
||||
|
||||
executor.execute(() -> {
|
||||
jobController.submitJobWithExistingDependencies(job, dependsOn, dependsOnQueue);
|
||||
wakeUp();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -23,6 +23,9 @@ public interface JobStorage {
|
||||
@WorkerThread
|
||||
@NonNull List<JobSpec> getPendingJobsWithNoDependenciesInCreatedOrder(long currentTime);
|
||||
|
||||
@WorkerThread
|
||||
@NonNull List<JobSpec> getJobsInQueue(@NonNull String queue);
|
||||
|
||||
@WorkerThread
|
||||
int getJobInstanceCount(@NonNull String factoryKey);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user