When removing a subscription, it's only removed from the database. When the synchronization runs, the worker sees the calendar on the system, but not the entry in the database, and it considers it as "an old calendar", and migrates it.
This is even worse, since in the conversion from subscription to calendar properties, we don't add NAME
:
|
/** |
|
* Converts this subscription's properties to [android.content.ContentValues] that can be |
|
* passed to the calendar provider in order to create/update the local calendar. |
|
*/ |
|
fun toCalendarProperties() = contentValuesOf( |
|
Calendars._ID to id, |
|
Calendars.CALENDAR_DISPLAY_NAME to displayName, |
|
Calendars.CALENDAR_COLOR to color, |
|
Calendars.CALENDAR_ACCESS_LEVEL to Calendars.CAL_ACCESS_READ, |
|
Calendars.SYNC_EVENTS to 1 |
|
) |
So the system doesn't know the url of the subscription, and just adds them with https://invalid-url
as specified here:
|
id = calendar.id, |
|
url = Uri.parse(calendar.url ?: "https://invalid-url"), |
|
eTag = calendar.eTag, |
We should fix the Subscription
-> ContentValues
conversion with this:
/**
* Converts this subscription's properties to [android.content.ContentValues] that can be
* passed to the calendar provider in order to create/update the local calendar.
*/
fun toCalendarProperties() = contentValuesOf(
Calendars._ID to id,
Calendars.NAME to url.toString(),
Calendars.CALENDAR_DISPLAY_NAME to displayName,
Calendars.CALENDAR_COLOR to color,
Calendars.CALENDAR_ACCESS_LEVEL to Calendars.CAL_ACCESS_READ,
Calendars.SYNC_EVENTS to 1
)
Which is fixed here: 3a84525
For migration, I suggest simply removing this process from synchronization, and moving it to the callback on the database creation:
|
.addCallback(object : Callback() { |
|
override fun onCreate(db: SupportSQLiteDatabase) { |
|
super.onCreate(db) |
|
SyncWorker.run(context, onlyMigrate = true) |
|
} |
|
}) |
Since I think there are really no reasons to run migration again after the database has been created. This also gets rid of ONLY_MIGRATE
from the worker, which is a bit specific.
Depends on #133