-
-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
ExportWorker gets killed by Android 14 due to new excessive binder call tracker feature #129
Comments
Hmm, it looks like the app is getting killed for doing too many binder calls in the background:
This behavior was introduced in Android 14 in commit https://android.googlesource.com/platform/frameworks/base.git/+/71d75c09b9a06732a6edb4d1488d2aa3eb779e14%5E%21/. I'll dig around and see if there's a way this can be worked around. |
Hi, Thank you for reporting this, and thank you very much for taking the time and making the effort to figure out the problem and create a (well-documented!) workaround. You're clearly a more advanced Android developer than I am :) I would like to understand the problem better, though, before merging a workaround like your PR: what, exactly, is the app doing wrong? I thought that doing high volume and long running database queries and file I/O is exactly the sort of thing that background work is designed for. What is the "excessive binder traffic" that Android is complaining about? Perhaps if I understood the problem better, I could redesign the scheduled export code to be more compliant with what Android expects. |
Sure thing! I don't think sms-ie is doing anything incorrectly. The problem is mainly in these two calls: sms-ie/app/src/main/java/com/github/tmo1/sms_ie/ImportExportMessages.kt Lines 179 to 181 in c56fa0e
sms-ie/app/src/main/java/com/github/tmo1/sms_ie/ImportExportMessages.kt Lines 229 to 233 in c56fa0e
Each of those queries involves inter-process communication between sms-ie and Android's In my case, I have 5000 or so MMS messages (well, RCS), so it ends up performing 10000+ queries. It takes around 4 minutes to export and Android usually kills the process about 1 minute 15 seconds in (~3k queries).
That's unfortunately no longer true in recent Android versions. There are special exceptions to this though, like downloading files, but in the general case, without using a foreground service, it is very likely that long-running (multiple minute) operations will be killed. |
Ah, I think I understand - thanks for the detailed explanation. Rant: I find Android development really aggravating. Everything is constantly changing, and unlike in Linux, where (with apologies to Perl) easy things are generally easy and hard things are usually at least possible, in Android it feels like easy things are generally hard and lots of things turn out to be impossible. The sheer amount of rules and restrictions imposed by the system just feels developer hostile, and while I understand that the purpose is to protect users and provide them with good user experiences, the result seems to be an unfortunate lack of availability of quality apps for those same users. E.g.: on Linux, there are innumerable backup applications, ranging from simple and easy to use to complex and powerful, from CLI to GUI, while (due to Android design decisions) there's literally not one decent generally usable backup app for normal non-rooted Android devices (which is in part why SMS I/E is needed in the first place). To be fair, I'm just an amateur, hobbyist developer, and perhaps this is not an entirely fair and accurate assessment of the state of things on Android, but this is what the situation feels like to me End rant. Thank you again very much for your work on this, though. I'll do some testing, and if everything looks good, I'll merge the PR. (You mention not having a telephony-capable Android <= 13 device for testing - did you try testing on a pre-14 AVD?) |
I 100% agree with your rant and feel the same way. Usable Linux phones can't come soon enough.
I wasn't aware they had the telephony components. I'll give that a try and report back. |
I tested on a handful of versions via AVD:
|
Thanks! I'm not sure why I didn't hit that crash when I tested the API 19 code, but I did reproduce it now, and confirmed that your fix fixes it.
Thank you again very much for all the work, testing, and documenting you've done on this! I've reviewed the code in your patch, and I think I understand what it's doing, but before I merge it, I'm trying to reproduce the crash you're seeing with the old code (and the patched code with battery optimizations disabled) and confirm that the fix works, but so far I haven't been able to reproduce the crash. I just did a scheduled export of 15400 MMS messages (on a Pixel 7 API 34 AVD) and it worked fine. Do you have any ideas as to how I can trigger the crash? |
No problem at all!
I forgot to mention this in my last post. I can reproduce the crash reliably, even after a factory reset, on a Pixel 8 Pro nearly every time, but for whatever reason, never in the AVD. In both cases, I restored from the same backup (~5000 MMS messages) and triggered a scheduled export. I'm not sure if Android's |
I realized that when I tested, I left the app in the foreground, so that's likely why the killing / freezing behavior did not occur :| I did a bunch more tests with the app removed from the foreground, on API 33 and 34 (all on AVDs), and I observed the following:
So it looks like your patch is definitely necessary for the reliable running of large scheduled exports, whether to avoid the binder issue or the "excessive cpu" / long-running service problem, but I wish I had a better understanding of all this. Another, likely unrelated question: when doing all this testing, I noticed that the notifications that the app is supposed to show upon completion of a scheduled export run are not being displayed (in 33 or 34). This used to work, and I'm not sure when / why it no longer does. Did you notice the completion notifications in your testing? |
Thanks for the additional testing!
This is because sms-ie currently doesn't use the |
Sounds right - I'll try it. |
Request permission to post notifications on API >= 33. Addresses: #129
Done - thanks! |
On Android 14 (Google Pixel stock firmware), the scheduled exports seem to be crashing, even though exports done manually via the UI work fine. When
ExportWorker
tries it run, it fails during the message export phase with a binder error:Manually triggering with scheduled job with the following command also results in the same crash:
When the crash occurs, it leaves behind a partially written zip file with just the local zip entry header for
messages.ndjson
:I'm not sure why this is happening yet. I'll see if I can reproduce the problem this weekend with a debug build to get a better stack trace. (The logs above are from the precompiled 2.2.0 APK from the Github release page.)
The text was updated successfully, but these errors were encountered: