diff --git a/src/com/android/email/provider/EmailContent.java b/src/com/android/email/provider/EmailContent.java index 0f91052d7..776fd15f6 100644 --- a/src/com/android/email/provider/EmailContent.java +++ b/src/com/android/email/provider/EmailContent.java @@ -1455,17 +1455,18 @@ public abstract class EmailContent { */ public static boolean isValidId(Context context, long accountId) { return null != Utility.getFirstRowLong(context, CONTENT_URI, ID_PROJECTION, - ID_SELECTION, new String[] {Long.toString(accountId)}, null, 0); + ID_SELECTION, new String[] {Long.toString(accountId)}, null, + ID_PROJECTION_COLUMN); } /** * Check a single account for security hold status. */ public static boolean isSecurityHold(Context context, long accountId) { - Long flags = Utility.getFirstRowLong(context, + return (Utility.getFirstRowLong(context, ContentUris.withAppendedId(Account.CONTENT_URI, accountId), - ACCOUNT_FLAGS_PROJECTION, null, null, null, ACCOUNT_FLAGS_COLUMN_FLAGS); - return (flags != null) && ((flags & Account.FLAGS_SECURITY_HOLD) != 0); + ACCOUNT_FLAGS_PROJECTION, null, null, null, ACCOUNT_FLAGS_COLUMN_FLAGS, 0L) + & Account.FLAGS_SECURITY_HOLD) != 0; } /** @@ -1474,7 +1475,7 @@ public abstract class EmailContent { public static long getInboxId(Context context, long accountId) { return Utility.getFirstRowLong(context, Mailbox.CONTENT_URI, ID_PROJECTION, FIND_INBOX_SELECTION, new String[] {Long.toString(accountId)}, null, - ID_PROJECTION_COLUMN); + ID_PROJECTION_COLUMN, -1L); } /** @@ -2294,19 +2295,17 @@ public abstract class EmailContent { } public static int getUnreadCountByMailboxType(Context context, int type) { - return Utility.getFirstRowLong(context, Mailbox.CONTENT_URI, + return Utility.getFirstRowInt(context, Mailbox.CONTENT_URI, MAILBOX_SUM_OF_UNREAD_COUNT_PROJECTION, MAILBOX_TYPE_SELECTION, - new String[] { String.valueOf(type) }, null, UNREAD_COUNT_COUNT_COLUMN) - .intValue(); + new String[] { String.valueOf(type) }, null, UNREAD_COUNT_COUNT_COLUMN, 0); } public static int getMessageCountByMailboxType(Context context, int type) { - return Utility.getFirstRowLong(context, Mailbox.CONTENT_URI, + return Utility.getFirstRowInt(context, Mailbox.CONTENT_URI, MAILBOX_SUM_OF_MESSAGE_COUNT_PROJECTION, MAILBOX_TYPE_SELECTION, - new String[] { String.valueOf(type) }, null, MESSAGE_COUNT_COUNT_COLUMN) - .intValue(); + new String[] { String.valueOf(type) }, null, MESSAGE_COUNT_COUNT_COLUMN, 0); } /** diff --git a/tests/src/com/android/email/provider/ProviderTests.java b/tests/src/com/android/email/provider/ProviderTests.java index 9d93e8421..8ceaab56a 100644 --- a/tests/src/com/android/email/provider/ProviderTests.java +++ b/tests/src/com/android/email/provider/ProviderTests.java @@ -1974,6 +1974,10 @@ public class ProviderTests extends ProviderTestCase2 { assertEquals(1, getMessageCount(b2.mId)); assertEquals(2, getMessageCount(b3.mId)); assertEquals(1, getMessageCount(b4.mId)); + + // No such mailbox type. + assertEquals(0, Mailbox.getMessageCountByMailboxType(c, 99999)); + assertEquals(0, Mailbox.getUnreadCountByMailboxType(c, 99999)); } private static Message createMessage(Context c, Mailbox b, boolean starred, boolean read) { @@ -2040,6 +2044,9 @@ public class ProviderTests extends ProviderTestCase2 { Mailbox b2i = ProviderTestUtils.setupMailbox("b2b", a2.mId, true, c, Mailbox.TYPE_INBOX); assertEquals(b2i.mId, Account.getInboxId(c, a2.mId)); + + // No account found. + assertEquals(-1, Account.getInboxId(c, 999999)); } public void testGetMailboxType() {