use of org.thoughtcrime.securesms.jobmanager.Data in project Signal-Android by WhisperSystems.
the class RateLimitUtil method retryAllRateLimitedMessages.
/**
* Forces a retry of all rate limited messages by editing jobs that are in the queue.
*/
@WorkerThread
public static void retryAllRateLimitedMessages(@NonNull Context context) {
Set<Long> sms = SignalDatabase.sms().getAllRateLimitedMessageIds();
Set<Long> mms = SignalDatabase.mms().getAllRateLimitedMessageIds();
if (sms.isEmpty() && mms.isEmpty()) {
return;
}
Log.i(TAG, "Retrying " + sms.size() + " sms records and " + mms.size() + " mms records.");
SignalDatabase.sms().clearRateLimitStatus(sms);
SignalDatabase.mms().clearRateLimitStatus(mms);
ApplicationDependencies.getJobManager().update((job, serializer) -> {
Data data = serializer.deserialize(job.getSerializedData());
if (job.getFactoryKey().equals(PushTextSendJob.KEY) && sms.contains(PushTextSendJob.getMessageId(data))) {
return job.withNextRunAttemptTime(System.currentTimeMillis());
} else if (job.getFactoryKey().equals(PushMediaSendJob.KEY) && mms.contains(PushMediaSendJob.getMessageId(data))) {
return job.withNextRunAttemptTime(System.currentTimeMillis());
} else if (job.getFactoryKey().equals(PushGroupSendJob.KEY) && mms.contains(PushGroupSendJob.getMessageId(data))) {
return job.withNextRunAttemptTime(System.currentTimeMillis());
} else {
return job;
}
});
}
use of org.thoughtcrime.securesms.jobmanager.Data in project Signal-Android by signalapp.
the class RateLimitUtil method retryAllRateLimitedMessages.
/**
* Forces a retry of all rate limited messages by editing jobs that are in the queue.
*/
@WorkerThread
public static void retryAllRateLimitedMessages(@NonNull Context context) {
Set<Long> sms = SignalDatabase.sms().getAllRateLimitedMessageIds();
Set<Long> mms = SignalDatabase.mms().getAllRateLimitedMessageIds();
if (sms.isEmpty() && mms.isEmpty()) {
return;
}
Log.i(TAG, "Retrying " + sms.size() + " sms records and " + mms.size() + " mms records.");
SignalDatabase.sms().clearRateLimitStatus(sms);
SignalDatabase.mms().clearRateLimitStatus(mms);
ApplicationDependencies.getJobManager().update((job, serializer) -> {
Data data = serializer.deserialize(job.getSerializedData());
if (job.getFactoryKey().equals(PushTextSendJob.KEY) && sms.contains(PushTextSendJob.getMessageId(data))) {
return job.withNextRunAttemptTime(System.currentTimeMillis());
} else if (job.getFactoryKey().equals(PushMediaSendJob.KEY) && mms.contains(PushMediaSendJob.getMessageId(data))) {
return job.withNextRunAttemptTime(System.currentTimeMillis());
} else if (job.getFactoryKey().equals(PushGroupSendJob.KEY) && mms.contains(PushGroupSendJob.getMessageId(data))) {
return job.withNextRunAttemptTime(System.currentTimeMillis());
} else {
return job;
}
});
}
use of org.thoughtcrime.securesms.jobmanager.Data in project Signal-Android by signalapp.
the class DownloadLatestEmojiDataJob method clearOldEmojiData.
private static void clearOldEmojiData(@NonNull Context context, @Nullable EmojiFiles.Version newVersion) {
EmojiFiles.Version version = EmojiFiles.Version.readVersion(context);
final String currentDirectoryName;
final String newVersionDirectoryName;
if (version != null) {
currentDirectoryName = version.getUuid().toString();
} else {
currentDirectoryName = "";
}
if (newVersion != null) {
newVersionDirectoryName = newVersion.getUuid().toString();
} else {
newVersionDirectoryName = "";
}
File emojiDirectory = EmojiFiles.getBaseDirectory(context);
File[] files = emojiDirectory.listFiles();
if (files == null) {
Log.d(TAG, "No emoji data to delete.");
return;
}
Log.d(TAG, "Deleting old folders of emoji data");
Stream.of(files).filter(File::isDirectory).filterNot(file -> file.getName().equals(currentDirectoryName)).filterNot(file -> file.getName().equals(newVersionDirectoryName)).forEach(FileUtils::deleteDirectory);
EmojiPageCache.INSTANCE.clear();
if (version != null) {
SignalStore.emojiValues().clearJumboEmojiSheets(version.getVersion());
}
}
use of org.thoughtcrime.securesms.jobmanager.Data in project Signal-Android by signalapp.
the class DonationReceiptRedemptionJob method onRun.
@Override
protected void onRun() throws Exception {
Data inputData = getInputData();
if (inputData == null) {
Log.w(TAG, "No input data. Exiting.", null, true);
return;
}
byte[] presentationBytes = inputData.getStringAsBlob(INPUT_RECEIPT_CREDENTIAL_PRESENTATION);
if (presentationBytes == null) {
Log.d(TAG, "No response data. Exiting.", null, true);
return;
}
ReceiptCredentialPresentation presentation = new ReceiptCredentialPresentation(presentationBytes);
Log.d(TAG, "Attempting to redeem token... isForSubscription: " + isForSubscription(), true);
ServiceResponse<EmptyResponse> response = ApplicationDependencies.getDonationsService().redeemReceipt(presentation, SignalStore.donationsValues().getDisplayBadgesOnProfile(), false).blockingGet();
if (response.getApplicationError().isPresent()) {
if (response.getStatus() >= 500) {
Log.w(TAG, "Encountered a server exception " + response.getStatus(), response.getApplicationError().get(), true);
throw new RetryableException();
} else {
Log.w(TAG, "Encountered a non-recoverable exception " + response.getStatus(), response.getApplicationError().get(), true);
DonationError.routeDonationError(context, DonationError.genericBadgeRedemptionFailure(errorSource));
throw new IOException(response.getApplicationError().get());
}
} else if (response.getExecutionError().isPresent()) {
Log.w(TAG, "Encountered a retryable exception", response.getExecutionError().get(), true);
throw new RetryableException();
}
Log.i(TAG, "Successfully redeemed token with response code " + response.getStatus() + "... isForSubscription: " + isForSubscription(), true);
if (isForSubscription()) {
Log.d(TAG, "Clearing subscription failure", true);
SignalStore.donationsValues().clearSubscriptionRedemptionFailed();
}
}
use of org.thoughtcrime.securesms.jobmanager.Data in project Signal-Android by signalapp.
the class SendReadReceiptsJobMigration method migrateSendReadReceiptJob.
@NonNull
private static JobData migrateSendReadReceiptJob(@NonNull MmsSmsDatabase mmsSmsDatabase, @NonNull JobData jobData) {
Data data = jobData.getData();
if (!data.hasLong("thread")) {
long[] messageIds = jobData.getData().getLongArray("message_ids");
SortedSet<Long> threadIds = new TreeSet<>();
for (long id : messageIds) {
long threadForMessageId = mmsSmsDatabase.getThreadForMessageId(id);
if (id != -1) {
threadIds.add(threadForMessageId);
}
}
if (threadIds.size() != 1) {
return new JobData("FailingJob", null, new Data.Builder().build());
} else {
return jobData.withData(data.buildUpon().putLong("thread", threadIds.first()).build());
}
} else {
return jobData;
}
}
Aggregations