Repository navigation
[Google3 Bug]: ProcessTextPlugin.queryTextActions causing ANRs #189176
Copy link
Copy link
Closed
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work listcustomer: googleVarious Google teamsVarious Google teamscustomer: money (g3)engineflutter/engine related. See also e: labels.flutter/engine related. See also e: labels.platform-androidAndroid applications specificallyAndroid applications specificallyteam-androidOwned by Android platform teamOwned by Android platform teamtriaged-androidTriaged by Android platform teamTriaged by Android platform team
Description
Help us understand the severity of this issue
- causing severe production issues e.g. malfunctions or data loss
- blocking next binary release
- blocking a client feature launch within a quarter
- nice-to-have but does not block a launch within the next quarter
Steps to reproduce
When editable text widget is rendered or user long taps text in editable text widget, ProcessTextPlugin.queryTextActions is called that triggers ResolveInfo.loadLabel binder method that blocks the main thread for more than 5s, causing ANR.
Stack trace:
#00 pc 0x000000000003b0dc /system/lib/libandroidfw.so (android::ChunkIterator::Next+100)
#01 pc 0x000000000003ed1f /system/lib/libandroidfw.so (android::LoadedPackage::Load+598)
#02 pc 0x0000000000040b1d /system/lib/libandroidfw.so (android::LoadedArsc::LoadTable+308)
#03 pc 0x0000000000040f01 /system/lib/libandroidfw.so (android::LoadedArsc::Load+164)
#04 pc 0x0000000000029365 /system/lib/libandroidfw.so (android::ApkAssets::LoadImpl+252)
#05 pc 0x00000000000290ab /system/lib/libandroidfw.so (android::ApkAssets::LoadImpl+190)
#06 pc 0x0000000000028e4b /system/lib/libandroidfw.so (android::ApkAssets::Load+34)
#07 pc 0x000000000012f1e3 /system/lib/libandroid_runtime.so (android::NativeLoad+882)
at android.content.res.ApkAssets.nativeLoad (Native method)
at android.content.res.ApkAssets.<init> (ApkAssets.java:296)
at android.content.res.ApkAssets.loadFromPath (ApkAssets.java:145)
at android.app.ResourcesManager.loadApkAssets (ResourcesManager.java:472)
at android.app.ResourcesManager.-$$Nest$mloadApkAssets (unavailable)
at android.app.ResourcesManager$ApkAssetsSupplier.load (ResourcesManager.java:167)
at android.app.ResourcesManager.createApkAssetsSupplierNotLocked (ResourcesManager.java:997)
at android.app.ResourcesManager.getResources (ResourcesManager.java:1118)
at android.app.ActivityThread.getTopLevelResources (ActivityThread.java:2506)
at android.app.ApplicationPackageManager.getResourcesForApplication (ApplicationPackageManager.java:2037)
at android.app.ApplicationPackageManager.getResourcesForApplication (ApplicationPackageManager.java:2023)
at android.app.ApplicationPackageManager.getText (ApplicationPackageManager.java:2349)
at android.content.pm.ComponentInfo.loadUnsafeLabel (ComponentInfo.java:130)
at android.content.pm.PackageItemInfo.loadLabel (PackageItemInfo.java:212)
at android.content.pm.ResolveInfo.loadLabel (ResolveInfo.java:238)
at io.flutter.plugin.text.ProcessTextPlugin.queryTextActions (ProcessTextPlugin.java:57)
at io.flutter.embedding.engine.systemchannels.ProcessTextChannel$1.onMethodCall (ProcessTextChannel.java:63)
at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage (MethodChannel.java:267)
at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler (DartMessenger.java:286)
at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0 (DartMessenger.java:313)
at io.flutter.embedding.engine.dart.DartMessenger.$r8$lambda$xiVpfGssfwbeQV0MS1TxLCE19hA (DartMessenger.java:1)
at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run (D8$$SyntheticClass:13)
at android.os.Handler.handleCallback (Handler.java:942)
at android.os.Handler.dispatchMessage (Handler.java:99)
at android.os.Looper.loopOnce (Looper.java:201)
at android.os.Looper.loop (Looper.java:288)
at android.app.ActivityThread.main (ActivityThread.java:7941)
at java.lang.reflect.Method.invoke (Native method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:569)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1015)
Related past issues: https://github.com/flutter/flutter/issues?q=queryTextActions%20anr
Please see b/532829373 for the proposed fix.
Expected results
Editable text widget renders without incident or available text actions are shown when user long taps text in editable text widget.
Actual results
ANR occurs.
Code sample
Code sample
[Paste your code here]Screenshots or Video
Screenshots / Video demonstration
[Upload media here]
Logs
Logs
[Paste your logs here]Flutter Doctor output
Doctor output
[Paste your output here]Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work listcustomer: googleVarious Google teamsVarious Google teamscustomer: money (g3)engineflutter/engine related. See also e: labels.flutter/engine related. See also e: labels.platform-androidAndroid applications specificallyAndroid applications specificallyteam-androidOwned by Android platform teamOwned by Android platform teamtriaged-androidTriaged by Android platform teamTriaged by Android platform team
Activity
saurabh-mirajkar commentedon Jul 9, 2026
@xRossKoh Thanks for the report.
There have been a couple of similar issues reported regarding this behavior, but none with concrete steps to reproduce:
To help us make this issue actionable, could you please provide:
flutter doctor -v.xRossKoh commentedon Jul 9, 2026
@saurabh-mirajkar Thank you for your prompt response.
Unfortunately, I do not have an MRE at the moment.
That being said, I have done an in-depth investigation into the ProcessTextPlugin and have identified the potential cause of the ANRs and a potential fix for it. Please see the attached doc in b/532829373 for more details. TL;DR, the ProcessTextPlugin does binder calls on the main thread to resolve the labels for text actions, which can take longer than 5s on low-end devices or when the device resources are under heavy load, resulting in ANR. Since it is an anti-pattern to do binder calls on the main thread (https://developer.android.com/topic/performance/anrs/find-unresponsive-thread#slow-binder), the proposed fix is to offload the querying of text actions to a background thread.
As for next steps, I intend to validate the proposed fix on my app internally. The purpose of raising this issue as this point is to get some visibility on this from the Flutter team. Subsequently, once my proposed fix is validated, I hope to get support from the Flutter team to get the fix into the Flutter repo.
cc @jiahaog
saurabh-mirajkar commentedon Jul 10, 2026
@xRossKoh Thanks for the additional details. However, the public issue is still missing some details needed to make it actionable outside the internal context.
Kindly provide the above details as requested earlier.
You also mentioned:
However, the contents of this document are not visible from the public issue. If there are any non-confidential details from that investigation that can be shared here, please include them so we can review the proposed fix.
xRossKoh commentedon Jul 24, 2026
@saurabh-mirajkar Apologies for the late reply.
Unfortunately, I do not have an MRE for the issue as I was not able to reproduce it locally either.
As for the details of the internal document that you requested, here is an summary:
The ProcessTextPlugin.queryTextActions method handler makes binder calls on the main thread. Attached is a Perfetto trace (with additional trace logging implemented to better visualize when the method is called) validating this behavior.
According to https://developer.android.com/topic/performance/anrs/find-unresponsive-thread#slow-binder, making binder calls on the main thread is an antipattern. The suspicion is that the binder calls might be especially slow if the user's device is of a lower tier and/or under heavy CPU load, blocking the main thread and leading to the ANRs.
The proposed fix is to offload the binder calls to the background. #189823 has been sent out for the fix.
4 remaining items
mboetger commentedon Jul 28, 2026
@xRossKoh - thank you for the perfetto trace! I do not see the Binderproxy calls in the perfetto trace to support your theory. Can you look for those specific calls via the SQL interface in perfetto?
https://developer.android.com/topic/performance/anrs/find-unresponsive-thread#slow-binder
xRossKoh commentedon Jul 29, 2026
@mboetger Thanks for your response.
Please see the attached trace where the binder transaction is present:
Additionally, I think my previous analysis was inaccurate. Here is the clarification.
The
queryTextActionsmethod does 2 things:resolveInfosByIdvariable in the plugin.resolveInfoByIdsvariable.Either way, it seems like both binder calls and blocking I/O on the main thread are anti-patterns as per https://developer.android.com/topic/performance/anrs/find-unresponsive-thread#common-causes.
Offload blocking work in ProcessTextPlugin to the background (flutter…
xRossKoh commentedon Aug 12, 2026
As called out my @mboetger in #189823 (comment), I was unable to repro the issue or validate that the PR fixes the ANR issue.
Now that the PR has been merged, I will provide an update on whether the PR fixes the ANR issue once the metrics become available on my app.
xRossKoh commentedon Sep 17, 2026
As per the latest metrics on my app, it has been observed that ANRs related to ProcessTextPlugin have been completely mitigated.
This fix also reduced startup latency by ~100-300ms on my app. Note that this scales based on the number of installed apps that provide text actions.
We expect other Flutter apps to also benefit from this change.
Closing this issue since this is now fixed and verified.
github-actions commentedon Oct 7, 2026
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.