Search in sources :

Example 6 with PduPart

use of com.google.android.mms.pdu_alt.PduPart in project qksms by moezbhatti.

the class MessageUtils method haveSomethingToCopyToSDCard.

/**
 * Looks to see if there are any valid parts of the attachment that can be copied to a SD card.
 *
 * @param context
 * @param msgId
 */
public static boolean haveSomethingToCopyToSDCard(Context context, long msgId) {
    PduBody body = null;
    try {
        body = SlideshowModel.getPduBody(context, ContentUris.withAppendedId(Mms.CONTENT_URI, msgId));
    } catch (MmsException e) {
        Log.e(TAG, "haveSomethingToCopyToSDCard can't load pdu body: " + msgId);
    }
    if (body == null) {
        return false;
    }
    boolean result = false;
    int partNum = body.getPartsNum();
    for (int i = 0; i < partNum; i++) {
        PduPart part = body.getPart(i);
        String type = new String(part.getContentType());
        if (Log.isLoggable(LogTag.APP, Log.VERBOSE)) {
            Log.v(TAG, "[CMA] haveSomethingToCopyToSDCard: part[" + i + "] contentType=" + type);
        }
        if (ContentType.isImageType(type) || ContentType.isVideoType(type) || ContentType.isAudioType(type) || DrmUtils.isDrmType(type)) {
            result = true;
            break;
        }
    }
    return result;
}
Also used : MmsException(com.google.android.mms.MmsException) PduBody(com.google.android.mms.pdu_alt.PduBody) PduPart(com.google.android.mms.pdu_alt.PduPart)

Example 7 with PduPart

use of com.google.android.mms.pdu_alt.PduPart in project Signal-Android by signalapp.

the class MmsDownloadJob method storeRetrievedMms.

private void storeRetrievedMms(String contentLocation, long messageId, long threadId, RetrieveConf retrieved, int subscriptionId, @Nullable Address notificationFrom) throws MmsException, NoSessionException, DuplicateMessageException, InvalidMessageException, LegacyMessageException {
    MmsDatabase database = DatabaseFactory.getMmsDatabase(context);
    SingleUseBlobProvider provider = SingleUseBlobProvider.getInstance();
    Optional<Address> group = Optional.absent();
    Set<Address> members = new HashSet<>();
    String body = null;
    List<Attachment> attachments = new LinkedList<>();
    Address from;
    if (retrieved.getFrom() != null) {
        from = Address.fromExternal(context, Util.toIsoString(retrieved.getFrom().getTextString()));
    } else if (notificationFrom != null) {
        from = notificationFrom;
    } else {
        from = Address.UNKNOWN;
    }
    if (retrieved.getTo() != null) {
        for (EncodedStringValue toValue : retrieved.getTo()) {
            members.add(Address.fromExternal(context, Util.toIsoString(toValue.getTextString())));
        }
    }
    if (retrieved.getCc() != null) {
        for (EncodedStringValue ccValue : retrieved.getCc()) {
            members.add(Address.fromExternal(context, Util.toIsoString(ccValue.getTextString())));
        }
    }
    members.add(from);
    members.add(Address.fromExternal(context, TextSecurePreferences.getLocalNumber(context)));
    if (retrieved.getBody() != null) {
        body = PartParser.getMessageText(retrieved.getBody());
        PduBody media = PartParser.getSupportedMediaParts(retrieved.getBody());
        for (int i = 0; i < media.getPartsNum(); i++) {
            PduPart part = media.getPart(i);
            if (part.getData() != null) {
                Uri uri = provider.createUri(part.getData());
                String name = null;
                if (part.getName() != null)
                    name = Util.toIsoString(part.getName());
                attachments.add(new UriAttachment(uri, Util.toIsoString(part.getContentType()), AttachmentDatabase.TRANSFER_PROGRESS_DONE, part.getData().length, name, false));
            }
        }
    }
    if (members.size() > 2) {
        group = Optional.of(Address.fromSerialized(DatabaseFactory.getGroupDatabase(context).getOrCreateGroupForMembers(new LinkedList<>(members), true)));
    }
    IncomingMediaMessage message = new IncomingMediaMessage(from, group, body, retrieved.getDate() * 1000L, attachments, subscriptionId, 0, false);
    Optional<InsertResult> insertResult = database.insertMessageInbox(message, contentLocation, threadId);
    if (insertResult.isPresent()) {
        database.delete(messageId);
        MessageNotifier.updateNotification(context, insertResult.get().getThreadId());
    }
}
Also used : InsertResult(org.thoughtcrime.securesms.database.MessagingDatabase.InsertResult) EncodedStringValue(com.google.android.mms.pdu_alt.EncodedStringValue) Address(org.thoughtcrime.securesms.database.Address) PduBody(com.google.android.mms.pdu_alt.PduBody) IncomingMediaMessage(org.thoughtcrime.securesms.mms.IncomingMediaMessage) UriAttachment(org.thoughtcrime.securesms.attachments.UriAttachment) Attachment(org.thoughtcrime.securesms.attachments.Attachment) Uri(android.net.Uri) LinkedList(java.util.LinkedList) SingleUseBlobProvider(org.thoughtcrime.securesms.providers.SingleUseBlobProvider) PduPart(com.google.android.mms.pdu_alt.PduPart) UriAttachment(org.thoughtcrime.securesms.attachments.UriAttachment) MmsDatabase(org.thoughtcrime.securesms.database.MmsDatabase) HashSet(java.util.HashSet)

Example 8 with PduPart

use of com.google.android.mms.pdu_alt.PduPart in project kdeconnect-android by KDE.

the class SmsMmsUtils method addTextPart.

/**
 * Copy of the same-name method from https://github.com/klinker41/android-smsmms
 */
private static int addTextPart(PduBody pb, MMSPart p, int id) {
    String filename = p.Name;
    final PduPart part = new PduPart();
    // Set Charset if it's a text media.
    if (p.MimeType.startsWith("text")) {
        part.setCharset(CharacterSets.UTF_8);
    }
    // Set Content-Type.
    part.setContentType(p.MimeType.getBytes());
    // Set Content-Location.
    part.setContentLocation(filename.getBytes());
    int index = filename.lastIndexOf(".");
    String contentId = (index == -1) ? filename : filename.substring(0, index);
    part.setContentId(contentId.getBytes());
    part.setData(p.Data);
    pb.addPart(part);
    return part.getData().length;
}
Also used : PduPart(com.google.android.mms.pdu_alt.PduPart)

Example 9 with PduPart

use of com.google.android.mms.pdu_alt.PduPart in project qksms by moezbhatti.

the class MessageUtils method resizeImageAsync.

public static void resizeImageAsync(final Context context, final Uri imageUri, final Handler handler, final ResizeImageResultCallback cb, final boolean append) {
    // Show a progress toast if the resize hasn't finished
    // within one second.
    // Stash the runnable for showing it away so we can cancel
    // it later if the resize completes ahead of the deadline.
    final Runnable showProgress = new Runnable() {

        @Override
        public void run() {
            Toast.makeText(context, R.string.compressing, Toast.LENGTH_SHORT).show();
        }
    };
    // Schedule it for one second from now.
    handler.postDelayed(showProgress, 1000);
    new Thread(new Runnable() {

        @Override
        public void run() {
            final PduPart part;
            try {
                UriImage image = new UriImage(context, imageUri);
                int widthLimit = MmsConfig.getMaxImageWidth();
                int heightLimit = MmsConfig.getMaxImageHeight();
                // as little as possible.
                if (image.getHeight() > image.getWidth()) {
                    int temp = widthLimit;
                    widthLimit = heightLimit;
                    heightLimit = temp;
                }
                part = image.getResizedImageAsPart(widthLimit, heightLimit, MmsConfig.getMaxMessageSize() - MESSAGE_OVERHEAD);
            } finally {
                // Cancel pending show of the progress toast if necessary.
                handler.removeCallbacks(showProgress);
            }
            handler.post(new Runnable() {

                @Override
                public void run() {
                    cb.onResizeResult(part, append);
                }
            });
        }
    }, "MessageUtils.resizeImageAsync").start();
}
Also used : UriImage(com.moez.QKSMS.common.google.UriImage) PduPart(com.google.android.mms.pdu_alt.PduPart)

Example 10 with PduPart

use of com.google.android.mms.pdu_alt.PduPart in project qksms by moezbhatti.

the class SmilHelper method createSmilDocument.

private static SMILDocument createSmilDocument(PduBody pb) {
    if (Config.LOGV) {
        Log.v(TAG, "Creating default SMIL document.");
    }
    SMILDocument document = new SmilDocumentImpl();
    // Create root element.
    // FIXME: Should we create root element in the constructor of document?
    SMILElement smil = (SMILElement) document.createElement("smil");
    smil.setAttribute("xmlns", "http://www.w3.org/2001/SMIL20/Language");
    document.appendChild(smil);
    // Create <head> and <layout> element.
    SMILElement head = (SMILElement) document.createElement("head");
    smil.appendChild(head);
    SMILLayoutElement layout = (SMILLayoutElement) document.createElement("layout");
    head.appendChild(layout);
    // Create <body> element and add a empty <par>.
    SMILElement body = (SMILElement) document.createElement("body");
    smil.appendChild(body);
    SMILParElement par = addPar(document);
    // Create media objects for the parts in PDU.
    int partsNum = pb.getPartsNum();
    if (partsNum == 0) {
        return document;
    }
    DrmManagerClient drmManagerClient = QKSMSApp.getApplication().getDrmManagerClient();
    boolean hasText = false;
    boolean hasMedia = false;
    for (int i = 0; i < partsNum; i++) {
        // Create new <par> element.
        if ((par == null) || (hasMedia && hasText)) {
            par = addPar(document);
            hasText = false;
            hasMedia = false;
        }
        PduPart part = pb.getPart(i);
        String contentType = new String(part.getContentType());
        if (ContentType.isDrmType(contentType)) {
            contentType = drmManagerClient.getOriginalMimeType(part.getDataUri());
        }
        if (contentType.equals(ContentType.TEXT_PLAIN) || contentType.equalsIgnoreCase(ContentType.APP_WAP_XHTML) || contentType.equals(ContentType.TEXT_HTML)) {
            SMILMediaElement textElement = createMediaElement(ELEMENT_TAG_TEXT, document, part.generateLocation());
            par.appendChild(textElement);
            hasText = true;
        } else if (ContentType.isImageType(contentType)) {
            SMILMediaElement imageElement = createMediaElement(ELEMENT_TAG_IMAGE, document, part.generateLocation());
            par.appendChild(imageElement);
            hasMedia = true;
        } else if (ContentType.isVideoType(contentType)) {
            SMILMediaElement videoElement = createMediaElement(ELEMENT_TAG_VIDEO, document, part.generateLocation());
            par.appendChild(videoElement);
            hasMedia = true;
        } else if (ContentType.isAudioType(contentType)) {
            SMILMediaElement audioElement = createMediaElement(ELEMENT_TAG_AUDIO, document, part.generateLocation());
            par.appendChild(audioElement);
            hasMedia = true;
        } else {
            // TODO: handle other media types.
            Log.w(TAG, "unsupport media type");
        }
    }
    return document;
}
Also used : SMILMediaElement(org.w3c.dom.smil.SMILMediaElement) SMILDocument(org.w3c.dom.smil.SMILDocument) SmilDocumentImpl(com.android.mms.dom.smil.SmilDocumentImpl) SMILLayoutElement(org.w3c.dom.smil.SMILLayoutElement) SMILParElement(org.w3c.dom.smil.SMILParElement) PduPart(com.google.android.mms.pdu_alt.PduPart) SMILElement(org.w3c.dom.smil.SMILElement) DrmManagerClient(android.drm.DrmManagerClient)

Aggregations

PduPart (com.google.android.mms.pdu_alt.PduPart)21 PduBody (com.google.android.mms.pdu_alt.PduBody)12 MmsException (com.google.android.mms.MmsException)7 EncodedStringValue (com.google.android.mms.pdu_alt.EncodedStringValue)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 SendReq (com.google.android.mms.pdu_alt.SendReq)4 IOException (java.io.IOException)4 Attachment (org.thoughtcrime.securesms.attachments.Attachment)4 Uri (android.net.Uri)3 InvalidHeaderValueException (com.google.android.mms.InvalidHeaderValueException)3 SMILDocument (org.w3c.dom.smil.SMILDocument)3 SmilDocumentImpl (com.android.mms.dom.smil.SmilDocumentImpl)2 MMSPart (com.google.android.mms.MMSPart)2 PduPersister (com.google.android.mms.pdu_alt.PduPersister)2 UriImage (com.moez.QKSMS.common.google.UriImage)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 LinkedList (java.util.LinkedList)2 UriAttachment (org.thoughtcrime.securesms.attachments.UriAttachment)2 Address (org.thoughtcrime.securesms.database.Address)2