From 900021dbeeb93409c069a04a740c2436e30d1b2a Mon Sep 17 00:00:00 2001 From: Andy Stadler Date: Wed, 5 Jan 2011 14:11:44 -0800 Subject: [PATCH] Prevent duplicate mailbox creation * Synchronized findOrCreateMailboxOfType Bug: 3291982 Change-Id: I7146458112296aa2b0f4b8f24d0c86f16a8b6626 --- src/com/android/email/Controller.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/com/android/email/Controller.java b/src/com/android/email/Controller.java index 4ac040cda..0c4a58c49 100644 --- a/src/com/android/email/Controller.java +++ b/src/com/android/email/Controller.java @@ -427,13 +427,18 @@ public class Controller { } /** + * Look for a specific mailbox, creating it if necessary, and return the mailbox id. + * This is a blocking operation and should not be called from the UI thread. + * + * Synchronized so multiple threads can call it (and not risk creating duplicate boxes). + * * @param accountId the account id * @param mailboxType the mailbox type (e.g. EmailContent.Mailbox.TYPE_TRASH) * @return the id of the mailbox. The mailbox is created if not existing. * Returns Mailbox.NO_MAILBOX if the accountId or mailboxType are negative. * Does not validate the input in other ways (e.g. does not verify the existence of account). */ - public long findOrCreateMailboxOfType(long accountId, int mailboxType) { + public synchronized long findOrCreateMailboxOfType(long accountId, int mailboxType) { if (accountId < 0 || mailboxType < 0) { return Mailbox.NO_MAILBOX; }