element-hq / element-android

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

Push Notifications not working or Inadequate Documentation on setting up FCM GCM push with own Sygnal server #6115

Open jittygitty opened 2 years ago

jittygitty commented 2 years ago

Steps to reproduce

  1. I updated pusher from https://matrix.org/_... to https://myserver/_....
  2. I replaced google-services.json with version from my Firebase account created for app with my own apps package name
  3. I setup Sygnal to connect to Dendrite

But I can NOT get any notifications on android phone.

Outcome

What did you expect?

I expect to get some notification on android phone when app gets a new message.

What happened instead?

Nothing.

I don't see any error messages in sygnal.log or in dendrite log when I'm sending the message and no notification comes up.

Your phone model

Samsung Note9

Operating system version

Android 8.1

Application version and app store

Element 1.4.16-dev olm 3.2.10 matrix sdk 1.4.16

Homeserver

Dendrite github

Will you send logs?

Yes

jittygitty commented 2 years ago

Should note that the tools/test_push.sh did seem to work and gave: "success": 1 But I didn't notice any notification on the android device at all. So it seems issue is with the app not sygnal etc.

jittygitty commented 2 years ago

I guess NOTIFICATIONS simply do not work at all on Android/mobile? I just tested with Official Desktop app talk to Official Android App from GooglePlay, both connected to a dendrite homeserver. The Desktop App gets notifications just fine, but the Android device, nothing at all. Is this a known issue? Notifications don't work on mobile/Android?

ouchadam commented 2 years ago

without knowing your entire setup it's hard to diagnose but I can confirm push notifications are working in Element Android (and in my personal project which hosts its own sygnal server)

To double check

jittygitty commented 2 years ago

@ouchadam I did a lot more testing and decided the issue is likely with dendrite<-->element-android not getting "PUSH RULES".

This is because I noticed in Advanced Settings-Notification Targets that pressing Push Rules showed a BLANK page. But when I connected to MATRIX.ORG server, the notifications WORKED and the PUSH RULES were indeed populated.

Where is the code to negotiate population of those PUSH RULES into the element-android app? I cheated a bit to test/confirm my PUSH RULES theory being the problem by:

  1. In android device connected/LOGGED-IN to my dendrite homeserver, I ALSO opened a private chat to another device connected/logged-in to MATRIX.ORG but noticed still Push Rules was EMPTY and notifications were not received.
  2. In android device connected/signed-in to MATRIX.org I can indeed RECEIVE notifications even sent to private/direct-message with someone on my dendrite home server. But because its signed in to Matrix.org I do see PUSH Rules populated.

So the app itself seems can receive and I been guessing PUSH RULES aren't propagated to Client from Dendrite server. When/where is this propagation of Push Rules from homeserver to client happen?

(PLEASE NOTE that REGISTRATION on my dendrite homeserver is disabled, so I MANUALLY CREATE users from command-line and so I do NOT do the "registration" process through the CLIENT/element-android app with dendrite, I just use "sign-in".)

Not sure if this would be a bug with Client/Element or with Dendrite. Any suggestions for workaround for now? (Can I somehow manually force Push Rules into client?) thanks!

OH and ALSO, to answer your questions: 1.Does the push tester within firebase display a notification on the device NO. But I think its because of PUSH RULES not propagated on Client/Android device?

  1. Have you associated your app signing key with app id within firebase Hmm I'm using android, not sure I did this and not sure required, I did make sure that i'm using correct "Package Name" in firebase setup and I uploaded the firebase provided JSON file to replace the existing one in element-android off github. I think it's only iOS that might require some further signature association. For Android, compiling the JSON into it and the package name matching is proof enough and Firebase should send to it. And using OFFICIAL matrix Element app from GPLAY has same exact issue with Notifications not working if I connect to my own homeserver when it actually uses "Matrix.org" as the PUSHGATEWAY and not mine. So I still think issue is somehow related to PUSH RULES not being propagated to client etc.

  2. Have you associated your firebase instance with sygnal config YES. But these NOTIFICATIONS issues persist even if I am using OFFICIAL MATRIX Google Play app, which would by default I think use Matrix' own push gateway, not mine anyway. So because of this I don't think issue is firebase/api/google-services.json etc. But yea I did test with my own compiled version of Element Android with my own google.json file and correct api server key in sygnal yaml etc. Previously I had senderid mismatch but after using my own google.json file that was resolve etc.

jittygitty commented 2 years ago

@ouchadam Can you confirm in your personal project where notifications work, are you using DENDRITE with sygnal or are you using Synapse instead? Also if indeed you are using DENDRITE, did you create the user you're logged into element android, did you create it from command-line on Dendrite server, or did you actually do the "Registration" process in element app to register user into your dendrite? thanks!

jittygitty commented 2 years ago

@ouchadam This has basically been reconfirmed by me and I think now by others as well. In fact notifications can be made to work by going to the settings of a room or direct message room and changing notifications to "none" and then back to "all". After that you will see the Push Rules will not be blank anymore but populated in Advanced Settings>Notifications>Push Rules

After that NOTIFICATIONS started working, before the push rules populated, they did not work.

ouchadam commented 2 years ago

thanks for the information :+1:

@ouchadam Can you confirm in your personal project where notifications work, are you using DENDRITE with sygnal or are you using Synapse instead?

unfortunately I'm running a synapse homeserver, it's worth noting that sygnal itself is not directly tied to a homeserver, it's a simple http proxy that will forward to the various supported push mechanisms

For Android, compiling the JSON into it and the package name matching is proof enough and Firebase should send to it. And using OFFICIAL matrix Element app from GPLAY has same exact issue with Notifications not working if I connect to my own homeserver when it actually uses "Matrix.org" as the PUSHGATEWAY and not mine. So I still think issue is somehow related to PUSH RULES not being propagated to client etc.

this isn't the case for debug builds pointing to matrix.org, the package id and signing key are used in conjunction to prove debug authenticity

2022-05-24T14:25:46,671205206+01:00

Where is the code to negotiate population of those PUSH RULES into the element-android app

As part of the sync handlers UserAccountDataSyncHandler

New events from the sync are actioned by the ProcessEventForPushTask (FCM push notifications trigger a sync)


This issue sounds like two possible scenarios

jittygitty commented 2 years ago

@ouchadam Actually I can try do double check, because all of my builds are debug builds so far, and I think some of them I had left with matrix.org pushgateway and with matrix.org's github included google json file and I think it works. I also built with my own pushgatway using same debug key, i don't know if the debug key is some generic one or one included in github repo, but notifications are working with my sygnal push-gateway via my custom build using same debug key. So I'm not sure if FCM cares to match the apk signature.

(Just think that you may want to deploy same app with different signatures, to different app stores etc, and if FCM was happy enough with apk containing proper googel-json FCM token and senderid etc, then you would not have to create a separate FCM entry for each different distribution channel and apk signatures. Anyway maybe I can retry sometime to really confirm, but busy with a lot of other things so just can't now.)

I think someone did a recent PULL-Request to Dendrite to fix the Push Rules issue, see: https://github.com/matrix-org/dendrite/pull/2484

S7evinK commented 2 years ago

The issue on Dendrite and using create-account is that it doesn't inform the SyncAPI about about the newly created push rules, so when you login on Android/probably any other client, you won't receive any of the rules. So as a workaround, at least what I've read in #dendrite, you can change any of the push rules (triggers the account data stream to update) and do an initial sync by logging back in to the app. (Or, using the developer options and doing an init sync using the menu)

jittygitty commented 2 years ago

@S7evinK Yea without the https://github.com/matrix-org/dendrite/pull/2484 patch, I was able to populate Push Rules by the mentioned workaround of going to any room and settings on that room and in Notifications changing Notify me for to "none" and then back again to "all messages", and after this the Push Rules will appear in the client finally, instead of all blank.

The above is less hassle than signing out and back in again and having to re-import encryption keys etc etc.

daqulazhang commented 10 months ago

I am wonderring whether this issue perfectly fixed or not?