Don't show null account on customize contacts to display. am: 67a0639c91
am: df5f047938

Change-Id: I551ae87d58294110ee0ee3cd7416ebfa9b6190d3
diff --git a/src/com/android/contacts/common/list/CustomContactListFilterActivity.java b/src/com/android/contacts/common/list/CustomContactListFilterActivity.java
index b961b67..157d0a8 100644
--- a/src/com/android/contacts/common/list/CustomContactListFilterActivity.java
+++ b/src/com/android/contacts/common/list/CustomContactListFilterActivity.java
@@ -143,7 +143,10 @@
 
             final AccountSet accounts = new AccountSet();
 
-            final List<AccountWithDataSet> sourceAccounts = accountTypes.getAccounts(false);
+            // Don't include the null account because it doesn't support writing to
+            // ContactsContract.Settings
+            final List<AccountWithDataSet> sourceAccounts = accountTypes.getAccounts(
+                    AccountTypeManager.nonNullAccountFilter());
             final AccountDisplayInfoFactory displayableAccountFactory =
                     new AccountDisplayInfoFactory(context, sourceAccounts);
             for (AccountWithDataSet account : sourceAccounts) {
diff --git a/src/com/android/contacts/common/model/AccountTypeManager.java b/src/com/android/contacts/common/model/AccountTypeManager.java
index 274020b..4a39bea 100644
--- a/src/com/android/contacts/common/model/AccountTypeManager.java
+++ b/src/com/android/contacts/common/model/AccountTypeManager.java
@@ -61,6 +61,8 @@
 import com.android.contactsbind.ObjectFactory;
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Objects;
+import com.google.common.base.Predicate;
+import com.google.common.collect.Collections2;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
 import com.google.common.collect.Sets;
@@ -76,6 +78,8 @@
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.atomic.AtomicBoolean;
 
+import javax.annotation.Nullable;
+
 import static com.android.contacts.common.util.DeviceLocalAccountTypeFactory.Util.isLocalAccountType;
 
 /**
@@ -128,6 +132,11 @@
         }
 
         @Override
+        public List<AccountWithDataSet> getAccounts(Predicate<AccountWithDataSet> filter) {
+            return Collections.emptyList();
+        }
+
+        @Override
         public List<AccountWithDataSet> getGroupWritableAccounts() {
             return Collections.emptyList();
         }
@@ -166,6 +175,8 @@
     // TODO: Consider splitting this into getContactWritableAccounts() and getAllAccounts()
     public abstract List<AccountWithDataSet> getAccounts(boolean contactWritableOnly);
 
+    public abstract List<AccountWithDataSet> getAccounts(Predicate<AccountWithDataSet> filter);
+
     public abstract List<AccountWithDataSet> getSortedAccounts(AccountWithDataSet defaultAccount,
             boolean contactWritableOnly);
 
@@ -272,6 +283,14 @@
         return canGetAccounts && canReadContacts;
     }
 
+    public static Predicate<AccountWithDataSet> nonNullAccountFilter() {
+        return new Predicate<AccountWithDataSet>() {
+            @Override
+            public boolean apply(@Nullable AccountWithDataSet account) {
+                return account != null && account.name != null && account.type != null;
+            }
+        };
+    }
 }
 
 class AccountComparator implements Comparator<AccountWithDataSet> {
@@ -751,6 +770,11 @@
         return Lists.newArrayList(contactWritableOnly ? mContactWritableAccounts : mAccounts);
     }
 
+    @Override
+    public List<AccountWithDataSet> getAccounts(Predicate<AccountWithDataSet> filter) {
+        return new ArrayList<>(Collections2.filter(mAccounts, filter));
+    }
+
     /**
      * Return list of all known or contact writable {@link AccountWithDataSet}'s sorted by
      * {@code defaultAccount}.
diff --git a/tests/src/com/android/contacts/common/test/mocks/MockAccountTypeManager.java b/tests/src/com/android/contacts/common/test/mocks/MockAccountTypeManager.java
index f4ec238..b701b3a 100644
--- a/tests/src/com/android/contacts/common/test/mocks/MockAccountTypeManager.java
+++ b/tests/src/com/android/contacts/common/test/mocks/MockAccountTypeManager.java
@@ -23,6 +23,8 @@
 import com.android.contacts.common.model.account.AccountWithDataSet;
 import com.android.contacts.common.model.account.BaseAccountType;
 import com.google.common.base.Objects;
+import com.google.common.base.Predicate;
+import com.google.common.collect.Collections2;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
 
@@ -68,6 +70,11 @@
     }
 
     @Override
+    public List<AccountWithDataSet> getAccounts(Predicate<AccountWithDataSet> filter) {
+        return Lists.newArrayList(Collections2.filter(Arrays.asList(mAccounts), filter));
+    }
+
+    @Override
     public List<AccountWithDataSet> getSortedAccounts(AccountWithDataSet account,
             boolean writableOnly) {
         return Arrays.asList(mAccounts);