-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Workaround (or fix maybe) for NEW_NOTIFICATION messages #12672
Conversation
Signed-off-by: Dariusz Olszewski <starypatyk@users.noreply.github.com>
132f420
to
b7479c1
Compare
APK file: https://www.kaminsky.me/nc-dev/android-artifacts/12672.apk |
blue-Light-Screenshot test failed: https://www.kaminsky.me/nc-dev/android-integrationTests/12672-Screenshot-blue-Light-12-06 |
Hello there, We hope that the review process is going smooth and is helpful for you. We want to ensure your pull request is reviewed to your satisfaction. If you have a moment, our community management team would very much appreciate your feedback on your experience with this PR review process. Your feedback is valuable to us as we continuously strive to improve our community developer experience. Please take a moment to complete our short survey by clicking on the following link: https://cloud.nextcloud.com/apps/forms/s/i9Ago4EQRZ7TWxjfmeEpPkf6 Thank you for contributing to Nextcloud and we hope to hear from you soon! |
Is there a chance that this could get a review anytime soon? I am experiencing the same bug, and would like to see a workaround getting merged that would prevent deleting the user data the next time. |
I have found a friend that has the same problem. @major-mayer how do you install Nextcloud App? Then I can also built a correctly signed version for you. |
Right now, I don't have this problem anymore. I always install Nextcloud from the Play Store. |
Tested on an affected phone and it work. |
This is an attempt of a workaround (or fix) for #1964.
TL;DR
Incoming notifications are initially handled by system-level FCM code. Then an intent is passed to the application, that is partially handled by Firebase SDK code and partially by the application code in the
onMessageReceived
method.Sometimes (I have not been able to find when), the intent contains an additional flag that causes the Firebase SDK code to handle (display) the notification without invoking at all the
onMessageReceived
method defined in application code.As the unencrypted body of the notification message contains just the NEW_NOTIFICATION text, this is what gets shown to the user.
Code in this PR "intercepts" the incoming intent before the SDK code and clears the notification flag, so the SDK code always invokes the
onMessageReceived
method. The application code can then handle the message as usual - i.e. decrypt it and display proper notification to the user.More detailed description below
Firebase documentation is quite clear that notification messages are delivered to the application code only when the application is in foreground.
So it seems that notification messages should not work at all. But sometimes they do. 😉
I have not been able to find out, why in some cases incoming messages are treated as combined notification/data messages and in other cases as just data messages. This would probably need insight into inner working of the
push-notifications.nextcloud.com
server.I did find out however, that even in cases when the message is treated as a combined notification/data message, the application code is involved in handling of the message.
After some investigation of the Firebase Android SDK, I have found that the decision to show notification or invoke the
onMessageReceived
method is made by theFirebaseMessagingService
class, in thedispatchMessage
method.Then, I found that the
NotificationParams.isNotification
method just checks for values of two extras in the intent sent by the FCM system code.So in this PR, I propose to override the
handleIntent
method and clear these two extras from the incoming intent before letting the Firebase SDK code process it. This means that the notifications will be always delivered to theonMessageReceived
method - as expected.I have been able to get the NEW_NOTIFICATION messages on the emulator - although I am not sure if I can provide a repeatable scenario.
With the additional debug code from this PR, but without clearing the extras in
handleIntent
, I get the wrong notification and the following sequence in the logs.When I clear the extras in
handleIntent
, I get the correct notification and the following logs.