1

I have two questions related to Android Push Notification System:

  1. What is the working principle of this system? The client sends its own IP to the Google Cloud Messaging Service (for example when it switches its own IP)? So it a sort of pooling?.
  2. How do you know that Google Cloud Messaging Service "looks into" the content of the notification message (created in the server and dispatched to the client)?
Reaz Murshed
  • 21,071
  • 12
  • 69
  • 87
PenguinEngineer
  • 216
  • 1
  • 7
  • 24
  • "How do you know that Google Cloud Messaging Service "looks into" the content of the notification message" please clarify more – Reaz Murshed Dec 07 '16 at 17:35
  • I would send data within the notification message: so when the client sees the notification, it can take data, without contact the server. Is it possible? I'm sure that GCM Service can't "look into" this message and sniffs data? – PenguinEngineer Dec 07 '16 at 18:09
  • Of course its possible. When a client receives notification, it can easily read the data inside it and can take necessary action without communicating to the server. That's the whole idea of push notification anyway. – Reaz Murshed Dec 08 '16 at 14:52
  • ok, but my initial question was: can I put inside the data (for example) sensitive information? I'm sure that GCM can't see data? or, in other words, data are encypted and decrypted only when the client receives the notification? – PenguinEngineer Dec 08 '16 at 17:22
  • 1
    Yes you can put data inside your notification. Data can be encrypted too. It can be decrypted in the client side. No problem. – Reaz Murshed Dec 09 '16 at 06:48

2 Answers2

1

What is the working principle of this system? The client sends its own IP to the Google Cloud Messaging Service (for example when it switches its own IP)? So it a sort of pooling?

I'm adding an image here describing how GCM works.

How GCM works

This is a step by step presentation. You need to get the push registration ID first when your application launches. So if you've a backend server to send some push notification in your application, you need to pass the registration ID to your backend server. So when you need to send a push notification, your backend server will send the push directly to GCM with the targeted registration ID. GCM manages to push the notification in your device when your device comes online.

So this is not any kind of pooling. The only thing GCM needs to know is the registration ID of your device when it comes online and tries to communicate with GCM. Once your device is registered, GCM sends the push notification using that registration ID.

How do you know that Google Cloud Messaging Service "looks into" the content of the notification message (created in the server and dispatched to the client)?

This question is not very clear to me. As far as I have understood, you wanted to know how GCM understands to whom it needs to send the push notification when the notification is coming from your backend server. If this is your question, then I think I have answered it already in the previous section of my answer.

GCM doesn't need to look into your notification content to know the destination of the push notification. As I said earlier, when your application launches, it requests for a push registration ID from GCM and when it receives an registration ID, you might have to pass the registration ID by calling a service of your backend server. The server then knows to whom it might send some notification.

So, when its time to send a notification to your client application, the backend server sends the notification to GCM with the registration ID you sent to your backend server earlier. GCM then handles sending the push notification to the client when the application comes online.

Hope that helps!

Reaz Murshed
  • 21,071
  • 12
  • 69
  • 87
  • Ok, this is clear, but my question is: how it is possible that GCM Service contacts the client? It must know his address, and this address can change... – PenguinEngineer Dec 07 '16 at 18:16
  • Or maybe during the registration operation the user sends to GCM Service the number of the SIM? – PenguinEngineer Dec 07 '16 at 18:28
  • No the number of the SIM doesn't count here. GCM knows about the registration ID only. As when the application comes online it sends the registration ID itself. This registration ID doesn't change frequently along with the network address changes. – Reaz Murshed Dec 08 '16 at 02:53
1

Answering the question about how GCM service contacts the client, the GCM client contacts GCM to create the connection. You are correct that device addresses change as the device disconnects and reconnects so GCM cannot initiate the connection from the server side.

This connection is maintained as much as possible and is not created for specific messages.

The registration id identifies the device and app and allows GCM to route the message to the device, if it is connected. If it is not connected, GCM needs to wait until the device reconnects.

Ian McDowall
  • 121
  • 2
  • ok, so it is the client that establishes the connection and maintains it. When the connection goes down, again the client contacts the GCM service and establishes a new connection (is it true?). There is a "global" connection used by all applications of the client, or each application maintains a connection? What kind of connection it is? A TCP connection? – PenguinEngineer Dec 08 '16 at 10:08
  • That is correct and the connection is shared for all apps - which gives savings in battery life and data usage. – Ian McDowall Dec 09 '16 at 11:23