Show starred contacts from only selected groups in customized view

Bug: 31710454

Test: Manually verified
1. All starred contacts show in all contacts list;
2. No starred contacts show when no group is selected in customized
view;
3. Only starred contacts from selected groups show in customized
view.

Change-Id: I73672ea472753b5194856da2354e5c87a2549648
diff --git a/src/com/android/contacts/common/list/FavoritesAndContactsLoader.java b/src/com/android/contacts/common/list/FavoritesAndContactsLoader.java
index d1ae911..11d19c0 100644
--- a/src/com/android/contacts/common/list/FavoritesAndContactsLoader.java
+++ b/src/com/android/contacts/common/list/FavoritesAndContactsLoader.java
@@ -115,8 +115,15 @@
     }
 
     private Cursor loadFavoritesContacts() {
+        final StringBuilder selection = new StringBuilder();
+        selection.append(Contacts.STARRED + "=?");
+        final ContactListFilter filter =
+                ContactListFilterController.getInstance(getContext()).getFilter();
+        if (filter != null && filter.filterType == ContactListFilter.FILTER_TYPE_CUSTOM) {
+            selection.append(" AND ").append(Contacts.IN_VISIBLE_GROUP + "=1");
+        }
         return getContext().getContentResolver().query(
-                Contacts.CONTENT_URI, mProjection, Contacts.STARRED + "=?", new String[]{"1"},
+                Contacts.CONTENT_URI, mProjection, selection.toString(), new String[]{"1"},
                 getSortOrder());
     }
 }