4

I am trying to figure out how Firebase connect to specific devices and send message to it. I now how to use Firebase and send notification to registed devices from my backend server but i don't know how is it working internally. Is firebase severs using persisted connection between device and server? What kind of tehnology is it using?

For now i am mostly interested in Android devices and how firebase wake up device even with background tasks restrictions.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
Patryk kowalski
  • 313
  • 2
  • 5
  • 18

2 Answers2

7

FCM is able to wake a device because the message is actually received by software components that come with Play services, which operates with elevated privileges. Play services can choose to wake the device and deliver the message to the target app.

The FCM software in Play services keeps a persistent socket connection open to its backend under normal circumstances. If it gets connection is dropped, it has logic to reestablish the connection without taxing the battery too much.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
  • So, FCM has elevated privileges because Google Play Services and Firebase are both owned by Google, but what about apps like Messenger/WhatsApp? Messages are delivered by those applications in real time. – Patryk kowalski Apr 19 '19 at 22:32
  • All messages from WhatsApp/Messenger are getting their push notification provided from FCM. Hence, if the device can reach FCM, it can get the push notification awaiting in the firebase server for all applications that are installed in the device. – Reaz Murshed Apr 19 '19 at 22:41
  • Messenger/WhatsApp is using FCM under the hood? Am i understand it correctly? – Patryk kowalski Apr 19 '19 at 22:50
1

I tried to explain how GCM works in my answer here. The internal working principle of Firebase is similar in my opinion.

When you are installing an application which has the Firebase SDK set up in it, it gets a push registration ID from Google server. Usually, you save the push registration ID in your server as well. Hence, when there is a situation for sending a push notification, your server uses this push registration ID to generate a request to the Firebase server for sending a push notification to your device.

Now let us think of the receiver part as well (i.e. your device). In my opinion, in newer versions of Android allows a JobScheduler to check repeatedly for push messages from the Firebase server and if there is one, the device notifies the corresponding application and the application then generates the push notification.

Hope that helps!

Reaz Murshed
  • 23,691
  • 13
  • 78
  • 98