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

Commit d13eae5d authored by Uma Maheshwari Bhiram's avatar Uma Maheshwari Bhiram Committed by Gerrit - the friendly Code Review server
Browse files

frameworks/base: creating separate files for ANRs traces based on debug flag

In case of multiple ANRs in different apps, we will get the traces for
the last ANR.
This patch will create one trace file for each application in case of ANR
and the filename would be traces_<app_name>_<date>.txt

Change-Id: Ib67d1961182938c797a9a3041fdf9a97b40ec14b
parent 961365c7
Loading
Loading
Loading
Loading
+20 −2
Original line number Diff line number Diff line
@@ -51,7 +51,8 @@ import android.util.Log;
import android.util.Slog;
import android.util.SparseArray;
import android.util.TimeUtils;

import java.util.Date;
import java.text.SimpleDateFormat;
import java.io.File;
import java.io.FileDescriptor;
import java.io.PrintWriter;
@@ -76,7 +77,7 @@ class AppErrors {

    private final ActivityManagerService mService;
    private final Context mContext;

    SimpleDateFormat mTraceDateFormat = new SimpleDateFormat("dd_MMM_HH_mm_ss.SSS");
    private ArraySet<String> mAppsNotReportingCrashes;

    /**
@@ -886,6 +887,23 @@ class AppErrors {
                    annotation != null ? "ANR " + annotation : "ANR",
                    info.toString());

            boolean enableTraceRename = SystemProperties.getBoolean("persist.sys.enableTraceRename", false);
            //Set the trace file name to app name + current date format to avoid overrinding trace file based on debug flag
            if(enableTraceRename) {
                String tracesPath = SystemProperties.get("dalvik.vm.stack-trace-file", null);
                if (tracesPath != null && tracesPath.length() != 0) {
                    File traceRenameFile = new File(tracesPath);
                    String newTracesPath;
                    int lpos = tracesPath.lastIndexOf (".");
                    if (-1 != lpos)
                        newTracesPath = tracesPath.substring (0, lpos) + "_" + app.processName + "_" + mTraceDateFormat.format(new Date()) + tracesPath.substring (lpos);
                    else
                        newTracesPath = tracesPath + "_" + app.processName;

                    traceRenameFile.renameTo(new File(newTracesPath));
                    SystemClock.sleep(1000);
                }
            }
            // Bring up the infamous App Not Responding dialog
            Message msg = Message.obtain();
            HashMap<String, Object> map = new HashMap<String, Object>();