Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a0d592c7 authored by Ricki Hirner's avatar Ricki Hirner
Browse files

Don't throw exception when content provider doesn't return all results

parent 7851ea3a
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -9,7 +9,7 @@ buildscript {
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.1'
        classpath 'com.android.tools.build:gradle:3.1.2'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "org.jetbrains.dokka:dokka-android-gradle-plugin:${dokka_version}"
    }
@@ -25,7 +25,7 @@ apply plugin: 'kotlin-android'
apply plugin: 'org.jetbrains.dokka-android'

ext {
    ical4j_version = "2.2.0"
    ical4j_version = '2.2.0'
}

android {

lombok.config

deleted100644 → 0
+0 −1
Original line number Diff line number Diff line
lombok.addGeneratedAnnotation = false
+12 −9
Original line number Diff line number Diff line
@@ -29,9 +29,9 @@ class BatchOperation(
        var affected = 0
        if (!queue.isEmpty())
            try {
                Constants.log.fine("Committing ${queue.size} operations")
                Constants.log.fine("Committing ${queue.size} operations")

                results = Array(queue.size, { null })
                results = arrayOfNulls(queue.size)
                runBatch(0, queue.size)

                for (result in results.filterNotNull())
@@ -40,6 +40,7 @@ class BatchOperation(
                        result.uri != null   -> affected += 1
                    }
                Constants.log.fine("… $affected record(s) affected")

            } catch(e: Exception) {
                throw CalendarStorageException("Couldn't apply batch operation", e)
            }
@@ -58,21 +59,22 @@ class BatchOperation(
     * @param end   index of last operation which will be run (exclusive!)
     * @throws RemoteException on calendar provider errors
     * @throws OperationApplicationException when the batch can't be processed
     * @throws CalendarStorageException if the transaction is too large or if the batch operation failed partially
     * @throws CalendarStorageException if the transaction is too large
     */
    private fun runBatch(start: Int, end: Int) {
        if (end == start)
            return     // nothing to do

        try {
            Constants.log.fine("Running operations $start to ${end-1}")
            val partResults = providerClient.applyBatch(toCPO(start, end))
            val ops = toCPO(start, end)
            Constants.log.fine("Running {${ops.size}} operations ($start .. ${end-1})")
            val partResults = providerClient.applyBatch(ops)

            val n = end - start
            if (partResults.size != n)
                throw CalendarStorageException("Batch operation failed partially (only ${partResults.size} of $n operations done)")
                Constants.log.warning("Batch operation returned only ${partResults.size} instead of $n results")

            System.arraycopy(partResults, 0, results, start, n)
            System.arraycopy(partResults, 0, results, start, partResults.size)
        } catch(e: TransactionTooLargeException) {
            if (end <= start + 1)
                // only one operation, can't be split
@@ -87,6 +89,7 @@ class BatchOperation(

    private fun toCPO(start: Int, end: Int): ArrayList<ContentProviderOperation> {
        val cpo = ArrayList<ContentProviderOperation>(end - start)

        for ((i, op) in queue.subList(start, end).withIndex()) {
            val builder = op.builder
            op.backrefKey?.let { key ->