diff --git a/src/com/android/settings/accounts/AccountAddressBookHelper.java b/src/com/android/settings/accounts/AccountAddressBookHelper.java new file mode 100644 index 0000000000000000000000000000000000000000..a5875f44b74e559e8e32286c0406c12735bf5ca9 --- /dev/null +++ b/src/com/android/settings/accounts/AccountAddressBookHelper.java @@ -0,0 +1,38 @@ +package com.android.settings.accounts; + +import android.accounts.Account; + +class AccountAddressBookHelper { + + /* + By convention all address book account types has "address_book" postfix + e.g. "foundation.e.accountmanager.address_book" + */ + public static final String ADDRESS_BOOK_ACCOUNT_TYPE = "address_book"; + + public static boolean isAccountAddressBookType(String account_type) { + if (account_type != null) { + return account_type.contains(ADDRESS_BOOK_ACCOUNT_TYPE); + } else { + return false; + } + } + + /** + * Converting account name get from nextcloud accoring to our needs + */ + public static String convertAccountName(Account account) { + if (account != null && account.type != null) { + if (!isAccountAddressBookType(account.type)) { + // ecloud account + // TODO - should be constructed out of resources + return "Settings (" + account.name + ")"; + } else { + // TODO change address_book account type name + return account.name; + } + } else { + return ""; + } + } +} diff --git a/src/com/android/settings/accounts/AccountPreferenceController.java b/src/com/android/settings/accounts/AccountPreferenceController.java index 1309cc2bb55c516d6493266a30f8a717eab8ac19..26b526109f743b241f1f85829efee662c0b534af 100644 --- a/src/com/android/settings/accounts/AccountPreferenceController.java +++ b/src/com/android/settings/accounts/AccountPreferenceController.java @@ -482,10 +482,6 @@ public class AccountPreferenceController extends AbstractPreferenceController for (int i = 0; i < accountTypes.length; i++) { final String accountType = accountTypes[i]; - // Skip showing any account that does not have any of the requested authorities - if (!accountTypeHasAnyRequestedAuthorities(helper, accountType)) { - continue; - } final CharSequence label = helper.getLabelForType(mContext, accountType); if (label == null) { continue; @@ -500,20 +496,26 @@ public class AccountPreferenceController extends AbstractPreferenceController // Add a preference row for each individual account for (Account account : accounts) { + // create account with converted name + Account convertedNameAccount = new Account( + AccountAddressBookHelper.convertAccountName(account.name), + account.type, + account.getAccessId() + ); final AccountTypePreference preference = - preferenceToRemove.remove(AccountTypePreference.buildKey(account)); + preferenceToRemove.remove(AccountTypePreference.buildKey(convertedNameAccount)); if (preference != null) { accountTypePreferences.add(preference); continue; } final ArrayList auths = - helper.getAuthoritiesForAccountType(account.type); + helper.getAuthoritiesForAccountType(convertedNameAccount.type); if (!AccountRestrictionHelper.showAccount(mAuthorities, auths)) { continue; } final Bundle fragmentArguments = new Bundle(); fragmentArguments.putParcelable(AccountDetailDashboardFragment.KEY_ACCOUNT, - account); + convertedNameAccount); fragmentArguments.putParcelable(AccountDetailDashboardFragment.KEY_USER_HANDLE, userHandle); fragmentArguments.putString(AccountDetailDashboardFragment.KEY_ACCOUNT_TYPE, @@ -523,9 +525,10 @@ public class AccountPreferenceController extends AbstractPreferenceController fragmentArguments.putInt(AccountDetailDashboardFragment.KEY_ACCOUNT_TITLE_RES, titleResId); fragmentArguments.putParcelable(EXTRA_USER, userHandle); + //c accountTypePreferences.add(new AccountTypePreference( prefContext, mMetricsFeatureProvider.getMetricsCategory(mParent), - account, titleResPackageName, titleResId, label, + convertedNameAccount, titleResPackageName, titleResId, label, AccountDetailDashboardFragment.class.getName(), fragmentArguments, icon)); } helper.preloadDrawableForType(mContext, accountType); diff --git a/src/com/android/settings/accounts/ChooseAccountPreferenceController.java b/src/com/android/settings/accounts/ChooseAccountPreferenceController.java index a217f017f99c0f4aec8b2823f0d5242e2b6eea41..c0973ba6655e878de302da43e451d469e574a6a1 100644 --- a/src/com/android/settings/accounts/ChooseAccountPreferenceController.java +++ b/src/com/android/settings/accounts/ChooseAccountPreferenceController.java @@ -76,6 +76,7 @@ public class ChooseAccountPreferenceController extends BasePreferenceController mProviderList = new ArrayList<>(); mTypeToAuthDescription = new HashMap<>(); + } public void initialize(String[] authorities, String[] accountTypesFilter, UserHandle userHandle, @@ -150,8 +151,9 @@ public class ChooseAccountPreferenceController extends BasePreferenceController } } } - if (addAccountPref && mAccountTypesFilter != null - && !mAccountTypesFilter.contains(accountType)) { + if (addAccountPref && ((mAccountTypesFilter != null + && !mAccountTypesFilter.contains(accountType)) + || AccountAddressBookHelper.isAccountAddressBookType(accountType))) { addAccountPref = false; } if (addAccountPref) {