-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Heap Dump Expedited Work not starting in Android < API31 with LeakCanary 2.8 #2268
Comments
Thanks for the detailed report and suggested solution! |
setExpedited() isn't enough, we also needed to provide ForegroundInfo. The documentation doesn't make this very obvious, and there's no API enforcement. Fixes #2268
I still have this error with 2.8.1 on Android 11 on Realme 8:
|
Sorry, it seems that this was due to the issue with WorkManager setup in the app (WorkerFactory always returned non-null worker from app's code even if workerClassName did not belong to the app's code). |
@arochevdev How did this WorkerFactory behavior trigger the crash? I worry that others might run into this. |
Application had its own WorkerFactory implementation, which always returned non-null ListenableWorker instance (app's own class). This prevented WorkManager from using its own built-in factory which creates workers from workerClassName using standard constructor parameters (custom WorkerFactory implementations are supposed to return null if requested to create worker with workerClassName that they know nothing about). I.e. every time any worker was created (including leakcanary.internal.HeapAnalyzerWorker), app's custom WorkerFactory created specific ListenableWorker implementation that had nothing to do with what being requested. And since WorkManager doesn't check that created worker's class matches workerClassName (it blindly trusts that if WorkerFactory returned non-null object then it did correct thing) it happily used it instead of requested worker. I don't think that there is anything that can be done on LeakCanary side, application just used WorkManager incorrectly. |
Thx! |
Description
When trying to do a 'Dump Heap Now' on an emulator with API30/29, the Work does not start, and and an exception is logged (see the trace in additional information section)
If the emulator runs API31, it works fine.
If I don't include the work-runtime, running an emulator with API30/29, it runs ok (I understand that in this case, the job is being done in a simple Thread)
Steps to Reproduce
Expected behavior:
The 'Dump Heap' work to run
Version Information
Additional Information
I think this is related to that Expedited work, when run in an Android version prior to API31, runs in a foreground service, and because of that, the Work should provide foreground info (like the icon and the title) for the notification the system displays when a foreground service is run
Trace:
The text was updated successfully, but these errors were encountered: