use of com.google.android.mms.pdu.EncodedStringValue in project XobotOS by xamarin.
the class PduPersister method setEncodedStringValueToHeaders.
private void setEncodedStringValueToHeaders(Cursor c, int columnIndex, PduHeaders headers, int mapColumn) {
String s = c.getString(columnIndex);
if ((s != null) && (s.length() > 0)) {
int charsetColumnIndex = CHARSET_COLUMN_INDEX_MAP.get(mapColumn);
int charset = c.getInt(charsetColumnIndex);
EncodedStringValue value = new EncodedStringValue(charset, getBytes(s));
headers.setEncodedStringValue(value, mapColumn);
}
}
use of com.google.android.mms.pdu.EncodedStringValue in project XobotOS by xamarin.
the class PduPersister method updateHeaders.
/**
* Update headers of a SendReq.
*
* @param uri The PDU which need to be updated.
* @param pdu New headers.
* @throws MmsException Bad URI or updating failed.
*/
public void updateHeaders(Uri uri, SendReq sendReq) {
PDU_CACHE_INSTANCE.purge(uri);
ContentValues values = new ContentValues(10);
byte[] contentType = sendReq.getContentType();
if (contentType != null) {
values.put(Mms.CONTENT_TYPE, toIsoString(contentType));
}
long date = sendReq.getDate();
if (date != -1) {
values.put(Mms.DATE, date);
}
int deliveryReport = sendReq.getDeliveryReport();
if (deliveryReport != 0) {
values.put(Mms.DELIVERY_REPORT, deliveryReport);
}
long expiry = sendReq.getExpiry();
if (expiry != -1) {
values.put(Mms.EXPIRY, expiry);
}
byte[] msgClass = sendReq.getMessageClass();
if (msgClass != null) {
values.put(Mms.MESSAGE_CLASS, toIsoString(msgClass));
}
int priority = sendReq.getPriority();
if (priority != 0) {
values.put(Mms.PRIORITY, priority);
}
int readReport = sendReq.getReadReport();
if (readReport != 0) {
values.put(Mms.READ_REPORT, readReport);
}
byte[] transId = sendReq.getTransactionId();
if (transId != null) {
values.put(Mms.TRANSACTION_ID, toIsoString(transId));
}
EncodedStringValue subject = sendReq.getSubject();
if (subject != null) {
values.put(Mms.SUBJECT, toIsoString(subject.getTextString()));
values.put(Mms.SUBJECT_CHARSET, subject.getCharacterSet());
} else {
values.put(Mms.SUBJECT, "");
}
long messageSize = sendReq.getMessageSize();
if (messageSize > 0) {
values.put(Mms.MESSAGE_SIZE, messageSize);
}
PduHeaders headers = sendReq.getPduHeaders();
HashSet<String> recipients = new HashSet<String>();
for (int addrType : ADDRESS_FIELDS) {
EncodedStringValue[] array = null;
if (addrType == PduHeaders.FROM) {
EncodedStringValue v = headers.getEncodedStringValue(addrType);
if (v != null) {
array = new EncodedStringValue[1];
array[0] = v;
}
} else {
array = headers.getEncodedStringValues(addrType);
}
if (array != null) {
long msgId = ContentUris.parseId(uri);
updateAddress(msgId, addrType, array);
if (addrType == PduHeaders.TO) {
for (EncodedStringValue v : array) {
if (v != null) {
recipients.add(v.getString());
}
}
}
}
}
long threadId = Threads.getOrCreateThreadId(mContext, recipients);
values.put(Mms.THREAD_ID, threadId);
SqliteWrapper.update(mContext, mContentResolver, uri, values, null, null);
}
use of com.google.android.mms.pdu.EncodedStringValue in project XobotOS by xamarin.
the class PduPersister method persistAddress.
private void persistAddress(long msgId, int type, EncodedStringValue[] array) {
ContentValues values = new ContentValues(3);
for (EncodedStringValue addr : array) {
// Clear all values first.
values.clear();
values.put(Addr.ADDRESS, toIsoString(addr.getTextString()));
values.put(Addr.CHARSET, addr.getCharacterSet());
values.put(Addr.TYPE, type);
Uri uri = Uri.parse("content://mms/" + msgId + "/addr");
SqliteWrapper.insert(mContext, mContentResolver, uri, values);
}
}
use of com.google.android.mms.pdu.EncodedStringValue in project android-aosp-mms by slvn.
the class WorkingMessage method makeSendReq.
/**
* makeSendReq should always return a non-null SendReq, whether the dest addresses are
* valid or not.
*/
private static SendReq makeSendReq(Conversation conv, CharSequence subject) {
String[] dests = conv.getRecipients().getNumbers(true);
SendReq req = new SendReq();
EncodedStringValue[] encodedNumbers = EncodedStringValue.encodeStrings(dests);
if (encodedNumbers != null) {
req.setTo(encodedNumbers);
}
if (!TextUtils.isEmpty(subject)) {
req.setSubject(new EncodedStringValue(subject.toString()));
}
req.setDate(System.currentTimeMillis() / 1000L);
return req;
}
use of com.google.android.mms.pdu.EncodedStringValue 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);
}
Aggregations