@Override
  public void onSend(MasterSecret masterSecret)
      throws MmsException, IOException, NoSuchMessageException {
    MmsDatabase database = DatabaseFactory.getMmsDatabase(context);
    SendReq message = database.getOutgoingMessage(masterSecret, messageId);

    try {
      deliver(masterSecret, message);

      database.markAsPush(messageId);
      database.markAsSecure(messageId);
      database.markAsSent(messageId, "push".getBytes(), 0);
    } catch (InvalidNumberException | RecipientFormattingException e) {
      Log.w(TAG, e);
      database.markAsSentFailed(messageId);
      notifyMediaMessageDeliveryFailed(context, messageId);
    } catch (EncapsulatedExceptions e) {
      Log.w(TAG, e);
      if (!e.getUnregisteredUserExceptions().isEmpty()) {
        database.markAsSentFailed(messageId);
      }

      for (UntrustedIdentityException uie : e.getUntrustedIdentityExceptions()) {
        IncomingIdentityUpdateMessage identityUpdateMessage =
            IncomingIdentityUpdateMessage.createFor(
                message.getTo()[0].getString(), uie.getIdentityKey());
        DatabaseFactory.getEncryptingSmsDatabase(context)
            .insertMessageInbox(masterSecret, identityUpdateMessage);
        database.markAsSentFailed(messageId);
      }

      notifyMediaMessageDeliveryFailed(context, messageId);
    }
  }
Exemple #2
0
  private void handleSendMessage(MasterSecret masterSecret, Intent intent) {
    long messageId = intent.getLongExtra("message_id", -1);
    UniversalTransport transport = new UniversalTransport(context, masterSecret);
    EncryptingSmsDatabase database = DatabaseFactory.getEncryptingSmsDatabase(context);

    EncryptingSmsDatabase.Reader reader = null;
    SmsMessageRecord record;

    Log.w("SmsSender", "Sending message: " + messageId);

    try {
      if (messageId != -1) reader = database.getMessage(masterSecret, messageId);
      else reader = database.getOutgoingMessages(masterSecret);

      while (reader != null && (record = reader.getNext()) != null) {
        try {
          database.markAsSending(record.getId());

          transport.deliver(record);
        } catch (UntrustedIdentityException e) {
          Log.w("SmsSender", e);
          IncomingIdentityUpdateMessage identityUpdateMessage =
              IncomingIdentityUpdateMessage.createFor(e.getE164Number(), e.getIdentityKey());
          DatabaseFactory.getEncryptingSmsDatabase(context)
              .insertMessageInbox(masterSecret, identityUpdateMessage);
          DatabaseFactory.getSmsDatabase(context).markAsSentFailed(messageId);
        } catch (UndeliverableMessageException ude) {
          Log.w("SmsSender", ude);
          DatabaseFactory.getSmsDatabase(context).markAsSentFailed(messageId);
        } catch (RetryLaterException rle) {
          Log.w("SmsSender", rle);
          if (systemStateListener.isConnected()) scheduleQuickRetryAlarm();
          else systemStateListener.registerForConnectivityChange();
        }
      }
    } finally {
      if (reader != null) reader.close();
    }
  }