-
-
Notifications
You must be signed in to change notification settings - Fork 144
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
Start data sync foreground service task when FCM notification is received #3281
Comments
I have noticed that Signal shows a notification saying "Checking for messages…" when FCM notification arrives and it downloads messages. Apparently starting foreground task and showing such notification helps getting access to the network at least on some phones. We should do the same, start a foreground task when notification arrives and this task should display connectivity status and display failure if connectivity does not become "connected" after some timeout. |
I have WhatsApp on my phone and it seems that it does the same. At least i see this "You may have new messages" when a bus with wi-fi passes by me. But i don't remember that it shows any failures. A user may have a poor connection quite a long time, so i'm not sure we should scare users with errors. |
shouldn't we go for iirc, and yes, before in case these two things are not sufficient, we can iterate still wondering, if there is a degradation somewhere, iirc, maybe due to the changed API version, android does things differently and kills app faster |
Just calling If we really need to know when background fetch finishes, then we need to change the core to reuse existing connections rather than just pausing I/O. On iOS it is only fine because most of the time I/O is stopped anyway. |
we should probably also ask for disabling battery optimizations for the app even if push notifications are are available, I always felt not doing so could bring potential issues |
Signal seems to only do this if you have no Play Services it seems, so should not be necessary. But maybe this is why they have to show foreground task notification. At least one recent report from Android 12 had |
I opened a related issue regarding Android >=13 where it is possible to deny notifications on the first start: #3305 |
Foreground task should be of We seem to have a "remote messaging" service (https://developer.android.com/develop/background-work/services/fg-service-types#remote-messaging), this should probably also be changed to dataSync. "Remote messaging" is basically what WhatsApp does when you connect web version to the phone: https://support.google.com/googleplay/android-developer/answer/13392821 |
Seems data sync tasks can run for 6 hours: Other tasks like remote messaging get only 3 minutes. |
well showing a "Checking for messages…" permanent notifications should be easy the question is how/when to remove it, because there is not clear "sync/fetch messages" blocking call in core api to know when core finished fetching, unless we use BTW, it sounds really odd to me that the app would need to show a permanent notification to get network access, it still counts as being in background so if background activity is blocked that will not solve this problem, also in some part you said that "the log clearly showed that messages were downloaded in background after receiving FCM notification" so it is not clear to me what exactly a "Checking for messages…" permanent notification would solve, the issue is about sometimes the connection being unavailable at the time of trying to check so in that case the "you may have new messages" normal notification that just opens the app on tapping sounds better |
thanks a lot for the heads up, @link2xt and @adbenitez
indeed, this is also unclear to me if we do not use before
imu, the permanent notification is not to get network access, but to stay active - and this makes some sense, iirc, there is just no background activity allowed on newer androids without showing a permanent notification. that signal/whatsapp show one as well points into that direction. anyway, worth a try. the notification as such is a simple change, we are using it already on various places (with dataSync-flag iirc). if it does not solve the issue, we can iterate :) |
But starting a foreground task makes the app considered to be in the foreground, right? Otherwise if the app has background access disabled it cannot download messages when receiving FCM notification at all. |
If it's easier, use
|
saying post-notifications-granted=false on API that do not need this grant is misleading as it looks as some error or if the user has rejected sth. just stumbled upon that and was irritated when trying out things wrt #3281 on android7
i have to re-dive into that again, but iirc, one needs to add a "visible permanent notification" for work needed to be done in the background - this is eg. also the case when doing an export and leave the app's activities, eg. by going to android's home screen - the export should be continued in background then. iirc, androids/googles idea is that every bit running is somehow visible to the user. but the wording foreground/background is confusing here, maybe also in our own code :) |
saying post-notifications-granted=false on API that do not need this grant is misleading as it looks as some error or if the user has rejected sth. just stumbled upon that and was irritated when trying out things wrt #3281 on android7
Currently FCM notifications are only used to start the application if it is in background so it can download the messages:
deltachat-android/src/gplay/java/org/thoughtcrime/securesms/notifications/FcmReceiveService.java
Lines 95 to 101 in 56717d3
Notification is shown only once core downloads a new message from IMAP and decides that notification should be shown. It is done this way to prevent showing notifications for read receipts as the server does not know for encrypted messages if the message is read receipt or not.
Users however report that on some Android phones application fails to connect immediately after receiving FCM notification and only downloads the messages when user opens the application. Because of this FCM notifications effectively do nothing, application starts in the background but cannot download messages. This seems to happen at least on some stock Samsung phones. See https://support.delta.chat/t/push-notifications-not-working-with-chatmail-server/3245/5. It should also be possible to replicate on vanilla Android by going to App info -> Mobile data & Wi-Fi and switching off "Background data" or configuring non-existing proxy.
In this case it would be nice to be able to show a local notification saying something like "Failed to connect". This can be done by checking connectivity status when FCM notification is received and if it is
DC_CONNECTIVITY_NOT_CONNECTED
show a notification "Failed to connect". Normally this should not happen because if we can connect to FCM, we should at least be in the "connecting" state in Delta Chat unless OS blocks internet connectivity.As this may be annoying to receive these notifications constantly on OS that don't allow fixing this behavior, it should be possible to disable the option and it should suggest disable this in the notification if it is enabled by default.
The text was updated successfully, but these errors were encountered: