mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-29 04:55:15 +00:00
42f1baaf61
We have to make some changes, and it's gotten to the point where maintaining it as a separate library is more hassle than it's worth, especially with Google releasing WorkManager as the preferred job scheduling library.
40 lines
1.2 KiB
Java
40 lines
1.2 KiB
Java
package org.thoughtcrime.securesms.jobs;
|
|
|
|
import android.content.Context;
|
|
|
|
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
|
import org.thoughtcrime.securesms.jobmanager.JobParameters;
|
|
import org.thoughtcrime.securesms.service.KeyCachingService;
|
|
|
|
public abstract class MasterSecretJob extends ContextJob {
|
|
|
|
public MasterSecretJob(Context context, JobParameters parameters) {
|
|
super(context, parameters);
|
|
}
|
|
|
|
@Override
|
|
public void onRun() throws Exception {
|
|
MasterSecret masterSecret = getMasterSecret();
|
|
onRun(masterSecret);
|
|
}
|
|
|
|
@Override
|
|
public boolean onShouldRetry(Exception exception) {
|
|
if (exception instanceof RequirementNotMetException) return true;
|
|
return onShouldRetryThrowable(exception);
|
|
}
|
|
|
|
public abstract void onRun(MasterSecret masterSecret) throws Exception;
|
|
public abstract boolean onShouldRetryThrowable(Exception exception);
|
|
|
|
private MasterSecret getMasterSecret() throws RequirementNotMetException {
|
|
MasterSecret masterSecret = KeyCachingService.getMasterSecret(context);
|
|
|
|
if (masterSecret == null) throw new RequirementNotMetException();
|
|
else return masterSecret;
|
|
}
|
|
|
|
protected static class RequirementNotMetException extends Exception {}
|
|
|
|
}
|