microg / GmsCore

Free implementation of Play Services
https://microg.org
Apache License 2.0
8.12k stars 1.69k forks source link

GCM -> FCM Update needed for push messaging #439

Closed chris42 closed 5 years ago

chris42 commented 6 years ago

---- EDITED 26. August for summarizing the history of original issue and needed solution

Google has updated the push messaging infrastructure to FCM and will retire the old setup called GCM in 2019 (https://firebase.googleblog.com/2018/04/time-to-upgrade-from-gcm-to-fcm.html).

Hence apps are moving over to use FCM and stop working with current GCM features of microg. This results in different app behaviors. Some apps do not receive any push messages anymore, others (like Whatsapp) fall back to a polling mechanism, that uses lots of battery.

To use updated apps again with microg, the GCM functionalities mimicking google service framework will need to be updated to FCM.

---- Original Issue that lead to missing FCM functionality issue Hi there,

I have a strange behaviour on my phone with GCM on AOSP Oreo. Some apps can register for GCM, even push notification tester works flawless. However Whatsapp and Threema won't register for the service. I regularly get the message "GmsGcmRegisterSvc(6107): registration not allowed".

So far I have the feeling, that the "ask for new apps" function is not working properly. As it was enabled in the beginning (When installing Threema and Whatsapp the first time), but not anymore.

Is there a way to clear the list of registered apps and start over? This is just a hunch now and want to test this, before digging into other things.

Regards Chris

P.S.: If you have any other idea, let me know. Can also produce some logfiles.

Bountysource

chris42 commented 6 years ago

So I wiped the phone and did a complete reinstall. Same behaviour as before. Apps can register, push notificaton tester and other apps work. However Whatsapp or Threema still do not show up in the registration list and do not receive messages via GCM. Within Threema I can reask the registration with GCM, however it receives a timeout.

Any idea? Any logs needed?

MartinX3 commented 6 years ago

WhatsAPP won't register at my side.

chris42 commented 6 years ago

So I checked with an older version (~mid 2017) of Whatsapp (2.17.223) and that will register fine with GCM.

So it seems that something has changed in the last versions and will need some adaptation in GMS Core.

ArchangeGabriel commented 6 years ago

I don’t know a lot of things about this, but maybe they moved to FCM instead of GCM.

MartinX3 commented 6 years ago

I updated WhatsAPP and since the last update, it registered fine. Maybe, it was because TitaniumBackup Restoration or was there a bug in a previous WhatsAPP version?

tomasz1986 commented 6 years ago

Restoring an app with TitaniumBackup is known to break its GCM, unless the app is capable of re-registering itself. The app's GCM connection may still work though if everything has taken place within the same Android installation, but if it is a different one or a different ROM, then it will always break (as the old token is no longer valid).

chris42 commented 6 years ago

Not sure about FCM. I am not a developer, but it is at the core GCM. They will have changed it, but can't tell to what extend.

I do not use TitaniumBackup Restore and have this phenomenon also with Threema. So far left options are: bug in app or needed adaptation in microg. Will check if older version of Threema solves this as well, then it should be needed adaptation in microg. (As I can't imagine Threema and Whatsapp to share code)

chris42 commented 6 years ago

I guess the issue gets more pressing now, as e.g. Whatsapp does not allow you to install older versions. It forces you to update before registration.

Hence the question: Is microg dead? I haven't seen updates aside from the google service number for a year now and more and more things are getting unusable.

I know about open source developers and "don't bother them, as they are doing it in their free time". But I am not asking to finish this at a certain time, more for a clear status on who is actually still developing this or if no one finds time?

Ra72xx commented 6 years ago

I'd like to ask that question, too. I'm grateful as for several years MicroG has allowed me to be almost Google-free, but I just now try to setup a new smartphone, and I do not longer get MicroG to work. As there is not too much activity on GitHub, it would be great to know if there is a fix in work or if it's time to switch back to Google :-(. As chris42 says, all the usual caveats concerning oss developpers apply ;-).

chris42 commented 6 years ago

I changed the Title to something more meaningful and added a $150 Bounty on Bountysource.

After numerous other issues referenced and talks about it in the forum. What is essentially needed to fix this issue: Rework of GMSCore to update GCM push messaging to FCM. I would consider it solved by the following: Current functionalities re-enabled

I don't think keeping backwards compatibility makes sense, as GCM is to be deactivated. Not sure if a transfer to FCM is feasible for old GCM (not updated) apps?

ale5000-git commented 6 years ago

If I'm not wrong FCM is just an extension of GCM (I'm not sure) so backwards compatibility is implied.

chris42 commented 6 years ago

Yes and No. FCM apparently has a lot of GCM in its core, however the GCM API and servers will be deprecated in April 2019. See here https://firebase.googleblog.com/2018/04/time-to-upgrade-from-gcm-to-fcm.html

pikatchu2k3 commented 6 years ago

Nice idea with the bounty starting for fixing this problem. I will add some bucks too, after the holidays.

dos1 commented 6 years ago

Note that client SDKs and GCM tokens will continue to work indefinitely. However, you won't be able to target the latest version of Google Play Services in your Android app unless you migrate to FCM. (https://developers.google.com/cloud-messaging/faq)

So, basically, microG has to reimplement its push messaging system to use Firebase servers and to add a client-side Firebase API alongside the existing GCM one, so both old and new apps can still work.

chris42 commented 6 years ago

@dos1 Yes pretty much. The GCM part could also be put into an extra proxy app. I think this was done with c2dm as well, when GCM was introduced. The developer would need to see if this is possible and worth to put effort in. First focus should be to adapt FCM API and handling of FCM Servers as this is missing for a lot of people.

Ra72xx commented 6 years ago

Stupid question: Who is the said developper? What's the matter with Marvin? I reverted to GApps because MicroG would no longer work properly, but I eagerly watch the developments here.

FOSSFOREVER commented 6 years ago

This project is very promising. Thanks to all the backers and developers for this. I'll eagerly be watching the developments, too!

kwokkeunglam commented 6 years ago

anyone already started working on it?

chris42 commented 6 years ago

@Larx "The developer" is any developer interested to fix it. Payment is done via bountysource.

@kwokkeunglam "denim2x" just set a bounty goal on bountysource (https://www.bountysource.com/issues/51518216-gcm-fcm-update-needed-for-push-messaging). This does not necessarily mean he started, but apparently he is interested.

Happy to help anyone who is looking into this.

kwokkeunglam commented 6 years ago

I prefer a new way of push, just teach developers to use it.

Save battery + Rich content , yet still free.

anyone support this?

chris42 commented 6 years ago

@kwokkeunglam Could you please clarify what you mean?

dropicallus commented 6 years ago

As mentioned GCM will be replaced by a firebase implemention until feb. 2019. I also think that would be a show stopper of using this project. But from a java developer perspective I think it could be a hard work to find informations about the new apis. Especially if google is still extending their cloud service infrastructure. A second problem is that this project has still only one maintainer, which was still mentioned in the other discussions. But that will slow down the development in the future.

chris42 commented 6 years ago

@kwokkeunglam and @dropicallus If your idea is to create a new push service aside GCM/FCM, this is admirable, but way out of scope of this issue and project. Microg was created to mimic the Google APIs, so apps that are utilizing Google APIs would run on a phone without the Google framework. To now create a new push system, you would need a new API, infrastructure and convince every app out there to use it. Feel free to setup anything to do so, but please understand that this issue and bounty is about FCM within the Google API.

kwokkeunglam commented 6 years ago

@chris42

  1. a push notification ecosystem completely independent of google

  2. I have a plan to use UDP, each message have bytes (8 byte header + 65,527 bytes of data) and fit inside one datagram. ( * fit inside one datagram means you either receive the whole message or you don't receive it. ) after some data used for protocol , such as QoS, resend, deduplicate, encryption, signature, etc; still have around 60000 bytes available for use.

( encryption is a must as UDP do not have it, need to do by ourselves ) Encryption and sign can be done using developer's certificate, like APNS.

There can be feedback UDP message send back to server after receive, or the message will try to resend again.

  1. the foot-print shall be small enough. Works both as an embedded service or as a central service. The SDK will ask user to install a push-service from F-Droid / Any store; If central service is installed, all apps share one UDP connection to backend, which can feature save energy.
    Otherwise, the app can start embedded service to receive push internally.

UDP socket itself is quite energy efficient.

  1. Cost & Developer acceptance: I am not a business man, but are we using letsencrypt for free?
    I am quite sure the cost is lower than running letsencrypt.

Push only require some server farm to run, no need to buy a C.A. cert.

kwokkeunglam commented 6 years ago

@chris42 agree for the out of scope here.

dropicallus commented 6 years ago

@chris42 Thanks for your answer. No that’s not my opinion. I would agree that
@kwokkeunglam idea is out of scope. The only thing I mentioned is that we should find a good development process in the future because these kind of incompatibility issues will arise every time google is changing the api. And that could be very often a month.

kwokkeunglam commented 6 years ago

for developer working on this, i can leave some hint: there may be 2 approaches:

  1. reverse engineer FirebaseMessagingService, which partially pro-guarded.
  2. mimic on network level subscribe can be done like this:

    curl -X POST https://android.clients.google.com/c2dm/register3 -H "Authorization: AidLogin 3575596404796697204:6917559070365768661" -H "app: com.firstrowria.pushnotificationtester" -H "gcm_ver: 12874000" -H "User-Agent: Android-GCM/1.5 (generic_x86 KK)" -H "content-type: application/x-www-form-urlencoded" -H "Connection: Keep-Alive" -H "Accept-Encoding: identity" -H "content-length: 206" -d "sender=197533215920&app=com.firstrowria.pushnotificationtester&device=3575596404796697204&cert=1acbe3831cb1827bee6a78879501d7c3bc074987&app_ver=7&info=Q4e--_NDkr0fUO6eTSP7b7Uo8wDiVxY&gcm_ver=12874000&plat=0"

    will get a reply : token=.... which is the push token.

mar-v-in commented 6 years ago

@kwokkeunglam This is already implemented in microG since long time.

FCM is not very well defined as it is 90% GCM in the backend logic and in communication between play services app (or microG) and the google services. I think the only relevant feature of FCM not present before is message channels / topics, which are not yet supported by microG (but also rarely used by apps). I guess GCM and FCM are mostly marketing terms (originally, the technology was called C2DM for client-to-device-messaging, and this term is still used internally in many places). For microG we should probably just call it push messaging.

9e0ee103a145564b1b33158a6b83697021d7ea9e fixes an issue that caused some newer apps to be unable to register for push messaging.

DPTJKKVH commented 6 years ago

@mar-v-in This brings up two questions:

  1. Shouldn't you claim this substantial bounty since you basically fixed the problem everyone has with GCM even though you technically did not fully implement FCM?

  2. Why do both LineageOS for MicroG and F-Droid not offer this updated version? I also saw you pull some new changes to gsmCore today. I think the current surge of bounty money and comments stem from the fact that we still are stuck on 0.2.4-111-gf1cdb48 and thus receive those warnings with Discord, Protonmail and so on.

mar-v-in commented 6 years ago
  1. Not sure about the bounty. As mentioned above, it is not well defined what FCM includes, but certainly the FCM implementation is not completed yet. This issue also has a lot of not-so-much-on-topic discussions about a new shiny open source replacement for push messaging (there are quite some of those out there already, because everyone wants to re-invent the wheel as they think they know things better, and in the end its still worse than Google, because Google has special handling by many ISPs, especially in US). I am not sure what exactly the bounty donators want to be done. Maybe those who did the donation can share what they expected from that bounty (@chris42, @GwenWing, @jacen05, @drrossum, @dicer, @bilbonotry, @avigoureux) - I am happy to reschedule those bounties to more properly defined issues and/or if the bounty was mostly about getting things running again (as it is now using 9e0ee10), I can also accept it as a donation to the project.

  2. The microG F-Droid server and website are already update. The F-Droid client caches the current database for about a day, but you can manually update the database by pulling down on the main screen - if you don't do it you will see the update for 0.2.5.12879 probably tomorrow. Of course this requires you to set up the microG F-Droid repo in your client. A future version of LineageOS for microG will contain the updated release, but you can also install the updated version 0.2.5.12879 directly from the microG F-Droid, download page or from GitHub release section.

chris42 commented 6 years ago

@mar-v-in Good to hear from you and thanks for the changes! I am just trying them, probably will know tomorrow if they solved the original issue. The idea of the bounty was to get push messaging going again, as described above https://github.com/microg/android_packages_apps_GmsCore/issues/439#issuecomment-415826803 If this solves it, I am happy to donate the remains of the bounty to the project.

n76 commented 6 years ago

Long discussion here so I might as well chime in. . .

First, thank you @mar-v-in for everything! I noticed the update in F-Droid earlier today and it installs just fine on my Lineage with microG phone.

Regarding the suggestion from @kwokkeunglam about totally replacing Google on the push messaging: I think that is a non-starter for this project for a very simple reason. MicroG is targeted to allowing apps written for distribution through the Play Store to run on a phone without gapps. As such the app developer's server side mechanisms are setup to use Google for push messaging. It is unlikely that you will be able to change that.

Your only hope would be to add a new push mechanism in addition to supporting Google's and then work to get app developers to migrate to it. That, however, need not be within the scope of this project.

DPTJKKVH commented 6 years ago

@mar-v-in I indeed received an update today and it works great! Thanks a lot Marvin. I was confused by you saying the fix was present for a long time alredy and referring to an 3 months old commit. But I guess the commit made today by you was what was missing.

I will donate directly to the project and not to the issue so you can claim and use the money easier.

Cheers!

PS: If I were you, I would direct this bounty towards the project. Everyone that donated clearly was interested in Notifications working again and you delivered on that today. The off topic and especially the crazy idea of creating an own notification service was introduced by non-donators so it's irrelevant what those said even if a donator replied to them after donating. Chris set the goal in his initial thread and the first donation arrived after his final edit. So everyone who donate shared his goal.

jacen05 commented 6 years ago

I agree with most of the previous comments here:

regentwo commented 6 years ago

Sry guys, I really don't get. It seems that the problem isn't solved with the update at least for me. There are many apps which do not register for push messages like Whatsapp, N26 or local news. I'm able to turn on & off push settings in those apps but it won't have any impact. (and yes I've installed all apps fresh) Protonmail & Push Tester are the only apps working :/

GwenWing commented 6 years ago

Thanks for the fix! I agree too. What we're seeking is the best possible support for notifications without Google Services enabled, whatever it is FCM or GCM. Earlier I read some people say that microG won't work with FCM, and that since Google will kill GCM next year, notifications won't work at all anymore with microG. So maybe it would be useful to state loud at microG website that it supports both FCM and GCM. That's a kind of "marketing" message but it would prevent FUD about the project.

dicer commented 6 years ago

@mar-v-in As one of the bounty funders I would define my goal as follows:

Implementation of all relevant FCM features regarding messaging/push. What is relevant? Well, I don't know either GCM nor FCM APIs, so it's hard to say. I guess, everything that an app needs to enable push. This might include push modes that no major app uses yet (but might in the future) and other new push features (app to app, encrypted push etc). Again: no idea what the FCM/GCM feature base is! These are just examples I made up! Of course the API does not need to be implemented completely. I don't need/want analystics and stuff like that which has no real benefit to the user and does not break apps.

So I guess it is really up to you @mar-v-in to look through the api and decide whether you think it's feature complete for our purposes.

If you think so, I'm happy to pay out the money. If you think there is important stuff missing that will break apps as soon as more developers adopt those functions, I would appreciate a list of classes/methods that need implementation. Then that should be the new goal of the bounty.

bilbonotry commented 6 years ago

As a minor donator, I agree with @jacen05, I think the bounty aim was to make FCM push messaging work. But a status of what is implemented in FCM and what is not would be nice. But I did not contribute much money...

Le mer. 29 août 2018 à 16:19, Felix Knecht notifications@github.com a écrit :

@mar-v-in As one of the bounty funders I would define my goal as follows:

Implementation of all relevant FCM features regarding messaging/push. What is relevant? Well, I don't know either GCM nor FCM APIs, so it's hard to say. I guess, everything that an app needs to enable push. This might include push modes that no major app uses yet (but might in the future) and other new push features (app to app, encrypted push etc). Again: no idea what the FCM/GCM feature base is! These are just examples I made up! Of course the API does not need to be implemented completely. I don't need/want analystics and stuff like that which has no real benefit to the user and does not break apps.

So I guess it is really up to you @mar-v-in to look through the api and decide whether you think it's feature complete for our purposes.

If you think so, I'm happy to pay out the money. If you think there is important stuff missing that will break apps as soon as more developers adopt those functions, I would appreciate a list of classes/methods that need implementation. Then that should be the new goal of the bounty.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/microg/android_packages_apps_GmsCore/issues/439#issuecomment-416970455, or mute the thread https://github.com/notifications/unsubscribe-auth/ARmvDJLtsCpZBUvIPiaC1dgPH4iRrWM_ks5uVqLogaJpZM4QcsUy .

kwokkeunglam commented 6 years ago

sorry for off topic, I would like to gather some help and suggestion for a new push notification system.

https://www.indiegogo.com/project/preview/aef58fc2#/ ( not launched yet, helpers and suggestions wanted )

This is sth I always want to make, one step ahead to make android "google free" .

chris42 commented 6 years ago

@mar-v-in and all: I tried the new version and it is not working for Whatsapp or Threema. Both won't register and will fall back to polling mechanism.

Within Threema I can pinpoint the error in the log and it seems to have changed from the registration not allowed (previous error above) to

08-30 08:51:18.530 W/System.err(25029): java.io.IOException: TIMEOUT
08-30 08:51:18.531 W/System.err(25029):     at bpi.a(Unknown Source:0)
08-30 08:51:18.531 W/System.err(25029):     at ch.threema.app.GcmRegistrationIntentService.onHandleIntent(SourceFile:4000)
08-30 08:51:18.531 W/System.err(25029):     at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:76)
08-30 08:51:18.531 W/System.err(25029):     at android.os.Handler.dispatchMessage(Handler.java:106)
08-30 08:51:18.531 W/System.err(25029):     at android.os.Looper.loop(Looper.java:164)
08-30 08:51:18.531 W/System.err(25029):     at android.os.HandlerThread.run(HandlerThread.java:65)
08-30 08:51:18.531 E/Threema (25029): java.io.IOException: TIMEOUT

With Whatsapp it seems more tricky, as I cannot find a logged error during registration. I found some Firebase related stuff after installation, in which at least Auth is stated as failed, but I am not sure if this has to do with the problem:

08-30 09:05:33.078 D/FirebaseApp(29496): com.google.firebase.auth.FirebaseAuth is not linked. Skipping initialization.
08-30 09:05:33.080 D/FirebaseApp(29496): com.google.firebase.crash.FirebaseCrash is not linked. Skipping initialization.
08-30 09:05:33.083 W/FirebaseInstanceId(29496): Failed to resolve IID implementation package, falling back
08-30 09:05:33.089 I/FirebaseInitProvider(29496): FirebaseApp initialization successful
08-30 09:05:33.097 I/FA      (29496): Collection disabled with firebase_analytics_collection_deactivated=1
08-30 09:05:33.097 I/FA      (29496): App measurement is starting up, version: 11910
08-30 09:05:33.097 I/FA      (29496): To enable debug logging run: adb shell setprop log.tag.FA VERBOSE
08-30 09:05:33.097 I/FA      (29496): To enable faster debug mode event logging run:
08-30 09:05:33.097 I/FA      (29496):   adb shell setprop debug.firebase.analytics.app com.whatsapp

Poking around the net for these errors, I found the following Link: https://github.com/firebase/quickstart-android on which apparently some people try to help getting into Firebase. Maybe that helps to figure out how firebase works and what maybe goes wrong. Also it seems to give some view on functionality (@dicer ).

For now I would say this issue needs more work to be solved. If I can help producing more logs or test anything. Let me know.

chris42 commented 6 years ago

So to update my previous comment: After receiving a few messages, I actually see Whatsapp in the list of the Apps using push messaging. BUT it says not registered and the messages are not counted as well.

I deactivated battery optimization for Whatsapp and will see if message delivery is on time (this is usally not the case in polling mode with battery optimization deactivated). This could give us a hint if push is actually be used.

So summary still stands as: For now I would say this issue needs more work to be solved. If I can help producing more logs or test anything. Let me know.

mar-v-in commented 6 years ago

@kwokkeunglam I don't see the need for another centralized push messaging service (there are already a few, some proprietary, some open source). Something interesting could be a decentralized/federated push messaging service. This is more likely to break out of restricted regions like China and has no risk of going down because the service is not profitable (already happened to some of them). If you base upon XMPP or IMAP, you'd already have a huge federated infrastructure you could use, plus ready to use server and client software.

@chris42 Threema uses its own client implementation for push messaging and always needs special handling ;)

I will send you a few debugging commands for WhatsApp later.

DPTJKKVH commented 6 years ago

I'd really appreciate if we could keep the ridiculous off topic out of this issue. It's very distracting from the actual issue and it's making it very hard for @mar-v-in to claim his bounty.

Please create your own project if you want to tackle such a big task.

PS: This rant is obviously not directed at you, Marvin. Thanks for keeping your cool and investing your time for our all benefit. If you need help with cleaning up issues from off topic content I'll gladly help.

chris42 commented 6 years ago

@mar-v-in It is getting weirder ;-) Just checked the detailed report in Microg for Whatsapp. It shows not registered as well, but also it shows 3 Messages as logged from a hour ago. Since then I probably got 20 messages. Not sure what it is doing.

julienschmidt commented 6 years ago

It seems to be some bug in microg. For about half of my apps it says "Not Registered" in the apps list, but push notifications seem to work fine (e.g. Telegram X, WhatsApp, Riot.im). In the details of the specific app it does however correctly show the number of received messages and the correct time of the last one.

mar-v-in commented 6 years ago

Yes, I can confirm there is a bug that causes some newly registered apps to not show up as registered (but those are still properly registered and receive push messages).

I also noticed that some (very few) apps still don't register for push messages...

chris42 commented 6 years ago

@mar-v-in Any update on this? let me know if I can help with tests or debug.

Schohns commented 6 years ago

One of the apps that don't work for me is IFTTT. It doesn't show up on the list of registered apps as well. I've set up a simple task and apparently it triggered as intended but I never received the notification.

I reinstalled the app, here's the log from that point on: https://pastebin.com/W70z4xdF. One line that caught my eye is the following: 09-04 22:35:41.784 I/AppSecurityPermissions( 5884): Ignoring unknown permission:com.ifttt.ifttt.permission.C2D_MESSAGE

I have to admit I don't know anything about that stuff but I hope this helps a little.

chris42 commented 6 years ago

Just to help a few people trying to figure out if push messaging is working or not, please check the following:

To verify incoming messages, look in you logs and search for "GmsGcmMcsInput". You should see the heartbeat and Incoming messages. In the incoming messages there should be a category stating your apps package. This should be messages your receive via push. (@mar-v-in I hope this is correct?!)

karcherm commented 5 years ago

Freshly installed LineageOS OmniROM 8.1 (unofficial build for Sony Xperia Z3 compact), GmsCore 0.2.5.12879:

I am most interested in whether input on the DB Navigator issue is considered helpful. The other items from my list seem to match known behaviour.