mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-27 12:05:22 +00:00
Expand MMS-specific queries, properly parse incoming MMS.
// FREEBIE
This commit is contained in:
parent
474922493f
commit
c258b4c7aa
@ -59,8 +59,6 @@ import org.thoughtcrime.securesms.recipients.RecipientFormattingException;
|
||||
import org.thoughtcrime.securesms.recipients.Recipients;
|
||||
import org.thoughtcrime.securesms.util.GroupUtil;
|
||||
import org.thoughtcrime.securesms.util.JsonUtils;
|
||||
import org.thoughtcrime.securesms.util.LRUCache;
|
||||
import org.thoughtcrime.securesms.util.ListenableFutureTask;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.whispersystems.jobqueue.JobManager;
|
||||
@ -69,15 +67,10 @@ import org.whispersystems.libaxolotl.util.guava.Optional;
|
||||
import org.whispersystems.textsecure.api.util.InvalidNumberException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.ref.SoftReference;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
||||
import ws.com.google.android.mms.MmsException;
|
||||
import ws.com.google.android.mms.pdu.NotificationInd;
|
||||
@ -128,18 +121,27 @@ public class MmsDatabase extends MessagingDatabase {
|
||||
};
|
||||
|
||||
private static final String[] MMS_PROJECTION = new String[] {
|
||||
ID, THREAD_ID, DATE_SENT + " AS " + NORMALIZED_DATE_SENT,
|
||||
MmsDatabase.TABLE_NAME + "." + ID + " AS " + ID,
|
||||
THREAD_ID, DATE_SENT + " AS " + NORMALIZED_DATE_SENT,
|
||||
DATE_RECEIVED + " AS " + NORMALIZED_DATE_RECEIVED,
|
||||
MESSAGE_BOX, READ,
|
||||
CONTENT_LOCATION, EXPIRY, MESSAGE_TYPE,
|
||||
MESSAGE_SIZE, STATUS, TRANSACTION_ID,
|
||||
BODY, PART_COUNT, ADDRESS, ADDRESS_DEVICE_ID,
|
||||
RECEIPT_COUNT, MISMATCHED_IDENTITIES, NETWORK_FAILURE
|
||||
RECEIPT_COUNT, MISMATCHED_IDENTITIES, NETWORK_FAILURE,
|
||||
AttachmentDatabase.TABLE_NAME + "." + AttachmentDatabase.ROW_ID + " AS " + AttachmentDatabase.ATTACHMENT_ID_ALIAS,
|
||||
AttachmentDatabase.UNIQUE_ID,
|
||||
AttachmentDatabase.MMS_ID,
|
||||
AttachmentDatabase.SIZE,
|
||||
AttachmentDatabase.DATA,
|
||||
AttachmentDatabase.CONTENT_TYPE,
|
||||
AttachmentDatabase.CONTENT_LOCATION,
|
||||
AttachmentDatabase.CONTENT_DISPOSITION,
|
||||
AttachmentDatabase.NAME,
|
||||
AttachmentDatabase.TRANSFER_STATE
|
||||
};
|
||||
|
||||
public static final ExecutorService slideResolver = org.thoughtcrime.securesms.util.Util.newSingleThreadedLifoExecutor();
|
||||
private static final Map<String, SoftReference<SlideDeck>> slideCache =
|
||||
Collections.synchronizedMap(new LRUCache<String, SoftReference<SlideDeck>>(20));
|
||||
private static final String RAW_ID_WHERE = TABLE_NAME + "._id = ?";
|
||||
|
||||
private final JobManager jobManager;
|
||||
|
||||
@ -305,19 +307,23 @@ public class MmsDatabase extends MessagingDatabase {
|
||||
return DatabaseFactory.getThreadDatabase(context).getThreadIdFor(recipients);
|
||||
}
|
||||
|
||||
private Cursor rawQuery(@NonNull String where, @Nullable String[] arguments) {
|
||||
SQLiteDatabase database = databaseHelper.getReadableDatabase();
|
||||
return database.rawQuery("SELECT " + Util.join(MMS_PROJECTION, ",") +
|
||||
" FROM " + MmsDatabase.TABLE_NAME + " LEFT OUTER JOIN " + AttachmentDatabase.TABLE_NAME +
|
||||
" ON (" + MmsDatabase.TABLE_NAME + "." + MmsDatabase.ID + " = " + AttachmentDatabase.TABLE_NAME + "." + AttachmentDatabase.MMS_ID + ")" +
|
||||
" WHERE " + where, arguments);
|
||||
}
|
||||
|
||||
public Cursor getMessage(long messageId) {
|
||||
SQLiteDatabase db = databaseHelper.getReadableDatabase();
|
||||
Cursor cursor = db.query(TABLE_NAME, MMS_PROJECTION, ID_WHERE, new String[] {messageId + ""},
|
||||
null, null, null);
|
||||
Cursor cursor = rawQuery(RAW_ID_WHERE, new String[] {messageId + ""});
|
||||
setNotifyConverationListeners(cursor, getThreadIdForMessage(messageId));
|
||||
return cursor;
|
||||
}
|
||||
|
||||
public Reader getDecryptInProgressMessages(MasterSecret masterSecret) {
|
||||
SQLiteDatabase db = databaseHelper.getReadableDatabase();
|
||||
String where = MESSAGE_BOX + " & " + (Types.ENCRYPTION_ASYMMETRIC_BIT) + " != 0";
|
||||
|
||||
return readerFor(masterSecret, db.query(TABLE_NAME, MMS_PROJECTION, where, null, null, null, null));
|
||||
String where = MESSAGE_BOX + " & " + (Types.ENCRYPTION_ASYMMETRIC_BIT) + " != 0";
|
||||
return readerFor(masterSecret, rawQuery(where, null));
|
||||
}
|
||||
|
||||
private void updateMailboxBitmask(long id, long maskOff, long maskOn) {
|
||||
@ -445,11 +451,10 @@ public class MmsDatabase extends MessagingDatabase {
|
||||
}
|
||||
|
||||
public Optional<NotificationInd> getNotification(long messageId) {
|
||||
SQLiteDatabase db = databaseHelper.getReadableDatabase();
|
||||
Cursor cursor = null;
|
||||
Cursor cursor = null;
|
||||
|
||||
try {
|
||||
cursor = db.query(TABLE_NAME, MMS_PROJECTION, ID_WHERE, new String[] {String.valueOf(messageId)}, null, null, null);
|
||||
cursor = rawQuery(RAW_ID_WHERE, new String[] {String.valueOf(messageId)});
|
||||
|
||||
if (cursor != null && cursor.moveToNext()) {
|
||||
PduHeaders headers = new PduHeaders();
|
||||
@ -475,11 +480,10 @@ public class MmsDatabase extends MessagingDatabase {
|
||||
{
|
||||
MmsAddressDatabase addr = DatabaseFactory.getMmsAddressDatabase(context);
|
||||
AttachmentDatabase attachmentDatabase = DatabaseFactory.getAttachmentDatabase(context);
|
||||
SQLiteDatabase database = databaseHelper.getReadableDatabase();
|
||||
Cursor cursor = null;
|
||||
|
||||
try {
|
||||
cursor = database.query(TABLE_NAME, MMS_PROJECTION, ID_WHERE, new String[]{String.valueOf(messageId)}, null, null, null);
|
||||
cursor = rawQuery(RAW_ID_WHERE, new String[] {String.valueOf(messageId)});
|
||||
|
||||
if (cursor != null && cursor.moveToNext()) {
|
||||
long outboxType = cursor.getLong(cursor.getColumnIndexOrThrow(MESSAGE_BOX));
|
||||
@ -582,6 +586,7 @@ public class MmsDatabase extends MessagingDatabase {
|
||||
contentValues.put(CONTENT_LOCATION, contentLocation);
|
||||
contentValues.put(STATUS, Status.DOWNLOAD_INITIALIZED);
|
||||
contentValues.put(DATE_RECEIVED, generatePduCompatTimestamp());
|
||||
contentValues.put(PART_COUNT, retrieved.getAttachments().size());
|
||||
contentValues.put(READ, 0);
|
||||
|
||||
if (!contentValues.containsKey(DATE_SENT)) {
|
||||
|
@ -17,6 +17,7 @@ import org.thoughtcrime.securesms.mms.ApnUnavailableException;
|
||||
import org.thoughtcrime.securesms.mms.CompatMmsConnection;
|
||||
import org.thoughtcrime.securesms.mms.IncomingMediaMessage;
|
||||
import org.thoughtcrime.securesms.mms.MmsRadioException;
|
||||
import org.thoughtcrime.securesms.mms.PartParser;
|
||||
import org.thoughtcrime.securesms.notifications.MessageNotifier;
|
||||
import org.thoughtcrime.securesms.providers.SingleUseBlobProvider;
|
||||
import org.thoughtcrime.securesms.service.KeyCachingService;
|
||||
@ -38,6 +39,7 @@ import ws.com.google.android.mms.ContentType;
|
||||
import ws.com.google.android.mms.MmsException;
|
||||
import ws.com.google.android.mms.pdu.EncodedStringValue;
|
||||
import ws.com.google.android.mms.pdu.NotificationInd;
|
||||
import ws.com.google.android.mms.pdu.PduBody;
|
||||
import ws.com.google.android.mms.pdu.PduPart;
|
||||
import ws.com.google.android.mms.pdu.RetrieveConf;
|
||||
|
||||
@ -173,12 +175,13 @@ public class MmsDownloadJob extends MasterSecretJob {
|
||||
}
|
||||
|
||||
if (retrieved.getBody() != null) {
|
||||
for (int i=0;i<retrieved.getBody().getPartsNum();i++) {
|
||||
PduPart part = retrieved.getBody().getPart(i);
|
||||
body = PartParser.getMessageText(retrieved.getBody());
|
||||
PduBody media = PartParser.getSupportedMediaParts(retrieved.getBody());
|
||||
|
||||
if (Util.toIsoString(part.getContentType()).equals(ContentType.TEXT_PLAIN)) {
|
||||
body = Util.toIsoString(part.getData());
|
||||
} else if (part.getData() != null) {
|
||||
for (int i=0;i<media.getPartsNum();i++) {
|
||||
PduPart part = media.getPart(i);
|
||||
|
||||
if (part.getData() != null) {
|
||||
Uri uri = provider.createUri(part.getData());
|
||||
attachments.add(new UriAttachment(uri, Util.toIsoString(part.getContentType()),
|
||||
AttachmentDatabase.TRANSFER_PROGRESS_DONE,
|
||||
|
@ -49,6 +49,7 @@ import java.io.OutputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@ -64,6 +65,10 @@ import ws.com.google.android.mms.pdu.EncodedStringValue;
|
||||
public class Util {
|
||||
public static Handler handler = new Handler(Looper.getMainLooper());
|
||||
|
||||
public static String join(String[] list, String delimiter) {
|
||||
return join(Arrays.asList(list), delimiter);
|
||||
}
|
||||
|
||||
public static String join(Collection<String> list, String delimiter) {
|
||||
StringBuilder result = new StringBuilder();
|
||||
int i = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user