summaryrefslogtreecommitdiffstats
path: root/src/com/android/camera/Storage.java
diff options
context:
space:
mode:
authorRuben Brunk <rubenbrunk@google.com>2013-11-15 15:30:47 -0800
committerRuben Brunk <rubenbrunk@google.com>2013-11-18 11:24:35 -0800
commit3bf1cda53ebd85152fa9eed3ea8c9652a944df9b (patch)
treebccc1d8d76483e8235515a3a8acfb16c775e9d75 /src/com/android/camera/Storage.java
parent9db4ac802c6f635bdc56c69f20be08e054ba2926 (diff)
downloadandroid_packages_apps_Snap-3bf1cda53ebd85152fa9eed3ea8c9652a944df9b.tar.gz
android_packages_apps_Snap-3bf1cda53ebd85152fa9eed3ea8c9652a944df9b.tar.bz2
android_packages_apps_Snap-3bf1cda53ebd85152fa9eed3ea8c9652a944df9b.zip
gcam: Clean up placeholders, and add deletion robustness.
Bug: 11708734 Change-Id: I8a017a382f12165be27afbf78e733bcc1fc0ef6f
Diffstat (limited to 'src/com/android/camera/Storage.java')
-rw-r--r--src/com/android/camera/Storage.java41
1 files changed, 26 insertions, 15 deletions
diff --git a/src/com/android/camera/Storage.java b/src/com/android/camera/Storage.java
index 499d03029..b09eedafe 100644
--- a/src/com/android/camera/Storage.java
+++ b/src/com/android/camera/Storage.java
@@ -144,21 +144,11 @@ public class Storage {
getContentValuesForData(title, date, location, orientation, jpegLength, path,
width, height, mimeType);
- Uri uri = null;
- try {
- uri = resolver.insert(Images.Media.EXTERNAL_CONTENT_URI, values);
- } catch (Throwable th) {
- // This can happen when the external volume is already mounted, but
- // MediaScanner has not notify MediaProvider to add that volume.
- // The picture is still safe and MediaScanner will find it and
- // insert it into MediaProvider. The only problem is that the user
- // cannot click the thumbnail to review the picture.
- Log.e(TAG, "Failed to write MediaStore" + th);
- }
- return uri;
+ return insertImage(resolver, values);
}
- // Overwrites the file and updates the MediaStore
+ // Overwrites the file and updates the MediaStore, or inserts the image if
+ // one does not already exist.
public static void updateImage(Uri imageUri, ContentResolver resolver, String title, long date,
Location location, int orientation, ExifInterface exif, byte[] jpeg, int width,
int height, String mimeType) {
@@ -168,7 +158,8 @@ public class Storage {
width, height, mimeType);
}
- // Updates the image values in MediaStore
+ // Updates the image values in MediaStore, or inserts the image if one does
+ // not already exist.
public static void updateImage(Uri imageUri, ContentResolver resolver, String title,
long date, Location location, int orientation, int jpegLength,
String path, int width, int height, String mimeType) {
@@ -179,7 +170,12 @@ public class Storage {
// Update the MediaStore
int rowsModified = resolver.update(imageUri, values, null, null);
- if (rowsModified != 1) {
+
+ if (rowsModified == 0) {
+ // If no prior row existed, insert a new one.
+ Log.w(TAG, "updateImage called with no prior image at uri: " + imageUri);
+ insertImage(resolver, values);
+ } else if (rowsModified != 1) {
// This should never happen
throw new IllegalStateException("Bad number of rows (" + rowsModified
+ ") updated for uri: " + imageUri);
@@ -233,4 +229,19 @@ public class Storage {
Log.e(TAG, "Failed to create " + nnnAAAAA.getPath());
}
}
+
+ private static Uri insertImage(ContentResolver resolver, ContentValues values) {
+ Uri uri = null;
+ try {
+ uri = resolver.insert(Images.Media.EXTERNAL_CONTENT_URI, values);
+ } catch (Throwable th) {
+ // This can happen when the external volume is already mounted, but
+ // MediaScanner has not notify MediaProvider to add that volume.
+ // The picture is still safe and MediaScanner will find it and
+ // insert it into MediaProvider. The only problem is that the user
+ // cannot click the thumbnail to review the picture.
+ Log.e(TAG, "Failed to write MediaStore" + th);
+ }
+ return uri;
+ }
}