mirror of
https://github.com/etesync/android
synced 2025-02-02 10:51:10 +00:00
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
This commit is contained in:
parent
97aefad0a2
commit
be833b03ee
@ -45,6 +45,8 @@ import com.etesync.syncadapter.model.Settings;
|
||||
import com.etesync.syncadapter.resource.LocalAddressBook;
|
||||
import com.etesync.syncadapter.resource.LocalCalendar;
|
||||
|
||||
import net.fortuna.ical4j.util.UidGenerator;
|
||||
|
||||
import org.apache.commons.lang3.time.DateFormatUtils;
|
||||
|
||||
import java.io.File;
|
||||
@ -70,6 +72,7 @@ import lombok.Cleanup;
|
||||
import lombok.Getter;
|
||||
import okhttp3.internal.tls.OkHostnameVerifier;
|
||||
|
||||
|
||||
public class App extends Application {
|
||||
public static final String FLAVOR_GOOGLE_PLAY = "gplay";
|
||||
|
||||
@ -92,18 +95,24 @@ public class App extends Application {
|
||||
@Getter
|
||||
private static HostnameVerifier hostnameVerifier;
|
||||
|
||||
@Getter
|
||||
private static UidGenerator uidGenerator;
|
||||
|
||||
public final static Logger log = Logger.getLogger("syncadapter");
|
||||
static {
|
||||
at.bitfire.cert4android.Constants.log = Logger.getLogger("syncadapter.cert4android");
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressLint("HardwareIds")
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
reinitCertManager();
|
||||
reinitLogger();
|
||||
StrictMode.enableDefaults();
|
||||
initPrefVersion();
|
||||
|
||||
uidGenerator = new UidGenerator(null, android.provider.Settings.Secure.getString(getContentResolver(), android.provider.Settings.Secure.ANDROID_ID));
|
||||
}
|
||||
|
||||
public void reinitCertManager() {
|
||||
|
@ -28,6 +28,7 @@ import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import at.bitfire.vcard4android.AndroidAddressBook;
|
||||
@ -101,9 +102,10 @@ public class LocalContact extends AndroidContact implements LocalResource {
|
||||
}
|
||||
}
|
||||
|
||||
public void updateFileNameAndUID(String uid) throws ContactsStorageException {
|
||||
public void prepareForUpload() throws ContactsStorageException {
|
||||
try {
|
||||
String newFileName = uid;
|
||||
final String uid = UUID.randomUUID().toString();
|
||||
final String newFileName = uid;
|
||||
|
||||
ContentValues values = new ContentValues(2);
|
||||
values.put(COLUMN_FILENAME, newFileName);
|
||||
|
@ -11,6 +11,7 @@ package com.etesync.syncadapter.resource;
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.ContentProviderOperation;
|
||||
import android.content.ContentValues;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.RemoteException;
|
||||
@ -31,6 +32,7 @@ import at.bitfire.ical4android.AndroidEventFactory;
|
||||
import at.bitfire.ical4android.CalendarStorageException;
|
||||
import at.bitfire.ical4android.Event;
|
||||
import at.bitfire.vcard4android.ContactsStorageException;
|
||||
import lombok.Cleanup;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@ -134,9 +136,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;
|
||||
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;
|
||||
|
||||
ContentValues values = new ContentValues(2);
|
||||
values.put(Events._SYNC_ID, newFileName);
|
||||
|
@ -26,6 +26,7 @@ import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import com.etesync.syncadapter.App;
|
||||
@ -100,8 +101,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);
|
||||
|
@ -25,7 +25,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;
|
||||
|
||||
}
|
||||
|
@ -14,6 +14,8 @@ import android.os.RemoteException;
|
||||
import android.provider.CalendarContract.Events;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import com.etesync.syncadapter.App;
|
||||
|
||||
import org.dmfs.provider.tasks.TaskContract.Tasks;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
@ -89,9 +91,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);
|
||||
|
@ -40,7 +40,6 @@ import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import at.bitfire.ical4android.CalendarStorageException;
|
||||
@ -428,9 +427,9 @@ abstract public class SyncManager {
|
||||
if (local.getUuid() != null) {
|
||||
continue;
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user