summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJay Shrauner <shrauner@google.com>2014-12-16 16:06:03 -0800
committerJay Shrauner <shrauner@google.com>2014-12-19 10:35:24 -0800
commit7158b6705d330ac1e61d5aa51c51b54507c4ab88 (patch)
tree0fc13fd92643f45f47367ee042360cbfee28b309
parentede5a97a7ed75ac04dfa58c3b867e67ea4e80f92 (diff)
downloadandroid_frameworks_ex-7158b6705d330ac1e61d5aa51c51b54507c4ab88.tar.gz
android_frameworks_ex-7158b6705d330ac1e61d5aa51c51b54507c4ab88.tar.bz2
android_frameworks_ex-7158b6705d330ac1e61d5aa51c51b54507c4ab88.zip
Fix StaleDataExceptions
In ensureCacheValid, check whether the cursor is closed before querying its count. In getItem, check whether the cursor is closed before moving it to position, as was already being done in getItemId. Bug:18815354 Change-Id: I4cf2509923695afe9499d0507383c4e0d51bd23e
-rw-r--r--common/java/com/android/common/widget/CompositeCursorAdapter.java11
1 files changed, 9 insertions, 2 deletions
diff --git a/common/java/com/android/common/widget/CompositeCursorAdapter.java b/common/java/com/android/common/widget/CompositeCursorAdapter.java
index dddbcf6..8a3fa9b 100644
--- a/common/java/com/android/common/widget/CompositeCursorAdapter.java
+++ b/common/java/com/android/common/widget/CompositeCursorAdapter.java
@@ -170,7 +170,12 @@ public abstract class CompositeCursorAdapter extends BaseAdapter {
mCount = 0;
for (Partition partition : mPartitions) {
Cursor cursor = partition.cursor;
- int count = cursor != null ? cursor.getCount() : 0;
+ int count;
+ if (cursor == null || cursor.isClosed()) {
+ count = 0;
+ } else {
+ count = cursor.getCount();
+ }
if (partition.hasHeader) {
if (count != 0 || partition.showIfEmpty) {
count++;
@@ -428,7 +433,9 @@ public abstract class CompositeCursorAdapter extends BaseAdapter {
return null;
}
Cursor cursor = mPartition.cursor;
- cursor.moveToPosition(offset);
+ if (cursor == null || cursor.isClosed() || !cursor.moveToPosition(offset)) {
+ return null;
+ }
return cursor;
}
start = end;