Added more info to startup listener, also log 3 previous startup reasons

This commit is contained in:
Sylvain Berfini 2025-11-24 11:35:21 +01:00
parent 85aa50d8d8
commit 8e76c60a38

View file

@ -39,18 +39,42 @@ class Api35Compatibility {
Executors.newSingleThreadExecutor() Executors.newSingleThreadExecutor()
) { info -> ) { info ->
Log.i("==== Current startup information dump ====") Log.i("==== Current startup information dump ====")
Log.i("TYPE = ${startupTypeToString(info.startType)}") logAppStartupInfo(info)
Log.i("STATE = ${startupStateToString(info.startupState)}") }
Log.i("REASON = ${startupReasonToString(info.reason)}")
Log.i("FORCE STOPPED = ${if (info.wasForceStopped()) "yes" else "no"}") Log.i("==== Fetching last three startup reasons if available ====")
Log.i("PROCESS NAME = ${info.processName}") val lastStartupInfo = activityManager.getHistoricalProcessStartReasons(3)
Log.i("=========================================") for (info in lastStartupInfo) {
Log.i("==== Previous startup information dump ====")
logAppStartupInfo(info)
} }
} catch (iae: IllegalArgumentException) { } catch (iae: IllegalArgumentException) {
Log.e("$TAG Can't add application start info completion listener: $iae") Log.e("$TAG Can't add application start info completion listener: $iae")
} }
} }
private fun logAppStartupInfo(info: ApplicationStartInfo) {
Log.i("TYPE = ${startupTypeToString(info.startType)}")
Log.i("STATE = ${startupStateToString(info.startupState)}")
Log.i("REASON = ${startupReasonToString(info.reason)}")
Log.i("START COMPONENT = ${startComponentToString(info.launchMode)}")
Log.i("INTENT = ${info.intent}")
Log.i("FORCE STOPPED = ${if (info.wasForceStopped()) "yes" else "no"}")
Log.i("PROCESS NAME = ${info.processName}")
Log.i("=========================================")
}
private fun startComponentToString(component: Int): String {
return when (component) {
ApplicationStartInfo.START_COMPONENT_ACTIVITY -> "Activity"
ApplicationStartInfo.START_COMPONENT_BROADCAST -> "Broadcast"
ApplicationStartInfo.START_COMPONENT_CONTENT_PROVIDER -> "Content Provider"
ApplicationStartInfo.START_COMPONENT_SERVICE -> "Service"
ApplicationStartInfo.START_COMPONENT_OTHER -> "Other"
else -> "Unexpected ($component)"
}
}
private fun startupTypeToString(type: Int): String { private fun startupTypeToString(type: Int): String {
return when (type) { return when (type) {
ApplicationStartInfo.START_TYPE_COLD -> "Cold" ApplicationStartInfo.START_TYPE_COLD -> "Cold"