Skip to content
Permalink
Browse files

reduce max size for encrypted MMS message

  • Loading branch information...
BLeQuerrec committed Aug 11, 2019
1 parent 376c6eb commit 925abd257d3a428ed2df820fdca08d60925eb7b6
@@ -1142,7 +1142,7 @@ private String getMessage() throws InvalidMessageException {
}

private MediaConstraints getCurrentMediaConstraints() {
return MediaConstraints.getMmsMediaConstraints(sendButton.getSelectedTransport().getSimSubscriptionId().or(-1));
return MediaConstraints.getMmsMediaConstraints(sendButton.getSelectedTransport().getSimSubscriptionId().or(-1), isSecureSmsDestination);
}

private void markThreadAsRead() {
@@ -191,7 +191,7 @@ private SendReq constructSendPdu(MasterSecret masterSecret, OutgoingMediaMessage
SendReq req = new SendReq();
String lineNumber = Utils.getMyPhoneNumber(context);
List<String> numbers = message.getRecipients().toNumberStringList(true);
MediaConstraints mediaConstraints = MediaConstraints.getMmsMediaConstraints(message.getSubscriptionId());
MediaConstraints mediaConstraints = MediaConstraints.getMmsMediaConstraints(message.getSubscriptionId(), message.isSecure());
List<Attachment> scaledAttachments = scaleAttachments(masterSecret, mediaConstraints, message.getAttachments());

if (!TextUtils.isEmpty(lineNumber)) {
@@ -21,8 +21,8 @@
public abstract class MediaConstraints {
private static final String TAG = MediaConstraints.class.getSimpleName();

public static MediaConstraints getMmsMediaConstraints(int subscriptionId) {
return new MmsMediaConstraints(subscriptionId);
public static MediaConstraints getMmsMediaConstraints(int subscriptionId, boolean isSecure) {
return new MmsMediaConstraints(subscriptionId, isSecure);
}

public abstract int getImageMaxWidth(Context context);
@@ -10,10 +10,14 @@
private static final int DEFAULT_MAX_IMAGE_DIMEN = 1024;
private static final int DEFAULT_MAX_MESSAGE_SIZE = 280 * 1024;

private static final double RATIO_IF_ENCRYPTED = 0.75; // Reduce by 25% max size for encrypted MMS mesages

private final int subscriptionId;
private final boolean isSecure;

MmsMediaConstraints(int subscriptionId) {
MmsMediaConstraints(int subscriptionId, boolean isSecure) {
this.subscriptionId = subscriptionId;
this.isSecure = isSecure;
}

@Override
@@ -65,7 +69,14 @@ private int getMaxMessageSize(Context context) {

if (mmsConfig != null) {
MmsConfig.Overridden overridden = new MmsConfig.Overridden(mmsConfig, new Bundle());
return overridden.getMaxMessageSize();
int size;
double plaintextMaxSize = (double) overridden.getMaxMessageSize();
if (isSecure) {
size = (int)(plaintextMaxSize * RATIO_IF_ENCRYPTED);
} else {
size = (int)plaintextMaxSize;
}
return size;
}

return DEFAULT_MAX_MESSAGE_SIZE;

0 comments on commit 925abd2

Please sign in to comment.
You can’t perform that action at this time.