Azure / azure-sdk-for-android

Android client SDKs for Microsoft Azure
https://azure.github.io/azure-sdk-for-android/
MIT License
97 stars 93 forks source link

[BUG] Azure Communication first chat notification gets lost when app is in killed state #1480

Open Calfredop opened 8 months ago

Calfredop commented 8 months ago

Describe the bug When the app is killed from the Android device task manager, the first chat notification received from Azure Communication Services cannot be shown in any way.

What seems to happens is that when the app gets killed so it does the service extending the FirebaseMessagingService. In normal situations, when an app implementing FirebaseMessagingService is in killed state, the Firebase SDK generates a notifications for the app, using the payload, without triggering the onMessageReceived. This is not the case with Azure Communication Chat notification, since the payload is data only and it's encrypted. For that, the Firebase SDK cannot create a standard notification and since the app is still not running (so neither is the FirebaseMessagingService), no notification can be shown to the user. Once the app has finished starting, the next notifcations payload can go through the decryption/notification flow descripted here.

I could not find any solution to this, because I cannot manipulate the payload before it gets to device, and the device cannot handle it if the app is not up and running.

Exception or Stack Trace No stacktrace generated by this issue.

To Reproduce Steps to reproduce the behavior:

Setup the app with the needed libraries to use azure-communication-chat:2.0.1.

Setup push notifications in Android app as described in the Azure Communication Services official documentation.

Verify that the notification flow works when app is running, by sending messages to user bound to the ChatClient generated by the app.

Kill the app and try to send messages to the same user/ChatClient, to verify that the onMessageReceived is not triggered until the app is running and that Firebase SDK do not generate any notification.

Code Snippet This is an example of Azure Communication Services Chat notification payload that cannot be processed by Firebase SDK:

{"eventId":200, "e": "cCxQh449Xy5qkQ15RYcMfcP5FvTMVeTiolsWVbBfKIZ83V8kEKdIydd42bKddBK7uUR8FFt5eWTfzGbXki0Do7cataG3i3AHMnGzWYzWZk3q15mwgh4..."}

Expected behavior If the app is in killed state the notification should still pop, given a correctly formed payload.

Screenshots Not applicable.

Setup (please complete the following information):

Information Checklist Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report

Maartinsh commented 2 months ago

Did you ever figure it out?

Calfredop commented 2 months ago

Did you ever figure it out?

No the problem resides here "since the payload is data only and it's encrypted". So on the app side there is nothing we can do. The issue is now almost 7 months old so I guess that's a trade for using this library.