예제 #1
0
  private void deliverSecureMessage(MasterSecret masterSecret, SmsMessageRecord message)
      throws UndeliverableMessageException, InsecureFallbackApprovalException {
    MultipartSmsMessageHandler multipartMessageHandler = new MultipartSmsMessageHandler();
    OutgoingTextMessage transportMessage = OutgoingTextMessage.from(message);

    if (message.isSecure() || message.isEndSession()) {
      transportMessage = getAsymmetricEncrypt(masterSecret, transportMessage);
    }

    ArrayList<String> messages = multipartMessageHandler.divideMessage(transportMessage);
    ArrayList<PendingIntent> sentIntents =
        constructSentIntents(message.getId(), message.getType(), messages, message.isSecure());
    ArrayList<PendingIntent> deliveredIntents =
        constructDeliveredIntents(message.getId(), message.getType(), messages);

    Log.w("SmsTransport", "Secure divide into message parts: " + messages.size());

    for (int i = 0; i < messages.size(); i++) {
      // NOTE 11/04/14 -- There's apparently a bug where for some unknown recipients
      // and messages, this will throw an NPE.  We have no idea why, so we're just
      // catching it and marking the message as a failure.  That way at least it
      // doesn't repeatedly crash every time you start the app.
      try {
        SmsManager.getDefault()
            .sendTextMessage(
                message.getIndividualRecipient().getNumber(),
                null,
                messages.get(i),
                sentIntents.get(i),
                deliveredIntents == null ? null : deliveredIntents.get(i));
      } catch (NullPointerException npe) {
        Log.w(TAG, npe);
        Log.w(TAG, "Recipient: " + message.getIndividualRecipient().getNumber());
        Log.w(TAG, "Message Total Parts/Current: " + messages.size() + "/" + i);
        Log.w(TAG, "Message Part Length: " + messages.get(i).getBytes().length);
        throw new UndeliverableMessageException(npe);
      } catch (IllegalArgumentException iae) {
        Log.w(TAG, iae);
        throw new UndeliverableMessageException(iae);
      }
    }
  }
예제 #2
0
 protected OutgoingTextMessage(OutgoingTextMessage base, String body) {
   this.recipients = base.getRecipients();
   this.message = body;
 }