mirror of
https://github.com/oxen-io/session-android.git
synced 2025-10-26 04:59:11 +00:00
Significant MMS changes
1) Remove all our PDU code and switch to the PDU code from the klinker library 2) Switch to using the system Lollipop MMS library by default, and falling back to our own custom library if that fails. 3) Format SMIL differently, using code from klinker instead of what we've pieced together. 4) Pull per-carrier MMS media constraints from the XML config files in the klinker library, instead of hardcoding it at 280kb. Hopefully this is an improvement, but given that MMS is involved, it will probably make things worse instead.
This commit is contained in:
@@ -36,13 +36,13 @@ import org.thoughtcrime.securesms.ApplicationContext;
|
||||
import org.thoughtcrime.securesms.attachments.Attachment;
|
||||
import org.thoughtcrime.securesms.attachments.AttachmentId;
|
||||
import org.thoughtcrime.securesms.attachments.DatabaseAttachment;
|
||||
import org.thoughtcrime.securesms.crypto.AsymmetricMasterCipher;
|
||||
import org.thoughtcrime.securesms.crypto.DecryptingPartInputStream;
|
||||
import org.thoughtcrime.securesms.crypto.EncryptingPartOutputStream;
|
||||
import org.thoughtcrime.securesms.crypto.MasterCipher;
|
||||
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
||||
import org.thoughtcrime.securesms.crypto.MasterSecretUnion;
|
||||
import org.thoughtcrime.securesms.mms.MediaStream;
|
||||
import org.thoughtcrime.securesms.mms.MmsException;
|
||||
import org.thoughtcrime.securesms.mms.PartAuthority;
|
||||
import org.thoughtcrime.securesms.util.MediaUtil;
|
||||
import org.thoughtcrime.securesms.util.MediaUtil.ThumbnailData;
|
||||
@@ -50,8 +50,6 @@ import org.thoughtcrime.securesms.util.Util;
|
||||
import org.thoughtcrime.securesms.video.EncryptedMediaDataSource;
|
||||
import org.whispersystems.libsignal.InvalidMessageException;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
@@ -63,9 +61,6 @@ import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
||||
import ws.com.google.android.mms.ContentType;
|
||||
import ws.com.google.android.mms.MmsException;
|
||||
|
||||
public class AttachmentDatabase extends Database {
|
||||
|
||||
private static final String TAG = AttachmentDatabase.class.getSimpleName();
|
||||
@@ -610,7 +605,7 @@ public class AttachmentDatabase extends Database {
|
||||
|
||||
ThumbnailData data;
|
||||
|
||||
if (ContentType.isVideoType(attachment.getContentType())) {
|
||||
if (MediaUtil.isVideoType(attachment.getContentType())) {
|
||||
data = generateVideoThumbnail(masterSecret, attachmentId);
|
||||
} else{
|
||||
data = MediaUtil.generateThumbnail(context, masterSecret, attachment.getContentType(), attachment.getDataUri());
|
||||
|
||||
@@ -17,15 +17,11 @@
|
||||
package org.thoughtcrime.securesms.database;
|
||||
|
||||
import android.content.ContentValues;
|
||||
import android.util.Log;
|
||||
|
||||
import com.google.android.mms.pdu_alt.EncodedStringValue;
|
||||
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
|
||||
import ws.com.google.android.mms.pdu.CharacterSets;
|
||||
import ws.com.google.android.mms.pdu.EncodedStringValue;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
public class ContentValuesBuilder {
|
||||
|
||||
private final ContentValues contentValues;
|
||||
|
||||
@@ -33,6 +33,7 @@ import org.thoughtcrime.securesms.crypto.MasterSecret;
|
||||
import org.thoughtcrime.securesms.crypto.MasterSecretUtil;
|
||||
import org.thoughtcrime.securesms.notifications.MessageNotifier;
|
||||
import org.thoughtcrime.securesms.util.Base64;
|
||||
import org.thoughtcrime.securesms.util.MediaUtil;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.whispersystems.libsignal.IdentityKey;
|
||||
import org.whispersystems.libsignal.InvalidMessageException;
|
||||
@@ -42,8 +43,6 @@ import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import ws.com.google.android.mms.ContentType;
|
||||
|
||||
public class DatabaseFactory {
|
||||
|
||||
private static final int INTRODUCED_IDENTITIES_VERSION = 2;
|
||||
@@ -381,7 +380,7 @@ public class DatabaseFactory {
|
||||
while (partCursor != null && partCursor.moveToNext()) {
|
||||
String contentType = partCursor.getString(partCursor.getColumnIndexOrThrow("ct"));
|
||||
|
||||
if (ContentType.isTextType(contentType)) {
|
||||
if (MediaUtil.isTextType(contentType)) {
|
||||
try {
|
||||
long partId = partCursor.getLong(partCursor.getColumnIndexOrThrow("_id"));
|
||||
String dataLocation = partCursor.getString(partCursor.getColumnIndexOrThrow("_data"));
|
||||
@@ -401,9 +400,9 @@ public class DatabaseFactory {
|
||||
} catch (IOException e) {
|
||||
Log.w("DatabaseFactory", e);
|
||||
}
|
||||
} else if (ContentType.isAudioType(contentType) ||
|
||||
ContentType.isImageType(contentType) ||
|
||||
ContentType.isVideoType(contentType))
|
||||
} else if (MediaUtil.isAudioType(contentType) ||
|
||||
MediaUtil.isImageType(contentType) ||
|
||||
MediaUtil.isVideoType(contentType))
|
||||
{
|
||||
partCount++;
|
||||
}
|
||||
|
||||
@@ -23,6 +23,8 @@ import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import com.google.android.mms.pdu_alt.PduHeaders;
|
||||
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.recipients.RecipientFactory;
|
||||
import org.thoughtcrime.securesms.recipients.Recipients;
|
||||
@@ -30,8 +32,6 @@ import org.thoughtcrime.securesms.recipients.Recipients;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import ws.com.google.android.mms.pdu.PduHeaders;
|
||||
|
||||
public class MmsAddressDatabase extends Database {
|
||||
|
||||
private static final String TAG = MmsAddressDatabase.class.getSimpleName();
|
||||
|
||||
@@ -19,7 +19,6 @@ package org.thoughtcrime.securesms.database;
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.database.MatrixCursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
import android.net.Uri;
|
||||
@@ -29,6 +28,8 @@ import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.util.Pair;
|
||||
|
||||
import com.google.android.mms.pdu_alt.NotificationInd;
|
||||
import com.google.android.mms.pdu_alt.PduHeaders;
|
||||
import com.google.i18n.phonenumbers.PhoneNumberUtil;
|
||||
|
||||
import org.thoughtcrime.securesms.ApplicationContext;
|
||||
@@ -77,9 +78,7 @@ import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import ws.com.google.android.mms.MmsException;
|
||||
import ws.com.google.android.mms.pdu.NotificationInd;
|
||||
import ws.com.google.android.mms.pdu.PduHeaders;
|
||||
import org.thoughtcrime.securesms.mms.MmsException;
|
||||
|
||||
import static org.thoughtcrime.securesms.util.Util.canonicalizeNumber;
|
||||
import static org.thoughtcrime.securesms.util.Util.canonicalizeNumberOrGroup;
|
||||
@@ -593,23 +592,16 @@ public class MmsDatabase extends MessagingDatabase {
|
||||
return new Pair<>(messageId, threadId);
|
||||
}
|
||||
|
||||
public Optional<Pair<NotificationInd, Integer>> getNotification(long messageId) {
|
||||
public Optional<MmsNotificationInfo> getNotification(long messageId) {
|
||||
Cursor cursor = null;
|
||||
|
||||
try {
|
||||
cursor = rawQuery(RAW_ID_WHERE, new String[] {String.valueOf(messageId)});
|
||||
|
||||
if (cursor != null && cursor.moveToNext()) {
|
||||
PduHeaders headers = new PduHeaders();
|
||||
PduHeadersBuilder builder = new PduHeadersBuilder(headers, cursor);
|
||||
builder.addText(CONTENT_LOCATION, PduHeaders.CONTENT_LOCATION);
|
||||
builder.addLong(NORMALIZED_DATE_SENT, PduHeaders.DATE);
|
||||
builder.addLong(EXPIRY, PduHeaders.EXPIRY);
|
||||
builder.addLong(MESSAGE_SIZE, PduHeaders.MESSAGE_SIZE);
|
||||
builder.addText(TRANSACTION_ID, PduHeaders.TRANSACTION_ID);
|
||||
|
||||
return Optional.of(new Pair<>(new NotificationInd(headers),
|
||||
cursor.getInt(cursor.getColumnIndexOrThrow(SUBSCRIPTION_ID))));
|
||||
return Optional.of(new MmsNotificationInfo(cursor.getString(cursor.getColumnIndexOrThrow(CONTENT_LOCATION)),
|
||||
cursor.getString(cursor.getColumnIndexOrThrow(TRANSACTION_ID)),
|
||||
cursor.getInt(cursor.getColumnIndexOrThrow(SUBSCRIPTION_ID))));
|
||||
} else {
|
||||
return Optional.absent();
|
||||
}
|
||||
@@ -820,22 +812,21 @@ public class MmsDatabase extends MessagingDatabase {
|
||||
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
||||
MmsAddressDatabase addressDatabase = DatabaseFactory.getMmsAddressDatabase(context);
|
||||
long threadId = getThreadIdFor(notification);
|
||||
PduHeaders headers = notification.getPduHeaders();
|
||||
ContentValues contentValues = new ContentValues();
|
||||
ContentValuesBuilder contentBuilder = new ContentValuesBuilder(contentValues);
|
||||
|
||||
Log.w(TAG, "Message received type: " + notification.getMessageType());
|
||||
|
||||
Log.w(TAG, "Message received type: " + headers.getOctet(PduHeaders.MESSAGE_TYPE));
|
||||
|
||||
contentBuilder.add(CONTENT_LOCATION, headers.getTextString(PduHeaders.CONTENT_LOCATION));
|
||||
contentBuilder.add(DATE_SENT, headers.getLongInteger(PduHeaders.DATE) * 1000L);
|
||||
contentBuilder.add(EXPIRY, headers.getLongInteger(PduHeaders.EXPIRY));
|
||||
contentBuilder.add(MESSAGE_SIZE, headers.getLongInteger(PduHeaders.MESSAGE_SIZE));
|
||||
contentBuilder.add(TRANSACTION_ID, headers.getTextString(PduHeaders.TRANSACTION_ID));
|
||||
contentBuilder.add(MESSAGE_TYPE, headers.getOctet(PduHeaders.MESSAGE_TYPE));
|
||||
contentBuilder.add(CONTENT_LOCATION, notification.getContentLocation());
|
||||
contentBuilder.add(DATE_SENT, System.currentTimeMillis());
|
||||
contentBuilder.add(EXPIRY, notification.getExpiry());
|
||||
contentBuilder.add(MESSAGE_SIZE, notification.getMessageSize());
|
||||
contentBuilder.add(TRANSACTION_ID, notification.getTransactionId());
|
||||
contentBuilder.add(MESSAGE_TYPE, notification.getMessageType());
|
||||
|
||||
if (headers.getEncodedStringValue(PduHeaders.FROM) != null) {
|
||||
contentBuilder.add(ADDRESS, headers.getEncodedStringValue(PduHeaders.FROM).getTextString());
|
||||
if (notification.getFrom() != null) {
|
||||
contentBuilder.add(ADDRESS, notification.getFrom().getTextString());
|
||||
} else {
|
||||
contentBuilder.add(ADDRESS, null);
|
||||
}
|
||||
@@ -852,7 +843,7 @@ public class MmsDatabase extends MessagingDatabase {
|
||||
|
||||
long messageId = db.insert(TABLE_NAME, null, contentValues);
|
||||
|
||||
if (headers.getEncodedStringValue(PduHeaders.FROM) != null) {
|
||||
if (notification.getFrom() != null) {
|
||||
addressDatabase.insertAddressesForId(messageId, MmsAddresses.forFrom(Util.toIsoString(notification.getFrom().getTextString())));
|
||||
}
|
||||
|
||||
@@ -1129,6 +1120,30 @@ public class MmsDatabase extends MessagingDatabase {
|
||||
public static final int DOWNLOAD_APN_UNAVAILABLE = 6;
|
||||
}
|
||||
|
||||
public static class MmsNotificationInfo {
|
||||
private final String contentLocation;
|
||||
private final String transactionId;
|
||||
private final int subscriptionId;
|
||||
|
||||
public MmsNotificationInfo(String contentLocation, String transactionId, int subscriptionId) {
|
||||
this.contentLocation = contentLocation;
|
||||
this.transactionId = transactionId;
|
||||
this.subscriptionId = subscriptionId;
|
||||
}
|
||||
|
||||
public String getContentLocation() {
|
||||
return contentLocation;
|
||||
}
|
||||
|
||||
public String getTransactionId() {
|
||||
return transactionId;
|
||||
}
|
||||
|
||||
public int getSubscriptionId() {
|
||||
return subscriptionId;
|
||||
}
|
||||
}
|
||||
|
||||
public class OutgoingMessageReader {
|
||||
|
||||
private final OutgoingMediaMessage message;
|
||||
|
||||
@@ -1,80 +0,0 @@
|
||||
/**
|
||||
* 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.database;
|
||||
|
||||
import android.database.Cursor;
|
||||
import android.util.Log;
|
||||
|
||||
import ws.com.google.android.mms.InvalidHeaderValueException;
|
||||
import ws.com.google.android.mms.pdu.CharacterSets;
|
||||
import ws.com.google.android.mms.pdu.EncodedStringValue;
|
||||
import ws.com.google.android.mms.pdu.PduHeaders;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
public class PduHeadersBuilder {
|
||||
|
||||
private final PduHeaders headers;
|
||||
private final Cursor cursor;
|
||||
|
||||
public PduHeadersBuilder(PduHeaders headers, Cursor cursor) {
|
||||
this.headers = headers;
|
||||
this.cursor = cursor;
|
||||
}
|
||||
|
||||
public PduHeaders getHeaders() {
|
||||
return headers;
|
||||
}
|
||||
|
||||
public void addLong(String key, int headersKey) {
|
||||
int columnIndex = cursor.getColumnIndexOrThrow(key);
|
||||
|
||||
if (!cursor.isNull(columnIndex))
|
||||
headers.setLongInteger(cursor.getLong(columnIndex), headersKey);
|
||||
}
|
||||
|
||||
public void addOctet(String key, int headersKey) throws InvalidHeaderValueException {
|
||||
int columnIndex = cursor.getColumnIndexOrThrow(key);
|
||||
|
||||
if (!cursor.isNull(columnIndex))
|
||||
headers.setOctet(cursor.getInt(columnIndex), headersKey);
|
||||
}
|
||||
|
||||
public void addText(String key, int headersKey) {
|
||||
String value = cursor.getString(cursor.getColumnIndexOrThrow(key));
|
||||
if (value != null && value.trim().length() > 0)
|
||||
headers.setTextString(getBytes(value), headersKey);
|
||||
}
|
||||
public void add(String key, String charsetKey, int headersKey) {
|
||||
String value = cursor.getString(cursor.getColumnIndexOrThrow(key));
|
||||
|
||||
if (value != null && value.trim().length() > 0) {
|
||||
int charsetValue = cursor.getInt(cursor.getColumnIndexOrThrow(charsetKey));
|
||||
EncodedStringValue encodedValue = new EncodedStringValue(charsetValue, getBytes(value));
|
||||
headers.setEncodedStringValue(encodedValue, headersKey);
|
||||
}
|
||||
}
|
||||
|
||||
private byte[] getBytes(String data) {
|
||||
try {
|
||||
return data.getBytes(CharacterSets.MIMENAME_ISO_8859_1);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
Log.e("PduHeadersBuilder", "ISO_8859_1 must be supported!", e);
|
||||
return new byte[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user