Add support for identity in attendees
Bug: 6353721
Change-Id: If167941b90b256073444f2660df2360f79872276
diff --git a/src/com/android/providers/calendar/CalendarDatabaseHelper.java b/src/com/android/providers/calendar/CalendarDatabaseHelper.java
index 7d5b8a9..9bca5d3 100644
--- a/src/com/android/providers/calendar/CalendarDatabaseHelper.java
+++ b/src/com/android/providers/calendar/CalendarDatabaseHelper.java
@@ -70,7 +70,7 @@
// 4xx for JB
// 5xx for K
// Bump this to the next hundred at each major release.
- static final int DATABASE_VERSION = 401;
+ static final int DATABASE_VERSION = 402;
private static final int PRE_FROYO_SYNC_STATE_VERSION = 3;
@@ -121,7 +121,9 @@
Attendees.ATTENDEE_EMAIL + "," +
Attendees.ATTENDEE_STATUS + "," +
Attendees.ATTENDEE_RELATIONSHIP + "," +
- Attendees.ATTENDEE_TYPE;
+ Attendees.ATTENDEE_TYPE + "," +
+ Attendees.ATTENDEE_IDENTITY + "," +
+ Attendees.ATTENDEE_ID_NAMESPACE;
// columns used to duplicate an extended property row
private static final String LAST_SYNCED_EXTENDED_PROPERTY_COLUMNS =
@@ -426,7 +428,9 @@
CalendarContract.Attendees.ATTENDEE_EMAIL + " TEXT," +
CalendarContract.Attendees.ATTENDEE_STATUS + " INTEGER," +
CalendarContract.Attendees.ATTENDEE_RELATIONSHIP + " INTEGER," +
- CalendarContract.Attendees.ATTENDEE_TYPE + " INTEGER" +
+ CalendarContract.Attendees.ATTENDEE_TYPE + " INTEGER," +
+ CalendarContract.Attendees.ATTENDEE_IDENTITY + " TEXT," +
+ CalendarContract.Attendees.ATTENDEE_ID_NAMESPACE + " TEXT" +
");");
db.execSQL("CREATE INDEX attendeesEventIdIndex ON " + Tables.ATTENDEES + " (" +
@@ -1368,6 +1372,11 @@
createEventsView = true;
oldVersion = 401;
}
+ if (oldVersion == 401) {
+ upgradeToVersion402(db);
+ createEventsView = true;
+ oldVersion = 402;
+ }
if (createEventsView) {
createEventsView(db);
}
@@ -1443,6 +1452,16 @@
/* 4xx db version is for J release
/**********************************************************/
+ @VisibleForTesting
+ void upgradeToVersion402(SQLiteDatabase db) {
+ /*
+ * Changes from version 401 to 402:
+ * - add identity and namespace to Attendees table
+ */
+ db.execSQL("ALTER TABLE Attendees ADD COLUMN attendeeIdentity TEXT;");
+ db.execSQL("ALTER TABLE Attendees ADD COLUMN attendeeIdNamespace TEXT;");
+ }
+
/*
* Changes from version 309 to 401:
* Fix repeating events' exceptions with the wrong original_id
diff --git a/src/com/android/providers/calendar/CalendarProvider2.java b/src/com/android/providers/calendar/CalendarProvider2.java
index 53b71f9..50183ea 100644
--- a/src/com/android/providers/calendar/CalendarProvider2.java
+++ b/src/com/android/providers/calendar/CalendarProvider2.java
@@ -4763,6 +4763,8 @@
sAttendeesProjectionMap.put(Attendees.ATTENDEE_STATUS, "attendeeStatus");
sAttendeesProjectionMap.put(Attendees.ATTENDEE_RELATIONSHIP, "attendeeRelationship");
sAttendeesProjectionMap.put(Attendees.ATTENDEE_TYPE, "attendeeType");
+ sAttendeesProjectionMap.put(Attendees.ATTENDEE_IDENTITY, "attendeeIdentity");
+ sAttendeesProjectionMap.put(Attendees.ATTENDEE_ID_NAMESPACE, "attendeeIdNamespace");
sAttendeesProjectionMap.put(Events.DELETED, "Events.deleted AS deleted");
sAttendeesProjectionMap.put(Events._SYNC_ID, "Events._sync_id AS _sync_id");
diff --git a/tests/AndroidManifest.xml b/tests/AndroidManifest.xml
index 22cb75b..0ce5105 100644
--- a/tests/AndroidManifest.xml
+++ b/tests/AndroidManifest.xml
@@ -4,9 +4,9 @@
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
-
+
http://www.apache.org/licenses/LICENSE-2.0
-
+
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -24,13 +24,16 @@
<uses-permission android:name="android.permission.READ_CALENDAR" />
<uses-permission android:name="android.permission.WRITE_CALENDAR" />
-
+
<!--
The test declared in this instrumentation will be run along with tests declared by
all other applications via the command: "adb shell itr".
The "itr" command will find all tests declared by all applications. If you want to run just these
tests on their own then use the command:
"adb shell am instrument -w com.android.providers.calendar.tests/android.test.InstrumentationTestRunner"
+
+ To test db upgrade:
+ adb shell am instrument -w -e class com.android.providers.calendar.CalendarDatabaseHelperTest#testSchemasEqualForAllTables com.android.providers.calendar.tests/android.test.InstrumentationTestRunner
-->
<instrumentation android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.android.providers.calendar"
diff --git a/tests/src/com/android/providers/calendar/CalendarDatabaseHelperTest.java b/tests/src/com/android/providers/calendar/CalendarDatabaseHelperTest.java
index fbd737e..9cb2e28 100644
--- a/tests/src/com/android/providers/calendar/CalendarDatabaseHelperTest.java
+++ b/tests/src/com/android/providers/calendar/CalendarDatabaseHelperTest.java
@@ -464,9 +464,21 @@
"tbl_name,sql" /* orderBy */);
while (goodCursor.moveToNext()) {
- assertTrue("Should have same number of tables", badCursor.moveToNext());
+ String goodTableName = goodCursor.getString(0);
+ // Ignore tables that do not belong to calendar
+ if (goodTableName.startsWith("sqlite_") || goodTableName.equals("android_metadata")) {
+ continue;
+ }
+
+ // Ignore tables that do not belong to calendar
+ String badTableName;
+ do {
+ assertTrue("Should have same number of tables", badCursor.moveToNext());
+ badTableName = badCursor.getString(0);
+ } while (badTableName.startsWith("sqlite_") || badTableName.equals("android_metadata"));
+
assertEquals("Table names different between upgraded schema and freshly-created scheme",
- goodCursor.getString(0), badCursor.getString(0));
+ goodTableName, badTableName);
String badString = badCursor.getString(1);
String goodString = goodCursor.getString(1);
diff --git a/tests/src/com/android/providers/calendar/CalendarProvider2Test.java b/tests/src/com/android/providers/calendar/CalendarProvider2Test.java
index 1be6069..dac3162 100644
--- a/tests/src/com/android/providers/calendar/CalendarProvider2Test.java
+++ b/tests/src/com/android/providers/calendar/CalendarProvider2Test.java
@@ -51,6 +51,7 @@
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
+import java.util.Set;
import java.util.TimeZone;
/**
@@ -1867,12 +1868,16 @@
attendee.put(CalendarContract.Attendees.ATTENDEE_RELATIONSHIP,
CalendarContract.Attendees.RELATIONSHIP_ORGANIZER);
attendee.put(CalendarContract.Attendees.EVENT_ID, eventId);
+ attendee.put(CalendarContract.Attendees.ATTENDEE_IDENTITY, "ID1");
+ attendee.put(CalendarContract.Attendees.ATTENDEE_ID_NAMESPACE, "IDNS1");
Uri attendeesUri = mResolver.insert(CalendarContract.Attendees.CONTENT_URI, attendee);
Cursor cursor = mResolver.query(CalendarContract.Attendees.CONTENT_URI, null,
"event_id=" + eventId, null, null);
assertEquals("Created event is missing - cannot find EventUri = " + eventUri, 1,
cursor.getCount());
+ Set<String> attendeeColumns = attendee.keySet();
+ verifyContentValueAgainstCursor(attendee, attendeeColumns, cursor);
cursor.close();
cursor = mResolver.query(eventUri, null, null, null, null);
@@ -1885,11 +1890,23 @@
assertEquals(CalendarContract.Attendees.ATTENDEE_STATUS_ACCEPTED, selfAttendeeStatus);
cursor.close();
- // Change status to declined
+ // Update status to declined and change identity
+ ContentValues attendeeUpdate = new ContentValues();
+ attendeeUpdate.put(CalendarContract.Attendees.ATTENDEE_IDENTITY, "ID2");
+ attendee.put(CalendarContract.Attendees.ATTENDEE_IDENTITY, "ID2");
+ attendeeUpdate.put(CalendarContract.Attendees.ATTENDEE_STATUS,
+ CalendarContract.Attendees.ATTENDEE_STATUS_DECLINED);
attendee.put(CalendarContract.Attendees.ATTENDEE_STATUS,
CalendarContract.Attendees.ATTENDEE_STATUS_DECLINED);
- mResolver.update(attendeesUri, attendee, null, null);
+ mResolver.update(attendeesUri, attendeeUpdate, null, null);
+ // Check in attendees table
+ cursor = mResolver.query(attendeesUri, null, null, null, null);
+ cursor.moveToNext();
+ verifyContentValueAgainstCursor(attendee, attendeeColumns, cursor);
+ cursor.close();
+
+ // Test that the self status in events table is updated
cursor = mResolver.query(eventUri, null, null, null, null);
cursor.moveToNext();
selfAttendeeStatus = cursor.getInt(selfColumn);
@@ -1915,6 +1932,16 @@
cursor.close();
}
+ private void verifyContentValueAgainstCursor(ContentValues cv,
+ Set<String> keys, Cursor cursor) {
+ cursor.moveToFirst();
+ for (String key : keys) {
+ assertEquals(cv.get(key).toString(),
+ cursor.getString(cursor.getColumnIndex(key)));
+ }
+ cursor.close();
+ }
+
/**
* Test the event's dirty status and clear it.
*