-
Notifications
You must be signed in to change notification settings - Fork 376
[Fix] very rare bug where app doesn't opening from notification tap when it cold starts the app #2289
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added some logs in this branch and triggered a notification. The logs appear in the correct order, which suggests that this implementation should work as expected.
That said, I had an additional thought. Converting NotificationListener into a bootstrappable service and moving the logic from start() to bootstrap() could also address this issue. Currently, all code within startableService.start() is executed on a background thread after initWithContext, which introduces the potential for a race condition—specifically, where intLifeCycleHandler is not subscribed before notificationReceived is invoked. This alternative approach might also resolve the timing issue related to the intLifecycleCallback call in canReceiveNotification.
However, as you mentioned, the current PR simplifies the architecture by removing the now-unnecessary NotificationLifeCycleEventHandler, which I’m also aligned with. I can approve this unless you want to try the other approach.
try { | ||
// Always use the top most notification if user tapped on the summary notification | ||
val firstPayloadItem = pushPayloads.getJSONObject(0) | ||
// val isHandled = _notificationLifecycleService.canOpenNotification(activity, firstPayloadItem) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line is not used, should we remove it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line was pre-existing, the whole function was copied over from the other file. However, I cleaned it up since were are looking at it now.
In rare cases when tapping on a notification the app would not open, as well as other issues like the click not being counted either. The issue was due to a race condition between NotificationListener.start and processing the click event. To fix and to avoid this mistake in the future moved all the code from NotificationListener into NotificationLifecycleService. There wasn't a clear set of responsibility difference between these to classes so this is also a win to remove complexity. Was able to reproduce the issue 1/5 times on an Android 14 (no extension level) emulator. After testing 20 times I am no longer able to reproduce the issue now.
33ef39f
to
571f7ec
Compare
In this case it made sense to merge the classes, since they had the same responsibilities anyway, but this isn't a solution across the code base. One idea is on all passed in dependencies we call |
Description
One Line Summary
Fix very rare bug where app doesn't opening from notification tap when it cold starts the app.
Details
In rare cases when tapping on a notification the app would not open, as well as other issues like the click not being counted either.
The issue was due to a race condition between
NotificationListener.start and processing the click event. To fix and to avoid this mistake in the future moved all the code from NotificationListener into NotificationLifecycleService. There wasn't a clear set of responsibility difference between these to classes so this is also a win to remove complexity.
Motivation
By default it is expected that the app should open when tapping on a notification.
Scope
Code changes are only around notification event handling.
Testing
Unit testing
Added new
NotificationLifecycleServiceTests
test class.Manual testing
Was able to reproduce the issue 1/5 times on an Android 14 (no extension level) emulator. After testing 20 times I am no longer able to reproduce the issue now.
Affected code checklist
Checklist
Overview
Testing
Final pass
This change is