am 2671ba8c: Merge "Handle locations with more than 30 chars for lat/lon."

* commit '2671ba8c47ffc40ae16b0861cd59547666147758':
  Handle locations with more than 30 chars for lat/lon.
diff --git a/Android.mk b/Android.mk
index 4754738..8933df8 100644
--- a/Android.mk
+++ b/Android.mk
@@ -15,12 +15,14 @@
 #
 LOCAL_PATH := $(my-dir)
 
+#########################################
+# non-jni part
+
 include $(CLEAR_VARS)
 
-LOCAL_MODULE_TAGS := user
+LOCAL_MODULE_TAGS := optional
 
 LOCAL_SRC_FILES:= \
-	main.c \
 	exif.c \
 	gpsinfo.c \
 	iptc.c \
@@ -31,8 +33,32 @@
 LOCAL_MODULE := libexif
 
 LOCAL_SHARED_LIBRARIES := \
-	libnativehelper \
 	libcutils \
 	libutils
 
 include $(BUILD_SHARED_LIBRARY)
+
+#########################################
+# jni part
+
+# allow jni build if java is supported, necessary for PDK
+ifneq ($(TARGET_BUILD_JAVA_SUPPORT_LEVEL),)
+
+include $(CLEAR_VARS)
+
+LOCAL_MODULE_TAGS := optional
+
+LOCAL_SRC_FILES:= \
+	main.c
+
+LOCAL_MODULE := libexif_jni
+
+LOCAL_SHARED_LIBRARIES := \
+	libnativehelper \
+	libcutils \
+	libutils \
+	libexif
+
+include $(BUILD_SHARED_LIBRARY)
+
+endif # JAVA_SUPPORT
diff --git a/exif.c b/exif.c
index 60aec70..381d9dc 100644
--- a/exif.c
+++ b/exif.c
@@ -28,7 +28,7 @@
 #undef SUPERDEBUG
 
 #ifdef SUPERDEBUG
-#define printf LOGE
+#define printf ALOGE
 #endif
 
 //--------------------------------------------------------------------------
@@ -311,6 +311,11 @@
     return -1;
 }
 
+int IsDateTimeTag(unsigned short tag)
+{
+    return ((tag == TAG_DATETIME)? TRUE: FALSE);
+}
+
 //--------------------------------------------------------------------------
 // Convert a 16 bit unsigned value to file's native byte order
 //--------------------------------------------------------------------------
@@ -1134,7 +1139,9 @@
         Put32u(Buffer+(*DirIndex) + 8, (*DataWriteIndex)-8);   // Pointer
         char* curElement = strtok((char*)value, ",");
         int i;
-        for (i = 0; i < components && curElement != NULL; i++) {
+
+        // (components == -1) Need to handle lists with unknown length too
+        for (i = 0; ((i < components) || (components == -1)) && curElement != NULL; i++) {
 #ifdef SUPERDEBUG
             printf("processing component %s format %s", curElement, formatStr(format));
 #endif
@@ -1157,6 +1164,11 @@
                     Put32u(Buffer+(*DataWriteIndex) + 4, denominator);
                     (*DataWriteIndex) += 8;
                 }
+            } else if ((components == -1) && ((format == FMT_USHORT) || (format == FMT_SSHORT))) {
+                // variable components need to go into data write area
+                value = atoi(curElement);
+                Put16u(Buffer+(*DataWriteIndex), value);
+                (*DataWriteIndex) += 4;
             } else {
                 // TODO: doesn't handle multiple components yet -- if more than one, have to put in data write area.
                 value = atoi(curElement);
@@ -1193,7 +1205,7 @@
 // Create minimal exif header - just date and thumbnail pointers,
 // so that date and thumbnail may be filled later.
 //--------------------------------------------------------------------------
-static void create_EXIF_internal(ExifElement_t* elements, int exifTagCount, int gpsTagCount, char* Buffer)
+static void create_EXIF_internal(ExifElement_t* elements, int exifTagCount, int gpsTagCount, int hasDateTimeTag, char* Buffer)
 {
     unsigned short NumEntries;
     int DataWriteIndex;
@@ -1201,7 +1213,7 @@
     int DirExifLink = 0;
 
 #ifdef SUPERDEBUG
-    LOGE("create_EXIF %d exif elements, %d gps elements", exifTagCount, gpsTagCount);
+    ALOGE("create_EXIF %d exif elements, %d gps elements", exifTagCount, gpsTagCount);
 #endif
     
     MotorolaOrder = 0;
@@ -1214,21 +1226,26 @@
 
     {
         DirIndex = DataWriteIndex;
-        NumEntries = 2 + exifTagCount;  // the two extra are the datetime and the thumbnail
+        NumEntries = 1 + exifTagCount;  // the extra is the thumbnail
         if (gpsTagCount) {
             ++NumEntries;       // allow for the GPS info tag
         }
+        if (!hasDateTimeTag) {
+            // We have to write extra date time tag. The entry number should be
+            // adjusted.
+            ++NumEntries;
+        }
         DataWriteIndex += 2 + NumEntries*12 + 4;
 
         Put16u(Buffer+DirIndex, NumEntries); // Number of entries
         DirIndex += 2;
   
         // Entries go here...
-        {
+        if (!hasDateTimeTag) {
             // Date/time entry
             char* dateTime = NULL;
             char dateBuf[20];
-            if (ImageInfo.numDateTimeTags){
+            if (ImageInfo.numDateTimeTags) {
                 // If we had a pre-existing exif header, use time from that.
                 dateTime = ImageInfo.DateTime;
             } else {
@@ -1257,7 +1274,7 @@
                     continue;
                 }
 #ifdef SUPERDEBUG
-                LOGE("create_EXIF saving tag %x value \"%s\"",elements[i].Tag, elements[i].Value);
+                ALOGE("create_EXIF saving tag %x value \"%s\"",elements[i].Tag, elements[i].Value);
 #endif
                 writeExifTagAndData(elements[i].Tag,
                                     entry->Format,
@@ -1268,7 +1285,7 @@
                                     &DirIndex,
                                     &DataWriteIndex);
             }
-        
+
             if (gpsTagCount) {
                 // Link to gps dir entry
                 writeExifTagAndData(TAG_GPSINFO,
@@ -1323,7 +1340,7 @@
                     continue;
                 }
 #ifdef SUPERDEBUG
-                LOGE("create_EXIF saving GPS tag %x value \"%s\"",elements[i].Tag, elements[i].Value);
+                ALOGE("create_EXIF saving GPS tag %x value \"%s\"",elements[i].Tag, elements[i].Value);
 #endif
                 writeExifTagAndData(elements[i].Tag,
                                     entry->Format,
@@ -1405,7 +1422,7 @@
     }
 }
 
-void create_EXIF(ExifElement_t* elements, int exifTagCount, int gpsTagCount)
+void create_EXIF(ExifElement_t* elements, int exifTagCount, int gpsTagCount, int hasDateTimeTag)
 {
     // It is hard to calculate exact necessary size for editing the exif
     // header dynamically, so we are using the maximum size of EXIF, 64K
@@ -1413,7 +1430,7 @@
     char* Buffer = malloc(EXIF_MAX_SIZE);
 
     if (Buffer != NULL) {
-        create_EXIF_internal(elements, exifTagCount, gpsTagCount, Buffer);
+        create_EXIF_internal(elements, exifTagCount, gpsTagCount, hasDateTimeTag, Buffer);
         free(Buffer);
     } else {
         ErrFatal("Could not allocate memory");
diff --git a/gpsinfo.c b/gpsinfo.c
index 2661e52..cbf261e 100644
--- a/gpsinfo.c
+++ b/gpsinfo.c
@@ -60,7 +60,7 @@
 #undef SUPERDEBUG
 
 #ifdef SUPERDEBUG
-#define printf LOGE
+#define printf ALOGE
 #endif
 
 
@@ -278,7 +278,7 @@
                         (char*)(ValuePtr + EXIF_ASCII_PREFIX_LEN), length);
                     ImageInfo.GpsProcessingMethod[length] = 0;
                 } else {
-                    LOGW("Unsupported encoding for GPSProcessingMethod");
+                    ALOGW("Unsupported encoding for GPSProcessingMethod");
                 }
                 break;
         }
diff --git a/jhead.c b/jhead.c
index 5740db6..7ecd84c 100644
--- a/jhead.c
+++ b/jhead.c
@@ -104,7 +104,7 @@
 //--------------------------------------------------------------------------
 void ErrFatal(char * msg)
 {
-    LOGE("Error : %s\n", msg);
+    ALOGE("Error : %s\n", msg);
     if (CurrentFile) fprintf(stderr,"in file '%s'\n",CurrentFile);
     exit(EXIT_FAILURE);
 } 
@@ -115,8 +115,8 @@
 //--------------------------------------------------------------------------
 void ErrNonfatal(char * msg, int a1, int a2)
 {
-    LOGV("Nonfatal Error : ");
-    LOGV(msg, a1, a2);
+    ALOGV("Nonfatal Error : ");
+    ALOGV(msg, a1, a2);
     if (SupressNonFatalErrors) return;
 
     fprintf(stderr,"\nNonfatal Error : ");
@@ -911,7 +911,7 @@
 
     if (CreateExifSection){
         // Make a new minimal exif section
-        create_EXIF(NULL, 0, 0);
+        create_EXIF(NULL, 0, 0, 0);
         Modified = TRUE;
     }
 
@@ -1696,4 +1696,3 @@
 #endif
 
 #endif   // commented out -- security risk
-
diff --git a/jhead.h b/jhead.h
index a73c578..596bfea 100644
--- a/jhead.h
+++ b/jhead.h
@@ -181,8 +181,9 @@
 unsigned Get32u(void * Long);
 int Get32s(void * Long);
 void Put32u(void * Value, unsigned PutValue);
-void create_EXIF(ExifElement_t* elements, int exifTagCount, int gpsTagCount);
+void create_EXIF(ExifElement_t* elements, int exifTagCount, int gpsTagCount, int hasDateTimeTag);
 int TagNameToValue(const char* tagName);
+int IsDateTimeTag(unsigned short tag);
 
 //--------------------------------------------------------------------------
 // Exif format descriptor stuff
@@ -282,5 +283,3 @@
 #define M_DHT   0xC4
 #define M_DRI   0xDD
 #define M_IPTC  0xED          // IPTC marker
-
-
diff --git a/jpgfile.c b/jpgfile.c
index cb1cdfb..1ef9e99 100755
--- a/jpgfile.c
+++ b/jpgfile.c
@@ -24,7 +24,7 @@
 #undef SUPERDEBUG
 
 #ifdef SUPERDEBUG
-#define printf LOGE
+#define printf ALOGE
 #endif
 
 
@@ -165,7 +165,7 @@
 
         if (itemlen < 2){
 //            ErrFatal("invalid marker");
-			LOGE("invalid marker");
+			ALOGE("invalid marker");
 	        return FALSE;
         }
 
@@ -174,7 +174,7 @@
         Data = (uchar *)malloc(itemlen);
         if (Data == NULL){
 	    // ErrFatal("Could not allocate memory");
-	    LOGE("Could not allocate memory");
+	    ALOGE("Could not allocate memory");
 	    return 0;
         }
         Sections[SectionsRead].Data = Data;
@@ -186,7 +186,7 @@
         got = fread(Data+2, 1, itemlen-2, infile); // Read the whole section.
         if (got != itemlen-2){
 //            ErrFatal("Premature end of file?");
-		   LOGE("Premature end of file?");
+		   ALOGE("Premature end of file?");
 	      return FALSE;
         }
         SectionsRead += 1;
@@ -208,14 +208,14 @@
                     Data = (uchar *)malloc(size);
                     if (Data == NULL){
 		            // ErrFatal("could not allocate data for entire image");
-		            LOGE("could not allocate data for entire image");
+		            ALOGE("could not allocate data for entire image");
     		        return FALSE;
                     }
 
                     got = fread(Data, 1, size, infile);
                     if (got != size){
 			        // ErrFatal("could not read the rest of the image");
-			        LOGE("could not read the rest of the image");
+			        ALOGE("could not read the rest of the image");
 				    return FALSE;
                     }
 
@@ -359,7 +359,7 @@
         itemlen = (lh << 8) | ll;
 
         if (itemlen < 2) {
-            LOGE("invalid marker");
+            ALOGE("invalid marker");
             return FALSE;
         }
 
@@ -367,7 +367,7 @@
 
         Data = (uchar *)malloc(itemlen);
         if (Data == NULL) {
-            LOGE("Could not allocate memory");
+            ALOGE("Could not allocate memory");
             return 0;
         }
         Sections[SectionsRead].Data = Data;
@@ -377,7 +377,7 @@
         Data[1] = (uchar)ll;
 
         if (pos+itemlen-2 > buffer_size) {
-           LOGE("Premature end of file?");
+           ALOGE("Premature end of file?");
           return FALSE;
         }
 
@@ -397,12 +397,12 @@
                     size = buffer_size - pos;
 
                     if (size < 1) {
-                        LOGE("could not read the rest of the image");
+                        ALOGE("could not read the rest of the image");
                         return FALSE;
                     }
                     Data = (uchar *)malloc(size);
                     if (Data == NULL) {
-                        LOGE("%d: could not allocate data for entire image size: %d", __LINE__, size);
+                        ALOGE("%d: could not allocate data for entire image size: %d", __LINE__, size);
                         return FALSE;
                     }
 
@@ -418,7 +418,7 @@
                 return TRUE;
 
             case M_EOI:   // in case it's a tables-only JPEG stream
-                LOGE("No image in jpeg!\n");
+                ALOGE("No image in jpeg!\n");
                 return FALSE;
 
             case M_COM: // Comment section
@@ -448,7 +448,7 @@
                     }else if (memcmp(Data+2, "http:", 5) == 0){
                         Sections[SectionsRead-1].Type = M_XMP; // Change tag for internal purposes.
                         if (ShowTags){
-                            LOGD("Image cotains XMP section, %d bytes long\n", itemlen);
+                            ALOGD("Image cotains XMP section, %d bytes long\n", itemlen);
                             if (ShowTags){
                                 ShowXmp(Sections[SectionsRead-1]);
                             }
@@ -463,7 +463,7 @@
             case M_IPTC:
                 if (ReadMode & READ_METADATA){
                     if (ShowTags){
-                        LOGD("Image cotains IPTC section, %d bytes long\n", itemlen);
+                        ALOGD("Image cotains IPTC section, %d bytes long\n", itemlen);
                     }
                     // Note: We just store the IPTC section.  Its relatively straightforward
                     // and we don't act on any part of it, so just display it at parse time.
@@ -490,7 +490,7 @@
             default:
                 // Skip any other sections.
                 if (ShowTags){
-                    LOGD("Jpeg section marker 0x%02x size %d\n",marker, itemlen);
+                    ALOGD("Jpeg section marker 0x%02x size %d\n",marker, itemlen);
                 }
                 break;
         }
@@ -525,7 +525,7 @@
     infile = fopen(FileName, "rb"); // Unix ignores 'b', windows needs it.
 
     if (infile == NULL) {
-        LOGE("can't open '%s'", FileName);
+        ALOGE("can't open '%s'", FileName);
         fprintf(stderr, "can't open '%s'\n", FileName);
         return FALSE;
     }
@@ -534,7 +534,7 @@
     printf("ReadJpegSections");
     ret = ReadJpegSections(infile, ReadMode);
     if (!ret){
-        LOGV("Cannot parse JPEG sections for file: %s", FileName);
+        ALOGV("Cannot parse JPEG sections for file: %s", FileName);
         fprintf(stderr,"Not JPEG: %s\n",FileName);
     }
 
@@ -578,7 +578,7 @@
         return TRUE;
     }else{
         // ErrFatal("Could not write thumbnail file");
-        LOGE("Could not write thumbnail file");
+        ALOGE("Could not write thumbnail file");
         return FALSE;
     }
 }
@@ -603,7 +603,7 @@
         // of the exif header, which is risky, and jhad doesn't know how to do.
         fprintf(stderr,"Image contains no thumbnail to replace - add is not possible\n");
 #ifdef SUPERDEBUG
-        LOGE("Image contains no thumbnail to replace - add is not possible\n");
+        ALOGE("Image contains no thumbnail to replace - add is not possible\n");
 #endif
         return FALSE;
     }
@@ -611,7 +611,7 @@
     if (Thumb) {
         if (ThumbLen + ImageInfo.ThumbnailOffset > 0x10000-20){
 	        //ErrFatal("Thumbnail is too large to insert into exif header");
-	        LOGE("Thumbnail is too large to insert into exif header");
+	        ALOGE("Thumbnail is too large to insert into exif header");
 	        return FALSE;
         }
     } else {
@@ -642,7 +642,7 @@
     ExifSection->Size = NewExifSize;
 
 #ifdef SUPERDEBUG
-        LOGE("ReplaceThumbnail successful thumblen %d", ThumbLen);
+        ALOGE("ReplaceThumbnail successful thumblen %d", ThumbLen);
 #endif
     return TRUE;
 }
@@ -668,7 +668,7 @@
         // of the exif header, which is risky, and jhad doesn't know how to do.
         fprintf(stderr,"Image contains no thumbnail to replace - add is not possible\n");
 #ifdef SUPERDEBUG
-        LOGE("Image contains no thumbnail to replace - add is not possible\n");
+        ALOGE("Image contains no thumbnail to replace - add is not possible\n");
 #endif
         return FALSE;
     }
@@ -678,7 +678,7 @@
 
         if (ThumbnailFile == NULL){
 	        //ErrFatal("Could not read thumbnail file");
-	        LOGE("Could not read thumbnail file");
+	        ALOGE("Could not read thumbnail file");
             return FALSE;
         }
 
@@ -690,7 +690,7 @@
 
         if (ThumbLen + ImageInfo.ThumbnailOffset > 0x10000-20){
 	        //ErrFatal("Thumbnail is too large to insert into exif header");
-	        LOGE("Thumbnail is too large to insert into exif header");
+	        ALOGE("Thumbnail is too large to insert into exif header");
 	        return FALSE;
         }
     }else{
@@ -723,7 +723,7 @@
     ExifSection->Size = NewExifSize;
 
 #ifdef SUPERDEBUG
-        LOGE("ReplaceThumbnail successful thumblen %d", ThumbLen);
+        ALOGE("ReplaceThumbnail successful thumblen %d", ThumbLen);
 #endif
     return TRUE;
 }
@@ -787,13 +787,13 @@
     int a;
 
     if (!HaveAll){
-        LOGE("Can't write back - didn't read all");
+        ALOGE("Can't write back - didn't read all");
         return FALSE;
     }
 
     outfile = fopen(FileName,"wb");
     if (outfile == NULL){
-        LOGE("Could not open file for write");
+        ALOGE("Could not open file for write");
         return FALSE;
     }
 
@@ -820,7 +820,7 @@
 	nWrite = fwrite(Sections[a].Data, 1, Sections[a].Size, outfile);
         writeOk = (nWrite == Sections[a].Size);
         if(!writeOk){
-            LOGE("write section %d failed expect %d actual %d",a,Sections[a].Size,nWrite);
+            ALOGE("write section %d failed expect %d actual %d",a,Sections[a].Size,nWrite);
             break;
         }
     }
@@ -830,7 +830,7 @@
         nWrite = fwrite(Sections[a].Data, 1,Sections[a].Size, outfile);
 	writeOk = (nWrite == Sections[a].Size);
         if (!writeOk){
-            LOGE("write section %d failed expect %d actual %d",a,Sections[a].Size,nWrite);
+            ALOGE("write section %d failed expect %d actual %d",a,Sections[a].Size,nWrite);
         }
     }
        
@@ -855,7 +855,7 @@
     }
 
     if (!HaveAll){
-        LOGE("Can't write back - didn't read all");
+        ALOGE("Can't write back - didn't read all");
         return FALSE;
     }
 
@@ -1004,7 +1004,7 @@
 
     if (SectionsRead < NewIndex){
         // ErrFatal("Too few sections!");
-        LOGE("Too few sections!");
+        ALOGE("Too few sections!");
         return FALSE;
     }
 
diff --git a/main.c b/main.c
index 9ad6443..b8f1445 100644
--- a/main.c
+++ b/main.c
@@ -69,7 +69,7 @@
 
 static int loadExifInfo(const char* FileName, int readJPG) {
 #ifdef SUPERDEBUG
-    LOGE("loadExifInfo");
+    ALOGE("loadExifInfo");
 #endif
     int Modified = FALSE;
     ReadMode_t ReadMode = READ_METADATA;
@@ -79,7 +79,7 @@
     }
 
 #ifdef SUPERDEBUG
-    LOGE("ResetJpgfile");
+    ALOGE("ResetJpgfile");
 #endif
     ResetJpgfile();
 
@@ -100,7 +100,7 @@
 
     strncpy(ImageInfo.FileName, FileName, PATH_MAX);
 #ifdef SUPERDEBUG
-    LOGE("ReadJpegFile");
+    ALOGE("ReadJpegFile");
 #endif
     return ReadJpegFile(FileName, ReadMode);
 }
@@ -110,7 +110,7 @@
     struct stat buf;
 
 #ifdef SUPERDEBUG
-    LOGE("Modified: %s\n", filename);
+    ALOGE("Modified: %s\n", filename);
 #endif
 
     strncpy(backupName, filename, 395);
@@ -118,25 +118,25 @@
 
     // Remove any .old file name that may pre-exist
 #ifdef SUPERDEBUG
-    LOGE("removing backup %s", backupName);
+    ALOGE("removing backup %s", backupName);
 #endif
     unlink(backupName);
 
     // Rename the old file.
 #ifdef SUPERDEBUG
-    LOGE("rename %s to %s", filename, backupName);
+    ALOGE("rename %s to %s", filename, backupName);
 #endif
     rename(filename, backupName);
 
     // Write the new file.
 #ifdef SUPERDEBUG
-    LOGE("WriteJpegFile %s", filename);
+    ALOGE("WriteJpegFile %s", filename);
 #endif
     if (WriteJpegFile(filename)) {
 
         // Copy the access rights from original file
 #ifdef SUPERDEBUG
-        LOGE("stating old file %s", backupName);
+        ALOGE("stating old file %s", backupName);
 #endif
         if (stat(backupName, &buf) == 0){
             // set Unix access rights and time to new file
@@ -151,15 +151,15 @@
 
         // Now that we are done, remove original file.
 #ifdef SUPERDEBUG
-        LOGE("unlinking old file %s", backupName);
+        ALOGE("unlinking old file %s", backupName);
 #endif
         unlink(backupName);
 #ifdef SUPERDEBUG
-        LOGE("returning from saveJPGFile");
+        ALOGE("returning from saveJPGFile");
 #endif
     } else {
 #ifdef SUPERDEBUG
-        LOGE("WriteJpegFile failed, restoring from backup file");
+        ALOGE("WriteJpegFile failed, restoring from backup file");
 #endif
         // move back the backup file
         rename(backupName, filename);
@@ -168,7 +168,7 @@
 
 void copyThumbnailData(uchar* thumbnailData, int thumbnailLen) {
 #ifdef SUPERDEBUG
-    LOGE("******************************** copyThumbnailData\n");
+    ALOGE("******************************** copyThumbnailData\n");
 #endif
     Section_t* ExifSection = FindSection(M_EXIF);
     if (ExifSection == NULL) {
@@ -195,7 +195,7 @@
 static void saveAttributes(JNIEnv *env, jobject jobj, jstring jfilename, jstring jattributes)
 {
 #ifdef SUPERDEBUG
-    LOGE("******************************** saveAttributes\n");
+    ALOGE("******************************** saveAttributes\n");
 #endif
     // format of attributes string passed from java:
     // "attrCnt attr1=valueLen value1attr2=value2Len value2..."
@@ -209,14 +209,14 @@
         goto exit;
     }
 #ifdef SUPERDEBUG
-    LOGE("attributes %s\n", attributes);
+    ALOGE("attributes %s\n", attributes);
 #endif
 
     // Get the number of attributes - it's the first number in the string.
     attrCnt = atoi(attributes);
     char* attrPtr = strchr(attributes, ' ') + 1;
 #ifdef SUPERDEBUG
-    LOGE("attribute count %d attrPtr %s\n", attrCnt, attrPtr);
+    ALOGE("attribute count %d attrPtr %s\n", attrCnt, attrPtr);
 #endif
 
     // Load all the hash exif elements into a more c-like structure
@@ -230,6 +230,7 @@
 
     int i;
     char tag[100];
+    int hasDateTimeTag = FALSE;
     int gpsTagCount = 0;
     int exifTagCount = 0;
 
@@ -239,13 +240,13 @@
         char* tagEnd = strchr(attrPtr, '=');
         if (tagEnd == 0) {
 #ifdef SUPERDEBUG
-            LOGE("saveAttributes: couldn't find end of tag");
+            ALOGE("saveAttributes: couldn't find end of tag");
 #endif
             goto exit;
         }
         if (tagEnd - attrPtr > 99) {
 #ifdef SUPERDEBUG
-            LOGE("saveAttributes: attribute tag way too long");
+            ALOGE("saveAttributes: attribute tag way too long");
 #endif
             goto exit;
         }
@@ -263,12 +264,16 @@
         }
         attrPtr = tagEnd + 1;
 
+        if (IsDateTimeTag(exifElementTable[i].Tag)) {
+            hasDateTimeTag = TRUE;
+        }
+
         // next get the length of the attribute value
         int valueLen = atoi(attrPtr);
         attrPtr = strchr(attrPtr, ' ') + 1;
         if (attrPtr == 0) {
 #ifdef SUPERDEBUG
-            LOGE("saveAttributes: couldn't find end of value len");
+            ALOGE("saveAttributes: couldn't find end of value len");
 #endif
             goto exit;
         }
@@ -283,14 +288,14 @@
         attrPtr += valueLen;
 
 #ifdef SUPERDEBUG
-        LOGE("tag %s id %d value %s data length=%d isGps=%d", tag, exifElementTable[i].Tag,
+        ALOGE("tag %s id %d value %s data length=%d isGps=%d", tag, exifElementTable[i].Tag,
             exifElementTable[i].Value, exifElementTable[i].DataLength, exifElementTable[i].GpsTag);
 #endif
     }
 
     filename = (*env)->GetStringUTFChars(env, jfilename, NULL);
 #ifdef SUPERDEBUG
-    LOGE("Call loadAttributes() with filename is %s. Loading exif info\n", filename);
+    ALOGE("Call loadAttributes() with filename is %s. Loading exif info\n", filename);
 #endif
     loadExifInfo(filename, TRUE);
 
@@ -298,7 +303,7 @@
 //    DumpExifMap = TRUE;
     ShowTags = TRUE;
     ShowImageInfo(TRUE);
-    LOGE("create exif 2");
+    ALOGE("create exif 2");
 #endif
 
     // If the jpg file has a thumbnail, preserve it.
@@ -315,7 +320,7 @@
         }
     }
 
-    create_EXIF(exifElementTable, exifTagCount, gpsTagCount);
+    create_EXIF(exifElementTable, exifTagCount, gpsTagCount, hasDateTimeTag);
 
     if (thumbnailData) {
         copyThumbnailData(thumbnailData, thumbnailLength);
@@ -323,7 +328,7 @@
 
 exit:
 #ifdef SUPERDEBUG
-    LOGE("cleaning up now in saveAttributes");
+    ALOGE("cleaning up now in saveAttributes");
 #endif
     // try to clean up resources
     if (attributes) {
@@ -343,7 +348,7 @@
         free(thumbnailData);
     }
 #ifdef SUPERDEBUG
-    LOGE("returning from saveAttributes");
+    ALOGE("returning from saveAttributes");
 #endif
 
 // Temporarily saving these commented out lines because they represent a lot of figuring out
@@ -390,7 +395,7 @@
 static jboolean appendThumbnail(JNIEnv *env, jobject jobj, jstring jfilename, jstring jthumbnailfilename)
 {
 #ifdef SUPERDEBUG
-    LOGE("******************************** appendThumbnail\n");
+    ALOGE("******************************** appendThumbnail\n");
 #endif
 
     const char* filename = (*env)->GetStringUTFChars(env, jfilename, NULL);
@@ -402,7 +407,7 @@
         return JNI_FALSE;
     }
  #ifdef SUPERDEBUG
-     LOGE("*******before actual call to ReplaceThumbnail\n");
+     ALOGE("*******before actual call to ReplaceThumbnail\n");
      ShowImageInfo(TRUE);
  #endif
     ReplaceThumbnail(thumbnailfilename);
@@ -419,7 +424,7 @@
 static void commitChanges(JNIEnv *env, jobject jobj, jstring jfilename)
 {
 #ifdef SUPERDEBUG
-    LOGE("******************************** commitChanges\n");
+    ALOGE("******************************** commitChanges\n");
 #endif
     const char* filename = (*env)->GetStringUTFChars(env, jfilename, NULL);
     if (filename) {
@@ -432,7 +437,7 @@
 static jbyteArray getThumbnail(JNIEnv *env, jobject jobj, jstring jfilename)
 {
 #ifdef SUPERDEBUG
-    LOGE("******************************** getThumbnail\n");
+    ALOGE("******************************** getThumbnail\n");
 #endif
 
     const char* filename = (*env)->GetStringUTFChars(env, jfilename, NULL);
@@ -441,7 +446,7 @@
         Section_t* ExifSection = FindSection(M_EXIF);
         if (ExifSection == NULL ||  ImageInfo.ThumbnailSize == 0) {
 #ifdef SUPERDEBUG
-    LOGE("no exif section or size == 0, so no thumbnail\n");
+    ALOGE("no exif section or size == 0, so no thumbnail\n");
 #endif
             goto noThumbnail;
         }
@@ -450,13 +455,13 @@
         jbyteArray byteArray = (*env)->NewByteArray(env, ImageInfo.ThumbnailSize);
         if (byteArray == NULL) {
 #ifdef SUPERDEBUG
-    LOGE("couldn't allocate thumbnail memory, so no thumbnail\n");
+    ALOGE("couldn't allocate thumbnail memory, so no thumbnail\n");
 #endif
             goto noThumbnail;
         }
         (*env)->SetByteArrayRegion(env, byteArray, 0, ImageInfo.ThumbnailSize, thumbnailPointer);
 #ifdef SUPERDEBUG
-    LOGE("thumbnail size %d\n", ImageInfo.ThumbnailSize);
+    ALOGE("thumbnail size %d\n", ImageInfo.ThumbnailSize);
 #endif
         (*env)->ReleaseStringUTFChars(env, jfilename, filename);
         DiscardData();
@@ -485,7 +490,7 @@
     if (newLen >= bufLen) {
 #ifdef REALLOCTEST
         bufLen = newLen + 5;
-        LOGE("reallocing to %d", bufLen);
+        ALOGE("reallocing to %d", bufLen);
 #else
         bufLen = newLen + 500;
 #endif
@@ -497,7 +502,7 @@
     // append the new attribute and value
     snprintf(*buf + strlen(*buf), bufLen, "%s%s%s", key, valueLen, value);
 #ifdef SUPERDEBUG
-    LOGE("buf %s", *buf);
+    ALOGE("buf %s", *buf);
 #endif
     ++attributeCount;
     return bufLen;
@@ -529,7 +534,7 @@
 static jstring getAttributes(JNIEnv *env, jobject jobj, jstring jfilename)
 {
 #ifdef SUPERDEBUG
-    LOGE("******************************** getAttributes\n");
+    ALOGE("******************************** getAttributes\n");
 #endif
     const char* filename = (*env)->GetStringUTFChars(env, jfilename, NULL);
     loadExifInfo(filename, FALSE);
@@ -707,7 +712,7 @@
     free(buf);
 
 #ifdef SUPERDEBUG
-    LOGE("*********Returning result \"%s\"", finalResult);
+    ALOGE("*********Returning result \"%s\"", finalResult);
 #endif
     jstring result = ((*env)->NewStringUTF(env, finalResult));
     free(finalResult);