Skip to content

Commit 09625ff

Browse files
committed
feat_: log historical process exit reasons in MainApplication
* Implement logging of the last five historical process exit reasons on devices running Android R and above. * Handle cases where no exit reasons are found and log relevant details for each exit reason, including process name, reason, timestamp, and memory usage.
1 parent ae01e60 commit 09625ff

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

android/app/src/main/java/im/status/ethereum/MainApplication.kt

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ import im.status.ethereum.StatusOkHttpClientFactory
2525
import org.json.JSONObject
2626
import android.content.ComponentCallbacks2
2727
import android.util.Log
28+
import android.app.ActivityManager
29+
import android.content.Context
30+
import android.os.Build
31+
import android.os.Process
2832

2933
class MainApplication : NavigationApplication() {
3034

@@ -54,6 +58,8 @@ class MainApplication : NavigationApplication() {
5458
if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
5559
DefaultNewArchitectureEntryPoint.load()
5660
}
61+
62+
logHistoricalProcessExitReasons()
5763
}
5864

5965
override fun onLowMemory() {
@@ -92,4 +98,40 @@ class MainApplication : NavigationApplication() {
9298

9399
private fun getCurrentReactContext(): ReactContext? =
94100
reactNativeHost.reactInstanceManager.currentReactContext
101+
102+
private fun logHistoricalProcessExitReasons() {
103+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
104+
try {
105+
val activityManager = getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
106+
val exitReasons = activityManager.getHistoricalProcessExitReasons(packageName, 0, 5)
107+
108+
if (exitReasons.isEmpty()) {
109+
Log.i("MainApplication", "No historical process exit reasons found")
110+
return
111+
}
112+
113+
Log.e("MainApplication", "Historical process exit reasons (last 5):")
114+
exitReasons.forEachIndexed { index, reason ->
115+
Log.e("MainApplication", "Exit reason #${index + 1}:")
116+
Log.e("MainApplication", " Process: ${reason.processName}")
117+
Log.e("MainApplication", " Reason: ${reason.reason}")
118+
Log.e("MainApplication", " Timestamp: ${reason.timestamp}")
119+
Log.e("MainApplication", " Description: ${reason.description}")
120+
if (reason.importance > 0) {
121+
Log.e("MainApplication", " Importance: ${reason.importance}")
122+
}
123+
if (reason.pss > 0) {
124+
Log.e("MainApplication", " PSS: ${reason.pss} KB")
125+
}
126+
if (reason.rss > 0) {
127+
Log.e("MainApplication", " RSS: ${reason.rss} KB")
128+
}
129+
}
130+
} catch (e: Exception) {
131+
Log.e("MainApplication", "Error getting historical process exit reasons", e)
132+
}
133+
} else {
134+
Log.i("MainApplication", "Historical process exit reasons not available on this Android version")
135+
}
136+
}
95137
}

0 commit comments

Comments
 (0)