SlideShare a Scribd company logo
Building Push Applications
for Android
Debajit Ghosh
May 20, 2010
View live notes and ask questions
about this session on Google Wave
http://bit.ly/ac2dmwave
Outline

•  Accessing Data in the Cloud
•  Polling and Pushing
•  Android Cloud to Device Messaging
•  Demos
•  Summary




4
Accessing Data in the Cloud

•  Apps provide seamless access to data in the cloud
    –  Mobile Alerts
    –  Send to Phone
    –  Background Sync
•  Challenge: How do you keep data on a device fresh?




5
Polling

•  Simple to implement
•  Device periodically asks server for new data
    –  Radio draws a lot of power, stays on for several seconds
    –  Ideally, use If-Modified-Since, If-None-Match, etc.
        •  Make no-ops as cheap as possible
•  Appropriate for content that changes constantly
    –  Stock Quotes, News Headlines
    –  Poll infrequently, update on demand




6
Impact of Polling on Battery


                                             •  Baseline: ~5-8 mA
                                             •  Network: ~180-200 mA
                                                –  Tx more expensive than Rx
                                             •  Radio stays on for few secs
                                             •  ~0.50 mAh for a short poll
                                                –  5m frequency: ~144 mAh / day
                                                –  15m frequency: ~48 mAh / day




Source: Android development team at Google


7
When to Poll?

•  Tradeoff between freshness and efficiency
    –  Poll frequently – more fresh, less efficient
•  Desire: Push, don’t poll
    –  Only fetch data when useful




8
Pushing

•  Enables freshness with less impact on battery
    –  Only use network when necessary
    –  Constant overhead of persistent connection
•  Google Contacts, Calendar, Gmail, etc., use push sync
•  Can be tricky to implement
•  Android Cloud to Device Messaging makes push easy




9
Android Cloud to Device Messaging

•  Simple Google API
     –  Android 2.2 devices with Market
     –  Will be open to all developers
•  Uses existing connection for Google services
•  Allows servers to send lightweight “data” messages to apps
     –  Tell app new data available
     –  Intent broadcast wakes up app
     –  App supplies UI, e.g., Notification, if/as necessary
•  Best effort delivery



10
Peeking Under the Hood

•  Background service
     –  Honor background data setting
     –  Start when network available
•  Maintain connection with server
     –  Use heartbeats to keep alive, detect dead connections
•  Efficient
     –  Minimize per connect overhead
     –  Minimize heartbeat frequency
     –  Minimize concurrent connections




11
Heartbeats




                               X
                               ✓
                                 PING


                                 ACK
                                                       SERVER




      •  Use Alarms                     •  Can also initiate ping
         •  (Re)schedule pings              •  May be half open
         •  Wait for acks               •  Clean up state when dead
      •  Reconnect when dead

12
Overview of Lifecycle

•  Enabling cloud to device messaging
     –  App (on device) registers with Google, gets registration ID
     –  App sends registration ID to its App Server
•  Per message
     –  App Server sends (authenticated) message to Google
     –  Google sends message to device
•  Disabling cloud to device messaging
     –  App can unregister ID, e.g., when user no longer wants push




13
Life of a Message

                     CONN
                    SERVER

      WAKE
      UP!           GOOGLE
       APP
                     C2D MSG
                    FRONTEND




                     APP
                    SERVER




14
Registration – Requesting a Registration ID

// Use the Intent API to get a registration ID
// Registration ID is compartmentalized per app/device
Intent regIntent = new
  Intent(“com.google.android.c2dm.intent.REGISTER”);
// Identify your app
regIntent.putExtra(“app”,
     PendingIntent.getBroadcast(this, 0, new Intent(), 0);
// Identify role account server will use to send
regIntent.putExtra(“sender”, emailOfSender);
// Start the registration process
startService(regIntent);




15
Registration – Receiving the Registration ID

•  App receives the ID as an Intent
     –  com.google.android.c2dm.intent.REGISTRATION
•  App should send this ID to its server
•  Service may issue new registration ID at any time
     –  App will receive REGISTRATION Intent broadcast
     –  App must update server with new ID




16
Registration – Receiving the Registration ID

// Registration ID received via an Intent
public void onReceive(Context context, Intent intent) {
     String action = intent.getAction();
     if (“…REGISTRATION”.equals(action)) {
       handleRegistration(context, intent);
     } }


private void handleRegistration(Context context, Intent intent){
     String id = intent.getExtra(“registration_id”);
     if ((intent.getExtra(“error”) != null) {
       // Registration failed.   Try again later, with backoff.
     } else if (id != null) {
       // Send the registration ID to the app’s server.
       // Be sure to do this in a separate thread.
     } }
17
Sending Messages

•  Get “ac2dm” auth token, install on server
     –  http://code.google.com/apis/accounts/docs/AuthForInstalledApps.html
•  Send authenticated POST
     –  https://android.apis.google.com/c2dm/send
     –  Authorization: GoogleLogin auth=<auth token>
     –  URL Encoded parameters
         •  registration_id
         •  collapse_key
         •  (optional) delay_while_idle
         •  (optional) data.<key>*




18
Sending Messages – Response Codes

•  200 OK
     –  With “id” – request succeeded, message enqueued
     –  With “Error” – request failed
         •  QuotaExceeded, DeviceQuotaExceeded: Retry after a while
         •  InvalidRegistration, NotRegistered: Stop sending messages
         •  MessageTooBig: Reduce size of message
         •  MissingCollapseKey: Include collapse key in request
•  401 Not Authorized: Get new auth token
•  503 Service Unavailable: Retry with backoff




19
Receiving Messages

•  Device receives message, converts to Intent
•  App woken up/started by Intent broadcast
     –  com.google.android.c2dm.intent.RECEIVE
     –  data.<key>* set as Intent extras
     –  App needs com.example.app.permission.C2D_MESSAGE


public void onReceive(Context context, Intent intent) {
     String action = intent.getAction();
     if (“…RECEIVE”.equals(action)) {
         // Grab a wakelock, use IntentService to do work
     }
}


20
Collapse Keys

•  Latest message replaces older ones with same key
•  Avoids message explosion for offline device
•  App may use multiple collapse keys
     –  Correspond to “feed” app will fetch
     –  Max of four in flight (per device)
•  State should be in app server, not in message
     –  Tell app when it should fetch data




21
Collapse Keys

                 CONN
                SERVER


                GOOGLE
                 C2D MSG
                FRONTEND




                 APP
                SERVER




22
Attenuation

•  Messages may not be delivered to device immediately
•  Protects devices that are receiving many messages
     –  Avoid constant radio wakeup
•  Attenuation per app/collapse key




23
Attenuation

               CONN
              SERVER


              GOOGLE
               C2D MSG
              FRONTEND




               APP
              SERVER




24
Delay While Idle

•  Device tells Connection Server when screen is on, off
     –  Screen off == device is idle
•  Apps can request message only be delivered when active
     –  Avoid waking up device with info that will not be seen/used
     –  e.g., chat presence, friend location updates




25
Delay While Idle

                    CONN
                   SERVER


                   GOOGLE
      Zzzz
                    C2D MSG
                   FRONTEND




                    APP
                   SERVER




26
Demo: Google Chrome to Phone Extension

•  Send any web page to Android device
     –  Special handling for Maps, YouTube
•  Chrome Extension
•  App Engine backend
                              APP
                             ENGINE
                                         AC2DM




                             ORIGIN
                            SERVER

27
Demo: JumpNote

•  Notes, with two way push sync
         –  App Engine backend, GWT UI
•  Uses Sync Framework
•  Uses Android Cloud to Device Messaging
         –  Register, Unregister based on auto-sync selection

public void onReceive(Context context, Intent intent) {
     String action = intent.getAction();
     if (“…RECEIVE”.equals(action)) {
         // Determine account, feed that changed …
         context.getContentResolver.requestSync(account, “…jumpnote”, extras);
     }
}

28
Android Cloud to Device Messaging Signup

•  Launching in Labs, accepting signups
•  Visit http://code.google.com/android/c2dm for details




29
Summary

•  Many Android apps access data in cloud
•  Push keeps apps up to date, efficiently
•  Android Cloud to Device Messaging makes push simple
•  Sign up now
     –  http://code.google.com/android/c2dm




30
View live notes and ask questions
about this session on Google Wave
http://bit.ly/ac2dmwave
Android push-applications-android

More Related Content

Similar to Android push-applications-android

google cloud messaging
google cloud messaginggoogle cloud messaging
google cloud messaging
shuklajiawesome
 
Accelerrate your PaaS to the Mobile World
Accelerrate your PaaS to the Mobile WorldAccelerrate your PaaS to the Mobile World
Accelerrate your PaaS to the Mobile World
Ryan Campbell
 
AndroidAppPPT
AndroidAppPPTAndroidAppPPT
AndroidAppPPT
Akchay Srivastava
 
GCM aperitivo Android
GCM aperitivo AndroidGCM aperitivo Android
GCM aperitivo Android
Luca Morettoni
 
Android Cloud To Device Messaging
Android Cloud To Device MessagingAndroid Cloud To Device Messaging
Android Cloud To Device Messaging
Fernando Cejas
 
Android cloud to device messaging
Android cloud to device messagingAndroid cloud to device messaging
Android cloud to device messaging
Fe
 
Leveraging Zend Framework for Sending Push Notifications
Leveraging Zend Framework for Sending Push NotificationsLeveraging Zend Framework for Sending Push Notifications
Leveraging Zend Framework for Sending Push Notifications
Mike Willbanks
 
Android C2DM Presentation at O'Reilly AndroidOpen Conference
Android C2DM Presentation at O'Reilly AndroidOpen ConferenceAndroid C2DM Presentation at O'Reilly AndroidOpen Conference
Android C2DM Presentation at O'Reilly AndroidOpen Conference
Lars Vogel
 
Android Cloud to Device Messaging with the Google App Engine
Android Cloud to Device Messaging with the Google App EngineAndroid Cloud to Device Messaging with the Google App Engine
Android Cloud to Device Messaging with the Google App Engine
Lars Vogel
 
Workshop: Android
Workshop: AndroidWorkshop: Android
Powering your Apps via Google Cloud Platform
Powering your Apps via Google Cloud PlatformPowering your Apps via Google Cloud Platform
Powering your Apps via Google Cloud Platform
Romin Irani
 
Prepare and Manage Remote Applications through Virtualization
Prepare and Manage Remote Applications through Virtualization      Prepare and Manage Remote Applications through Virtualization
Prepare and Manage Remote Applications through Virtualization
Rubal Sagwal
 
Introduction to google cloud messaging in android
Introduction to google cloud messaging in androidIntroduction to google cloud messaging in android
Introduction to google cloud messaging in android
RIA RUI Society
 
128-ch4.pptx
128-ch4.pptx128-ch4.pptx
128-ch4.pptx
SankalpKabra
 
google cloud messaging
google cloud messaginggoogle cloud messaging
google cloud messaging
Bhavana Sharma
 
4Developers 2018: Zero-Downtime deployments with Kubernetes (Mateusz Dymiński)
4Developers 2018: Zero-Downtime deployments with Kubernetes (Mateusz Dymiński)4Developers 2018: Zero-Downtime deployments with Kubernetes (Mateusz Dymiński)
4Developers 2018: Zero-Downtime deployments with Kubernetes (Mateusz Dymiński)
PROIDEA
 
AutoMate+
AutoMate+AutoMate+
AutoMate+
Sanat Maharjan
 
GCM Android
GCM AndroidGCM Android
GCM Android
aswapnal
 
A Google Cloud Solution Minus Dedicated Server - App Only (Server and Client)
A Google Cloud Solution Minus Dedicated Server - App Only (Server and Client)A Google Cloud Solution Minus Dedicated Server - App Only (Server and Client)
A Google Cloud Solution Minus Dedicated Server - App Only (Server and Client)
Chinnayya Math
 
FOSS STHLM Android Cloud to Device Messaging
FOSS STHLM Android Cloud to Device MessagingFOSS STHLM Android Cloud to Device Messaging
FOSS STHLM Android Cloud to Device Messaging
Johan Nilsson
 

Similar to Android push-applications-android (20)

google cloud messaging
google cloud messaginggoogle cloud messaging
google cloud messaging
 
Accelerrate your PaaS to the Mobile World
Accelerrate your PaaS to the Mobile WorldAccelerrate your PaaS to the Mobile World
Accelerrate your PaaS to the Mobile World
 
AndroidAppPPT
AndroidAppPPTAndroidAppPPT
AndroidAppPPT
 
GCM aperitivo Android
GCM aperitivo AndroidGCM aperitivo Android
GCM aperitivo Android
 
Android Cloud To Device Messaging
Android Cloud To Device MessagingAndroid Cloud To Device Messaging
Android Cloud To Device Messaging
 
Android cloud to device messaging
Android cloud to device messagingAndroid cloud to device messaging
Android cloud to device messaging
 
Leveraging Zend Framework for Sending Push Notifications
Leveraging Zend Framework for Sending Push NotificationsLeveraging Zend Framework for Sending Push Notifications
Leveraging Zend Framework for Sending Push Notifications
 
Android C2DM Presentation at O'Reilly AndroidOpen Conference
Android C2DM Presentation at O'Reilly AndroidOpen ConferenceAndroid C2DM Presentation at O'Reilly AndroidOpen Conference
Android C2DM Presentation at O'Reilly AndroidOpen Conference
 
Android Cloud to Device Messaging with the Google App Engine
Android Cloud to Device Messaging with the Google App EngineAndroid Cloud to Device Messaging with the Google App Engine
Android Cloud to Device Messaging with the Google App Engine
 
Workshop: Android
Workshop: AndroidWorkshop: Android
Workshop: Android
 
Powering your Apps via Google Cloud Platform
Powering your Apps via Google Cloud PlatformPowering your Apps via Google Cloud Platform
Powering your Apps via Google Cloud Platform
 
Prepare and Manage Remote Applications through Virtualization
Prepare and Manage Remote Applications through Virtualization      Prepare and Manage Remote Applications through Virtualization
Prepare and Manage Remote Applications through Virtualization
 
Introduction to google cloud messaging in android
Introduction to google cloud messaging in androidIntroduction to google cloud messaging in android
Introduction to google cloud messaging in android
 
128-ch4.pptx
128-ch4.pptx128-ch4.pptx
128-ch4.pptx
 
google cloud messaging
google cloud messaginggoogle cloud messaging
google cloud messaging
 
4Developers 2018: Zero-Downtime deployments with Kubernetes (Mateusz Dymiński)
4Developers 2018: Zero-Downtime deployments with Kubernetes (Mateusz Dymiński)4Developers 2018: Zero-Downtime deployments with Kubernetes (Mateusz Dymiński)
4Developers 2018: Zero-Downtime deployments with Kubernetes (Mateusz Dymiński)
 
AutoMate+
AutoMate+AutoMate+
AutoMate+
 
GCM Android
GCM AndroidGCM Android
GCM Android
 
A Google Cloud Solution Minus Dedicated Server - App Only (Server and Client)
A Google Cloud Solution Minus Dedicated Server - App Only (Server and Client)A Google Cloud Solution Minus Dedicated Server - App Only (Server and Client)
A Google Cloud Solution Minus Dedicated Server - App Only (Server and Client)
 
FOSS STHLM Android Cloud to Device Messaging
FOSS STHLM Android Cloud to Device MessagingFOSS STHLM Android Cloud to Device Messaging
FOSS STHLM Android Cloud to Device Messaging
 

Recently uploaded

AWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptxAWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptx
HarisZaheer8
 
JavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green MasterplanJavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green Masterplan
Miro Wengner
 
Trusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process MiningTrusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process Mining
LucaBarbaro3
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
Ivanti
 
A Comprehensive Guide to DeFi Development Services in 2024
A Comprehensive Guide to DeFi Development Services in 2024A Comprehensive Guide to DeFi Development Services in 2024
A Comprehensive Guide to DeFi Development Services in 2024
Intelisync
 
Public CyberSecurity Awareness Presentation 2024.pptx
Public CyberSecurity Awareness Presentation 2024.pptxPublic CyberSecurity Awareness Presentation 2024.pptx
Public CyberSecurity Awareness Presentation 2024.pptx
marufrahmanstratejm
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
Zilliz
 
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Jeffrey Haguewood
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
Tatiana Kojar
 
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Tatiana Kojar
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
Tomaz Bratanic
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
Jakub Marek
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
Zilliz
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
Zilliz
 
FREE A4 Cyber Security Awareness Posters-Social Engineering part 3
FREE A4 Cyber Security Awareness  Posters-Social Engineering part 3FREE A4 Cyber Security Awareness  Posters-Social Engineering part 3
FREE A4 Cyber Security Awareness Posters-Social Engineering part 3
Data Hops
 
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
saastr
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
ssuserfac0301
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 

Recently uploaded (20)

AWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptxAWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptx
 
JavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green MasterplanJavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green Masterplan
 
Trusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process MiningTrusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process Mining
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
 
A Comprehensive Guide to DeFi Development Services in 2024
A Comprehensive Guide to DeFi Development Services in 2024A Comprehensive Guide to DeFi Development Services in 2024
A Comprehensive Guide to DeFi Development Services in 2024
 
Public CyberSecurity Awareness Presentation 2024.pptx
Public CyberSecurity Awareness Presentation 2024.pptxPublic CyberSecurity Awareness Presentation 2024.pptx
Public CyberSecurity Awareness Presentation 2024.pptx
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
 
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
 
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
 
FREE A4 Cyber Security Awareness Posters-Social Engineering part 3
FREE A4 Cyber Security Awareness  Posters-Social Engineering part 3FREE A4 Cyber Security Awareness  Posters-Social Engineering part 3
FREE A4 Cyber Security Awareness Posters-Social Engineering part 3
 
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 

Android push-applications-android

  • 1.
  • 2. Building Push Applications for Android Debajit Ghosh May 20, 2010
  • 3. View live notes and ask questions about this session on Google Wave http://bit.ly/ac2dmwave
  • 4. Outline •  Accessing Data in the Cloud •  Polling and Pushing •  Android Cloud to Device Messaging •  Demos •  Summary 4
  • 5. Accessing Data in the Cloud •  Apps provide seamless access to data in the cloud –  Mobile Alerts –  Send to Phone –  Background Sync •  Challenge: How do you keep data on a device fresh? 5
  • 6. Polling •  Simple to implement •  Device periodically asks server for new data –  Radio draws a lot of power, stays on for several seconds –  Ideally, use If-Modified-Since, If-None-Match, etc. •  Make no-ops as cheap as possible •  Appropriate for content that changes constantly –  Stock Quotes, News Headlines –  Poll infrequently, update on demand 6
  • 7. Impact of Polling on Battery •  Baseline: ~5-8 mA •  Network: ~180-200 mA –  Tx more expensive than Rx •  Radio stays on for few secs •  ~0.50 mAh for a short poll –  5m frequency: ~144 mAh / day –  15m frequency: ~48 mAh / day Source: Android development team at Google 7
  • 8. When to Poll? •  Tradeoff between freshness and efficiency –  Poll frequently – more fresh, less efficient •  Desire: Push, don’t poll –  Only fetch data when useful 8
  • 9. Pushing •  Enables freshness with less impact on battery –  Only use network when necessary –  Constant overhead of persistent connection •  Google Contacts, Calendar, Gmail, etc., use push sync •  Can be tricky to implement •  Android Cloud to Device Messaging makes push easy 9
  • 10. Android Cloud to Device Messaging •  Simple Google API –  Android 2.2 devices with Market –  Will be open to all developers •  Uses existing connection for Google services •  Allows servers to send lightweight “data” messages to apps –  Tell app new data available –  Intent broadcast wakes up app –  App supplies UI, e.g., Notification, if/as necessary •  Best effort delivery 10
  • 11. Peeking Under the Hood •  Background service –  Honor background data setting –  Start when network available •  Maintain connection with server –  Use heartbeats to keep alive, detect dead connections •  Efficient –  Minimize per connect overhead –  Minimize heartbeat frequency –  Minimize concurrent connections 11
  • 12. Heartbeats X ✓ PING ACK SERVER •  Use Alarms •  Can also initiate ping •  (Re)schedule pings •  May be half open •  Wait for acks •  Clean up state when dead •  Reconnect when dead 12
  • 13. Overview of Lifecycle •  Enabling cloud to device messaging –  App (on device) registers with Google, gets registration ID –  App sends registration ID to its App Server •  Per message –  App Server sends (authenticated) message to Google –  Google sends message to device •  Disabling cloud to device messaging –  App can unregister ID, e.g., when user no longer wants push 13
  • 14. Life of a Message CONN SERVER WAKE UP! GOOGLE APP C2D MSG FRONTEND APP SERVER 14
  • 15. Registration – Requesting a Registration ID // Use the Intent API to get a registration ID // Registration ID is compartmentalized per app/device Intent regIntent = new Intent(“com.google.android.c2dm.intent.REGISTER”); // Identify your app regIntent.putExtra(“app”, PendingIntent.getBroadcast(this, 0, new Intent(), 0); // Identify role account server will use to send regIntent.putExtra(“sender”, emailOfSender); // Start the registration process startService(regIntent); 15
  • 16. Registration – Receiving the Registration ID •  App receives the ID as an Intent –  com.google.android.c2dm.intent.REGISTRATION •  App should send this ID to its server •  Service may issue new registration ID at any time –  App will receive REGISTRATION Intent broadcast –  App must update server with new ID 16
  • 17. Registration – Receiving the Registration ID // Registration ID received via an Intent public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (“…REGISTRATION”.equals(action)) { handleRegistration(context, intent); } } private void handleRegistration(Context context, Intent intent){ String id = intent.getExtra(“registration_id”); if ((intent.getExtra(“error”) != null) { // Registration failed. Try again later, with backoff. } else if (id != null) { // Send the registration ID to the app’s server. // Be sure to do this in a separate thread. } } 17
  • 18. Sending Messages •  Get “ac2dm” auth token, install on server –  http://code.google.com/apis/accounts/docs/AuthForInstalledApps.html •  Send authenticated POST –  https://android.apis.google.com/c2dm/send –  Authorization: GoogleLogin auth=<auth token> –  URL Encoded parameters •  registration_id •  collapse_key •  (optional) delay_while_idle •  (optional) data.<key>* 18
  • 19. Sending Messages – Response Codes •  200 OK –  With “id” – request succeeded, message enqueued –  With “Error” – request failed •  QuotaExceeded, DeviceQuotaExceeded: Retry after a while •  InvalidRegistration, NotRegistered: Stop sending messages •  MessageTooBig: Reduce size of message •  MissingCollapseKey: Include collapse key in request •  401 Not Authorized: Get new auth token •  503 Service Unavailable: Retry with backoff 19
  • 20. Receiving Messages •  Device receives message, converts to Intent •  App woken up/started by Intent broadcast –  com.google.android.c2dm.intent.RECEIVE –  data.<key>* set as Intent extras –  App needs com.example.app.permission.C2D_MESSAGE public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (“…RECEIVE”.equals(action)) { // Grab a wakelock, use IntentService to do work } } 20
  • 21. Collapse Keys •  Latest message replaces older ones with same key •  Avoids message explosion for offline device •  App may use multiple collapse keys –  Correspond to “feed” app will fetch –  Max of four in flight (per device) •  State should be in app server, not in message –  Tell app when it should fetch data 21
  • 22. Collapse Keys CONN SERVER GOOGLE C2D MSG FRONTEND APP SERVER 22
  • 23. Attenuation •  Messages may not be delivered to device immediately •  Protects devices that are receiving many messages –  Avoid constant radio wakeup •  Attenuation per app/collapse key 23
  • 24. Attenuation CONN SERVER GOOGLE C2D MSG FRONTEND APP SERVER 24
  • 25. Delay While Idle •  Device tells Connection Server when screen is on, off –  Screen off == device is idle •  Apps can request message only be delivered when active –  Avoid waking up device with info that will not be seen/used –  e.g., chat presence, friend location updates 25
  • 26. Delay While Idle CONN SERVER GOOGLE Zzzz C2D MSG FRONTEND APP SERVER 26
  • 27. Demo: Google Chrome to Phone Extension •  Send any web page to Android device –  Special handling for Maps, YouTube •  Chrome Extension •  App Engine backend APP ENGINE AC2DM ORIGIN SERVER 27
  • 28. Demo: JumpNote •  Notes, with two way push sync –  App Engine backend, GWT UI •  Uses Sync Framework •  Uses Android Cloud to Device Messaging –  Register, Unregister based on auto-sync selection public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (“…RECEIVE”.equals(action)) { // Determine account, feed that changed … context.getContentResolver.requestSync(account, “…jumpnote”, extras); } } 28
  • 29. Android Cloud to Device Messaging Signup •  Launching in Labs, accepting signups •  Visit http://code.google.com/android/c2dm for details 29
  • 30. Summary •  Many Android apps access data in cloud •  Push keeps apps up to date, efficiently •  Android Cloud to Device Messaging makes push simple •  Sign up now –  http://code.google.com/android/c2dm 30
  • 31. View live notes and ask questions about this session on Google Wave http://bit.ly/ac2dmwave