use of org.thoughtcrime.securesms.net.NotPushRegisteredException in project Signal-Android by signalapp.
the class MultiDeviceStickerPackSyncJob method onRun.
@Override
protected void onRun() throws Exception {
if (!Recipient.self().isRegistered()) {
throw new NotPushRegisteredException();
}
if (!TextSecurePreferences.isMultiDevice(context)) {
Log.i(TAG, "Not multi device, aborting...");
return;
}
List<StickerPackOperationMessage> operations = new LinkedList<>();
try (StickerPackRecordReader reader = new StickerPackRecordReader(SignalDatabase.stickers().getInstalledStickerPacks())) {
StickerPackRecord pack;
while ((pack = reader.getNext()) != null) {
byte[] packIdBytes = Hex.fromStringCondensed(pack.getPackId());
byte[] packKeyBytes = Hex.fromStringCondensed(pack.getPackKey());
operations.add(new StickerPackOperationMessage(packIdBytes, packKeyBytes, StickerPackOperationMessage.Type.INSTALL));
}
}
SignalServiceMessageSender messageSender = ApplicationDependencies.getSignalServiceMessageSender();
messageSender.sendSyncMessage(SignalServiceSyncMessage.forStickerPackOperations(operations), UnidentifiedAccessUtil.getAccessForSync(context));
}
use of org.thoughtcrime.securesms.net.NotPushRegisteredException in project Signal-Android by signalapp.
the class MultiDeviceVerifiedUpdateJob method onRun.
@Override
public void onRun() throws IOException, UntrustedIdentityException {
if (!Recipient.self().isRegistered()) {
throw new NotPushRegisteredException();
}
try {
if (!TextSecurePreferences.isMultiDevice(context)) {
Log.i(TAG, "Not multi device...");
return;
}
if (destination == null) {
Log.w(TAG, "No destination...");
return;
}
SignalServiceMessageSender messageSender = ApplicationDependencies.getSignalServiceMessageSender();
Recipient recipient = Recipient.resolved(destination);
if (recipient.isUnregistered()) {
Log.w(TAG, recipient.getId() + " not registered!");
return;
}
VerifiedMessage.VerifiedState verifiedState = getVerifiedState(verifiedStatus);
SignalServiceAddress verifiedAddress = RecipientUtil.toSignalServiceAddress(context, recipient);
VerifiedMessage verifiedMessage = new VerifiedMessage(verifiedAddress, new IdentityKey(identityKey, 0), verifiedState, timestamp);
messageSender.sendSyncMessage(SignalServiceSyncMessage.forVerified(verifiedMessage), UnidentifiedAccessUtil.getAccessFor(context, recipient));
} catch (InvalidKeyException e) {
throw new IOException(e);
}
}
use of org.thoughtcrime.securesms.net.NotPushRegisteredException in project Signal-Android by signalapp.
the class PaymentSendJob method onRun.
@Override
protected void onRun() throws Exception {
if (!Recipient.self().isRegistered()) {
throw new NotPushRegisteredException();
}
if (!SignalStore.paymentsValues().mobileCoinPaymentsEnabled()) {
Log.w(TAG, "Payments are not enabled");
return;
}
Stopwatch stopwatch = new Stopwatch("Payment submission");
Wallet wallet = ApplicationDependencies.getPayments().getWallet();
PaymentDatabase paymentDatabase = SignalDatabase.payments();
paymentDatabase.createOutgoingPayment(uuid, recipientId, publicAddress, timestamp, note, amount);
Log.i(TAG, "Payment record created " + uuid);
stopwatch.split("Record created");
try {
PaymentSubmissionResult paymentSubmissionResult = wallet.sendPayment(publicAddress, amount.requireMobileCoin(), totalFee.requireMobileCoin());
stopwatch.split("Payment submitted");
if (paymentSubmissionResult.containsDefrags()) {
Log.i(TAG, "Payment contains " + paymentSubmissionResult.defrags().size() + " defrags, main payment" + uuid);
RecipientId self = Recipient.self().getId();
MobileCoinPublicAddress selfAddress = wallet.getMobileCoinPublicAddress();
for (TransactionSubmissionResult defrag : paymentSubmissionResult.defrags()) {
UUID defragUuid = UUID.randomUUID();
PaymentTransactionId.MobileCoin mobileCoinTransaction = (PaymentTransactionId.MobileCoin) defrag.getTransactionId();
paymentDatabase.createDefrag(defragUuid, self, selfAddress, timestamp - 1, mobileCoinTransaction.getFee(), mobileCoinTransaction.getTransaction(), mobileCoinTransaction.getReceipt());
Log.i(TAG, "Defrag entered with id " + defragUuid);
ApplicationDependencies.getJobManager().startChain(new PaymentTransactionCheckJob(defragUuid, QUEUE)).then(new MultiDeviceOutgoingPaymentSyncJob(defragUuid)).enqueue();
}
stopwatch.split("Defrag");
}
TransactionSubmissionResult.ErrorCode errorCode = paymentSubmissionResult.getErrorCode();
switch(errorCode) {
case INSUFFICIENT_FUNDS:
paymentDatabase.markPaymentFailed(uuid, FailureReason.INSUFFICIENT_FUNDS);
throw new PaymentException("Payment failed due to " + errorCode);
case GENERIC_FAILURE:
paymentDatabase.markPaymentFailed(uuid, FailureReason.UNKNOWN);
throw new PaymentException("Payment failed due to " + errorCode);
case NETWORK_FAILURE:
paymentDatabase.markPaymentFailed(uuid, FailureReason.NETWORK);
throw new PaymentException("Payment failed due to " + errorCode);
case NONE:
Log.i(TAG, "Payment submission complete");
TransactionSubmissionResult transactionSubmissionResult = Objects.requireNonNull(paymentSubmissionResult.getNonDefrag());
PaymentTransactionId.MobileCoin mobileCoinTransaction = (PaymentTransactionId.MobileCoin) transactionSubmissionResult.getTransactionId();
paymentDatabase.markPaymentSubmitted(uuid, mobileCoinTransaction.getTransaction(), mobileCoinTransaction.getReceipt(), mobileCoinTransaction.getFee());
Log.i(TAG, "Payment record updated " + uuid);
break;
}
} catch (Exception e) {
Log.w(TAG, "Unknown payment failure", e);
paymentDatabase.markPaymentFailed(uuid, FailureReason.UNKNOWN);
throw e;
}
stopwatch.split("Update database record");
stopwatch.stop(TAG);
}
use of org.thoughtcrime.securesms.net.NotPushRegisteredException in project Signal-Android by signalapp.
the class MultiDeviceConfigurationUpdateJob method onRun.
@Override
public void onRun() throws IOException, UntrustedIdentityException {
if (!Recipient.self().isRegistered()) {
throw new NotPushRegisteredException();
}
if (!TextSecurePreferences.isMultiDevice(context)) {
Log.i(TAG, "Not multi device, aborting...");
return;
}
if (SignalStore.account().isLinkedDevice()) {
Log.i(TAG, "Not primary device, aborting...");
return;
}
SignalServiceMessageSender messageSender = ApplicationDependencies.getSignalServiceMessageSender();
messageSender.sendSyncMessage(SignalServiceSyncMessage.forConfiguration(new ConfigurationMessage(Optional.of(readReceiptsEnabled), Optional.of(unidentifiedDeliveryIndicatorsEnabled), Optional.of(typingIndicatorsEnabled), Optional.of(linkPreviewsEnabled))), UnidentifiedAccessUtil.getAccessForSync(context));
}
use of org.thoughtcrime.securesms.net.NotPushRegisteredException in project Signal-Android by signalapp.
the class MultiDeviceGroupUpdateJob method onRun.
@Override
public void onRun() throws Exception {
if (!Recipient.self().isRegistered()) {
throw new NotPushRegisteredException();
}
if (!TextSecurePreferences.isMultiDevice(context)) {
Log.i(TAG, "Not multi device, aborting...");
return;
}
if (SignalStore.account().isLinkedDevice()) {
Log.i(TAG, "Not primary device, aborting...");
return;
}
ParcelFileDescriptor[] pipe = ParcelFileDescriptor.createPipe();
InputStream inputStream = new ParcelFileDescriptor.AutoCloseInputStream(pipe[0]);
Uri uri = BlobProvider.getInstance().forData(inputStream, 0).withFileName("multidevice-group-update").createForSingleSessionOnDiskAsync(context, () -> Log.i(TAG, "Write successful."), e -> Log.w(TAG, "Error during write.", e));
try (GroupDatabase.Reader reader = SignalDatabase.groups().getGroups()) {
DeviceGroupsOutputStream out = new DeviceGroupsOutputStream(new ParcelFileDescriptor.AutoCloseOutputStream(pipe[1]));
boolean hasData = false;
GroupDatabase.GroupRecord record;
while ((record = reader.getNext()) != null) {
if (record.isV1Group()) {
List<SignalServiceAddress> members = new LinkedList<>();
List<Recipient> registeredMembers = RecipientUtil.getEligibleForSending(Recipient.resolvedList(record.getMembers()));
for (Recipient member : registeredMembers) {
members.add(RecipientUtil.toSignalServiceAddress(context, member));
}
RecipientId recipientId = SignalDatabase.recipients().getOrInsertFromPossiblyMigratedGroupId(record.getId());
Recipient recipient = Recipient.resolved(recipientId);
Optional<Integer> expirationTimer = recipient.getExpiresInSeconds() > 0 ? Optional.of(recipient.getExpiresInSeconds()) : Optional.absent();
Map<RecipientId, Integer> inboxPositions = SignalDatabase.threads().getInboxPositions();
Set<RecipientId> archived = SignalDatabase.threads().getArchivedRecipients();
out.write(new DeviceGroup(record.getId().getDecodedId(), Optional.fromNullable(record.getTitle()), members, getAvatar(record.getRecipientId()), record.isActive(), expirationTimer, Optional.of(ChatColorsMapper.getMaterialColor(recipient.getChatColors()).serialize()), recipient.isBlocked(), Optional.fromNullable(inboxPositions.get(recipientId)), archived.contains(recipientId)));
hasData = true;
}
}
out.close();
if (hasData) {
long length = BlobProvider.getInstance().calculateFileSize(context, uri);
sendUpdate(ApplicationDependencies.getSignalServiceMessageSender(), BlobProvider.getInstance().getStream(context, uri), length);
} else {
Log.w(TAG, "No groups present for sync message. Sending an empty update.");
sendUpdate(ApplicationDependencies.getSignalServiceMessageSender(), null, 0);
}
} finally {
BlobProvider.getInstance().delete(context, uri);
}
}
Aggregations