Merge pull request #1437 from mcginty/mms-npe

prevent NPE in MMS logic
This commit is contained in:
Moxie Marlinspike 2014-05-01 13:05:01 -07:00
commit 7a3d509ef4

View File

@ -18,6 +18,7 @@ package org.thoughtcrime.securesms.mms;
import android.content.Context; import android.content.Context;
import android.net.ConnectivityManager; import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.http.AndroidHttpClient; import android.net.http.AndroidHttpClient;
import android.util.Log; import android.util.Log;
@ -36,6 +37,7 @@ import ws.com.google.android.mms.pdu.PduParser;
import ws.com.google.android.mms.pdu.SendConf; import ws.com.google.android.mms.pdu.SendConf;
public class MmsSendHelper extends MmsCommunication { public class MmsSendHelper extends MmsCommunication {
private final static String TAG = MmsSendHelper.class.getSimpleName();
private static byte[] makePost(Context context, MmsConnectionParameters parameters, byte[] mms) private static byte[] makePost(Context context, MmsConnectionParameters parameters, byte[] mms)
throws IOException throws IOException
@ -43,7 +45,7 @@ public class MmsSendHelper extends MmsCommunication {
AndroidHttpClient client = null; AndroidHttpClient client = null;
try { try {
Log.w("MmsSender", "Sending MMS1 of length: " + (mms != null ? mms.length : "null")); Log.w(TAG, "Sending MMS1 of length: " + (mms != null ? mms.length : "null"));
client = constructHttpClient(context, parameters); client = constructHttpClient(context, parameters);
URI targetUrl = new URI(parameters.getMmsc()); URI targetUrl = new URI(parameters.getMmsc());
@ -68,7 +70,7 @@ public class MmsSendHelper extends MmsCommunication {
return parseResponse(response.getEntity()); return parseResponse(response.getEntity());
} catch (URISyntaxException use) { } catch (URISyntaxException use) {
Log.w("MmsSendHelper", use); Log.w(TAG, use);
throw new IOException("Couldn't parse URI."); throw new IOException("Couldn't parse URI.");
} finally { } finally {
if (client != null) if (client != null)
@ -100,13 +102,13 @@ public class MmsSendHelper extends MmsCommunication {
boolean usingMmsRadio, boolean useProxyIfAvailable) boolean usingMmsRadio, boolean useProxyIfAvailable)
throws IOException throws IOException
{ {
Log.w("MmsSender", "Sending MMS of length: " + mms.length); Log.w(TAG, "Sending MMS of length: " + mms.length);
try { try {
MmsConnectionParameters parameters = getMmsConnectionParameters(context, apn, useProxyIfAvailable); MmsConnectionParameters parameters = getMmsConnectionParameters(context, apn, useProxyIfAvailable);
checkRouteToHost(context, parameters, parameters.getMmsc(), usingMmsRadio); checkRouteToHost(context, parameters, parameters.getMmsc(), usingMmsRadio);
return makePost(context, parameters, mms); return makePost(context, parameters, mms);
} catch (ApnUnavailableException aue) { } catch (ApnUnavailableException aue) {
Log.w("MmsSender", aue); Log.w(TAG, aue);
throw new IOException("Failed to get MMSC information..."); throw new IOException("Failed to get MMSC information...");
} }
} }
@ -114,7 +116,12 @@ public class MmsSendHelper extends MmsCommunication {
public static boolean hasNecessaryApnDetails(Context context) { public static boolean hasNecessaryApnDetails(Context context) {
try { try {
ConnectivityManager connectivityManager = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE); ConnectivityManager connectivityManager = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
String apn = connectivityManager.getNetworkInfo(MmsRadio.TYPE_MOBILE_MMS).getExtraInfo(); NetworkInfo networkInfo = connectivityManager.getNetworkInfo(MmsRadio.TYPE_MOBILE_MMS);
if (networkInfo == null) {
Log.w(TAG, "MMS network info was null, unsupported by this device");
return false;
}
String apn = networkInfo.getExtraInfo();
MmsCommunication.getMmsConnectionParameters(context, apn, true); MmsCommunication.getMmsConnectionParameters(context, apn, true);
return true; return true;