Search in sources :

Example 6 with MediaConstraints

use of org.thoughtcrime.securesms.mms.MediaConstraints in project Signal-Android by WhisperSystems.

the class ImageEditorFragment method onCreate.

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Fragment parent = getParentFragment();
    if (parent instanceof Controller) {
        controller = (Controller) parent;
    } else if (getActivity() instanceof Controller) {
        controller = (Controller) getActivity();
    } else {
        throw new IllegalStateException("Parent must implement Controller interface.");
    }
    Bundle arguments = getArguments();
    if (arguments != null) {
        imageUri = arguments.getParcelable(KEY_IMAGE_URI);
    }
    if (imageUri == null) {
        throw new AssertionError("No KEY_IMAGE_URI supplied");
    }
    MediaConstraints mediaConstraints = new PushMediaConstraints(SentMediaQuality.HIGH);
    imageMaxWidth = mediaConstraints.getImageMaxWidth(requireContext());
    imageMaxHeight = mediaConstraints.getImageMaxHeight(requireContext());
}
Also used : PushMediaConstraints(org.thoughtcrime.securesms.mms.PushMediaConstraints) MediaConstraints(org.thoughtcrime.securesms.mms.MediaConstraints) Bundle(android.os.Bundle) Fragment(androidx.fragment.app.Fragment) MediaSendPageFragment(org.thoughtcrime.securesms.mediasend.MediaSendPageFragment) PushMediaConstraints(org.thoughtcrime.securesms.mms.PushMediaConstraints)

Example 7 with MediaConstraints

use of org.thoughtcrime.securesms.mms.MediaConstraints in project Signal-Android by signalapp.

the class ImageEditorFragment method onCreate.

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Fragment parent = getParentFragment();
    if (parent instanceof Controller) {
        controller = (Controller) parent;
    } else if (getActivity() instanceof Controller) {
        controller = (Controller) getActivity();
    } else {
        throw new IllegalStateException("Parent must implement Controller interface.");
    }
    Bundle arguments = getArguments();
    if (arguments != null) {
        imageUri = arguments.getParcelable(KEY_IMAGE_URI);
    }
    if (imageUri == null) {
        throw new AssertionError("No KEY_IMAGE_URI supplied");
    }
    MediaConstraints mediaConstraints = new PushMediaConstraints(SentMediaQuality.HIGH);
    imageMaxWidth = mediaConstraints.getImageMaxWidth(requireContext());
    imageMaxHeight = mediaConstraints.getImageMaxHeight(requireContext());
}
Also used : PushMediaConstraints(org.thoughtcrime.securesms.mms.PushMediaConstraints) MediaConstraints(org.thoughtcrime.securesms.mms.MediaConstraints) Bundle(android.os.Bundle) Fragment(androidx.fragment.app.Fragment) MediaSendPageFragment(org.thoughtcrime.securesms.mediasend.MediaSendPageFragment) PushMediaConstraints(org.thoughtcrime.securesms.mms.PushMediaConstraints)

Example 8 with MediaConstraints

use of org.thoughtcrime.securesms.mms.MediaConstraints in project Signal-Android by signalapp.

the class AttachmentCompressionJob method onRun.

@Override
public void onRun() throws Exception {
    Log.d(TAG, "Running for: " + attachmentId);
    AttachmentDatabase database = SignalDatabase.attachments();
    DatabaseAttachment databaseAttachment = database.getAttachment(attachmentId);
    if (databaseAttachment == null) {
        throw new UndeliverableMessageException("Cannot find the specified attachment.");
    }
    if (databaseAttachment.getTransformProperties().shouldSkipTransform()) {
        Log.i(TAG, "Skipping at the direction of the TransformProperties.");
        return;
    }
    MediaConstraints mediaConstraints = mms ? MediaConstraints.getMmsMediaConstraints(mmsSubscriptionId) : MediaConstraints.getPushMediaConstraints(SentMediaQuality.fromCode(databaseAttachment.getTransformProperties().getSentMediaQuality()));
    compress(database, mediaConstraints, databaseAttachment);
}
Also used : MediaConstraints(org.thoughtcrime.securesms.mms.MediaConstraints) UndeliverableMessageException(org.thoughtcrime.securesms.transport.UndeliverableMessageException) DatabaseAttachment(org.thoughtcrime.securesms.attachments.DatabaseAttachment) AttachmentDatabase(org.thoughtcrime.securesms.database.AttachmentDatabase)

Example 9 with MediaConstraints

use of org.thoughtcrime.securesms.mms.MediaConstraints in project Signal-Android by signalapp.

the class MmsSendJob method constructSendPdu.

private SendReq constructSendPdu(OutgoingMediaMessage message) throws UndeliverableMessageException {
    SendReq req = new SendReq();
    String lineNumber = getMyNumber(context);
    MediaConstraints mediaConstraints = MediaConstraints.getMmsMediaConstraints(message.getSubscriptionId());
    List<Attachment> scaledAttachments = message.getAttachments();
    if (!TextUtils.isEmpty(lineNumber)) {
        req.setFrom(new EncodedStringValue(lineNumber));
    } else {
        req.setFrom(new EncodedStringValue(SignalStore.account().getE164()));
    }
    if (message.getRecipient().isMmsGroup()) {
        List<Recipient> members = SignalDatabase.groups().getGroupMembers(message.getRecipient().requireGroupId(), GroupDatabase.MemberSet.FULL_MEMBERS_EXCLUDING_SELF);
        for (Recipient member : members) {
            if (!member.hasSmsAddress()) {
                throw new UndeliverableMessageException("One of the group recipients did not have an SMS address! " + member.getId());
            }
            if (message.getDistributionType() == ThreadDatabase.DistributionTypes.BROADCAST) {
                req.addBcc(new EncodedStringValue(member.requireSmsAddress()));
            } else {
                req.addTo(new EncodedStringValue(member.requireSmsAddress()));
            }
        }
    } else {
        if (!message.getRecipient().hasSmsAddress()) {
            throw new UndeliverableMessageException("Recipient did not have an SMS address! " + message.getRecipient().getId());
        }
        req.addTo(new EncodedStringValue(message.getRecipient().requireSmsAddress()));
    }
    req.setDate(System.currentTimeMillis() / 1000);
    PduBody body = new PduBody();
    int size = 0;
    if (!TextUtils.isEmpty(message.getBody())) {
        PduPart part = new PduPart();
        String name = String.valueOf(System.currentTimeMillis());
        part.setData(Util.toUtf8Bytes(message.getBody()));
        part.setCharset(CharacterSets.UTF_8);
        part.setContentType(ContentType.TEXT_PLAIN.getBytes());
        part.setContentId(name.getBytes());
        part.setContentLocation((name + ".txt").getBytes());
        part.setName((name + ".txt").getBytes());
        body.addPart(part);
        size += getPartSize(part);
    }
    for (Attachment attachment : scaledAttachments) {
        try {
            if (attachment.getUri() == null)
                throw new IOException("Assertion failed, attachment for outgoing MMS has no data!");
            String fileName = attachment.getFileName();
            PduPart part = new PduPart();
            if (fileName == null) {
                fileName = String.valueOf(Math.abs(new SecureRandom().nextLong()));
                String fileExtension = MimeTypeMap.getSingleton().getExtensionFromMimeType(attachment.getContentType());
                if (fileExtension != null)
                    fileName = fileName + "." + fileExtension;
            }
            if (attachment.getContentType().startsWith("text")) {
                part.setCharset(CharacterSets.UTF_8);
            }
            part.setContentType(attachment.getContentType().getBytes());
            part.setContentLocation(fileName.getBytes());
            part.setName(fileName.getBytes());
            int index = fileName.lastIndexOf(".");
            String contentId = (index == -1) ? fileName : fileName.substring(0, index);
            part.setContentId(contentId.getBytes());
            part.setData(StreamUtil.readFully(PartAuthority.getAttachmentStream(context, attachment.getUri())));
            body.addPart(part);
            size += getPartSize(part);
        } catch (IOException e) {
            Log.w(TAG, e);
        }
    }
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    SmilXmlSerializer.serialize(SmilHelper.createSmilDocument(body), out);
    PduPart smilPart = new PduPart();
    smilPart.setContentId("smil".getBytes());
    smilPart.setContentLocation("smil.xml".getBytes());
    smilPart.setContentType(ContentType.APP_SMIL.getBytes());
    smilPart.setData(out.toByteArray());
    body.addPart(0, smilPart);
    req.setBody(body);
    req.setMessageSize(size);
    req.setMessageClass(PduHeaders.MESSAGE_CLASS_PERSONAL_STR.getBytes());
    req.setExpiry(7 * 24 * 60 * 60);
    try {
        req.setPriority(PduHeaders.PRIORITY_NORMAL);
        req.setDeliveryReport(PduHeaders.VALUE_NO);
        req.setReadReport(PduHeaders.VALUE_NO);
    } catch (InvalidHeaderValueException e) {
    }
    return req;
}
Also used : EncodedStringValue(com.google.android.mms.pdu_alt.EncodedStringValue) PduBody(com.google.android.mms.pdu_alt.PduBody) SecureRandom(java.security.SecureRandom) Attachment(org.thoughtcrime.securesms.attachments.Attachment) DatabaseAttachment(org.thoughtcrime.securesms.attachments.DatabaseAttachment) Recipient(org.thoughtcrime.securesms.recipients.Recipient) IOException(java.io.IOException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SendReq(com.google.android.mms.pdu_alt.SendReq) NetworkConstraint(org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint) MediaConstraints(org.thoughtcrime.securesms.mms.MediaConstraints) UndeliverableMessageException(org.thoughtcrime.securesms.transport.UndeliverableMessageException) InvalidHeaderValueException(com.google.android.mms.InvalidHeaderValueException) PduPart(com.google.android.mms.pdu_alt.PduPart)

Aggregations

MediaConstraints (org.thoughtcrime.securesms.mms.MediaConstraints)9 DatabaseAttachment (org.thoughtcrime.securesms.attachments.DatabaseAttachment)4 UndeliverableMessageException (org.thoughtcrime.securesms.transport.UndeliverableMessageException)4 Attachment (org.thoughtcrime.securesms.attachments.Attachment)3 Bundle (android.os.Bundle)2 Fragment (androidx.fragment.app.Fragment)2 InvalidHeaderValueException (com.google.android.mms.InvalidHeaderValueException)2 EncodedStringValue (com.google.android.mms.pdu_alt.EncodedStringValue)2 PduBody (com.google.android.mms.pdu_alt.PduBody)2 PduPart (com.google.android.mms.pdu_alt.PduPart)2 SendReq (com.google.android.mms.pdu_alt.SendReq)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 IOException (java.io.IOException)2 SecureRandom (java.security.SecureRandom)2 TransportOptions (org.thoughtcrime.securesms.TransportOptions)2 AttachmentDatabase (org.thoughtcrime.securesms.database.AttachmentDatabase)2 NetworkConstraint (org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint)2 MediaSendPageFragment (org.thoughtcrime.securesms.mediasend.MediaSendPageFragment)2 PushMediaConstraints (org.thoughtcrime.securesms.mms.PushMediaConstraints)2 Recipient (org.thoughtcrime.securesms.recipients.Recipient)2