From ef6a5c69af4fcd122922e40768842d415f17bb01 Mon Sep 17 00:00:00 2001 From: Moxie Marlinspike Date: Sun, 3 Mar 2013 18:44:58 -0800 Subject: [PATCH] Tweak MMS retrieval and submission. 1) Only attempt direct connect outside of MMS radio mode on CDMA. 2) Don't switch back to normal radio state if pending messages remain. --- .../securesms/service/MmsDownloader.java | 8 ++++++-- .../thoughtcrime/securesms/service/MmsSender.java | 12 ++++++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/org/thoughtcrime/securesms/service/MmsDownloader.java b/src/org/thoughtcrime/securesms/service/MmsDownloader.java index 8f54d7ade7..d3db620ebd 100644 --- a/src/org/thoughtcrime/securesms/service/MmsDownloader.java +++ b/src/org/thoughtcrime/securesms/service/MmsDownloader.java @@ -18,6 +18,7 @@ package org.thoughtcrime.securesms.service; import android.content.Context; import android.content.Intent; +import android.telephony.TelephonyManager; import android.util.Log; import org.thoughtcrime.securesms.R; @@ -46,7 +47,8 @@ public class MmsDownloader extends MmscProcessor { public void process(MasterSecret masterSecret, Intent intent) { if (intent.getAction().equals(SendReceiveService.DOWNLOAD_MMS_ACTION)) { - DownloadItem item = new DownloadItem(masterSecret, false, false, + boolean isCdma = ((TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE)).getPhoneType() == TelephonyManager.PHONE_TYPE_CDMA; + DownloadItem item = new DownloadItem(masterSecret, !isCdma, false, intent.getLongExtra("message_id", -1), intent.getLongExtra("thread_id", -1), intent.getStringExtra("content_location"), @@ -147,7 +149,9 @@ public class MmsDownloader extends MmscProcessor { downloadMms(item); } - finishConnectivity(); + if (pendingMessages.isEmpty()) + finishConnectivity(); + } else if (!isConnected() && !isConnectivityPossible()) { pendingMessages.clear(); diff --git a/src/org/thoughtcrime/securesms/service/MmsSender.java b/src/org/thoughtcrime/securesms/service/MmsSender.java index 1aab057898..a6aaad6dad 100644 --- a/src/org/thoughtcrime/securesms/service/MmsSender.java +++ b/src/org/thoughtcrime/securesms/service/MmsSender.java @@ -64,13 +64,14 @@ public class MmsSender extends MmscProcessor { public void process(MasterSecret masterSecret, Intent intent) { if (intent.getAction().equals(SendReceiveService.SEND_MMS_ACTION)) { long messageId = intent.getLongExtra("message_id", -1); + boolean isCdma = ((TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE)).getPhoneType() == TelephonyManager.PHONE_TYPE_CDMA; MmsDatabase database = DatabaseFactory.getEncryptingMmsDatabase(context, masterSecret); try { List sendRequests = getOutgoingMessages(masterSecret, messageId); for (SendReq sendRequest : sendRequests) { - handleSendMmsAction(new SendItem(masterSecret, sendRequest, messageId != -1, false, false)); + handleSendMmsAction(new SendItem(masterSecret, sendRequest, messageId != -1, !isCdma, false)); } } catch (MmsException me) { @@ -192,12 +193,15 @@ public class MmsSender extends MmscProcessor { return; } - for (SendItem item : pendingMessages) { + List outgoing = (List)pendingMessages.clone(); + pendingMessages.clear(); + + for (SendItem item : outgoing) { sendMmsMessage(item); } - pendingMessages.clear(); - finishConnectivity(); + if (pendingMessages.isEmpty()) + finishConnectivity(); } private boolean isInconsistentResponse(SendReq send, SendConf response) {