use of com.android.mms.ExceedMessageSizeException in project android-aosp-mms by slvn.
the class SlideEditorActivity method onActivityResult.
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode != RESULT_OK) {
return;
}
switch(requestCode) {
case REQUEST_CODE_EDIT_TEXT:
// XXX where does this come from? Action is probably not the
// right place to have the text...
mSlideshowEditor.changeText(mPosition, data.getAction());
break;
case REQUEST_CODE_TAKE_PICTURE:
Uri pictureUri = null;
boolean showError = false;
try {
pictureUri = TempFileProvider.renameScrapFile(".jpg", Integer.toString(mPosition), this);
if (pictureUri == null) {
showError = true;
} else {
// Remove the old captured picture's thumbnail from the cache
MmsApp.getApplication().getThumbnailManager().removeThumbnail(pictureUri);
mSlideshowEditor.changeImage(mPosition, pictureUri);
setReplaceButtonText(R.string.replace_image);
}
} catch (MmsException e) {
Log.e(TAG, "add image failed", e);
showError = true;
} catch (UnsupportContentTypeException e) {
MessageUtils.showErrorDialog(SlideEditorActivity.this, getResourcesString(R.string.unsupported_media_format, getPictureString()), getResourcesString(R.string.select_different_media, getPictureString()));
} catch (ResolutionException e) {
MessageUtils.resizeImageAsync(this, pictureUri, new Handler(), mResizeImageCallback, false);
} catch (ExceedMessageSizeException e) {
MessageUtils.resizeImageAsync(this, pictureUri, new Handler(), mResizeImageCallback, false);
}
if (showError) {
notifyUser("add picture failed");
Toast.makeText(SlideEditorActivity.this, getResourcesString(R.string.failed_to_add_media, getPictureString()), Toast.LENGTH_SHORT).show();
}
break;
case REQUEST_CODE_CHANGE_PICTURE:
try {
mSlideshowEditor.changeImage(mPosition, data.getData());
setReplaceButtonText(R.string.replace_image);
} catch (MmsException e) {
Log.e(TAG, "add image failed", e);
notifyUser("add picture failed");
Toast.makeText(SlideEditorActivity.this, getResourcesString(R.string.failed_to_add_media, getPictureString()), Toast.LENGTH_SHORT).show();
} catch (UnsupportContentTypeException e) {
MessageUtils.showErrorDialog(SlideEditorActivity.this, getResourcesString(R.string.unsupported_media_format, getPictureString()), getResourcesString(R.string.select_different_media, getPictureString()));
} catch (ResolutionException e) {
MessageUtils.resizeImageAsync(this, data.getData(), new Handler(), mResizeImageCallback, false);
} catch (ExceedMessageSizeException e) {
MessageUtils.resizeImageAsync(this, data.getData(), new Handler(), mResizeImageCallback, false);
}
break;
case REQUEST_CODE_CHANGE_MUSIC:
case REQUEST_CODE_RECORD_SOUND:
Uri uri;
if (requestCode == REQUEST_CODE_CHANGE_MUSIC) {
uri = (Uri) data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
if (Settings.System.DEFAULT_RINGTONE_URI.equals(uri)) {
return;
}
} else {
uri = data.getData();
}
try {
mSlideshowEditor.changeAudio(mPosition, uri);
} catch (MmsException e) {
Log.e(TAG, "add audio failed", e);
notifyUser("add music failed");
Toast.makeText(SlideEditorActivity.this, getResourcesString(R.string.failed_to_add_media, getAudioString()), Toast.LENGTH_SHORT).show();
} catch (UnsupportContentTypeException e) {
MessageUtils.showErrorDialog(SlideEditorActivity.this, getResourcesString(R.string.unsupported_media_format, getAudioString()), getResourcesString(R.string.select_different_media, getAudioString()));
} catch (ExceedMessageSizeException e) {
MessageUtils.showErrorDialog(SlideEditorActivity.this, getResourcesString(R.string.exceed_message_size_limitation), getResourcesString(R.string.failed_to_add_media, getAudioString()));
}
break;
case REQUEST_CODE_TAKE_VIDEO:
try {
Uri videoUri = TempFileProvider.renameScrapFile(".3gp", Integer.toString(mPosition), this);
mSlideshowEditor.changeVideo(mPosition, videoUri);
} catch (MmsException e) {
notifyUser("add video failed");
Toast.makeText(SlideEditorActivity.this, getResourcesString(R.string.failed_to_add_media, getVideoString()), Toast.LENGTH_SHORT).show();
} catch (UnsupportContentTypeException e) {
MessageUtils.showErrorDialog(SlideEditorActivity.this, getResourcesString(R.string.unsupported_media_format, getVideoString()), getResourcesString(R.string.select_different_media, getVideoString()));
} catch (ExceedMessageSizeException e) {
MessageUtils.showErrorDialog(SlideEditorActivity.this, getResourcesString(R.string.exceed_message_size_limitation), getResourcesString(R.string.failed_to_add_media, getVideoString()));
}
break;
case REQUEST_CODE_CHANGE_VIDEO:
try {
mSlideshowEditor.changeVideo(mPosition, data.getData());
} catch (MmsException e) {
Log.e(TAG, "add video failed", e);
notifyUser("add video failed");
Toast.makeText(SlideEditorActivity.this, getResourcesString(R.string.failed_to_add_media, getVideoString()), Toast.LENGTH_SHORT).show();
} catch (UnsupportContentTypeException e) {
MessageUtils.showErrorDialog(SlideEditorActivity.this, getResourcesString(R.string.unsupported_media_format, getVideoString()), getResourcesString(R.string.select_different_media, getVideoString()));
} catch (ExceedMessageSizeException e) {
MessageUtils.showErrorDialog(SlideEditorActivity.this, getResourcesString(R.string.exceed_message_size_limitation), getResourcesString(R.string.failed_to_add_media, getVideoString()));
}
break;
case REQUEST_CODE_CHANGE_DURATION:
mSlideshowEditor.changeDuration(mPosition, Integer.valueOf(data.getAction()) * 1000);
break;
}
}
use of com.android.mms.ExceedMessageSizeException in project android-aosp-mms by slvn.
the class ImageModel method resizeMedia.
@Override
protected void resizeMedia(int byteLimit, long messageId) throws MmsException {
UriImage image = new UriImage(mContext, getUri());
int widthLimit = MmsConfig.getMaxImageWidth();
int heightLimit = MmsConfig.getMaxImageHeight();
int size = getMediaSize();
// possible.
if (image.getHeight() > image.getWidth()) {
int temp = widthLimit;
widthLimit = heightLimit;
heightLimit = temp;
}
if (Log.isLoggable(LogTag.APP, Log.VERBOSE)) {
Log.v(TAG, "resizeMedia size: " + size + " image.getWidth(): " + image.getWidth() + " widthLimit: " + widthLimit + " image.getHeight(): " + image.getHeight() + " heightLimit: " + heightLimit + " image.getContentType(): " + image.getContentType());
}
// set the size.
if (size != 0 && size <= byteLimit && image.getWidth() <= widthLimit && image.getHeight() <= heightLimit && SUPPORTED_MMS_IMAGE_CONTENT_TYPES.contains(image.getContentType())) {
if (Log.isLoggable(LogTag.APP, Log.VERBOSE)) {
Log.v(TAG, "resizeMedia - already sized");
}
return;
}
PduPart part = image.getResizedImageAsPart(widthLimit, heightLimit, byteLimit);
if (part == null) {
throw new ExceedMessageSizeException("Not enough memory to turn image into part: " + getUri());
}
// Update the content type because it may have changed due to resizing/recompressing
mContentType = new String(part.getContentType());
String src = getSrc();
byte[] srcBytes = src.getBytes();
part.setContentLocation(srcBytes);
int period = src.lastIndexOf(".");
byte[] contentId = period != -1 ? src.substring(0, period).getBytes() : srcBytes;
part.setContentId(contentId);
PduPersister persister = PduPersister.getPduPersister(mContext);
this.mSize = part.getData().length;
if (Log.isLoggable(LogTag.APP, Log.VERBOSE)) {
Log.v(TAG, "resizeMedia mSize: " + mSize);
}
Uri newUri = persister.persistPart(part, messageId, null);
setUri(newUri);
}
use of com.android.mms.ExceedMessageSizeException in project android-aosp-mms by slvn.
the class WorkingMessage method sendMmsWorker.
private void sendMmsWorker(Conversation conv, Uri mmsUri, PduPersister persister, SlideshowModel slideshow, SendReq sendReq, boolean textOnly) {
long threadId = 0;
Cursor cursor = null;
boolean newMessage = false;
try {
// Put a placeholder message in the database first
DraftCache.getInstance().setSavingDraft(true);
mStatusListener.onPreMessageSent();
// Make sure we are still using the correct thread ID for our
// recipient set.
threadId = conv.ensureThreadId();
if (Log.isLoggable(LogTag.APP, Log.VERBOSE)) {
LogTag.debug("sendMmsWorker: update draft MMS message " + mmsUri + " threadId: " + threadId);
}
// One last check to verify the address of the recipient.
String[] dests = conv.getRecipients().getNumbers(true);
if (dests.length == 1) {
// verify the single address matches what's in the database. If we get a different
// address back, jam the new value back into the SendReq.
String newAddress = Conversation.verifySingleRecipient(mActivity, conv.getThreadId(), dests[0]);
if (Log.isLoggable(LogTag.APP, Log.VERBOSE)) {
LogTag.debug("sendMmsWorker: newAddress " + newAddress + " dests[0]: " + dests[0]);
}
if (!newAddress.equals(dests[0])) {
dests[0] = newAddress;
EncodedStringValue[] encodedNumbers = EncodedStringValue.encodeStrings(dests);
if (encodedNumbers != null) {
if (Log.isLoggable(LogTag.APP, Log.VERBOSE)) {
LogTag.debug("sendMmsWorker: REPLACING number!!!");
}
sendReq.setTo(encodedNumbers);
}
}
}
newMessage = mmsUri == null;
if (newMessage) {
// Write something in the database so the new message will appear as sending
ContentValues values = new ContentValues();
values.put(Mms.MESSAGE_BOX, Mms.MESSAGE_BOX_OUTBOX);
values.put(Mms.THREAD_ID, threadId);
values.put(Mms.MESSAGE_TYPE, PduHeaders.MESSAGE_TYPE_SEND_REQ);
if (textOnly) {
values.put(Mms.TEXT_ONLY, 1);
}
mmsUri = SqliteWrapper.insert(mActivity, mContentResolver, Mms.Outbox.CONTENT_URI, values);
}
mStatusListener.onMessageSent();
// If user tries to send the message, it's a signal the inputted text is
// what they wanted.
UserHappinessSignals.userAcceptedImeText(mActivity);
// First make sure we don't have too many outstanding unsent message.
cursor = SqliteWrapper.query(mActivity, mContentResolver, Mms.Outbox.CONTENT_URI, MMS_OUTBOX_PROJECTION, null, null, null);
if (cursor != null) {
long maxMessageSize = MmsConfig.getMaxSizeScaleForPendingMmsAllowed() * MmsConfig.getMaxMessageSize();
long totalPendingSize = 0;
while (cursor.moveToNext()) {
totalPendingSize += cursor.getLong(MMS_MESSAGE_SIZE_INDEX);
}
if (totalPendingSize >= maxMessageSize) {
// it wasn't successfully sent. Allow it to be saved as a draft.
unDiscard();
mStatusListener.onMaxPendingMessagesReached();
markMmsMessageWithError(mmsUri);
return;
}
}
} finally {
if (cursor != null) {
cursor.close();
}
}
try {
if (newMessage) {
// Create a new MMS message if one hasn't been made yet.
mmsUri = createDraftMmsMessage(persister, sendReq, slideshow, mmsUri, mActivity, null);
} else {
// Otherwise, sync the MMS message in progress to disk.
updateDraftMmsMessage(mmsUri, persister, slideshow, sendReq, null);
}
// Be paranoid and clean any draft SMS up.
deleteDraftSmsMessage(threadId);
} finally {
DraftCache.getInstance().setSavingDraft(false);
}
// Resize all the resizeable attachments (e.g. pictures) to fit
// in the remaining space in the slideshow.
int error = 0;
try {
slideshow.finalResize(mmsUri);
} catch (ExceedMessageSizeException e1) {
error = MESSAGE_SIZE_EXCEEDED;
} catch (MmsException e1) {
error = UNKNOWN_ERROR;
}
if (error != 0) {
markMmsMessageWithError(mmsUri);
mStatusListener.onAttachmentError(error);
return;
}
MessageSender sender = new MmsMessageSender(mActivity, mmsUri, slideshow.getCurrentMessageSize());
try {
if (!sender.sendMessage(threadId)) {
// The message was sent through SMS protocol, we should
// delete the copy which was previously saved in MMS drafts.
SqliteWrapper.delete(mActivity, mContentResolver, mmsUri, null, null);
}
// Make sure this thread isn't over the limits in message count
Recycler.getMmsRecycler().deleteOldMessagesByThreadId(mActivity, threadId);
} catch (Exception e) {
Log.e(TAG, "Failed to send message: " + mmsUri + ", threadId=" + threadId, e);
}
MmsWidgetProvider.notifyDatasetChanged(mActivity);
}
use of com.android.mms.ExceedMessageSizeException in project android-aosp-mms by slvn.
the class SlideshowModel method finalResize.
/**
* Resize all the resizeable media objects to fit in the remaining size of the slideshow.
* This should be called off of the UI thread.
*
* @throws MmsException, ExceedMessageSizeException
*/
public void finalResize(Uri messageUri) throws MmsException, ExceedMessageSizeException {
// Figure out if we have any media items that need to be resized and total up the
// sizes of the items that can't be resized.
int resizableCnt = 0;
int fixedSizeTotal = 0;
for (SlideModel slide : mSlides) {
for (MediaModel media : slide) {
if (media.getMediaResizable()) {
++resizableCnt;
} else {
fixedSizeTotal += media.getMediaSize();
}
}
}
if (Log.isLoggable(LogTag.APP, Log.VERBOSE)) {
Log.v(TAG, "finalResize: original message size: " + getCurrentMessageSize() + " getMaxMessageSize: " + MmsConfig.getMaxMessageSize() + " fixedSizeTotal: " + fixedSizeTotal);
}
if (resizableCnt > 0) {
int remainingSize = MmsConfig.getMaxMessageSize() - fixedSizeTotal - SLIDESHOW_SLOP;
if (remainingSize <= 0) {
throw new ExceedMessageSizeException("No room for pictures");
}
long messageId = ContentUris.parseId(messageUri);
int bytesPerMediaItem = remainingSize / resizableCnt;
// Resize the resizable media items to fit within their byte limit.
for (SlideModel slide : mSlides) {
for (MediaModel media : slide) {
if (media.getMediaResizable()) {
media.resizeMedia(bytesPerMediaItem, messageId);
}
}
}
// One last time through to calc the real message size.
int totalSize = 0;
for (SlideModel slide : mSlides) {
for (MediaModel media : slide) {
totalSize += media.getMediaSize();
}
}
if (Log.isLoggable(LogTag.APP, Log.VERBOSE)) {
Log.v(TAG, "finalResize: new message size: " + totalSize);
}
if (totalSize > MmsConfig.getMaxMessageSize()) {
throw new ExceedMessageSizeException("After compressing pictures, message too big");
}
setCurrentMessageSize(totalSize);
// clear the cached pdu body
onModelChanged(this, true);
PduBody pb = toPduBody();
// This will write out all the new parts to:
// /data/data/com.android.providers.telephony/app_parts
// and at the same time delete the old parts.
PduPersister.getPduPersister(mContext).updateParts(messageUri, pb, null);
}
}
Aggregations