private void deliver(MasterSecret masterSecret, SmsMessageRecord message) throws UndeliverableMessageException, InsecureFallbackApprovalException { if (message.isSecure() || message.isKeyExchange() || message.isEndSession()) { deliverSecureMessage(masterSecret, message); } else { deliverPlaintextMessage(message); } }
public static OutgoingTextMessage from(SmsMessageRecord record) { if (record.isSecure()) { return new OutgoingEncryptedMessage( record.getIndividualRecipient(), record.getBody().getBody()); } else if (record.isKeyExchange()) { return new OutgoingKeyExchangeMessage( record.getIndividualRecipient(), record.getBody().getBody()); } else if (record.isEndSession()) { return new OutgoingEndSessionMessage( new OutgoingTextMessage(record.getIndividualRecipient(), record.getBody().getBody())); } else { return new OutgoingTextMessage(record.getIndividualRecipient(), record.getBody().getBody()); } }
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); } } }