Loading src/main/java/at/bitfire/vcard4android/AndroidContact.kt +6 −1 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ import at.bitfire.vcard4android.contactrow.ContactProcessor import at.bitfire.vcard4android.contactrow.PhotoBuilder import org.apache.commons.lang3.builder.ToStringBuilder import java.io.FileNotFoundException import java.util.logging.Level open class AndroidContact( open val addressBook: AndroidAddressBook<out AndroidContact, out AndroidGroup> Loading Loading @@ -127,7 +128,11 @@ open class AndroidContact( id = ContentUris.parseId(resultUri) getContact().photo?.let { photo -> try { PhotoBuilder.insertPhoto(provider, addressBook.account, id!!, photo) } catch (e: IllegalArgumentException) { Constants.log.log(Level.WARNING, "Invalid contact photo", e) } } return resultUri Loading src/main/java/at/bitfire/vcard4android/contactrow/PhotoBuilder.kt +6 −2 Original line number Diff line number Diff line Loading @@ -39,13 +39,17 @@ class PhotoBuilder(dataRowUri: Uri, rawContactId: Long?, contact: Contact) * * @return URI of the raw contact display photo ([Photo.PHOTO_URI]) * * @throws IllegalArgumentException when the image can't be read by [BitmapFactory] * @throws ContactsStorageException when the image couldn't be written */ fun insertPhoto(provider: ContentProviderClient, account: Account, rawContactId: Long, data: ByteArray): Uri? { // verify that data can be decoded by BitmapFactory, so that the contacts provider can process it val valid = BitmapFactory.decodeByteArray(data, 0, data.size) != null val opts = BitmapFactory.Options() opts.inJustDecodeBounds = true BitmapFactory.decodeByteArray(data, 0, data.size, opts) val valid = opts.outHeight != -1 && opts.outWidth != -1 if (!valid) throw IllegalArgumentException("Image can't be decoded") throw IllegalArgumentException("BitmapFactory can't decode image") // write file to contacts provider val uri = RawContacts.CONTENT_URI.buildUpon() Loading Loading
src/main/java/at/bitfire/vcard4android/AndroidContact.kt +6 −1 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ import at.bitfire.vcard4android.contactrow.ContactProcessor import at.bitfire.vcard4android.contactrow.PhotoBuilder import org.apache.commons.lang3.builder.ToStringBuilder import java.io.FileNotFoundException import java.util.logging.Level open class AndroidContact( open val addressBook: AndroidAddressBook<out AndroidContact, out AndroidGroup> Loading Loading @@ -127,7 +128,11 @@ open class AndroidContact( id = ContentUris.parseId(resultUri) getContact().photo?.let { photo -> try { PhotoBuilder.insertPhoto(provider, addressBook.account, id!!, photo) } catch (e: IllegalArgumentException) { Constants.log.log(Level.WARNING, "Invalid contact photo", e) } } return resultUri Loading
src/main/java/at/bitfire/vcard4android/contactrow/PhotoBuilder.kt +6 −2 Original line number Diff line number Diff line Loading @@ -39,13 +39,17 @@ class PhotoBuilder(dataRowUri: Uri, rawContactId: Long?, contact: Contact) * * @return URI of the raw contact display photo ([Photo.PHOTO_URI]) * * @throws IllegalArgumentException when the image can't be read by [BitmapFactory] * @throws ContactsStorageException when the image couldn't be written */ fun insertPhoto(provider: ContentProviderClient, account: Account, rawContactId: Long, data: ByteArray): Uri? { // verify that data can be decoded by BitmapFactory, so that the contacts provider can process it val valid = BitmapFactory.decodeByteArray(data, 0, data.size) != null val opts = BitmapFactory.Options() opts.inJustDecodeBounds = true BitmapFactory.decodeByteArray(data, 0, data.size, opts) val valid = opts.outHeight != -1 && opts.outWidth != -1 if (!valid) throw IllegalArgumentException("Image can't be decoded") throw IllegalArgumentException("BitmapFactory can't decode image") // write file to contacts provider val uri = RawContacts.CONTENT_URI.buildUpon() Loading