summaryrefslogtreecommitdiffstats
path: root/src/com
diff options
context:
space:
mode:
authorChih-Chung Chang <chihchung@google.com>2009-07-09 10:27:02 +0800
committerChih-Chung Chang <chihchung@google.com>2009-07-09 16:15:38 +0800
commit2c28c55197bd37f1f199dd9884c4bfca7ea6ff0e (patch)
tree1e56a5ebdfa51cc077d11f8e4cde03eed0c83466 /src/com
parenta274cf1800a18e94653ee999f19c7d4844ad3d80 (diff)
downloadLegacyCamera-2c28c55197bd37f1f199dd9884c4bfca7ea6ff0e.zip
LegacyCamera-2c28c55197bd37f1f199dd9884c4bfca7ea6ff0e.tar.gz
LegacyCamera-2c28c55197bd37f1f199dd9884c4bfca7ea6ff0e.tar.bz2
Fix 1962656: Going to gallery when sd card is full causes a crash.
Also simplify the thumbnail reading code. I think we don't need to check the thumbnail magic being id because all current thumbnail files should have random number and not id. (see bug 1240638 for date).
Diffstat (limited to 'src/com')
-rw-r--r--src/com/android/camera/ImageLoader.java2
-rw-r--r--src/com/android/camera/gallery/BaseImage.java27
-rw-r--r--src/com/android/camera/gallery/BaseImageList.java23
-rw-r--r--src/com/android/camera/gallery/MiniThumbFile.java8
4 files changed, 38 insertions, 22 deletions
diff --git a/src/com/android/camera/ImageLoader.java b/src/com/android/camera/ImageLoader.java
index da6ea83..d93934b 100644
--- a/src/com/android/camera/ImageLoader.java
+++ b/src/com/android/camera/ImageLoader.java
@@ -297,10 +297,12 @@ class ThumbnailChecker {
Log.e(TAG, "Failed to check thumbnail..."
+ " was the sd card removed? - " + ex.getMessage());
stopCheckingThumbnails();
+ return;
}
if (!mThumbCheckCallback.checking(mNextToCheck, mTotalToCheck)) {
stopCheckingThumbnails();
+ return;
}
mNextToCheck++;
diff --git a/src/com/android/camera/gallery/BaseImage.java b/src/com/android/camera/gallery/BaseImage.java
index 815c0ef..0235afa 100644
--- a/src/com/android/camera/gallery/BaseImage.java
+++ b/src/com/android/camera/gallery/BaseImage.java
@@ -297,20 +297,21 @@ public abstract class BaseImage implements IImage {
public Bitmap miniThumbBitmap() {
try {
long id = mId;
- long dbMagic = mMiniThumbMagic;
- if (dbMagic == 0 || dbMagic == id) {
- dbMagic = ((BaseImageList)
- getContainer()).checkThumbnail(this, null);
- }
synchronized (sMiniThumbData) {
- dbMagic = mMiniThumbMagic;
- byte [] data = mContainer.getMiniThumbFromFile(id,
- sMiniThumbData, dbMagic);
+ byte [] data = null;
+
+ // Try to get it from the file.
+ if (mMiniThumbMagic != 0) {
+ data = mContainer.getMiniThumbFromFile(id, sMiniThumbData,
+ mMiniThumbMagic);
+ }
+
+ // If it does not exist, try to create the thumbnail
if (data == null) {
byte[][] createdThumbData = new byte[1][];
try {
- dbMagic = ((BaseImageList) getContainer())
+ ((BaseImageList) getContainer())
.checkThumbnail(this, createdThumbData);
} catch (IOException ex) {
// Typically IOException because the sd card is full.
@@ -319,13 +320,11 @@ public abstract class BaseImage implements IImage {
}
data = createdThumbData[0];
}
+
if (data == null) {
- data = mContainer.getMiniThumbFromFile(id, sMiniThumbData,
- dbMagic);
- }
- if (data == null) {
- // Unable to get mini-thumb data from file.
+ // Unable to get mini-thumb.
}
+
if (data != null) {
Bitmap b = BitmapFactory.decodeByteArray(data, 0,
data.length);
diff --git a/src/com/android/camera/gallery/BaseImageList.java b/src/com/android/camera/gallery/BaseImageList.java
index b49acd1..2f6afba 100644
--- a/src/com/android/camera/gallery/BaseImageList.java
+++ b/src/com/android/camera/gallery/BaseImageList.java
@@ -188,7 +188,11 @@ public abstract class BaseImageList implements IImageList {
values.put(Thumbnails.IMAGE_ID, imageId);
values.put(Thumbnails.HEIGHT, height);
values.put(Thumbnails.WIDTH, width);
- return mContentResolver.insert(mThumbUri, values);
+ try {
+ return mContentResolver.insert(mThumbUri, values);
+ } catch (Exception ex) {
+ return null;
+ }
}
private static final Random sRandom =
@@ -212,8 +216,12 @@ public abstract class BaseImageList implements IImageList {
int width = options.outWidth;
int height = options.outHeight;
if (width >= IImage.THUMBNAIL_TARGET_SIZE
- && height >= IImage.THUMBNAIL_TARGET_SIZE
- && storeThumbnail(thumbData, id, width, height)) {
+ && height >= IImage.THUMBNAIL_TARGET_SIZE) {
+
+ // We do not check the return value of storeThumbnail because
+ // we should return the mini thumb even if the storing fails.
+ storeThumbnail(thumbData, id, width, height);
+
// this is used for *encoding* the minithumb, so
// we don't want to dither or convert to 565 here.
//
@@ -264,7 +272,7 @@ public abstract class BaseImageList implements IImageList {
* thumbnail even if the sdcard is full.
* @throws IOException
*/
- public long checkThumbnail(BaseImage existingImage,
+ public void checkThumbnail(BaseImage existingImage,
byte[][] createdThumbnailData) throws IOException {
long magic, id;
@@ -273,8 +281,8 @@ public abstract class BaseImageList implements IImageList {
if (magic != 0) {
long fileMagic = mMiniThumbFile.getMagic(id);
- if (fileMagic == magic && magic != 0 && magic != id) {
- return magic;
+ if (fileMagic == magic) {
+ return;
}
}
@@ -311,6 +319,8 @@ public abstract class BaseImageList implements IImageList {
if (createdThumbnailData != null) {
createdThumbnailData[0] = data;
}
+
+ // This could throw IOException.
saveMiniThumbToFile(data, id, magic);
}
@@ -319,7 +329,6 @@ public abstract class BaseImageList implements IImageList {
mContentResolver.update(
existingImage.fullSizeImageUri(), values, null, null);
existingImage.mMiniThumbMagic = magic;
- return magic;
}
// TODO: Change public to protected
diff --git a/src/com/android/camera/gallery/MiniThumbFile.java b/src/com/android/camera/gallery/MiniThumbFile.java
index 1a94486..a08cb77 100644
--- a/src/com/android/camera/gallery/MiniThumbFile.java
+++ b/src/com/android/camera/gallery/MiniThumbFile.java
@@ -79,7 +79,13 @@ class MiniThumbFile {
try {
mMiniThumbFile = new RandomAccessFile(f, "rw");
} catch (IOException ex) {
- // ignore exception
+ // Open as read-only so we can at least read the existing
+ // thumbnails.
+ try {
+ mMiniThumbFile = new RandomAccessFile(f, "r");
+ } catch (IOException ex2) {
+ // ignore exception
+ }
}
}
return mMiniThumbFile;