Don't throw exception on moveToPosition in CachedCursor
* Just return false Bug: 3240290 Change-Id: I808ca88c7897c573d19c2c2c92b179b4106a6dd3
This commit is contained in:
parent
2201b38fe3
commit
68dc380d62
@ -262,7 +262,9 @@ public final class ContentCache extends LinkedHashMap<String, Cursor> {
|
|||||||
/**
|
/**
|
||||||
* The cached cursor is simply a CursorWrapper whose underlying cursor contains zero or one
|
* The cached cursor is simply a CursorWrapper whose underlying cursor contains zero or one
|
||||||
* rows. We handle simple movement (moveToFirst(), moveToNext(), etc.), and override close()
|
* rows. We handle simple movement (moveToFirst(), moveToNext(), etc.), and override close()
|
||||||
* to keep the underlying cursor alive (unless it's no longer cached due to an invalidation)
|
* to keep the underlying cursor alive (unless it's no longer cached due to an invalidation).
|
||||||
|
* Multiple CachedCursor's can use the same underlying cursor, so we override the various
|
||||||
|
* moveX methods such that each CachedCursor can have its own position information
|
||||||
*/
|
*/
|
||||||
public static final class CachedCursor extends CursorWrapper {
|
public static final class CachedCursor extends CursorWrapper {
|
||||||
// The cursor we're wrapping
|
// The cursor we're wrapping
|
||||||
@ -310,14 +312,11 @@ public final class ContentCache extends LinkedHashMap<String, Cursor> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* We'll be happy to move to position 0 or -1; others are illegal
|
* We'll be happy to move to position 0 or -1
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean moveToPosition(int pos) {
|
public boolean moveToPosition(int pos) {
|
||||||
if (pos > 0) {
|
if (pos >= getCount() || pos < -1) {
|
||||||
throw new IllegalArgumentException();
|
|
||||||
}
|
|
||||||
if (pos >= getCount()) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
mPosition = pos;
|
mPosition = pos;
|
||||||
@ -336,11 +335,7 @@ public final class ContentCache extends LinkedHashMap<String, Cursor> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean moveToPrevious() {
|
public boolean moveToPrevious() {
|
||||||
if (mPosition == 0) {
|
return moveToPosition(mPosition - 1);
|
||||||
mPosition--;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -168,13 +168,7 @@ public class ContentCacheTests extends ProviderTestCase2<EmailProvider> {
|
|||||||
assertEquals(0, cursor.getPosition());
|
assertEquals(0, cursor.getPosition());
|
||||||
cursor.moveToPosition(0);
|
cursor.moveToPosition(0);
|
||||||
assertEquals(0, cursor.getPosition());
|
assertEquals(0, cursor.getPosition());
|
||||||
// And something that should
|
assertFalse(cursor.moveToPosition(1));
|
||||||
try {
|
|
||||||
cursor.moveToPosition(1);
|
|
||||||
fail("Shouldn't be able to move to position > 0");
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
// Correct
|
|
||||||
}
|
|
||||||
|
|
||||||
cursor.close();
|
cursor.close();
|
||||||
// We've closed the cached cursor; make sure
|
// We've closed the cached cursor; make sure
|
||||||
|
Loading…
Reference in New Issue
Block a user