Commit 47639c45 authored by Ricki Hirner's avatar Ricki Hirner 🐑

Retain Events.UID_2445 when preparing events for upload

* move file name/UID generation from SyncManager to LocalContact, LocalEvent, LocalTask
* rename updateFileNameAndUID() to prepareForUpload()
* use random UUID for contacts, UidGenerator with Android device ID for events/tasks
* LocalEvent.prepareForUpload(): use existing UID_2445 if available
parent 6dd31063
Pipeline #6409951 passed with stage
in 16 minutes and 35 seconds
......@@ -8,6 +8,7 @@
package at.bitfire.davdroid;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Application;
import android.content.BroadcastReceiver;
......@@ -24,6 +25,8 @@ import android.support.v4.app.NotificationManagerCompat;
import android.support.v7.app.NotificationCompat;
import android.util.Log;
import net.fortuna.ical4j.util.UidGenerator;
import org.apache.commons.lang3.time.DateFormatUtils;
import java.io.File;
......@@ -66,6 +69,9 @@ public class App extends Application {
@Getter
private static HostnameVerifier hostnameVerifier;
@Getter
private static UidGenerator uidGenerator;
public final static Logger log = Logger.getLogger("davdroid");
static {
at.bitfire.dav4android.Constants.log = Logger.getLogger("davdroid.dav4android");
......@@ -73,10 +79,13 @@ public class App extends Application {
}
@Override
@SuppressLint("HardwareIds")
public void onCreate() {
super.onCreate();
reinitCertManager();
reinitLogger();
uidGenerator = new UidGenerator(null, android.provider.Settings.Secure.getString(getContentResolver(), android.provider.Settings.Secure.ANDROID_ID));
}
public void reinitCertManager() {
......
......@@ -11,7 +11,6 @@ package at.bitfire.davdroid.resource;
import android.content.ContentProviderOperation;
import android.content.ContentValues;
import android.database.Cursor;
import android.net.Uri;
import android.os.Build;
import android.os.RemoteException;
import android.provider.ContactsContract;
......@@ -22,6 +21,7 @@ import android.support.annotation.NonNull;
import java.io.FileNotFoundException;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import at.bitfire.davdroid.App;
import at.bitfire.davdroid.BuildConfig;
......@@ -86,9 +86,10 @@ public class LocalContact extends AndroidContact implements LocalResource {
}
}
public void updateFileNameAndUID(String uid) throws ContactsStorageException {
public void prepareForUpload() throws ContactsStorageException {
try {
String newFileName = uid + ".vcf";
final String uid = UUID.randomUUID().toString();
final String newFileName = uid + ".vcf";
ContentValues values = new ContentValues(2);
values.put(COLUMN_FILENAME, newFileName);
......
......@@ -11,6 +11,7 @@ package at.bitfire.davdroid.resource;
import android.annotation.TargetApi;
import android.content.ContentProviderOperation;
import android.content.ContentValues;
import android.database.Cursor;
import android.os.Build;
import android.os.RemoteException;
import android.provider.CalendarContract;
......@@ -19,12 +20,14 @@ import android.support.annotation.NonNull;
import net.fortuna.ical4j.model.property.ProdId;
import at.bitfire.davdroid.App;
import at.bitfire.davdroid.BuildConfig;
import at.bitfire.ical4android.AndroidCalendar;
import at.bitfire.ical4android.AndroidEvent;
import at.bitfire.ical4android.AndroidEventFactory;
import at.bitfire.ical4android.CalendarStorageException;
import at.bitfire.ical4android.Event;
import lombok.Cleanup;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
......@@ -100,9 +103,16 @@ public class LocalEvent extends AndroidEvent implements LocalResource {
/* custom queries */
public void updateFileNameAndUID(String uid) throws CalendarStorageException {
public void prepareForUpload() throws CalendarStorageException {
try {
String newFileName = uid + ".ics";
String uid = null;
@Cleanup Cursor c = calendar.provider.query(eventSyncURI(), new String[] { Events.UID_2445 }, null, null, null);
if (c.moveToNext())
uid = c.getString(0);
if (uid == null)
uid = App.getUidGenerator().generateUid().getValue();
final String newFileName = uid + ".ics";
ContentValues values = new ContentValues(2);
values.put(Events._SYNC_ID, newFileName);
......
......@@ -25,6 +25,7 @@ import org.apache.commons.lang3.ArrayUtils;
import java.io.FileNotFoundException;
import java.util.LinkedList;
import java.util.List;
import java.util.UUID;
import java.util.logging.Level;
import at.bitfire.dav4android.Constants;
......@@ -87,8 +88,9 @@ public class LocalGroup extends AndroidGroup implements LocalResource {
}
@Override
public void updateFileNameAndUID(String uid) throws ContactsStorageException {
String newFileName = uid + ".vcf";
public void prepareForUpload() throws ContactsStorageException {
final String uid = UUID.randomUUID().toString();
final String newFileName = uid + ".vcf";
ContentValues values = new ContentValues(2);
values.put(COLUMN_FILENAME, newFileName);
......
......@@ -20,7 +20,7 @@ public interface LocalResource {
int delete() throws CalendarStorageException, ContactsStorageException;
void updateFileNameAndUID(String uuid) throws CalendarStorageException, ContactsStorageException;
void prepareForUpload() throws CalendarStorageException, ContactsStorageException;
void clearDirty(String eTag) throws CalendarStorageException, ContactsStorageException;
}
......@@ -21,6 +21,7 @@ import org.dmfs.provider.tasks.TaskContract.Tasks;
import java.io.FileNotFoundException;
import java.text.ParseException;
import at.bitfire.davdroid.App;
import at.bitfire.davdroid.BuildConfig;
import at.bitfire.ical4android.AndroidTask;
import at.bitfire.ical4android.AndroidTaskFactory;
......@@ -84,9 +85,10 @@ public class LocalTask extends AndroidTask implements LocalResource {
/* custom queries */
public void updateFileNameAndUID(String uid) throws CalendarStorageException {
public void prepareForUpload() throws CalendarStorageException {
try {
String newFileName = uid + ".ics";
final String uid = App.getUidGenerator().generateUid().getValue();
final String newFileName = uid + ".ics";
ContentValues values = new ContentValues(2);
values.put(Tasks._SYNC_ID, newFileName);
......
......@@ -26,7 +26,6 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.logging.Level;
import at.bitfire.dav4android.DavResource;
......@@ -309,9 +308,8 @@ abstract public class SyncManager {
for (final LocalResource local : localCollection.getWithoutFileName()) {
currentLocalResource = local;
String uuid = UUID.randomUUID().toString();
App.log.fine("Found local record #" + local.getId() + " without file name; assigning file name/UID based on " + uuid);
local.updateFileNameAndUID(uuid);
App.log.fine("Found local record #" + local.getId() + " without file name; generating file name/UID if necessary");
local.prepareForUpload();
currentLocalResource = null;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment