From b998c5f86ce7b15ef192eb4106948e03e5e71467 Mon Sep 17 00:00:00 2001 From: Jake McGinty Date: Fri, 6 Mar 2015 13:57:00 -0800 Subject: [PATCH] Add missing MSISDN headers to MMS send request Fixes #1935 Fixes #2451 Closes #2605 // FREEBIE --- .../securesms/jobs/MmsSendJob.java | 3 ++- .../securesms/mms/IncomingMmsConnection.java | 5 ++++- .../securesms/mms/MmsConnection.java | 20 +++++++++++++++++++ .../securesms/mms/OutgoingMmsConnection.java | 12 ++++++++--- .../securesms/util/TelephonyUtil.java | 4 ++++ 5 files changed, 39 insertions(+), 5 deletions(-) diff --git a/src/org/thoughtcrime/securesms/jobs/MmsSendJob.java b/src/org/thoughtcrime/securesms/jobs/MmsSendJob.java index bca2c3928b..6eda18200a 100644 --- a/src/org/thoughtcrime/securesms/jobs/MmsSendJob.java +++ b/src/org/thoughtcrime/securesms/jobs/MmsSendJob.java @@ -24,6 +24,7 @@ import org.thoughtcrime.securesms.transport.InsecureFallbackApprovalException; import org.thoughtcrime.securesms.transport.UndeliverableMessageException; import org.thoughtcrime.securesms.util.Hex; import org.thoughtcrime.securesms.util.NumberUtil; +import org.thoughtcrime.securesms.util.TelephonyUtil; import org.whispersystems.jobqueue.JobParameters; import org.whispersystems.jobqueue.requirements.NetworkRequirement; import org.whispersystems.libaxolotl.NoSessionException; @@ -146,7 +147,7 @@ public class MmsSendJob extends SendJob { boolean usingMmsRadio, boolean useProxy) throws IOException, UndeliverableMessageException, InsecureFallbackApprovalException { - String number = ((TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE)).getLine1Number(); + String number = TelephonyUtil.getManager(context).getLine1Number(); boolean upgradedSecure = false; prepareMessageMedia(masterSecret, message, MediaConstraints.MMS_CONSTRAINTS, true); diff --git a/src/org/thoughtcrime/securesms/mms/IncomingMmsConnection.java b/src/org/thoughtcrime/securesms/mms/IncomingMmsConnection.java index d29a9c8f69..a3c24a4b0c 100644 --- a/src/org/thoughtcrime/securesms/mms/IncomingMmsConnection.java +++ b/src/org/thoughtcrime/securesms/mms/IncomingMmsConnection.java @@ -20,6 +20,7 @@ import android.content.Context; import android.net.Uri; import android.util.Log; +import org.apache.http.Header; import org.apache.http.HttpHost; import org.apache.http.client.config.RequestConfig; import org.apache.http.client.methods.HttpGetHC4; @@ -41,7 +42,9 @@ public class IncomingMmsConnection extends MmsConnection { @Override protected HttpUriRequest constructRequest(boolean useProxy) throws IOException { HttpGetHC4 request = new HttpGetHC4(apn.getMmsc()); - request.addHeader("Accept", "*/*, application/vnd.wap.mms-message, application/vnd.wap.sic"); + for (Header header : getBaseHeaders()) { + request.addHeader(header); + } if (useProxy) { HttpHost proxy = new HttpHost(apn.getProxy(), apn.getPort()); request.setConfig(RequestConfig.custom().setProxy(proxy).build()); diff --git a/src/org/thoughtcrime/securesms/mms/MmsConnection.java b/src/org/thoughtcrime/securesms/mms/MmsConnection.java index de91f9234d..fc26ad99bb 100644 --- a/src/org/thoughtcrime/securesms/mms/MmsConnection.java +++ b/src/org/thoughtcrime/securesms/mms/MmsConnection.java @@ -21,6 +21,7 @@ import android.net.ConnectivityManager; import android.text.TextUtils; import android.util.Log; +import org.apache.http.Header; import org.apache.http.auth.AuthScope; import org.apache.http.auth.UsernamePasswordCredentials; import org.apache.http.client.CredentialsProvider; @@ -33,6 +34,7 @@ import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.impl.client.LaxRedirectStrategy; import org.apache.http.impl.conn.BasicHttpClientConnectionManager; +import org.apache.http.message.BasicHeader; import org.thoughtcrime.securesms.database.ApnDatabase; import org.thoughtcrime.securesms.util.TelephonyUtil; import org.thoughtcrime.securesms.util.Conversions; @@ -45,6 +47,8 @@ import java.io.IOException; import java.io.InputStream; import java.net.InetAddress; import java.net.URL; +import java.util.LinkedList; +import java.util.List; public abstract class MmsConnection { private static final String TAG = "MmsCommunication"; @@ -168,6 +172,22 @@ public abstract class MmsConnection { protected abstract HttpUriRequest constructRequest(boolean useProxy) throws IOException; + protected List
getBaseHeaders() { + final String number = TelephonyUtil.getManager(context).getLine1Number(); + return new LinkedList
() {{ + add(new BasicHeader("Accept", "*/*, application/vnd.wap.mms-message, application/vnd.wap.sic")); + add(new BasicHeader("x-wap-profile", "http://www.google.com/oha/rdf/ua-profile-kila.xml")); + add(new BasicHeader("Content-Type", "application/vnd.wap.mms-message")); + add(new BasicHeader("x-carrier-magic", "http://magic.google.com")); + if (!TextUtils.isEmpty(number)) { + add(new BasicHeader("x-up-calling-line-id", number)); + add(new BasicHeader("X-MDN", number)); + } + }}; + + + } + public static class Apn { public static Apn EMPTY = new Apn("", "", "", "", ""); diff --git a/src/org/thoughtcrime/securesms/mms/OutgoingMmsConnection.java b/src/org/thoughtcrime/securesms/mms/OutgoingMmsConnection.java index 66a892089d..35b461f96a 100644 --- a/src/org/thoughtcrime/securesms/mms/OutgoingMmsConnection.java +++ b/src/org/thoughtcrime/securesms/mms/OutgoingMmsConnection.java @@ -20,13 +20,18 @@ import android.content.Context; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.net.Uri; +import android.telephony.TelephonyManager; +import android.text.TextUtils; import android.util.Log; +import org.apache.http.Header; import org.apache.http.HttpHost; import org.apache.http.client.config.RequestConfig; import org.apache.http.client.methods.HttpPostHC4; import org.apache.http.client.methods.HttpUriRequest; import org.apache.http.entity.ByteArrayEntityHC4; +import org.thoughtcrime.securesms.util.TelephonyUtil; +import org.thoughtcrime.securesms.util.Util; import java.io.IOException; @@ -49,9 +54,10 @@ public class OutgoingMmsConnection extends MmsConnection { { try { HttpPostHC4 request = new HttpPostHC4(apn.getMmsc()); - request.addHeader("Accept", "*/*, application/vnd.wap.mms-message, application/vnd.wap.sic"); - request.addHeader("x-wap-profile", "http://www.google.com/oha/rdf/ua-profile-kila.xml"); - request.addHeader("Content-Type", "application/vnd.wap.mms-message"); + for (Header header : getBaseHeaders()) { + request.addHeader(header); + } + request.setEntity(new ByteArrayEntityHC4(mms)); if (useProxy) { HttpHost proxy = new HttpHost(apn.getProxy(), apn.getPort()); diff --git a/src/org/thoughtcrime/securesms/util/TelephonyUtil.java b/src/org/thoughtcrime/securesms/util/TelephonyUtil.java index 9e3ee1db91..dedb56091a 100644 --- a/src/org/thoughtcrime/securesms/util/TelephonyUtil.java +++ b/src/org/thoughtcrime/securesms/util/TelephonyUtil.java @@ -9,6 +9,10 @@ import android.util.Log; public class TelephonyUtil { private static final String TAG = TelephonyUtil.class.getSimpleName(); + public static TelephonyManager getManager(final Context context) { + return (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE); + } + public static String getMccMnc(final Context context) { final TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); final int configMcc = context.getResources().getConfiguration().mcc;