diff --git a/src/org/thoughtcrime/securesms/mms/MmsCommunication.java b/src/org/thoughtcrime/securesms/mms/MmsCommunication.java index dc7eaf372a..206959da91 100644 --- a/src/org/thoughtcrime/securesms/mms/MmsCommunication.java +++ b/src/org/thoughtcrime/securesms/mms/MmsCommunication.java @@ -174,7 +174,7 @@ public class MmsCommunication { protected static byte[] parseResponse(HttpEntity entity) throws IOException { if (entity == null || entity.getContentLength() == 0) - throw new IOException("Null response"); + return null; if (entity.getContentLength() < 0) throw new IOException("Unknown content length!"); diff --git a/src/org/thoughtcrime/securesms/mms/MmsDownloadHelper.java b/src/org/thoughtcrime/securesms/mms/MmsDownloadHelper.java index c32227cbb5..8ea09dd591 100644 --- a/src/org/thoughtcrime/securesms/mms/MmsDownloadHelper.java +++ b/src/org/thoughtcrime/securesms/mms/MmsDownloadHelper.java @@ -36,7 +36,7 @@ import java.net.URISyntaxException; public class MmsDownloadHelper extends MmsCommunication { private static byte[] makeRequest(Context context, MmsConnectionParameters connectionParameters, String url) - throws ClientProtocolException, IOException + throws IOException { AndroidHttpClient client = null; @@ -82,6 +82,10 @@ public class MmsDownloadHelper extends MmsCommunication { byte[] pdu = makeRequest(context, connectionParameters, url); + if (pdu == null) { + throw new IOException("Retrieved null PDU!"); + } + RetrieveConf retrieved = (RetrieveConf)new PduParser(pdu).parse(); if (retrieved == null) { diff --git a/src/org/thoughtcrime/securesms/mms/MmsSendHelper.java b/src/org/thoughtcrime/securesms/mms/MmsSendHelper.java index f430350584..5bc9407fc3 100644 --- a/src/org/thoughtcrime/securesms/mms/MmsSendHelper.java +++ b/src/org/thoughtcrime/securesms/mms/MmsSendHelper.java @@ -54,7 +54,6 @@ public class MmsSendHelper extends MmsCommunication { request.setEntity(entity); request.setParams(client.getParams()); request.addHeader("Accept", "*/*, application/vnd.wap.mms-message, application/vnd.wap.sic"); -// request.addHeader("x-wap-profile", "http://www.htcmms.com.tw/Android/Common/nexusone/ua-profile.xml"); request.addHeader("x-wap-profile", "http://www.google.com/oha/rdf/ua-profile-kila.xml"); HttpResponse response = client.execute(target, request); StatusLine status = response.getStatusLine(); @@ -72,16 +71,35 @@ public class MmsSendHelper extends MmsCommunication { } } + public static void sendNotificationReceived(Context context, byte[] mms, String apn, + boolean usingMmsRadio, boolean useProxyIfAvailable) + throws IOException + { + sendBytes(context, mms, apn, usingMmsRadio, useProxyIfAvailable); + } + public static SendConf sendMms(Context context, byte[] mms, String apn, boolean usingMmsRadio, boolean useProxyIfAvailable) + throws IOException + { + byte[] response = sendBytes(context, mms, apn, usingMmsRadio, useProxyIfAvailable); + + if (response == null) { + throw new IOException("Got null response!"); + } + + return (SendConf) new PduParser(response).parse(); + } + + private static byte[] sendBytes(Context context, byte[] mms, String apn, + boolean usingMmsRadio, boolean useProxyIfAvailable) throws IOException { Log.w("MmsSender", "Sending MMS of length: " + mms.length); try { MmsConnectionParameters parameters = getMmsConnectionParameters(context, apn, useProxyIfAvailable); checkRouteToHost(context, parameters, parameters.getMmsc(), usingMmsRadio); - byte[] response = makePost(context, parameters, mms); - return (SendConf) new PduParser(response).parse(); + return makePost(context, parameters, mms); } catch (ApnUnavailableException aue) { Log.w("MmsSender", aue); throw new IOException("Failed to get MMSC information..."); diff --git a/src/org/thoughtcrime/securesms/service/MmsDownloader.java b/src/org/thoughtcrime/securesms/service/MmsDownloader.java index c13d99aa68..b6c2dcb2c7 100644 --- a/src/org/thoughtcrime/securesms/service/MmsDownloader.java +++ b/src/org/thoughtcrime/securesms/service/MmsDownloader.java @@ -28,10 +28,15 @@ import org.thoughtcrime.securesms.crypto.MasterSecret; import org.thoughtcrime.securesms.database.DatabaseFactory; import org.thoughtcrime.securesms.database.MmsDatabase; import org.thoughtcrime.securesms.mms.MmsDownloadHelper; +import org.thoughtcrime.securesms.mms.MmsSendHelper; import org.thoughtcrime.securesms.notifications.MessageNotifier; import org.thoughtcrime.securesms.protocol.WirePrefix; +import ws.com.google.android.mms.InvalidHeaderValueException; import ws.com.google.android.mms.MmsException; +import ws.com.google.android.mms.pdu.NotifyRespInd; +import ws.com.google.android.mms.pdu.PduComposer; +import ws.com.google.android.mms.pdu.PduHeaders; import ws.com.google.android.mms.pdu.RetrieveConf; import java.io.IOException; @@ -100,9 +105,7 @@ public class MmsDownloader extends MmscProcessor { } storeRetrievedMms(mmsDatabase, item, retrieved); - - // NotifyRespInd notifyResponse = new NotifyRespInd(PduHeaders.CURRENT_MMS_VERSION, item.getTransactionId(), PduHeaders.STATUS_RETRIEVED); - // MmsSendHelper.sendMms(context, new PduComposer(context, notifyResponse).make()); + sendRetrievedAcknowledgement(item); } catch (IOException e) { Log.w("MmsDownloader", e); @@ -147,6 +150,22 @@ public class MmsDownloader extends MmscProcessor { MessageNotifier.updateNotification(context, item.getMasterSecret(), messageAndThreadId.second); } + private void sendRetrievedAcknowledgement(DownloadItem item) { + try { + NotifyRespInd notifyResponse = new NotifyRespInd(PduHeaders.CURRENT_MMS_VERSION, + item.getTransactionId(), + PduHeaders.STATUS_RETRIEVED); + + MmsSendHelper.sendNotificationReceived(context, new PduComposer(context, notifyResponse).make(), + getApnInformation(), item.useMmsRadioMode(), + item.proxyRequestIfPossible()); + } catch (InvalidHeaderValueException e) { + Log.w("MmsDownloader", e); + } catch (IOException e) { + Log.w("MmsDownloader", e); + } + } + protected void handleConnectivityChange() { LinkedList downloadItems = (LinkedList)pendingMessages.clone(); diff --git a/src/org/thoughtcrime/securesms/service/SmsListener.java b/src/org/thoughtcrime/securesms/service/SmsListener.java index c9d17d9a80..c5fb38aee5 100644 --- a/src/org/thoughtcrime/securesms/service/SmsListener.java +++ b/src/org/thoughtcrime/securesms/service/SmsListener.java @@ -110,8 +110,6 @@ public class SmsListener extends BroadcastReceiver { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); String messageBody = getSmsMessageBodyFromIntent(intent); - Log.w("SmsListener", "Checking challenge: " + messageBody); - if (messageBody == null) return false;