diff options
author | Treehugger Robot <treehugger-gerrit@google.com> | 2017-08-31 16:17:04 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2017-08-31 16:17:04 +0000 |
commit | c39ea3c55fac807c0b98aabdf56c70dc8a49036c (patch) | |
tree | e282668a9587cf6c1ec7b604dea860400c75c6c7 /java/com/android/contacts/common/database/NoNullCursorAsyncQueryHandler.java | |
parent | 68038172793ee0e2ab3e2e56ddfbeb82879d1f58 (diff) | |
parent | 2ca4318cc1ee57dda907ba2069bd61d162b1baef (diff) |
Merge "Update Dialer source to latest internal Google revision."
Diffstat (limited to 'java/com/android/contacts/common/database/NoNullCursorAsyncQueryHandler.java')
-rw-r--r-- | java/com/android/contacts/common/database/NoNullCursorAsyncQueryHandler.java | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/java/com/android/contacts/common/database/NoNullCursorAsyncQueryHandler.java b/java/com/android/contacts/common/database/NoNullCursorAsyncQueryHandler.java index d5e61354a..5d10720b5 100644 --- a/java/com/android/contacts/common/database/NoNullCursorAsyncQueryHandler.java +++ b/java/com/android/contacts/common/database/NoNullCursorAsyncQueryHandler.java @@ -20,6 +20,9 @@ import android.content.AsyncQueryHandler; import android.content.ContentResolver; import android.database.Cursor; import android.net.Uri; +import android.support.annotation.Nullable; +import android.support.annotation.VisibleForTesting; +import java.util.concurrent.atomic.AtomicInteger; /** * An {@AsyncQueryHandler} that will never return a null cursor. @@ -27,6 +30,8 @@ import android.net.Uri; * <p>Instead, will return a {@link Cursor} with 0 records. */ public abstract class NoNullCursorAsyncQueryHandler extends AsyncQueryHandler { + private static final AtomicInteger pendingQueryCount = new AtomicInteger(); + @Nullable private static PendingQueryCountChangedListener pendingQueryCountChangedListener; public NoNullCursorAsyncQueryHandler(ContentResolver cr) { super(cr); @@ -41,6 +46,11 @@ public abstract class NoNullCursorAsyncQueryHandler extends AsyncQueryHandler { String selection, String[] selectionArgs, String orderBy) { + pendingQueryCount.getAndIncrement(); + if (pendingQueryCountChangedListener != null) { + pendingQueryCountChangedListener.onPendingQueryCountChanged(); + } + final CookieWithProjection projectionCookie = new CookieWithProjection(cookie, projection); super.startQuery(token, projectionCookie, uri, projection, selection, selectionArgs, orderBy); } @@ -55,10 +65,31 @@ public abstract class NoNullCursorAsyncQueryHandler extends AsyncQueryHandler { cursor = new EmptyCursor(projectionCookie.projection); } onNotNullableQueryComplete(token, projectionCookie.originalCookie, cursor); + + pendingQueryCount.getAndDecrement(); + if (pendingQueryCountChangedListener != null) { + pendingQueryCountChangedListener.onPendingQueryCountChanged(); + } } protected abstract void onNotNullableQueryComplete(int token, Object cookie, Cursor cursor); + @VisibleForTesting(otherwise = VisibleForTesting.NONE) + public static void setPendingQueryCountChangedListener( + @Nullable PendingQueryCountChangedListener listener) { + pendingQueryCountChangedListener = listener; + } + + @VisibleForTesting(otherwise = VisibleForTesting.NONE) + public static int getPendingQueryCount() { + return pendingQueryCount.get(); + } + + /** Callback to listen for changes in the number of queries that have not completed. */ + public interface PendingQueryCountChangedListener { + void onPendingQueryCountChanged(); + } + /** Class to add projection to an existing cookie. */ private static class CookieWithProjection { |