1616
1717package androidxc .camera .core .impl .utils ;
1818
19- import android .annotation .SuppressLint ;
2019import android .location .Location ;
2120
2221import androidx .annotation .NonNull ;
2322import androidx .annotation .Nullable ;
24- import androidx .annotation .RequiresApi ;
23+ import androidx .annotation .VisibleForTesting ;
2524import androidx .camera .core .ImageProxy ;
2625import androidx .camera .core .Logger ;
2726import androidxc .exifinterface .media .ExifInterface ;
3837import java .util .Date ;
3938import java .util .List ;
4039import java .util .Locale ;
40+ import java .util .Objects ;
4141
4242/**
4343 * Utility class for modifying metadata on JPEG files.
4444 *
4545 * <p>Call {@link #save()} to persist changes to disc.
4646 */
47- @ SuppressLint ("RestrictedApi" )
48- @ RequiresApi (21 ) // TODO(b/200306659): Remove and replace with annotation on package-info.java
4947public final class Exif {
5048
5149 /** Timestamp value indicating a timestamp value that is either not set or not valid */
5250 public static final long INVALID_TIMESTAMP = -1 ;
51+ // Forked from ExifInterface.TAG_THUMBNAIL_ORIENTATION. The value is library-internal so we
52+ // can't depend on it directly.
53+ public static final String TAG_THUMBNAIL_ORIENTATION = "ThumbnailOrientation" ;
5354
5455 private static final String TAG = Exif .class .getSimpleName ();
5556
@@ -94,7 +95,7 @@ public SimpleDateFormat initialValue() {
9495 ExifInterface .TAG_JPEG_INTERCHANGE_FORMAT_LENGTH ,
9596 ExifInterface .TAG_THUMBNAIL_IMAGE_LENGTH ,
9697 ExifInterface .TAG_THUMBNAIL_IMAGE_WIDTH ,
97- ExifInterface . TAG_THUMBNAIL_ORIENTATION );
98+ TAG_THUMBNAIL_ORIENTATION );
9899
99100 private final ExifInterface mExifInterface ;
100101
@@ -187,7 +188,8 @@ public void copyToCroppedImage(@NonNull Exif croppedExif) {
187188 exifTags .removeAll (DO_NOT_COPY_EXIF_TAGS );
188189 for (String tag : exifTags ) {
189190 String originalValue = mExifInterface .getAttribute (tag );
190- if (originalValue != null ) {
191+ String croppedExifValue = croppedExif .mExifInterface .getAttribute (tag );
192+ if (originalValue != null && !Objects .equals (originalValue , croppedExifValue )) {
191193 croppedExif .mExifInterface .setAttribute (tag , originalValue );
192194 }
193195 }
@@ -603,6 +605,17 @@ public void flipHorizontally() {
603605 mExifInterface .setAttribute (ExifInterface .TAG_ORIENTATION , String .valueOf (orientation ));
604606 }
605607
608+ @ VisibleForTesting
609+ @ Nullable
610+ public String getMetadata () {
611+ return mExifInterface .getAttribute (ExifInterface .TAG_XMP );
612+ }
613+
614+ @ NonNull
615+ public ExifInterface getExifInterface () {
616+ return mExifInterface ;
617+ }
618+
606619 /** Attaches the current timestamp to the file. */
607620 public void attachTimestamp () {
608621 long now = System .currentTimeMillis ();
@@ -690,11 +703,6 @@ private static final class Speed {
690703 static Converter fromKilometersPerHour (double kph ) {
691704 return new Converter (kph * 0.621371 );
692705 }
693-
694- static Converter fromMetersPerSecond (double mps ) {
695- return new Converter (mps * 2.23694 );
696- }
697-
698706 static Converter fromMilesPerHour (double mph ) {
699707 return new Converter (mph );
700708 }
@@ -710,18 +718,6 @@ static final class Converter {
710718 mMph = mph ;
711719 }
712720
713- double toKilometersPerHour () {
714- return mMph / 0.621371 ;
715- }
716-
717- double toMilesPerHour () {
718- return mMph ;
719- }
720-
721- double toKnots () {
722- return mMph / 1.15078 ;
723- }
724-
725721 double toMetersPerSecond () {
726722 return mMph / 2.23694 ;
727723 }
@@ -873,7 +869,7 @@ public static List<String> getAllExifTags() {
873869 ExifInterface .TAG_INTEROPERABILITY_INDEX ,
874870 ExifInterface .TAG_THUMBNAIL_IMAGE_LENGTH ,
875871 ExifInterface .TAG_THUMBNAIL_IMAGE_WIDTH ,
876- ExifInterface . TAG_THUMBNAIL_ORIENTATION ,
872+ TAG_THUMBNAIL_ORIENTATION ,
877873 ExifInterface .TAG_DNG_VERSION ,
878874 ExifInterface .TAG_DEFAULT_CROP_SIZE ,
879875 ExifInterface .TAG_ORF_THUMBNAIL_IMAGE ,
@@ -890,9 +886,5 @@ public static List<String> getAllExifTags() {
890886 ExifInterface .TAG_NEW_SUBFILE_TYPE ,
891887 ExifInterface .TAG_SUBFILE_TYPE );
892888 }
893-
894- public ExifInterface getExifInterface () {
895- return mExifInterface ;
896- }
897889}
898890
0 commit comments