Move blockingTasks to run outside transaction
If blocking tasks are run inside transaction, they seemed to cause ANRs
in some devices because of blocking scans taking a lot of time.
Bug: 169634969
Test: atest packages/providers/MediaProvider
Merged-In: I1890f8864b9f227f81fa7c4c8a0646e8fced4c27
Change-Id: I1890f8864b9f227f81fa7c4c8a0646e8fced4c27
diff --git a/src/com/android/providers/media/DatabaseHelper.java b/src/com/android/providers/media/DatabaseHelper.java
index 8a32eff..26e3f31 100644
--- a/src/com/android/providers/media/DatabaseHelper.java
+++ b/src/com/android/providers/media/DatabaseHelper.java
@@ -518,15 +518,6 @@
if (state == null) {
throw new IllegalStateException("No transaction in progress");
}
- if (state.successful) {
- // Run blocking tasks inside the same transaction. This optimizes
- // the database operations from blocking tasks to run in same
- // transaction and sends notifications resulting from these tasks
- // in batch.
- for (int i = 0; i < state.blockingTasks.size(); i++) {
- state.blockingTasks.get(i).run();
- }
- }
mTransactionState.remove();
final SQLiteDatabase db = super.getWritableDatabase();
@@ -534,6 +525,9 @@
mSchemaLock.readLock().unlock();
if (state.successful) {
+ for (int i = 0; i < state.blockingTasks.size(); i++) {
+ state.blockingTasks.get(i).run();
+ }
// We carefully "phase" our two sets of work here to ensure that we
// completely finish dispatching all change notifications before we
// process background tasks, to ensure that the background work