From f5ba161f66524e04e86b8821bac023273e1106da Mon Sep 17 00:00:00 2001 From: jinwu Date: Fri, 21 Sep 2018 18:00:28 +0800 Subject: SnapdragonCamera:Fix location recording Get location information from ExifInterface when location is not send to MediaSaveService Change-Id: I7bd49fc5cd303f5bc5b43edb8769156d693232df CRs-Fixed: 2279097 --- src/com/android/camera/CaptureModule.java | 3 ++- src/com/android/camera/MediaSaveService.java | 3 ++- src/com/android/camera/Storage.java | 27 ++++++++++++++++++++++----- 3 files changed, 26 insertions(+), 7 deletions(-) mode change 100644 => 100755 src/com/android/camera/MediaSaveService.java (limited to 'src') diff --git a/src/com/android/camera/CaptureModule.java b/src/com/android/camera/CaptureModule.java index 7bfee3041..0240607af 100755 --- a/src/com/android/camera/CaptureModule.java +++ b/src/com/android/camera/CaptureModule.java @@ -2438,7 +2438,7 @@ public class CaptureModule implements CameraModule, PhotoController, } } else { mActivity.getMediaSaveService().addImage(bytes, title, date, - null, image.getWidth(), image.getHeight(), orientation, null, + null, image.getWidth(), image.getHeight(), orientation, exif, mOnMediaSavedListener, mContentResolver, "jpeg"); if (mLongshotActive) { @@ -2765,6 +2765,7 @@ public class CaptureModule implements CameraModule, PhotoController, } else { Log.d(TAG, "no location - getRecordLocation: " + getRecordLocation()); } + builder.set(CaptureRequest.JPEG_ORIENTATION, CameraUtil.getJpegRotation(id, mOrientation)); builder.set(CaptureRequest.JPEG_THUMBNAIL_SIZE, mPictureThumbSize); builder.set(CaptureRequest.JPEG_THUMBNAIL_QUALITY, (byte)80); diff --git a/src/com/android/camera/MediaSaveService.java b/src/com/android/camera/MediaSaveService.java old mode 100644 new mode 100755 index 217f44f27..6a5f2b6d8 --- a/src/com/android/camera/MediaSaveService.java +++ b/src/com/android/camera/MediaSaveService.java @@ -36,6 +36,7 @@ import android.os.Binder; import android.os.IBinder; import android.provider.MediaStore.Video; import android.util.Log; +import android.widget.Toast; import com.android.camera.exif.ExifInterface; import com.android.camera.mpo.MpoData; @@ -279,7 +280,7 @@ public class MediaSaveService extends Service { if (f.exists() && f.isFile()) { size = (int) f.length(); } - return Storage.addImage(resolver, title, date, loc, orientation, + return Storage.addImage(resolver, title, date, loc, orientation, null, size, path, width, height, pictureFormat); } diff --git a/src/com/android/camera/Storage.java b/src/com/android/camera/Storage.java index 13f65e14c..d125ebe63 100755 --- a/src/com/android/camera/Storage.java +++ b/src/com/android/camera/Storage.java @@ -122,13 +122,13 @@ public class Storage { if (f.exists() && f.isFile()) { size = (int) f.length(); } - return addImage(resolver, title, date, location, orientation, + return addImage(resolver, title, date, location, orientation, exif, size, path, width, height, mimeType); } // Get a ContentValues object for the given photo data public static ContentValues getContentValuesForData(String title, - long date, Location location, int orientation, int jpegLength, + long date, Location location, int orientation, ExifInterface exif, int jpegLength, String path, int width, int height, String mimeType) { // Insert into MediaStore. ContentValues values = new ContentValues(9); @@ -152,22 +152,39 @@ public class Storage { if (location != null) { values.put(ImageColumns.LATITUDE, location.getLatitude()); values.put(ImageColumns.LONGITUDE, location.getLongitude()); + } else if (exif != null) { + double[] latlng = exif.getLatLongAsDoubles(); + if (latlng != null) { + values.put(Images.Media.LATITUDE, latlng[0]); + values.put(Images.Media.LONGITUDE, latlng[1]); + } } return values; } // Add the image to media store. public static Uri addImage(ContentResolver resolver, String title, - long date, Location location, int orientation, int jpegLength, + long date, Location location, int orientation, ExifInterface exif,int jpegLength, String path, int width, int height, String mimeType) { // Insert into MediaStore. ContentValues values = - getContentValuesForData(title, date, location, orientation, jpegLength, path, + getContentValuesForData(title, date, location, orientation, exif, jpegLength, path, width, height, mimeType); return insertImage(resolver, values); } + public static Uri addImage(ContentResolver resolver, String title, + long date, Location location, int orientation,int jpegLength, + String path, int width, int height, String mimeType) { + // Insert into MediaStore. + ContentValues values = + getContentValuesForData(title, date, location, orientation, null, jpegLength, + path, width, height, mimeType); + + return insertImage(resolver, values); + } + public static long addRawImage(String title, byte[] data, String mimeType) { String path = generateFilepath(title, mimeType); @@ -198,7 +215,7 @@ public class Storage { String path, int width, int height, String mimeType) { ContentValues values = - getContentValuesForData(title, date, location, orientation, jpegLength, path, + getContentValuesForData(title, date, location, orientation, null, jpegLength, path, width, height, mimeType); // Update the MediaStore -- cgit v1.2.3