summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Santoro <dsantoro@google.com>2011-09-21 14:47:59 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2011-09-21 14:47:59 -0700
commitae94a710dbc0ea239277c25986e39ba53904c5fc (patch)
tree0ff2a0890e8953f136f6ddbdc8fbcbc1533620d9
parent078f588cef389358adabc579de00747878f3c108 (diff)
parent0e21a867a572679d64d79041eb574d13665178d4 (diff)
downloadpackages_providers_ContactsProvider-ae94a710dbc0ea239277c25986e39ba53904c5fc.zip
packages_providers_ContactsProvider-ae94a710dbc0ea239277c25986e39ba53904c5fc.tar.gz
packages_providers_ContactsProvider-ae94a710dbc0ea239277c25986e39ba53904c5fc.tar.bz2
Merge "Change Settings insert conflict to do an update." into ics-factoryrom
-rw-r--r--src/com/android/providers/contacts/ContactsProvider2.java16
-rw-r--r--tests/src/com/android/providers/contacts/ContactsProvider2Test.java25
2 files changed, 25 insertions, 16 deletions
diff --git a/src/com/android/providers/contacts/ContactsProvider2.java b/src/com/android/providers/contacts/ContactsProvider2.java
index 6189240..f0aa549 100644
--- a/src/com/android/providers/contacts/ContactsProvider2.java
+++ b/src/com/android/providers/contacts/ContactsProvider2.java
@@ -3048,8 +3048,20 @@ public class ContactsProvider2 extends AbstractContactsProvider
Cursor c = queryLocal(settingsUri.build(), null, null, null, null, 0);
try {
if (c.getCount() > 0) {
- throw new SQLiteConstraintException("Can't insert a settings record with the same "
- + "account name/type/data set");
+ // If a record was found, replace it with the new values.
+ String selection = null;
+ String[] selectionArgs = null;
+ if (accountName != null && accountType != null) {
+ selection = Settings.ACCOUNT_NAME + "=? AND " + Settings.ACCOUNT_TYPE + "=?";
+ if (dataSet == null) {
+ selection += " AND " + Settings.DATA_SET + " IS NULL";
+ selectionArgs = new String[] {accountName, accountType};
+ } else {
+ selection += " AND " + Settings.DATA_SET + "=?";
+ selectionArgs = new String[] {accountName, accountType, dataSet};
+ }
+ }
+ return updateSettings(uri, values, selection, selectionArgs);
}
} finally {
c.close();
diff --git a/tests/src/com/android/providers/contacts/ContactsProvider2Test.java b/tests/src/com/android/providers/contacts/ContactsProvider2Test.java
index c37d40e..10c9e11 100644
--- a/tests/src/com/android/providers/contacts/ContactsProvider2Test.java
+++ b/tests/src/com/android/providers/contacts/ContactsProvider2Test.java
@@ -2270,20 +2270,17 @@ public class ContactsProvider2Test extends BaseContactsProvider2Test {
createSettings(account1, "0", "0");
createSettings(account2, "1", "1");
- // Now try creating the settings rows again.
- try {
- createSettings(account1, "1", "0");
- fail("Provider should have prevented inserting duplicate settings without data set.");
- } catch (SQLiteConstraintException expected) {
- // Expected.
- }
-
- try {
- createSettings(account2, "0", "1");
- fail("Provider should have prevented inserting duplicate settings with data set.");
- } catch (SQLiteConstraintException expected) {
- // Expected.
- }
+ // Now try creating the settings rows again. It should update the existing settings rows.
+ createSettings(account1, "1", "0");
+ assertStoredValue(Settings.CONTENT_URI,
+ Settings.ACCOUNT_NAME + "=? AND " + Settings.ACCOUNT_TYPE + "=?",
+ new String[] {"a", "b"}, Settings.SHOULD_SYNC, "1");
+
+ createSettings(account2, "0", "1");
+ assertStoredValue(Settings.CONTENT_URI,
+ Settings.ACCOUNT_NAME + "=? AND " + Settings.ACCOUNT_TYPE + "=? AND " +
+ Settings.DATA_SET + "=?",
+ new String[] {"c", "d", "plus"}, Settings.SHOULD_SYNC, "0");
}
public void testDisplayNameParsingWhenPartsUnspecified() {