DO NOT MERGE) ExifInterface: Make saveAttributes throw an exception before change
am: 659275dc30

Change-Id: I385c86e9753f1c99201a4f32b3c8b840da51376e
diff --git a/media/java/android/media/ExifInterface.java b/media/java/android/media/ExifInterface.java
index 654a08a..d51dbda 100644
--- a/media/java/android/media/ExifInterface.java
+++ b/media/java/android/media/ExifInterface.java
@@ -1034,6 +1034,7 @@
     private int mThumbnailOffset;
     private int mThumbnailLength;
     private byte[] mThumbnailBytes;
+    private boolean mIsSupportedFile;
 
     // Pattern to check non zero timestamp
     private static final Pattern sNonZeroTimePattern = Pattern.compile(".*[1-9].*");
@@ -1332,9 +1333,11 @@
         try {
             InputStream in = new FileInputStream(mFilename);
             getJpegAttributes(in);
+            mIsSupportedFile = true;
         } catch (IOException e) {
             // Ignore exceptions in order to keep the compatibility with the old versions of
             // ExifInterface.
+            mIsSupportedFile = false;
             Log.w(TAG, "Invalid image.", e);
         } finally {
             addDefaultValuesForCompatibility();
@@ -1363,6 +1366,10 @@
      * and make a single call rather than multiple calls for each attribute.
      */
     public void saveAttributes() throws IOException {
+        if (!mIsSupportedFile) {
+            throw new UnsupportedOperationException(
+                    "ExifInterface only supports saving attributes on JPEG formats.");
+        }
         // Keep the thumbnail in memory
         mThumbnailBytes = getThumbnail();