element-hq / element-android

A Matrix collaboration client for Android.
https://element.io/
GNU Affero General Public License v3.0
3.37k stars 721 forks source link

FCM notifications don't work if the app is terminated #1931

Open rkfg opened 4 years ago

rkfg commented 4 years ago

Describe the bug If the app is unloaded from memory for whatever reason (by the OS or force stop) there are no push notifications arriving anymore.

To Reproduce Steps to reproduce the behavior:

  1. Force stop the app
  2. Send yourself a message so that a push would be triggered
  3. There's no push notification until you run the app manually

Expected behavior Pushes should arrive regardless the app state. FCM should deliver them to the system tray where the user can tap them to launch or open the running app.

Smartphone (please complete the following information):

Additional context

This might look like correct behavior at the first glance, if the user unloads the app they explicitly don't want to receive notifications. But the OS can do the same if it needs memory and there's no way to prevent that. The user would then miss messages which is a very bad UX. If the user wants to stop notifications there's an option in the preferences for that.

Another case of notification delays is implicit Doze mode when the device is idle for 30+ minutes. Interestingly enough it's not the same as triggering the Doze manually with adb shell dumpsys deviceidle force-idle (in this case notifications get through). If my phone just lies motionlessly for an hour notifications will also stop until I wake it up and open the app. This shouldn't be the case as the notifications have "high priority" flag by default and yet here we are. I know there are all sorts of nasty vendor tricks that improve UX in other messengers like WhatsApp or Viber. The phone vendors have whitelists for such apps that prevent them from unloading and losing incoming notifications. Element is not on these lists of course.

saligari commented 4 years ago

I know of two cases where they have installed element from the play store and they don't receive any notifications when I message them. Either some bug or extreme battery optimizations by the system?

I use the version from f-droid and I think that I have allowed for background running and also disabled the battery optimizations for the app and I mostly get notifications correctly (I think it doesn't use FCM/GCM).

Could you see if by disabling the battery optimization for the app the issue is resolved?

rkfg commented 4 years ago

No, it still doesn't work after I disable battery optimization. This issue is specifically NOT about the F-Droid version which is expected not to work if you explicitly stop it (or the OS stops the background service for whatever reason). FCM is supposed to work all the time, it's a system service which is able to show notifications on its own, without starting the app. From what I see and know, Element doesn't use this functionality instead relying on showing the popups in onMessageReceive. Which is not called if the app is not running. I believe it would be much better to show the notification from FCM itself, without the content and such (for privacy reasons) but at least it would appear at all. After tapping it the app launches and user can read the details.

BillCarsonFr commented 4 years ago

Hello @rkfg , can you go to settings and run the Notification troubleshoot screen? We should see there if there are any issue with FCM registration.

rkfg commented 4 years ago

Everything's fine. Like I said, I receive notifications most of the time but I don't if I force close the app (or system does). Do you not observe this behavior? Screenshot_20200904-123829

huguesdk commented 4 years ago

a friend of mine has the same problem. notifications only work if the app is launched manually and if it is not silently killed by the system. we disabled battery optimizations for element on his phone and it seems to work better. note that other messaging apps he uses (whatsapp and signal) did not need any tweaking and notifications seem to work flawlessly.

this is with the google play version.

rkfg commented 4 years ago

Yes, turning off battery optimization makes it better and yet it's not 100% reliable. I remember missing notifications and calls (which renders them useless) even when it was on. If there's no notifications in certain normal situations, like leaving the phone on the table for hours without moving it, that's a very bad UX. People will miss messages, and even if it's not as important to read and answer immediately by their nature, they will also miss voice/video calls that have to be answered to be useful.

karthanistyr commented 3 years ago

I have 5 Element Android users (70% of my user base...) on a variety of android devices, OS versions and manufacturers who have consistently complained about a very similar issue. I'm chiming in here as I'm the tech contact, and would like this issue to have more visibility.

They all use the Google Play version that uses FCM, and their symptoms are consistent among them, and consist in notifications working for a short while after they opened the app, but stop appearing at all after that, leading to missed conversations and calls. They also noted that the app appeared to have been killed by the OS despite their best efforts to configure the OS not to do that (no battery optimisation), so there's this correlation.

(On a side note, I have suggested to use fluffychat for those who can, and it also reportedly uses FCM but those who now use it have said the notifications issue is gone with fluffychat.)

brunakov commented 3 years ago

Same issue here with notificatrions. On Xiaomi Note 9 Pro I am receiving notifications on Element Android GPlay when the application is active. If I switch to another app, I am not always receiving notifications / calls. Sometimes I do , sometimes not. Also all tests on notifications troubleshooter pass. Fluffychat seems to work reliable on notifications as others have stated.

kolorafa commented 1 month ago

Don't know about the other cases, but for "force stop" if you do that then notifications will never get delivered, the force stop is intentionally unregistering/preventing app from receiving push notifications.

For the "other reasons" it depends on the specific brand implementations, I know that some of them after few days of not using app will intentionally prevent receiving push, and only disabling some of the optimizations did fix that. I know for a fact that if you install any app on a Samsung device, without disabling some optimization options you will stop getting message notifications after few days of "not using that app".

Normally if you minimize app and then swipe it's activity from recent activities, then the main process should totally stop, you should see no activity/app running in Developer mode > services, but push notifications will still work.

There is also another setting that will remove permissions from app if not used for X days, that one most likely also will block receiving push notifications.

But I totally agree that Android battery optimization options are a mess, they are badly documented and described, so as a user we don't know exactly which options do what, which of them only prevent it fully running in background and which will kill it.

You should not do force close, you should just go out of app and swap the app activity away.


tl-dr

"but I don't if I force close the app"- works as expected OS kill => not getting push - depends on OS