Android DeadSystemException

目前,我们正在经历一个 DeadSystemException在我们的 HockeyApp 崩溃报告。它出现在 Android 7.0和 Android 7.1上。我们在以前的应用程序版本中没有遇到这种异常(当前用户都在使用它们) ,所以我猜测这种异常是由一些代码更改引起的。但是堆栈跟踪对此没有太大帮助。知道吗? 谢谢你的建议。

来自 HockeyApp 的堆栈跟踪:

java.lang.RuntimeException: android.os.DeadSystemException
at android.app.ActivityThread$StopInfo.run(ActivityThread.java:3781)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: android.os.DeadSystemException
... 8 more
56833 次浏览

The Android Developer docs for android.os.DeadSystemException says the following:

The core Android system has died and is going through a runtime restart. All running apps will be promptly killed.

The source code does not help much more:

package android.os;
/**
* The core Android system has died and is going through a runtime restart. All
* running apps will be promptly killed.
*/
public class DeadSystemException extends DeadObjectException {
public DeadSystemException() {
super();
}
}

Overall, it looks like this is being thrown by the OS and has nothing to do with our code.

Looking at the JavaDoc from the superclass, DeadObjectException, backs this theory up:

The object you are calling has died because its hosting process no longer exists.

Fatal Exception: java.lang.RuntimeException: android.os.DeadSystemException

This exception was caused in one of the apps I was developing, it occurred mostly in MI devices.

After debugging I found that I was trying to start another service (Say B) in the current service (Say A) from a background thread, but when startService(itService) method was called the service A was already killed.

The only solution I found till now is to check if the current service A is running or not before you start another service B. Depending on your implementation you can use one of the various ways to check if a services is running from this answer.

One cause was a bug in the notification service of Android version 7 and 8.

It was caused by using "vibration pattern" in the notifications, which throws an ArrayOutOfBoundsException. This leads the whole system to crash and post a DeadSystemException.

For further details you can refer to this Medium article here.

Another example :

try {
ActivityManager.getMyMemoryState(mAppProcessInfo);
} catch (Exception exception) {
exception.printStackTrace();
return;
}

I was able to reproduce this exception in one of my apps.

It turns out that I misunderstood something while implementing in-app purchases, as I wasn't expecting Google to notify also the already purchased and acknowledged products, so I was not checking if I already managed the purchased product notified about.

So I had an infinite loop in my app consisting on reloading again and again and again the same information on screen, until eventually (but a little bit randomly I must say) this exception raises.

Caused by java.lang.RuntimeException
android.os.DeadSystemException
android.app.ApplicationPackageManager.getPackageInfoAsUser (ApplicationPackageManager.java:188)
android.app.ApplicationPackageManager.getPackageInfo (ApplicationPackageManager.java:159)
com.google.android.gms.common.GooglePlayServicesUtilLight.isGooglePlayServicesAvailable (GooglePlayServicesUtilLight.java:13)
com.google.android.gms.common.GoogleApiAvailabilityLight.isGooglePlayServicesAvailable (GoogleApiAvailabilityLight.java:2)

I hope this to be useful to someone, as it's info about how to try to reproduce the exception, not how to solve it (well, in my case was just fixing the silly error and preventing the infinite loop of screen reloading, but there must be variety of different causes producing this exception).