Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 43b0a458 authored by Michal Piechowski's avatar Michal Piechowski Committed by Takahiro Aizawa
Browse files

Don't use timestamps with all zero

Although all zero (0000:00:00) is valid time, in most cases it means
that value is not present. According to http://www.exiv2.org/Exif2-2.PDF
in such case those values should be omitted, however
some cameras set them to 0 anyway. With this commit such timestamps
will be treated as they were empty.

Change-Id: I9c762b1fa04ea6bf9c0fba9e2459a20430c71c90
parent 749501e8
Loading
Loading
Loading
Loading
+10 −2
Original line number Diff line number Diff line
@@ -17,6 +17,8 @@
package android.media;

import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Date;
@@ -128,6 +130,9 @@ public class ExifInterface {
    // use sLock to serialize the accesses.
    private static final Object sLock = new Object();

    // Pattern to check non zero timestamp
    private static final Pattern sNonZeroTimePattern = Pattern.compile(".*[1-9].*");

    /**
     * Reads Exif tags from the specified JPEG file.
     */
@@ -367,7 +372,8 @@ public class ExifInterface {
     */
    public long getDateTime() {
        String dateTimeString = mAttributes.get(TAG_DATETIME);
        if (dateTimeString == null) return -1;
        if (dateTimeString == null
                || !sNonZeroTimePattern.matcher(dateTimeString).matches()) return -1;

        ParsePosition pos = new ParsePosition(0);
        try {
@@ -402,7 +408,9 @@ public class ExifInterface {
    public long getGpsDateTime() {
        String date = mAttributes.get(TAG_GPS_DATESTAMP);
        String time = mAttributes.get(TAG_GPS_TIMESTAMP);
        if (date == null || time == null) return -1;
        if (date == null || time == null
                || (!sNonZeroTimePattern.matcher(date).matches()
                && !sNonZeroTimePattern.matcher(time).matches())) return -1;

        String dateTimeString = date + ' ' + time;