Add GPS tags and timestamp to Exif when photo is saved

Patchset 2: Fix formatting
            Sync exif code of PhotoModule and PanoramaModule

Change-Id: I8b6f77687f01c537a2a3d5bb2b2d8b4ad21642c8
diff --git a/src/com/android/camera/PanoramaModule.java b/src/com/android/camera/PanoramaModule.java
index 57405ec..66cdc2d 100644
--- a/src/com/android/camera/PanoramaModule.java
+++ b/src/com/android/camera/PanoramaModule.java
@@ -914,12 +914,11 @@
             ExifInterface exif = new ExifInterface();
             try {
                 exif.readExif(jpegData);
-                exif.addGpsDateTimeStampTag(mTimeTaken);
                 exif.addDateTimeStampTag(ExifInterface.TAG_DATE_TIME, mTimeTaken,
                         TimeZone.getDefault());
                 exif.setTag(exif.buildTag(ExifInterface.TAG_ORIENTATION,
                         ExifInterface.getOrientationValueForRotation(orientation)));
-                writeLocation(loc, exif);
+                writeLocation(loc, mTimeTaken, exif);
                 exif.writeExif(jpegData, filepath);
             } catch (IOException e) {
                 Log.e(TAG, "Cannot set exif for " + filepath, e);
@@ -932,11 +931,12 @@
         return null;
     }
 
-    private static void writeLocation(Location location, ExifInterface exif) {
+    private static void writeLocation(Location location, long timestamp, ExifInterface exif) {
         if (location == null) {
             return;
         }
         exif.addGpsTags(location.getLatitude(), location.getLongitude());
+        exif.addGpsDateTimeStampTag(timestamp);
         exif.setTag(exif.buildTag(ExifInterface.TAG_GPS_PROCESSING_METHOD, location.getProvider()));
     }
 
diff --git a/src/com/android/camera/PhotoModule.java b/src/com/android/camera/PhotoModule.java
index 61982e5..282ada0 100644
--- a/src/com/android/camera/PhotoModule.java
+++ b/src/com/android/camera/PhotoModule.java
@@ -80,6 +80,7 @@
 import java.util.Collections;
 import java.util.Formatter;
 import java.util.List;
+import java.util.TimeZone;
 
 public class PhotoModule
     implements CameraModule,
@@ -890,6 +891,14 @@
                         exif.setTag(directionRefTag);
                         exif.setTag(directionTag);
                     }
+                    if (mLocation != null) {
+                        exif.addGpsTags(mLocation.getLatitude(), mLocation.getLongitude());
+                        exif.addGpsDateTimeStampTag(date);
+                        exif.setTag(exif.buildTag(ExifInterface.TAG_GPS_PROCESSING_METHOD,
+                                mLocation.getProvider()));
+                    }
+                    exif.addDateTimeStampTag(ExifInterface.TAG_DATE_TIME,
+                            date, TimeZone.getDefault());
 
                     if (isSamsungHDR) {
                         final long finalDate = date;