Ensure jobs have a Context during onAdded().

Fixes a crash.
This commit is contained in:
Greyson Parrelli 2018-10-20 22:52:14 -07:00
parent 0dd7b39bb1
commit ae9c53bdf8
3 changed files with 13 additions and 5 deletions

View File

@ -171,7 +171,7 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc
.setMinimumLoggingLevel(android.util.Log.DEBUG)
.build());
this.jobManager = new JobManager(WorkManager.getInstance());
this.jobManager = new JobManager(this, WorkManager.getInstance());
}
public void initializeMessageRetrieval() {

View File

@ -107,8 +107,13 @@ public abstract class Job extends Worker implements Serializable {
}
}
final void onSubmit(UUID id) {
final void onSubmit(@NonNull Context context, @NonNull UUID id) {
Log.i(TAG, buildLog(id, "onSubmit()"));
if (this instanceof ContextDependent) {
((ContextDependent) this).setContext(context);
}
onAdded();
}

View File

@ -1,5 +1,6 @@
package org.thoughtcrime.securesms.jobmanager;
import android.content.Context;
import android.support.annotation.NonNull;
import java.util.concurrent.Executor;
@ -22,10 +23,12 @@ public class JobManager {
private final Executor executor = Executors.newSingleThreadExecutor();
private final Context context;
private final WorkManager workManager;
public JobManager(@NonNull WorkManager workManager) {
this.workManager = workManager;
public JobManager(@NonNull Context context, @NonNull WorkManager workManager) {
this.context = context;
this.workManager = workManager;
}
public void add(Job job) {
@ -56,7 +59,7 @@ public class JobManager {
OneTimeWorkRequest request = requestBuilder.build();
job.onSubmit(request.getId());
job.onSubmit(context, request.getId());
String groupId = jobParameters.getGroupId();
if (groupId != null) {