DeadSystemException start service Android 7 - android

For the past few weeks, I have on my crash reporter:
Fatal Exception: java.lang.RuntimeException: Unable to start service com.####.MyService#ef705d8 with Intent { act=HIDE cmp=com.####/.MyService (has extras) }: java.lang.RuntimeException: android.os.DeadSystemException
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3344)
at android.app.ActivityThread.-wrap21(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1583)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6121)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)
This crash is present on:
all Samsung devices 7.0
all Nexus devices on 7.1.2
Note:
It is not due to a recent update of our application, just an OS updates on theses phones.
It is a very very frequent crashes (by far our biggest).
Our users don't report crashes than before (is this crash actually visible for the user?)
We are not able to reproduce it on our side
As you can see into the stack trace, the code impacted is system only. Not much I can do from my side to try and catch and handle the issue.
I checked the thread Android DeadSystemException but that doesn't help me much.
I know that DeadSystemException is:
The core Android system has died and is going through a runtime restart. All running apps will be promptly killed.
Is there anything we can do but to say "that's system, we cannot do anything"?

When the device is being restarted, you cannot run an app. Any app, not just yours but any given app cannot run when the device is restarting. AFAIK it occurs when you try to do something when the system crashes. Meaning if the system crashes and as it restarts your app starts a service or does something you get that error.
Meaning the exception is not connected to your app, but the Android OS and there is nothing you can do about it.
The crash being related to starting a service is because that is what your app did when the system crashed.
So: The error is something the system threw because your app did something when the system did a run-time reboot. There is nothing you can do about this, as you cannot control the Android OS from an app.

I've had the same issue. I implemented a service that uses the android SensorService. In some point of the time, two things happened but I still don't know which one caused the other. 1) The runtime restarted 2) The android SensorService died. I have implemented a default unhandled exceptions handler because I was debugging some other stuff on my app. I noticed that such handler, at least sometimes was catching that exception.
I followed this tutorial to implement it https://doandroid.wordpress.com/2011/11/19/writing-crash-reports-into-device-sd-card/
So, supposing that you implement this handler and it is actually being called when the system dies, you can add some sort of validations inside the handler such that if the exception is the DeadSystemException, you can set up an alarm to restart your application in let's say, 5 minutes or something.
This is of course not an ideal solution, but at least might be a workaround to your problem until you figure out what is really going on with the system.
Some information about how to restart you app programmatically:
Force application to restart on first activity

Your app crashed because of android OS system dies.
Here is the reference.
https://developer.android.com/reference/android/os/DeadSystemException
The core Android system has died and is going through a runtime restart. All running apps will be promptly killed.

Related

xamarin forms Android App crashes when BroadcastReceiver fires during Doze in OREO

I have a reminder app which needs to show reminders on time even if the phone is in Doze mode. This was appeared to be fine when compiling using the Android 7.1 SDK.
My BroadcastReceiver gets a WAKE_LOCK when it starts and releases it in a finally clause. It also logs activity to a local SQLLite database (for debug)
I've now changed to compile with Android 8.1 SDK and still all works fine
when the phone is not in Doze mode.
However, when the phone goes into Doze the App crashes at the due time of the alarm. My logging statement, which is the first line within OnReceive, is not invoked.
I have traps in for uncaught exceptions, which report to AppCenter and record locally. These work for other exceptions.
TaskScheduler.UnobservedTaskException += ReportUnobservedTaskException;
AppDomain.CurrentDomain.UnhandledException += ReportUnhandledException;
AndroidEnvironment.UnhandledExceptionRaiser += ReportThrowableEvent;
Can anybody advise why and where this might be failing, or how I can debug it better?
It feels like a change since moving the 8.1 SDK for compiling, but I can't see anything that has changed that would affect this.
Answering my own question in case it helps somebody else.
Investigation of the logcat shows that the problem here was that the application was not initialized when the Broadcast Receiver was invoked.
logcat showed the message:
android.runtime.JavaProxyThrowable: System.InvalidOperationException: You MUST call
Xamarin.Forms.Init(); prior to using it.
It appears that a scheduled job was crashing the app and so when the alarm fired the receiver was not initialized and could not deal with the message.
Next investigation is why the scheduled job failed ....

Why might my service not be started and what can I do about it

On a particular (low-end) Android phone (running Android 5.1) one of my app's services will fail to start, when this happens logcat has the following lines:
D/nzy ( 1499): shouldBlock from:<package name>, ComponentInfo{<service name>}elapsed:21270
D/nzy ( 1499): ===ignore ==ComponentInfo{<service name>}
D/zlg ( 1499): startService ===ignore ==ComponentInfo{<service name>}
I'm not clear as to the exact circumstances when the service fails to start. Although it does seem to be consistent that when I install the app from fresh the service is started, but if I then manually do a "Force Stop" of the the app and then restart it, the service will not be started, with the above output in logcat.
What do nzy and zlg refer to?
How can I prevent this from happening?

App is not killed/restarted when location permission is taken away while app running

(in reference to the new Android M runtime permissions system) Everywhere I look, it says that if a permission is taken away while the app is running, my app will be killed (or restarted). However, when I try this, my app is not killed/restarted, and when I got back to the app, it crashes because the permission is taken away.
the device I'm testing on is a nexus 5, running android 6.0.1
once i get my hands on a different device to test on, I will update.
note: I didnt include any code or error log becuase I want the focus to be on why my app is not getting killed by the system like everyone says, and not on why it's crashing.
I don't recall seeing anything about apps being killed in Android 6. Just all the dire warnings about apps crashing when the OS suddenly starts throwing exceptions that pre-M apps took for granted.
Just handle exceptions whenever you do something that requires a "dangerous" permission.
https://developer.android.com/training/permissions/requesting.html#perm-check
https://developer.android.com/guide/topics/security/permissions.html#normal-dangerous

Is it possible to hide the error message when an Android service is crashed

I have a bound service in separate process. It crashes occasionally due to the oem native libs on certain phones. I am trying to make the app recover from it.
I would like to silently restart the service and continue the workflow. But it seems the error message is always displayed after the service is crashed. Is there a way to suppress the error? We can handle the unhanded java exception, but not sure how to handle the native crash.
Figured out. Handle the sig works for me.

Calling a method in the system process without a qualified user error

I'm using the notification listener service in android 4.4 and I'm coming across an error that causes my app to stop getting notifications posted.
It's fairly random, but when it happens I'm seeing:
12-31 01:40:44.080 21680-21680/? W/ContextImpl﹕ Calling a method in the system process without a qualified user:
android.app.ContextImpl.sendOrderedBroadcast:1192
android.app.ContextImpl.sendOrderedBroadcast:1183
android.content.ContextWrapper.sendOrderedBroadcast:390
com.android.settings.applications.ProcessStatsDetail.checkForceStop:314
com.android.settings.applications.ProcessStatsDetail.onResume:108
in the logs.
I can even recreate this by just entering the "process stats" section of the developer tools on the phone. As soon as I select an app that uses the notification listener the puts up this warning and unbinds and destroys the service and when it recreates is it doesn't always pick up on events again.
I'm not sure why this would happen, can anyone shed any light?
1) the NotificationListenerService is started by the system and the code for sendOrderedBroadcast throws a warning if it was called by the system process (here)
2) That is just a warning though. There is probably a crash somewhere else in your code. When a NotificationListenerService crashes, Android doesn't restart it unless you toggle the permission or restart your phone. Look for another crash and try either of those methods to restart it if it has. Starting it yourself will not work.
Check your AIDL Package name, for me the Package name in client and server were mismatched. Hope it help somebody

Categories

Resources