mirror of
https://github.com/oxen-io/session-android.git
synced 2025-12-03 05:22:23 +00:00
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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user