mirror of
https://github.com/etesync/android
synced 2025-02-16 17:42:03 +00:00
bug fixes
* avoid crashes when content providers return null cursors * ignore invalid URLs (for instance, with spaces) in WebDAV multi-status responses
This commit is contained in:
parent
5db8bcb9d8
commit
d15478b863
@ -105,9 +105,10 @@ public class LocalAddressBook extends LocalCollection<Contact> {
|
|||||||
Cursor cursor = providerClient.query(entriesURI(),
|
Cursor cursor = providerClient.query(entriesURI(),
|
||||||
new String[] { RawContacts._ID, entryColumnRemoteName(), entryColumnETag() },
|
new String[] { RawContacts._ID, entryColumnRemoteName(), entryColumnETag() },
|
||||||
entryColumnRemoteName() + "=?", new String[] { remoteName }, null);
|
entryColumnRemoteName() + "=?", new String[] { remoteName }, null);
|
||||||
if (cursor.moveToNext())
|
if (cursor != null && cursor.moveToNext())
|
||||||
return new Contact(cursor.getLong(0), cursor.getString(1), cursor.getString(2));
|
return new Contact(cursor.getLong(0), cursor.getString(1), cursor.getString(2));
|
||||||
return null;
|
else
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -118,7 +119,7 @@ public class LocalAddressBook extends LocalCollection<Contact> {
|
|||||||
|
|
||||||
Cursor cursor = providerClient.query(ContentUris.withAppendedId(entriesURI(), c.getLocalID()),
|
Cursor cursor = providerClient.query(ContentUris.withAppendedId(entriesURI(), c.getLocalID()),
|
||||||
new String[] { entryColumnUID(), RawContacts.STARRED }, null, null, null);
|
new String[] { entryColumnUID(), RawContacts.STARRED }, null, null, null);
|
||||||
if (cursor.moveToNext()) {
|
if (cursor != null && cursor.moveToNext()) {
|
||||||
c.setUid(cursor.getString(0));
|
c.setUid(cursor.getString(0));
|
||||||
c.setStarred(cursor.getInt(1) != 0);
|
c.setStarred(cursor.getInt(1) != 0);
|
||||||
}
|
}
|
||||||
@ -130,7 +131,7 @@ public class LocalAddressBook extends LocalCollection<Contact> {
|
|||||||
/* 6 */ StructuredName.PHONETIC_GIVEN_NAME, StructuredName.PHONETIC_MIDDLE_NAME, StructuredName.PHONETIC_FAMILY_NAME
|
/* 6 */ StructuredName.PHONETIC_GIVEN_NAME, StructuredName.PHONETIC_MIDDLE_NAME, StructuredName.PHONETIC_FAMILY_NAME
|
||||||
}, StructuredName.RAW_CONTACT_ID + "=? AND " + Data.MIMETYPE + "=?",
|
}, StructuredName.RAW_CONTACT_ID + "=? AND " + Data.MIMETYPE + "=?",
|
||||||
new String[] { String.valueOf(res.getLocalID()), StructuredName.CONTENT_ITEM_TYPE }, null);
|
new String[] { String.valueOf(res.getLocalID()), StructuredName.CONTENT_ITEM_TYPE }, null);
|
||||||
if (cursor.moveToNext()) {
|
if (cursor != null && cursor.moveToNext()) {
|
||||||
c.setDisplayName(cursor.getString(0));
|
c.setDisplayName(cursor.getString(0));
|
||||||
|
|
||||||
c.setPrefix(cursor.getString(1));
|
c.setPrefix(cursor.getString(1));
|
||||||
@ -149,7 +150,7 @@ public class LocalAddressBook extends LocalCollection<Contact> {
|
|||||||
Nickname.RAW_CONTACT_ID + "=? AND " + Data.MIMETYPE + "=?",
|
Nickname.RAW_CONTACT_ID + "=? AND " + Data.MIMETYPE + "=?",
|
||||||
new String[] { String.valueOf(c.getLocalID()), Nickname.CONTENT_ITEM_TYPE }, null);
|
new String[] { String.valueOf(c.getLocalID()), Nickname.CONTENT_ITEM_TYPE }, null);
|
||||||
List<String> nickNames = new LinkedList<String>();
|
List<String> nickNames = new LinkedList<String>();
|
||||||
while (cursor.moveToNext())
|
while (cursor != null && cursor.moveToNext())
|
||||||
nickNames.add(cursor.getString(0));
|
nickNames.add(cursor.getString(0));
|
||||||
if (!nickNames.isEmpty())
|
if (!nickNames.isEmpty())
|
||||||
c.setNickNames(nickNames.toArray(new String[0]));
|
c.setNickNames(nickNames.toArray(new String[0]));
|
||||||
@ -158,7 +159,7 @@ public class LocalAddressBook extends LocalCollection<Contact> {
|
|||||||
cursor = providerClient.query(dataURI(), new String[] { Email.TYPE, Email.ADDRESS },
|
cursor = providerClient.query(dataURI(), new String[] { Email.TYPE, Email.ADDRESS },
|
||||||
Email.RAW_CONTACT_ID + "=? AND " + Data.MIMETYPE + "=?",
|
Email.RAW_CONTACT_ID + "=? AND " + Data.MIMETYPE + "=?",
|
||||||
new String[] { String.valueOf(c.getLocalID()), Email.CONTENT_ITEM_TYPE }, null);
|
new String[] { String.valueOf(c.getLocalID()), Email.CONTENT_ITEM_TYPE }, null);
|
||||||
while (cursor.moveToNext()) {
|
while (cursor != null && cursor.moveToNext()) {
|
||||||
net.fortuna.ical4j.vcard.property.Email email = new net.fortuna.ical4j.vcard.property.Email(cursor.getString(1));
|
net.fortuna.ical4j.vcard.property.Email email = new net.fortuna.ical4j.vcard.property.Email(cursor.getString(1));
|
||||||
switch (cursor.getInt(0)) {
|
switch (cursor.getInt(0)) {
|
||||||
case Email.TYPE_HOME:
|
case Email.TYPE_HOME:
|
||||||
@ -175,7 +176,7 @@ public class LocalAddressBook extends LocalCollection<Contact> {
|
|||||||
cursor = providerClient.query(dataURI(), new String[] { Phone.TYPE, Phone.NUMBER },
|
cursor = providerClient.query(dataURI(), new String[] { Phone.TYPE, Phone.NUMBER },
|
||||||
Phone.RAW_CONTACT_ID + "=? AND " + Data.MIMETYPE + "=?",
|
Phone.RAW_CONTACT_ID + "=? AND " + Data.MIMETYPE + "=?",
|
||||||
new String[] { String.valueOf(c.getLocalID()), Phone.CONTENT_ITEM_TYPE }, null);
|
new String[] { String.valueOf(c.getLocalID()), Phone.CONTENT_ITEM_TYPE }, null);
|
||||||
while (cursor.moveToNext()) {
|
while (cursor != null && cursor.moveToNext()) {
|
||||||
Telephone number = new Telephone(cursor.getString(1));
|
Telephone number = new Telephone(cursor.getString(1));
|
||||||
List<String> types = new LinkedList<String>();
|
List<String> types = new LinkedList<String>();
|
||||||
|
|
||||||
@ -220,14 +221,14 @@ public class LocalAddressBook extends LocalCollection<Contact> {
|
|||||||
cursor = providerClient.query(dataURI(), new String[] { Photo.PHOTO },
|
cursor = providerClient.query(dataURI(), new String[] { Photo.PHOTO },
|
||||||
Photo.RAW_CONTACT_ID + "=? AND " + Data.MIMETYPE + "=?",
|
Photo.RAW_CONTACT_ID + "=? AND " + Data.MIMETYPE + "=?",
|
||||||
new String[] { String.valueOf(c.getLocalID()), Photo.CONTENT_ITEM_TYPE }, null);
|
new String[] { String.valueOf(c.getLocalID()), Photo.CONTENT_ITEM_TYPE }, null);
|
||||||
if (cursor.moveToNext())
|
if (cursor != null && cursor.moveToNext())
|
||||||
c.setPhoto(cursor.getBlob(0));
|
c.setPhoto(cursor.getBlob(0));
|
||||||
|
|
||||||
// events (birthday)
|
// events (birthday)
|
||||||
cursor = providerClient.query(dataURI(), new String[] { CommonDataKinds.Event.TYPE, CommonDataKinds.Event.START_DATE },
|
cursor = providerClient.query(dataURI(), new String[] { CommonDataKinds.Event.TYPE, CommonDataKinds.Event.START_DATE },
|
||||||
Photo.RAW_CONTACT_ID + "=? AND " + Data.MIMETYPE + "=?",
|
Photo.RAW_CONTACT_ID + "=? AND " + Data.MIMETYPE + "=?",
|
||||||
new String[] { String.valueOf(c.getLocalID()), CommonDataKinds.Event.CONTENT_ITEM_TYPE }, null);
|
new String[] { String.valueOf(c.getLocalID()), CommonDataKinds.Event.CONTENT_ITEM_TYPE }, null);
|
||||||
while (cursor.moveToNext())
|
while (cursor != null && cursor.moveToNext())
|
||||||
try {
|
try {
|
||||||
switch (cursor.getInt(0)) {
|
switch (cursor.getInt(0)) {
|
||||||
case CommonDataKinds.Event.TYPE_BIRTHDAY:
|
case CommonDataKinds.Event.TYPE_BIRTHDAY:
|
||||||
@ -242,7 +243,7 @@ public class LocalAddressBook extends LocalCollection<Contact> {
|
|||||||
cursor = providerClient.query(dataURI(), new String[] { Website.URL },
|
cursor = providerClient.query(dataURI(), new String[] { Website.URL },
|
||||||
Website.RAW_CONTACT_ID + "=? AND " + Data.MIMETYPE + "=?",
|
Website.RAW_CONTACT_ID + "=? AND " + Data.MIMETYPE + "=?",
|
||||||
new String[] { String.valueOf(c.getLocalID()), Website.CONTENT_ITEM_TYPE }, null);
|
new String[] { String.valueOf(c.getLocalID()), Website.CONTENT_ITEM_TYPE }, null);
|
||||||
while (cursor.moveToNext())
|
while (cursor != null && cursor.moveToNext())
|
||||||
try {
|
try {
|
||||||
c.addURL(new URI(cursor.getString(0)));
|
c.addURL(new URI(cursor.getString(0)));
|
||||||
} catch (URISyntaxException ex) {
|
} catch (URISyntaxException ex) {
|
||||||
@ -253,7 +254,7 @@ public class LocalAddressBook extends LocalCollection<Contact> {
|
|||||||
cursor = providerClient.query(dataURI(), new String[] { Note.NOTE },
|
cursor = providerClient.query(dataURI(), new String[] { Note.NOTE },
|
||||||
Website.RAW_CONTACT_ID + "=? AND " + Data.MIMETYPE + "=?",
|
Website.RAW_CONTACT_ID + "=? AND " + Data.MIMETYPE + "=?",
|
||||||
new String[] { String.valueOf(c.getLocalID()), Note.CONTENT_ITEM_TYPE }, null);
|
new String[] { String.valueOf(c.getLocalID()), Note.CONTENT_ITEM_TYPE }, null);
|
||||||
while (cursor.moveToNext())
|
while (cursor != null && cursor.moveToNext())
|
||||||
c.addNote(new String(cursor.getString(0)));
|
c.addNote(new String(cursor.getString(0)));
|
||||||
|
|
||||||
c.populated = true;
|
c.populated = true;
|
||||||
|
@ -107,8 +107,9 @@ public class LocalCalendar extends LocalCollection<Event> {
|
|||||||
Cursor cursor = providerClient.query(calendarsURI(account),
|
Cursor cursor = providerClient.query(calendarsURI(account),
|
||||||
new String[] { Calendars._ID, Calendars.NAME, COLLECTION_COLUMN_CTAG },
|
new String[] { Calendars._ID, Calendars.NAME, COLLECTION_COLUMN_CTAG },
|
||||||
Calendars.DELETED + "=0 AND " + Calendars.SYNC_EVENTS + "=1", null, null);
|
Calendars.DELETED + "=0 AND " + Calendars.SYNC_EVENTS + "=1", null, null);
|
||||||
|
|
||||||
LinkedList<LocalCalendar> calendars = new LinkedList<LocalCalendar>();
|
LinkedList<LocalCalendar> calendars = new LinkedList<LocalCalendar>();
|
||||||
while (cursor.moveToNext())
|
while (cursor != null && cursor.moveToNext())
|
||||||
calendars.add(new LocalCalendar(account, providerClient, cursor.getInt(0), cursor.getString(1), cursor.getString(2)));
|
calendars.add(new LocalCalendar(account, providerClient, cursor.getInt(0), cursor.getString(1), cursor.getString(2)));
|
||||||
return calendars.toArray(new LocalCalendar[0]);
|
return calendars.toArray(new LocalCalendar[0]);
|
||||||
}
|
}
|
||||||
@ -147,9 +148,10 @@ public class LocalCalendar extends LocalCollection<Event> {
|
|||||||
new String[] { entryColumnID(), entryColumnRemoteName(), entryColumnETag() },
|
new String[] { entryColumnID(), entryColumnRemoteName(), entryColumnETag() },
|
||||||
Events.CALENDAR_ID + "=? AND " + entryColumnRemoteName() + "=?",
|
Events.CALENDAR_ID + "=? AND " + entryColumnRemoteName() + "=?",
|
||||||
new String[] { String.valueOf(id), remoteName }, null);
|
new String[] { String.valueOf(id), remoteName }, null);
|
||||||
if (cursor.moveToNext())
|
if (cursor != null && cursor.moveToNext())
|
||||||
return new Event(cursor.getLong(0), cursor.getString(1), cursor.getString(2));
|
return new Event(cursor.getLong(0), cursor.getString(1), cursor.getString(2));
|
||||||
return null;
|
else
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -167,7 +169,7 @@ public class LocalCalendar extends LocalCollection<Event> {
|
|||||||
/* 14 */ Events.HAS_ATTENDEE_DATA, Events.ORGANIZER, Events.SELF_ATTENDEE_STATUS,
|
/* 14 */ Events.HAS_ATTENDEE_DATA, Events.ORGANIZER, Events.SELF_ATTENDEE_STATUS,
|
||||||
/* 17 */ entryColumnUID()
|
/* 17 */ entryColumnUID()
|
||||||
}, null, null, null);
|
}, null, null, null);
|
||||||
if (cursor.moveToNext()) {
|
if (cursor != null && cursor.moveToNext()) {
|
||||||
e.setUid(cursor.getString(17));
|
e.setUid(cursor.getString(17));
|
||||||
|
|
||||||
e.setSummary(cursor.getString(0));
|
e.setSummary(cursor.getString(0));
|
||||||
@ -250,7 +252,7 @@ public class LocalCalendar extends LocalCollection<Event> {
|
|||||||
/* 0 */ Attendees.ATTENDEE_EMAIL, Attendees.ATTENDEE_NAME, Attendees.ATTENDEE_TYPE,
|
/* 0 */ Attendees.ATTENDEE_EMAIL, Attendees.ATTENDEE_NAME, Attendees.ATTENDEE_TYPE,
|
||||||
/* 3 */ Attendees.ATTENDEE_RELATIONSHIP, Attendees.STATUS
|
/* 3 */ Attendees.ATTENDEE_RELATIONSHIP, Attendees.STATUS
|
||||||
}, Attendees.EVENT_ID + "=?", new String[] { String.valueOf(e.getLocalID()) }, null);
|
}, Attendees.EVENT_ID + "=?", new String[] { String.valueOf(e.getLocalID()) }, null);
|
||||||
while (c.moveToNext()) {
|
while (c != null && c.moveToNext()) {
|
||||||
try {
|
try {
|
||||||
Attendee attendee = new Attendee("mailto:" + c.getString(0));
|
Attendee attendee = new Attendee("mailto:" + c.getString(0));
|
||||||
ParameterList params = attendee.getParameters();
|
ParameterList params = attendee.getParameters();
|
||||||
|
@ -19,7 +19,7 @@ import org.simpleframework.xml.Root;
|
|||||||
public class DavResponse {
|
public class DavResponse {
|
||||||
@Element
|
@Element
|
||||||
@Getter DavHref href;
|
@Getter DavHref href;
|
||||||
|
|
||||||
@ElementList(inline=true)
|
@ElementList(inline=true)
|
||||||
@Getter List<DavPropstat> propstat;
|
@Getter List<DavPropstat> propstat;
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,6 @@ import org.simpleframework.xml.Serializer;
|
|||||||
import org.simpleframework.xml.core.Persister;
|
import org.simpleframework.xml.core.Persister;
|
||||||
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import at.bitfire.davdroid.resource.IncapableResourceException;
|
|
||||||
|
|
||||||
public class WebDavCollection extends WebDavResource {
|
public class WebDavCollection extends WebDavResource {
|
||||||
private static final String TAG = "davdroid.WebDavCollection";
|
private static final String TAG = "davdroid.WebDavCollection";
|
||||||
@ -170,8 +169,16 @@ public class WebDavCollection extends WebDavResource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
WebDavResource referenced = null;
|
WebDavResource referenced = null;
|
||||||
|
|
||||||
|
URI thisURI;
|
||||||
|
try {
|
||||||
|
thisURI = location.resolve(href);
|
||||||
|
} catch(IllegalArgumentException ex) {
|
||||||
|
Log.w(TAG, "Server returned illegal URI", ex);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (sameURL(location, location.resolve(href))) {
|
if (sameURL(location, thisURI)) {
|
||||||
// response is about this property
|
// response is about this property
|
||||||
referenced = this;
|
referenced = this;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user