1
0
mirror of https://github.com/etesync/android synced 2024-11-26 01:48:34 +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:
rfc2822 2013-10-26 20:35:22 +02:00
parent 5db8bcb9d8
commit d15478b863
4 changed files with 29 additions and 19 deletions

View File

@ -105,8 +105,9 @@ public class LocalAddressBook extends LocalCollection<Contact> {
Cursor cursor = providerClient.query(entriesURI(),
new String[] { RawContacts._ID, entryColumnRemoteName(), entryColumnETag() },
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));
else
return null;
}
@ -118,7 +119,7 @@ public class LocalAddressBook extends LocalCollection<Contact> {
Cursor cursor = providerClient.query(ContentUris.withAppendedId(entriesURI(), c.getLocalID()),
new String[] { entryColumnUID(), RawContacts.STARRED }, null, null, null);
if (cursor.moveToNext()) {
if (cursor != null && cursor.moveToNext()) {
c.setUid(cursor.getString(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
}, StructuredName.RAW_CONTACT_ID + "=? AND " + Data.MIMETYPE + "=?",
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.setPrefix(cursor.getString(1));
@ -149,7 +150,7 @@ public class LocalAddressBook extends LocalCollection<Contact> {
Nickname.RAW_CONTACT_ID + "=? AND " + Data.MIMETYPE + "=?",
new String[] { String.valueOf(c.getLocalID()), Nickname.CONTENT_ITEM_TYPE }, null);
List<String> nickNames = new LinkedList<String>();
while (cursor.moveToNext())
while (cursor != null && cursor.moveToNext())
nickNames.add(cursor.getString(0));
if (!nickNames.isEmpty())
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 },
Email.RAW_CONTACT_ID + "=? AND " + Data.MIMETYPE + "=?",
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));
switch (cursor.getInt(0)) {
case Email.TYPE_HOME:
@ -175,7 +176,7 @@ public class LocalAddressBook extends LocalCollection<Contact> {
cursor = providerClient.query(dataURI(), new String[] { Phone.TYPE, Phone.NUMBER },
Phone.RAW_CONTACT_ID + "=? AND " + Data.MIMETYPE + "=?",
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));
List<String> types = new LinkedList<String>();
@ -220,14 +221,14 @@ public class LocalAddressBook extends LocalCollection<Contact> {
cursor = providerClient.query(dataURI(), new String[] { Photo.PHOTO },
Photo.RAW_CONTACT_ID + "=? AND " + Data.MIMETYPE + "=?",
new String[] { String.valueOf(c.getLocalID()), Photo.CONTENT_ITEM_TYPE }, null);
if (cursor.moveToNext())
if (cursor != null && cursor.moveToNext())
c.setPhoto(cursor.getBlob(0));
// events (birthday)
cursor = providerClient.query(dataURI(), new String[] { CommonDataKinds.Event.TYPE, CommonDataKinds.Event.START_DATE },
Photo.RAW_CONTACT_ID + "=? AND " + Data.MIMETYPE + "=?",
new String[] { String.valueOf(c.getLocalID()), CommonDataKinds.Event.CONTENT_ITEM_TYPE }, null);
while (cursor.moveToNext())
while (cursor != null && cursor.moveToNext())
try {
switch (cursor.getInt(0)) {
case CommonDataKinds.Event.TYPE_BIRTHDAY:
@ -242,7 +243,7 @@ public class LocalAddressBook extends LocalCollection<Contact> {
cursor = providerClient.query(dataURI(), new String[] { Website.URL },
Website.RAW_CONTACT_ID + "=? AND " + Data.MIMETYPE + "=?",
new String[] { String.valueOf(c.getLocalID()), Website.CONTENT_ITEM_TYPE }, null);
while (cursor.moveToNext())
while (cursor != null && cursor.moveToNext())
try {
c.addURL(new URI(cursor.getString(0)));
} catch (URISyntaxException ex) {
@ -253,7 +254,7 @@ public class LocalAddressBook extends LocalCollection<Contact> {
cursor = providerClient.query(dataURI(), new String[] { Note.NOTE },
Website.RAW_CONTACT_ID + "=? AND " + Data.MIMETYPE + "=?",
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.populated = true;

View File

@ -107,8 +107,9 @@ public class LocalCalendar extends LocalCollection<Event> {
Cursor cursor = providerClient.query(calendarsURI(account),
new String[] { Calendars._ID, Calendars.NAME, COLLECTION_COLUMN_CTAG },
Calendars.DELETED + "=0 AND " + Calendars.SYNC_EVENTS + "=1", null, null);
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)));
return calendars.toArray(new LocalCalendar[0]);
}
@ -147,8 +148,9 @@ public class LocalCalendar extends LocalCollection<Event> {
new String[] { entryColumnID(), entryColumnRemoteName(), entryColumnETag() },
Events.CALENDAR_ID + "=? AND " + entryColumnRemoteName() + "=?",
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));
else
return null;
}
@ -167,7 +169,7 @@ public class LocalCalendar extends LocalCollection<Event> {
/* 14 */ Events.HAS_ATTENDEE_DATA, Events.ORGANIZER, Events.SELF_ATTENDEE_STATUS,
/* 17 */ entryColumnUID()
}, null, null, null);
if (cursor.moveToNext()) {
if (cursor != null && cursor.moveToNext()) {
e.setUid(cursor.getString(17));
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,
/* 3 */ Attendees.ATTENDEE_RELATIONSHIP, Attendees.STATUS
}, Attendees.EVENT_ID + "=?", new String[] { String.valueOf(e.getLocalID()) }, null);
while (c.moveToNext()) {
while (c != null && c.moveToNext()) {
try {
Attendee attendee = new Attendee("mailto:" + c.getString(0));
ParameterList params = attendee.getParameters();

View File

@ -30,7 +30,6 @@ import org.simpleframework.xml.Serializer;
import org.simpleframework.xml.core.Persister;
import android.util.Log;
import at.bitfire.davdroid.resource.IncapableResourceException;
public class WebDavCollection extends WebDavResource {
private static final String TAG = "davdroid.WebDavCollection";
@ -171,7 +170,15 @@ public class WebDavCollection extends WebDavResource {
WebDavResource referenced = null;
if (sameURL(location, location.resolve(href))) {
URI thisURI;
try {
thisURI = location.resolve(href);
} catch(IllegalArgumentException ex) {
Log.w(TAG, "Server returned illegal URI", ex);
continue;
}
if (sameURL(location, thisURI)) {
// response is about this property
referenced = this;