mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-27 12:05:22 +00:00
support mms basic auth
// FREEBIE
This commit is contained in:
parent
5002a749cf
commit
f3f173f653
@ -645,6 +645,8 @@
|
||||
<string name="preferences__mmsc_url_required">MMSC URL (Required)</string>
|
||||
<string name="preferences__mms_proxy_host_optional">MMS Proxy Host (Optional)</string>
|
||||
<string name="preferences__mms_proxy_port_optional">MMS Proxy Port (Optional)</string>
|
||||
<string name="preferences__mmsc_username_optional">MMSC Username (Optional)</string>
|
||||
<string name="preferences__mmsc_password_optional">MMSC Password (Optional)</string>
|
||||
<string name="preferences__sms_delivery_reports">SMS delivery reports</string>
|
||||
<string name="preferences__request_a_delivery_report_for_each_sms_message_you_send">Request a delivery report for each SMS message you send</string>
|
||||
<string name="preferences__automatically_delete_older_messages_once_a_conversation_thread_exceeds_a_specified_length">Automatically delete older messages once a conversation thread exceeds a specified length</string>
|
||||
|
@ -20,4 +20,14 @@
|
||||
android:title="@string/preferences__mms_proxy_port_optional"
|
||||
android:dependency="pref_enable_manual_mms"
|
||||
android:inputType="number" />
|
||||
|
||||
<EditTextPreference android:key="pref_apn_mmsc_username"
|
||||
android:title="@string/preferences__mmsc_username_optional"
|
||||
android:dependency="pref_enable_manual_mms"
|
||||
android:inputType="textNoSuggestions" />
|
||||
|
||||
<EditTextPreference android:key="pref_apn_mmsc_password"
|
||||
android:title="@string/preferences__mmsc_password_optional"
|
||||
android:dependency="pref_enable_manual_mms"
|
||||
android:inputType="textVisiblePassword" />
|
||||
</PreferenceScreen>
|
@ -65,6 +65,8 @@ public class MmsPreferencesFragment extends PreferenceFragment {
|
||||
initializeEditTextSummary((EditTextPreference)this.findPreference(TextSecurePreferences.MMSC_HOST_PREF));
|
||||
initializeEditTextSummary((EditTextPreference)this.findPreference(TextSecurePreferences.MMSC_PROXY_HOST_PREF));
|
||||
initializeEditTextSummary((EditTextPreference)this.findPreference(TextSecurePreferences.MMSC_PROXY_PORT_PREF));
|
||||
initializeEditTextSummary((EditTextPreference)this.findPreference(TextSecurePreferences.MMSC_USERNAME_PREF));
|
||||
initializeEditTextSummary((EditTextPreference)this.findPreference(TextSecurePreferences.MMSC_PASSWORD_PREF));
|
||||
}
|
||||
|
||||
private class OverrideMmsChangeListener implements Preference.OnPreferenceChangeListener {
|
||||
|
@ -104,8 +104,10 @@ public class ApnDatabase {
|
||||
|
||||
String proxy = TextSecurePreferences.getMmscProxy(context);
|
||||
String port = TextSecurePreferences.getMmscProxyPort(context);
|
||||
String user = TextSecurePreferences.getMmscUsername(context);
|
||||
String pass = TextSecurePreferences.getMmscPassword(context);
|
||||
|
||||
return new Apn(mmsc, proxy, port);
|
||||
return new Apn(mmsc, proxy, port, user, pass);
|
||||
}
|
||||
|
||||
throw new ApnUnavailableException("No locally configured parameters available");
|
||||
@ -151,7 +153,9 @@ public class ApnDatabase {
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
Apn params = new Apn(cursor.getString(cursor.getColumnIndexOrThrow(MMSC_COLUMN)),
|
||||
cursor.getString(cursor.getColumnIndexOrThrow(MMS_PROXY_COLUMN)),
|
||||
cursor.getString(cursor.getColumnIndexOrThrow(MMS_PORT_COLUMN)));
|
||||
cursor.getString(cursor.getColumnIndexOrThrow(MMS_PORT_COLUMN)),
|
||||
cursor.getString(cursor.getColumnIndexOrThrow(USER_COLUMN)),
|
||||
cursor.getString(cursor.getColumnIndexOrThrow(PASSWORD_COLUMN)));
|
||||
Log.w(TAG, "Returning preferred APN " + params);
|
||||
return params;
|
||||
}
|
||||
|
@ -192,7 +192,7 @@ public class MmsDownloadJob extends MasterSecretJob {
|
||||
InvalidMessageException, LegacyMessageException
|
||||
{
|
||||
Apn dbApn = MmsConnection.getApn(context, radio.getApnInformation());
|
||||
Apn contentApn = new Apn(contentLocation, dbApn.getProxy(), Integer.toString(dbApn.getPort()));
|
||||
Apn contentApn = new Apn(contentLocation, dbApn.getProxy(), Integer.toString(dbApn.getPort()), dbApn.getUsername(), dbApn.getPassword());
|
||||
IncomingMmsConnection connection = new IncomingMmsConnection(context, contentApn);
|
||||
RetrieveConf retrieved = connection.retrieve(radioEnabled, useProxy);
|
||||
|
||||
|
@ -21,10 +21,14 @@ import android.net.ConnectivityManager;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import org.apache.http.auth.AuthScope;
|
||||
import org.apache.http.auth.UsernamePasswordCredentials;
|
||||
import org.apache.http.client.CredentialsProvider;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpUriRequest;
|
||||
import org.apache.http.impl.NoConnectionReuseStrategyHC4;
|
||||
import org.apache.http.impl.client.BasicCredentialsProvider;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.impl.client.LaxRedirectStrategy;
|
||||
@ -39,6 +43,7 @@ import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.InetAddress;
|
||||
import java.net.URL;
|
||||
|
||||
public abstract class MmsConnection {
|
||||
private static final String TAG = "MmsCommunication";
|
||||
@ -116,12 +121,21 @@ public abstract class MmsConnection {
|
||||
.setMaxRedirects(20)
|
||||
.build();
|
||||
|
||||
URL mmsc = new URL(apn.getMmsc());
|
||||
CredentialsProvider credsProvider = new BasicCredentialsProvider();
|
||||
|
||||
if (apn.hasAuthentication()) {
|
||||
credsProvider.setCredentials(new AuthScope(mmsc.getHost(), mmsc.getPort() > -1 ? mmsc.getPort() : mmsc.getDefaultPort()),
|
||||
new UsernamePasswordCredentials(apn.getUsername(), apn.getPassword()));
|
||||
}
|
||||
|
||||
return HttpClients.custom()
|
||||
.setConnectionReuseStrategy(new NoConnectionReuseStrategyHC4())
|
||||
.setRedirectStrategy(new LaxRedirectStrategy())
|
||||
.setUserAgent("Android-Mms/2.0")
|
||||
.setConnectionManager(new BasicHttpClientConnectionManager())
|
||||
.setDefaultRequestConfig(config)
|
||||
.setDefaultCredentialsProvider(credsProvider)
|
||||
.build();
|
||||
}
|
||||
|
||||
@ -155,11 +169,15 @@ public abstract class MmsConnection {
|
||||
private final String mmsc;
|
||||
private final String proxy;
|
||||
private final String port;
|
||||
private final String username;
|
||||
private final String password;
|
||||
|
||||
public Apn(String mmsc, String proxy, String port) {
|
||||
this.mmsc = mmsc;
|
||||
this.proxy = proxy;
|
||||
this.port = port;
|
||||
public Apn(String mmsc, String proxy, String port, String username, String password) {
|
||||
this.mmsc = mmsc;
|
||||
this.proxy = proxy;
|
||||
this.port = port;
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public boolean hasProxy() {
|
||||
@ -178,12 +196,26 @@ public abstract class MmsConnection {
|
||||
return TextUtils.isEmpty(port) ? 80 : Integer.parseInt(port);
|
||||
}
|
||||
|
||||
public boolean hasAuthentication() {
|
||||
return !TextUtils.isEmpty(username) || !TextUtils.isEmpty(password);
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return Apn.class.getSimpleName() +
|
||||
"{ mmsc: \"" + mmsc + "\"" +
|
||||
", proxy: " + (proxy == null ? "none" : '"' + proxy + '"') +
|
||||
", port: " + (port == null ? "none" : port) + " }";
|
||||
", port: " + (port == null ? "(none)" : port) +
|
||||
", user: " + (username == null ? "none" : '"' + username + '"') +
|
||||
", pass: " + (password == null ? "none" : '"' + password + '"') + " }";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,8 @@ public class TextSecurePreferences {
|
||||
public static final String MMSC_HOST_PREF = "pref_apn_mmsc_host";
|
||||
public static final String MMSC_PROXY_HOST_PREF = "pref_apn_mms_proxy";
|
||||
public static final String MMSC_PROXY_PORT_PREF = "pref_apn_mms_proxy_port";
|
||||
public static final String MMSC_USERNAME_PREF = "pref_apn_mmsc_username";
|
||||
public static final String MMSC_PASSWORD_PREF = "pref_apn_mmsc_password";
|
||||
public static final String THREAD_TRIM_LENGTH = "pref_trim_length";
|
||||
public static final String THREAD_TRIM_NOW = "pref_trim_now";
|
||||
public static final String ENABLE_MANUAL_MMS_PREF = "pref_enable_manual_mms";
|
||||
@ -177,6 +179,14 @@ public class TextSecurePreferences {
|
||||
return getStringPreference(context, MMSC_PROXY_PORT_PREF, "");
|
||||
}
|
||||
|
||||
public static String getMmscUsername(Context context) {
|
||||
return getStringPreference(context, MMSC_USERNAME_PREF, "");
|
||||
}
|
||||
|
||||
public static String getMmscPassword(Context context) {
|
||||
return getStringPreference(context, MMSC_PASSWORD_PREF, "");
|
||||
}
|
||||
|
||||
public static String getIdentityContactUri(Context context) {
|
||||
return getStringPreference(context, IDENTITY_PREF, null);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user