Search in sources :

Example 16 with InvalidNumberException

use of org.whispersystems.signalservice.api.util.InvalidNumberException in project Signal-Android by WhisperSystems.

the class PushGroupSendJob method onPushSend.

@Override
public void onPushSend(MasterSecret masterSecret) throws MmsException, IOException, NoSuchMessageException {
    MmsDatabase database = DatabaseFactory.getMmsDatabase(context);
    OutgoingMediaMessage message = database.getOutgoingMessage(masterSecret, messageId);
    try {
        deliver(masterSecret, message, filterRecipientId);
        database.markAsSent(messageId, true);
        markAttachmentsUploaded(messageId, message.getAttachments());
        if (message.getExpiresIn() > 0 && !message.isExpirationUpdate()) {
            database.markExpireStarted(messageId);
            ApplicationContext.getInstance(context).getExpiringMessageManager().scheduleDeletion(messageId, true, message.getExpiresIn());
        }
    } catch (InvalidNumberException | RecipientFormattingException | UndeliverableMessageException e) {
        Log.w(TAG, e);
        database.markAsSentFailed(messageId);
        notifyMediaMessageDeliveryFailed(context, messageId);
    } catch (EncapsulatedExceptions e) {
        Log.w(TAG, e);
        List<NetworkFailure> failures = new LinkedList<>();
        for (NetworkFailureException nfe : e.getNetworkExceptions()) {
            Recipient recipient = RecipientFactory.getRecipientsFromString(context, nfe.getE164number(), false).getPrimaryRecipient();
            failures.add(new NetworkFailure(recipient.getRecipientId()));
        }
        for (UntrustedIdentityException uie : e.getUntrustedIdentityExceptions()) {
            Recipient recipient = RecipientFactory.getRecipientsFromString(context, uie.getE164Number(), false).getPrimaryRecipient();
            database.addMismatchedIdentity(messageId, recipient.getRecipientId(), uie.getIdentityKey());
        }
        database.addFailures(messageId, failures);
        if (e.getNetworkExceptions().isEmpty() && e.getUntrustedIdentityExceptions().isEmpty()) {
            database.markAsSent(messageId, true);
            markAttachmentsUploaded(messageId, message.getAttachments());
        } else {
            database.markAsSentFailed(messageId);
            notifyMediaMessageDeliveryFailed(context, messageId);
        }
    }
}
Also used : EncapsulatedExceptions(org.whispersystems.signalservice.api.push.exceptions.EncapsulatedExceptions) UntrustedIdentityException(org.whispersystems.signalservice.api.crypto.UntrustedIdentityException) InvalidNumberException(org.whispersystems.signalservice.api.util.InvalidNumberException) OutgoingMediaMessage(org.thoughtcrime.securesms.mms.OutgoingMediaMessage) Recipient(org.thoughtcrime.securesms.recipients.Recipient) NetworkFailure(org.thoughtcrime.securesms.database.documents.NetworkFailure) UndeliverableMessageException(org.thoughtcrime.securesms.transport.UndeliverableMessageException) LinkedList(java.util.LinkedList) List(java.util.List) NetworkFailureException(org.whispersystems.signalservice.api.push.exceptions.NetworkFailureException) RecipientFormattingException(org.thoughtcrime.securesms.recipients.RecipientFormattingException) MmsDatabase(org.thoughtcrime.securesms.database.MmsDatabase)

Example 17 with InvalidNumberException

use of org.whispersystems.signalservice.api.util.InvalidNumberException in project Signal-Android by WhisperSystems.

the class PushMediaSendJob method deliver.

private void deliver(MasterSecret masterSecret, OutgoingMediaMessage message) throws RetryLaterException, InsecureFallbackApprovalException, UntrustedIdentityException, UndeliverableMessageException {
    if (message.getRecipients() == null || message.getRecipients().getPrimaryRecipient() == null || message.getRecipients().getPrimaryRecipient().getNumber() == null) {
        throw new UndeliverableMessageException("No destination address.");
    }
    SignalServiceMessageSender messageSender = messageSenderFactory.create();
    try {
        SignalServiceAddress address = getPushAddress(message.getRecipients().getPrimaryRecipient().getNumber());
        List<Attachment> scaledAttachments = scaleAttachments(masterSecret, MediaConstraints.PUSH_CONSTRAINTS, message.getAttachments());
        List<SignalServiceAttachment> attachmentStreams = getAttachmentsFor(masterSecret, scaledAttachments);
        SignalServiceDataMessage mediaMessage = SignalServiceDataMessage.newBuilder().withBody(message.getBody()).withAttachments(attachmentStreams).withTimestamp(message.getSentTimeMillis()).withExpiration((int) (message.getExpiresIn() / 1000)).asExpirationUpdate(message.isExpirationUpdate()).build();
        messageSender.sendMessage(address, mediaMessage);
    } catch (InvalidNumberException | UnregisteredUserException e) {
        Log.w(TAG, e);
        throw new InsecureFallbackApprovalException(e);
    } catch (FileNotFoundException e) {
        Log.w(TAG, e);
        throw new UndeliverableMessageException(e);
    } catch (IOException e) {
        Log.w(TAG, e);
        throw new RetryLaterException(e);
    }
}
Also used : UnregisteredUserException(org.whispersystems.signalservice.api.push.exceptions.UnregisteredUserException) InvalidNumberException(org.whispersystems.signalservice.api.util.InvalidNumberException) FileNotFoundException(java.io.FileNotFoundException) SignalServiceMessageSender(org.whispersystems.signalservice.api.SignalServiceMessageSender) SignalServiceAttachment(org.whispersystems.signalservice.api.messages.SignalServiceAttachment) Attachment(org.thoughtcrime.securesms.attachments.Attachment) IOException(java.io.IOException) InsecureFallbackApprovalException(org.thoughtcrime.securesms.transport.InsecureFallbackApprovalException) SignalServiceAttachment(org.whispersystems.signalservice.api.messages.SignalServiceAttachment) SignalServiceDataMessage(org.whispersystems.signalservice.api.messages.SignalServiceDataMessage) UndeliverableMessageException(org.thoughtcrime.securesms.transport.UndeliverableMessageException) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) RetryLaterException(org.thoughtcrime.securesms.transport.RetryLaterException)

Example 18 with InvalidNumberException

use of org.whispersystems.signalservice.api.util.InvalidNumberException in project Signal-Android by WhisperSystems.

the class PushTextSendJob method deliver.

private void deliver(SmsMessageRecord message) throws UntrustedIdentityException, InsecureFallbackApprovalException, RetryLaterException {
    try {
        SignalServiceAddress address = getPushAddress(message.getIndividualRecipient().getNumber());
        SignalServiceMessageSender messageSender = messageSenderFactory.create();
        SignalServiceDataMessage textSecureMessage = SignalServiceDataMessage.newBuilder().withTimestamp(message.getDateSent()).withBody(message.getBody().getBody()).withExpiration((int) (message.getExpiresIn() / 1000)).asEndSessionMessage(message.isEndSession()).build();
        messageSender.sendMessage(address, textSecureMessage);
    } catch (InvalidNumberException | UnregisteredUserException e) {
        Log.w(TAG, e);
        throw new InsecureFallbackApprovalException(e);
    } catch (IOException e) {
        Log.w(TAG, e);
        throw new RetryLaterException(e);
    }
}
Also used : SignalServiceDataMessage(org.whispersystems.signalservice.api.messages.SignalServiceDataMessage) UnregisteredUserException(org.whispersystems.signalservice.api.push.exceptions.UnregisteredUserException) InvalidNumberException(org.whispersystems.signalservice.api.util.InvalidNumberException) SignalServiceMessageSender(org.whispersystems.signalservice.api.SignalServiceMessageSender) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) RetryLaterException(org.thoughtcrime.securesms.transport.RetryLaterException) IOException(java.io.IOException) InsecureFallbackApprovalException(org.thoughtcrime.securesms.transport.InsecureFallbackApprovalException)

Example 19 with InvalidNumberException

use of org.whispersystems.signalservice.api.util.InvalidNumberException in project Signal-Android by WhisperSystems.

the class DirectoryHelper method refreshDirectoryFor.

public static UserCapabilities refreshDirectoryFor(@NonNull Context context, @Nullable MasterSecret masterSecret, @NonNull Recipients recipients, @NonNull String localNumber) throws IOException {
    try {
        TextSecureDirectory directory = TextSecureDirectory.getInstance(context);
        SignalServiceAccountManager accountManager = AccountManagerFactory.createManager(context);
        String number = Util.canonicalizeNumber(context, recipients.getPrimaryRecipient().getNumber());
        Optional<ContactTokenDetails> details = accountManager.getContact(number);
        if (details.isPresent()) {
            directory.setNumber(details.get(), true);
            RefreshResult result = updateContactsDatabase(context, localNumber, details.get());
            if (!result.getNewUsers().isEmpty() && TextSecurePreferences.isMultiDevice(context)) {
                ApplicationContext.getInstance(context).getJobManager().add(new MultiDeviceContactUpdateJob(context));
            }
            if (!result.isFresh()) {
                notifyNewUsers(context, masterSecret, result.getNewUsers());
            }
            return new UserCapabilities(Capability.SUPPORTED, details.get().isVoice() ? Capability.SUPPORTED : Capability.UNSUPPORTED, details.get().isVideo() ? Capability.SUPPORTED : Capability.UNSUPPORTED);
        } else {
            ContactTokenDetails absent = new ContactTokenDetails();
            absent.setNumber(number);
            directory.setNumber(absent, false);
            return UserCapabilities.UNSUPPORTED;
        }
    } catch (InvalidNumberException e) {
        Log.w(TAG, e);
        return UserCapabilities.UNSUPPORTED;
    }
}
Also used : MultiDeviceContactUpdateJob(org.thoughtcrime.securesms.jobs.MultiDeviceContactUpdateJob) InvalidNumberException(org.whispersystems.signalservice.api.util.InvalidNumberException) SignalServiceAccountManager(org.whispersystems.signalservice.api.SignalServiceAccountManager) ContactTokenDetails(org.whispersystems.signalservice.api.push.ContactTokenDetails) TextSecureDirectory(org.thoughtcrime.securesms.database.TextSecureDirectory)

Example 20 with InvalidNumberException

use of org.whispersystems.signalservice.api.util.InvalidNumberException in project Signal-Android by WhisperSystems.

the class WebRtcCallService method sendMessage.

private ListenableFutureTask<Boolean> sendMessage(@NonNull final Recipient recipient, @NonNull final SignalServiceCallMessage callMessage) {
    Callable<Boolean> callable = new Callable<Boolean>() {

        @Override
        public Boolean call() throws Exception {
            try {
                String number = Util.canonicalizeNumber(WebRtcCallService.this, recipient.getNumber());
                messageSender.sendCallMessage(new SignalServiceAddress(number), callMessage);
                return true;
            } catch (InvalidNumberException e) {
                throw new IOException(e);
            }
        }
    };
    ListenableFutureTask<Boolean> listenableFutureTask = new ListenableFutureTask<>(callable, null, serviceExecutor);
    networkExecutor.execute(listenableFutureTask);
    return listenableFutureTask;
}
Also used : ListenableFutureTask(org.thoughtcrime.securesms.util.ListenableFutureTask) InvalidNumberException(org.whispersystems.signalservice.api.util.InvalidNumberException) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) IOException(java.io.IOException) Callable(java.util.concurrent.Callable)

Aggregations

InvalidNumberException (org.whispersystems.signalservice.api.util.InvalidNumberException)20 Cursor (android.database.Cursor)7 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)6 Recipient (org.thoughtcrime.securesms.recipients.Recipient)5 SignalServiceMessageSender (org.whispersystems.signalservice.api.SignalServiceMessageSender)5 ContentValues (android.content.ContentValues)4 Uri (android.net.Uri)4 LinkedList (java.util.LinkedList)4 IOException (java.io.IOException)3 SignalServiceAddress (org.whispersystems.signalservice.api.push.SignalServiceAddress)3 Pair (android.util.Pair)2 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 TrimThreadJob (org.thoughtcrime.securesms.jobs.TrimThreadJob)2 InsecureFallbackApprovalException (org.thoughtcrime.securesms.transport.InsecureFallbackApprovalException)2 RetryLaterException (org.thoughtcrime.securesms.transport.RetryLaterException)2 UndeliverableMessageException (org.thoughtcrime.securesms.transport.UndeliverableMessageException)2 SignalServiceDataMessage (org.whispersystems.signalservice.api.messages.SignalServiceDataMessage)2 DeviceContact (org.whispersystems.signalservice.api.messages.multidevice.DeviceContact)2 DeviceContactsOutputStream (org.whispersystems.signalservice.api.messages.multidevice.DeviceContactsOutputStream)2