From 8df9af0df3ea8d987b06364f388cd5de57c7bea9 Mon Sep 17 00:00:00 2001 From: Marc Blank Date: Fri, 15 Jul 2011 13:00:35 -0700 Subject: [PATCH] Clear account incomplete flag properly; handle unusual flow * We waited to clear the incomplete flag until security was agreed to, but this can lead to accounts left incomplete; we now clear the flag as soon as the AccountManager account is created (by convention, this is when the EmailProvider account is complete) * Also, allow onDone() to be called more than once with a saved account, leaving cleanly, rather than throwing a runtime exception Bug: 5016792 Change-Id: Ib5fc44ac045a1dd9bd5d63f922c037ed637d5341 --- .../activity/setup/AccountSetupOptions.java | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/com/android/email/activity/setup/AccountSetupOptions.java b/src/com/android/email/activity/setup/AccountSetupOptions.java index c91615f46..b118a4f03 100644 --- a/src/com/android/email/activity/setup/AccountSetupOptions.java +++ b/src/com/android/email/activity/setup/AccountSetupOptions.java @@ -207,9 +207,14 @@ public class AccountSetupOptions extends AccountSetupActivity implements OnClick */ private void onDone() { final Account account = SetupData.getAccount(); + if (account.isSaved()) { + // Disrupting the normal flow could get us here, but if the account is already + // saved, we've done this work + return; + } account.setDisplayName(account.getEmailAddress()); int newFlags = account.getFlags() & - ~(Account.FLAGS_NOTIFY_NEW_MAIL | Account.FLAGS_BACKGROUND_ATTACHMENTS); + ~(Account.FLAGS_NOTIFY_NEW_MAIL | Account.FLAGS_BACKGROUND_ATTACHMENTS); if (mNotifyView.isChecked()) { newFlags |= Account.FLAGS_NOTIFY_NEW_MAIL; } @@ -225,9 +230,6 @@ public class AccountSetupOptions extends AccountSetupActivity implements OnClick } account.setDefaultAccount(mDefaultView.isChecked()); - if (account.isSaved()) { - throw new IllegalStateException("in AccountSetupOptions with already-saved account"); - } if (account.mHostAuthRecv == null) { throw new IllegalStateException("in AccountSetupOptions with null mHostAuthRecv"); } @@ -321,14 +323,18 @@ public class AccountSetupOptions extends AccountSetupActivity implements OnClick private void optionsComplete() { // If the account manager initiated the creation, report success at this point AccountAuthenticatorResponse authenticatorResponse = - SetupData.getAccountAuthenticatorResponse(); + SetupData.getAccountAuthenticatorResponse(); if (authenticatorResponse != null) { authenticatorResponse.onResult(null); SetupData.setAccountAuthenticatorResponse(null); } - // If we've got policies for this account, ask the user to accept. + // Now that AccountManager account creation is complete, clear the INCOMPLETE flag Account account = SetupData.getAccount(); + account.mFlags &= ~Account.FLAGS_INCOMPLETE; + AccountSettingsUtils.commitSettings(AccountSetupOptions.this, account); + + // If we've got policies for this account, ask the user to accept. if ((account.mFlags & Account.FLAGS_SECURITY_HOLD) != 0) { Intent intent = AccountSecurity.actionUpdateSecurityIntent(this, account.mId, false); startActivityForResult(intent, AccountSetupOptions.REQUEST_CODE_ACCEPT_POLICIES); @@ -358,9 +364,9 @@ public class AccountSetupOptions extends AccountSetupActivity implements OnClick @Override public void run() { AccountSetupOptions context = AccountSetupOptions.this; - // Clear the incomplete/security hold flag now + // Clear the security hold flag now Account account = SetupData.getAccount(); - account.mFlags &= ~(Account.FLAGS_INCOMPLETE | Account.FLAGS_SECURITY_HOLD); + account.mFlags &= ~Account.FLAGS_SECURITY_HOLD; AccountSettingsUtils.commitSettings(context, account); // Start up services based on new account(s) Email.setServicesEnabledSync(context);