From 025d29fd4b9dd8351fe2e0428a585cf327ddaca4 Mon Sep 17 00:00:00 2001 From: Ben Komalo Date: Sun, 10 Jul 2011 17:19:56 -0700 Subject: [PATCH] Fix some missed account setup flags. There were two places where account flags were being set on setup: one was in manual setup when the user selected the account type (pop/imap/eas), and another was when it was automatically determined from XML. The two paths were inconsistent and one was setting bits like SUPPORTS_SEARCH but the other wasn't. This fixes being able to search in IMAP Bug: 5011932 Change-Id: I50eada7485aaef4e2a85d25fa7eb9ac7ab03093a --- .../android/emailcommon/provider/Account.java | 2 +- .../setup/AccountSetupAccountType.java | 11 +++------- .../activity/setup/AccountSetupBasics.java | 21 +++++++++++++++---- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/emailcommon/src/com/android/emailcommon/provider/Account.java b/emailcommon/src/com/android/emailcommon/provider/Account.java index 7accab1b7..7ef8bfb3e 100644 --- a/emailcommon/src/com/android/emailcommon/provider/Account.java +++ b/emailcommon/src/com/android/emailcommon/provider/Account.java @@ -337,7 +337,7 @@ public final class Account extends EmailContent implements AccountColumns, Parce /** * Set the sync lookback window. Be sure to call save() to commit to database. * TODO define sentinel values for "all", "1 month", etc. See Account.java - * @param value One of the {@code Account.SYNC_WINDOW_*} constants + * @param value One of the {@link com.android.emailcommon.service.SyncWindow} constants */ public void setSyncLookback(int value) { mSyncLookback = value; diff --git a/src/com/android/email/activity/setup/AccountSetupAccountType.java b/src/com/android/email/activity/setup/AccountSetupAccountType.java index bb6109c7a..53f20a9e0 100644 --- a/src/com/android/email/activity/setup/AccountSetupAccountType.java +++ b/src/com/android/email/activity/setup/AccountSetupAccountType.java @@ -88,6 +88,7 @@ public class AccountSetupAccountType extends AccountSetupActivity implements OnC hostAuth.mLogin = hostAuth.mLogin + "@" + hostAuth.mAddress; hostAuth.mAddress = AccountSettingsUtils.inferServerName(hostAuth.mAddress, HostAuth.SCHEME_POP3, null); + AccountSetupBasics.setFlagsForProtocol(account, HostAuth.SCHEME_POP3); SetupData.setCheckSettingsMode(SetupData.CHECK_INCOMING | SetupData.CHECK_OUTGOING); AccountSetupIncoming.actionIncomingSettings(this, SetupData.getFlowMode(), account); finish(); @@ -104,10 +105,7 @@ public class AccountSetupAccountType extends AccountSetupActivity implements OnC hostAuth.mLogin = hostAuth.mLogin + "@" + hostAuth.mAddress; hostAuth.mAddress = AccountSettingsUtils.inferServerName(hostAuth.mAddress, HostAuth.SCHEME_IMAP, null); - // Delete policy must be set explicitly, because IMAP does not provide a UI selection - // for it. This logic needs to be followed in the auto setup flow as well. - account.setDeletePolicy(Account.DELETE_POLICY_ON_DELETE); - account.mFlags |= Account.FLAGS_SUPPORTS_SEARCH; + AccountSetupBasics.setFlagsForProtocol(account, HostAuth.SCHEME_IMAP); SetupData.setCheckSettingsMode(SetupData.CHECK_INCOMING | SetupData.CHECK_OUTGOING); AccountSetupIncoming.actionIncomingSettings(this, SetupData.getFlowMode(), account); finish(); @@ -125,10 +123,7 @@ public class AccountSetupAccountType extends AccountSetupActivity implements OnC HostAuth sendAuth = account.getOrCreateHostAuthSend(this); sendAuth.setConnection(HostAuth.SCHEME_EAS, sendAuth.mAddress, sendAuth.mPort, sendAuth.mFlags | HostAuth.FLAG_SSL); - // TODO: Confirm correct delete policy for exchange - account.setDeletePolicy(Account.DELETE_POLICY_ON_DELETE); - account.setSyncInterval(Account.CHECK_INTERVAL_PUSH); - account.setSyncLookback(1); + AccountSetupBasics.setFlagsForProtocol(account, HostAuth.SCHEME_EAS); SetupData.setCheckSettingsMode(SetupData.CHECK_AUTODISCOVER); AccountSetupExchange.actionIncomingSettings(this, SetupData.getFlowMode(), account); finish(); diff --git a/src/com/android/email/activity/setup/AccountSetupBasics.java b/src/com/android/email/activity/setup/AccountSetupBasics.java index 0d4c2a7b6..a54949243 100644 --- a/src/com/android/email/activity/setup/AccountSetupBasics.java +++ b/src/com/android/email/activity/setup/AccountSetupBasics.java @@ -52,7 +52,9 @@ import com.android.emailcommon.Logging; import com.android.emailcommon.provider.Account; import com.android.emailcommon.provider.EmailContent; import com.android.emailcommon.provider.HostAuth; +import com.android.emailcommon.service.SyncWindow; import com.android.emailcommon.utility.Utility; +import com.google.common.annotations.VisibleForTesting; import java.net.URISyntaxException; import java.util.concurrent.Callable; @@ -112,7 +114,7 @@ public class AccountSetupBasics extends AccountSetupActivity private EditText mEmailView; private EditText mPasswordView; private CheckBox mDefaultView; - private EmailAddressValidator mEmailValidator = new EmailAddressValidator(); + private final EmailAddressValidator mEmailValidator = new EmailAddressValidator(); private Provider mProvider; private Button mManualButton; private Button mNextButton; @@ -397,7 +399,7 @@ public class AccountSetupBasics extends AccountSetupActivity /** * Callable that returns the username (based on other accounts) or null. */ - private Callable mOwnerLookupCallable = new Callable() { + private final Callable mOwnerLookupCallable = new Callable() { public String call() { Context context = AccountSetupBasics.this; String name = null; @@ -601,15 +603,26 @@ public class AccountSetupBasics extends AccountSetupActivity SetupData.setDefault(isDefault); // TODO - why duplicated, if already set in account String protocol = account.mHostAuthRecv.mProtocol; - // Set sync and delete policies for specific inbound account types + setFlagsForProtocol(account, protocol); + } + + /** + * Sets the account sync, delete, and other misc flags not captured in {@code HostAuth} + * information for the specified account based on the protocol type. + */ + @VisibleForTesting + static void setFlagsForProtocol(Account account, String protocol) { if (HostAuth.SCHEME_IMAP.equals(protocol)) { // Delete policy must be set explicitly, because IMAP does not provide a UI selection - // for it. This logic needs to be followed in the auto setup flow as well. + // for it. account.setDeletePolicy(Account.DELETE_POLICY_ON_DELETE); + account.mFlags |= Account.FLAGS_SUPPORTS_SEARCH; } if (HostAuth.SCHEME_EAS.equals(protocol)) { + account.setDeletePolicy(Account.DELETE_POLICY_ON_DELETE); account.setSyncInterval(Account.CHECK_INTERVAL_PUSH); + account.setSyncLookback(SyncWindow.SYNC_WINDOW_AUTO); } else { account.setSyncInterval(DEFAULT_ACCOUNT_CHECK_INTERVAL); }