Async code for read/unread and starred
* Move each worker into async (combining common code) * Update unit tests to match * Make the message->account->controller lookups more efficient Bug: 3134653 Change-Id: Icc82998a5d8eb07c7ebc7edbd28cd9308378d866
This commit is contained in:
parent
8d22e85e45
commit
3b1cccf234
|
@ -741,7 +741,7 @@ public class Controller {
|
||||||
*
|
*
|
||||||
* @param messageIds The IDs of the messages to move
|
* @param messageIds The IDs of the messages to move
|
||||||
* @param newMailboxId The id of the folder we're supposed to move the folder to
|
* @param newMailboxId The id of the folder we're supposed to move the folder to
|
||||||
* @return the AsyncTask that will execute the move
|
* @return the AsyncTask that will execute the move (for testing only)
|
||||||
*/
|
*/
|
||||||
public AsyncTask<Void, Void, Void> moveMessage(final long[] messageIds,
|
public AsyncTask<Void, Void, Void> moveMessage(final long[] messageIds,
|
||||||
final long newMailboxId) {
|
final long newMailboxId) {
|
||||||
|
@ -771,67 +771,54 @@ public class Controller {
|
||||||
/**
|
/**
|
||||||
* Set/clear the unread status of a message
|
* Set/clear the unread status of a message
|
||||||
*
|
*
|
||||||
* TODO db ops should not be in this thread. queue it up.
|
|
||||||
*
|
|
||||||
* @param messageId the message to update
|
* @param messageId the message to update
|
||||||
* @param isRead the new value for the isRead flag
|
* @param isRead the new value for the isRead flag
|
||||||
|
* @return the AsyncTask that will execute the changes (for testing only)
|
||||||
*/
|
*/
|
||||||
public void setMessageRead(final long messageId, boolean isRead) {
|
public AsyncTask<Void, Void, Void> setMessageRead(final long messageId, final boolean isRead) {
|
||||||
ContentValues cv = new ContentValues();
|
return setMessageBoolean(messageId, EmailContent.MessageColumns.FLAG_READ, isRead);
|
||||||
cv.put(EmailContent.MessageColumns.FLAG_READ, isRead);
|
|
||||||
Uri uri = ContentUris.withAppendedId(
|
|
||||||
EmailContent.Message.SYNCED_CONTENT_URI, messageId);
|
|
||||||
mProviderContext.getContentResolver().update(uri, cv, null, null);
|
|
||||||
|
|
||||||
// Service runs automatically, MessagingController needs a kick
|
|
||||||
final Message message = Message.restoreMessageWithId(mProviderContext, messageId);
|
|
||||||
if (message == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Account account = Account.restoreAccountWithId(mProviderContext, message.mAccountKey);
|
|
||||||
if (account == null) {
|
|
||||||
return; // isMessagingController returns false for null, but let's make it clear.
|
|
||||||
}
|
|
||||||
if (isMessagingController(account)) {
|
|
||||||
Utility.runAsync(new Runnable() {
|
|
||||||
public void run() {
|
|
||||||
mLegacyController.processPendingActions(message.mAccountKey);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set/clear the favorite status of a message
|
* Set/clear the favorite status of a message
|
||||||
*
|
*
|
||||||
* TODO db ops should not be in this thread. queue it up.
|
|
||||||
*
|
|
||||||
* @param messageId the message to update
|
* @param messageId the message to update
|
||||||
* @param isFavorite the new value for the isFavorite flag
|
* @param isFavorite the new value for the isFavorite flag
|
||||||
|
* @return the AsyncTask that will execute the changes (for testing only)
|
||||||
*/
|
*/
|
||||||
public void setMessageFavorite(final long messageId, boolean isFavorite) {
|
public AsyncTask<Void, Void, Void> setMessageFavorite(final long messageId,
|
||||||
ContentValues cv = new ContentValues();
|
final boolean isFavorite) {
|
||||||
cv.put(EmailContent.MessageColumns.FLAG_FAVORITE, isFavorite);
|
return setMessageBoolean(messageId, EmailContent.MessageColumns.FLAG_FAVORITE, isFavorite);
|
||||||
Uri uri = ContentUris.withAppendedId(
|
}
|
||||||
EmailContent.Message.SYNCED_CONTENT_URI, messageId);
|
|
||||||
mProviderContext.getContentResolver().update(uri, cv, null, null);
|
|
||||||
|
|
||||||
// Service runs automatically, MessagingController needs a kick
|
/**
|
||||||
final Message message = Message.restoreMessageWithId(mProviderContext, messageId);
|
* Set/clear boolean columns of a message
|
||||||
if (message == null) {
|
*
|
||||||
return;
|
* @param messageId the message to update
|
||||||
}
|
* @param columnName the column to update
|
||||||
Account account = Account.restoreAccountWithId(mProviderContext, message.mAccountKey);
|
* @param columnValue the new value for the column
|
||||||
if (account == null) {
|
* @return the AsyncTask that will execute the changes (for testing only)
|
||||||
return; // isMessagingController returns false for null, but let's make it clear.
|
*/
|
||||||
}
|
private AsyncTask<Void, Void, Void> setMessageBoolean(final long messageId,
|
||||||
if (isMessagingController(account)) {
|
final String columnName, final boolean columnValue) {
|
||||||
Utility.runAsync(new Runnable() {
|
return Utility.runAsync(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
mLegacyController.processPendingActions(message.mAccountKey);
|
ContentValues cv = new ContentValues();
|
||||||
|
cv.put(columnName, columnValue);
|
||||||
|
Uri uri = ContentUris.withAppendedId(
|
||||||
|
EmailContent.Message.SYNCED_CONTENT_URI, messageId);
|
||||||
|
mProviderContext.getContentResolver().update(uri, cv, null, null);
|
||||||
|
|
||||||
|
// Service runs automatically, MessagingController needs a kick
|
||||||
|
long accountId = Account.getAccountIdForMessageId(mProviderContext, messageId);
|
||||||
|
if (accountId == -1) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
});
|
if (isMessagingController(accountId)) {
|
||||||
}
|
mLegacyController.processPendingActions(accountId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1579,8 +1566,8 @@ public class Controller {
|
||||||
|
|
||||||
public static class ControllerService extends Service {
|
public static class ControllerService extends Service {
|
||||||
/**
|
/**
|
||||||
* Create our EmailService implementation here. For now, only loadAttachment is supported; the
|
* Create our EmailService implementation here. For now, only loadAttachment is supported;
|
||||||
* intention, however, is to move more functionality to the service interface
|
* the intention, however, is to move more functionality to the service interface
|
||||||
*/
|
*/
|
||||||
private final IEmailService.Stub mBinder = new IEmailService.Stub() {
|
private final IEmailService.Stub mBinder = new IEmailService.Stub() {
|
||||||
|
|
||||||
|
@ -1621,7 +1608,7 @@ public class Controller {
|
||||||
msg = Message.restoreMessageWithId(ControllerService.this,
|
msg = Message.restoreMessageWithId(ControllerService.this,
|
||||||
Long.parseLong(cols[BODY_SOURCE_KEY_COLUMN]));
|
Long.parseLong(cols[BODY_SOURCE_KEY_COLUMN]));
|
||||||
if (msg == null) {
|
if (msg == null) {
|
||||||
// TODO: We can try restoring from the deleted table at this point...
|
// TODO: We can try restoring from the deleted table here...
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -161,9 +161,6 @@ public class ControllerProviderOpsTests extends ProviderTestCase2<EmailProvider>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test the "move message" function.
|
* Test the "move message" function.
|
||||||
*
|
|
||||||
* @throws ExecutionException
|
|
||||||
* @throws InterruptedException
|
|
||||||
*/
|
*/
|
||||||
public void testMoveMessage() throws InterruptedException, ExecutionException {
|
public void testMoveMessage() throws InterruptedException, ExecutionException {
|
||||||
Account account1 = ProviderTestUtils.setupAccount("message-move", true, mProviderContext);
|
Account account1 = ProviderTestUtils.setupAccount("message-move", true, mProviderContext);
|
||||||
|
@ -196,8 +193,6 @@ public class ControllerProviderOpsTests extends ProviderTestCase2<EmailProvider>
|
||||||
* Test the "delete message" function. Sunny day:
|
* Test the "delete message" function. Sunny day:
|
||||||
* - message/mailbox/account all exist
|
* - message/mailbox/account all exist
|
||||||
* - trash mailbox exists
|
* - trash mailbox exists
|
||||||
* @throws ExecutionException
|
|
||||||
* @throws InterruptedException
|
|
||||||
*/
|
*/
|
||||||
public void testDeleteMessage() throws InterruptedException, ExecutionException {
|
public void testDeleteMessage() throws InterruptedException, ExecutionException {
|
||||||
Account account1 = ProviderTestUtils.setupAccount("message-delete", true, mProviderContext);
|
Account account1 = ProviderTestUtils.setupAccount("message-delete", true, mProviderContext);
|
||||||
|
@ -272,8 +267,6 @@ public class ControllerProviderOpsTests extends ProviderTestCase2<EmailProvider>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test deleting message when there is no trash mailbox
|
* Test deleting message when there is no trash mailbox
|
||||||
* @throws ExecutionException
|
|
||||||
* @throws InterruptedException
|
|
||||||
*/
|
*/
|
||||||
public void testDeleteMessageNoTrash() throws InterruptedException, ExecutionException {
|
public void testDeleteMessageNoTrash() throws InterruptedException, ExecutionException {
|
||||||
Account account1 =
|
Account account1 =
|
||||||
|
@ -304,7 +297,7 @@ public class ControllerProviderOpsTests extends ProviderTestCase2<EmailProvider>
|
||||||
/**
|
/**
|
||||||
* Test read/unread flag
|
* Test read/unread flag
|
||||||
*/
|
*/
|
||||||
public void testReadUnread() {
|
public void testReadUnread() throws InterruptedException, ExecutionException {
|
||||||
Account account1 = ProviderTestUtils.setupAccount("read-unread", false, mProviderContext);
|
Account account1 = ProviderTestUtils.setupAccount("read-unread", false, mProviderContext);
|
||||||
account1.mHostAuthRecv
|
account1.mHostAuthRecv
|
||||||
= ProviderTestUtils.setupHostAuth("read-unread", 0, false, mProviderContext);
|
= ProviderTestUtils.setupHostAuth("read-unread", 0, false, mProviderContext);
|
||||||
|
@ -318,20 +311,25 @@ public class ControllerProviderOpsTests extends ProviderTestCase2<EmailProvider>
|
||||||
long message1Id = message1.mId;
|
long message1Id = message1.mId;
|
||||||
|
|
||||||
// test setting to "read"
|
// test setting to "read"
|
||||||
mTestController.setMessageRead(message1Id, true);
|
mTestController.setMessageRead(message1Id, true).get();
|
||||||
Message message1get = Message.restoreMessageWithId(mProviderContext, message1Id);
|
Message message1get = Message.restoreMessageWithId(mProviderContext, message1Id);
|
||||||
assertTrue(message1get.mFlagRead);
|
assertTrue(message1get.mFlagRead);
|
||||||
|
|
||||||
// test setting to "unread"
|
// test setting to "unread"
|
||||||
mTestController.setMessageRead(message1Id, false);
|
mTestController.setMessageRead(message1Id, false).get();
|
||||||
message1get = Message.restoreMessageWithId(mProviderContext, message1Id);
|
message1get = Message.restoreMessageWithId(mProviderContext, message1Id);
|
||||||
assertFalse(message1get.mFlagRead);
|
assertFalse(message1get.mFlagRead);
|
||||||
|
|
||||||
|
// test setting to "read"
|
||||||
|
mTestController.setMessageRead(message1Id, true).get();
|
||||||
|
message1get = Message.restoreMessageWithId(mProviderContext, message1Id);
|
||||||
|
assertTrue(message1get.mFlagRead);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test favorites flag
|
* Test favorites flag
|
||||||
*/
|
*/
|
||||||
public void testFavorites() {
|
public void testFavorites() throws InterruptedException, ExecutionException {
|
||||||
Account account1 = ProviderTestUtils.setupAccount("favorites", false, mProviderContext);
|
Account account1 = ProviderTestUtils.setupAccount("favorites", false, mProviderContext);
|
||||||
account1.mHostAuthRecv
|
account1.mHostAuthRecv
|
||||||
= ProviderTestUtils.setupHostAuth("favorites", 0, false, mProviderContext);
|
= ProviderTestUtils.setupHostAuth("favorites", 0, false, mProviderContext);
|
||||||
|
@ -345,14 +343,19 @@ public class ControllerProviderOpsTests extends ProviderTestCase2<EmailProvider>
|
||||||
long message1Id = message1.mId;
|
long message1Id = message1.mId;
|
||||||
|
|
||||||
// test setting to "favorite"
|
// test setting to "favorite"
|
||||||
mTestController.setMessageFavorite(message1Id, true);
|
mTestController.setMessageFavorite(message1Id, true).get();
|
||||||
Message message1get = Message.restoreMessageWithId(mProviderContext, message1Id);
|
Message message1get = Message.restoreMessageWithId(mProviderContext, message1Id);
|
||||||
assertTrue(message1get.mFlagFavorite);
|
assertTrue(message1get.mFlagFavorite);
|
||||||
|
|
||||||
// test setting to "not favorite"
|
// test setting to "not favorite"
|
||||||
mTestController.setMessageFavorite(message1Id, false);
|
mTestController.setMessageFavorite(message1Id, false).get();
|
||||||
message1get = Message.restoreMessageWithId(mProviderContext, message1Id);
|
message1get = Message.restoreMessageWithId(mProviderContext, message1Id);
|
||||||
assertFalse(message1get.mFlagFavorite);
|
assertFalse(message1get.mFlagFavorite);
|
||||||
|
|
||||||
|
// test setting to "favorite"
|
||||||
|
mTestController.setMessageFavorite(message1Id, true).get();
|
||||||
|
message1get = Message.restoreMessageWithId(mProviderContext, message1Id);
|
||||||
|
assertTrue(message1get.mFlagFavorite);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetAndDeleteAttachmentMailbox() {
|
public void testGetAndDeleteAttachmentMailbox() {
|
||||||
|
|
Loading…
Reference in New Issue