use of org.thoughtcrime.securesms.jobmanager.Data in project Signal-Android by WhisperSystems.
the class AttachmentUploadJob method onRun.
@Override
public void onRun() throws Exception {
if (!Recipient.self().isRegistered()) {
throw new NotPushRegisteredException();
}
Data inputData = getInputData();
ResumableUploadSpec resumableUploadSpec;
if (forceV2) {
Log.d(TAG, "Forcing utilization of V2");
resumableUploadSpec = null;
} else if (inputData != null && inputData.hasString(ResumableUploadSpecJob.KEY_RESUME_SPEC)) {
Log.d(TAG, "Using attachments V3");
resumableUploadSpec = ResumableUploadSpec.deserialize(inputData.getString(ResumableUploadSpecJob.KEY_RESUME_SPEC));
} else {
Log.d(TAG, "Using attachments V2");
resumableUploadSpec = null;
}
SignalServiceMessageSender messageSender = ApplicationDependencies.getSignalServiceMessageSender();
AttachmentDatabase database = SignalDatabase.attachments();
DatabaseAttachment databaseAttachment = database.getAttachment(attachmentId);
if (databaseAttachment == null) {
throw new InvalidAttachmentException("Cannot find the specified attachment.");
}
long timeSinceUpload = System.currentTimeMillis() - databaseAttachment.getUploadTimestamp();
if (timeSinceUpload < UPLOAD_REUSE_THRESHOLD && !TextUtils.isEmpty(databaseAttachment.getLocation())) {
Log.i(TAG, "We can re-use an already-uploaded file. It was uploaded " + timeSinceUpload + " ms ago. Skipping.");
return;
} else if (databaseAttachment.getUploadTimestamp() > 0) {
Log.i(TAG, "This file was previously-uploaded, but too long ago to be re-used. Age: " + timeSinceUpload + " ms");
}
Log.i(TAG, "Uploading attachment for message " + databaseAttachment.getMmsId() + " with ID " + databaseAttachment.getAttachmentId());
try (NotificationController notification = getNotificationForAttachment(databaseAttachment)) {
SignalServiceAttachment localAttachment = getAttachmentFor(databaseAttachment, notification, resumableUploadSpec);
SignalServiceAttachmentPointer remoteAttachment = messageSender.uploadAttachment(localAttachment.asStream());
Attachment attachment = PointerAttachment.forPointer(Optional.of(remoteAttachment), null, databaseAttachment.getFastPreflightId()).get();
database.updateAttachmentAfterUpload(databaseAttachment.getAttachmentId(), attachment, remoteAttachment.getUploadTimestamp());
} catch (NonSuccessfulResumableUploadResponseCodeException e) {
if (e.getCode() == 400) {
Log.w(TAG, "Failed to upload due to a 400 when getting resumable upload information. Downgrading to attachments v2", e);
forceV2 = true;
}
}
}
use of org.thoughtcrime.securesms.jobmanager.Data in project Signal-Android by WhisperSystems.
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 WhisperSystems.
the class RecipientIdJobMigration method migrateMultiDeviceVerifiedUpdateJob.
@NonNull
private JobData migrateMultiDeviceVerifiedUpdateJob(@NonNull JobData jobData) {
String address = jobData.getData().getString("destination");
Recipient recipient = Recipient.external(application, address);
Data updatedData = new Data.Builder().putString("destination", recipient.getId().serialize()).putString("identity_key", jobData.getData().getString("identity_key")).putInt("verified_status", jobData.getData().getInt("verified_status")).putLong("timestamp", jobData.getData().getLong("timestamp")).build();
return jobData.withData(updatedData);
}
use of org.thoughtcrime.securesms.jobmanager.Data in project Signal-Android by WhisperSystems.
the class RecipientIdJobMigration method migrateDirectoryRefreshJob.
@NonNull
private JobData migrateDirectoryRefreshJob(@NonNull JobData jobData) {
String address = jobData.getData().hasString("address") ? jobData.getData().getString("address") : null;
Recipient recipient = address != null ? Recipient.external(application, address) : null;
Data updatedData = new Data.Builder().putString("recipient", recipient != null ? recipient.getId().serialize() : null).putBoolean("notify_of_new_users", jobData.getData().getBoolean("notify_of_new_users")).build();
return jobData.withData(updatedData);
}
use of org.thoughtcrime.securesms.jobmanager.Data in project Signal-Android by WhisperSystems.
the class RecipientIdJobMigration method migrateMultiDeviceViewOnceOpenJob.
@NonNull
private JobData migrateMultiDeviceViewOnceOpenJob(@NonNull JobData jobData) {
try {
String rawOld = jobData.getData().getString("message_id");
OldSerializableSyncMessageId old = JsonUtils.fromJson(rawOld, OldSerializableSyncMessageId.class);
Recipient recipient = Recipient.external(application, old.sender);
NewSerializableSyncMessageId updated = new NewSerializableSyncMessageId(recipient.getId().serialize(), old.timestamp);
String rawUpdated = JsonUtils.toJson(updated);
Data updatedData = new Data.Builder().putString("message_id", rawUpdated).build();
return jobData.withData(updatedData);
} catch (IOException e) {
throw new AssertionError(e);
}
}
Aggregations