This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
List<ApplicationExitInfo> applicationExitInfos = am.getHistoricalProcessExitReasons(null, 0, 0); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
long lastExitTimestamp = getPreferences(0).getLong(PREV_DETECT_TIME_KEY, 0); | |
List<ApplicationExitInfo> unprocessedExitInfos = new ArrayList<>(); | |
for (ApplicationExitInfo exitInfo: applicationExitInfos) { | |
if (exitInfo.getTimestamp() > lastExitTimestamp) { | |
unprocessedExitInfos.add(exitInfo); | |
} else { | |
break; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for (ApplicationExitInfo exitInfo: unprocessedExitInfos) { | |
Log.e(TAG, String.format("Exit reason: %d, description: %s", exitInfo.getReason(), exitInfo.getDescription())); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for (ApplicationExitInfo exitInfo: unprocessedExitInfos) { | |
if (exitInfo.getReason() == ApplicationExitInfo.REASON_ANR) { | |
UUID uuid = UUID.randomUUID(); | |
String fileName = "anr_info_" + uuid.toString() + ".trace"; | |
File outFile = new File(getFilesDir().getAbsolutePath() + "/" + fileName); | |
try (InputStream inputStream = exitInfo.getTraceInputStream()) { | |
copyStreamToFile(inputStream, outFile); | |
} catch (IOException e) { | |
Log.e(TAG, "copyStreamToFile: ", e); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@file:DependsOn("com.github.ajalt:clikt:2.8.0") | |
@file:DependsOn("org.apache.opennlp:opennlp-tools:1.9.3") | |
import com.github.ajalt.clikt.core.CliktCommand | |
import com.github.ajalt.clikt.parameters.options.option | |
import com.github.ajalt.clikt.parameters.options.prompt | |
import opennlp.tools.stemmer.PorterStemmer | |
import org.xml.sax.Attributes | |
import org.xml.sax.helpers.DefaultHandler | |
import java.io.File |
OlderNewer