Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Respect threadId when sending MMS
  • Loading branch information
moezbhatti committed Dec 26, 2019
1 parent af2f694 commit 0dadcfb
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 16 deletions.
Expand Up @@ -169,7 +169,7 @@ public static Uri persist(Context context, byte[] response, MmsConfig.Overridden
// }
// Store the downloaded message
final PduPersister persister = PduPersister.getPduPersister(context);
final Uri messageUri = persister.persist(pdu, Telephony.Mms.Inbox.CONTENT_URI, true, true, null);
final Uri messageUri = persister.persist(pdu, Telephony.Mms.Inbox.CONTENT_URI, PduPersister.DUMMY_THREAD_ID, true, true, null);
if (messageUri == null) {
Timber.e("DownloadRequest.persistIfRequired: can not persist message");
return null;
Expand Down
Expand Up @@ -110,9 +110,8 @@ public NotificationTransaction(
try {
// Save the pdu. If we can start downloading the real pdu immediately, don't allow
// persist() to create a thread for the notificationInd because it causes UI jank.
mUri = PduPersister.getPduPersister(context).persist(
ind, Inbox.CONTENT_URI, !allowAutoDownload(mContext),
true, null);
mUri = PduPersister.getPduPersister(context).persist(ind, Inbox.CONTENT_URI,
PduPersister.DUMMY_THREAD_ID, !allowAutoDownload(mContext), true, null);
} catch (MmsException e) {
Timber.e(e, "Failed to save NotificationInd in constructor.");
throw new IllegalArgumentException();
Expand Down Expand Up @@ -185,8 +184,8 @@ public void run() {
} else {
// Save the received PDU (must be a M-RETRIEVE.CONF).
PduPersister p = PduPersister.getPduPersister(mContext);
Uri uri = p.persist(pdu, Inbox.CONTENT_URI, true,
true, null);
Uri uri = p.persist(pdu, Inbox.CONTENT_URI, PduPersister.DUMMY_THREAD_ID,
true, true, null);

RetrieveConf retrieveConf = (RetrieveConf) pdu;

Expand Down
Expand Up @@ -107,8 +107,8 @@ protected Void doInBackground(Intent... intents) {
break;
}

Uri uri = p.persist(pdu, Uri.parse("content://mms/inbox"), true,
true, null);
Uri uri = p.persist(pdu, Uri.parse("content://mms/inbox"),
PduPersister.DUMMY_THREAD_ID, true, true, null);
// Update thread ID for ReadOrigInd & DeliveryInd.
ContentValues values = new ContentValues(1);
values.put(Mms.THREAD_ID, threadId);
Expand Down Expand Up @@ -136,7 +136,8 @@ protected Void doInBackground(Intent... intents) {
// Save the pdu. If we can start downloading the real pdu immediately,
// don't allow persist() to create a thread for the notificationInd
// because it causes UI jank.
Uri uri = p.persist(pdu, Inbox.CONTENT_URI, true, true, null);
Uri uri = p.persist(pdu, Inbox.CONTENT_URI,
PduPersister.DUMMY_THREAD_ID, true, true, null);

String location = getContentLocation(mContext, uri);
if (downloadedUrls.contains(location)) {
Expand Down
Expand Up @@ -153,8 +153,8 @@ public void run() {
} else {
// Store M-Retrieve.conf into Inbox
PduPersister persister = PduPersister.getPduPersister(mContext);
msgUri = persister.persist(retrieveConf, Inbox.CONTENT_URI, true,
true, null);
msgUri = persister.persist(retrieveConf, Inbox.CONTENT_URI,
PduPersister.DUMMY_THREAD_ID, true, true, null);

// Use local time instead of PDU time
ContentValues values = new ContentValues(3);
Expand Down
Expand Up @@ -67,7 +67,7 @@
public class PduPersister {
private static final boolean LOCAL_LOGV = false;

private static final long DUMMY_THREAD_ID = Long.MAX_VALUE;
public static final long DUMMY_THREAD_ID = Long.MAX_VALUE;
private static final int DEFAULT_SUBSCRIPTION = 0;
private static final int MAX_TEXT_BODY_SIZE = 300 * 1024;

Expand Down Expand Up @@ -1263,6 +1263,7 @@ public void updateParts(Uri uri, PduBody body, HashMap<Uri, InputStream> preOpen
*
* @param pdu The PDU object to be stored.
* @param uri Where to store the given PDU object.
* @param threadId
* @param createThreadId if true, this function may create a thread id for the recipients
* @param groupMmsEnabled if true, all of the recipients addressed in the PDU will be used
* to create the associated thread. When false, only the sender will be used in finding or
Expand All @@ -1271,7 +1272,7 @@ public void updateParts(Uri uri, PduBody body, HashMap<Uri, InputStream> preOpen
* @return A Uri which can be used to access the stored PDU.
*/

public Uri persist(GenericPdu pdu, Uri uri, boolean createThreadId, boolean groupMmsEnabled,
public Uri persist(GenericPdu pdu, Uri uri, long threadId, boolean createThreadId, boolean groupMmsEnabled,
HashMap<Uri, InputStream> preOpenedFiles) throws MmsException {

if (uri == null) {
Expand Down Expand Up @@ -1400,8 +1401,7 @@ public Uri persist(GenericPdu pdu, Uri uri, boolean createThreadId, boolean grou
loadRecipients(PduHeaders.TO, recipients, addressMap, false);
break;
}
long threadId = DUMMY_THREAD_ID;
if (createThreadId && !recipients.isEmpty()) {
if (threadId == DUMMY_THREAD_ID && createThreadId && !recipients.isEmpty()) {
// Given all the recipients associated with this message, find (or create) the
// correct thread.
threadId = Threads.getOrCreateThreadId(mContext, recipients);
Expand Down
Expand Up @@ -94,7 +94,7 @@ class Transaction @JvmOverloads constructor(private val context: Context, settin

val sendReq = buildPdu(context, addresses, subject, parts)
val persister = PduPersister.getPduPersister(context)
val messageUri = existingUri ?: persister.persist(sendReq, Uri.parse("content://mms/outbox"), true, true, null)
val messageUri = existingUri ?: persister.persist(sendReq, Uri.parse("content://mms/outbox"), threadId, true, true, null)

val sentIntent = Intent(MMS_SENT)
BroadcastUtils.addClassName(context, sentIntent, MMS_SENT)
Expand Down

0 comments on commit 0dadcfb

Please sign in to comment.