Loading src/com/android/calendar/CalendarEventModel.java +6 −6 Original line number Diff line number Diff line Loading @@ -61,7 +61,7 @@ public class CalendarEventModel implements Serializable { public String mCalendarAllowedAttendeeTypes; public String mCalendarAllowedAvailability; public String mSyncId = null; public String mSyncAccount = null; public String mSyncAccountName = null; public String mSyncAccountType = null; public EventColorCache mEventColorCache; // PROVIDER_NOTES owner account comes from the calendars table Loading Loading @@ -232,7 +232,7 @@ public class CalendarEventModel implements Serializable { mEventColorInitialized = false; mSyncId = null; mSyncAccount = null; mSyncAccountName = null; mSyncAccountType = null; mOwnerAccount = null; Loading Loading @@ -349,7 +349,7 @@ public class CalendarEventModel implements Serializable { result = prime * result + mSelfAttendeeStatus; result = prime * result + mOwnerAttendeeId; result = prime * result + (int) (mStart ^ (mStart >>> 32)); result = prime * result + ((mSyncAccount == null) ? 0 : mSyncAccount.hashCode()); result = prime * result + ((mSyncAccountName == null) ? 0 : mSyncAccountName.hashCode()); result = prime * result + ((mSyncAccountType == null) ? 0 : mSyncAccountType.hashCode()); result = prime * result + ((mSyncId == null) ? 0 : mSyncId.hashCode()); result = prime * result + ((mTimezone == null) ? 0 : mTimezone.hashCode()); Loading Loading @@ -639,11 +639,11 @@ public class CalendarEventModel implements Serializable { if (mOwnerAttendeeId != originalModel.mOwnerAttendeeId) { return false; } if (mSyncAccount == null) { if (originalModel.mSyncAccount != null) { if (mSyncAccountName == null) { if (originalModel.mSyncAccountName != null) { return false; } } else if (!mSyncAccount.equals(originalModel.mSyncAccount)) { } else if (!mSyncAccountName.equals(originalModel.mSyncAccountName)) { return false; } Loading src/com/android/calendar/DeleteEventHelper.java +18 −3 Original line number Diff line number Diff line Loading @@ -34,6 +34,7 @@ import android.widget.ArrayAdapter; import android.widget.Button; import com.android.calendar.event.EditEventHelper; import com.android.calendar.persistence.CalendarRepository; import com.android.calendarcommon2.EventRecurrence; import java.util.ArrayList; Loading Loading @@ -99,7 +100,17 @@ public class DeleteEventHelper { public void onClick(DialogInterface dialog, int button) { deleteStarted(); long id = mModel.mId; // mCursor.getInt(mEventIndexId); Uri uri = ContentUris.withAppendedId(CalendarContract.Events.CONTENT_URI, id); // If this event is part of a local calendar, really remove it from the database // // "There are two versions of delete: as an app and as a sync adapter. // An app delete will set the deleted column on an event and remove all instances of that event. // A sync adapter delete will remove the event from the database and all associated data." // from https://developer.android.com/reference/android/provider/CalendarContract.Events boolean isLocal = mModel.mSyncAccountType.equals(CalendarContract.ACCOUNT_TYPE_LOCAL); Uri deleteContentUri = isLocal ? CalendarRepository.asLocalCalendarSyncAdapter(mModel.mSyncAccountName, Events.CONTENT_URI) : Events.CONTENT_URI; Uri uri = ContentUris.withAppendedId(deleteContentUri, id); mService.startDelete(mService.getNextToken(), null, uri, null, null, Utils.UNDO_DELAY); if (mCallback != null) { mCallback.run(); Loading Loading @@ -346,6 +357,10 @@ public class DeleteEventHelper { long dtstart = mModel.mStart; long id = mModel.mId; // mCursor.getInt(mEventIndexId); // See mDeleteNormalDialogListener for more info on this boolean isLocal = mModel.mSyncAccountType.equals(CalendarContract.ACCOUNT_TYPE_LOCAL); Uri deleteContentUri = isLocal ? CalendarRepository.asLocalCalendarSyncAdapter(mModel.mSyncAccountName, Events.CONTENT_URI) : Events.CONTENT_URI; switch (which) { case DELETE_SELECTED: { // If we are deleting the first event in the series, then Loading Loading @@ -382,7 +397,7 @@ public class DeleteEventHelper { break; } case DELETE_ALL: { Uri uri = ContentUris.withAppendedId(CalendarContract.Events.CONTENT_URI, id); Uri uri = ContentUris.withAppendedId(deleteContentUri, id); mService.startDelete(mService.getNextToken(), null, uri, null, null, Utils.UNDO_DELAY); break; Loading @@ -391,7 +406,7 @@ public class DeleteEventHelper { // If we are deleting the first event in the series and all // following events, then delete them all. if (dtstart == mStartMillis) { Uri uri = ContentUris.withAppendedId(CalendarContract.Events.CONTENT_URI, id); Uri uri = ContentUris.withAppendedId(deleteContentUri, id); mService.startDelete(mService.getNextToken(), null, uri, null, null, Utils.UNDO_DELAY); break; Loading src/com/android/calendar/event/EditEventHelper.java +7 −1 Original line number Diff line number Diff line Loading @@ -90,7 +90,9 @@ public class EditEventHelper { Events.STATUS, // 21 Events.CALENDAR_COLOR, // 22 Events.EVENT_COLOR, // 23 Events.EVENT_COLOR_KEY // 24 Events.EVENT_COLOR_KEY, // 24 Events.ACCOUNT_NAME, // 25 Events.ACCOUNT_TYPE // 26 }; protected static final int EVENT_INDEX_ID = 0; protected static final int EVENT_INDEX_TITLE = 1; Loading @@ -117,6 +119,8 @@ public class EditEventHelper { protected static final int EVENT_INDEX_CALENDAR_COLOR = 22; protected static final int EVENT_INDEX_EVENT_COLOR = 23; protected static final int EVENT_INDEX_EVENT_COLOR_KEY = 24; protected static final int EVENT_INDEX_ACCOUNT_NAME = 25; protected static final int EVENT_INDEX_ACCOUNT_TYPE = 26; public static final String[] REMINDERS_PROJECTION = new String[] { Reminders._ID, // 0 Loading Loading @@ -1065,6 +1069,8 @@ public class EditEventHelper { String rRule = cursor.getString(EVENT_INDEX_RRULE); model.mRrule = rRule; model.mSyncId = cursor.getString(EVENT_INDEX_SYNC_ID); model.mSyncAccountName = cursor.getString(EVENT_INDEX_ACCOUNT_NAME); model.mSyncAccountType = cursor.getString(EVENT_INDEX_ACCOUNT_TYPE); model.mAvailability = cursor.getInt(EVENT_INDEX_AVAILABILITY); int accessLevel = cursor.getInt(EVENT_INDEX_ACCESS_LEVEL); model.mOwnerAccount = cursor.getString(EVENT_INDEX_OWNER_ACCOUNT); Loading src/com/android/calendar/persistence/CalendarRepository.kt +14 −13 Original line number Diff line number Diff line Loading @@ -104,16 +104,6 @@ internal class CalendarRepository(val application: Application) { } } /** * Operations only work if they are made "under" the correct account */ private fun buildLocalCalendarUri(accountName: String, uri: Uri): Uri { return uri.buildUpon() .appendQueryParameter(CalendarContract.CALLER_IS_SYNCADAPTER, "true") .appendQueryParameter(CalendarContract.Calendars.ACCOUNT_NAME, accountName) .appendQueryParameter(CalendarContract.Calendars.ACCOUNT_TYPE, CalendarContract.ACCOUNT_TYPE_LOCAL).build() } private fun buildLocalCalendarContentValues(accountName: String, displayName: String): ContentValues { val internalName = "etar_local_" + displayName.replace("[^a-zA-Z0-9]".toRegex(), "") return ContentValues().apply { Loading Loading @@ -149,7 +139,7 @@ internal class CalendarRepository(val application: Application) { maybeAddCalendarAndEventColors(accountName) val cv = buildLocalCalendarContentValues(accountName, displayName) return contentResolver.insert(buildLocalCalendarUri(accountName, CalendarContract.Calendars.CONTENT_URI), cv) return contentResolver.insert(asLocalCalendarSyncAdapter(accountName, CalendarContract.Calendars.CONTENT_URI), cv) ?: throw IllegalArgumentException() } Loading @@ -168,7 +158,7 @@ internal class CalendarRepository(val application: Application) { insertBulk.add(colorCvCalendar) insertBulk.add(colorCvEvent) } contentResolver.bulkInsert(buildLocalCalendarUri(accountName, CalendarContract.Colors.CONTENT_URI), insertBulk.toTypedArray()) contentResolver.bulkInsert(asLocalCalendarSyncAdapter(accountName, CalendarContract.Colors.CONTENT_URI), insertBulk.toTypedArray()) } private fun areCalendarColorsExisting(accountName: String): Boolean { Loading @@ -188,7 +178,7 @@ internal class CalendarRepository(val application: Application) { * @return true iff exactly one row is deleted */ fun deleteLocalCalendar(accountName: String, id: Long): Boolean { val calUri = ContentUris.withAppendedId(buildLocalCalendarUri(accountName, CalendarContract.Calendars.CONTENT_URI), id) val calUri = ContentUris.withAppendedId(asLocalCalendarSyncAdapter(accountName, CalendarContract.Calendars.CONTENT_URI), id) return contentResolver.delete(calUri, null, null) == 1 } Loading @@ -213,6 +203,17 @@ internal class CalendarRepository(val application: Application) { const val ACCOUNT_INDEX_TYPE = 1 const val DEFAULT_COLOR_KEY = "1" /** * Operations only work if they are made "under" the correct account */ @JvmStatic fun asLocalCalendarSyncAdapter(accountName: String, uri: Uri): Uri { return uri.buildUpon() .appendQueryParameter(CalendarContract.CALLER_IS_SYNCADAPTER, "true") .appendQueryParameter(CalendarContract.Calendars.ACCOUNT_NAME, accountName) .appendQueryParameter(CalendarContract.Calendars.ACCOUNT_TYPE, CalendarContract.ACCOUNT_TYPE_LOCAL).build() } } } No newline at end of file Loading
src/com/android/calendar/CalendarEventModel.java +6 −6 Original line number Diff line number Diff line Loading @@ -61,7 +61,7 @@ public class CalendarEventModel implements Serializable { public String mCalendarAllowedAttendeeTypes; public String mCalendarAllowedAvailability; public String mSyncId = null; public String mSyncAccount = null; public String mSyncAccountName = null; public String mSyncAccountType = null; public EventColorCache mEventColorCache; // PROVIDER_NOTES owner account comes from the calendars table Loading Loading @@ -232,7 +232,7 @@ public class CalendarEventModel implements Serializable { mEventColorInitialized = false; mSyncId = null; mSyncAccount = null; mSyncAccountName = null; mSyncAccountType = null; mOwnerAccount = null; Loading Loading @@ -349,7 +349,7 @@ public class CalendarEventModel implements Serializable { result = prime * result + mSelfAttendeeStatus; result = prime * result + mOwnerAttendeeId; result = prime * result + (int) (mStart ^ (mStart >>> 32)); result = prime * result + ((mSyncAccount == null) ? 0 : mSyncAccount.hashCode()); result = prime * result + ((mSyncAccountName == null) ? 0 : mSyncAccountName.hashCode()); result = prime * result + ((mSyncAccountType == null) ? 0 : mSyncAccountType.hashCode()); result = prime * result + ((mSyncId == null) ? 0 : mSyncId.hashCode()); result = prime * result + ((mTimezone == null) ? 0 : mTimezone.hashCode()); Loading Loading @@ -639,11 +639,11 @@ public class CalendarEventModel implements Serializable { if (mOwnerAttendeeId != originalModel.mOwnerAttendeeId) { return false; } if (mSyncAccount == null) { if (originalModel.mSyncAccount != null) { if (mSyncAccountName == null) { if (originalModel.mSyncAccountName != null) { return false; } } else if (!mSyncAccount.equals(originalModel.mSyncAccount)) { } else if (!mSyncAccountName.equals(originalModel.mSyncAccountName)) { return false; } Loading
src/com/android/calendar/DeleteEventHelper.java +18 −3 Original line number Diff line number Diff line Loading @@ -34,6 +34,7 @@ import android.widget.ArrayAdapter; import android.widget.Button; import com.android.calendar.event.EditEventHelper; import com.android.calendar.persistence.CalendarRepository; import com.android.calendarcommon2.EventRecurrence; import java.util.ArrayList; Loading Loading @@ -99,7 +100,17 @@ public class DeleteEventHelper { public void onClick(DialogInterface dialog, int button) { deleteStarted(); long id = mModel.mId; // mCursor.getInt(mEventIndexId); Uri uri = ContentUris.withAppendedId(CalendarContract.Events.CONTENT_URI, id); // If this event is part of a local calendar, really remove it from the database // // "There are two versions of delete: as an app and as a sync adapter. // An app delete will set the deleted column on an event and remove all instances of that event. // A sync adapter delete will remove the event from the database and all associated data." // from https://developer.android.com/reference/android/provider/CalendarContract.Events boolean isLocal = mModel.mSyncAccountType.equals(CalendarContract.ACCOUNT_TYPE_LOCAL); Uri deleteContentUri = isLocal ? CalendarRepository.asLocalCalendarSyncAdapter(mModel.mSyncAccountName, Events.CONTENT_URI) : Events.CONTENT_URI; Uri uri = ContentUris.withAppendedId(deleteContentUri, id); mService.startDelete(mService.getNextToken(), null, uri, null, null, Utils.UNDO_DELAY); if (mCallback != null) { mCallback.run(); Loading Loading @@ -346,6 +357,10 @@ public class DeleteEventHelper { long dtstart = mModel.mStart; long id = mModel.mId; // mCursor.getInt(mEventIndexId); // See mDeleteNormalDialogListener for more info on this boolean isLocal = mModel.mSyncAccountType.equals(CalendarContract.ACCOUNT_TYPE_LOCAL); Uri deleteContentUri = isLocal ? CalendarRepository.asLocalCalendarSyncAdapter(mModel.mSyncAccountName, Events.CONTENT_URI) : Events.CONTENT_URI; switch (which) { case DELETE_SELECTED: { // If we are deleting the first event in the series, then Loading Loading @@ -382,7 +397,7 @@ public class DeleteEventHelper { break; } case DELETE_ALL: { Uri uri = ContentUris.withAppendedId(CalendarContract.Events.CONTENT_URI, id); Uri uri = ContentUris.withAppendedId(deleteContentUri, id); mService.startDelete(mService.getNextToken(), null, uri, null, null, Utils.UNDO_DELAY); break; Loading @@ -391,7 +406,7 @@ public class DeleteEventHelper { // If we are deleting the first event in the series and all // following events, then delete them all. if (dtstart == mStartMillis) { Uri uri = ContentUris.withAppendedId(CalendarContract.Events.CONTENT_URI, id); Uri uri = ContentUris.withAppendedId(deleteContentUri, id); mService.startDelete(mService.getNextToken(), null, uri, null, null, Utils.UNDO_DELAY); break; Loading
src/com/android/calendar/event/EditEventHelper.java +7 −1 Original line number Diff line number Diff line Loading @@ -90,7 +90,9 @@ public class EditEventHelper { Events.STATUS, // 21 Events.CALENDAR_COLOR, // 22 Events.EVENT_COLOR, // 23 Events.EVENT_COLOR_KEY // 24 Events.EVENT_COLOR_KEY, // 24 Events.ACCOUNT_NAME, // 25 Events.ACCOUNT_TYPE // 26 }; protected static final int EVENT_INDEX_ID = 0; protected static final int EVENT_INDEX_TITLE = 1; Loading @@ -117,6 +119,8 @@ public class EditEventHelper { protected static final int EVENT_INDEX_CALENDAR_COLOR = 22; protected static final int EVENT_INDEX_EVENT_COLOR = 23; protected static final int EVENT_INDEX_EVENT_COLOR_KEY = 24; protected static final int EVENT_INDEX_ACCOUNT_NAME = 25; protected static final int EVENT_INDEX_ACCOUNT_TYPE = 26; public static final String[] REMINDERS_PROJECTION = new String[] { Reminders._ID, // 0 Loading Loading @@ -1065,6 +1069,8 @@ public class EditEventHelper { String rRule = cursor.getString(EVENT_INDEX_RRULE); model.mRrule = rRule; model.mSyncId = cursor.getString(EVENT_INDEX_SYNC_ID); model.mSyncAccountName = cursor.getString(EVENT_INDEX_ACCOUNT_NAME); model.mSyncAccountType = cursor.getString(EVENT_INDEX_ACCOUNT_TYPE); model.mAvailability = cursor.getInt(EVENT_INDEX_AVAILABILITY); int accessLevel = cursor.getInt(EVENT_INDEX_ACCESS_LEVEL); model.mOwnerAccount = cursor.getString(EVENT_INDEX_OWNER_ACCOUNT); Loading
src/com/android/calendar/persistence/CalendarRepository.kt +14 −13 Original line number Diff line number Diff line Loading @@ -104,16 +104,6 @@ internal class CalendarRepository(val application: Application) { } } /** * Operations only work if they are made "under" the correct account */ private fun buildLocalCalendarUri(accountName: String, uri: Uri): Uri { return uri.buildUpon() .appendQueryParameter(CalendarContract.CALLER_IS_SYNCADAPTER, "true") .appendQueryParameter(CalendarContract.Calendars.ACCOUNT_NAME, accountName) .appendQueryParameter(CalendarContract.Calendars.ACCOUNT_TYPE, CalendarContract.ACCOUNT_TYPE_LOCAL).build() } private fun buildLocalCalendarContentValues(accountName: String, displayName: String): ContentValues { val internalName = "etar_local_" + displayName.replace("[^a-zA-Z0-9]".toRegex(), "") return ContentValues().apply { Loading Loading @@ -149,7 +139,7 @@ internal class CalendarRepository(val application: Application) { maybeAddCalendarAndEventColors(accountName) val cv = buildLocalCalendarContentValues(accountName, displayName) return contentResolver.insert(buildLocalCalendarUri(accountName, CalendarContract.Calendars.CONTENT_URI), cv) return contentResolver.insert(asLocalCalendarSyncAdapter(accountName, CalendarContract.Calendars.CONTENT_URI), cv) ?: throw IllegalArgumentException() } Loading @@ -168,7 +158,7 @@ internal class CalendarRepository(val application: Application) { insertBulk.add(colorCvCalendar) insertBulk.add(colorCvEvent) } contentResolver.bulkInsert(buildLocalCalendarUri(accountName, CalendarContract.Colors.CONTENT_URI), insertBulk.toTypedArray()) contentResolver.bulkInsert(asLocalCalendarSyncAdapter(accountName, CalendarContract.Colors.CONTENT_URI), insertBulk.toTypedArray()) } private fun areCalendarColorsExisting(accountName: String): Boolean { Loading @@ -188,7 +178,7 @@ internal class CalendarRepository(val application: Application) { * @return true iff exactly one row is deleted */ fun deleteLocalCalendar(accountName: String, id: Long): Boolean { val calUri = ContentUris.withAppendedId(buildLocalCalendarUri(accountName, CalendarContract.Calendars.CONTENT_URI), id) val calUri = ContentUris.withAppendedId(asLocalCalendarSyncAdapter(accountName, CalendarContract.Calendars.CONTENT_URI), id) return contentResolver.delete(calUri, null, null) == 1 } Loading @@ -213,6 +203,17 @@ internal class CalendarRepository(val application: Application) { const val ACCOUNT_INDEX_TYPE = 1 const val DEFAULT_COLOR_KEY = "1" /** * Operations only work if they are made "under" the correct account */ @JvmStatic fun asLocalCalendarSyncAdapter(accountName: String, uri: Uri): Uri { return uri.buildUpon() .appendQueryParameter(CalendarContract.CALLER_IS_SYNCADAPTER, "true") .appendQueryParameter(CalendarContract.Calendars.ACCOUNT_NAME, accountName) .appendQueryParameter(CalendarContract.Calendars.ACCOUNT_TYPE, CalendarContract.ACCOUNT_TYPE_LOCAL).build() } } } No newline at end of file