From d0b81a0d062f9bad15c9d9ba104b6cdf8590e5fe Mon Sep 17 00:00:00 2001 From: Yu Ping Hu Date: Mon, 21 Oct 2013 14:59:53 -0700 Subject: [PATCH] Treat updates into non-existent body rows as inserts. Bug: 11245727 Change-Id: I648b0267e9149f3f431ce01be9789087f73edab1 --- .../com/android/emailcommon/provider/EmailContent.java | 2 ++ src/com/android/email/provider/EmailProvider.java | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/emailcommon/src/com/android/emailcommon/provider/EmailContent.java b/emailcommon/src/com/android/emailcommon/provider/EmailContent.java index cd6db2655..89e730354 100755 --- a/emailcommon/src/com/android/emailcommon/provider/EmailContent.java +++ b/emailcommon/src/com/android/emailcommon/provider/EmailContent.java @@ -314,6 +314,8 @@ public abstract class EmailContent { public static final class Body extends EmailContent implements BodyColumns { public static final String TABLE_NAME = "Body"; + public static final String SELECTION_BY_MESSAGE_KEY = MESSAGE_KEY + "=?"; + public static Uri CONTENT_URI; public static void initBody() { diff --git a/src/com/android/email/provider/EmailProvider.java b/src/com/android/email/provider/EmailProvider.java index 3bb92b0e4..417a704ad 100644 --- a/src/com/android/email/provider/EmailProvider.java +++ b/src/com/android/email/provider/EmailProvider.java @@ -1857,6 +1857,16 @@ public class EmailProvider extends ContentProvider { } break; case BODY: + result = db.update(tableName, values, selection, selectionArgs); + if (result == 0 && selection.equals(Body.SELECTION_BY_MESSAGE_KEY)) { + // TODO: This is a hack. Notably, the selection equality test above + // is hokey at best. + LogUtils.i(TAG, "Body Update to non-existent row, morphing to insert"); + final ContentValues insertValues = new ContentValues(values); + insertValues.put(EmailContent.Body.MESSAGE_KEY, selectionArgs[0]); + insert(EmailContent.Body.CONTENT_URI, insertValues); + } + break; case MESSAGE: case UPDATED_MESSAGE: case ATTACHMENT: