Skip to content

[Google3 Bug]: ProcessTextPlugin.queryTextActions causing ANRs #189176

Closed

Description

@xRossKoh

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]

Activity

  1. saurabh-mirajkar commented on Jul 9, 2026

    @saurabh-mirajkar
    Contributor

    @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:

    1. A minimal reproducible example (MRE) that demonstrates the issue.
    2. The specific device models and OS versions where this crash/ANR occurs.
    3. The complete output of flutter doctor -v.
  2. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    needs repro infoAutomated crash report whose cause isn't yet known
    and removed
    in triagePresently being triaged by the triage team
    on Jul 9, 2026
  3. xRossKoh commented on Jul 9, 2026

    @xRossKoh
    ContributorAuthor

    @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

  4. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Jul 9, 2026
  5. saurabh-mirajkar commented on Jul 10, 2026

    @saurabh-mirajkar
    Contributor

    @xRossKoh Thanks for the additional details. However, the public issue is still missing some details needed to make it actionable outside the internal context.

    To help us make this issue actionable, could you please provide:

    1. A minimal reproducible example (MRE) that demonstrates the issue.
    2. The specific device models and OS versions where this crash/ANR occurs.
    3. The complete output of flutter doctor -v.

    Kindly provide the above details as requested earlier.

    You also mentioned:

    Please see the attached doc in b/532829373 for more details.

    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.

  6. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Jul 10, 2026
  7. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Jul 20, 2026
  8. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Jul 21, 2026
  9. xRossKoh commented on Jul 24, 2026

    @xRossKoh
    ContributorAuthor

    @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.

    Image

    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.

  10. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Jul 24, 2026
  11. 4 remaining items

  12. mboetger commented on Jul 28, 2026

    @mboetger
    Contributor

    @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

    Look for BinderProxy.transactNative or Binderproxy.transact in the stacks. This means a binder call is taking place. Following these two lines, you can see the binder API that is called. In the following example, the call is to IAccessibilityManager.addClient.

  13. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    P2Important issues not at the top of the work list
    and removed
    triaged-androidTriaged by Android platform team
    on Jul 28, 2026
  14. xRossKoh commented on Jul 29, 2026

    @xRossKoh
    ContributorAuthor

    @mboetger Thanks for your response.

    Please see the attached trace where the binder transaction is present:

    Image

    Additionally, I think my previous analysis was inaccurate. Here is the clarification.

    The queryTextActions method does 2 things:

    1. Queries package manager for the activities with process text intent, which is a binder transaction.
    • This happens once on initialization of the plugin, and the list of activities returned is subsequently cached in the resolveInfosById variable in the plugin.
    1. Resolves the text action labels for each activities fetched from step 1, which is a disk I/O transaction.
    • This happens each time the method is called, using the list of activities cached in the aforementioned resolveInfoByIds variable.

    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.

  15. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Jul 29, 2026
  16. xRossKoh commented on Aug 12, 2026

    @xRossKoh
    ContributorAuthor

    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.

  17. xRossKoh commented on Sep 17, 2026

    @xRossKoh
    ContributorAuthor

    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.

  18. github-actions commented on Oct 7, 2026

    @github-actions

    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 -v and a minimal reproduction of the issue.

  19. locked as resolved and limited conversation to collaborators on Oct 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listcustomer: googleVarious Google teamscustomer: money (g3)engineflutter/engine related. See also e: labels.platform-androidAndroid applications specificallyteam-androidOwned by Android platform teamtriaged-androidTriaged by Android platform team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions