From 9dac94975f31013d4b31ffb15eba27f352b2e758 Mon Sep 17 00:00:00 2001 From: Daisuke Miyakawa Date: Thu, 7 Oct 2010 14:17:11 -0700 Subject: [PATCH] Use AccountAuthenticatorResponse properly. Current implementation ignores callbacks coming from AccountManager, which should be called everytime when this Activity finishes its job. Bug: 3069222 Change-Id: Iea03cf94bdfe8da184e415bf7e759ddeb46ecdd9 --- .../activity/setup/AccountSetupBasics.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/com/android/email/activity/setup/AccountSetupBasics.java b/src/com/android/email/activity/setup/AccountSetupBasics.java index b420e3e01..a75b25718 100644 --- a/src/com/android/email/activity/setup/AccountSetupBasics.java +++ b/src/com/android/email/activity/setup/AccountSetupBasics.java @@ -23,6 +23,8 @@ import com.android.email.activity.Welcome; import com.android.email.provider.EmailContent.Account; import com.android.email.provider.EmailContent.HostAuth; +import android.accounts.AccountAuthenticatorResponse; +import android.accounts.AccountManager; import android.app.Activity; import android.app.FragmentTransaction; import android.content.Context; @@ -48,6 +50,12 @@ public class AccountSetupBasics extends AccountSetupActivity private boolean mManualButtonDisplayed; private boolean mNextButtonEnabled; + // Used when this Activity is called as part of account authentification flow, + // which requires to do extra work before and after the account creation. + // See also AccountAuthenticatorActivity. + private AccountAuthenticatorResponse mAccountAuthenticatorResponse = null; + private Bundle mResultBundle = null; + public static void actionNewAccount(Activity fromActivity) { SetupData.init(SetupData.FLOW_MODE_NORMAL); fromActivity.startActivity(new Intent(fromActivity, AccountSetupBasics.class)); @@ -132,6 +140,13 @@ public class AccountSetupBasics extends AccountSetupActivity // Configure fragment mFragment.setCallback(this, alternateStrings); + + mAccountAuthenticatorResponse = + getIntent().getParcelableExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE); + + if (mAccountAuthenticatorResponse != null) { + mAccountAuthenticatorResponse.onRequestContinued(); + } } /** @@ -248,4 +263,19 @@ public class AccountSetupBasics extends AccountSetupActivity SetupData.setAllowAutodiscover(allowAutoDiscover); AccountSetupAccountType.actionSelectAccountType(this); } + + @Override + public void finish() { + if (mAccountAuthenticatorResponse != null) { + // send the result bundle back if set, otherwise send an error. + if (mResultBundle != null) { + mAccountAuthenticatorResponse.onResult(mResultBundle); + } else { + mAccountAuthenticatorResponse.onError(AccountManager.ERROR_CODE_CANCELED, + "canceled"); + } + mAccountAuthenticatorResponse = null; + } + super.finish(); + } }