mirror of
https://github.com/oxen-io/session-android.git
synced 2025-05-01 12:00:46 +00:00
Use APN defaults when no other APN information is available.
Provides an in-app source for APN info for use in the case that the device store is unavailable and the user hasn't provided local connection parameters. Only covers T-Moble USA, AT&T, and Verizon right now. Only T-Mobile is tested. Other carriers can be added and tested on an ongoing basis.
This commit is contained in:
parent
fb21c09dbe
commit
8e2288205c
38
src/org/thoughtcrime/securesms/mms/ApnDefaults.java
Normal file
38
src/org/thoughtcrime/securesms/mms/ApnDefaults.java
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
package org.thoughtcrime.securesms.mms;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.telephony.TelephonyManager;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static org.thoughtcrime.securesms.mms.MmsCommunication.MmsConnectionParameters;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class provides an in-app source for APN MMSC info for use as a fallback in
|
||||||
|
* the event that the system APN DB is unavailable and the user has not provided
|
||||||
|
* local MMSC configuration details of their own.
|
||||||
|
*/
|
||||||
|
public class ApnDefaults {
|
||||||
|
|
||||||
|
private static final Map<String, MmsConnectionParameters> paramMap =
|
||||||
|
new HashMap<String, MmsConnectionParameters>(){{
|
||||||
|
|
||||||
|
//T-Mobile USA - Tested: Works
|
||||||
|
put("310260", new MmsConnectionParameters("http://mms.msg.eng.t-mobile.com/mms/wapenc", null, null));
|
||||||
|
|
||||||
|
//AT&T - Untested
|
||||||
|
put("310410", new MmsConnectionParameters("http://mmsc.cingular.com/", "wireless.cingular.com", "80"));
|
||||||
|
|
||||||
|
//Verizon - Untested
|
||||||
|
put("310004", new MmsConnectionParameters("http://mms.vtext.com/servlets/mms", null, null));
|
||||||
|
put("310005", new MmsConnectionParameters("http://mms.vtext.com/servlets/mms", null, null));
|
||||||
|
put("310012", new MmsConnectionParameters("http://mms.vtext.com/servlets/mms", null, null));
|
||||||
|
|
||||||
|
}};
|
||||||
|
|
||||||
|
public static MmsConnectionParameters getMmsConnectionParameters(Context context) {
|
||||||
|
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
|
||||||
|
return paramMap.get(tm.getSimOperator());
|
||||||
|
}
|
||||||
|
}
|
@ -64,6 +64,24 @@ public class MmsCommunication {
|
|||||||
throw new ApnUnavailableException("No locally configured parameters available");
|
throw new ApnUnavailableException("No locally configured parameters available");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected static MmsConnectionParameters getLocalMmsConnectionParameters(Context context)
|
||||||
|
throws ApnUnavailableException
|
||||||
|
{
|
||||||
|
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
|
|
||||||
|
if (preferences.getBoolean(ApplicationPreferencesActivity.USE_LOCAL_MMS_APNS_PREF, false)) {
|
||||||
|
return getLocallyConfiguredMmsConnectionParameters(context);
|
||||||
|
} else {
|
||||||
|
MmsConnectionParameters params = ApnDefaults.getMmsConnectionParameters(context);
|
||||||
|
|
||||||
|
if (params == null) {
|
||||||
|
throw new ApnUnavailableException("No parameters available from ApnDefaults.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return params;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected static MmsConnectionParameters getMmsConnectionParameters(Context context, String apn,
|
protected static MmsConnectionParameters getMmsConnectionParameters(Context context, String apn,
|
||||||
boolean proxyIfPossible)
|
boolean proxyIfPossible)
|
||||||
throws ApnUnavailableException
|
throws ApnUnavailableException
|
||||||
@ -74,7 +92,7 @@ public class MmsCommunication {
|
|||||||
cursor = DatabaseFactory.getMmsDatabase(context).getCarrierMmsInformation(apn);
|
cursor = DatabaseFactory.getMmsDatabase(context).getCarrierMmsInformation(apn);
|
||||||
|
|
||||||
if (cursor == null || !cursor.moveToFirst())
|
if (cursor == null || !cursor.moveToFirst())
|
||||||
return getLocallyConfiguredMmsConnectionParameters(context);
|
return getLocalMmsConnectionParameters(context);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
String mmsc = cursor.getString(cursor.getColumnIndexOrThrow("mmsc"));
|
String mmsc = cursor.getString(cursor.getColumnIndexOrThrow("mmsc"));
|
||||||
@ -91,16 +109,16 @@ public class MmsCommunication {
|
|||||||
|
|
||||||
} while (cursor.moveToNext());
|
} while (cursor.moveToNext());
|
||||||
|
|
||||||
return getLocallyConfiguredMmsConnectionParameters(context);
|
return getLocalMmsConnectionParameters(context);
|
||||||
} catch (SQLiteException sqe) {
|
} catch (SQLiteException sqe) {
|
||||||
Log.w("MmsCommunication", sqe);
|
Log.w("MmsCommunication", sqe);
|
||||||
return getLocallyConfiguredMmsConnectionParameters(context);
|
return getLocalMmsConnectionParameters(context);
|
||||||
} catch (SecurityException se) {
|
} catch (SecurityException se) {
|
||||||
Log.w("MmsCommunication", se);
|
Log.w("MmsCommunication", se);
|
||||||
return getLocallyConfiguredMmsConnectionParameters(context);
|
return getLocalMmsConnectionParameters(context);
|
||||||
} catch (IllegalArgumentException iae) {
|
} catch (IllegalArgumentException iae) {
|
||||||
Log.w("MmsCommunication", iae);
|
Log.w("MmsCommunication", iae);
|
||||||
return getLocallyConfiguredMmsConnectionParameters(context);
|
return getLocalMmsConnectionParameters(context);
|
||||||
} finally {
|
} finally {
|
||||||
if (cursor != null)
|
if (cursor != null)
|
||||||
cursor.close();
|
cursor.close();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user