2012-09-30 18:46:45 +00:00
|
|
|
/**
|
2011-12-20 18:20:44 +00:00
|
|
|
* Copyright (C) 2011 Whisper Systems
|
2012-09-30 18:46:45 +00:00
|
|
|
*
|
2011-12-20 18:20:44 +00:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2012-09-30 18:46:45 +00:00
|
|
|
*
|
2011-12-20 18:20:44 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
package org.thoughtcrime.securesms.service;
|
|
|
|
|
2012-09-30 18:46:45 +00:00
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.telephony.TelephonyManager;
|
|
|
|
import android.util.Log;
|
2011-12-20 18:20:44 +00:00
|
|
|
|
2013-02-09 23:17:55 +00:00
|
|
|
import org.thoughtcrime.securesms.R;
|
2011-12-20 18:20:44 +00:00
|
|
|
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
|
|
|
import org.thoughtcrime.securesms.crypto.SessionCipher;
|
|
|
|
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
|
|
|
import org.thoughtcrime.securesms.database.MmsDatabase;
|
|
|
|
import org.thoughtcrime.securesms.mms.MmsSendHelper;
|
|
|
|
import org.thoughtcrime.securesms.mms.TextTransport;
|
2013-02-09 23:17:55 +00:00
|
|
|
import org.thoughtcrime.securesms.notifications.MessageNotifier;
|
2011-12-20 18:20:44 +00:00
|
|
|
import org.thoughtcrime.securesms.protocol.WirePrefix;
|
|
|
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
2013-02-09 23:17:55 +00:00
|
|
|
import org.thoughtcrime.securesms.recipients.Recipients;
|
2013-02-21 02:10:33 +00:00
|
|
|
import org.thoughtcrime.securesms.service.SendReceiveService.ToastHandler;
|
2011-12-20 18:20:44 +00:00
|
|
|
import org.thoughtcrime.securesms.util.Hex;
|
|
|
|
|
|
|
|
import ws.com.google.android.mms.ContentType;
|
|
|
|
import ws.com.google.android.mms.MmsException;
|
|
|
|
import ws.com.google.android.mms.pdu.EncodedStringValue;
|
|
|
|
import ws.com.google.android.mms.pdu.PduBody;
|
|
|
|
import ws.com.google.android.mms.pdu.PduComposer;
|
|
|
|
import ws.com.google.android.mms.pdu.PduHeaders;
|
|
|
|
import ws.com.google.android.mms.pdu.PduPart;
|
|
|
|
import ws.com.google.android.mms.pdu.SendConf;
|
|
|
|
import ws.com.google.android.mms.pdu.SendReq;
|
2012-09-30 18:46:45 +00:00
|
|
|
|
|
|
|
import java.io.IOException;
|
2013-02-21 02:10:33 +00:00
|
|
|
import java.util.ArrayList;
|
2012-09-30 18:46:45 +00:00
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.LinkedList;
|
2013-02-21 02:10:33 +00:00
|
|
|
import java.util.List;
|
2011-12-20 18:20:44 +00:00
|
|
|
|
|
|
|
public class MmsSender extends MmscProcessor {
|
|
|
|
|
2013-02-21 02:10:33 +00:00
|
|
|
private final LinkedList<SendItem> pendingMessages = new LinkedList<SendItem>();
|
|
|
|
private final ToastHandler toastHandler;
|
2012-09-30 18:46:45 +00:00
|
|
|
|
2013-02-21 02:10:33 +00:00
|
|
|
public MmsSender(Context context, ToastHandler toastHandler) {
|
2011-12-20 18:20:44 +00:00
|
|
|
super(context);
|
2013-02-09 23:17:55 +00:00
|
|
|
this.toastHandler = toastHandler;
|
2011-12-20 18:20:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void process(MasterSecret masterSecret, Intent intent) {
|
|
|
|
if (intent.getAction().equals(SendReceiveService.SEND_MMS_ACTION)) {
|
2012-09-30 18:46:45 +00:00
|
|
|
long messageId = intent.getLongExtra("message_id", -1);
|
2013-03-04 02:44:58 +00:00
|
|
|
boolean isCdma = ((TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE)).getPhoneType() == TelephonyManager.PHONE_TYPE_CDMA;
|
Major storage layer refactoring to set the stage for clean GCM.
1) We now try to hand out cursors at a minimum. There has always been
a fairly clean insertion layer that handles encrypting message bodies,
but the process of decrypting message bodies has always been less than
ideal. Here we introduce a "Reader" interface that will decrypt message
bodies when appropriate and return objects that encapsulate record state.
No more MessageDisplayHelper. The MmsSmsDatabase interface is also more
sane.
2) We finally rid ourselves of the technical debt associated with TextSecure's
initial usage of the default SMS DB. In that world, we weren't able to use
anything other than the default "Inbox, Outbox, Sent" types to describe a
message, and had to overload the message content itself with a set of
local "prefixes" to describe what it was (encrypted, asymetric encrypted,
remote encrypted, a key exchange, procssed key exchange), and so on.
This includes a major schema update that transforms the "type" field into
a bitmask that describes everything that used to be encoded in a prefix,
and prefixes have been completely eliminated from the system.
No more Prefix.java
3) Refactoring of the MultipartMessageHandler code. It's less of a mess, and
hopefully more clear as to what's going on.
The next step is to remove what we can from SmsTransportDetails and genericize
that interface for a GCM equivalent.
2013-04-20 19:22:04 +00:00
|
|
|
MmsDatabase database = DatabaseFactory.getMmsDatabase(context);
|
2011-12-20 18:20:44 +00:00
|
|
|
|
|
|
|
try {
|
2013-02-21 02:10:33 +00:00
|
|
|
List<SendReq> sendRequests = getOutgoingMessages(masterSecret, messageId);
|
2012-09-30 18:46:45 +00:00
|
|
|
|
2013-02-21 02:10:33 +00:00
|
|
|
for (SendReq sendRequest : sendRequests) {
|
2013-03-04 02:44:58 +00:00
|
|
|
handleSendMmsAction(new SendItem(masterSecret, sendRequest, messageId != -1, !isCdma, false));
|
2012-09-30 18:46:45 +00:00
|
|
|
}
|
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
} catch (MmsException me) {
|
2012-09-30 18:46:45 +00:00
|
|
|
Log.w("MmsSender", me);
|
|
|
|
if (messageId != -1)
|
|
|
|
database.markAsSentFailed(messageId);
|
|
|
|
}
|
2011-12-20 18:20:44 +00:00
|
|
|
} else if (intent.getAction().equals(SendReceiveService.SEND_MMS_CONNECTIVITY_ACTION)) {
|
2013-02-21 02:10:33 +00:00
|
|
|
handleConnectivityChange();
|
2011-12-20 18:20:44 +00:00
|
|
|
}
|
|
|
|
}
|
2012-09-30 18:46:45 +00:00
|
|
|
|
2013-02-21 02:10:33 +00:00
|
|
|
private void handleSendMmsAction(SendItem item) {
|
2011-12-20 18:20:44 +00:00
|
|
|
if (!isConnectivityPossible()) {
|
2013-02-21 02:10:33 +00:00
|
|
|
if (item.targeted) {
|
2013-02-09 23:17:55 +00:00
|
|
|
toastHandler
|
|
|
|
.obtainMessage(0, context.getString(R.string.MmsSender_currently_unable_to_send_your_mms_message))
|
|
|
|
.sendToTarget();
|
|
|
|
}
|
2013-02-21 02:10:33 +00:00
|
|
|
|
|
|
|
return;
|
2011-12-20 18:20:44 +00:00
|
|
|
}
|
2012-09-30 18:46:45 +00:00
|
|
|
|
2013-02-21 02:10:33 +00:00
|
|
|
if (item.useMmsRadio) sendMmsMessageWithRadioChange(item);
|
|
|
|
else sendMmsMessage(item);
|
2011-12-20 18:20:44 +00:00
|
|
|
}
|
|
|
|
|
2013-02-21 02:10:33 +00:00
|
|
|
private void sendMmsMessageWithRadioChange(SendItem item) {
|
|
|
|
Log.w("MmsSender", "Sending MMS with radio change..");
|
|
|
|
pendingMessages.add(item);
|
|
|
|
issueConnectivityRequest();
|
2011-12-20 18:20:44 +00:00
|
|
|
}
|
2012-09-30 18:46:45 +00:00
|
|
|
|
2013-02-21 02:10:33 +00:00
|
|
|
private void sendMmsMessage(SendItem item) {
|
|
|
|
Log.w("MmsSender", "Sending MMS SendItem...");
|
Major storage layer refactoring to set the stage for clean GCM.
1) We now try to hand out cursors at a minimum. There has always been
a fairly clean insertion layer that handles encrypting message bodies,
but the process of decrypting message bodies has always been less than
ideal. Here we introduce a "Reader" interface that will decrypt message
bodies when appropriate and return objects that encapsulate record state.
No more MessageDisplayHelper. The MmsSmsDatabase interface is also more
sane.
2) We finally rid ourselves of the technical debt associated with TextSecure's
initial usage of the default SMS DB. In that world, we weren't able to use
anything other than the default "Inbox, Outbox, Sent" types to describe a
message, and had to overload the message content itself with a set of
local "prefixes" to describe what it was (encrypted, asymetric encrypted,
remote encrypted, a key exchange, procssed key exchange), and so on.
This includes a major schema update that transforms the "type" field into
a bitmask that describes everything that used to be encoded in a prefix,
and prefixes have been completely eliminated from the system.
No more Prefix.java
3) Refactoring of the MultipartMessageHandler code. It's less of a mess, and
hopefully more clear as to what's going on.
The next step is to remove what we can from SmsTransportDetails and genericize
that interface for a GCM equivalent.
2013-04-20 19:22:04 +00:00
|
|
|
MmsDatabase db = DatabaseFactory.getMmsDatabase(context);
|
2013-02-21 02:10:33 +00:00
|
|
|
String number = ((TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE)).getLine1Number();
|
|
|
|
long messageId = item.request.getDatabaseMessageId();
|
|
|
|
long messageBox = item.request.getDatabaseMessageBox();
|
|
|
|
SendReq request = item.request;
|
2011-12-20 18:20:44 +00:00
|
|
|
|
2012-09-30 18:46:45 +00:00
|
|
|
|
Major storage layer refactoring to set the stage for clean GCM.
1) We now try to hand out cursors at a minimum. There has always been
a fairly clean insertion layer that handles encrypting message bodies,
but the process of decrypting message bodies has always been less than
ideal. Here we introduce a "Reader" interface that will decrypt message
bodies when appropriate and return objects that encapsulate record state.
No more MessageDisplayHelper. The MmsSmsDatabase interface is also more
sane.
2) We finally rid ourselves of the technical debt associated with TextSecure's
initial usage of the default SMS DB. In that world, we weren't able to use
anything other than the default "Inbox, Outbox, Sent" types to describe a
message, and had to overload the message content itself with a set of
local "prefixes" to describe what it was (encrypted, asymetric encrypted,
remote encrypted, a key exchange, procssed key exchange), and so on.
This includes a major schema update that transforms the "type" field into
a bitmask that describes everything that used to be encoded in a prefix,
and prefixes have been completely eliminated from the system.
No more Prefix.java
3) Refactoring of the MultipartMessageHandler code. It's less of a mess, and
hopefully more clear as to what's going on.
The next step is to remove what we can from SmsTransportDetails and genericize
that interface for a GCM equivalent.
2013-04-20 19:22:04 +00:00
|
|
|
if (MmsDatabase.Types.isSecureType(messageBox)) {
|
2013-02-21 02:10:33 +00:00
|
|
|
request = getEncryptedMms(item.masterSecret, request, messageId);
|
|
|
|
}
|
2012-09-30 18:46:45 +00:00
|
|
|
|
2013-02-21 02:10:33 +00:00
|
|
|
if (number != null && number.trim().length() != 0) {
|
|
|
|
request.setFrom(new EncodedStringValue(number));
|
|
|
|
}
|
2012-09-30 18:46:45 +00:00
|
|
|
|
2013-02-21 02:10:33 +00:00
|
|
|
try {
|
|
|
|
SendConf conf = MmsSendHelper.sendMms(context, new PduComposer(context, request).make(),
|
|
|
|
getApnInformation(), item.useMmsRadio, item.useProxyIfAvailable);
|
2012-09-30 18:46:45 +00:00
|
|
|
|
2013-02-21 02:10:33 +00:00
|
|
|
for (int i=0;i<request.getBody().getPartsNum();i++) {
|
|
|
|
Log.w("MmsSender", "Sent MMS part of content-type: " + new String(request.getBody().getPart(i).getContentType()));
|
2011-12-20 18:20:44 +00:00
|
|
|
}
|
2012-09-30 18:46:45 +00:00
|
|
|
|
2013-02-09 23:17:55 +00:00
|
|
|
long threadId = DatabaseFactory.getMmsDatabase(context).getThreadIdForMessage(messageId);
|
|
|
|
Recipients recipients = DatabaseFactory.getThreadDatabase(context).getRecipientsForThreadId(context, threadId);
|
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
if (conf == null) {
|
2012-09-30 18:46:45 +00:00
|
|
|
db.markAsSentFailed(messageId);
|
2013-02-09 23:17:55 +00:00
|
|
|
MessageNotifier.notifyMessageDeliveryFailed(context, recipients, threadId);
|
2012-09-30 18:46:45 +00:00
|
|
|
Log.w("MmsSender", "No M-Send.conf received in response to send.");
|
|
|
|
return;
|
2011-12-20 18:20:44 +00:00
|
|
|
} else if (conf.getResponseStatus() != PduHeaders.RESPONSE_STATUS_OK) {
|
2012-09-30 18:46:45 +00:00
|
|
|
Log.w("MmsSender", "Got bad response: " + conf.getResponseStatus());
|
|
|
|
db.updateResponseStatus(messageId, conf.getResponseStatus());
|
|
|
|
db.markAsSentFailed(messageId);
|
2013-02-09 23:17:55 +00:00
|
|
|
MessageNotifier.notifyMessageDeliveryFailed(context, recipients, threadId);
|
2012-09-30 18:46:45 +00:00
|
|
|
return;
|
2013-02-21 02:10:33 +00:00
|
|
|
} else if (isInconsistentResponse(request, conf)) {
|
2012-09-30 18:46:45 +00:00
|
|
|
db.markAsSentFailed(messageId);
|
2013-02-09 23:17:55 +00:00
|
|
|
MessageNotifier.notifyMessageDeliveryFailed(context, recipients, threadId);
|
2012-09-30 18:46:45 +00:00
|
|
|
Log.w("MmsSender", "Got a response for the wrong transaction?");
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
Log.w("MmsSender", "Successful send! " + messageId);
|
Major storage layer refactoring to set the stage for clean GCM.
1) We now try to hand out cursors at a minimum. There has always been
a fairly clean insertion layer that handles encrypting message bodies,
but the process of decrypting message bodies has always been less than
ideal. Here we introduce a "Reader" interface that will decrypt message
bodies when appropriate and return objects that encapsulate record state.
No more MessageDisplayHelper. The MmsSmsDatabase interface is also more
sane.
2) We finally rid ourselves of the technical debt associated with TextSecure's
initial usage of the default SMS DB. In that world, we weren't able to use
anything other than the default "Inbox, Outbox, Sent" types to describe a
message, and had to overload the message content itself with a set of
local "prefixes" to describe what it was (encrypted, asymetric encrypted,
remote encrypted, a key exchange, procssed key exchange), and so on.
This includes a major schema update that transforms the "type" field into
a bitmask that describes everything that used to be encoded in a prefix,
and prefixes have been completely eliminated from the system.
No more Prefix.java
3) Refactoring of the MultipartMessageHandler code. It's less of a mess, and
hopefully more clear as to what's going on.
The next step is to remove what we can from SmsTransportDetails and genericize
that interface for a GCM equivalent.
2013-04-20 19:22:04 +00:00
|
|
|
db.markAsSent(messageId, conf.getMessageId(), conf.getResponseStatus());
|
2013-02-21 02:10:33 +00:00
|
|
|
}
|
2011-12-20 18:20:44 +00:00
|
|
|
} catch (IOException ioe) {
|
|
|
|
Log.w("MmsSender", ioe);
|
2013-02-21 02:10:33 +00:00
|
|
|
if (!item.useMmsRadio) scheduleSendWithMmsRadio(item);
|
|
|
|
else if (!item.useProxyIfAvailable) scheduleSendWithMmsRadioAndProxy(item);
|
|
|
|
else db.markAsSentFailed(messageId);
|
2012-09-30 18:46:45 +00:00
|
|
|
}
|
2011-12-20 18:20:44 +00:00
|
|
|
}
|
2012-09-30 18:46:45 +00:00
|
|
|
|
2013-02-21 02:10:33 +00:00
|
|
|
private List<SendReq> getOutgoingMessages(MasterSecret masterSecret, long messageId)
|
|
|
|
throws MmsException
|
|
|
|
{
|
Major storage layer refactoring to set the stage for clean GCM.
1) We now try to hand out cursors at a minimum. There has always been
a fairly clean insertion layer that handles encrypting message bodies,
but the process of decrypting message bodies has always been less than
ideal. Here we introduce a "Reader" interface that will decrypt message
bodies when appropriate and return objects that encapsulate record state.
No more MessageDisplayHelper. The MmsSmsDatabase interface is also more
sane.
2) We finally rid ourselves of the technical debt associated with TextSecure's
initial usage of the default SMS DB. In that world, we weren't able to use
anything other than the default "Inbox, Outbox, Sent" types to describe a
message, and had to overload the message content itself with a set of
local "prefixes" to describe what it was (encrypted, asymetric encrypted,
remote encrypted, a key exchange, procssed key exchange), and so on.
This includes a major schema update that transforms the "type" field into
a bitmask that describes everything that used to be encoded in a prefix,
and prefixes have been completely eliminated from the system.
No more Prefix.java
3) Refactoring of the MultipartMessageHandler code. It's less of a mess, and
hopefully more clear as to what's going on.
The next step is to remove what we can from SmsTransportDetails and genericize
that interface for a GCM equivalent.
2013-04-20 19:22:04 +00:00
|
|
|
MmsDatabase database = DatabaseFactory.getMmsDatabase(context);
|
2013-02-21 02:10:33 +00:00
|
|
|
List<SendReq> sendRequests;
|
2012-09-30 18:46:45 +00:00
|
|
|
|
2013-02-21 02:10:33 +00:00
|
|
|
if (messageId == -1) {
|
Major storage layer refactoring to set the stage for clean GCM.
1) We now try to hand out cursors at a minimum. There has always been
a fairly clean insertion layer that handles encrypting message bodies,
but the process of decrypting message bodies has always been less than
ideal. Here we introduce a "Reader" interface that will decrypt message
bodies when appropriate and return objects that encapsulate record state.
No more MessageDisplayHelper. The MmsSmsDatabase interface is also more
sane.
2) We finally rid ourselves of the technical debt associated with TextSecure's
initial usage of the default SMS DB. In that world, we weren't able to use
anything other than the default "Inbox, Outbox, Sent" types to describe a
message, and had to overload the message content itself with a set of
local "prefixes" to describe what it was (encrypted, asymetric encrypted,
remote encrypted, a key exchange, procssed key exchange), and so on.
This includes a major schema update that transforms the "type" field into
a bitmask that describes everything that used to be encoded in a prefix,
and prefixes have been completely eliminated from the system.
No more Prefix.java
3) Refactoring of the MultipartMessageHandler code. It's less of a mess, and
hopefully more clear as to what's going on.
The next step is to remove what we can from SmsTransportDetails and genericize
that interface for a GCM equivalent.
2013-04-20 19:22:04 +00:00
|
|
|
sendRequests = Arrays.asList(database.getOutgoingMessages(masterSecret));
|
2013-02-21 02:10:33 +00:00
|
|
|
} else {
|
|
|
|
sendRequests = new ArrayList<SendReq>(1);
|
Major storage layer refactoring to set the stage for clean GCM.
1) We now try to hand out cursors at a minimum. There has always been
a fairly clean insertion layer that handles encrypting message bodies,
but the process of decrypting message bodies has always been less than
ideal. Here we introduce a "Reader" interface that will decrypt message
bodies when appropriate and return objects that encapsulate record state.
No more MessageDisplayHelper. The MmsSmsDatabase interface is also more
sane.
2) We finally rid ourselves of the technical debt associated with TextSecure's
initial usage of the default SMS DB. In that world, we weren't able to use
anything other than the default "Inbox, Outbox, Sent" types to describe a
message, and had to overload the message content itself with a set of
local "prefixes" to describe what it was (encrypted, asymetric encrypted,
remote encrypted, a key exchange, procssed key exchange), and so on.
This includes a major schema update that transforms the "type" field into
a bitmask that describes everything that used to be encoded in a prefix,
and prefixes have been completely eliminated from the system.
No more Prefix.java
3) Refactoring of the MultipartMessageHandler code. It's less of a mess, and
hopefully more clear as to what's going on.
The next step is to remove what we can from SmsTransportDetails and genericize
that interface for a GCM equivalent.
2013-04-20 19:22:04 +00:00
|
|
|
sendRequests.add(database.getSendRequest(masterSecret, messageId));
|
2013-02-21 02:10:33 +00:00
|
|
|
}
|
2011-12-20 18:20:44 +00:00
|
|
|
|
2013-02-21 02:10:33 +00:00
|
|
|
return sendRequests;
|
|
|
|
}
|
2012-09-30 18:46:45 +00:00
|
|
|
|
2013-02-21 02:10:33 +00:00
|
|
|
protected void handleConnectivityChange() {
|
|
|
|
if (!isConnected()) {
|
|
|
|
if (!isConnectivityPossible() && !pendingMessages.isEmpty()) {
|
|
|
|
DatabaseFactory.getMmsDatabase(context).markAsSentFailed(pendingMessages.remove().request.getDatabaseMessageId());
|
|
|
|
toastHandler.makeToast(context.getString(R.string.MmsSender_currently_unable_to_send_your_mms_message));
|
|
|
|
Log.w("MmsSender", "Unable to send MMS.");
|
|
|
|
finishConnectivity();
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
2012-09-30 18:46:45 +00:00
|
|
|
|
2013-03-04 02:44:58 +00:00
|
|
|
List<SendItem> outgoing = (List<SendItem>)pendingMessages.clone();
|
|
|
|
pendingMessages.clear();
|
|
|
|
|
|
|
|
for (SendItem item : outgoing) {
|
2013-02-21 02:10:33 +00:00
|
|
|
sendMmsMessage(item);
|
2011-12-20 18:20:44 +00:00
|
|
|
}
|
2012-09-30 18:46:45 +00:00
|
|
|
|
2013-03-04 02:44:58 +00:00
|
|
|
if (pendingMessages.isEmpty())
|
|
|
|
finishConnectivity();
|
2013-02-21 02:10:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private boolean isInconsistentResponse(SendReq send, SendConf response) {
|
|
|
|
Log.w("MmsSenderService", "Comparing: " + Hex.toString(send.getTransactionId()));
|
|
|
|
Log.w("MmsSenderService", "With: " + Hex.toString(response.getTransactionId()));
|
|
|
|
return !Arrays.equals(send.getTransactionId(), response.getTransactionId());
|
|
|
|
}
|
|
|
|
|
|
|
|
private byte[] getEncryptedPdu(MasterSecret masterSecret, String recipient, byte[] pduBytes) {
|
|
|
|
synchronized (SessionCipher.CIPHER_LOCK) {
|
|
|
|
SessionCipher cipher = new SessionCipher(context, masterSecret, new Recipient(null, recipient, null, null), new TextTransport());
|
|
|
|
return cipher.encryptMessage(pduBytes);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private SendReq getEncryptedMms(MasterSecret masterSecret, SendReq pdu, long messageId) {
|
|
|
|
Log.w("MmsSender", "Sending Secure MMS.");
|
|
|
|
EncodedStringValue[] encodedRecipient = pdu.getTo();
|
|
|
|
String recipient = encodedRecipient[0].getString();
|
|
|
|
byte[] pduBytes = new PduComposer(context, pdu).make();
|
|
|
|
byte[] encryptedPdu = getEncryptedPdu(masterSecret, recipient, pduBytes);
|
|
|
|
Log.w("MmsSendeR", "Got encrypted bytes: " + encryptedPdu.length);
|
|
|
|
PduBody body = new PduBody();
|
|
|
|
PduPart part = new PduPart();
|
|
|
|
|
|
|
|
part.setContentId((System.currentTimeMillis()+"").getBytes());
|
|
|
|
part.setContentType(ContentType.TEXT_PLAIN.getBytes());
|
|
|
|
part.setName((System.currentTimeMillis()+"").getBytes());
|
|
|
|
part.setData(encryptedPdu);
|
|
|
|
body.addPart(part);
|
|
|
|
pdu.setSubject(new EncodedStringValue(WirePrefix.calculateEncryptedMmsSubject()));
|
|
|
|
pdu.setBody(body);
|
|
|
|
|
|
|
|
return pdu;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void scheduleSendWithMmsRadioAndProxy(SendItem item) {
|
2013-03-10 22:47:13 +00:00
|
|
|
Log.w("MmsSender", "Falling back to sending MMS with radio and proxy...");
|
|
|
|
item.useMmsRadio = true;
|
|
|
|
item.useProxyIfAvailable = true;
|
2013-02-21 02:10:33 +00:00
|
|
|
handleSendMmsAction(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void scheduleSendWithMmsRadio(SendItem item) {
|
2013-03-10 22:47:13 +00:00
|
|
|
Log.w("MmsSender", "Falling back to sending MMS with radio only...");
|
|
|
|
item.useMmsRadio = true;
|
2013-02-21 02:10:33 +00:00
|
|
|
handleSendMmsAction(item);
|
2011-12-20 18:20:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-09-30 18:46:45 +00:00
|
|
|
protected String getConnectivityAction() {
|
2011-12-20 18:20:44 +00:00
|
|
|
return SendReceiveService.SEND_MMS_CONNECTIVITY_ACTION;
|
|
|
|
}
|
|
|
|
|
2013-02-21 02:10:33 +00:00
|
|
|
private static class SendItem {
|
|
|
|
private final MasterSecret masterSecret;
|
|
|
|
|
|
|
|
private boolean useMmsRadio;
|
|
|
|
private boolean useProxyIfAvailable;
|
|
|
|
private SendReq request;
|
|
|
|
private boolean targeted;
|
|
|
|
|
|
|
|
public SendItem(MasterSecret masterSecret, SendReq request,
|
|
|
|
boolean targeted, boolean useMmsRadio,
|
|
|
|
boolean useProxyIfAvailable)
|
|
|
|
{
|
|
|
|
this.masterSecret = masterSecret;
|
|
|
|
this.request = request;
|
|
|
|
this.targeted = targeted;
|
|
|
|
this.useMmsRadio = useMmsRadio;
|
|
|
|
this.useProxyIfAvailable = useProxyIfAvailable;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
}
|