mirror of
https://github.com/oxen-io/session-android.git
synced 2025-10-26 11:21:55 +00:00
Enhanced MMS configuration prompts and processing.
1) Added a new message status to MmsDatabase to signify a pending MMS download which requires APN settings. 2) Added a database method to query MMS messages based on status. 3) Added login to SendReceiveService for processing of MMS pending APN information. 4) Moved all APN/MMS settings into ApnPreferencesActivity and transformed PromptApnActivity into a simple informational activity. 5) Added logic to check for APN settings on send and receive of all MMS (media, group, email) and direct user to PromptApnActivity then ApnPreferencesActivity if necessary. 6) Vocab/grammar adjustments.
This commit is contained in:
committed by
Moxie Marlinspike
parent
f3fdde6040
commit
2c2a03e5e2
@@ -79,10 +79,11 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredSherlockPr
|
||||
private static final String CHANGE_PASSPHRASE_PREF = "pref_change_passphrase";
|
||||
public static final String DISABLE_PASSPHRASE_PREF = "pref_disable_passphrase";
|
||||
|
||||
public static final String USE_LOCAL_MMS_APNS_PREF = "pref_use_local_apns";
|
||||
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 MMS_PREF = "pref_mms_preferences";
|
||||
public static final String ENABLE_MANUAL_MMS_PREF = "pref_enable_manual_mms";
|
||||
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 SMS_DELIVERY_REPORT_PREF = "pref_delivery_report_sms";
|
||||
|
||||
@@ -109,7 +110,6 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredSherlockPr
|
||||
addPreferencesFromResource(R.xml.preferences);
|
||||
|
||||
initializeIdentitySelection();
|
||||
initializeEditTextSummaries();
|
||||
|
||||
this.findPreference(CHANGE_PASSPHRASE_PREF)
|
||||
.setOnPreferenceClickListener(new ChangePassphraseClickListener());
|
||||
@@ -119,6 +119,8 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredSherlockPr
|
||||
.setOnPreferenceChangeListener(new TrimLengthValidationListener());
|
||||
this.findPreference(DISABLE_PASSPHRASE_PREF)
|
||||
.setOnPreferenceChangeListener(new DisablePassphraseClickListener());
|
||||
this.findPreference(MMS_PREF)
|
||||
.setOnPreferenceClickListener(new ApnPreferencesClickListener());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -174,28 +176,6 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredSherlockPr
|
||||
return false;
|
||||
}
|
||||
|
||||
private void initializeEditTextSummary(final EditTextPreference preference) {
|
||||
if (preference.getText() == null) {
|
||||
preference.setSummary("Not set");
|
||||
} else {
|
||||
preference.setSummary(preference.getText());
|
||||
}
|
||||
|
||||
preference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference pref, Object newValue) {
|
||||
preference.setSummary(newValue == null ? "Not set" : ((String) newValue));
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void initializeEditTextSummaries() {
|
||||
initializeEditTextSummary((EditTextPreference)this.findPreference(MMSC_HOST_PREF));
|
||||
initializeEditTextSummary((EditTextPreference)this.findPreference(MMSC_PROXY_HOST_PREF));
|
||||
initializeEditTextSummary((EditTextPreference)this.findPreference(MMSC_PROXY_PORT_PREF));
|
||||
}
|
||||
|
||||
private void initializeIdentitySelection() {
|
||||
ContactIdentityManager identity = ContactIdentityManager.getInstance(this);
|
||||
|
||||
@@ -363,6 +343,15 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredSherlockPr
|
||||
|
||||
}
|
||||
|
||||
private class ApnPreferencesClickListener implements Preference.OnPreferenceClickListener {
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
startActivity(new Intent(ApplicationPreferencesActivity.this, MmsPreferencesActivity.class));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/* http://code.google.com/p/android/issues/detail?id=4611#c35 */
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
|
||||
@@ -465,10 +465,18 @@ public class ConversationActivity extends PassphraseRequiredSherlockFragmentActi
|
||||
builder.setAdapter(attachmentAdapter, new AttachmentTypeListener());
|
||||
builder.show();
|
||||
} else {
|
||||
startActivity(new Intent(this, PromptApnActivity.class));
|
||||
handleManualMmsRequired();
|
||||
}
|
||||
}
|
||||
|
||||
private void handleManualMmsRequired() {
|
||||
Toast.makeText(this, R.string.MmsDownloader_error_reading_mms_settings, Toast.LENGTH_LONG).show();
|
||||
|
||||
Intent intent = new Intent(this, PromptMmsActivity.class);
|
||||
intent.putExtras(getIntent().getExtras());
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
///// Initializers
|
||||
|
||||
private void initializeTitleBar() {
|
||||
@@ -849,7 +857,10 @@ public class ConversationActivity extends PassphraseRequiredSherlockFragmentActi
|
||||
String body = getMessage();
|
||||
long allocatedThreadId;
|
||||
|
||||
if (attachmentManager.isAttachmentPresent()) {
|
||||
if ((!recipients.isSingleRecipient() || recipients.isEmailRecipient()) && !isMmsEnabled) {
|
||||
handleManualMmsRequired();
|
||||
return;
|
||||
} else if (attachmentManager.isAttachmentPresent()) {
|
||||
allocatedThreadId = MessageSender.sendMms(ConversationActivity.this, masterSecret, recipients,
|
||||
threadId, attachmentManager.getSlideDeck(), body,
|
||||
distributionType, isEncryptedConversation && !forcePlaintext);
|
||||
@@ -870,7 +881,6 @@ public class ConversationActivity extends PassphraseRequiredSherlockFragmentActi
|
||||
allocatedThreadId = MessageSender.send(ConversationActivity.this, masterSecret,
|
||||
message, threadId);
|
||||
}
|
||||
|
||||
sendComplete(recipients, allocatedThreadId);
|
||||
} catch (RecipientFormattingException ex) {
|
||||
Toast.makeText(ConversationActivity.this,
|
||||
|
||||
@@ -92,10 +92,11 @@ public class ConversationItem extends LinearLayout {
|
||||
private TextView mmsDownloadingLabel;
|
||||
private ListenableFutureTask<SlideDeck> slideDeck;
|
||||
|
||||
private final FailedIconClickListener failedIconClickListener = new FailedIconClickListener();
|
||||
private final MmsDownloadClickListener mmsDownloadClickListener = new MmsDownloadClickListener();
|
||||
private final ClickListener clickListener = new ClickListener();
|
||||
private final Handler handler = new Handler();
|
||||
private final FailedIconClickListener failedIconClickListener = new FailedIconClickListener();
|
||||
private final MmsDownloadClickListener mmsDownloadClickListener = new MmsDownloadClickListener();
|
||||
private final MmsPreferencesClickListener mmsPreferencesClickListener = new MmsPreferencesClickListener();
|
||||
private final ClickListener clickListener = new ClickListener();
|
||||
private final Handler handler = new Handler();
|
||||
private final Context context;
|
||||
|
||||
public ConversationItem(Context context) {
|
||||
@@ -168,7 +169,7 @@ public class ConversationItem extends LinearLayout {
|
||||
|
||||
private void setBodyText(MessageRecord messageRecord) {
|
||||
bodyText.setText(Emoji.getInstance(context).emojify(messageRecord.getDisplayBody(), Emoji.EMOJI_LARGE),
|
||||
TextView.BufferType.SPANNABLE);
|
||||
TextView.BufferType.SPANNABLE);
|
||||
}
|
||||
|
||||
private void setContactPhoto(MessageRecord messageRecord) {
|
||||
@@ -203,8 +204,8 @@ public class ConversationItem extends LinearLayout {
|
||||
|
||||
if (!messageRecord.isOutgoing() && messageRecord.getRecipients().isSingleRecipient()) {
|
||||
checkForAutoInitiate(messageRecord.getIndividualRecipient(),
|
||||
messageRecord.getBody().getBody(),
|
||||
messageRecord.getThreadId());
|
||||
messageRecord.getBody().getBody(),
|
||||
messageRecord.getThreadId());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -236,6 +237,11 @@ public class ConversationItem extends LinearLayout {
|
||||
mmsDownloadingLabel.setText(MmsDatabase.Status.getLabelForStatus(context, messageRecord.getStatus()));
|
||||
mmsDownloadButton.setVisibility(View.GONE);
|
||||
mmsDownloadingLabel.setVisibility(View.VISIBLE);
|
||||
|
||||
if (MmsDatabase.Status.isHardError(messageRecord.getStatus()) && !messageRecord.isOutgoing())
|
||||
setOnClickListener(mmsDownloadClickListener);
|
||||
else if (MmsDatabase.Status.DOWNLOAD_APN_UNAVAILABLE == messageRecord.getStatus() && !messageRecord.isOutgoing())
|
||||
setOnClickListener(mmsPreferencesClickListener);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -313,7 +319,7 @@ public class ConversationItem extends LinearLayout {
|
||||
if (recipient.getContactUri() != null) {
|
||||
QuickContact.showQuickContact(context, contactPhoto, recipient.getContactUri(), QuickContact.MODE_LARGE, null);
|
||||
} else {
|
||||
Intent intent = new Intent(Intents.SHOW_OR_CREATE_CONTACT, Uri.fromParts("tel", recipient.getNumber(), null));
|
||||
Intent intent = new Intent(Intents.SHOW_OR_CREATE_CONTACT, Uri.fromParts("tel", recipient.getNumber(), null));
|
||||
context.startActivity(intent);
|
||||
}
|
||||
}
|
||||
@@ -504,6 +510,16 @@ public class ConversationItem extends LinearLayout {
|
||||
}
|
||||
}
|
||||
|
||||
private class MmsPreferencesClickListener implements View.OnClickListener {
|
||||
public void onClick(View v) {
|
||||
Intent intent = new Intent(context, PromptMmsActivity.class);
|
||||
intent.putExtra("message_id", messageRecord.getId());
|
||||
intent.putExtra("thread_id", messageRecord.getThreadId());
|
||||
intent.putExtra("automatic", true);
|
||||
context.startActivity(intent);
|
||||
}
|
||||
}
|
||||
|
||||
private class FailedIconClickListener implements View.OnClickListener {
|
||||
public void onClick(View v) {
|
||||
if (failedIconHandler != null && !messageRecord.isKeyExchange()) {
|
||||
|
||||
136
src/org/thoughtcrime/securesms/MmsPreferencesActivity.java
Normal file
136
src/org/thoughtcrime/securesms/MmsPreferencesActivity.java
Normal file
@@ -0,0 +1,136 @@
|
||||
/**
|
||||
* Copyright (C) 2011 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;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.preference.EditTextPreference;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.actionbarsherlock.view.MenuItem;
|
||||
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
||||
import org.thoughtcrime.securesms.mms.MmsDownloadHelper;
|
||||
import org.thoughtcrime.securesms.service.SendReceiveService;
|
||||
import org.thoughtcrime.securesms.util.DynamicLanguage;
|
||||
import org.thoughtcrime.securesms.util.DynamicTheme;
|
||||
import org.thoughtcrime.securesms.util.MemoryCleaner;
|
||||
|
||||
public class MmsPreferencesActivity extends PassphraseRequiredSherlockPreferenceActivity {
|
||||
|
||||
private MasterSecret masterSecret;
|
||||
|
||||
private final DynamicTheme dynamicTheme = new DynamicTheme();
|
||||
private final DynamicLanguage dynamicLanguage = new DynamicLanguage();
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle icicle) {
|
||||
dynamicTheme.onCreate(this);
|
||||
dynamicLanguage.onCreate(this);
|
||||
super.onCreate(icicle);
|
||||
|
||||
this.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
initializePreferences();
|
||||
|
||||
masterSecret = getIntent().getParcelableExtra("master_secret");
|
||||
|
||||
initializeEditTextSummaries();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
dynamicTheme.onResume(this);
|
||||
dynamicLanguage.onResume(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
MemoryCleaner.clean(masterSecret);
|
||||
MemoryCleaner.clean((MasterSecret) getIntent().getParcelableExtra("master_secret"));
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
handleDownloadMmsPendingApn();
|
||||
finish();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
handleDownloadMmsPendingApn();
|
||||
super.onBackPressed();
|
||||
}
|
||||
|
||||
private void initializePreferences() {
|
||||
if (!MmsDownloadHelper.isMmsConnectionParametersAvailable(this, null, false)) {
|
||||
PreferenceManager.getDefaultSharedPreferences(this).edit()
|
||||
.putBoolean(ApplicationPreferencesActivity.ENABLE_MANUAL_MMS_PREF, true).commit();
|
||||
addPreferencesFromResource(R.xml.mms_preferences);
|
||||
this.findPreference(ApplicationPreferencesActivity.ENABLE_MANUAL_MMS_PREF).setOnPreferenceChangeListener(new OverrideMmsChangeListener());
|
||||
} else {
|
||||
addPreferencesFromResource(R.xml.mms_preferences);
|
||||
}
|
||||
}
|
||||
|
||||
private void initializeEditTextSummary(final EditTextPreference preference) {
|
||||
if (preference.getText() == null) {
|
||||
preference.setSummary("Not set");
|
||||
} else {
|
||||
preference.setSummary(preference.getText());
|
||||
}
|
||||
|
||||
preference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference pref, Object newValue) {
|
||||
preference.setSummary(newValue == null ? "Not set" : ((String) newValue));
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void initializeEditTextSummaries() {
|
||||
initializeEditTextSummary((EditTextPreference)this.findPreference(ApplicationPreferencesActivity.MMSC_HOST_PREF));
|
||||
initializeEditTextSummary((EditTextPreference)this.findPreference(ApplicationPreferencesActivity.MMSC_PROXY_HOST_PREF));
|
||||
initializeEditTextSummary((EditTextPreference)this.findPreference(ApplicationPreferencesActivity.MMSC_PROXY_PORT_PREF));
|
||||
}
|
||||
|
||||
private void handleDownloadMmsPendingApn() {
|
||||
Intent intent = new Intent(this, SendReceiveService.class);
|
||||
intent.setAction(SendReceiveService.DOWNLOAD_MMS_PENDING_APN_ACTION);
|
||||
startService(intent);
|
||||
}
|
||||
|
||||
private class OverrideMmsChangeListener implements Preference.OnPreferenceChangeListener {
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object o) {
|
||||
PreferenceManager.getDefaultSharedPreferences(MmsPreferencesActivity.this).edit()
|
||||
.putBoolean(ApplicationPreferencesActivity.ENABLE_MANUAL_MMS_PREF, true).commit();
|
||||
Toast.makeText(MmsPreferencesActivity.this, R.string.mms_preferences_activity__manual_mms_settings_are_required, Toast.LENGTH_SHORT).show();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
package org.thoughtcrime.securesms;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
|
||||
public class PromptApnActivity extends PassphraseRequiredSherlockActivity {
|
||||
|
||||
private EditText mmsc;
|
||||
private EditText proxyHost;
|
||||
private EditText proxyPort;
|
||||
|
||||
private Button okButton;
|
||||
private Button cancelButton;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle bundle) {
|
||||
super.onCreate(bundle);
|
||||
setContentView(R.layout.prompt_apn_activity);
|
||||
|
||||
initializeResources();
|
||||
initializeValues();
|
||||
}
|
||||
|
||||
private void initializeValues() {
|
||||
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
mmsc.setText(preferences.getString(ApplicationPreferencesActivity.MMSC_HOST_PREF, ""));
|
||||
proxyHost.setText(preferences.getString(ApplicationPreferencesActivity.MMSC_PROXY_HOST_PREF, ""));
|
||||
proxyPort.setText(preferences.getString(ApplicationPreferencesActivity.MMSC_PROXY_PORT_PREF, ""));
|
||||
}
|
||||
|
||||
private void initializeResources() {
|
||||
this.mmsc = (EditText)findViewById(R.id.mmsc_url);
|
||||
this.proxyHost = (EditText)findViewById(R.id.mms_proxy_host);
|
||||
this.proxyPort = (EditText)findViewById(R.id.mms_proxy_port);
|
||||
this.okButton = (Button)findViewById(R.id.ok_button);
|
||||
this.cancelButton = (Button)findViewById(R.id.cancel_button);
|
||||
|
||||
this.okButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
handleSettings();
|
||||
}
|
||||
});
|
||||
|
||||
this.cancelButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void handleSettings() {
|
||||
if (Util.isEmpty(mmsc)) {
|
||||
Toast.makeText(this, R.string.PromptApnActivity_you_must_specify_an_mmsc_url_for_your_carrier, Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
|
||||
PreferenceManager.getDefaultSharedPreferences(this).edit()
|
||||
.putBoolean(ApplicationPreferencesActivity.USE_LOCAL_MMS_APNS_PREF, true)
|
||||
.putString(ApplicationPreferencesActivity.MMSC_HOST_PREF, mmsc.getText().toString().trim())
|
||||
.putString(ApplicationPreferencesActivity.MMSC_PROXY_HOST_PREF, proxyHost.getText().toString().trim())
|
||||
.putString(ApplicationPreferencesActivity.MMSC_PROXY_PORT_PREF, proxyPort.getText().toString().trim())
|
||||
.commit();
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setTitle(R.string.PromptApnActivity_mms_settings_updated);
|
||||
builder.setMessage(R.string.PromptApnActivity_you_can_modify_these_values_from_the_textsecure_settings_menu_at_any_time_);
|
||||
builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
builder.show();
|
||||
}
|
||||
}
|
||||
43
src/org/thoughtcrime/securesms/PromptMmsActivity.java
Normal file
43
src/org/thoughtcrime/securesms/PromptMmsActivity.java
Normal file
@@ -0,0 +1,43 @@
|
||||
package org.thoughtcrime.securesms;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
|
||||
public class PromptMmsActivity extends PassphraseRequiredSherlockActivity {
|
||||
|
||||
private Button okButton;
|
||||
private Button cancelButton;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle bundle) {
|
||||
super.onCreate(bundle);
|
||||
|
||||
setContentView(R.layout.prompt_apn_activity);
|
||||
initializeResources();
|
||||
}
|
||||
|
||||
private void initializeResources() {
|
||||
this.okButton = (Button)findViewById(R.id.ok_button);
|
||||
this.cancelButton = (Button)findViewById(R.id.cancel_button);
|
||||
|
||||
this.okButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = new Intent(PromptMmsActivity.this, MmsPreferencesActivity.class);
|
||||
intent.putExtras(PromptMmsActivity.this.getIntent().getExtras());
|
||||
startActivity(intent);
|
||||
finish();
|
||||
}
|
||||
});
|
||||
|
||||
this.cancelButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -345,6 +345,15 @@ public class MmsDatabase extends Database implements MmsSmsColumns {
|
||||
}
|
||||
}
|
||||
|
||||
public Reader getNotificationsWithDownloadState(MasterSecret masterSecret, long state) {
|
||||
SQLiteDatabase database = databaseHelper.getReadableDatabase();
|
||||
String selection = STATUS + " = ?";
|
||||
String[] selectionArgs = new String[]{state + ""};
|
||||
|
||||
Cursor cursor = database.query(TABLE_NAME, MMS_PROJECTION, selection, selectionArgs, null, null, null);
|
||||
return new Reader(masterSecret, cursor);
|
||||
}
|
||||
|
||||
private Pair<Long, Long> insertMessageInbox(MasterSecret masterSecret, RetrieveConf retrieved,
|
||||
String contentLocation, long threadId, long mailbox)
|
||||
throws MmsException
|
||||
@@ -679,6 +688,7 @@ public class MmsDatabase extends Database implements MmsSmsColumns {
|
||||
public static final int DOWNLOAD_CONNECTING = 3;
|
||||
public static final int DOWNLOAD_SOFT_FAILURE = 4;
|
||||
public static final int DOWNLOAD_HARD_FAILURE = 5;
|
||||
public static final int DOWNLOAD_APN_UNAVAILABLE = 6;
|
||||
|
||||
public static boolean isDisplayDownloadButton(int status) {
|
||||
return
|
||||
@@ -689,9 +699,10 @@ public class MmsDatabase extends Database implements MmsSmsColumns {
|
||||
|
||||
public static String getLabelForStatus(Context context, int status) {
|
||||
switch (status) {
|
||||
case DOWNLOAD_CONNECTING: return context.getString(R.string.MmsDatabase_connecting_to_mms_server);
|
||||
case DOWNLOAD_INITIALIZED: return context.getString(R.string.MmsDatabase_downloading_mms);
|
||||
case DOWNLOAD_HARD_FAILURE: return context.getString(R.string.MmsDatabase_mms_download_failed);
|
||||
case DOWNLOAD_CONNECTING: return context.getString(R.string.MmsDatabase_connecting_to_mms_server);
|
||||
case DOWNLOAD_INITIALIZED: return context.getString(R.string.MmsDatabase_downloading_mms);
|
||||
case DOWNLOAD_HARD_FAILURE: return context.getString(R.string.MmsDatabase_mms_download_failed);
|
||||
case DOWNLOAD_APN_UNAVAILABLE: return context.getString(R.string.MmsDatabase_mms_pending_download);
|
||||
}
|
||||
|
||||
return context.getString(R.string.MmsDatabase_downloading);
|
||||
|
||||
@@ -49,11 +49,14 @@ public class MmsCommunication {
|
||||
{
|
||||
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
|
||||
if (preferences.getBoolean(ApplicationPreferencesActivity.USE_LOCAL_MMS_APNS_PREF, false)) {
|
||||
if (preferences.getBoolean(ApplicationPreferencesActivity.ENABLE_MANUAL_MMS_PREF, false)) {
|
||||
String mmsc = preferences.getString(ApplicationPreferencesActivity.MMSC_HOST_PREF, null);
|
||||
|
||||
if (mmsc == null || !mmsc.startsWith("http"))
|
||||
throw new ApnUnavailableException("Malformed locally configured MMSC: " + mmsc);
|
||||
if (mmsc == null)
|
||||
throw new ApnUnavailableException("Malformed locally configured MMSC.");
|
||||
|
||||
if (!mmsc.startsWith("http"))
|
||||
mmsc = "http://" + mmsc;
|
||||
|
||||
String proxy = preferences.getString(ApplicationPreferencesActivity.MMSC_PROXY_HOST_PREF, null);
|
||||
String port = preferences.getString(ApplicationPreferencesActivity.MMSC_PROXY_PORT_PREF, null);
|
||||
@@ -69,7 +72,7 @@ public class MmsCommunication {
|
||||
{
|
||||
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
|
||||
if (preferences.getBoolean(ApplicationPreferencesActivity.USE_LOCAL_MMS_APNS_PREF, false)) {
|
||||
if (preferences.getBoolean(ApplicationPreferencesActivity.ENABLE_MANUAL_MMS_PREF, false)) {
|
||||
return getLocallyConfiguredMmsConnectionParameters(context);
|
||||
} else {
|
||||
MmsConnectionParameters params = ApnDefaults.getMmsConnectionParameters(context);
|
||||
|
||||
@@ -64,18 +64,20 @@ public class MmsDownloadHelper extends MmsCommunication {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isMmsConnectionParametersAvailable(Context context, String apn, boolean proxyIfPossible) {
|
||||
try {
|
||||
getMmsConnectionParameters(context, apn, proxyIfPossible);
|
||||
return true;
|
||||
} catch (ApnUnavailableException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static RetrieveConf retrieveMms(Context context, String url, String apn,
|
||||
boolean usingMmsRadio, boolean proxyIfPossible)
|
||||
throws IOException
|
||||
throws IOException, ApnUnavailableException
|
||||
{
|
||||
MmsConnectionParameters connectionParameters;
|
||||
|
||||
try {
|
||||
connectionParameters = getMmsConnectionParameters(context, apn, proxyIfPossible);
|
||||
} catch (ApnUnavailableException aue) {
|
||||
Log.w("MmsDownloadHelper", aue);
|
||||
connectionParameters = new MmsConnectionParameters(null, null, null);
|
||||
}
|
||||
MmsConnectionParameters connectionParameters = getMmsConnectionParameters(context, apn, proxyIfPossible);
|
||||
|
||||
checkRouteToHost(context, connectionParameters, url, usingMmsRadio);
|
||||
|
||||
|
||||
@@ -27,11 +27,17 @@ import org.thoughtcrime.securesms.crypto.DecryptingQueue;
|
||||
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||
import org.thoughtcrime.securesms.database.MmsDatabase;
|
||||
import org.thoughtcrime.securesms.database.model.NotificationMmsMessageRecord;
|
||||
import org.thoughtcrime.securesms.mms.ApnUnavailableException;
|
||||
import org.thoughtcrime.securesms.mms.MmsDownloadHelper;
|
||||
import org.thoughtcrime.securesms.mms.MmsSendHelper;
|
||||
import org.thoughtcrime.securesms.notifications.MessageNotifier;
|
||||
import org.thoughtcrime.securesms.protocol.WirePrefix;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import ws.com.google.android.mms.InvalidHeaderValueException;
|
||||
import ws.com.google.android.mms.MmsException;
|
||||
import ws.com.google.android.mms.pdu.NotifyRespInd;
|
||||
@@ -39,10 +45,6 @@ import ws.com.google.android.mms.pdu.PduComposer;
|
||||
import ws.com.google.android.mms.pdu.PduHeaders;
|
||||
import ws.com.google.android.mms.pdu.RetrieveConf;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public class MmsDownloader extends MmscProcessor {
|
||||
|
||||
private final LinkedList<DownloadItem> pendingMessages = new LinkedList<DownloadItem>();
|
||||
@@ -66,6 +68,8 @@ public class MmsDownloader extends MmscProcessor {
|
||||
handleDownloadMmsAction(item);
|
||||
} else if (intent.getAction().equals(SendReceiveService.DOWNLOAD_MMS_CONNECTIVITY_ACTION)) {
|
||||
handleConnectivityChange();
|
||||
} else if (intent.getAction().equals(SendReceiveService.DOWNLOAD_MMS_PENDING_APN_ACTION)) {
|
||||
handleMmsPendingApnDownloads(masterSecret);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,6 +87,28 @@ public class MmsDownloader extends MmscProcessor {
|
||||
else downloadMms(item);
|
||||
}
|
||||
|
||||
private void handleMmsPendingApnDownloads(MasterSecret masterSecret) {
|
||||
if (!MmsDownloadHelper.isMmsConnectionParametersAvailable(context, null, false))
|
||||
return;
|
||||
|
||||
MmsDatabase mmsDatabase = DatabaseFactory.getMmsDatabase(context);
|
||||
MmsDatabase.Reader stalledMmsReader = mmsDatabase.getNotificationsWithDownloadState(masterSecret,
|
||||
MmsDatabase.Status.DOWNLOAD_APN_UNAVAILABLE);
|
||||
while (stalledMmsReader.getNext() != null) {
|
||||
NotificationMmsMessageRecord stalledMmsRecord = (NotificationMmsMessageRecord) stalledMmsReader.getCurrent();
|
||||
|
||||
Intent intent = new Intent(SendReceiveService.DOWNLOAD_MMS_ACTION, null, context, SendReceiveService.class);
|
||||
intent.putExtra("content_location", new String(stalledMmsRecord.getContentLocation()));
|
||||
intent.putExtra("message_id", stalledMmsRecord.getId());
|
||||
intent.putExtra("transaction_id", stalledMmsRecord.getTransactionId());
|
||||
intent.putExtra("thread_id", stalledMmsRecord.getThreadId());
|
||||
intent.putExtra("automatic", true);
|
||||
context.startService(intent);
|
||||
}
|
||||
|
||||
stalledMmsReader.close();
|
||||
}
|
||||
|
||||
private void downloadMmsWithRadioChange(DownloadItem item) {
|
||||
Log.w("MmsDownloader", "Handling MMS download with radio change...");
|
||||
pendingMessages.add(item);
|
||||
@@ -107,6 +133,10 @@ public class MmsDownloader extends MmscProcessor {
|
||||
storeRetrievedMms(mmsDatabase, item, retrieved);
|
||||
sendRetrievedAcknowledgement(item);
|
||||
|
||||
} catch (ApnUnavailableException e) {
|
||||
Log.w("MmsDownloader", e);
|
||||
handleDownloadError(item, MmsDatabase.Status.DOWNLOAD_APN_UNAVAILABLE,
|
||||
context.getString(R.string.MmsDownloader_error_reading_mms_settings));
|
||||
} catch (IOException e) {
|
||||
Log.w("MmsDownloader", e);
|
||||
if (!item.useMmsRadioMode() && !item.proxyRequestIfPossible()) {
|
||||
@@ -188,18 +218,9 @@ public class MmsDownloader extends MmscProcessor {
|
||||
}
|
||||
|
||||
private void handleDownloadError(List<DownloadItem> items, int downloadStatus, String error) {
|
||||
MmsDatabase db = DatabaseFactory.getMmsDatabase(context);
|
||||
|
||||
for (DownloadItem item : items) {
|
||||
db.markDownloadState(item.getMessageId(), downloadStatus);
|
||||
|
||||
if (item.isAutomatic()) {
|
||||
db.markIncomingNotificationReceived(item.getThreadId());
|
||||
MessageNotifier.updateNotification(context, item.getMasterSecret(), item.getThreadId());
|
||||
}
|
||||
handleDownloadError(item, downloadStatus, error);
|
||||
}
|
||||
|
||||
toastHandler.makeToast(error);
|
||||
}
|
||||
|
||||
private void handleDownloadError(DownloadItem item, int downloadStatus, String error) {
|
||||
|
||||
@@ -54,12 +54,14 @@ public class SendReceiveService extends Service {
|
||||
public static final String RECEIVE_MMS_ACTION = "org.thoughtcrime.securesms.SendReceiveService.RECEIVE_MMS_ACTION";
|
||||
public static final String DOWNLOAD_MMS_ACTION = "org.thoughtcrime.securesms.SendReceiveService.DOWNLOAD_MMS_ACTION";
|
||||
public static final String DOWNLOAD_MMS_CONNECTIVITY_ACTION = "org.thoughtcrime.securesms.SendReceiveService.DOWNLOAD_MMS_CONNECTIVITY_ACTION";
|
||||
public static final String DOWNLOAD_MMS_PENDING_APN_ACTION = "org.thoughtcrime.securesms.SendReceiveService.DOWNLOAD_MMS_PENDING_APN_ACTION";
|
||||
|
||||
private static final int SEND_SMS = 0;
|
||||
private static final int RECEIVE_SMS = 1;
|
||||
private static final int SEND_MMS = 2;
|
||||
private static final int RECEIVE_MMS = 3;
|
||||
private static final int DOWNLOAD_MMS = 4;
|
||||
private static final int DOWNLOAD_MMS_PENDING = 5;
|
||||
|
||||
private ToastHandler toastHandler;
|
||||
|
||||
@@ -105,6 +107,8 @@ public class SendReceiveService extends Service {
|
||||
scheduleIntent(RECEIVE_MMS, intent);
|
||||
else if (intent.getAction().equals(DOWNLOAD_MMS_ACTION) || intent.getAction().equals(DOWNLOAD_MMS_CONNECTIVITY_ACTION))
|
||||
scheduleSecretRequiredIntent(DOWNLOAD_MMS, intent);
|
||||
else if (intent.getAction().equals(DOWNLOAD_MMS_PENDING_APN_ACTION))
|
||||
scheduleSecretRequiredIntent(DOWNLOAD_MMS_PENDING, intent);
|
||||
else
|
||||
Log.w("SendReceiveService", "Received intent with unknown action: " + intent.getAction());
|
||||
}
|
||||
@@ -216,11 +220,12 @@ public class SendReceiveService extends Service {
|
||||
@Override
|
||||
public void run() {
|
||||
switch (what) {
|
||||
case RECEIVE_SMS: smsReceiver.process(masterSecret, intent); return;
|
||||
case SEND_SMS: smsSender.process(masterSecret, intent); return;
|
||||
case RECEIVE_MMS: mmsReceiver.process(masterSecret, intent); return;
|
||||
case SEND_MMS: mmsSender.process(masterSecret, intent); return;
|
||||
case DOWNLOAD_MMS: mmsDownloader.process(masterSecret, intent); return;
|
||||
case RECEIVE_SMS: smsReceiver.process(masterSecret, intent); return;
|
||||
case SEND_SMS: smsSender.process(masterSecret, intent); return;
|
||||
case RECEIVE_MMS: mmsReceiver.process(masterSecret, intent); return;
|
||||
case SEND_MMS: mmsSender.process(masterSecret, intent); return;
|
||||
case DOWNLOAD_MMS: mmsDownloader.process(masterSecret, intent); return;
|
||||
case DOWNLOAD_MMS_PENDING: mmsDownloader.process(masterSecret, intent); return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user