Performance optimizations for applyBatch

1. Moved blocking tasks to run before transaction ends. This optimizes
the database operations from blocking tasks to run in same transaction
and sends notifications in batch.
2. Removed unnecessary notifications resulting from query() method called
for MediaProvider where cursor doesn't leave our process.
3. Removed validateSql() when there is no userWhere. validateSql()
validates the user-supplied selection to detect syntactic anomalies in
the selection string that could indicate a SQL injection attempt. If
there is no user selection, this call be can be avoided.

With these improvements, applyBatch() for clearing is_pending for 100
files can see a performance gain of 400-450ms.

Bug: 169634969
Test: Manual, verified the performance improvements in applyBatch()
Test: atest packages/providers/MediaProvider
Change-Id: Iea385eb5833d2f3253b51480a1790a257f81af41
(cherry picked from commit 693d7a1f5ca9517bc876b1037ac06682c02dbdbd)
3 files changed