mirror of
https://github.com/oxen-io/session-android.git
synced 2025-12-03 12:02:18 +00:00
Support granular "custom" MMS preferences.
1) Make each MMS preference an individual choice between custom and default. 2) Display default values. Closes #2487 // FREEBIE
This commit is contained in:
@@ -27,6 +27,7 @@ import org.thoughtcrime.securesms.mms.ApnUnavailableException;
|
||||
import org.thoughtcrime.securesms.mms.MmsConnection.Apn;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.whispersystems.libaxolotl.util.guava.Optional;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
@@ -93,13 +94,11 @@ public class ApnDatabase {
|
||||
null,
|
||||
SQLiteDatabase.OPEN_READONLY | SQLiteDatabase.NO_LOCALIZED_COLLATORS);
|
||||
}
|
||||
protected Apn getLocallyConfiguredMmsConnectionParameters() throws ApnUnavailableException {
|
||||
if (TextSecurePreferences.isUseLocalApnsEnabled(context)) {
|
||||
String mmsc = TextSecurePreferences.getMmscUrl(context).trim();
|
||||
if (TextUtils.isEmpty(mmsc))
|
||||
throw new ApnUnavailableException("Malformed locally configured MMSC.");
|
||||
|
||||
if (!mmsc.startsWith("http"))
|
||||
private Apn getCustomApnParameters() {
|
||||
String mmsc = TextSecurePreferences.getMmscUrl(context).trim();
|
||||
|
||||
if (!TextUtils.isEmpty(mmsc) && !mmsc.startsWith("http"))
|
||||
mmsc = "http://" + mmsc;
|
||||
|
||||
String proxy = TextSecurePreferences.getMmscProxy(context);
|
||||
@@ -108,26 +107,12 @@ public class ApnDatabase {
|
||||
String pass = TextSecurePreferences.getMmscPassword(context);
|
||||
|
||||
return new Apn(mmsc, proxy, port, user, pass);
|
||||
}
|
||||
|
||||
throw new ApnUnavailableException("No locally configured parameters available");
|
||||
|
||||
}
|
||||
|
||||
public Apn getMmsConnectionParameters(final String mccmnc, final String apn) {
|
||||
|
||||
if (TextSecurePreferences.isUseLocalApnsEnabled(context)) {
|
||||
Log.w(TAG, "Choosing locally-overridden MMS settings");
|
||||
try {
|
||||
return getLocallyConfiguredMmsConnectionParameters();
|
||||
} catch (ApnUnavailableException aue) {
|
||||
Log.w(TAG, "preference to use local apn set, but no parameters avaiable. falling back.");
|
||||
}
|
||||
}
|
||||
|
||||
public Apn getDefaultApnParameters(String mccmnc, String apn) {
|
||||
if (mccmnc == null) {
|
||||
Log.w(TAG, "mccmnc was null, returning null");
|
||||
return null;
|
||||
return Apn.EMPTY;
|
||||
}
|
||||
|
||||
Cursor cursor = null;
|
||||
@@ -161,9 +146,25 @@ public class ApnDatabase {
|
||||
}
|
||||
|
||||
Log.w(TAG, "No matching APNs found, returning null");
|
||||
return null;
|
||||
|
||||
return Apn.EMPTY;
|
||||
} finally {
|
||||
if (cursor != null) cursor.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Optional<Apn> getMmsConnectionParameters(String mccmnc, String apn) {
|
||||
Apn customApn = getCustomApnParameters();
|
||||
Apn defaultApn = getDefaultApnParameters(mccmnc, apn);
|
||||
Apn result = new Apn(customApn, defaultApn,
|
||||
TextSecurePreferences.getUseCustomMmsc(context),
|
||||
TextSecurePreferences.getUseCustomMmscProxy(context),
|
||||
TextSecurePreferences.getUseCustomMmscProxyPort(context),
|
||||
TextSecurePreferences.getUseCustomMmscUsername(context),
|
||||
TextSecurePreferences.getUseCustomMmscPassword(context));
|
||||
|
||||
if (TextUtils.isEmpty(result.getMmsc())) return Optional.absent();
|
||||
else return Optional.of(result);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user