mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-23 00:17:34 +00:00
Let's have JobManager only deal with checked exceptions.
Also, switch to Builder for JobManager construction.
This commit is contained in:
parent
d9d4ec9d9d
commit
0d06d50a65
@ -7,6 +7,7 @@ import org.whispersystems.jobqueue.jobs.RequirementDeferringTestJob;
|
|||||||
import org.whispersystems.jobqueue.jobs.RequirementTestJob;
|
import org.whispersystems.jobqueue.jobs.RequirementTestJob;
|
||||||
import org.whispersystems.jobqueue.jobs.TestJob;
|
import org.whispersystems.jobqueue.jobs.TestJob;
|
||||||
import org.whispersystems.jobqueue.persistence.JavaJobSerializer;
|
import org.whispersystems.jobqueue.persistence.JavaJobSerializer;
|
||||||
|
import org.whispersystems.jobqueue.requirements.RequirementProvider;
|
||||||
import org.whispersystems.jobqueue.util.MockRequirement;
|
import org.whispersystems.jobqueue.util.MockRequirement;
|
||||||
import org.whispersystems.jobqueue.util.MockRequirementProvider;
|
import org.whispersystems.jobqueue.util.MockRequirementProvider;
|
||||||
import org.whispersystems.jobqueue.util.PersistentMockRequirement;
|
import org.whispersystems.jobqueue.util.PersistentMockRequirement;
|
||||||
@ -15,12 +16,17 @@ import org.whispersystems.jobqueue.util.PersistentResult;
|
|||||||
import org.whispersystems.jobqueue.util.RunnableThrowable;
|
import org.whispersystems.jobqueue.util.RunnableThrowable;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class JobManagerTest extends AndroidTestCase {
|
public class JobManagerTest extends AndroidTestCase {
|
||||||
|
|
||||||
public void testTransientJobExecution() throws InterruptedException {
|
public void testTransientJobExecution() throws InterruptedException {
|
||||||
TestJob testJob = new TestJob();
|
TestJob testJob = new TestJob();
|
||||||
JobManager jobManager = new JobManager(getContext(), "transient-test", null, null, 1);
|
JobManager jobManager = JobManager.newBuilder(getContext())
|
||||||
|
.withName("transient-test")
|
||||||
|
.withConsumerThreads(1)
|
||||||
|
.build();
|
||||||
|
|
||||||
jobManager.add(testJob);
|
jobManager.add(testJob);
|
||||||
|
|
||||||
@ -32,8 +38,12 @@ public class JobManagerTest extends AndroidTestCase {
|
|||||||
MockRequirementProvider provider = new MockRequirementProvider();
|
MockRequirementProvider provider = new MockRequirementProvider();
|
||||||
MockRequirement requirement = new MockRequirement(false);
|
MockRequirement requirement = new MockRequirement(false);
|
||||||
TestJob testJob = new RequirementTestJob(requirement);
|
TestJob testJob = new RequirementTestJob(requirement);
|
||||||
JobManager jobManager = new JobManager(getContext(), "transient-requirement-test",
|
|
||||||
provider, null, 1);
|
JobManager jobManager = JobManager.newBuilder(getContext())
|
||||||
|
.withName("transient-requirement-test")
|
||||||
|
.withRequirementProviders(provider)
|
||||||
|
.withConsumerThreads(1)
|
||||||
|
.build();
|
||||||
|
|
||||||
jobManager.add(testJob);
|
jobManager.add(testJob);
|
||||||
|
|
||||||
@ -75,8 +85,12 @@ public class JobManagerTest extends AndroidTestCase {
|
|||||||
MockRequirementProvider provider = new MockRequirementProvider();
|
MockRequirementProvider provider = new MockRequirementProvider();
|
||||||
MockRequirement requirement = new MockRequirement(false);
|
MockRequirement requirement = new MockRequirement(false);
|
||||||
RequirementDeferringTestJob testJob = new RequirementDeferringTestJob(requirement, 5, waitRunnable);
|
RequirementDeferringTestJob testJob = new RequirementDeferringTestJob(requirement, 5, waitRunnable);
|
||||||
JobManager jobManager = new JobManager(getContext(), "transient-requirement-test",
|
|
||||||
provider, null, 1);
|
JobManager jobManager = JobManager.newBuilder(getContext())
|
||||||
|
.withName("transient-requirement-test")
|
||||||
|
.withRequirementProviders(provider)
|
||||||
|
.withConsumerThreads(1)
|
||||||
|
.build();
|
||||||
|
|
||||||
jobManager.add(testJob);
|
jobManager.add(testJob);
|
||||||
|
|
||||||
@ -106,8 +120,11 @@ public class JobManagerTest extends AndroidTestCase {
|
|||||||
public void testPersistentJobExecuton() throws InterruptedException {
|
public void testPersistentJobExecuton() throws InterruptedException {
|
||||||
PersistentMockRequirement requirement = new PersistentMockRequirement();
|
PersistentMockRequirement requirement = new PersistentMockRequirement();
|
||||||
PersistentTestJob testJob = new PersistentTestJob(requirement);
|
PersistentTestJob testJob = new PersistentTestJob(requirement);
|
||||||
JobManager jobManager = new JobManager(getContext(), "persistent-requirement-test3",
|
JobManager jobManager = JobManager.newBuilder(getContext())
|
||||||
null, new JavaJobSerializer(getContext()), 1);
|
.withName("persistent-requirement-test3")
|
||||||
|
.withJobSerializer(new JavaJobSerializer(getContext()))
|
||||||
|
.withConsumerThreads(1)
|
||||||
|
.build();
|
||||||
|
|
||||||
PersistentResult.getInstance().reset();
|
PersistentResult.getInstance().reset();
|
||||||
PersistentRequirement.getInstance().setPresent(false);
|
PersistentRequirement.getInstance().setPresent(false);
|
||||||
@ -118,8 +135,12 @@ public class JobManagerTest extends AndroidTestCase {
|
|||||||
assertTrue(!PersistentResult.getInstance().isRan());
|
assertTrue(!PersistentResult.getInstance().isRan());
|
||||||
|
|
||||||
PersistentRequirement.getInstance().setPresent(true);
|
PersistentRequirement.getInstance().setPresent(true);
|
||||||
jobManager = new JobManager(getContext(), "persistent-requirement-test3", null,
|
|
||||||
new JavaJobSerializer(getContext()), 1);
|
jobManager = JobManager.newBuilder(getContext())
|
||||||
|
.withName("persistent-requirement-test3")
|
||||||
|
.withJobSerializer(new JavaJobSerializer(getContext()))
|
||||||
|
.withConsumerThreads(1)
|
||||||
|
.build();
|
||||||
|
|
||||||
assertTrue(PersistentResult.getInstance().isRan());
|
assertTrue(PersistentResult.getInstance().isRan());
|
||||||
}
|
}
|
||||||
@ -128,8 +149,12 @@ public class JobManagerTest extends AndroidTestCase {
|
|||||||
EncryptionKeys keys = new EncryptionKeys(new byte[30]);
|
EncryptionKeys keys = new EncryptionKeys(new byte[30]);
|
||||||
PersistentMockRequirement requirement = new PersistentMockRequirement();
|
PersistentMockRequirement requirement = new PersistentMockRequirement();
|
||||||
PersistentTestJob testJob = new PersistentTestJob(requirement, keys);
|
PersistentTestJob testJob = new PersistentTestJob(requirement, keys);
|
||||||
JobManager jobManager = new JobManager(getContext(), "persistent-requirement-test4",
|
JobManager jobManager = JobManager.newBuilder(getContext())
|
||||||
null, new JavaJobSerializer(getContext()), 1);
|
.withName("persistent-requirement-test4")
|
||||||
|
.withJobSerializer(new JavaJobSerializer(getContext()))
|
||||||
|
.withConsumerThreads(1)
|
||||||
|
.build();
|
||||||
|
|
||||||
jobManager.setEncryptionKeys(keys);
|
jobManager.setEncryptionKeys(keys);
|
||||||
|
|
||||||
PersistentResult.getInstance().reset();
|
PersistentResult.getInstance().reset();
|
||||||
@ -141,7 +166,11 @@ public class JobManagerTest extends AndroidTestCase {
|
|||||||
assertTrue(!PersistentResult.getInstance().isRan());
|
assertTrue(!PersistentResult.getInstance().isRan());
|
||||||
|
|
||||||
PersistentRequirement.getInstance().setPresent(true);
|
PersistentRequirement.getInstance().setPresent(true);
|
||||||
jobManager = new JobManager(getContext(), "persistent-requirement-test4", null, new JavaJobSerializer(getContext()), 1);
|
jobManager = JobManager.newBuilder(getContext())
|
||||||
|
.withName("persistent-requirement-test4")
|
||||||
|
.withJobSerializer(new JavaJobSerializer(getContext()))
|
||||||
|
.withConsumerThreads(1)
|
||||||
|
.build();
|
||||||
|
|
||||||
assertTrue(!PersistentResult.getInstance().isRan());
|
assertTrue(!PersistentResult.getInstance().isRan());
|
||||||
|
|
||||||
@ -169,7 +198,10 @@ public class JobManagerTest extends AndroidTestCase {
|
|||||||
TestJob testJobOne = new TestJob(JobParameters.newBuilder().withGroupId("foo").create(), waitRunnable);
|
TestJob testJobOne = new TestJob(JobParameters.newBuilder().withGroupId("foo").create(), waitRunnable);
|
||||||
TestJob testJobTwo = new TestJob(JobParameters.newBuilder().withGroupId("foo").create());
|
TestJob testJobTwo = new TestJob(JobParameters.newBuilder().withGroupId("foo").create());
|
||||||
TestJob testJobThree = new TestJob(JobParameters.newBuilder().withGroupId("bar").create());
|
TestJob testJobThree = new TestJob(JobParameters.newBuilder().withGroupId("bar").create());
|
||||||
JobManager jobManager = new JobManager(getContext(), "transient-test", null, null, 3);
|
JobManager jobManager = JobManager.newBuilder(getContext())
|
||||||
|
.withName("transient-test")
|
||||||
|
.withConsumerThreads(3)
|
||||||
|
.build();
|
||||||
|
|
||||||
jobManager.add(testJobOne);
|
jobManager.add(testJobOne);
|
||||||
jobManager.add(testJobTwo);
|
jobManager.add(testJobTwo);
|
||||||
|
@ -19,11 +19,11 @@ public class PersistentTestJob extends Job {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAdded() {
|
public void onAdded() {
|
||||||
PersistentResult.getInstance().onAdded();;
|
PersistentResult.getInstance().onAdded();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRun() throws Throwable {
|
public void onRun() throws Exception {
|
||||||
PersistentResult.getInstance().onRun();
|
PersistentResult.getInstance().onRun();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ public class PersistentTestJob extends Job {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onShouldRetry(Throwable throwable) {
|
public boolean onShouldRetry(Exception exception) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ public class RequirementDeferringTestJob extends TestJob {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRun() throws Throwable {
|
public void onRun() throws Exception {
|
||||||
synchronized (RAN_LOCK) {
|
synchronized (RAN_LOCK) {
|
||||||
this.ran = true;
|
this.ran = true;
|
||||||
}
|
}
|
||||||
@ -34,8 +34,8 @@ public class RequirementDeferringTestJob extends TestJob {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onShouldRetry(Throwable throwable) {
|
public boolean onShouldRetry(Exception exception) {
|
||||||
if (throwable instanceof Exception) {
|
if (exception instanceof Exception) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -37,7 +37,7 @@ public class TestJob extends Job {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRun() throws Throwable {
|
public void onRun() throws Exception {
|
||||||
synchronized (RAN_LOCK) {
|
synchronized (RAN_LOCK) {
|
||||||
this.ran = true;
|
this.ran = true;
|
||||||
}
|
}
|
||||||
@ -54,7 +54,7 @@ public class TestJob extends Job {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onShouldRetry(Throwable throwable) {
|
public boolean onShouldRetry(Exception exception) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,4 +15,9 @@ public class MockRequirementProvider implements RequirementProvider {
|
|||||||
public void setListener(RequirementListener listener) {
|
public void setListener(RequirementListener listener) {
|
||||||
this.listener = listener;
|
this.listener = listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "mock-requirement-provider";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ public class PersistentResult {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onRun() throws Throwable {
|
public void onRun() throws Exception {
|
||||||
synchronized (RAN_LOCK) {
|
synchronized (RAN_LOCK) {
|
||||||
this.ran = true;
|
this.ran = true;
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@ package org.whispersystems.jobqueue.util;
|
|||||||
|
|
||||||
public interface RunnableThrowable {
|
public interface RunnableThrowable {
|
||||||
|
|
||||||
public void run() throws Throwable;
|
public void run() throws Exception;
|
||||||
|
|
||||||
public void shouldThrow(Boolean value);
|
public void shouldThrow(Boolean value);
|
||||||
}
|
}
|
||||||
|
@ -81,9 +81,10 @@ public abstract class Job implements Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public abstract void onAdded();
|
public abstract void onAdded();
|
||||||
public abstract void onRun() throws Throwable;
|
public abstract void onRun() throws Exception;
|
||||||
|
public abstract boolean onShouldRetry(Exception exception);
|
||||||
public abstract void onCanceled();
|
public abstract void onCanceled();
|
||||||
public abstract boolean onShouldRetry(Throwable throwable);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -43,10 +43,11 @@ public class JobConsumer extends Thread {
|
|||||||
public void run() {
|
public void run() {
|
||||||
while (true) {
|
while (true) {
|
||||||
Job job = jobQueue.getNext();
|
Job job = jobQueue.getNext();
|
||||||
|
JobResult result = runJob(job);
|
||||||
|
|
||||||
JobResult result;
|
if (result == JobResult.DEFERRED) {
|
||||||
|
jobQueue.push(job);
|
||||||
if ((result = runJob(job)) != JobResult.DEFERRED) {
|
} else {
|
||||||
if (result == JobResult.FAILURE) {
|
if (result == JobResult.FAILURE) {
|
||||||
job.onCanceled();
|
job.onCanceled();
|
||||||
}
|
}
|
||||||
@ -54,8 +55,6 @@ public class JobConsumer extends Thread {
|
|||||||
if (job.isPersistent()) {
|
if (job.isPersistent()) {
|
||||||
persistentStorage.remove(job.getPersistentId());
|
persistentStorage.remove(job.getPersistentId());
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
jobQueue.add(job);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (job.getGroupId() != null) {
|
if (job.getGroupId() != null) {
|
||||||
@ -72,9 +71,11 @@ public class JobConsumer extends Thread {
|
|||||||
try {
|
try {
|
||||||
job.onRun();
|
job.onRun();
|
||||||
return JobResult.SUCCESS;
|
return JobResult.SUCCESS;
|
||||||
} catch (Throwable throwable) {
|
} catch (Exception exception) {
|
||||||
Log.w(TAG, throwable);
|
Log.w(TAG, exception);
|
||||||
if (!job.onShouldRetry(throwable)) {
|
if (exception instanceof RuntimeException) {
|
||||||
|
throw (RuntimeException)exception;
|
||||||
|
} else if (!job.onShouldRetry(exception)) {
|
||||||
return JobResult.FAILURE;
|
return JobResult.FAILURE;
|
||||||
} else if (!job.isRequirementsMet()) {
|
} else if (!job.isRequirementsMet()) {
|
||||||
job.setRunIteration(runIteration+1);
|
job.setRunIteration(runIteration+1);
|
||||||
|
@ -26,6 +26,7 @@ import org.whispersystems.jobqueue.requirements.RequirementListener;
|
|||||||
import org.whispersystems.jobqueue.requirements.RequirementProvider;
|
import org.whispersystems.jobqueue.requirements.RequirementProvider;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
@ -41,7 +42,7 @@ public class JobManager implements RequirementListener {
|
|||||||
private final List<RequirementProvider> requirementProviders;
|
private final List<RequirementProvider> requirementProviders;
|
||||||
private final DependencyInjector dependencyInjector;
|
private final DependencyInjector dependencyInjector;
|
||||||
|
|
||||||
public JobManager(Context context, String name,
|
private JobManager(Context context, String name,
|
||||||
List<RequirementProvider> requirementProviders,
|
List<RequirementProvider> requirementProviders,
|
||||||
DependencyInjector dependencyInjector,
|
DependencyInjector dependencyInjector,
|
||||||
JobSerializer jobSerializer, int consumers)
|
JobSerializer jobSerializer, int consumers)
|
||||||
@ -63,6 +64,10 @@ public class JobManager implements RequirementListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Builder newBuilder(Context context) {
|
||||||
|
return new Builder(context);
|
||||||
|
}
|
||||||
|
|
||||||
public RequirementProvider getRequirementProvider(String name) {
|
public RequirementProvider getRequirementProvider(String name) {
|
||||||
for (RequirementProvider provider : requirementProviders) {
|
for (RequirementProvider provider : requirementProviders) {
|
||||||
if (provider.getName().equals(name)) {
|
if (provider.getName().equals(name)) {
|
||||||
@ -131,4 +136,53 @@ public class JobManager implements RequirementListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class Builder {
|
||||||
|
private final Context context;
|
||||||
|
private String name;
|
||||||
|
private List<RequirementProvider> requirementProviders;
|
||||||
|
private DependencyInjector dependencyInjector;
|
||||||
|
private JobSerializer jobSerializer;
|
||||||
|
private int consumerThreads;
|
||||||
|
|
||||||
|
Builder(Context context) {
|
||||||
|
this.context = context;
|
||||||
|
this.consumerThreads = 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder withName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder withRequirementProviders(RequirementProvider... requirementProviders) {
|
||||||
|
this.requirementProviders = Arrays.asList(requirementProviders);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder withDependencyInjector(DependencyInjector dependencyInjector) {
|
||||||
|
this.dependencyInjector = dependencyInjector;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder withJobSerializer(JobSerializer jobSerializer) {
|
||||||
|
this.jobSerializer = jobSerializer;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder withConsumerThreads(int consumerThreads) {
|
||||||
|
this.consumerThreads = consumerThreads;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JobManager build() {
|
||||||
|
if (name == null) {
|
||||||
|
throw new IllegalArgumentException("You must specify a name!");
|
||||||
|
}
|
||||||
|
|
||||||
|
return new JobManager(context, name, requirementProviders,
|
||||||
|
dependencyInjector, jobSerializer,
|
||||||
|
consumerThreads);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -43,6 +43,10 @@ public class JobQueue {
|
|||||||
notifyAll();
|
notifyAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
synchronized void push(Job job) {
|
||||||
|
jobQueue.push(job);
|
||||||
|
}
|
||||||
|
|
||||||
public synchronized Job getNext() {
|
public synchronized Job getNext() {
|
||||||
try {
|
try {
|
||||||
Job nextAvailableJob;
|
Job nextAvailableJob;
|
||||||
|
@ -22,18 +22,12 @@ import android.content.Context;
|
|||||||
import org.thoughtcrime.securesms.crypto.PRNGFixes;
|
import org.thoughtcrime.securesms.crypto.PRNGFixes;
|
||||||
import org.thoughtcrime.securesms.dependencies.AxolotlStorageModule;
|
import org.thoughtcrime.securesms.dependencies.AxolotlStorageModule;
|
||||||
import org.thoughtcrime.securesms.dependencies.InjectableType;
|
import org.thoughtcrime.securesms.dependencies.InjectableType;
|
||||||
import org.thoughtcrime.securesms.jobs.persistence.EncryptingJobSerializer;
|
|
||||||
import org.thoughtcrime.securesms.jobs.GcmRefreshJob;
|
|
||||||
import org.thoughtcrime.securesms.jobs.requirements.MasterSecretRequirementProvider;
|
|
||||||
import org.thoughtcrime.securesms.dependencies.TextSecureCommunicationModule;
|
import org.thoughtcrime.securesms.dependencies.TextSecureCommunicationModule;
|
||||||
|
import org.thoughtcrime.securesms.jobs.GcmRefreshJob;
|
||||||
|
import org.thoughtcrime.securesms.jobs.persistence.EncryptingJobSerializer;
|
||||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||||
import org.whispersystems.jobqueue.JobManager;
|
import org.whispersystems.jobqueue.JobManager;
|
||||||
import org.whispersystems.jobqueue.dependencies.DependencyInjector;
|
import org.whispersystems.jobqueue.dependencies.DependencyInjector;
|
||||||
import org.whispersystems.jobqueue.requirements.NetworkRequirementProvider;
|
|
||||||
import org.whispersystems.jobqueue.requirements.RequirementProvider;
|
|
||||||
|
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import dagger.ObjectGraph;
|
import dagger.ObjectGraph;
|
||||||
|
|
||||||
@ -79,13 +73,12 @@ public class ApplicationContext extends Application implements DependencyInjecto
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void initializeJobManager() {
|
private void initializeJobManager() {
|
||||||
List<RequirementProvider> providers = new LinkedList<RequirementProvider>() {{
|
this.jobManager = JobManager.newBuilder(this)
|
||||||
add(new NetworkRequirementProvider(ApplicationContext.this));
|
.withName("TextSecureJobs")
|
||||||
add(new MasterSecretRequirementProvider(ApplicationContext.this));
|
.withDependencyInjector(this)
|
||||||
}};
|
.withJobSerializer(new EncryptingJobSerializer(this))
|
||||||
|
.withConsumerThreads(5)
|
||||||
this.jobManager = new JobManager(this, "TextSecureJobs", providers, this,
|
.build();
|
||||||
new EncryptingJobSerializer(this), 5);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initializeDependencyInjection() {
|
private void initializeDependencyInjection() {
|
||||||
|
@ -77,8 +77,8 @@ public class AttachmentDownloadJob extends MasterSecretJob implements Injectable
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onShouldRetryThrowable(Throwable throwable) {
|
public boolean onShouldRetryThrowable(Exception exception) {
|
||||||
if (throwable instanceof PushNetworkException) return true;
|
if (exception instanceof PushNetworkException) return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -91,8 +91,8 @@ public class AvatarDownloadJob extends MasterSecretJob {
|
|||||||
public void onCanceled() {}
|
public void onCanceled() {}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onShouldRetryThrowable(Throwable throwable) {
|
public boolean onShouldRetryThrowable(Exception exception) {
|
||||||
if (throwable instanceof IOException) return true;
|
if (exception instanceof IOException) return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,7 +84,7 @@ public class CleanPreKeysJob extends MasterSecretJob implements InjectableType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onShouldRetryThrowable(Throwable throwable) {
|
public boolean onShouldRetryThrowable(Exception throwable) {
|
||||||
if (throwable instanceof NonSuccessfulResponseCodeException) return false;
|
if (throwable instanceof NonSuccessfulResponseCodeException) return false;
|
||||||
if (throwable instanceof PushNetworkException) return true;
|
if (throwable instanceof PushNetworkException) return true;
|
||||||
return false;
|
return false;
|
||||||
|
@ -7,7 +7,6 @@ import org.thoughtcrime.securesms.crypto.IdentityKeyUtil;
|
|||||||
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
||||||
import org.thoughtcrime.securesms.crypto.PreKeyUtil;
|
import org.thoughtcrime.securesms.crypto.PreKeyUtil;
|
||||||
import org.thoughtcrime.securesms.dependencies.InjectableType;
|
import org.thoughtcrime.securesms.dependencies.InjectableType;
|
||||||
import org.thoughtcrime.securesms.push.TextSecureCommunicationFactory;
|
|
||||||
import org.thoughtcrime.securesms.util.ParcelUtil;
|
import org.thoughtcrime.securesms.util.ParcelUtil;
|
||||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||||
import org.whispersystems.jobqueue.EncryptionKeys;
|
import org.whispersystems.jobqueue.EncryptionKeys;
|
||||||
@ -60,8 +59,8 @@ public class CreateSignedPreKeyJob extends ContextJob implements InjectableType
|
|||||||
public void onCanceled() {}
|
public void onCanceled() {}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onShouldRetry(Throwable throwable) {
|
public boolean onShouldRetry(Exception exception) {
|
||||||
if (throwable instanceof PushNetworkException) return true;
|
if (exception instanceof PushNetworkException) return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -62,10 +62,10 @@ public class DeliveryReceiptJob extends ContextJob implements InjectableType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onShouldRetry(Throwable throwable) {
|
public boolean onShouldRetry(Exception exception) {
|
||||||
Log.w(TAG, throwable);
|
Log.w(TAG, exception);
|
||||||
if (throwable instanceof NonSuccessfulResponseCodeException) return false;
|
if (exception instanceof NonSuccessfulResponseCodeException) return false;
|
||||||
if (throwable instanceof PushNetworkException) return true;
|
if (exception instanceof PushNetworkException) return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@ public class GcmRefreshJob extends ContextJob {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onShouldRetry(Throwable throwable) {
|
public boolean onShouldRetry(Exception throwable) {
|
||||||
if (throwable instanceof NonSuccessfulResponseCodeException) return false;
|
if (throwable instanceof NonSuccessfulResponseCodeException) return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -13,19 +13,19 @@ public abstract class MasterSecretJob extends ContextJob {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRun() throws Throwable {
|
public void onRun() throws Exception {
|
||||||
MasterSecret masterSecret = getMasterSecret();
|
MasterSecret masterSecret = getMasterSecret();
|
||||||
onRun(masterSecret);
|
onRun(masterSecret);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onShouldRetry(Throwable throwable) {
|
public boolean onShouldRetry(Exception exception) {
|
||||||
if (throwable instanceof RequirementNotMetException) return true;
|
if (exception instanceof RequirementNotMetException) return true;
|
||||||
return onShouldRetryThrowable(throwable);
|
return onShouldRetryThrowable(exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void onRun(MasterSecret masterSecret) throws Throwable;
|
public abstract void onRun(MasterSecret masterSecret) throws Exception;
|
||||||
public abstract boolean onShouldRetryThrowable(Throwable throwable);
|
public abstract boolean onShouldRetryThrowable(Exception exception);
|
||||||
|
|
||||||
private MasterSecret getMasterSecret() throws RequirementNotMetException {
|
private MasterSecret getMasterSecret() throws RequirementNotMetException {
|
||||||
MasterSecret masterSecret = KeyCachingService.getMasterSecret(context);
|
MasterSecret masterSecret = KeyCachingService.getMasterSecret(context);
|
||||||
|
@ -179,7 +179,7 @@ public class MmsDownloadJob extends MasterSecretJob {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onShouldRetryThrowable(Throwable throwable) {
|
public boolean onShouldRetryThrowable(Exception exception) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ public class MmsReceiveJob extends ContextJob {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onShouldRetry(Throwable throwable) {
|
public boolean onShouldRetry(Exception exception) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -84,7 +84,7 @@ public class MmsSendJob extends MasterSecretJob {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onShouldRetryThrowable(Throwable throwable) {
|
public boolean onShouldRetryThrowable(Exception exception) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,7 +78,7 @@ public class PushDecryptJob extends MasterSecretJob {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onShouldRetryThrowable(Throwable throwable) {
|
public boolean onShouldRetryThrowable(Exception exception) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,8 +97,8 @@ public class PushGroupSendJob extends PushSendJob implements InjectableType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onShouldRetryThrowable(Throwable throwable) {
|
public boolean onShouldRetryThrowable(Exception exception) {
|
||||||
if (throwable instanceof IOException) return true;
|
if (exception instanceof IOException) return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,8 +86,8 @@ public class PushMediaSendJob extends PushSendJob implements InjectableType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onShouldRetryThrowable(Throwable throwable) {
|
public boolean onShouldRetryThrowable(Exception exception) {
|
||||||
if (throwable instanceof RequirementNotMetException) return true;
|
if (exception instanceof RequirementNotMetException) return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ public class PushReceiveJob extends ContextJob {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onShouldRetry(Throwable throwable) {
|
public boolean onShouldRetry(Exception exception) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,8 +82,8 @@ public class PushTextSendJob extends PushSendJob implements InjectableType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onShouldRetryThrowable(Throwable throwable) {
|
public boolean onShouldRetryThrowable(Exception exception) {
|
||||||
if (throwable instanceof RetryLaterException) return true;
|
if (exception instanceof RetryLaterException) return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,6 @@ import org.thoughtcrime.securesms.crypto.MasterSecret;
|
|||||||
import org.thoughtcrime.securesms.crypto.PreKeyUtil;
|
import org.thoughtcrime.securesms.crypto.PreKeyUtil;
|
||||||
import org.thoughtcrime.securesms.dependencies.InjectableType;
|
import org.thoughtcrime.securesms.dependencies.InjectableType;
|
||||||
import org.thoughtcrime.securesms.jobs.requirements.MasterSecretRequirement;
|
import org.thoughtcrime.securesms.jobs.requirements.MasterSecretRequirement;
|
||||||
import org.thoughtcrime.securesms.push.TextSecureCommunicationFactory;
|
|
||||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||||
import org.whispersystems.jobqueue.JobParameters;
|
import org.whispersystems.jobqueue.JobParameters;
|
||||||
import org.whispersystems.jobqueue.requirements.NetworkRequirement;
|
import org.whispersystems.jobqueue.requirements.NetworkRequirement;
|
||||||
@ -17,7 +16,6 @@ import org.whispersystems.libaxolotl.IdentityKeyPair;
|
|||||||
import org.whispersystems.libaxolotl.state.PreKeyRecord;
|
import org.whispersystems.libaxolotl.state.PreKeyRecord;
|
||||||
import org.whispersystems.libaxolotl.state.SignedPreKeyRecord;
|
import org.whispersystems.libaxolotl.state.SignedPreKeyRecord;
|
||||||
import org.whispersystems.textsecure.api.TextSecureAccountManager;
|
import org.whispersystems.textsecure.api.TextSecureAccountManager;
|
||||||
import org.whispersystems.textsecure.push.PushServiceSocket;
|
|
||||||
import org.whispersystems.textsecure.push.exceptions.NonSuccessfulResponseCodeException;
|
import org.whispersystems.textsecure.push.exceptions.NonSuccessfulResponseCodeException;
|
||||||
import org.whispersystems.textsecure.push.exceptions.PushNetworkException;
|
import org.whispersystems.textsecure.push.exceptions.PushNetworkException;
|
||||||
|
|
||||||
@ -76,9 +74,9 @@ public class RefreshPreKeysJob extends MasterSecretJob implements InjectableType
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onShouldRetryThrowable(Throwable throwable) {
|
public boolean onShouldRetryThrowable(Exception exception) {
|
||||||
if (throwable instanceof NonSuccessfulResponseCodeException) return false;
|
if (exception instanceof NonSuccessfulResponseCodeException) return false;
|
||||||
if (throwable instanceof PushNetworkException) return true;
|
if (exception instanceof PushNetworkException) return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -5,15 +5,14 @@ import android.util.Log;
|
|||||||
|
|
||||||
import org.thoughtcrime.securesms.crypto.AsymmetricMasterCipher;
|
import org.thoughtcrime.securesms.crypto.AsymmetricMasterCipher;
|
||||||
import org.thoughtcrime.securesms.crypto.AsymmetricMasterSecret;
|
import org.thoughtcrime.securesms.crypto.AsymmetricMasterSecret;
|
||||||
import org.thoughtcrime.securesms.crypto.SecurityEvent;
|
|
||||||
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
||||||
import org.thoughtcrime.securesms.crypto.MasterSecretUtil;
|
import org.thoughtcrime.securesms.crypto.MasterSecretUtil;
|
||||||
|
import org.thoughtcrime.securesms.crypto.SecurityEvent;
|
||||||
import org.thoughtcrime.securesms.crypto.SmsCipher;
|
import org.thoughtcrime.securesms.crypto.SmsCipher;
|
||||||
import org.thoughtcrime.securesms.crypto.storage.TextSecureAxolotlStore;
|
import org.thoughtcrime.securesms.crypto.storage.TextSecureAxolotlStore;
|
||||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||||
import org.thoughtcrime.securesms.database.EncryptingSmsDatabase;
|
import org.thoughtcrime.securesms.database.EncryptingSmsDatabase;
|
||||||
import org.thoughtcrime.securesms.database.NoSuchMessageException;
|
import org.thoughtcrime.securesms.database.NoSuchMessageException;
|
||||||
import org.thoughtcrime.securesms.database.SmsDatabase;
|
|
||||||
import org.thoughtcrime.securesms.database.model.SmsMessageRecord;
|
import org.thoughtcrime.securesms.database.model.SmsMessageRecord;
|
||||||
import org.thoughtcrime.securesms.jobs.requirements.MasterSecretRequirement;
|
import org.thoughtcrime.securesms.jobs.requirements.MasterSecretRequirement;
|
||||||
import org.thoughtcrime.securesms.notifications.MessageNotifier;
|
import org.thoughtcrime.securesms.notifications.MessageNotifier;
|
||||||
@ -94,7 +93,7 @@ public class SmsDecryptJob extends MasterSecretJob {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onShouldRetryThrowable(Throwable throwable) {
|
public boolean onShouldRetryThrowable(Exception exception) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ public class SmsReceiveJob extends ContextJob {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onShouldRetry(Throwable throwable) {
|
public boolean onShouldRetry(Exception exception) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,7 +73,7 @@ public class SmsSendJob extends MasterSecretJob {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onShouldRetryThrowable(Throwable throwable) {
|
public boolean onShouldRetryThrowable(Exception throwable) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ public class SmsSentJob extends MasterSecretJob {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onShouldRetryThrowable(Throwable throwable) {
|
public boolean onShouldRetryThrowable(Exception throwable) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user