分析原因:新建彩信草稿,保存后,再打开草稿,修改收件人,再保存会产生新的threadId, 而之前保存的草稿theadId还存在,导致此问题。

(必现。 解决方法:将原来的Thread_id和新的收件人传递到Provider,对收件人进行更新,避免生成新的Thread)

MMS草稿保存

private void asyncUpdateDraftMmsMessage(final Conversation conv, final boolean isStopping) {
if (Log.isLoggable(LogTag.APP, Log.VERBOSE)) {
LogTag.debug("asyncUpdateDraftMmsMessage conv=%s mMessageUri=%s", conv, mMessageUri);
}
final HashMap<Uri, InputStream> preOpenedFiles =
mSlideshow.openPartFiles(mContentResolver); new Thread(new Runnable() {
@Override
public void run() {
try {
DraftCache.getInstance().setSavingDraft(true); final PduPersister persister = PduPersister.getPduPersister(mActivity);
final SendReq sendReq = makeSendReq(conv, mSubject);
persister.setMmsDraftThreadId(mOldMmsDraftThreadId);//add by antoon, send old thread_id to pdu if (mMessageUri == null) {
mMessageUri = createDraftMmsMessage(persister, sendReq, mSlideshow, null,
mActivity, preOpenedFiles);//对于MMS保存,thread_id会在pdu保存时创建
} else {
updateDraftMmsMessage(mMessageUri, persister, mSlideshow, sendReq,
preOpenedFiles);//修改之前保存的MMS后,pdu更新数据,这里会根据收件人getOrCreateThreadId,所以修改收件人会导致创建新的thread
}
ensureThreadIdIfNeeded(conv, isStopping);//这里确认thread_id创建或获取成功,否则再次执行getOrCreateThreadId
conv.setDraftState(true);
if (Log.isLoggable(LogTag.APP, Log.VERBOSE)) {
LogTag.debug("asyncUpdateDraftMmsMessage conv: " + conv +
" uri: " + mMessageUri);
} // Be paranoid and delete any SMS drafts that might be lying around. Must do
// this after ensureThreadId so conv has the correct thread id.
asyncDeleteDraftSmsMessage(conv);
} finally {
DraftCache.getInstance().setSavingDraft(false);
closePreOpenedFiles(preOpenedFiles);
}
}
}, "WorkingMessage.asyncUpdateDraftMmsMessage").start();
}

看看  ensureThreadIdIfNeeded(conv, isStopping)

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();
}
}
public synchronized void clearThreadId() {
// remove ourself from the cache
if (Log.isLoggable(LogTag.APP, Log.VERBOSE)) {
LogTag.debug("clearThreadId old threadId was: " + mThreadId + " now zero");
}
Cache.remove(mThreadId); mThreadId = 0;
} public synchronized long ensureThreadId() {
if (DEBUG || DELETEDEBUG) {
LogTag.debug("ensureThreadId before: " + mThreadId);
}
if (mThreadId <= 0) {
if (mIsGroupChat && mGroupChat != null) {
HashSet<String> numbers = new HashSet<String>();
numbers.add(String.valueOf(mGroupChat.getThreadId()));
ContactList groupRecip = ContactList.getByNumbers(numbers, false);
mThreadId = getOrCreateThreadId(mContext, groupRecip, mIsGroupChat);
} else {
mThreadId = getOrCreateThreadId(mContext, mRecipients, mIsGroupChat);
}
}
if (DEBUG || DELETEDEBUG) {
LogTag.debug("ensureThreadId after: " + mThreadId);
} return mThreadId;
}

对于MMS, SMS草稿保存时都会调用 ensureThreadIdIfNeeded  , 如果修改了收件人,应该都会有thread_id重建,获取操作。

但是对于SMS却没有反馈此问题,是怎么回事呢?

——原因:sms草稿会在重新打开时,将数据库删掉。重新保存草稿时,重新插入数据。 而MMS草稿在重新打开时,不会将数据库删除,修改收件人后,重新创建thread,导致此Bug。

但sms草稿的处理方式,重新打开sms草稿,即使不修改,再次保存时,也会重新创建数据库数据。

05-02 21:52