Skip to content
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

Our PN broadcast receiver issue causes ANR on Android #290

Closed
ikbalkaya opened this issue Jan 7, 2022 · 2 comments · Fixed by #291
Closed

Our PN broadcast receiver issue causes ANR on Android #290

ikbalkaya opened this issue Jan 7, 2022 · 2 comments · Fixed by #291
Assignees
Labels
bug Something isn't working. It's clear that this does need to be fixed.

Comments

@ikbalkaya
Copy link
Contributor

ikbalkaya commented Jan 7, 2022

Issue spotted at #226 (comment)

There is an ANR problem that is raised from broadcast receiver implemented to interact push notifications in order to communicate to Dart side. This issue is happening when our library is used with Firebase messaging library. However the issue might be there already and Firebase messaging library might just be aggravating it.

Investigate following

  • Understand the impact of using multiple broadcast receivers that are accepting that has same intent filters. Will they both receive the intent? Will there be a priority? Is there a scheduling, priority etc that is designed for this case? Official documentation may not be enough to understand these, so might be a good idea to delve into Android source code.
  • Compare implementation of broadcast receiver with the official one.
  • Try to identify execution block that causes ANR. This issue might be hard to replicate but hopefully adding the firebase library will make it easier. Then try to move this block to a background thread with minimal impact (without losing or changing any functionality) and see if that could quickly solve the issue (As recommended by @QuintinWillison thanks!)
  • If above solutions do not work, try to adopt approach from [Firebase's official package |https://github.com/FirebaseExtended/flutterfire/tree/master/packages/firebase_messaging/firebase_messaging]
@ikbalkaya ikbalkaya self-assigned this Jan 7, 2022
@ikbalkaya
Copy link
Contributor Author

Some initial thoughts after comparing Firebase's official plugin with our Plugin.

  • Our plugin tries to do something quite similar to what Firebase's official plugin does. Also architecturally looks like Ben B. tried to create something similar to Firebase team did.
  • Firebase's implementation has a store to store / read /write messages, a job service for proper enqueue and dequeue and a background executor. We try to immediately execute incoming messages by trying to manually starting the app. I think we should follow the Firebase plugin implementation path.
  • We may not be able to directly use Firebase's Flutter library for now however I think our eventual aim to be using their library directly and customising the behaviour in Flutter side. That's a more pragmatic approach as we do not want to reinvent the wheel.
  • We can temporarily use Firebase library's Android plugin code, customising some behaviour on our side and making sure the dart-native channels are set up properly so that we don't have to change code in the dart side. I will also create the same package as what official plugin does in order to avoiding any clash for users who additionaly installs Firebase's official library.

@ikbalkaya
Copy link
Contributor Author

I tried to use components from Firebase messaging library and it ended up being very convoluted. It wasn't easy to migrate background channels used in the library to ours so I gave up.

However. I confirmed that broadcast receivers with same intent filters will indeed block each other and they run in turn. So moving long running bit in our broadcast receiver should solve the ANR problem.

@ikbalkaya ikbalkaya linked a pull request Jan 11, 2022 that will close this issue
@QuintinWillison QuintinWillison added the bug Something isn't working. It's clear that this does need to be fixed. label Jan 14, 2022
@QuintinWillison QuintinWillison changed the title Investigate and possibly fix broadcast receiver issue that causes ANR Our PN broadcast receiver issue causes ANR on Android Jan 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working. It's clear that this does need to be fixed.
Development

Successfully merging a pull request may close this issue.

2 participants