2014-11-03 23:16:04 +00:00
|
|
|
package org.thoughtcrime.securesms.jobs;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
|
|
|
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
|
|
|
import org.thoughtcrime.securesms.service.KeyCachingService;
|
|
|
|
import org.whispersystems.jobqueue.JobParameters;
|
|
|
|
|
|
|
|
public abstract class MasterSecretJob extends ContextJob {
|
|
|
|
|
|
|
|
public MasterSecretJob(Context context, JobParameters parameters) {
|
|
|
|
super(context, parameters);
|
|
|
|
}
|
|
|
|
|
2014-11-12 03:57:53 +00:00
|
|
|
@Override
|
2014-11-12 05:11:57 +00:00
|
|
|
public void onRun() throws Exception {
|
2014-11-12 03:57:53 +00:00
|
|
|
MasterSecret masterSecret = getMasterSecret();
|
|
|
|
onRun(masterSecret);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-11-12 05:11:57 +00:00
|
|
|
public boolean onShouldRetry(Exception exception) {
|
|
|
|
if (exception instanceof RequirementNotMetException) return true;
|
|
|
|
return onShouldRetryThrowable(exception);
|
2014-11-12 03:57:53 +00:00
|
|
|
}
|
|
|
|
|
2014-11-12 05:11:57 +00:00
|
|
|
public abstract void onRun(MasterSecret masterSecret) throws Exception;
|
|
|
|
public abstract boolean onShouldRetryThrowable(Exception exception);
|
2014-11-12 03:57:53 +00:00
|
|
|
|
|
|
|
private MasterSecret getMasterSecret() throws RequirementNotMetException {
|
2014-11-03 23:16:04 +00:00
|
|
|
MasterSecret masterSecret = KeyCachingService.getMasterSecret(context);
|
|
|
|
|
|
|
|
if (masterSecret == null) throw new RequirementNotMetException();
|
|
|
|
else return masterSecret;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected static class RequirementNotMetException extends Exception {}
|
|
|
|
|
|
|
|
}
|