diff --git a/src/at/bitfire/davdroid/resource/LocalAddressBook.java b/src/at/bitfire/davdroid/resource/LocalAddressBook.java index b5ed2fc9..6e6f531a 100644 --- a/src/at/bitfire/davdroid/resource/LocalAddressBook.java +++ b/src/at/bitfire/davdroid/resource/LocalAddressBook.java @@ -306,22 +306,31 @@ public class LocalAddressBook extends LocalCollection { } protected void populatePhoto(Contact c) throws RemoteException { - Uri photoUri = Uri.withAppendedPath( - ContentUris.withAppendedId(RawContacts.CONTENT_URI, c.getLocalID()), - RawContacts.DisplayPhoto.CONTENT_DIRECTORY); - try { - @Cleanup AssetFileDescriptor fd = providerClient.openAssetFile(photoUri, "r"); - @Cleanup InputStream is = fd.createInputStream(); - c.setPhoto(IOUtils.toByteArray(is)); - } catch(IOException ex) { - Log.v(TAG, "Couldn't read contact photo", ex); + @Cleanup Cursor cursor = providerClient.query(dataURI(), + new String[] { Photo.PHOTO_FILE_ID, Photo.PHOTO }, + Photo.RAW_CONTACT_ID + "=? AND " + Data.MIMETYPE + "=?", + new String[] { String.valueOf(c.getLocalID()), Photo.CONTENT_ITEM_TYPE }, null); + if (cursor != null && cursor.moveToNext()) { + if (!cursor.isNull(0)) { + Uri photoUri = Uri.withAppendedPath( + ContentUris.withAppendedId(RawContacts.CONTENT_URI, c.getLocalID()), + RawContacts.DisplayPhoto.CONTENT_DIRECTORY); + try { + @Cleanup AssetFileDescriptor fd = providerClient.openAssetFile(photoUri, "r"); + @Cleanup InputStream is = fd.createInputStream(); + c.setPhoto(IOUtils.toByteArray(is)); + } catch(IOException ex) { + Log.w(TAG, "Couldn't read high-res contact photo", ex); + } + } else + c.setPhoto(cursor.getBlob(1)); } } protected void populateOrganization(Contact c) throws RemoteException { @Cleanup Cursor cursor = providerClient.query(dataURI(), new String[] { Organization.COMPANY, Organization.DEPARTMENT, Organization.TITLE, Organization.JOB_DESCRIPTION }, - Photo.RAW_CONTACT_ID + "=? AND " + Data.MIMETYPE + "=?", + Organization.RAW_CONTACT_ID + "=? AND " + Data.MIMETYPE + "=?", new String[] { String.valueOf(c.getLocalID()), Organization.CONTENT_ITEM_TYPE }, null); if (cursor != null && cursor.moveToNext()) { String company = cursor.getString(0), @@ -345,7 +354,7 @@ public class LocalAddressBook extends LocalCollection { protected void populateIMPPs(Contact c) throws RemoteException { @Cleanup Cursor cursor = providerClient.query(dataURI(), new String[] { Im.DATA, Im.TYPE, Im.LABEL, Im.PROTOCOL, Im.CUSTOM_PROTOCOL }, - Photo.RAW_CONTACT_ID + "=? AND " + Data.MIMETYPE + "=?", + Im.RAW_CONTACT_ID + "=? AND " + Data.MIMETYPE + "=?", new String[] { String.valueOf(c.getLocalID()), Im.CONTENT_ITEM_TYPE }, null); while (cursor != null && cursor.moveToNext()) { String handle = cursor.getString(0); @@ -411,7 +420,7 @@ public class LocalAddressBook extends LocalCollection { protected void populateNote(Contact c) throws RemoteException { @Cleanup Cursor cursor = providerClient.query(dataURI(), new String[] { Note.NOTE }, - Website.RAW_CONTACT_ID + "=? AND " + Data.MIMETYPE + "=?", + Note.RAW_CONTACT_ID + "=? AND " + Data.MIMETYPE + "=?", new String[] { String.valueOf(c.getLocalID()), Note.CONTENT_ITEM_TYPE }, null); if (cursor != null && cursor.moveToNext()) c.setNote(cursor.getString(0)); @@ -485,9 +494,9 @@ public class LocalAddressBook extends LocalCollection { protected void populateSipAddress(Contact c) throws RemoteException { @Cleanup Cursor cursor = providerClient.query(dataURI(), - new String[] { CommonDataKinds.SipAddress.SIP_ADDRESS, CommonDataKinds.SipAddress.TYPE, CommonDataKinds.SipAddress.LABEL }, - Website.RAW_CONTACT_ID + "=? AND " + Data.MIMETYPE + "=?", - new String[] { String.valueOf(c.getLocalID()), CommonDataKinds.SipAddress.CONTENT_ITEM_TYPE }, null); + new String[] { SipAddress.SIP_ADDRESS, SipAddress.TYPE, SipAddress.LABEL }, + SipAddress.RAW_CONTACT_ID + "=? AND " + Data.MIMETYPE + "=?", + new String[] { String.valueOf(c.getLocalID()), SipAddress.CONTENT_ITEM_TYPE }, null); if (cursor != null && cursor.moveToNext()) { Impp impp = new Impp("sip:" + cursor.getString(0)); switch (cursor.getInt(1)) { diff --git a/src/at/bitfire/davdroid/syncadapter/SyncManager.java b/src/at/bitfire/davdroid/syncadapter/SyncManager.java index db409ec5..a2e64416 100644 --- a/src/at/bitfire/davdroid/syncadapter/SyncManager.java +++ b/src/at/bitfire/davdroid/syncadapter/SyncManager.java @@ -82,7 +82,9 @@ public class SyncManager { remotelyAdded.add(remoteResource); } } - + + try { Thread.sleep(2000); } catch (InterruptedException e) { } + // PHASE 3: pull remote changes from server syncResult.stats.numInserts = pullNew(remotelyAdded.toArray(new Resource[0])); syncResult.stats.numUpdates = pullChanged(remotelyUpdated.toArray(new Resource[0])); diff --git a/src/at/bitfire/davdroid/webdav/DavHttpClient.java b/src/at/bitfire/davdroid/webdav/DavHttpClient.java index acddcb08..9d0e2beb 100644 --- a/src/at/bitfire/davdroid/webdav/DavHttpClient.java +++ b/src/at/bitfire/davdroid/webdav/DavHttpClient.java @@ -36,7 +36,7 @@ public class DavHttpClient { defaultRqConfig = RequestConfig.copy(RequestConfig.DEFAULT) .setConnectTimeout(20*1000) .setSocketTimeout(20*1000) - .setStaleConnectionCheckEnabled(true) + .setStaleConnectionCheckEnabled(false) .build(); // enable logging