package xcrash;

import java.util.Map;

public class DumpTraceManager {

    public interface OnDumpTraceCallback{
        void OnDumpTrace(String trace);
    }

    public static void dumpTrace(final OnDumpTraceCallback callback) {
        ICrashCallback iCallback = new ICrashCallback() {
            @Override
            public void onCrash(String logPath, String emergency) throws Exception {
                XCrash.getLogger().i(Util.TAG, "xCrash receive dumpCallback callback, path: " + logPath);

                Map<String, String> map = TombstoneParser.parse(logPath, emergency);

                String trace = map.get(TombstoneParser.keyOtherThreads);

                TombstoneManager.deleteTombstone(logPath);

                callback.OnDumpTrace(trace);

            }
        };

        //需要5.0以上而且打开anrenable
        if (!XCrash.dumpTrace(iCallback)) {
            callback.OnDumpTrace("");
        }
    }
}
