diff options
author | Simranjit Singh Kohli <simranjit@google.com> | 2015-05-22 14:00:32 -0700 |
---|---|---|
committer | Simranjit Singh Kohli <simranjit@google.com> | 2015-05-22 17:19:21 -0700 |
commit | 734f8fb69d0c8af7b10bded718897a55ced49bf0 (patch) | |
tree | 51941b99854f3590637b72d59fb4d2d5e4542749 | |
parent | 97bf518f7b818d297a500204627d1ad06127bff1 (diff) | |
download | frameworks_base-734f8fb69d0c8af7b10bded718897a55ced49bf0.zip frameworks_base-734f8fb69d0c8af7b10bded718897a55ced49bf0.tar.gz frameworks_base-734f8fb69d0c8af7b10bded718897a55ced49bf0.tar.bz2 |
[ChooseAccount/AccountManager.newChooseAccountIntent Bug Fixes]
Fixing lots of bugs related to the ChooseAccount Activities.
1. Fix jank which is seen when no accounts are present on the device.
2. After addition of the account, return to the user.
3. Don't crash when the user provides null to allowableAccountTypes.
4. Updated documentation of AccountManager#newChooseAccountIntent.
5. Fix NPE.
Bug: 13104800
Bug: 17926560
Bug: 9626001
Change-Id: I0d1913e46560cfb458526a7c930a38049602d8f1
-rw-r--r-- | core/java/android/accounts/AccountManager.java | 3 | ||||
-rw-r--r-- | core/java/android/accounts/ChooseTypeAndAccountActivity.java | 55 |
2 files changed, 32 insertions, 26 deletions
diff --git a/core/java/android/accounts/AccountManager.java b/core/java/android/accounts/AccountManager.java index fd40d99..31e129b 100644 --- a/core/java/android/accounts/AccountManager.java +++ b/core/java/android/accounts/AccountManager.java @@ -2326,7 +2326,8 @@ public class AccountManager { * shown. If not specified then this field will not limit the displayed accounts. * @param allowableAccountTypes an optional string array of account types. These are used * both to filter the shown accounts and to filter the list of account types that are shown - * when adding an account. + * when adding an account. If not specified then this field will not limit the displayed + * account types when adding an account. * @param alwaysPromptForAccount if set the account chooser screen is always shown, otherwise * it is only shown when there is more than one account from which to choose * @param descriptionOverrideText if non-null this string is used as the description in the diff --git a/core/java/android/accounts/ChooseTypeAndAccountActivity.java b/core/java/android/accounts/ChooseTypeAndAccountActivity.java index 82c2159..c06b462 100644 --- a/core/java/android/accounts/ChooseTypeAndAccountActivity.java +++ b/core/java/android/accounts/ChooseTypeAndAccountActivity.java @@ -132,7 +132,6 @@ public class ChooseTypeAndAccountActivity extends Activity @Override public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); if (Log.isLoggable(TAG, Log.VERBOSE)) { Log.v(TAG, "ChooseTypeAndAccountActivity.onCreate(savedInstanceState=" + savedInstanceState + ")"); @@ -192,7 +191,6 @@ public class ChooseTypeAndAccountActivity extends Activity mAlwaysPromptForAccount = intent.getBooleanExtra(EXTRA_ALWAYS_PROMPT_FOR_ACCOUNT, false); mDescriptionOverride = intent.getStringExtra(EXTRA_DESCRIPTION_TEXT_OVERRIDE); - // Need to do this once here to request the window feature. Can't do it in onResume mAccounts = getAcceptableAccountChoices(AccountManager.get(this)); if (mAccounts.isEmpty() && mDisallowAddAccounts) { @@ -200,17 +198,11 @@ public class ChooseTypeAndAccountActivity extends Activity setContentView(R.layout.app_not_authorized); mDontShowPicker = true; } - } - - @Override - protected void onResume() { - super.onResume(); - - if (mDontShowPicker) return; - final AccountManager accountManager = AccountManager.get(this); - - mAccounts = getAcceptableAccountChoices(accountManager); + if (mDontShowPicker) { + super.onCreate(savedInstanceState); + return; + } // In cases where the activity does not need to show an account picker, cut the chase // and return the result directly. Eg: @@ -220,6 +212,7 @@ public class ChooseTypeAndAccountActivity extends Activity // If there are no relevant accounts and only one relevant account type go directly to // add account. Otherwise let the user choose. if (mAccounts.isEmpty()) { + setNonLabelThemeAndCallSuperCreate(savedInstanceState); if (mSetOfRelevantAccountTypes.size() == 1) { runAddAccountForAuthenticator(mSetOfRelevantAccountTypes.iterator().next()); } else { @@ -231,6 +224,7 @@ public class ChooseTypeAndAccountActivity extends Activity // if there is only one allowable account return it if (!mAlwaysPromptForAccount && mAccounts.size() == 1) { Account account = mAccounts.get(0); + super.onCreate(savedInstanceState); setResultAndFinish(account.name, account.type); return; } @@ -240,8 +234,7 @@ public class ChooseTypeAndAccountActivity extends Activity mSelectedItemIndex = getItemIndexToSelect( mAccounts, mSelectedAccountName, mSelectedAddNewAccount); - // Cannot set content view until we know that mPendingRequest is not null, otherwise - // would cause screen flicker. + super.onCreate(savedInstanceState); setContentView(R.layout.choose_type_and_account); overrideDescriptionIfSupplied(mDescriptionOverride); populateUIAccountList(listItems); @@ -409,6 +402,17 @@ public class ChooseTypeAndAccountActivity extends Activity finish(); } + /** + * The default activity theme shows label at the top. Set a theme which does + * not show label, which effectively makes the activity invisible. Note that + * no content is being set. If something gets set, using this theme may be + * useless. + */ + private void setNonLabelThemeAndCallSuperCreate(Bundle savedInstanceState) { + setTheme(R.style.Theme_Material_Light_Dialog_NoActionBar); + super.onCreate(savedInstanceState); + } + private void onAccountSelected(Account account) { Log.d(TAG, "selected account " + account); setResultAndFinish(account.name, account.type); @@ -489,8 +493,7 @@ public class ChooseTypeAndAccountActivity extends Activity mCallingUid); ArrayList<Account> accountsToPopulate = new ArrayList<Account>(accounts.length); for (Account account : accounts) { - if (mSetOfAllowableAccounts != null - && !mSetOfAllowableAccounts.contains(account)) { + if (mSetOfAllowableAccounts != null && !mSetOfAllowableAccounts.contains(account)) { continue; } if (mSetOfRelevantAccountTypes != null @@ -503,7 +506,7 @@ public class ChooseTypeAndAccountActivity extends Activity } /** - * Return a set of account types speficied by the intent as well as supported by the + * Return a set of account types specified by the intent as well as supported by the * AccountManager. */ private Set<String> getReleventAccountTypes(final Intent intent) { @@ -512,14 +515,16 @@ public class ChooseTypeAndAccountActivity extends Activity Set<String> setOfRelevantAccountTypes = null; final String[] allowedAccountTypes = intent.getStringArrayExtra(EXTRA_ALLOWABLE_ACCOUNT_TYPES_STRING_ARRAY); - if (allowedAccountTypes != null) { - setOfRelevantAccountTypes = Sets.newHashSet(allowedAccountTypes); - AuthenticatorDescription[] descs = AccountManager.get(this).getAuthenticatorTypes(); - Set<String> supportedAccountTypes = new HashSet<String>(descs.length); - for (AuthenticatorDescription desc : descs) { - supportedAccountTypes.add(desc.type); - } - setOfRelevantAccountTypes.retainAll(supportedAccountTypes); + AuthenticatorDescription[] descs = AccountManager.get(this).getAuthenticatorTypes(); + Set<String> supportedAccountTypes = new HashSet<String>(descs.length); + for (AuthenticatorDescription desc : descs) { + supportedAccountTypes.add(desc.type); + } + if (allowedAccountTypes != null) { + setOfRelevantAccountTypes = Sets.newHashSet(allowedAccountTypes); + setOfRelevantAccountTypes.retainAll(supportedAccountTypes); + } else { + setOfRelevantAccountTypes = supportedAccountTypes; } return setOfRelevantAccountTypes; } |