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
This commit is contained in:
@@ -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"));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user