Let's have JobManager only deal with checked exceptions.

Also, switch to Builder for JobManager construction.
This commit is contained in:
Moxie Marlinspike
2014-11-11 21:11:57 -08:00
parent d9d4ec9d9d
commit 0d06d50a65
32 changed files with 180 additions and 94 deletions

View File

@@ -77,8 +77,8 @@ public class AttachmentDownloadJob extends MasterSecretJob implements Injectable
}
@Override
public boolean onShouldRetryThrowable(Throwable throwable) {
if (throwable instanceof PushNetworkException) return true;
public boolean onShouldRetryThrowable(Exception exception) {
if (exception instanceof PushNetworkException) return true;
return false;
}

View File

@@ -91,8 +91,8 @@ public class AvatarDownloadJob extends MasterSecretJob {
public void onCanceled() {}
@Override
public boolean onShouldRetryThrowable(Throwable throwable) {
if (throwable instanceof IOException) return true;
public boolean onShouldRetryThrowable(Exception exception) {
if (exception instanceof IOException) return true;
return false;
}

View File

@@ -84,7 +84,7 @@ public class CleanPreKeysJob extends MasterSecretJob implements InjectableType {
}
@Override
public boolean onShouldRetryThrowable(Throwable throwable) {
public boolean onShouldRetryThrowable(Exception throwable) {
if (throwable instanceof NonSuccessfulResponseCodeException) return false;
if (throwable instanceof PushNetworkException) return true;
return false;

View File

@@ -7,7 +7,6 @@ import org.thoughtcrime.securesms.crypto.IdentityKeyUtil;
import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.thoughtcrime.securesms.crypto.PreKeyUtil;
import org.thoughtcrime.securesms.dependencies.InjectableType;
import org.thoughtcrime.securesms.push.TextSecureCommunicationFactory;
import org.thoughtcrime.securesms.util.ParcelUtil;
import org.thoughtcrime.securesms.util.TextSecurePreferences;
import org.whispersystems.jobqueue.EncryptionKeys;
@@ -60,8 +59,8 @@ public class CreateSignedPreKeyJob extends ContextJob implements InjectableType
public void onCanceled() {}
@Override
public boolean onShouldRetry(Throwable throwable) {
if (throwable instanceof PushNetworkException) return true;
public boolean onShouldRetry(Exception exception) {
if (exception instanceof PushNetworkException) return true;
return false;
}
}

View File

@@ -62,10 +62,10 @@ public class DeliveryReceiptJob extends ContextJob implements InjectableType {
}
@Override
public boolean onShouldRetry(Throwable throwable) {
Log.w(TAG, throwable);
if (throwable instanceof NonSuccessfulResponseCodeException) return false;
if (throwable instanceof PushNetworkException) return true;
public boolean onShouldRetry(Exception exception) {
Log.w(TAG, exception);
if (exception instanceof NonSuccessfulResponseCodeException) return false;
if (exception instanceof PushNetworkException) return true;
return false;
}

View File

@@ -56,7 +56,7 @@ public class GcmRefreshJob extends ContextJob {
}
@Override
public boolean onShouldRetry(Throwable throwable) {
public boolean onShouldRetry(Exception throwable) {
if (throwable instanceof NonSuccessfulResponseCodeException) return false;
return true;
}

View File

@@ -13,19 +13,19 @@ public abstract class MasterSecretJob extends ContextJob {
}
@Override
public void onRun() throws Throwable {
public void onRun() throws Exception {
MasterSecret masterSecret = getMasterSecret();
onRun(masterSecret);
}
@Override
public boolean onShouldRetry(Throwable throwable) {
if (throwable instanceof RequirementNotMetException) return true;
return onShouldRetryThrowable(throwable);
public boolean onShouldRetry(Exception exception) {
if (exception instanceof RequirementNotMetException) return true;
return onShouldRetryThrowable(exception);
}
public abstract void onRun(MasterSecret masterSecret) throws Throwable;
public abstract boolean onShouldRetryThrowable(Throwable throwable);
public abstract void onRun(MasterSecret masterSecret) throws Exception;
public abstract boolean onShouldRetryThrowable(Exception exception);
private MasterSecret getMasterSecret() throws RequirementNotMetException {
MasterSecret masterSecret = KeyCachingService.getMasterSecret(context);

View File

@@ -179,7 +179,7 @@ public class MmsDownloadJob extends MasterSecretJob {
}
@Override
public boolean onShouldRetryThrowable(Throwable throwable) {
public boolean onShouldRetryThrowable(Exception exception) {
return false;
}

View File

@@ -63,7 +63,7 @@ public class MmsReceiveJob extends ContextJob {
}
@Override
public boolean onShouldRetry(Throwable throwable) {
public boolean onShouldRetry(Exception exception) {
return false;
}
}

View File

@@ -84,7 +84,7 @@ public class MmsSendJob extends MasterSecretJob {
}
@Override
public boolean onShouldRetryThrowable(Throwable throwable) {
public boolean onShouldRetryThrowable(Exception exception) {
return false;
}

View File

@@ -78,7 +78,7 @@ public class PushDecryptJob extends MasterSecretJob {
}
@Override
public boolean onShouldRetryThrowable(Throwable throwable) {
public boolean onShouldRetryThrowable(Exception exception) {
return false;
}

View File

@@ -97,8 +97,8 @@ public class PushGroupSendJob extends PushSendJob implements InjectableType {
}
@Override
public boolean onShouldRetryThrowable(Throwable throwable) {
if (throwable instanceof IOException) return true;
public boolean onShouldRetryThrowable(Exception exception) {
if (exception instanceof IOException) return true;
return false;
}

View File

@@ -86,8 +86,8 @@ public class PushMediaSendJob extends PushSendJob implements InjectableType {
}
@Override
public boolean onShouldRetryThrowable(Throwable throwable) {
if (throwable instanceof RequirementNotMetException) return true;
public boolean onShouldRetryThrowable(Exception exception) {
if (exception instanceof RequirementNotMetException) return true;
return false;
}

View File

@@ -60,7 +60,7 @@ public class PushReceiveJob extends ContextJob {
}
@Override
public boolean onShouldRetry(Throwable throwable) {
public boolean onShouldRetry(Exception exception) {
return false;
}

View File

@@ -82,8 +82,8 @@ public class PushTextSendJob extends PushSendJob implements InjectableType {
}
@Override
public boolean onShouldRetryThrowable(Throwable throwable) {
if (throwable instanceof RetryLaterException) return true;
public boolean onShouldRetryThrowable(Exception exception) {
if (exception instanceof RetryLaterException) return true;
return false;
}

View File

@@ -9,7 +9,6 @@ import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.thoughtcrime.securesms.crypto.PreKeyUtil;
import org.thoughtcrime.securesms.dependencies.InjectableType;
import org.thoughtcrime.securesms.jobs.requirements.MasterSecretRequirement;
import org.thoughtcrime.securesms.push.TextSecureCommunicationFactory;
import org.thoughtcrime.securesms.util.TextSecurePreferences;
import org.whispersystems.jobqueue.JobParameters;
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.SignedPreKeyRecord;
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.PushNetworkException;
@@ -76,9 +74,9 @@ public class RefreshPreKeysJob extends MasterSecretJob implements InjectableType
}
@Override
public boolean onShouldRetryThrowable(Throwable throwable) {
if (throwable instanceof NonSuccessfulResponseCodeException) return false;
if (throwable instanceof PushNetworkException) return true;
public boolean onShouldRetryThrowable(Exception exception) {
if (exception instanceof NonSuccessfulResponseCodeException) return false;
if (exception instanceof PushNetworkException) return true;
return false;
}

View File

@@ -5,15 +5,14 @@ import android.util.Log;
import org.thoughtcrime.securesms.crypto.AsymmetricMasterCipher;
import org.thoughtcrime.securesms.crypto.AsymmetricMasterSecret;
import org.thoughtcrime.securesms.crypto.SecurityEvent;
import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.thoughtcrime.securesms.crypto.MasterSecretUtil;
import org.thoughtcrime.securesms.crypto.SecurityEvent;
import org.thoughtcrime.securesms.crypto.SmsCipher;
import org.thoughtcrime.securesms.crypto.storage.TextSecureAxolotlStore;
import org.thoughtcrime.securesms.database.DatabaseFactory;
import org.thoughtcrime.securesms.database.EncryptingSmsDatabase;
import org.thoughtcrime.securesms.database.NoSuchMessageException;
import org.thoughtcrime.securesms.database.SmsDatabase;
import org.thoughtcrime.securesms.database.model.SmsMessageRecord;
import org.thoughtcrime.securesms.jobs.requirements.MasterSecretRequirement;
import org.thoughtcrime.securesms.notifications.MessageNotifier;
@@ -94,7 +93,7 @@ public class SmsDecryptJob extends MasterSecretJob {
}
@Override
public boolean onShouldRetryThrowable(Throwable throwable) {
public boolean onShouldRetryThrowable(Exception exception) {
return false;
}

View File

@@ -55,7 +55,7 @@ public class SmsReceiveJob extends ContextJob {
}
@Override
public boolean onShouldRetry(Throwable throwable) {
public boolean onShouldRetry(Exception exception) {
return false;
}

View File

@@ -73,7 +73,7 @@ public class SmsSendJob extends MasterSecretJob {
}
@Override
public boolean onShouldRetryThrowable(Throwable throwable) {
public boolean onShouldRetryThrowable(Exception throwable) {
return false;
}

View File

@@ -58,7 +58,7 @@ public class SmsSentJob extends MasterSecretJob {
}
@Override
public boolean onShouldRetryThrowable(Throwable throwable) {
public boolean onShouldRetryThrowable(Exception throwable) {
return false;
}