summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndy Huang <ath@google.com>2013-06-28 20:53:44 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2013-06-28 20:53:44 +0000
commit217568e3c29fa113e9f2d075ed5f65554780872a (patch)
treea256f10cfd53da460b5b5b5f38d84f84c60eb4cd
parentfe23512c2be21d7c87677f5263078021002d89cb (diff)
parentc4e230fd260e8d80cffc0515bb9322f7553853f9 (diff)
downloadandroid_packages_apps_UnifiedEmail-217568e3c29fa113e9f2d075ed5f65554780872a.tar.gz
android_packages_apps_UnifiedEmail-217568e3c29fa113e9f2d075ed5f65554780872a.tar.bz2
android_packages_apps_UnifiedEmail-217568e3c29fa113e9f2d075ed5f65554780872a.zip
Merge "list caching tweaks" into jb-ub-mail-ur10
-rw-r--r--src/com/android/mail/browse/ConversationCursor.java32
1 files changed, 26 insertions, 6 deletions
diff --git a/src/com/android/mail/browse/ConversationCursor.java b/src/com/android/mail/browse/ConversationCursor.java
index 75a0ea65b..7024f6e0e 100644
--- a/src/com/android/mail/browse/ConversationCursor.java
+++ b/src/com/android/mail/browse/ConversationCursor.java
@@ -312,6 +312,7 @@ public final class ConversationCursor implements Cursor, ConversationCursorOpera
}
mCachePos = pos + 1;
}
+ System.gc();
} finally {
Utils.traceEndSection();
}
@@ -356,6 +357,7 @@ public final class ConversationCursor implements Cursor, ConversationCursorOpera
* notes on thread safety.
*/
private int mCachePos;
+ private boolean mCachingEnabled = true;
private final NewCursorUpdateObserver mCursorUpdateObserver;
private boolean mUpdateObserverRegistered;
@@ -453,18 +455,25 @@ public final class ConversationCursor implements Cursor, ConversationCursorOpera
mCachePos = 0;
}
- private void startCaching() {
+ /**
+ * Resumes caching at {@link #mCachePos}.
+ *
+ * @return true if we actually resumed, false if we're done or stopped
+ */
+ private boolean resumeCaching() {
if (mCacheLoaderTask != null) {
throw new IllegalStateException("unexpected existing task: " + mCacheLoaderTask);
}
- if (mCachePos < getCount()) {
+ if (mCachingEnabled && mCachePos < getCount()) {
mCacheLoaderTask = new CacheLoaderTask(mCachePos);
mCacheLoaderTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
+ return true;
}
+ return false;
}
- private void stopCaching() {
+ private void pauseCaching() {
if (mCacheLoaderTask != null) {
LogUtils.i(LOG_TAG, "Cancelling caching startPos=%s pos=%s",
mCacheLoaderTask.mStartPos, mCachePos);
@@ -473,6 +482,11 @@ public final class ConversationCursor implements Cursor, ConversationCursorOpera
}
}
+ public void stopCaching() {
+ pauseCaching();
+ mCachingEnabled = false;
+ }
+
public boolean contains(String uri) {
return mConversationUriPositionMap.containsKey(uri);
}
@@ -538,13 +552,13 @@ public final class ConversationCursor implements Cursor, ConversationCursorOpera
if (oldState != newState) {
if (newState == DrawIdler.STATE_IDLE) {
// begin/resume caching
- startCaching();
- if (mCachePos < getCount()) {
+ final boolean resumed = resumeCaching();
+ if (resumed) {
LogUtils.i(LOG_TAG, "Resuming caching, pos=%s idler=%s", mCachePos, idler);
}
} else {
// pause caching
- stopCaching();
+ pauseCaching();
}
}
}
@@ -612,7 +626,9 @@ public final class ConversationCursor implements Cursor, ConversationCursorOpera
}
long time = System.currentTimeMillis();
+ Utils.traceBeginSection("query");
final Cursor result = mResolver.query(uri, qProjection, null, null, null);
+ Utils.traceEndSection();
if (result == null) {
LogUtils.w(LOG_TAG, "doQuery returning null cursor, uri: " + uri);
} else if (DEBUG) {
@@ -620,6 +636,7 @@ public final class ConversationCursor implements Cursor, ConversationCursorOpera
LogUtils.i(LOG_TAG, "ConversationCursor query: %s, %dms, %d results",
uri, time, result.getCount());
}
+ System.gc();
return new UnderlyingCursorWrapper(result);
}
@@ -1069,6 +1086,9 @@ public final class ConversationCursor implements Cursor, ConversationCursorOpera
}
return false;
}
+ if (mUnderlyingCursor != null) {
+ mUnderlyingCursor.stopCaching();
+ }
mRefreshTask = new RefreshTask();
mRefreshTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}