aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitri Plotnikov <dplotnikov@google.com>2010-10-14 14:17:18 -0700
committerDmitri Plotnikov <dplotnikov@google.com>2010-10-14 14:17:18 -0700
commit093b6446d0c63b8d725324ea41369b76ace153df (patch)
tree4971bb7b28fa217d208229f780ca5d2b31fb992e
parent72c7667755dfabba69a2afa479185a3ab458e948 (diff)
downloadContactsProvider-093b6446d0c63b8d725324ea41369b76ace153df.tar.gz
Fixing the trigger for aggregated presence.
Aggregated presence was not updated properly when presence was changed to NULL. Added a test that covers the specific situation. Bug: 3069107 Change-Id: I52396db7c9006e9f18ec6b7c51b22ba09c0ae480
-rw-r--r--src/com/android/providers/contacts/ContactsDatabaseHelper.java33
-rw-r--r--tests/src/com/android/providers/contacts/ContactsProvider2Test.java28
2 files changed, 45 insertions, 16 deletions
diff --git a/src/com/android/providers/contacts/ContactsDatabaseHelper.java b/src/com/android/providers/contacts/ContactsDatabaseHelper.java
index 85c6bb11..9273c5ae 100644
--- a/src/com/android/providers/contacts/ContactsDatabaseHelper.java
+++ b/src/com/android/providers/contacts/ContactsDatabaseHelper.java
@@ -627,24 +627,25 @@ import java.util.Locale;
final String replaceAggregatePresenceSql =
"INSERT OR REPLACE INTO " + Tables.AGGREGATED_PRESENCE + "("
- + AggregatedPresenceColumns.CONTACT_ID + ", "
- + StatusUpdates.PRESENCE_STATUS + ", "
- + StatusUpdates.CHAT_CAPABILITY + ")"
- + " SELECT " + PresenceColumns.CONTACT_ID + ","
- + StatusUpdates.PRESENCE_STATUS + ","
- + StatusUpdates.CHAT_CAPABILITY
+ + AggregatedPresenceColumns.CONTACT_ID + ", "
+ + StatusUpdates.PRESENCE + ", "
+ + StatusUpdates.CHAT_CAPABILITY + ")"
+ + " SELECT "
+ + PresenceColumns.CONTACT_ID + ","
+ + StatusUpdates.PRESENCE + ","
+ + StatusUpdates.CHAT_CAPABILITY
+ " FROM " + Tables.PRESENCE
+ " WHERE "
- + " (" + StatusUpdates.PRESENCE_STATUS
- + " * 10 + " + StatusUpdates.CHAT_CAPABILITY + ")"
- + " = (SELECT "
- + "MAX (" + StatusUpdates.PRESENCE_STATUS
- + " * 10 + " + StatusUpdates.CHAT_CAPABILITY + ")"
- + " FROM " + Tables.PRESENCE
- + " WHERE " + PresenceColumns.CONTACT_ID
- + "=NEW." + PresenceColumns.CONTACT_ID + ")"
- + " AND " + PresenceColumns.CONTACT_ID
- + "=NEW." + PresenceColumns.CONTACT_ID + ";";
+ + " (ifnull(" + StatusUpdates.PRESENCE + ",0) * 10 "
+ + "+ ifnull(" + StatusUpdates.CHAT_CAPABILITY + ", 0))"
+ + " = (SELECT "
+ + "MAX (ifnull(" + StatusUpdates.PRESENCE + ",0) * 10 "
+ + "+ ifnull(" + StatusUpdates.CHAT_CAPABILITY + ", 0))"
+ + " FROM " + Tables.PRESENCE
+ + " WHERE " + PresenceColumns.CONTACT_ID
+ + "=NEW." + PresenceColumns.CONTACT_ID
+ + ")"
+ + " AND " + PresenceColumns.CONTACT_ID + "=NEW." + PresenceColumns.CONTACT_ID + ";";
db.execSQL("CREATE TRIGGER " + DATABASE_PRESENCE + "." + Tables.PRESENCE + "_inserted"
+ " AFTER INSERT ON " + DATABASE_PRESENCE + "." + Tables.PRESENCE
diff --git a/tests/src/com/android/providers/contacts/ContactsProvider2Test.java b/tests/src/com/android/providers/contacts/ContactsProvider2Test.java
index 5114894f..5b404858 100644
--- a/tests/src/com/android/providers/contacts/ContactsProvider2Test.java
+++ b/tests/src/com/android/providers/contacts/ContactsProvider2Test.java
@@ -1345,6 +1345,34 @@ public class ContactsProvider2Test extends BaseContactsProvider2Test {
assertStoredValuesWithProjection(contactUri, values);
}
+ public void testStatusUpdateUpdateToNull() {
+ long rawContactId = createRawContact();
+ insertImHandle(rawContactId, Im.PROTOCOL_AIM, null, "aim");
+
+ long contactId = queryContactId(rawContactId);
+ Uri contactUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, contactId);
+
+ ContentValues values = new ContentValues();
+ Uri statusUri =
+ insertStatusUpdate(Im.PROTOCOL_AIM, null, "aim", StatusUpdates.AVAILABLE, "Available",
+ StatusUpdates.CAPABILITY_HAS_CAMERA);
+ long statusId = ContentUris.parseId(statusUri);
+
+ values.put(Contacts.CONTACT_PRESENCE, StatusUpdates.AVAILABLE);
+ values.put(Contacts.CONTACT_STATUS, "Available");
+ assertStoredValuesWithProjection(contactUri, values);
+
+ values.clear();
+ values.putNull(StatusUpdates.PRESENCE);
+ mResolver.update(StatusUpdates.CONTENT_URI, values,
+ StatusUpdates.DATA_ID + "=" + statusId, null);
+
+ values.clear();
+ values.putNull(Contacts.CONTACT_PRESENCE);
+ values.put(Contacts.CONTACT_STATUS, "Available");
+ assertStoredValuesWithProjection(contactUri, values);
+ }
+
public void testStatusUpdateWithTimestamp() {
long rawContactId = createRawContact();
insertImHandle(rawContactId, Im.PROTOCOL_AIM, null, "aim");