Remove SUMMARY_GROUP_COUNT_PER_ACCOUNT support (for now)
This sub-query needs to be rewritten for the upcoming accounts
refactoring, but since it's @hide'ed and no one is using it, let's
just remove it for now.
I believe this count can be implemented efficiently using a join
(in a similar way we support SUMMARY_COUNT) rather than a subquery, but
this should be even easier after the refactoring.
Also when we re-implement this, we can just check if the projection
contains SUMMARY_GROUP_COUNT_PER_ACCOUNT, so we'll probably be able to
remove PARAM_RETURN_GROUP_COUNT_PER_ACCOUNT.
Change-Id: I3adc93cdf57280ab06b4a2cab77f834811178af8
diff --git a/src/com/android/providers/contacts/ContactsProvider2.java b/src/com/android/providers/contacts/ContactsProvider2.java
index 5ae434b..a7b59d6 100644
--- a/src/com/android/providers/contacts/ContactsProvider2.java
+++ b/src/com/android/providers/contacts/ContactsProvider2.java
@@ -890,6 +890,8 @@
* Note {@link Groups#SUMMARY_COUNT} doesn't exist in groups/view_groups.
* When we detect this column being requested, we join {@link Joins#GROUP_MEMBER_COUNT} to
* generate it.
+ *
+ * TODO Support SUMMARY_GROUP_COUNT_PER_ACCOUNT too. See also queryLocal().
*/
private static final ProjectionMap sGroupsSummaryProjectionMap = ProjectionMap.builder()
.addAll(sGroupsProjectionMap)
@@ -898,27 +900,7 @@
"(SELECT COUNT(" + ContactsColumns.CONCRETE_ID + ") FROM "
+ Tables.CONTACTS_JOIN_RAW_CONTACTS_DATA_FILTERED_BY_GROUPMEMBERSHIP
+ " WHERE " + Contacts.HAS_PHONE_NUMBER + ")")
- .build();
-
- // This is only exposed as hidden API for the contacts app, so we can be very specific in
- // the filtering
- private static final ProjectionMap sGroupsSummaryProjectionMapWithGroupCountPerAccount =
- ProjectionMap.builder()
- .addAll(sGroupsSummaryProjectionMap)
- .add(Groups.SUMMARY_GROUP_COUNT_PER_ACCOUNT,
- "(SELECT COUNT(*) FROM " + Views.GROUPS + " WHERE "
- + "(" + Groups.ACCOUNT_NAME + "="
- + GroupsColumns.CONCRETE_ACCOUNT_NAME
- + " AND "
- + Groups.ACCOUNT_TYPE + "=" + GroupsColumns.CONCRETE_ACCOUNT_TYPE
- + " AND "
- + Groups.DELETED + "=0 AND "
- + Groups.FAVORITES + "=0 AND "
- + Groups.AUTO_ADD + "=0"
- + ")"
- + " GROUP BY "
- + Groups.ACCOUNT_NAME + ", " + Groups.ACCOUNT_TYPE
- + ")")
+ .add(Groups.SUMMARY_GROUP_COUNT_PER_ACCOUNT, "0") // Always returns 0 for now.
.build();
/** Contains the agg_exceptions columns */
@@ -5842,17 +5824,18 @@
}
case GROUPS_SUMMARY: {
- final boolean returnGroupCountPerAccount =
- readBooleanQueryParameter(uri, Groups.PARAM_RETURN_GROUP_COUNT_PER_ACCOUNT,
- false);
String tables = Views.GROUPS + " AS " + Tables.GROUPS;
if (ContactsDatabaseHelper.isInProjection(projection, Groups.SUMMARY_COUNT)) {
tables = tables + Joins.GROUP_MEMBER_COUNT;
}
+ if (ContactsDatabaseHelper.isInProjection(projection,
+ Groups.SUMMARY_GROUP_COUNT_PER_ACCOUNT)) {
+ // TODO Add join for this column too (and update the projection map)
+ // TODO Also remove Groups.PARAM_RETURN_GROUP_COUNT_PER_ACCOUNT when it works.
+ Log.w(TAG, Groups.SUMMARY_GROUP_COUNT_PER_ACCOUNT + " is not supported yet");
+ }
qb.setTables(tables);
- qb.setProjectionMap(returnGroupCountPerAccount ?
- sGroupsSummaryProjectionMapWithGroupCountPerAccount
- : sGroupsSummaryProjectionMap);
+ qb.setProjectionMap(sGroupsSummaryProjectionMap);
appendAccountFromParameter(qb, uri);
groupBy = GroupsColumns.CONCRETE_ID;
break;
diff --git a/tests/src/com/android/providers/contacts/ContactsProvider2Test.java b/tests/src/com/android/providers/contacts/ContactsProvider2Test.java
index 599f1e7..ef8d995 100644
--- a/tests/src/com/android/providers/contacts/ContactsProvider2Test.java
+++ b/tests/src/com/android/providers/contacts/ContactsProvider2Test.java
@@ -558,6 +558,7 @@
Groups.SYNC4,
Groups.SUMMARY_COUNT,
Groups.SUMMARY_WITH_PHONES,
+ Groups.SUMMARY_GROUP_COUNT_PER_ACCOUNT,
});
}
@@ -2316,19 +2317,29 @@
assertStoredValues(Groups.CONTENT_SUMMARY_URI, new ContentValues[] { v1, v2, v3 });
- final Uri uri = Groups.CONTENT_SUMMARY_URI.buildUpon()
- .appendQueryParameter(Groups.PARAM_RETURN_GROUP_COUNT_PER_ACCOUNT, "true")
- .build();
- v1.put(Groups.SUMMARY_GROUP_COUNT_PER_ACCOUNT, 1);
- v2.put(Groups.SUMMARY_GROUP_COUNT_PER_ACCOUNT, 2);
- v3.put(Groups.SUMMARY_GROUP_COUNT_PER_ACCOUNT, 2);
+ final Uri uri = Groups.CONTENT_SUMMARY_URI;
+
+ // TODO Once SUMMARY_GROUP_COUNT_PER_ACCOUNT is supported remove all the if(false).
+ if (false) {
+ v1.put(Groups.SUMMARY_GROUP_COUNT_PER_ACCOUNT, 1);
+ v2.put(Groups.SUMMARY_GROUP_COUNT_PER_ACCOUNT, 2);
+ v3.put(Groups.SUMMARY_GROUP_COUNT_PER_ACCOUNT, 2);
+ } else {
+ v1.put(Groups.SUMMARY_GROUP_COUNT_PER_ACCOUNT, 0);
+ v2.put(Groups.SUMMARY_GROUP_COUNT_PER_ACCOUNT, 0);
+ v3.put(Groups.SUMMARY_GROUP_COUNT_PER_ACCOUNT, 0);
+ }
assertStoredValues(uri, new ContentValues[] { v1, v2, v3 });
// Introduce another group in account1, testing SUMMARY_GROUP_COUNT_PER_ACCOUNT correctly
// reflects the change.
final long groupId4 = createGroup(account1, "sourceId4", "title4");
- v1.put(Groups.SUMMARY_GROUP_COUNT_PER_ACCOUNT,
- v1.getAsInteger(Groups.SUMMARY_GROUP_COUNT_PER_ACCOUNT) + 1);
+ if (false) {
+ v1.put(Groups.SUMMARY_GROUP_COUNT_PER_ACCOUNT,
+ v1.getAsInteger(Groups.SUMMARY_GROUP_COUNT_PER_ACCOUNT) + 1);
+ } else {
+ v1.put(Groups.SUMMARY_GROUP_COUNT_PER_ACCOUNT, 0);
+ }
ContentValues v4 = new ContentValues();
v4.put(Groups._ID, groupId4);
v4.put(Groups.TITLE, "title4");
@@ -2337,8 +2348,12 @@
v4.put(Groups.ACCOUNT_TYPE, account1.type);
v4.put(Groups.SUMMARY_COUNT, 0);
v4.put(Groups.SUMMARY_WITH_PHONES, 0);
- v4.put(Groups.SUMMARY_GROUP_COUNT_PER_ACCOUNT,
- v1.getAsInteger(Groups.SUMMARY_GROUP_COUNT_PER_ACCOUNT));
+ if (false) {
+ v4.put(Groups.SUMMARY_GROUP_COUNT_PER_ACCOUNT,
+ v1.getAsInteger(Groups.SUMMARY_GROUP_COUNT_PER_ACCOUNT));
+ } else {
+ v4.put(Groups.SUMMARY_GROUP_COUNT_PER_ACCOUNT, 0);
+ }
assertStoredValues(uri, new ContentValues[] { v1, v2, v3, v4 });
// We change the tables dynamically according to the requested projection.