From 9bbdd0bf5006512a000b0d3e6bd6ee2998a2e48b Mon Sep 17 00:00:00 2001 From: Fred Quintana Date: Tue, 27 Sep 2011 17:24:32 -0700 Subject: [PATCH] Fix a bug in the account chooser where relaunching an in-progress flow results in a blank screen. The fix involves making the first activity just call the account type chooser to get the account type to add, rather than having the account type chooser also kick off the AccountManager.addAccount() request itself. Instead the first activity will get the type back and then call AccountManager.addAccount() Bug: 5346810 Change-Id: I4a0cf2370971b98f8ee0910f5401d97e999e546b --- .../accounts/ChooseAccountTypeActivity.java | 54 +++++-------------- .../ChooseTypeAndAccountActivity.java | 47 ++++++++++++++-- 2 files changed, 56 insertions(+), 45 deletions(-) diff --git a/core/java/android/accounts/ChooseAccountTypeActivity.java b/core/java/android/accounts/ChooseAccountTypeActivity.java index 5239e8c56fb0e..448b2c0c49ae7 100644 --- a/core/java/android/accounts/ChooseAccountTypeActivity.java +++ b/core/java/android/accounts/ChooseAccountTypeActivity.java @@ -33,7 +33,6 @@ import android.widget.ListView; import android.widget.TextView; import com.android.internal.R; -import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -43,7 +42,7 @@ import java.util.Set; /** * @hide */ -public class ChooseAccountTypeActivity extends Activity implements AccountManagerCallback { +public class ChooseAccountTypeActivity extends Activity { private static final String TAG = "AccountManager"; private HashMap mTypeToAuthenticatorInfo = new HashMap(); @@ -52,7 +51,6 @@ public class ChooseAccountTypeActivity extends Activity implements AccountManage @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.choose_account_type); // Read the validAccountTypes, if present, and add them to the setOfAllowableAccountTypes Set setOfAllowableAccountTypes = null; @@ -90,10 +88,11 @@ public class ChooseAccountTypeActivity extends Activity implements AccountManage } if (mAuthenticatorInfosToDisplay.size() == 1) { - runAddAccountForAuthenticator(mAuthenticatorInfosToDisplay.get(0)); + setResultAndFinish(mAuthenticatorInfosToDisplay.get(0).desc.type); return; } + setContentView(R.layout.choose_account_type); // Setup the list ListView list = (ListView) findViewById(android.R.id.list); // Use an existing ListAdapter that will map an array of strings to TextViews @@ -103,11 +102,20 @@ public class ChooseAccountTypeActivity extends Activity implements AccountManage list.setTextFilterEnabled(false); list.setOnItemClickListener(new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView parent, View v, int position, long id) { - runAddAccountForAuthenticator(mAuthenticatorInfosToDisplay.get(position)); + setResultAndFinish(mAuthenticatorInfosToDisplay.get(position).desc.type); } }); } + private void setResultAndFinish(final String type) { + Bundle bundle = new Bundle(); + bundle.putString(AccountManager.KEY_ACCOUNT_TYPE, type); + setResult(Activity.RESULT_OK, new Intent().putExtras(bundle)); + Log.d(TAG, "ChooseAccountTypeActivity.setResultAndFinish: " + + "selected account type " + type); + finish(); + } + private void buildTypeToAuthDescriptionMap() { for(AuthenticatorDescription desc : AccountManager.get(this).getAuthenticatorTypes()) { String name = null; @@ -136,42 +144,6 @@ public class ChooseAccountTypeActivity extends Activity implements AccountManage } } - protected void runAddAccountForAuthenticator(AuthInfo authInfo) { - Log.d(TAG, "selected account type " + authInfo.name); - final Bundle options = getIntent().getBundleExtra( - ChooseTypeAndAccountActivity.EXTRA_ADD_ACCOUNT_OPTIONS_BUNDLE); - final String[] requiredFeatures = getIntent().getStringArrayExtra( - ChooseTypeAndAccountActivity.EXTRA_ADD_ACCOUNT_REQUIRED_FEATURES_STRING_ARRAY); - final String authTokenType = getIntent().getStringExtra( - ChooseTypeAndAccountActivity.EXTRA_ADD_ACCOUNT_AUTH_TOKEN_TYPE_STRING); - AccountManager.get(this).addAccount(authInfo.desc.type, authTokenType, requiredFeatures, - options, this, this, null /* Handler */); - } - - public void run(final AccountManagerFuture accountManagerFuture) { - try { - Bundle accountManagerResult = accountManagerFuture.getResult(); - Bundle bundle = new Bundle(); - bundle.putString(AccountManager.KEY_ACCOUNT_NAME, - accountManagerResult.getString(AccountManager.KEY_ACCOUNT_NAME)); - bundle.putString(AccountManager.KEY_ACCOUNT_TYPE, - accountManagerResult.getString(AccountManager.KEY_ACCOUNT_TYPE)); - setResult(Activity.RESULT_OK, new Intent().putExtras(bundle)); - finish(); - return; - } catch (OperationCanceledException e) { - setResult(Activity.RESULT_CANCELED); - finish(); - return; - } catch (IOException e) { - } catch (AuthenticatorException e) { - } - Bundle bundle = new Bundle(); - bundle.putString(AccountManager.KEY_ERROR_MESSAGE, "error communicating with server"); - setResult(Activity.RESULT_OK, new Intent().putExtras(bundle)); - finish(); - } - private static class AuthInfo { final AuthenticatorDescription desc; final String name; diff --git a/core/java/android/accounts/ChooseTypeAndAccountActivity.java b/core/java/android/accounts/ChooseTypeAndAccountActivity.java index 852c4dddf8197..8cc200250ba3d 100644 --- a/core/java/android/accounts/ChooseTypeAndAccountActivity.java +++ b/core/java/android/accounts/ChooseTypeAndAccountActivity.java @@ -36,6 +36,7 @@ import android.widget.ListView; import android.widget.TextView; import com.android.internal.R; +import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -44,7 +45,8 @@ import java.util.Set; /** * @hide */ -public class ChooseTypeAndAccountActivity extends Activity { +public class ChooseTypeAndAccountActivity extends Activity + implements AccountManagerCallback { private static final String TAG = "AccountManager"; /** @@ -211,10 +213,9 @@ public class ChooseTypeAndAccountActivity extends Activity { protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) { if (resultCode == RESULT_OK && data != null) { - String accountName = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME); String accountType = data.getStringExtra(AccountManager.KEY_ACCOUNT_TYPE); - if (accountName != null && accountType != null) { - setResultAndFinish(accountName, accountType); + if (accountType != null) { + runAddAccountForAuthenticator(accountType); return; } } @@ -223,6 +224,43 @@ public class ChooseTypeAndAccountActivity extends Activity { finish(); } + protected void runAddAccountForAuthenticator(String type) { + Log.d(TAG, "selected account type " + type); + final Bundle options = getIntent().getBundleExtra( + ChooseTypeAndAccountActivity.EXTRA_ADD_ACCOUNT_OPTIONS_BUNDLE); + final String[] requiredFeatures = getIntent().getStringArrayExtra( + ChooseTypeAndAccountActivity.EXTRA_ADD_ACCOUNT_REQUIRED_FEATURES_STRING_ARRAY); + final String authTokenType = getIntent().getStringExtra( + ChooseTypeAndAccountActivity.EXTRA_ADD_ACCOUNT_AUTH_TOKEN_TYPE_STRING); + AccountManager.get(this).addAccount(type, authTokenType, requiredFeatures, + options, this, this, null /* Handler */); + } + + public void run(final AccountManagerFuture accountManagerFuture) { + try { + final Bundle accountManagerResult = accountManagerFuture.getResult(); + final String name = accountManagerResult.getString(AccountManager.KEY_ACCOUNT_NAME); + final String type = accountManagerResult.getString(AccountManager.KEY_ACCOUNT_TYPE); + if (name != null && type != null) { + final Bundle bundle = new Bundle(); + bundle.putString(AccountManager.KEY_ACCOUNT_NAME, name); + bundle.putString(AccountManager.KEY_ACCOUNT_TYPE, type); + setResult(Activity.RESULT_OK, new Intent().putExtras(bundle)); + finish(); + return; + } + } catch (OperationCanceledException e) { + setResult(Activity.RESULT_CANCELED); + finish(); + return; + } catch (IOException e) { + } catch (AuthenticatorException e) { + } + Bundle bundle = new Bundle(); + bundle.putString(AccountManager.KEY_ERROR_MESSAGE, "error communicating with server"); + setResult(Activity.RESULT_OK, new Intent().putExtras(bundle)); + finish(); + } private Drawable getDrawableForType( final HashMap typeToAuthDescription, @@ -266,6 +304,7 @@ public class ChooseTypeAndAccountActivity extends Activity { private void startChooseAccountTypeActivity() { final Intent intent = new Intent(this, ChooseAccountTypeActivity.class); + intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); intent.putExtra(EXTRA_ALLOWABLE_ACCOUNT_TYPES_STRING_ARRAY, getIntent().getStringArrayExtra(EXTRA_ALLOWABLE_ACCOUNT_TYPES_STRING_ARRAY)); intent.putExtra(EXTRA_ADD_ACCOUNT_OPTIONS_BUNDLE,