/** * Find all messages to be sent or downloaded before certain time. */ public Cursor getPendingMessages(long dueTime) { Uri.Builder uriBuilder = MessageDAO.MMS_PENDING_URI.buildUpon(); uriBuilder.appendQueryParameter("protocol", "mms"); String selection = PendingMessages.ERROR_TYPE + " < ?" + " AND " + PendingMessages.DUE_TIME + " <= ?"; String[] selectionArgs = new String[] { String.valueOf(MmsSms.ERR_TYPE_GENERIC_PERMANENT), String.valueOf(dueTime) }; return SqliteWrapper.query(mContext, mContentResolver, uriBuilder.build(), null, selection, selectionArgs, PendingMessages.DUE_TIME); }
private void markMmsFailedToSend(Context context, Uri msgUri) { // https://github.com/qklabs/aosp-messenger/blob/master/src/com/android/mms/data/WorkingMessage.java#L1476-1476 try { PduPersister p = PduPersister.getPduPersister(context); // Move the message into MMS Outbox. A trigger will create an entry in // the "pending_msgs" table. p.move(msgUri, Telephony.Mms.Outbox.CONTENT_URI); // Now update the pending_msgs table with an error for that new item. ContentValues values = new ContentValues(1); values.put(Telephony.MmsSms.PendingMessages.ERROR_TYPE, Telephony.MmsSms.ERR_TYPE_GENERIC_PERMANENT); long msgId = ContentUris.parseId(msgUri); SqliteWrapper.update(context, mContentResolver, Telephony.MmsSms.PendingMessages.CONTENT_URI, values, Telephony.MmsSms.PendingMessages.MSG_ID + "=" + msgId, null); } catch (MmsException e) { // Not much we can do here. If the p.move throws an exception, we'll just // leave the message in the draft box. Log.e(TAG, "Failed to move message to outbox and mark as error: " + msgUri, e); } }
private void markMmsMessageWithError(Uri mmsUri) { try { PduPersister p = PduPersister.getPduPersister(mActivity); // Move the message into MMS Outbox. A trigger will create an entry // in // the "pending_msgs" table. p.move(mmsUri, Mms.Outbox.CONTENT_URI); // Now update the pending_msgs table with an error for that new // item. ContentValues values = new ContentValues(1); values.put(PendingMessages.ERROR_TYPE, MmsSms.ERR_TYPE_GENERIC_PERMANENT); long msgId = ContentUris.parseId(mmsUri); SqliteWrapper.update(mActivity, mContentResolver, PendingMessages.CONTENT_URI, values, PendingMessages.MSG_ID + "=" + msgId, null); } catch (MmsException e) { // Not much we can do here. If the p.move throws an exception, we'll // just // leave the message in the draft box. Log.e(TAG, "Failed to move message to outbox and mark as error: " + mmsUri, e); } }
private void markMmsMessageWithError(Uri mmsUri) { try { PduPersister p = PduPersister.getPduPersister(mActivity); // Move the message into MMS Outbox. A trigger will create an entry in // the "pending_msgs" table. p.move(mmsUri, Mms.Outbox.CONTENT_URI); // Now update the pending_msgs table with an error for that new item. ContentValues values = new ContentValues(1); values.put(PendingMessages.ERROR_TYPE, MmsSms.ERR_TYPE_GENERIC_PERMANENT); long msgId = ContentUris.parseId(mmsUri); SqliteWrapper.update(mActivity, mContentResolver, PendingMessages.CONTENT_URI, values, PendingMessages.MSG_ID + "=" + msgId, null); } catch (MmsException e) { // Not much we can do here. If the p.move throws an exception, we'll just // leave the message in the draft box. Log.e(TAG, "Failed to move message to outbox and mark as error: " + mmsUri, e); } }
public static void setRetryAlarm(Context context) { Cursor cursor = PduPersister.getPduPersister(context).getPendingMessages( Long.MAX_VALUE); if (cursor != null) { try { if (cursor.moveToFirst()) { // The result of getPendingMessages() is order by due time. long retryAt = cursor.getLong(cursor.getColumnIndexOrThrow( PendingMessages.DUE_TIME)); Intent service = new Intent( TransactionService.HANDLE_PENDING_TRANSACTIONS_ACTION, null, context, TransactionService.class ); PendingIntent operation = PendingIntent.getService( context, 0, service, PendingIntent.FLAG_ONE_SHOT); AlarmManager am = (AlarmManager) context.getSystemService( Context.ALARM_SERVICE); am.set(AlarmManager.RTC, retryAt, operation); if (LOCAL_LOGV) Log.v(TAG, "Next retry is scheduled at " + (retryAt - System.currentTimeMillis()) + "ms from now"); } } finally { cursor.close(); } } }
/** * Find all messages to be sent or downloaded before certain time. */ public Cursor getPendingMessages(long dueTime) { Uri.Builder uriBuilder = PendingMessages.CONTENT_URI.buildUpon(); uriBuilder.appendQueryParameter("protocol", "mms"); String selection = PendingMessages.ERROR_TYPE + " < ?" + " AND " + PendingMessages.DUE_TIME + " <= ?"; String[] selectionArgs = new String[] { String.valueOf(MmsSms.ERR_TYPE_GENERIC_PERMANENT), String.valueOf(dueTime) }; return mContentResolver.query( uriBuilder.build(), null, selection, selectionArgs, PendingMessages.DUE_TIME); }
public static void setRetryAlarm(Context context) { Cursor cursor = PduPersister.getPduPersister(context).getPendingMessages( Long.MAX_VALUE); if (cursor != null) { try { if (cursor.moveToFirst()) { // The result of getPendingMessages() is order by due time. long retryAt = cursor.getLong(cursor.getColumnIndexOrThrow( PendingMessages.DUE_TIME)); Intent service = new Intent(TransactionService.ACTION_ONALARM, null, context, TransactionService.class); PendingIntent operation = PendingIntent.getService( context, 0, service, PendingIntent.FLAG_ONE_SHOT); AlarmManager am = (AlarmManager) context.getSystemService( Context.ALARM_SERVICE); am.set(AlarmManager.RTC, retryAt, operation); if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE)) { Log.v(TAG, "Next retry is scheduled at" + (retryAt - System.currentTimeMillis()) + "ms from now"); } } } finally { cursor.close(); } } }
public boolean sendMessage(long token) throws MmsException { // Load the MMS from the message uri if (Log.isLoggable(LogTag.APP, Log.VERBOSE)) { LogTag.debug("sendMessage uri: " + mMessageUri); } PduPersister p = PduPersister.getPduPersister(mContext); GenericPdu pdu = p.load(mMessageUri); if (pdu.getMessageType() != PduHeaders.MESSAGE_TYPE_SEND_REQ) { throw new MmsException("Invalid message: " + pdu.getMessageType()); } SendReq sendReq = (SendReq) pdu; // Update headers. updatePreferencesHeaders(sendReq); // MessageClass. sendReq.setMessageClass(DEFAULT_MESSAGE_CLASS.getBytes()); // Update the 'date' field of the message before sending it. sendReq.setDate(System.currentTimeMillis() / 1000L); sendReq.setMessageSize(mMessageSize); p.updateHeaders(mMessageUri, sendReq); long messageId = ContentUris.parseId(mMessageUri); // Move the message into MMS Outbox. if (!mMessageUri.toString().startsWith(Mms.Draft.CONTENT_URI.toString())) { // If the message is already in the outbox (most likely because we created a "primed" // message in the outbox when the user hit send), then we have to manually put an // entry in the pending_msgs table which is where TransacationService looks for // messages to send. Normally, the entry in pending_msgs is created by the trigger: // insert_mms_pending_on_update, when a message is moved from drafts to the outbox. ContentValues values = new ContentValues(7); values.put(PendingMessages.PROTO_TYPE, MmsSms.MMS_PROTO); values.put(PendingMessages.MSG_ID, messageId); values.put(PendingMessages.MSG_TYPE, pdu.getMessageType()); values.put(PendingMessages.ERROR_TYPE, 0); values.put(PendingMessages.ERROR_CODE, 0); values.put(PendingMessages.RETRY_INDEX, 0); values.put(PendingMessages.DUE_TIME, 0); SqliteWrapper.insert(mContext, mContext.getContentResolver(), PendingMessages.CONTENT_URI, values); } else { p.move(mMessageUri, Mms.Outbox.CONTENT_URI); } // Start MMS transaction service SendingProgressTokenManager.put(messageId, token); if (MultiSimConfig.isMultiSimEnabled()) { Intent intent = new Intent(mContext, TransactionService.class); intent.putExtra(Mms.SUB_ID, ComposeMessageActivity.subSelected); Intent silentIntent = new Intent(mContext, edu.bupt.mms.ui.SelectMmsSubscription.class); silentIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); silentIntent.putExtras(intent); //copy all extras mContext.startService(silentIntent); } else { mContext.startService(new Intent(mContext, TransactionService.class)); } return true; }
public boolean sendMessage(long token) throws MmsException { // Load the MMS from the message uri if (Log.isLoggable(LogTag.APP, Log.VERBOSE)) { LogTag.debug("sendMessage uri: " + mMessageUri); } PduPersister p = PduPersister.getPduPersister(mContext); GenericPdu pdu = p.load(mMessageUri); if (pdu.getMessageType() != PduHeaders.MESSAGE_TYPE_SEND_REQ) { throw new MmsException("Invalid message: " + pdu.getMessageType()); } SendReq sendReq = (SendReq) pdu; // Update headers. updatePreferencesHeaders(sendReq); // MessageClass. sendReq.setMessageClass(DEFAULT_MESSAGE_CLASS.getBytes()); // Update the 'date' field of the message before sending it. sendReq.setDate(System.currentTimeMillis() / 1000L); sendReq.setMessageSize(mMessageSize); p.updateHeaders(mMessageUri, sendReq); long messageId = ContentUris.parseId(mMessageUri); // Move the message into MMS Outbox. if (!mMessageUri.toString().startsWith(Mms.Draft.CONTENT_URI.toString())) { // If the message is already in the outbox (most likely because we created a "primed" // message in the outbox when the user hit send), then we have to manually put an // entry in the pending_msgs table which is where TransacationService looks for // messages to send. Normally, the entry in pending_msgs is created by the trigger: // insert_mms_pending_on_update, when a message is moved from drafts to the outbox. ContentValues values = new ContentValues(7); values.put(PendingMessages.PROTO_TYPE, MmsSms.MMS_PROTO); values.put(PendingMessages.MSG_ID, messageId); values.put(PendingMessages.MSG_TYPE, pdu.getMessageType()); values.put(PendingMessages.ERROR_TYPE, 0); values.put(PendingMessages.ERROR_CODE, 0); values.put(PendingMessages.RETRY_INDEX, 0); values.put(PendingMessages.DUE_TIME, 0); SqliteWrapper.insert(mContext, mContext.getContentResolver(), PendingMessages.CONTENT_URI, values); } else { p.move(mMessageUri, Mms.Outbox.CONTENT_URI); } // Start MMS transaction service SendingProgressTokenManager.put(messageId, token); mContext.startService(new Intent(mContext, TransactionService.class)); return true; }