diff options
author | Chih-Chung Chang <chihchung@google.com> | 2009-08-28 20:14:42 +0800 |
---|---|---|
committer | Chih-Chung Chang <chihchung@google.com> | 2009-08-28 20:14:42 +0800 |
commit | d4271821a35c87769b004991793b1928c31b41bc (patch) | |
tree | 321582d2ba36c8063b43b23100ed36bacbfd682e | |
parent | 0f1e5801cbddffccf95e639b2096dd6c90b6af26 (diff) | |
download | LegacyCamera-d4271821a35c87769b004991793b1928c31b41bc.zip LegacyCamera-d4271821a35c87769b004991793b1928c31b41bc.tar.gz LegacyCamera-d4271821a35c87769b004991793b1928c31b41bc.tar.bz2 |
Fix 2059728: NPE in BaseImageList.getCursor
Return an empty image list if the cursor is not available.
Change-Id: Ib9f0b23668da7b3c29d208bd46c020e268a0b7f2
-rw-r--r-- | src/com/android/camera/ImageManager.java | 6 | ||||
-rw-r--r-- | src/com/android/camera/gallery/BaseImageList.java | 27 |
2 files changed, 11 insertions, 22 deletions
diff --git a/src/com/android/camera/ImageManager.java b/src/com/android/camera/ImageManager.java index db0ccf1..2148e73 100644 --- a/src/com/android/camera/ImageManager.java +++ b/src/com/android/camera/ImageManager.java @@ -327,11 +327,7 @@ public class ImageManager { Uri singleImageUri = param.mSingleImageUri; boolean isEmptyImageList = param.mIsEmptyImageList; - if (cr == null) { - return null; - } - - if (isEmptyImageList) { + if (isEmptyImageList || cr == null) { return new EmptyImageList(); } diff --git a/src/com/android/camera/gallery/BaseImageList.java b/src/com/android/camera/gallery/BaseImageList.java index 64bcc54..12bd212 100644 --- a/src/com/android/camera/gallery/BaseImageList.java +++ b/src/com/android/camera/gallery/BaseImageList.java @@ -67,20 +67,8 @@ public abstract class BaseImageList implements IImageList { mContentResolver = resolver; mCursor = createCursor(); - // If the media provider is killed, we will fail to get the cursor. - // This is a workaround to wait a bit and retry in the hope that the - // new instance of media provider will be created soon enough. if (mCursor == null) { - for (int i = 0; i < 10; i++) { - Log.w(TAG, "createCursor failed, retry..."); - try { - Thread.sleep(300); - } catch (InterruptedException ex) { - // ignore. - } - mCursor = createCursor(); - if (mCursor != null) break; - } + Log.w(TAG, "createCursor returns null."); } // TODO: We need to clear the cache because we may "reopen" the image @@ -336,7 +324,8 @@ public abstract class BaseImageList implements IImageList { public int getCount() { Cursor cursor = getCursor(); - synchronized (cursor) { + if (cursor == null) return 0; + synchronized (this) { return cursor.getCount(); } } @@ -346,7 +335,8 @@ public abstract class BaseImageList implements IImageList { } private Cursor getCursor() { - synchronized (mCursor) { + synchronized (this) { + if (mCursor == null) return null; if (mCursorDeactivated) { mCursor.requery(); mCursorDeactivated = false; @@ -359,7 +349,8 @@ public abstract class BaseImageList implements IImageList { BaseImage result = mCache.get(i); if (result == null) { Cursor cursor = getCursor(); - synchronized (cursor) { + if (cursor == null) return null; + synchronized (this) { result = cursor.moveToPosition(i) ? loadImageFromCursor(cursor) : null; @@ -402,6 +393,7 @@ public abstract class BaseImageList implements IImageList { protected abstract long getImageId(Cursor cursor); protected void invalidateCursor() { + if (mCursor == null) return; mCursor.deactivate(); mCursorDeactivated = true; } @@ -442,7 +434,8 @@ public abstract class BaseImageList implements IImageList { } // TODO: design a better method to get URI of specified ID Cursor cursor = getCursor(); - synchronized (cursor) { + if (cursor == null) return null; + synchronized (this) { cursor.moveToPosition(-1); // before first for (int i = 0; cursor.moveToNext(); ++i) { if (getImageId(cursor) == matchId) { |