Apply contact updates in batches of 50.

If batch sizes are too large, we'll get a Binder exception.

Fixes #8580
This commit is contained in:
Greyson Parrelli
2019-02-01 12:47:34 -08:00
parent c6d3bed8da
commit 5d9d6ac12b
4 changed files with 95 additions and 7 deletions

View File

@@ -19,6 +19,7 @@ package org.thoughtcrime.securesms.contacts;
import android.accounts.Account;
import android.annotation.SuppressLint;
import android.content.ContentProviderOperation;
import android.content.ContentResolver;
import android.content.Context;
import android.content.OperationApplicationException;
import android.database.Cursor;
@@ -137,7 +138,7 @@ public class ContactsDatabase {
}
if (!operations.isEmpty()) {
context.getContentResolver().applyBatch(ContactsContract.AUTHORITY, operations);
applyOperationsInBatches(context.getContentResolver(), ContactsContract.AUTHORITY, operations, 50);
}
}
@@ -532,6 +533,18 @@ public class ContactsDatabase {
}
}
private void applyOperationsInBatches(@NonNull ContentResolver contentResolver,
@NonNull String authority,
@NonNull List<ContentProviderOperation> operations,
int batchSize)
throws OperationApplicationException, RemoteException
{
List<List<ContentProviderOperation>> batches = Util.chunk(operations, batchSize);
for (List<ContentProviderOperation> batch : batches) {
contentResolver.applyBatch(authority, new ArrayList<>(batch));
}
}
private static class ProjectionMappingCursor extends CursorWrapper {
private final Map<String, String> projectionMap;