aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJeff Sharkey <jsharkey@android.com>2009-09-26 02:15:35 -0700
committerJeff Sharkey <jsharkey@android.com>2009-09-26 05:22:46 -0700
commit1a21fa6383449df4bf0d46138a23aa02dfa235a0 (patch)
tree51d4be672fb75a62b0e09f839150275fdccc952b /src
parentd4b57da3f07bc530db69015d363c61a768a4713a (diff)
downloadContactsProvider-1a21fa6383449df4bf0d46138a23aa02dfa235a0.tar.gz
Replace delayed query parameters with transaction flags.
Callers should instead use applyBatch(), which now delays any visible updates until the transation finishes. This partially fixes http://b/2075275 This change also fixes a bug where aggregated visibility wasn't being updated correctly. Wrote new unit tests to verify correct behavior.
Diffstat (limited to 'src')
-rw-r--r--src/com/android/providers/contacts/ContactsProvider2.java63
-rw-r--r--src/com/android/providers/contacts/OpenHelper.java7
2 files changed, 27 insertions, 43 deletions
diff --git a/src/com/android/providers/contacts/ContactsProvider2.java b/src/com/android/providers/contacts/ContactsProvider2.java
index b55aeb7e..e594eb04 100644
--- a/src/com/android/providers/contacts/ContactsProvider2.java
+++ b/src/com/android/providers/contacts/ContactsProvider2.java
@@ -1502,6 +1502,8 @@ public class ContactsProvider2 extends SQLiteContentProvider implements OnAccoun
private HashSet<Long> mUpdatedRawContacts = Sets.newHashSet();
private HashMap<Long, Object> mUpdatedSyncStates = Maps.newHashMap();
+ private boolean mVisibleTouched = false;
+
private boolean mSyncToNetwork;
public ContactsProvider2() {
@@ -1814,6 +1816,10 @@ public class ContactsProvider2 extends SQLiteContentProvider implements OnAccoun
super.beforeTransactionCommit();
flushTransactionalChanges();
mContactAggregator.aggregateInTransaction(mDb);
+ if (mVisibleTouched) {
+ mVisibleTouched = false;
+ mOpenHelper.updateAllVisible();
+ }
}
private void flushTransactionalChanges() {
@@ -2219,31 +2225,6 @@ public class ContactsProvider2 extends SQLiteContentProvider implements OnAccoun
}
/**
- * Determine if the given {@link Uri} and {@link ContentValues} should
- * trigger a call to {@link OpenHelper#updateAllVisible()}, usually based on
- * query parameters like {@link Contacts#DELAY_STARRED_UPDATE} and columns
- * like {@link Groups#GROUP_VISIBLE}.
- */
- private boolean shouldUpdateAllVisible(Uri uri, ContentValues values, String visibleColumn) {
- final boolean delayUpdate = readBooleanQueryParameter(uri,
- Contacts.DELAY_STARRED_UPDATE, false);
- final boolean forceUpdate = readBooleanQueryParameter(uri,
- Contacts.FORCE_STARRED_UPDATE, false);
- final boolean touchedVisible = (values == null) ? true : values.containsKey(visibleColumn);
-
- return forceUpdate || (!delayUpdate && touchedVisible);
- }
-
- /**
- * Determine if the given {@link Uri} and {@link ContentValues} should
- * trigger a call to {@link OpenHelper#updateAllVisible()}, usually based on
- * query parameters like {@link Contacts#DELAY_STARRED_UPDATE}.
- */
- private boolean shouldUpdateAllVisible(Uri uri) {
- return shouldUpdateAllVisible(uri, null, null);
- }
-
- /**
* Inserts an item in the groups table
*/
private long insertGroup(Uri uri, ContentValues values, Account account, boolean callerIsSyncAdapter) {
@@ -2265,8 +2246,8 @@ public class ContactsProvider2 extends SQLiteContentProvider implements OnAccoun
long result = mDb.insert(Tables.GROUPS, Groups.TITLE, overriddenValues);
- if (shouldUpdateAllVisible(uri, overriddenValues, Groups.GROUP_VISIBLE)) {
- mOpenHelper.updateAllVisible();
+ if (overriddenValues.containsKey(Groups.GROUP_VISIBLE)) {
+ mVisibleTouched = true;
}
return result;
@@ -2275,9 +2256,10 @@ public class ContactsProvider2 extends SQLiteContentProvider implements OnAccoun
private long insertSettings(Uri uri, ContentValues values) {
final long id = mDb.insert(Tables.SETTINGS, null, values);
- if (shouldUpdateAllVisible(uri, values, Settings.UNGROUPED_VISIBLE)) {
- mOpenHelper.updateAllVisible();
+ if (values.containsKey(Settings.UNGROUPED_VISIBLE)) {
+ mVisibleTouched = true;
}
+
return id;
}
@@ -2573,17 +2555,13 @@ public class ContactsProvider2 extends SQLiteContentProvider implements OnAccoun
return mDb.update(Tables.GROUPS, mValues, Groups._ID + "=" + groupId, null);
}
} finally {
- if (shouldUpdateAllVisible(uri)) {
- mOpenHelper.updateAllVisible();
- }
+ mVisibleTouched = true;
}
}
private int deleteSettings(Uri uri, String selection, String[] selectionArgs) {
final int count = mDb.delete(Tables.SETTINGS, selection, selectionArgs);
- if (count > 0 && shouldUpdateAllVisible(uri)) {
- mOpenHelper.updateAllVisible();
- }
+ mVisibleTouched = true;
return count;
}
@@ -2782,18 +2760,16 @@ public class ContactsProvider2 extends SQLiteContentProvider implements OnAccoun
}
int count = mDb.update(Tables.GROUPS, updatedValues, selectionWithId, selectionArgs);
-
- // If changing visibility, then update contacts
- if (shouldUpdateAllVisible(uri, updatedValues, Groups.GROUP_VISIBLE)) {
- mOpenHelper.updateAllVisible();
+ if (updatedValues.containsKey(Groups.GROUP_VISIBLE)) {
+ mVisibleTouched = true;
}
return count;
}
private int updateSettings(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
final int count = mDb.update(Tables.SETTINGS, values, selection, selectionArgs);
- if (shouldUpdateAllVisible(uri, values, Settings.UNGROUPED_VISIBLE)) {
- mOpenHelper.updateAllVisible();
+ if (values.containsKey(Settings.UNGROUPED_VISIBLE)) {
+ mVisibleTouched = true;
}
return count;
}
@@ -4198,7 +4174,8 @@ public class ContactsProvider2 extends SQLiteContentProvider implements OnAccoun
Groups.SYNC4,
Groups.SYSTEM_ID,
Groups.NOTES,
- Groups.DELETED};
+ Groups.DELETED,
+ Groups.SHOULD_SYNC};
private static final int COLUMN_ID = 0;
private static final int COLUMN_ACCOUNT_NAME = 1;
@@ -4217,6 +4194,7 @@ public class ContactsProvider2 extends SQLiteContentProvider implements OnAccoun
private static final int COLUMN_SYSTEM_ID = 14;
private static final int COLUMN_NOTES = 15;
private static final int COLUMN_DELETED = 16;
+ private static final int COLUMN_SHOULD_SYNC = 17;
public GroupsEntityIterator(ContactsProvider2 provider, String groupIdString, Uri uri,
String selection, String[] selectionArgs, String sortOrder) {
@@ -4300,6 +4278,7 @@ public class ContactsProvider2 extends SQLiteContentProvider implements OnAccoun
groupValues.put(Groups.SYSTEM_ID, c.getString(COLUMN_SYSTEM_ID));
groupValues.put(Groups.DELETED, c.getLong(COLUMN_DELETED));
groupValues.put(Groups.NOTES, c.getString(COLUMN_NOTES));
+ groupValues.put(Groups.SHOULD_SYNC, c.getString(COLUMN_SHOULD_SYNC));
Entity group = new Entity(groupValues);
mEntityCursor.moveToNext();
diff --git a/src/com/android/providers/contacts/OpenHelper.java b/src/com/android/providers/contacts/OpenHelper.java
index 93d8d0e7..b39a3654 100644
--- a/src/com/android/providers/contacts/OpenHelper.java
+++ b/src/com/android/providers/contacts/OpenHelper.java
@@ -217,9 +217,12 @@ import java.util.HashMap;
final String ZERO_GROUP_MEMBERSHIPS = "COUNT(" + GroupsColumns.CONCRETE_ID + ")=0";
+ final String OUTER_RAW_CONTACTS = "outer_raw_contacts";
+ final String OUTER_RAW_CONTACTS_ID = OUTER_RAW_CONTACTS + "." + RawContacts._ID;
+
final String CONTACT_IS_VISIBLE =
"SELECT " +
- "(CASE WHEN " +
+ "MAX((SELECT (CASE WHEN " +
"(CASE" +
" WHEN " + RAW_CONTACT_IS_LOCAL +
" THEN 1 " +
@@ -228,6 +231,8 @@ import java.util.HashMap;
" ELSE MAX(" + Groups.GROUP_VISIBLE + ")" +
"END)=1 THEN 1 ELSE 0 END)" +
" FROM " + Tables.RAW_CONTACTS_JOIN_SETTINGS_DATA_GROUPS +
+ " WHERE " + RawContactsColumns.CONCRETE_ID + "=" + OUTER_RAW_CONTACTS_ID + "))" +
+ " FROM " + Tables.RAW_CONTACTS + " AS " + OUTER_RAW_CONTACTS +
" WHERE " + RawContacts.CONTACT_ID + "=" + ContactsColumns.CONCRETE_ID +
" GROUP BY " + RawContacts.CONTACT_ID;