Initialize WorkManager ourself.

This gives us more control over when it happens, as well as lets us set
things like the debug level. Also let's us get rid of the synchronized
block we had in Application#onCreate().
This commit is contained in:
Greyson Parrelli 2018-10-04 09:09:04 -07:00
parent 4da1af9a7b
commit 07d7af6e75
3 changed files with 25 additions and 29 deletions

View File

@ -572,6 +572,12 @@
android:authorities="org.thoughtcrime.securesms.database.attachment"
android:exported="false" />
<provider
android:name="androidx.work.impl.WorkManagerInitializer"
android:authorities="${applicationId}.workmanager-init"
android:exported="false"
tools:node="remove" />
<receiver android:name=".service.BootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>

View File

@ -61,6 +61,7 @@ import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import androidx.work.Configuration;
import androidx.work.WorkManager;
import dagger.ObjectGraph;
@ -80,7 +81,6 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc
private JobManager jobManager;
private ObjectGraph objectGraph;
private PersistentLogger persistentLogger;
private boolean initialized;
private volatile boolean isAppVisible;
@ -90,33 +90,20 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc
@Override
public void onCreate() {
synchronized (this) {
super.onCreate();
initializeRandomNumberFix();
initializeLogging();
initializeCrashHandling();
initializeDependencyInjection();
initializeJobManager();
initializeExpiringMessageManager();
initializeGcmCheck();
initializeSignedPreKeyCheck();
initializePeriodicTasks();
initializeCircumvention();
initializeWebRtc();
NotificationChannels.create(this);
ProcessLifecycleOwner.get().getLifecycle().addObserver(this);
initialized = true;
notifyAll();
}
}
public void ensureInitialized() {
synchronized (this) {
while (!initialized) {
Util.wait(this, 0);
}
}
super.onCreate();
initializeRandomNumberFix();
initializeLogging();
initializeCrashHandling();
initializeDependencyInjection();
initializeJobManager();
initializeExpiringMessageManager();
initializeGcmCheck();
initializeSignedPreKeyCheck();
initializePeriodicTasks();
initializeCircumvention();
initializeWebRtc();
NotificationChannels.create(this);
ProcessLifecycleOwner.get().getLifecycle().addObserver(this);
}
@Override
@ -172,6 +159,10 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc
}
private void initializeJobManager() {
WorkManager.initialize(this, new Configuration.Builder()
.setMinimumLoggingLevel(android.util.Log.DEBUG)
.build());
this.jobManager = new JobManager(WorkManager.getInstance());
}

View File

@ -53,7 +53,6 @@ public abstract class Job extends Worker implements Serializable {
log("doWork()" + logSuffix());
ApplicationContext.getInstance(getApplicationContext()).ensureInitialized();
ApplicationContext.getInstance(getApplicationContext()).injectDependencies(this);
if (this instanceof ContextDependent) {