summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJean-Baptiste Queru <jbq@google.com>2012-09-05 12:16:01 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2012-09-05 12:16:01 -0700
commita0cbec1365920c5916da95327ddcd0cdac6f1b03 (patch)
treeca75ca8a76e0871d1027b3bf0cb6ff5abf1af09e /src
parent4c6c7c65a1033d5cc0d87cc8b0e07a69db1842e8 (diff)
parentb22ea8fbc79f3361907e96e4d7737bc304db4ddf (diff)
downloadMms-a0cbec1365920c5916da95327ddcd0cdac6f1b03.tar.gz
am b22ea8fb: am 822ff2e4: Merge "We sometimes need a new thread id to update drafts"
* commit 'b22ea8fbc79f3361907e96e4d7737bc304db4ddf': We sometimes need a new thread id to update drafts
Diffstat (limited to 'src')
-rwxr-xr-xsrc/com/android/mms/data/WorkingMessage.java43
1 files changed, 26 insertions, 17 deletions
diff --git a/src/com/android/mms/data/WorkingMessage.java b/src/com/android/mms/data/WorkingMessage.java
index cfd00148..348a96fb 100755
--- a/src/com/android/mms/data/WorkingMessage.java
+++ b/src/com/android/mms/data/WorkingMessage.java
@@ -884,7 +884,7 @@ public class WorkingMessage {
// and takes that thread id (because it's the next thread id to be assigned), the
// new message will be merged with the draft message thread, causing confusion!
if (!TextUtils.isEmpty(content)) {
- asyncUpdateDraftSmsMessage(mConversation, content);
+ asyncUpdateDraftSmsMessage(mConversation, content, isStopping);
mHasSmsDraft = true;
} else {
// When there's no associated text message, we have to handle the case where there
@@ -1571,20 +1571,7 @@ public class WorkingMessage {
} else {
updateDraftMmsMessage(mMessageUri, persister, mSlideshow, sendReq);
}
- if (isStopping && conv.getMessageCount() == 0) {
- // createDraftMmsMessage can create the new thread in the threads table (the
- // call to createDraftMmsDraftMessage calls PduPersister.persist() which
- // can call Threads.getOrCreateThreadId()). Meanwhile, when the user goes
- // back to ConversationList while we're saving a draft from CMA's.onStop,
- // ConversationList will delete all threads from the thread table that
- // don't have associated sms or pdu entries. In case our thread got deleted,
- // well call clearThreadId() so ensureThreadId will query the db for the new
- // thread.
- conv.clearThreadId(); // force us to get the updated thread id
- }
- if (!conv.getRecipients().isEmpty()) {
- conv.ensureThreadId();
- }
+ ensureThreadIdIfNeeded(conv, isStopping);
conv.setDraftState(true);
if (Log.isLoggable(LogTag.APP, Log.VERBOSE)) {
LogTag.debug("asyncUpdateDraftMmsMessage conv: " + conv +
@@ -1687,7 +1674,8 @@ public class WorkingMessage {
conv.setDraftState(false);
}
- private void asyncUpdateDraftSmsMessage(final Conversation conv, final String contents) {
+ private void asyncUpdateDraftSmsMessage(final Conversation conv, final String contents,
+ final boolean isStopping) {
new Thread(new Runnable() {
@Override
public void run() {
@@ -1699,7 +1687,7 @@ public class WorkingMessage {
}
return;
}
- long threadId = conv.ensureThreadId();
+ ensureThreadIdIfNeeded(conv, isStopping);
conv.setDraftState(true);
updateDraftSmsMessage(conv, contents);
} finally {
@@ -1766,4 +1754,25 @@ public class WorkingMessage {
final String where = Mms.THREAD_ID + (threadId > 0 ? " = " + threadId : " IS NULL");
asyncDelete(Mms.Draft.CONTENT_URI, where, null);
}
+
+ /**
+ * Ensure the thread id in conversation if needed, when we try to save a draft with a orphaned
+ * one.
+ * @param conv The conversation we are in.
+ * @param isStopping Whether we are saving the draft in CMA'a onStop
+ */
+ private void ensureThreadIdIfNeeded(final Conversation conv, final boolean isStopping) {
+ if (isStopping && conv.getMessageCount() == 0) {
+ // We need to save the drafts in an unorphaned thread id. When the user goes
+ // back to ConversationList while we're saving a draft from CMA's.onStop,
+ // ConversationList will delete all threads from the thread table that
+ // don't have associated sms or pdu entries. In case our thread got deleted,
+ // well call clearThreadId() so ensureThreadId will query the db for the new
+ // thread.
+ conv.clearThreadId(); // force us to get the updated thread id
+ }
+ if (!conv.getRecipients().isEmpty()) {
+ conv.ensureThreadId();
+ }
+ }
}