From ec727411d2d97ba79d3e32edb304279af078377e Mon Sep 17 00:00:00 2001 From: Eino-Ville Talvala Date: Tue, 27 Sep 2016 17:15:11 -0700 Subject: [PATCH] DngCreator: Do not cache timezone in static initializer The static initializer for a pre-loaded framework class is run no later than at zygote startup, which happens at device boot. Which means that if the timezone later changes, DngCreator will use an incorrect cached timezone until the next reboot. This is especially evident in freshly wiped devices, where initial setup will typically change the timezone. Instead, read the timezone each time DngCreator is created, which is also when we query the current time for constructing the timestamps. Test: android.hardware.camera2.cts.DngCreatorTest#testSingleImageThumbnail Bug: 31743060 Change-Id: I83a4eac762650e5f904f3b8fa779c094cef30562 --- core/java/android/hardware/camera2/DngCreator.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/core/java/android/hardware/camera2/DngCreator.java b/core/java/android/hardware/camera2/DngCreator.java index 45fa15e043e5..1a51acd6c5ec 100644 --- a/core/java/android/hardware/camera2/DngCreator.java +++ b/core/java/android/hardware/camera2/DngCreator.java @@ -119,8 +119,14 @@ public final class DngCreator implements AutoCloseable { captureTime = timestamp / 1000000 + timeOffset; } + // Create this fresh each time since the time zone may change while a long-running application + // is active. + final DateFormat dateTimeStampFormat = + new SimpleDateFormat(TIFF_DATETIME_FORMAT); + dateTimeStampFormat.setTimeZone(TimeZone.getDefault()); + // Format for metadata - String formattedCaptureTime = sDateTimeStampFormat.format(captureTime); + String formattedCaptureTime = dateTimeStampFormat.format(captureTime); nativeInit(characteristics.getNativeCopy(), metadata.getNativeCopy(), formattedCaptureTime); @@ -467,13 +473,10 @@ public final class DngCreator implements AutoCloseable { private static final String GPS_DATE_FORMAT_STR = "yyyy:MM:dd"; private static final String TIFF_DATETIME_FORMAT = "yyyy:MM:dd HH:mm:ss"; private static final DateFormat sExifGPSDateStamp = new SimpleDateFormat(GPS_DATE_FORMAT_STR); - private static final DateFormat sDateTimeStampFormat = - new SimpleDateFormat(TIFF_DATETIME_FORMAT); private final Calendar mGPSTimeStampCalendar = Calendar .getInstance(TimeZone.getTimeZone("UTC")); static { - sDateTimeStampFormat.setTimeZone(TimeZone.getDefault()); sExifGPSDateStamp.setTimeZone(TimeZone.getTimeZone("UTC")); } -- 2.11.0