From 0c49f4e3218eaa9c5c22a8fb957a0aaa4c4bdc4f Mon Sep 17 00:00:00 2001 From: Andy Stadler <> Date: Sat, 18 Apr 2009 18:45:15 -0700 Subject: [PATCH] AI 146514: am: CL 146061 Add persistent storage that Store classes can access. The current design for Store classes (e.g. IMAP) did not provide for any persistent storage. This is the beginning of a mechanism to provide that. It's quite simplisitic - each Store can read/write one persistent string - but that's enough for the first simple use case (saving some sync data for EAS). The core changes here - suggest reviewing first - are in Account.java, Store.java, and AccountUnitTests.java. Everything else is just following the API change that was necessary. Note that, by definition, this only applies to remote stores (e.g. IMAP, POP3). You'll see everywhere that LocalStore is passed null, and this is correct - LocalStore *is* persistent storage and does not need access (so far, at least). Original author: stadler Automated import of CL 146514 --- .../android/email/MessagingController.java | 38 ++++++++----------- .../android/email/mail/store/ImapStore.java | 4 +- .../android/email/mail/store/Pop3Store.java | 8 ++-- .../email/mail/store/ImapStoreUnitTests.java | 2 +- .../email/mail/store/Pop3StoreUnitTests.java | 4 +- 5 files changed, 22 insertions(+), 34 deletions(-) diff --git a/src/com/android/email/MessagingController.java b/src/com/android/email/MessagingController.java index 26d513910..cacaad043 100644 --- a/src/com/android/email/MessagingController.java +++ b/src/com/android/email/MessagingController.java @@ -286,7 +286,7 @@ public class MessagingController implements Runnable { try { Store localStore = Store.getInstance(account.getLocalStoreUri(), mApplication, null); Folder localFolder = localStore.getFolder(folder); - localFolder.open(OpenMode.READ_WRITE, null); + localFolder.open(OpenMode.READ_WRITE); Message[] localMessages = localFolder.getMessages(null); ArrayList messages = new ArrayList(); for (Message message : localMessages) { @@ -388,7 +388,7 @@ public class MessagingController implements Runnable { final LocalStore localStore = (LocalStore) Store.getInstance(account.getLocalStoreUri(), mApplication, null); final LocalFolder localFolder = (LocalFolder) localStore.getFolder(folder); - localFolder.open(OpenMode.READ_WRITE, null); + localFolder.open(OpenMode.READ_WRITE); Message[] localMessages = localFolder.getMessages(null); HashMap localUidMap = new HashMap(); for (Message message : localMessages) { @@ -441,7 +441,7 @@ public class MessagingController implements Runnable { /* * Open the remote folder. This pre-loads certain metadata like message count. */ - remoteFolder.open(OpenMode.READ_WRITE, localFolder.getPersistentCallbacks()); + remoteFolder.open(OpenMode.READ_WRITE); /* * Trash any remote messages that are marked as trashed locally. @@ -837,7 +837,7 @@ public class MessagingController implements Runnable { return; } } - remoteFolder.open(OpenMode.READ_WRITE, localFolder.getPersistentCallbacks()); + remoteFolder.open(OpenMode.READ_WRITE); if (remoteFolder.getMode() != OpenMode.READ_WRITE) { return; } @@ -914,17 +914,13 @@ public class MessagingController implements Runnable { String folder = command.arguments[0]; String uid = command.arguments[1]; - LocalStore localStore = (LocalStore) Store.getInstance( - account.getLocalStoreUri(), mApplication, null); - LocalFolder localFolder = (LocalFolder) localStore.getFolder(folder); - Store remoteStore = Store.getInstance(account.getStoreUri(), mApplication, account.getStoreCallbacks()); Folder remoteFolder = remoteStore.getFolder(folder); if (!remoteFolder.exists()) { return; } - remoteFolder.open(OpenMode.READ_WRITE, localFolder.getPersistentCallbacks()); + remoteFolder.open(OpenMode.READ_WRITE); if (remoteFolder.getMode() != OpenMode.READ_WRITE) { return; } @@ -969,17 +965,13 @@ public class MessagingController implements Runnable { String uid = command.arguments[1]; boolean read = Boolean.parseBoolean(command.arguments[2]); - LocalStore localStore = (LocalStore) Store.getInstance( - account.getLocalStoreUri(), mApplication, null); - LocalFolder localFolder = (LocalFolder) localStore.getFolder(folder); - Store remoteStore = Store.getInstance(account.getStoreUri(), mApplication, account.getStoreCallbacks()); Folder remoteFolder = remoteStore.getFolder(folder); if (!remoteFolder.exists()) { return; } - remoteFolder.open(OpenMode.READ_WRITE, localFolder.getPersistentCallbacks()); + remoteFolder.open(OpenMode.READ_WRITE); if (remoteFolder.getMode() != OpenMode.READ_WRITE) { return; } @@ -1009,7 +1001,7 @@ public class MessagingController implements Runnable { try { Store localStore = Store.getInstance(account.getLocalStoreUri(), mApplication, null); Folder localFolder = localStore.getFolder(folder); - localFolder.open(OpenMode.READ_WRITE, null); + localFolder.open(OpenMode.READ_WRITE); Message message = localFolder.getMessage(uid); message.setFlag(Flag.SEEN, seen); @@ -1032,7 +1024,7 @@ public class MessagingController implements Runnable { Store localStore = Store.getInstance( account.getLocalStoreUri(), mApplication, null); LocalFolder localFolder = (LocalFolder) localStore.getFolder(folder); - localFolder.open(OpenMode.READ_WRITE, null); + localFolder.open(OpenMode.READ_WRITE); Message message = localFolder.getMessage(uid); @@ -1064,7 +1056,7 @@ public class MessagingController implements Runnable { Store remoteStore = Store.getInstance(account.getStoreUri(), mApplication, account.getStoreCallbacks()); Folder remoteFolder = remoteStore.getFolder(folder); - remoteFolder.open(OpenMode.READ_WRITE, localFolder.getPersistentCallbacks()); + remoteFolder.open(OpenMode.READ_WRITE); // Get the remote message and fully download it Message remoteMessage = remoteFolder.getMessage(uid); @@ -1111,7 +1103,7 @@ public class MessagingController implements Runnable { try { Store localStore = Store.getInstance(account.getLocalStoreUri(), mApplication, null); LocalFolder localFolder = (LocalFolder) localStore.getFolder(folder); - localFolder.open(OpenMode.READ_WRITE, null); + localFolder.open(OpenMode.READ_WRITE); Message message = localFolder.getMessage(uid); @@ -1215,7 +1207,7 @@ public class MessagingController implements Runnable { LocalFolder localFolder = (LocalFolder) localStore.getFolder(message.getFolder().getName()); Folder remoteFolder = remoteStore.getFolder(message.getFolder().getName()); - remoteFolder.open(OpenMode.READ_WRITE, localFolder.getPersistentCallbacks()); + remoteFolder.open(OpenMode.READ_WRITE); FetchProfile fp = new FetchProfile(); fp.add(part); @@ -1252,7 +1244,7 @@ public class MessagingController implements Runnable { Store localStore = Store.getInstance(account.getLocalStoreUri(), mApplication, null); LocalFolder localFolder = (LocalFolder) localStore.getFolder(account.getOutboxFolderName()); - localFolder.open(OpenMode.READ_WRITE, null); + localFolder.open(OpenMode.READ_WRITE); localFolder.appendMessages(new Message[] { message }); @@ -1295,7 +1287,7 @@ public class MessagingController implements Runnable { if (!localFolder.exists()) { return; } - localFolder.open(OpenMode.READ_WRITE, null); + localFolder.open(OpenMode.READ_WRITE); Message[] localMessages = localFolder.getMessages(null); @@ -1401,7 +1393,7 @@ public class MessagingController implements Runnable { Store localStore = Store.getInstance( account.getLocalStoreUri(), mApplication, null); Folder localFolder = localStore.getFolder(account.getTrashFolderName()); - localFolder.open(OpenMode.READ_WRITE, null); + localFolder.open(OpenMode.READ_WRITE); Message[] messages = localFolder.getMessages(null); localFolder.setFlags(messages, new Flag[] { Flag.DELETED @@ -1459,7 +1451,7 @@ public class MessagingController implements Runnable { Store localStore = Store.getInstance(account.getLocalStoreUri(), mApplication, null); LocalFolder localFolder = (LocalFolder) localStore.getFolder(account.getDraftsFolderName()); - localFolder.open(OpenMode.READ_WRITE, null); + localFolder.open(OpenMode.READ_WRITE); localFolder.appendMessages(new Message[] { message }); diff --git a/src/com/android/email/mail/store/ImapStore.java b/src/com/android/email/mail/store/ImapStore.java index 1b09b6c85..2f924a5b6 100644 --- a/src/com/android/email/mail/store/ImapStore.java +++ b/src/com/android/email/mail/store/ImapStore.java @@ -29,7 +29,6 @@ import com.android.email.mail.MessagingException; import com.android.email.mail.Part; import com.android.email.mail.Store; import com.android.email.mail.Transport; -import com.android.email.mail.Folder.PersistentDataCallbacks; import com.android.email.mail.internet.MimeBodyPart; import com.android.email.mail.internet.MimeHeader; import com.android.email.mail.internet.MimeMessage; @@ -326,8 +325,7 @@ public class ImapStore extends Store { this.mName = name; } - public void open(OpenMode mode, PersistentDataCallbacks callbacks) - throws MessagingException { + public void open(OpenMode mode) throws MessagingException { if (isOpen() && mMode == mode) { // Make sure the connection is valid. If it's not we'll close it down and continue // on to get a new one. diff --git a/src/com/android/email/mail/store/Pop3Store.java b/src/com/android/email/mail/store/Pop3Store.java index 57aaef91b..813879893 100644 --- a/src/com/android/email/mail/store/Pop3Store.java +++ b/src/com/android/email/mail/store/Pop3Store.java @@ -28,7 +28,6 @@ import com.android.email.mail.MessagingException; import com.android.email.mail.Store; import com.android.email.mail.Transport; import com.android.email.mail.Folder.OpenMode; -import com.android.email.mail.Folder.PersistentDataCallbacks; import com.android.email.mail.internet.MimeMessage; import com.android.email.mail.transport.LoggingInputStream; import com.android.email.mail.transport.MailTransport; @@ -180,7 +179,7 @@ public class Pop3Store extends Store { public void checkSettings() throws MessagingException { Pop3Folder folder = new Pop3Folder("INBOX"); try { - folder.open(OpenMode.READ_WRITE, null); + folder.open(OpenMode.READ_WRITE); folder.checkSettings(); } finally { folder.close(false); // false == don't expunge anything @@ -230,8 +229,7 @@ public class Pop3Store extends Store { } @Override - public synchronized void open(OpenMode mode, PersistentDataCallbacks callbacks) - throws MessagingException { + public synchronized void open(OpenMode mode) throws MessagingException { if (mTransport.isOpen()) { return; } @@ -857,7 +855,7 @@ public class Pop3Store extends Store { */ private String executeSensitiveCommand(String command, String sensitiveReplacement) throws IOException, MessagingException { - open(OpenMode.READ_WRITE, null); + open(OpenMode.READ_WRITE); if (command != null) { mTransport.writeLine(command, sensitiveReplacement); diff --git a/tests/src/com/android/email/mail/store/ImapStoreUnitTests.java b/tests/src/com/android/email/mail/store/ImapStoreUnitTests.java index a956bc0f7..ef0b2f6bc 100644 --- a/tests/src/com/android/email/mail/store/ImapStoreUnitTests.java +++ b/tests/src/com/android/email/mail/store/ImapStoreUnitTests.java @@ -66,7 +66,7 @@ public class ImapStoreUnitTests extends AndroidTestCase { // try to open it setupOpenFolder(mockTransport); - mFolder.open(OpenMode.READ_WRITE, null); + mFolder.open(OpenMode.READ_WRITE); // TODO: inject specific facts in the initial folder SELECT and check them here } diff --git a/tests/src/com/android/email/mail/store/Pop3StoreUnitTests.java b/tests/src/com/android/email/mail/store/Pop3StoreUnitTests.java index f0b8d8e6f..d05f3b331 100644 --- a/tests/src/com/android/email/mail/store/Pop3StoreUnitTests.java +++ b/tests/src/com/android/email/mail/store/Pop3StoreUnitTests.java @@ -129,7 +129,7 @@ public class Pop3StoreUnitTests extends AndroidTestCase { // try to open it setupOpenFolder(mockTransport, 0, null); - mFolder.open(OpenMode.READ_ONLY, null); + mFolder.open(OpenMode.READ_ONLY); } /** @@ -569,7 +569,7 @@ public class Pop3StoreUnitTests extends AndroidTestCase { private void openFolderWithMessage(MockTransport mockTransport) throws MessagingException { // try to open it setupOpenFolder(mockTransport, 1, null); - mFolder.open(OpenMode.READ_ONLY, null); + mFolder.open(OpenMode.READ_ONLY); // check message count assertEquals(1, mFolder.getMessageCount());