diff options
| author | Neil Fuller <nfuller@google.com> | 2019-08-19 14:02:35 +0100 |
|---|---|---|
| committer | Neil Fuller <nfuller@google.com> | 2019-08-19 14:02:35 +0100 |
| commit | 4fc11649bcc57e00e7fd3c3cac9c5b4da22bcc43 (patch) | |
| tree | 7c3598c41b8445905e63145d72775e9ac68d4b1b /core/java | |
| parent | 3628bb3a64d3e150c53fabe85e01ab03b2fd9681 (diff) | |
Switch from android.text.format.Time
Convert a use of android.text.format.Time.format() to use calculations
based on java.time instead. This avoids future Y2038 issues associated
with Time.
Bug: 16550209
Test: build / boot / treehugger
Change-Id: I37567367f108562bec1510e549186c123f51318b
Diffstat (limited to 'core/java')
| -rw-r--r-- | core/java/android/hardware/camera2/legacy/SurfaceTextureRenderer.java | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/core/java/android/hardware/camera2/legacy/SurfaceTextureRenderer.java b/core/java/android/hardware/camera2/legacy/SurfaceTextureRenderer.java index 1b28d614a7f2..a4c65aeb1050 100644 --- a/core/java/android/hardware/camera2/legacy/SurfaceTextureRenderer.java +++ b/core/java/android/hardware/camera2/legacy/SurfaceTextureRenderer.java @@ -28,7 +28,6 @@ import android.opengl.EGLSurface; import android.opengl.GLES11Ext; import android.opengl.GLES20; import android.opengl.Matrix; -import android.text.format.Time; import android.util.Log; import android.util.Pair; import android.util.Size; @@ -39,9 +38,14 @@ import java.io.File; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.FloatBuffer; +import java.time.Instant; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.Collection; import java.util.List; +import java.util.Locale; /** * A renderer class that manages the GL state, and can draw a frame into a set of output @@ -63,6 +67,9 @@ public class SurfaceTextureRenderer { private static final int FLIP_TYPE_VERTICAL = 2; private static final int FLIP_TYPE_BOTH = FLIP_TYPE_HORIZONTAL | FLIP_TYPE_VERTICAL; + private static final DateTimeFormatter LOG_NAME_TIME_FORMATTER = + DateTimeFormatter.ofPattern("yyyyMMdd'T'HHmmss", Locale.ROOT); + private EGLDisplay mEGLDisplay = EGL14.EGL_NO_DISPLAY; private EGLContext mEGLContext = EGL14.EGL_NO_CONTEXT; private EGLConfig mConfigs; @@ -624,9 +631,7 @@ public class SurfaceTextureRenderer { path.append(File.separator); path.append("durations_"); - Time now = new Time(); - now.setToNow(); - path.append(now.format2445()); + path.append(formatTimestamp(System.currentTimeMillis())); path.append("_S"); for (EGLSurfaceHolder surface : mSurfaces) { path.append(String.format("_%d_%d", surface.width, surface.height)); @@ -639,6 +644,15 @@ public class SurfaceTextureRenderer { mPerfMeasurer.dumpPerformanceData(path.toString()); } + private static String formatTimestamp(long timeMillis) { + // This is a replacement for {@link Time#format2445()} that doesn't suffer from Y2038 + // issues. + Instant instant = Instant.ofEpochMilli(timeMillis); + ZoneId zoneId = ZoneId.systemDefault(); + LocalDateTime localDateTime = LocalDateTime.ofInstant(instant, zoneId); + return LOG_NAME_TIME_FORMATTER.format(localDateTime); + } + private void setupGlTiming() { if (PerfMeasurement.isGlTimingSupported()) { Log.d(TAG, "Enabling GL performance measurement"); |
