mirror of
https://github.com/oxen-io/session-android.git
synced 2025-10-20 14:54:09 +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
@@ -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