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

Commit 7046f2da authored by Neil Fuller's avatar Neil Fuller
Browse files

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.

Note: The new code doesn't support digit localization for, for example,
Arabic devices. I strongly suspect that the digit localization would not
be intentional in this usecase so it has not been preserved.

Bug: 16550209
Test: build / boot / treehugger
Change-Id: Ia246e63a1cd9be08f78f54c38b45c64e4795618a
parent 9aa7b74a
Loading
Loading
Loading
Loading
+11 −4
Original line number Diff line number Diff line
@@ -79,7 +79,6 @@ import android.os.SystemProperties;
import android.os.UserHandle;
import android.os.UserManager;
import android.text.TextUtils;
import android.text.format.Time;
import android.util.ArrayMap;
import android.util.DebugUtils;
import android.util.DisplayMetrics;
@@ -97,12 +96,16 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.URISyntaxException;
import java.time.Clock;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
@@ -115,10 +118,14 @@ import javax.microedition.khronos.egl.EGLSurface;

final class ActivityManagerShellCommand extends ShellCommand {
    public static final String NO_CLASS_ERROR_CODE = "Error type 3";

    private static final String SHELL_PACKAGE_NAME = "com.android.shell";

    private static final int USER_OPERATION_TIMEOUT_MS = 2 * 60 * 1000; // 2 minutes

    private static final DateTimeFormatter LOG_NAME_TIME_FORMATTER =
            DateTimeFormatter.ofPattern("yyyyMMdd-HHmmss", Locale.ROOT);

    // IPC interface to activity manager -- don't need to do additional security checks.
    final IActivityManager mInterface;
    final IActivityTaskManager mTaskInterface;
@@ -919,9 +926,9 @@ final class ActivityManagerShellCommand extends ShellCommand {
        String process = getNextArgRequired();
        String heapFile = getNextArg();
        if (heapFile == null) {
            final Time t = new Time();
            t.set(System.currentTimeMillis());
            heapFile = "/data/local/tmp/heapdump-" + t.format("%Y%m%d-%H%M%S") + ".prof";
            LocalDateTime localDateTime = LocalDateTime.now(Clock.systemDefaultZone());
            String logNameTimeString = LOG_NAME_TIME_FORMATTER.format(localDateTime);
            heapFile = "/data/local/tmp/heapdump-" + logNameTimeString + ".prof";
        }
        pw.println("File: " + heapFile);
        pw.flush();