2015-02-16 20:31:44 -08:00
|
|
|
/**
|
|
|
|
* Copyright (C) 2014 Open Whisper Systems
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
package org.thoughtcrime.securesms.preferences;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.os.AsyncTask;
|
|
|
|
import android.os.Bundle;
|
2020-08-19 10:06:26 +10:00
|
|
|
import androidx.annotation.Nullable;
|
2015-02-16 20:31:44 -08:00
|
|
|
|
|
|
|
import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity;
|
2019-07-24 12:30:23 +10:00
|
|
|
import network.loki.messenger.R;
|
2015-02-16 20:31:44 -08:00
|
|
|
import org.thoughtcrime.securesms.components.CustomDefaultPreference;
|
|
|
|
import org.thoughtcrime.securesms.database.ApnDatabase;
|
2018-08-01 11:09:24 -04:00
|
|
|
import org.thoughtcrime.securesms.logging.Log;
|
2014-12-29 14:01:02 -08:00
|
|
|
import org.thoughtcrime.securesms.mms.LegacyMmsConnection;
|
2015-02-16 20:31:44 -08:00
|
|
|
import org.thoughtcrime.securesms.util.TelephonyUtil;
|
|
|
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
|
2017-09-20 18:10:44 -07:00
|
|
|
public class MmsPreferencesFragment extends CorrectedPreferenceFragment {
|
2015-02-16 20:31:44 -08:00
|
|
|
|
|
|
|
private static final String TAG = MmsPreferencesFragment.class.getSimpleName();
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle paramBundle) {
|
|
|
|
super.onCreate(paramBundle);
|
|
|
|
|
|
|
|
((PassphraseRequiredActionBarActivity) getActivity()).getSupportActionBar()
|
|
|
|
.setTitle(R.string.preferences__advanced_mms_access_point_names);
|
|
|
|
}
|
|
|
|
|
2017-09-20 18:10:44 -07:00
|
|
|
@Override
|
|
|
|
public void onCreatePreferences(@Nullable Bundle savedInstanceState, String rootKey) {
|
|
|
|
addPreferencesFromResource(R.xml.preferences_manual_mms);
|
|
|
|
}
|
|
|
|
|
2015-02-16 20:31:44 -08:00
|
|
|
@Override
|
|
|
|
public void onResume() {
|
|
|
|
super.onResume();
|
2017-10-23 13:03:32 -07:00
|
|
|
new LoadApnDefaultsTask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
2015-02-16 20:31:44 -08:00
|
|
|
}
|
|
|
|
|
2014-12-29 14:01:02 -08:00
|
|
|
private class LoadApnDefaultsTask extends AsyncTask<Void, Void, LegacyMmsConnection.Apn> {
|
2015-02-16 20:31:44 -08:00
|
|
|
|
|
|
|
@Override
|
2014-12-29 14:01:02 -08:00
|
|
|
protected LegacyMmsConnection.Apn doInBackground(Void... params) {
|
2015-02-16 20:31:44 -08:00
|
|
|
try {
|
|
|
|
Context context = getActivity();
|
|
|
|
|
|
|
|
if (context != null) {
|
|
|
|
return ApnDatabase.getInstance(context)
|
|
|
|
.getDefaultApnParameters(TelephonyUtil.getMccMnc(context),
|
|
|
|
TelephonyUtil.getApn(context));
|
|
|
|
}
|
|
|
|
} catch (IOException e) {
|
|
|
|
Log.w(TAG, e);
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-12-29 14:01:02 -08:00
|
|
|
protected void onPostExecute(LegacyMmsConnection.Apn apnDefaults) {
|
2015-02-16 20:31:44 -08:00
|
|
|
((CustomDefaultPreference)findPreference(TextSecurePreferences.MMSC_HOST_PREF))
|
2017-09-20 18:10:44 -07:00
|
|
|
.setValidator(new CustomDefaultPreference.CustomDefaultPreferenceDialogFragmentCompat.UriValidator())
|
2015-02-16 20:31:44 -08:00
|
|
|
.setDefaultValue(apnDefaults.getMmsc());
|
|
|
|
|
|
|
|
((CustomDefaultPreference)findPreference(TextSecurePreferences.MMSC_PROXY_HOST_PREF))
|
2017-09-20 18:10:44 -07:00
|
|
|
.setValidator(new CustomDefaultPreference.CustomDefaultPreferenceDialogFragmentCompat.HostnameValidator())
|
2015-02-16 20:31:44 -08:00
|
|
|
.setDefaultValue(apnDefaults.getProxy());
|
|
|
|
|
|
|
|
((CustomDefaultPreference)findPreference(TextSecurePreferences.MMSC_PROXY_PORT_PREF))
|
2017-09-20 18:10:44 -07:00
|
|
|
.setValidator(new CustomDefaultPreference.CustomDefaultPreferenceDialogFragmentCompat.PortValidator())
|
2015-02-16 20:31:44 -08:00
|
|
|
.setDefaultValue(apnDefaults.getPort());
|
|
|
|
|
|
|
|
((CustomDefaultPreference)findPreference(TextSecurePreferences.MMSC_USERNAME_PREF))
|
|
|
|
.setDefaultValue(apnDefaults.getPort());
|
|
|
|
|
|
|
|
((CustomDefaultPreference)findPreference(TextSecurePreferences.MMSC_PASSWORD_PREF))
|
|
|
|
.setDefaultValue(apnDefaults.getPassword());
|
2015-01-17 22:10:46 -05:00
|
|
|
|
|
|
|
((CustomDefaultPreference)findPreference(TextSecurePreferences.MMS_USER_AGENT))
|
|
|
|
.setDefaultValue(LegacyMmsConnection.USER_AGENT);
|
2015-02-16 20:31:44 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|