From f9d845c1b74d1e31db4796cbdb0ad05c0da0068e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20D=C3=A9camps?= Date: Wed, 6 Aug 2014 13:22:50 +0200 Subject: [PATCH] Fix `getAllAmAccounts()` returning duplicated accounts Use a set to save the account types, in order to de-duplicate identical types. Also, remove unused imports. Bug: 16811863 Duplicate POP accounts are listed Change-Id: If699d03b2c12959cfde9926bec9352b71c3d8912 --- .../email/provider/AccountReconciler.java | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/com/android/email/provider/AccountReconciler.java b/src/com/android/email/provider/AccountReconciler.java index 9f604dbab..26f303fc2 100644 --- a/src/com/android/email/provider/AccountReconciler.java +++ b/src/com/android/email/provider/AccountReconciler.java @@ -31,13 +31,9 @@ import android.text.TextUtils; import com.android.email.NotificationController; import com.android.email.R; -import com.android.email.activity.ComposeActivityEmail; -import com.android.email.service.EasAuthenticatorService; -import com.android.email.service.EasAuthenticatorServiceAlternate; import com.android.email.service.EmailServiceUtils; import com.android.email.service.EmailServiceUtils.EmailServiceInfo; import com.android.emailcommon.Logging; -import com.android.emailcommon.VendorPolicyLoader; import com.android.emailcommon.provider.Account; import com.android.emailcommon.provider.HostAuth; import com.android.mail.utils.LogUtils; @@ -46,6 +42,7 @@ import com.google.common.collect.ImmutableList; import java.io.IOException; import java.util.Arrays; import java.util.Collections; +import java.util.LinkedHashSet; import java.util.List; public class AccountReconciler { @@ -56,14 +53,19 @@ public class AccountReconciler { */ private static List getAllAmAccounts(final Context context) { final AccountManager am = AccountManager.get(context); - final ImmutableList.Builder builder = ImmutableList.builder(); + // TODO: Consider getting the types programmatically, in case we add more types. - builder.addAll(Arrays.asList(am.getAccountsByType( - context.getString(R.string.account_manager_type_legacy_imap)))); - builder.addAll(Arrays.asList(am.getAccountsByType( - context.getString(R.string.account_manager_type_pop3)))); - builder.addAll(Arrays.asList(am.getAccountsByType( - context.getString(R.string.account_manager_type_exchange)))); + // Some Accounts types can be identical, the set de-duplicates. + final LinkedHashSet accountTypes = new LinkedHashSet(); + accountTypes.add(context.getString(R.string.account_manager_type_legacy_imap)); + accountTypes.add(context.getString(R.string.account_manager_type_pop3)); + accountTypes.add(context.getString(R.string.account_manager_type_exchange)); + + final ImmutableList.Builder builder = ImmutableList.builder(); + for (final String type : accountTypes) { + final android.accounts.Account[] accounts = am.getAccountsByType(type); + builder.add(accounts); + } return builder.build(); }