 Okay, so to start off I'll begin with a small demo after which I'll be Showing you how the various steps of what are cloud 2 device messaging is the framework and how the all steps go on For our proper implementation of cloud 2 device messaging and what alternatives could be there for this for implementation of cloud 2 device messaging Yeah, so for demoing, I just build a small application Which can be installed on any phone and what this does is Your application that is there it needs to register to any kind of service From which you need to get the notifications or the messages This could be done So Yeah, so this one is pretty simple it just displayed It registered itself and it displayed the register ready any modification and Then I can use any server application that needs to send a message and hopefully it gets gets sent the phone so Very basic thing of how you're going to send your Data from your server your own most it's over or through what I've done is over here is from the Google App Engine and Sending any kind of data to whatever application that you have using the push notifications framework that is cloud 2 device messaging framework so I like to go a bit faster because I love to cover a lot of steps and I hopefully Will be able to go to all look in corners of what are the basic configurations that are required for Cloud 2 device messaging so a bit about me Yeah, so maybe Discussing Pull versus push why do you require a data continuously on your applications C2DM the requirements for C2DM How does it work the architecture and the settings that are required your registration? How you're going to implement C2DM your client application and your server application and If there are any alternative or if you want to host your own cloud-based service what you could do and it works on it So before I start a few assumptions you know Java You have the experience in building apps, you know broadcast receivers services permissions user permissions application permissions wake logs A&Rs a bit of what should we get first and The bit of Python code because that's what the application service and application is built-in Okay, so start with why we require to send any kind of data from your servers to Your devices like in the case of news applications or in the case of any kind of applications or you want to send updates Like various projects have been spawned for sports updates or any kind of updates in real time You need to set or continuously keep on sending fresh data to your device. So that is the requirement that we want now few approaches are there for sending this kind of data you Use polling in polling. You're going to use timers Which are going to continuously run and after that timer is going to come out You're going to again go to the server Ask if the data has been changed or no if the change that is this one over here Whether the data has been modified or not that will be checked and if it is modified then that data will be sent now Make this advantage over here is if you're going to run your own polling service I have taken this data from the group and our presentation that was done two years ago then C2DM was introduced so The engineers over there they told that our idle power draw is about five to eight million years like when The polling service the service that is there in the background is running Without even going and connecting to the server it uses about five to eight million years But when it starts connecting actually to the server So maybe it wants to connect after five five minutes or so It will fetch about one hundred and forty four million amperes per day. That is about 10 percent of the whole day Whole day's quota of your device battery If you work for 15 minutes Polling that is about 48 million years and you do not want to do this for the particular For the particular device because your user gets fed up and needs to non install your application So instead of this Push can be thought of as an alternative because we continuously do not know when and when I need to keep on polling because Always the data on the server is not going to be updated or there is no proper requirement Or the data may be continuously being updated on the servers. So there are various requirements that need to be met So that can be handled properly on the server side. So instead of code, we are going to use a push now, uh, it only has uh It only uses the network and essentially the battery only when it is necessary That is there are some kind of updates in the server and you can only present the data to the device So how you can do it? You can send a simple sms one That is you run in the sms. So you run in your application. You Uh put on permissions for acceptance of sms and you get the URL and you send an sms to the particular device and That particular device is going to be notified that you need to update your data So this this this particular way is costly because there is the possible form of sending of sms, which is very costly another way is by using a persistent, uh, connection that is, uh means it stays alive But it's going to use a very low level, uh, low amount of battery and it is used to produce some kind of Sorry, uh, that is the third one. Uh before that is back So back essentially is again, uh, in the end you're going to, uh, you're going to require sms to be sent to your device Uh, means after the whole cycle of back that takes place You need to send a message uh to your device, which is going to again, uh, fetch the data based on, uh, the received sms So instead of that, uh We are going to use or we are going to look into, uh, what is c2dm, which is google's persistent connection uh Influences this also used some kind of polling, but uh, good. Let's figure it out. Uh, and also if, uh, it's free Also, it's already been installed on various of the devices while they're being manufactured So instead of providing your own persistent service, which is going to draw another amount of battery from the device You can use the existing service that is provided by google Optimize messaging. It's a free actually standard framework that is provided by google Uh more efficient because it uses big backing on the already existing connection provided by google Messages by best effort delivery here. It's fully meant for notification You cannot, uh, send in like rich application rich data or heavy amounts of data through the framework requirements and limitations So c2dm is supported but that is from through your own words Uh, it requires the device to have a google market app installed Which is going to install the gss that is google services framework On the emulator if you're trying to run on the emulator you require One of the google api is installed from above 2.2 and at least one google account Which is going to be there on the device which is used for connection or and sending or identification of that device Which is used for sending data to that device Uh, some limitations. It is best effort delivery. Uh, it's not so Means how the how the order is that is not predefined The payload is going to going to be fixed at uh, once you know before you cannot exceed that how the data is said We'll be looking uh later It's okay because we just need to send the notifications and we'll be looking that after you send notifications You can run your own service to fetch the actual data from your servers Uh, another important thing it's just still in labs the quota that is there like in the other um other services like Uh, ua and then we'll be discussing uh, it's not quite clear the quota for pricing. It's not clear But what do you mean it doesn't have to be installed to the market? That you just made a point You don't have to be installed by a market Yeah, uh, that is uh your application Uh, necessarily doesn't need to be have be there on that market list Means unsaid application from your own network. You can provide it The only thing is uh, it needs google So market app over here is not uh, connected in any sense with uh, your application You just need it there so that the market uh, the Google services framework from the market app that is installed is going to be used by your application But it doesn't need to be posted on the market market so I'll be going step by step how the way list thinks that takes place Basically them steps for sending in Sending in an authentication and sending the notification from the google service. So this is about the architecture of c2tn Your device. This is the google cloud and if you have your own app server your own app server So one by one, we'll be looking into all of the steps So, uh, I guess I'll uh Move on So I'll move on directly to the steps that are involved. So step zero you need to sign up for an account Uh for sending sending of the messages that are there for sending of notification You need to as it is still in the uh, it's still in the beta. It's in the labs. You need to have a account that is vitally Uh, you need to sign a page and you need to provide the details of how much Estimate of how much messages you're going to send. Uh, what is the peak data? Peak number of messages that you're going to send and it is limited currently to Two million messages per day for that particular sender It also limits to the number of messages that are sent to more device But that again is unclear. It is not even in the quota So contacts you at a roll email which is tightly a google account that is the center Sender address that is going to be used for sending the notifications So the first step Your device needs to be registered for receiving the notifications. So this you're going to do from your application So the device is going to send a registered request to the c2d of front end So a bit about so moving on Notifications from one server one day So one one right listed even address can send uh, two million Notifications in one week just two million Again, there is a limitation of all device and quota So that is not given quite clearly Yeah, it is like, uh, the messages that are going to be sent for device that is not quite clear But if you have a Large amount of like your customers So in that case if you want to go and exit the quota you again need to fill a form and you need to request it from google and they hopefully Send back to your request and you can get a lot of No amount of quota from them, but that is again a paid service. This i'm speaking for free service see the Registration can be done in two ways for your device or for an app So basically what happens is you're going to associate the registration ID with your device or with the application So the registration ID is going to be Issued to the application that is for the device from the c2d in front end Right, so the device is going to ask it, uh, the authorization ID for the device For c2d Step number zero Yeah Request to defend Uh, no It's fine Till when your package name is same So for two different apps, which i create as a developer i'll apply for c2c2d It's fine. It's coming Yeah, it's completely different next time creating another app for which again i have to You have to request another No, you can use the same authorization that you'll be looking you can use the same one It depends on the registration ID that you're going to get from the device and not the one that is already with the developer So there are two authentications in what one is from the device Which is the id for the device second one is for the developer. So you do not need to uh Go on to fetch a new registration for id for every application So therefore because it requires a device that you cannot sign up for c2dm from html5 education You need an idea I'm not quite clear about html5 But uh, yeah, you need to access gsf Like you need to use the file that is provided by marketplace So we'll be looking how that registration takes place You mentioned the application level, but the other one is at the user id level Yeah, that helped me So if coming back to this question, if it is at the app level and then you want it for another app, then you see as a app will also require a separate registration See it depends like uh, you want to have multiple applications from your company on the device But you need to send only one notification for all of the apps This question uh, coming from the back is a little about the limitation of how many number of notifications uh, can be sent But coming back to the registration process If you're talking about the app-based registration, I want to register two apps Inverting that they will have two different packages. So that would be two, two registrations required Yeah That is identified as here If I'm doing it Won't happen that won't happen. Uh, I'll be coming to that point by that won't happen. So No, uh, I'll be telling you what happens. Uh, basically when receiving takes place So only one will be receiving you can single other other applications that I'll install Uh, do I need to message today? So if you have multiple applications only one single application is going to be notified that I'll uh, be explaining and then you can go on Uh, issuing the service for communicating with the other of your other applications Uh, I'll get back to the questions, right? Uh, so first step First step you need to register This is how the app manager manuscript looks. So So simple permissions you require for c2dm sending or receiving which are Distinguished by your app package Over here, they're using gate lock that I'll be speaking about internet connection for sending c2dm permissions for receiving and accepting and receiving of the message One important permission over here is uh, signature level permission. So using this one I make sure that uh, the messages that are going to be Whenever the application is registering from this, uh, this particular Uh, application minute is going to register only this specific application is going to receive whatever messages are going to be said from this C2dm server So only for this signature that is for this package name I'm going to get All the notifications for that particular registration So hopefully, uh, I'll come back to you and answer this your question based on this So, uh, after I specify this, uh, so this you need to specify, uh, not as a user permission So this will become a signature, uh, after you've given that, uh, you need to register your app So you're going to create a new, uh, internet registration Uh, wherein you're going to issue a new intent for registration over here You identify your app using any name over here So that, uh, whenever it is going to get the registered registration intent, it is going to be identified by this particular string Uh, you need to set over here the sender account that is from which particular email address you're going to receive the notifications That is the whiteness your email ID that you have registered You fire up the uh fire of the registration so after the registration happens You need to get the ID that is an ID will be returned to you That you need to send to your app server because that particular ID is going to be used Along with your lecturing it with a username and that particular ID you're going to use for sending notifications to the device Okay, so, uh Uh, using broad pass service, I need to handle the all receive event I'll be showing you the biggest files that I have got so If, uh, simple I need to check whether it is a registration uh action Uh, which is going to be provided to me, uh by the c2d and so that is Google service framework I need to handle I need to get the registration ID over here is unregistered. Uh, this will be true so If there are any errors, there are various errors like service and not available currently or we'll be looking into various errors later on They can be handled over here If you have your registration ID, you get the registration ID, you're going to start a separate trip Uh, this thing over here, uh, you're going to start, uh, like you need to send your ID to your third party server and you're posted So for doing this, you're going to go create a new intent and go out of this because uh, you're not going to create The law, sorry, that is the a and r the unresponsiveness Uh, so over here. I'll be creating a new service. Which is going to Send the data. Uh, that is the ID and it's going to register on the third party. Uh, my app server Can use a service which is essentially going to get the registration ID and Over here you use the device ID from the telephone manager. You can use the device ID And this you're going to send it using a post request to your server to embed some kind of identification The token is there and some kind of identification is there Which is going to be used the token is going to be used along with the identification So that if there's a username that i'm going to use along with the token for sending the Uh, particular notification for the device. So i'm going to record that ID over here So, uh, this is the server side, uh, which has been created in python Assisted so I created a simple To just two fields over here the account name registration ID Uh, I need to handle the post of yet request. I need to get the account and the ID over here Associated the manager's process them. So this data are going to be used for sending Notifications that we'll be looking into So it has been after your device has got the registration ID It has been gone to your server. It is registered over there along with the username Now you need to go and authenticate with the google The google front end, uh, which is going to use the client login service to get an Authentication, uh, token based on the sender in the ID that you have been registered Uh, which is my industry. So using that, uh, send an ID, you'll be getting, uh, an authentication token This you can use using, uh the client login service Where you need to give The parameters uh account type which can be uh Google or hosted or google your email address over here, which is the white listed email address your password The service is a AC to dm And over here the source can be anything, uh, which is being a basic format for which is my company my app and the version of that particular application Uh, header will be application slash and uh form url included Okay, so after I issue this particular issue this particular request I'm going to get a if able to authenticate. I'll get the hdp 200 response with the offline Which is basically my token So this token i'm going to cache it and this token i'm going to use for sending for authenticating with my front end of my c2d app So message with octoken and device id are used They are sent to the server so the whichever device you want to send the message the idea of that i'm going to use And the octoken that i receive these both are going to use and send it to the c2d in front end So if you post wherein you provide the registration id You provide uh, so these are the various fields that are required a registration id Uh, the data which is encoded in the form of uh data dot key equals to value This one is straightforward the device on which you want to send that is a registration id uh to Uh important feature the warrior that are provided as collapse key and delay by id So if uh, you know if you're if the device is offline and you're sending the ddp sending updates So you can club the same type of messages under one collapse key So instead of flooding the device with number of notifications all of those modifications will be clubbed together again One single message so the messages are going to be overwritten based on the collapse key So at once only four collapse key that is four different kind of messages are Supported by google that is delay by ident. So Instead of going, uh, so if this is true, uh, whenever the user screen is not, uh, that is you do not want to using this device like the screen is uh, The screen is black off. So I do not want to wake up the device I can send a send in the notification after the device is going to be So after the user starts using the particular device. So for that, uh, which is going to be handled by google Uh, the process from the addition by google knows when whenever the device is on or off So using that I can set it like I need to uh, send the notification when the whenever the user is up So some of the errors if I do not get a shpp or so, uh the first one then later if Google reissues your odd tokens, uh, without with other specific time frame that is it is going to change the odd taker or tokens for that Send the email id. So in that case you need to go re-login again send the shpp post request to the client login page and get a new odd token 503 the server is busy use pgpacking and go and send the message later logs from submitted time Uh, I should be uh, so some of the iron and iron messages Based on sending or sending Uh, uh, to the device maybe quota exceeded one day quota exceeded device quota for that particular device exceeded invalid registration Not registered means the device is unregistered from the service. It is not it does not currently want to handle Notifications methods to big greater than 1024 Uh missing collapsey collapsey is compensated over here so Step six seven eight these are handled by the google servers Uh, you don't want me to worry about it. What happens is uh, the best is going to be uh, so based on your authentication idea And the device authentication idea is going to uh, first of all authenticate you Then it is going to use the uh messaging queue and it is going to be a queue your message in the c2dm messaging queue And uh, then it is going to ask the c2dm messaging server to round that particular message So what happens is uh, first for it verifies it temporarily queues us queues a message over there Calls some messages until uh, they are delivered or they are going to be expired point when they are going to be delivered It's just best effort delivery If you're going to send messages continuously and the previous message was not delivered to the device With the same registration idea and the collapse key that is same type of message. It is going to replace the existing message Uh, yeah, it's going to avoid so that is going to be used for avoiding overload So previously as i told four that is four different types of messages can be used with the collapse key And then the route round is going to be handled by c2dm messaging server And then the messaging server is going to be delivered by your message which again you need to handle on your device now now So google is uh, uh, so i just want to uh check uh check into the thing that uh, i'm not continuously sending my notifications So that uh, the device is not going to be overloaded with continuous notifications and my battery is not good The device battery is not going to be uh bono It is going to detect number of messages uh for it to add So first few messages are let through As and then they come but subsequent messages may be delayed So this is handled by the queuing servers the logic over there, uh, which is known as for attenuation Which is handled by the google servers. So this is basically used for saving, uh, the battery Of the user. I mean she told you about divine divine ID This is how your messaging server is going to send the message from cloud to your device using, uh, They have a personal connection. Sorry. They have a connection based on the gdoc service over there And so this is how they're going to Send in a whole of the The whole idea behind that is that you're going to send key value pairs over here Uh, and based on the filter that that we have put in your android assembly file, you're going to receive Uh, you're going to receive a call to your on uh, on that is broad cut receiver Broad cut receiver and your broadcast receiver needs to handle the on receive event So, uh, before moving on to handling of the event you can you need to handle Wakelocks because after you're going to go in handling or Petching of data you need to handle wakelock over here So if you're going to use wakelock, it's not compulsory. You compulsory use wakelock, but it's just pretty Visibly use one if you do that you need to provide, uh, this permission wakelock Again, if you have to use your application your android, uh, manifest file Uh, you get a partial wakelock And so two methods that I want to Uh, acquire the wakelock and release the wakelock these are used, uh, later on So when I get the message, uh, I have provided an android, uh, manifest file Which broadcast receiver is going to be called, uh, called for whenever I'm going to receive my message So based on that this, uh, uh, c2gm receiver is going to be, uh, this Is going to be called So here I need to handle, uh, if it is registration I need to handle registration if it is, uh, that was previously done If it is received that is I've got a new message then I, uh, again As I told previously those values are going to be provided as data and, uh, that is key and value pair So I need to fetch, uh, the data based on that particular, uh, key value pair So that key value pair you have already provided from your, uh, Server application as you remember recall So that you're given on your server application Based on that you're going to retrieve it over here And then whatever data is there you can pass it for application Okay, so Then I'm going to get a wakelock over here And start my own because you know we do not want this application to stop working because it isn't the broadcast receiver So I start a new, uh, another service over here Which is going to go and perform the task of refreshing the data that is there on the device So after this data is, uh, fetched, uh, totally visiting of data Maybe I get a post request over here Based on how the passing works I can, uh, pass what kind of data I want to, uh, fetch from my server Then I'll handle this fetching of data over here and then I'll release the wakelock Yeah, and the final step would be, uh, you acknowledge the delivery Uh, after the acknowledging of delivery, uh, C2DM client, uh, sends an ACK That is your, uh, device is going to send an ACK And then your messaging server is going to remove that particular message from the queue Okay, and again if you want to send a recent multiple amount of messages, uh, More messages to the same device You can go and scare her and repeat the step number five And, uh, essentially step by step number two, uh, uh, two and three need to be, uh, run again if, uh, like, you're all here You're going to handle the four So if there is 200, that is, uh, quota exceeded or device quota exceeded as well as 503, uh, that is, the service is not available You need to handle them, that is, you can catch them on the server and later deliver those messages Or you can essentially use, especially with our exposition backup if there is 503 But, uh, if you're going on with the quota exceeded, device quota exceeded, you need to try on later Again, you can also handle the unregistration of that particular app from the, uh, push notification service So this again is going to be handled by your broadcast receiver So on, again over here, while you're just handling the unregistration, uh, it needs to notify your app server, third party app server That this application has unregistered itself So now strong sending messages, uh, uh, to that particular registration ID So quick review of all the steps before I move ahead This was the architecture, 11 steps, easy steps You register for your, you sign in first, step number zero You register yourself You send 90 You record it on the third party app server You authenticate yourself with the client login Use that particular authentication token and catch it so that next time when it wants to authenticate itself, uh, that is If it runs into 401, it is going to again re-shoot the auth Uh, using that authentication token and the device ID, uh, send your message to the security imprinted Our cloud is going to handle, uh, requesting, uh, that is handling the authentication Cueing it to the messaging queue and handling the routing of the, uh, routing of your message And then deliver your message The link of message you're going to refresh the data on your device And the final step would be acknowledgement of the delivery So that was the basic steps that are, uh, that take place while you need to, uh, set up notification, uh, handling From c2dm that is existing, uh The Google framework that is there Some alternatives, uh, can also be used, uh, instead of if you do not want to go to c2dm There are some other alternatives like, uh, there's overnation So this is the same, uh, same framework that is provided by, uh, Google But they have their customized library for c2dm Uh, they have their own proprietary connection library that is android helium Using which they want to set up their own communication, uh, that is, uh Their own protocol they're going to use for communication and push service And, uh, you can also use hybrid, uh, like if you can switch on between the services, uh, instead of c2dm or helium Now for your s3 for using android helium, you need to pay, uh, and you can check out their products You can see the, uh, uh, see the, uh, cost that is required for android helium But you need to pay for that and c2dm again, uh, that is free again up to the two, uh, two million, uh, quota that is there Which is again same as what Google provides Uh, x25, uh, again, uh, they have their own, uh, particular service for push notifications Pretty limited, simple notifications Uh, one thing over here, uh, it's half support for, uh, rich, rich push that is html5, uh, Sending of html5 data directly as push notifications, but for, uh, for android they're going to use, uh, they're going to use a simple notification service Yeah, it will be coming to that. So, uh, good question over here Let me put that in slide, uh, last number of devices are still in 2.1 or later devices, uh, previous devices So these services are not going to be, uh, these services are not going to handle, uh, uh, that kind of push notifications Android helium over here supports, uh, from above, uh, 1.6 But again if you want to support it for any kind of device, you can run in your own position connection So that is the alternative if you do not, if you're not able to support that particular service So you go on to run in your own position connection So some alternatives for running your own connection, uh, like, you do not want the whole strip service from google or, uh, Urban asian and you want to run the whole service from your own servers. You can use these libraries Uh, decal is one of them, a push library, uh, which is, which you can run it on your own server It is built, uh, it is way, uh, to make it lightweight, it uses the, uh, lightweight to meet your browser Everything that you could use for is, uh, MQ telemetry transport, which is built again by IBM So, uh, there are several other few, uh, listings of persistent connection But these are the optimal ones that are available if you want to run your own service or if you want to handle devices Uh, that are below 2.2 Uh, I'll just go on to the summary So we do not want push, so requirement is you want to keep, uh, the data that is there updated Uh, we want to keep the data fresh Uh, polling sucks because a large amount of battery is going to be used by polling So we are going to use push, uh, we could use sms or rap, but again the data charges that are involved Makes it inefficient It's expensive We could run in our own persistent connection, but that again is not, uh, pretty, uh, good because that again is going to cost you with the use of radio and internet And instead of having two different connections, why not use the existing one? So using c2dm, which is again an existing framework over there Uh, it requires some work that is there, uh, setting up, uh, setting up of your application But that is again boilerplate Moderate points over here, features, collabs key that are told you for clubbing, similar, uh, line number of notifications Your attenuation, that is, uh, your delay while idle and your attenuation, that is, uh, you continuously are going to set The uh, the google servers are going to, uh, block in the continuous delivery, uh, which are associated with the same collabs key And last but not the least, they are still in laps, so the ground steps pretty easy