Show local profile with account filter on

Bug: 5155996 Set up my profile is displayed for each account
     selected,even if the profile has been set

Fixed the query.
Also fixed a bug with number of contacts not shown correctly that
I discovered during the testing.

Change-Id: Ib493fc3ba626d1607e235b1c20ee0a811b03dd85
diff --git a/src/com/android/contacts/list/DefaultContactBrowseListFragment.java b/src/com/android/contacts/list/DefaultContactBrowseListFragment.java
index 5134a1a..ca07516 100644
--- a/src/com/android/contacts/list/DefaultContactBrowseListFragment.java
+++ b/src/com/android/contacts/list/DefaultContactBrowseListFragment.java
@@ -140,11 +140,12 @@
         if (!isSearchMode() && data != null) {
             int count = data.getCount();
             if (count != 0) {
+                count -= (mUserProfileExists ? 1: 0);
                 String format = getResources().getQuantityText(
                         R.plurals.listTotalAllContacts, count).toString();
                 // Do not count the user profile in the contacts count
                 if (mUserProfileExists) {
-                    getAdapter().setContactsCount(String.format(format, count - 1));
+                    getAdapter().setContactsCount(String.format(format, count));
                 } else {
                     mCounterHeaderView.setText(String.format(format, count));
                 }
diff --git a/src/com/android/contacts/list/DefaultContactListAdapter.java b/src/com/android/contacts/list/DefaultContactListAdapter.java
index 89de966..bb49027 100644
--- a/src/com/android/contacts/list/DefaultContactListAdapter.java
+++ b/src/com/android/contacts/list/DefaultContactListAdapter.java
@@ -192,16 +192,16 @@
                                 + "SELECT DISTINCT " + RawContacts.CONTACT_ID
                                 + " FROM raw_contacts"
                                 + " WHERE " + RawContacts.ACCOUNT_TYPE + "=?"
-                                + " AND " + RawContacts.ACCOUNT_NAME + "=?"
-                                + " OR " + Contacts.IS_USER_PROFILE + "=1");
+                                + " AND " + RawContacts.ACCOUNT_NAME + "=?");
                 selectionArgs.add(filter.accountType);
                 selectionArgs.add(filter.accountName);
                 if (filter.dataSet != null) {
-                    selection.append(" AND " + RawContacts.DATA_SET + "=?)");
+                    selection.append(" AND " + RawContacts.DATA_SET + "=?");
                     selectionArgs.add(filter.dataSet);
                 } else {
-                    selection.append(" AND " + RawContacts.DATA_SET + " IS NULL)");
+                    selection.append(" AND " + RawContacts.DATA_SET + " IS NULL");
                 }
+                selection.append(" OR " + Contacts.IS_USER_PROFILE + "=1)");
                 break;
             }
             case ContactListFilter.FILTER_TYPE_GROUP: {