From 74309ea53a5a72430bafaa8cea4d82d4e24f61bd Mon Sep 17 00:00:00 2001 From: Fabrice Di Meglio Date: Thu, 20 Feb 2014 14:41:51 -0800 Subject: [PATCH] Fix bug #13058470 Cannot add account -- Settings app crashes - revert back to an Activity instead of a fragment. This is a straight reverse of the changes introduced for trying to have a Fragment. Basically ChooseAccountActivity was previously an Activity for choosing an account type. If the list of account types was containing only one item, then the ChooseAccountActivity was just a pass thru and was falling back to the only account authority available. In the current reported bug, this was happening by disabling the Email app and thus having only the GoogleAuthenticator as an Authority. Then in the onCreate() the ChooseAccountFragment was seeing that there was only one account authenticator and issuing a BACK button press. Too bad, this was done into a non finished Fragment transaction and leading to a crash. All in all, we NEED to have an Activity and cannot use a Fragment in that case. Change-Id: I4a867a25fe9580929ec50a6775105adac1f88c52 --- AndroidManifest.xml | 8 +++--- src/com/android/settings/Settings.java | 1 - .../android/settings/SettingsActivity.java | 2 -- .../settings/accounts/AddAccountSettings.java | 2 +- ...agment.java => ChooseAccountActivity.java} | 26 +++++++++---------- 5 files changed, 17 insertions(+), 22 deletions(-) rename src/com/android/settings/accounts/{ChooseAccountFragment.java => ChooseAccountActivity.java} (91%) diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 6e01aecb824..fe777c9fbc2 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -1535,12 +1535,10 @@ - - - + android:configChanges="orientation|keyboardHidden|screenSize" + android:theme="@android:style/Theme.Holo.DialogWhenLarge"/> mProviderList = new ArrayList(); @@ -77,13 +76,14 @@ public class ChooseAccountFragment extends SettingsPreferenceFragment { } @Override - public void onCreate(Bundle icicle) { + protected void onCreate(Bundle icicle) { super.onCreate(icicle); + setContentView(R.layout.add_account_screen); addPreferencesFromResource(R.xml.add_account_settings); - mAuthorities = getActivity().getIntent().getStringArrayExtra( + mAuthorities = getIntent().getStringArrayExtra( AccountPreferenceBase.AUTHORITIES_FILTER_KEY); - String[] accountTypesFilter = getActivity().getIntent().getStringArrayExtra( + String[] accountTypesFilter = getIntent().getStringArrayExtra( AccountPreferenceBase.ACCOUNT_TYPES_FILTER_KEY); if (accountTypesFilter != null) { mAccountTypesFilter = new HashSet(); @@ -100,7 +100,7 @@ public class ChooseAccountFragment extends SettingsPreferenceFragment { * and update any UI that depends on AuthenticatorDescriptions in onAuthDescriptionsUpdated(). */ private void updateAuthDescriptions() { - mAuthDescs = AccountManager.get(getActivity()).getAuthenticatorTypes(); + mAuthDescs = AccountManager.get(this).getAuthenticatorTypes(); for (int i = 0; i < mAuthDescs.length; i++) { mTypeToAuthDescription.put(mAuthDescs[i].type, mAuthDescs[i]); } @@ -148,7 +148,7 @@ public class ChooseAccountFragment extends SettingsPreferenceFragment { for (ProviderEntry pref : mProviderList) { Drawable drawable = getDrawableForType(pref.type); ProviderPreference p = - new ProviderPreference(getActivity(), pref.type, drawable, pref.name); + new ProviderPreference(this, pref.type, drawable, pref.name); mAddAccountGroup.addPreference(p); } } else { @@ -160,7 +160,7 @@ public class ChooseAccountFragment extends SettingsPreferenceFragment { } Log.v(TAG, "No providers found for authorities: " + auths); } - getActivity().setResult(Activity.RESULT_CANCELED); + setResult(RESULT_CANCELED); finish(); } } @@ -196,7 +196,7 @@ public class ChooseAccountFragment extends SettingsPreferenceFragment { if (mTypeToAuthDescription.containsKey(accountType)) { try { AuthenticatorDescription desc = mTypeToAuthDescription.get(accountType); - Context authContext = getActivity().createPackageContext(desc.packageName, 0); + Context authContext = createPackageContext(desc.packageName, 0); icon = authContext.getResources().getDrawable(desc.iconId); } catch (PackageManager.NameNotFoundException e) { // TODO: place holder icon for missing account icons? @@ -219,7 +219,7 @@ public class ChooseAccountFragment extends SettingsPreferenceFragment { if (mTypeToAuthDescription.containsKey(accountType)) { try { AuthenticatorDescription desc = mTypeToAuthDescription.get(accountType); - Context authContext = getActivity().createPackageContext(desc.packageName, 0); + Context authContext = createPackageContext(desc.packageName, 0); label = authContext.getResources().getText(desc.labelId); } catch (PackageManager.NameNotFoundException e) { Log.w(TAG, "No label name for account type " + accountType); @@ -245,7 +245,7 @@ public class ChooseAccountFragment extends SettingsPreferenceFragment { private void finishWithAccountType(String accountType) { Intent intent = new Intent(); intent.putExtra(AddAccountSettings.EXTRA_SELECTED_ACCOUNT, accountType); - getActivity().setResult(Activity.RESULT_OK, intent); + setResult(RESULT_OK, intent); finish(); } }