SlideShare a Scribd company logo
1 of 83
Download to read offline
Sync              ON ANDROID


Jerzy Chalupski
chalup
jerzy@futuresimple.com
What we do in general...
What we do ALL THE TIME




                          sync, sync, sync, sync
Sync     ON ANDROID




   OVERVIEW                ARCHITECTURE

CONTENT PROVIDER         PITFALLS & PROTIPS
Sync     ON ANDROID




   OVERVIEW                ARCHITECTURE

CONTENT PROVIDER         PITFALLS & PROTIPS
Not exactly the fresh topic...




        „Developing Android REST client
        applications”
                                     by Virgil Dobjanschi
                                       @Google I/O 2010
Not exactly the fresh topic...




        „Synchronizacja danych z serwisami
        webowymi w Androidzie”
                                   by Bartosz Filipowicz
                                       @KrakDroid 2011
Not exactly the fresh topic...




        „Synchronizacja danych z serwisami
        webowymi w Androidzie”
                                       by Bartosz Filipowicz
                                           @KrakDroid 2011




                        ...but there is still much confusion
AccountManager
 SyncManager
                  UI     Authenticator

ContentProvider
                          SyncAdapter
    ContentResolver
„Wat? Why do I need to write
all this crap, sync is just
fetching data from server”
                         typical reaction
Sync provides data sharing
Sync provides data sharing
             offline mode
Sync provides data sharing
             offline mode
             responsive UI
Sync provides data sharing
             offline mode
             responsive UI

              GREAT UX
Sync     ON ANDROID




   OVERVIEW                ARCHITECTURE

CONTENT PROVIDER         PITFALLS & PROTIPS
ContentProvider 101: CRUD



       CREATE               insert()


       READ                 query()


       UPDATE               update()


       DELETE               delete()
ContentProvider 101: URI




       content://com.futuresimple.krakdroid.Provider/datasets/1
ContentProvider 101: URI




       content://com.futuresimple.krakdroid.Provider/datasets/1
ContentProvider 101: URI




       content://com.futuresimple.krakdroid.Provider/datasets/1
ContentProvider 101: URI




       content://com.futuresimple.krakdroid.Provider/datasets/1
ContentProvider 101: notifications




       content://com.futuresimple.krakdroid.Provider/datasets/1
       content://com.futuresimple.krakdroid.Provider/solutions
       content://com.futuresimple.krakdroid.Provider/solutions/1
       content://com.futuresimple.krakdroid.Provider/solutions/1/answers/1
       content://com.futuresimple.krakdroid.Provider/solutions/1/answers/2
       content://com.futuresimple.krakdroid.Provider/solutions/2/answers/1
ContentProvider 101: notifications




       content://com.futuresimple.krakdroid.Provider/datasets/1
       content://com.futuresimple.krakdroid.Provider/solutions
       content://com.futuresimple.krakdroid.Provider/solutions/1
       content://com.futuresimple.krakdroid.Provider/solutions/1/answers/1
       content://com.futuresimple.krakdroid.Provider/solutions/1/answers/2
       content://com.futuresimple.krakdroid.Provider/solutions/2/answers/1


           ContentResolver.notifyChange(“content://
       com.futuresimple.krakdroid.Provider/datasets/1”);
ContentProvider 101: notifications




        content://com.futuresimple.krakdroid.Provider/datasets/1
        content://com.futuresimple.krakdroid.Provider/solutions
        content://com.futuresimple.krakdroid.Provider/solutions/1
        content://com.futuresimple.krakdroid.Provider/solutions/1/answers/1
        content://com.futuresimple.krakdroid.Provider/solutions/1/answers/2
        content://com.futuresimple.krakdroid.Provider/solutions/2/answers/1


             ContentResolver.notifyChange(“content://
   com.futuresimple.krakdroid.Provider/solutions/1/answers/1”);
Sync     ON ANDROID




   OVERVIEW                ARCHITECTURE

CONTENT PROVIDER         PITFALLS & PROTIPS
AccountManager
 SyncManager
                  UI     Authenticator

ContentProvider
                          SyncAdapter
    ContentResolver
Authenticator                   Sync architecture
                                    CREATING NEW ACCOUNT




AccountManager
        addAccount()


                       UI

 SyncManager                ContentResolver



 SyncAdapter                ContentProvider
Authenticator                   Sync architecture
                                    CREATING NEW ACCOUNT
        addAccount()




AccountManager
        addAccount()


                       UI

 SyncManager                ContentResolver



 SyncAdapter                ContentProvider
Authenticator                   Sync architecture
                                    CREATING NEW ACCOUNT
        addAccount()




AccountManager
        addAccount()


                       UI

 SyncManager                ContentResolver



 SyncAdapter                ContentProvider
Authenticator             Sync architecture
                                    SHOW SYNCED DATA




AccountManager

                 UI
                              query()




 SyncManager          ContentResolver

                              query()




 SyncAdapter          ContentProvider
Authenticator                          Sync architecture
                                                 REQUEST SYNC




AccountManager
        getAccountsByType()


                              UI

 SyncManager                       ContentResolver



 SyncAdapter                       ContentProvider
Authenticator                          Sync architecture
                                                       REQUEST SYNC




AccountManager
        getAccountsByType()


                              UI           requestSync()




 SyncManager                       ContentResolver



 SyncAdapter                       ContentProvider
Authenticator                                  Sync architecture
                                                                 REQUEST SYNC




AccountManager
                  getAccountsByType()


                                        UI           requestSync()




   SyncManager                               ContentResolver

onPerformSync()




   SyncAdapter                               ContentProvider
Authenticator             Sync architecture
                                             EDIT DATA




AccountManager

                 UI               insert()




 SyncManager          ContentResolver

                                  insert()




 SyncAdapter          ContentProvider
Authenticator                         Sync architecture
                                                         EDIT DATA




AccountManager

                 UI                           insert()




 SyncManager                  ContentResolver

                      notifyChange()          insert()




 SyncAdapter                  ContentProvider
Authenticator                         Sync architecture
                                                         EDIT DATA




AccountManager

                 UI                           insert()




 SyncManager                  ContentResolver

                      notifyChange()          insert()




 SyncAdapter                  ContentProvider
Authenticator                                      Sync architecture
                                                                      EDIT DATA




AccountManager

        getAccountsByType()
                              UI                           insert()




 SyncManager                               ContentResolver

                                   notifyChange()          insert()




 SyncAdapter                               ContentProvider
Authenticator                                              Sync architecture
                                                                                EDIT DATA




AccountManager

                  getAccountsByType()
                                        UI                           insert()




   SyncManager                                       ContentResolver

onPerformSync()                              notifyChange()          insert()




   SyncAdapter                                       ContentProvider
Authenticator             Sync architecture
                                     POST NEW DATA




AccountManager

                   UI

   SyncManager          ContentResolver

onPerformSync()




   SyncAdapter          ContentProvider
Authenticator                             Sync architecture
                                                     POST NEW DATA
                  getAuthToken()




AccountManager

                                   UI

   SyncManager                          ContentResolver

onPerformSync()




   SyncAdapter                          ContentProvider
Authenticator                                  Sync architecture
                                                           POST NEW DATA
                  getAuthToken()




AccountManager

                                        UI

   SyncManager                               ContentResolver
                                   query()
onPerformSync()                                          query()




   SyncAdapter                               ContentProvider
Authenticator                                         Sync architecture
                                                                  POST NEW DATA
                  getAuthToken()




AccountManager

                                               UI

   SyncManager                                      ContentResolver
                                          query()
onPerformSync()                                                 query()




   SyncAdapter                     POST
                                                    ContentProvider
Authenticator             Sync architecture
                                     GET NEW DATA




AccountManager

                   UI

   SyncManager          ContentResolver

onPerformSync()




   SyncAdapter          ContentProvider
Authenticator                             Sync architecture
                                                     GET NEW DATA
                  getAuthToken()




AccountManager

                                   UI

   SyncManager                          ContentResolver

onPerformSync()




   SyncAdapter                          ContentProvider
Authenticator                                   Sync architecture
                                                           GET NEW DATA
                  getAuthToken()




AccountManager

                                         UI

   SyncManager                                ContentResolver

onPerformSync()




   SyncAdapter                     GET
                                              ContentProvider
Authenticator                                             Sync architecture
                                                                     GET NEW DATA
                  getAuthToken()




AccountManager

                                             UI

   SyncManager                                      ContentResolver
                                     applyBatch()
onPerformSync()

                                                     applyBatch()




   SyncAdapter                     GET
                                                    ContentProvider
Authenticator                                             Sync architecture
                                                                       GET NEW DATA
                  getAuthToken()




AccountManager

                                             UI

   SyncManager                                      ContentResolver
                                     applyBatch()
onPerformSync()                                                     notifyChange()

                                                     applyBatch()




   SyncAdapter                     GET
                                                    ContentProvider
Authenticator                                               Sync architecture
                                                                            GET NEW DATA
                  getAuthToken()




AccountManager

                                                    onLoaderFinished()
                                             UI

   SyncManager                                      ContentResolver
                                     applyBatch()
onPerformSync()                                                          notifyChange()

                                                       applyBatch()




   SyncAdapter                     GET
                                                    ContentProvider
Authenticator             Sync architecture
                            WIN #1: NO REMOTE I/O IN UI




AccountManager

                 UI

 SyncManager          ContentResolver



 SyncAdapter          ContentProvider
Authenticator             Sync architecture
                             WIN #2: SYNC SCHEDULING




AccountManager

                 UI

 SyncManager          ContentResolver



 SyncAdapter          ContentProvider
Sync     ON ANDROID




   OVERVIEW                ARCHITECTURE

CONTENT PROVIDER         PITFALLS & PROTIPS
IDs in ContentProvider URIs


      content://com.futuresimple.krakdroid.Provider/datasets/1
IDs in ContentProvider URIs


      content://com.futuresimple.krakdroid.Provider/datasets/1




  Plan A: Use local IDs! (BaseColumns._ID)
IDs in ContentProvider URIs


      content://com.futuresimple.krakdroid.Provider/datasets/1




  Plan A: Use local IDs! (BaseColumns._ID)



  ISSUE: still need server-side IDs for relations
IDs in ContentProvider URIs


      content://com.futuresimple.krakdroid.Provider/datasets/1




  Plan A: Use local IDs! (BaseColumns._ID)



  ISSUE: still need server-side IDs for relations
  ISSUE: conversions between server and local IDs
IDs in ContentProvider URIs


   content://com.futuresimple.krakdroid.Provider/datasets/15002900




  Plan B: OK, use server-side IDs!
IDs in ContentProvider URIs


   content://com.futuresimple.krakdroid.Provider/datasets/15002900




  Plan B: OK, use server-side IDs!



  ISSUE: what about offline mode?
IDs in ContentProvider URIs


  content://com.futuresimple.krakdroid.Provider/datasets/-42
  content://com.futuresimple.krakdroid.Provider/datasets/15002900


  Plan C: OK, let’s mix things up!
IDs in ContentProvider URIs


  content://com.futuresimple.krakdroid.Provider/datasets/-42
  content://com.futuresimple.krakdroid.Provider/datasets/15002900


  Plan C: OK, let’s mix things up!



  ISSUE: very tricky implementation
IDs in ContentProvider URIs


     content://com.futuresimple.krakdroid.Provider/datasets/GUID




  Plan D: GUID
IDs in ContentProvider URIs


     content://com.futuresimple.krakdroid.Provider/datasets/GUID




  Plan D: GUID



  ISSUE: needs support on the backend
ContentResolver requestSync() vs. notifyChange()




      requestSync(account, authority, extras)

      notifyChange(uri, observer, syncToNetwork)
ContentResolver requestSync() vs. notifyChange()




      requestSync(account, authority, extras)

      notifyChange(uri, observer, syncToNetwork)
Deleting an account




      From your app

      From system settings

      From 3rd party app
Deleting an account




      From your app
                             “Where should I
      From system settings     perform user
                              data cleanup?”
      From 3rd party app
Deleting an account




  @Override getAccountRemovalAllowed()
Deleting an account




  @Override getAccountRemovalAllowed()



  CONS: depends on current Settings implementation.
  PROS: exactly the thing you need.
Deleting an account



  <receiver
      android:name=".auth.AccountBroadcastReceiver"
      android:enabled="true" >
      <intent-filter>
          <action android:name="android.accounts.LOGIN_ACCOUNTS_CHANGED" />
      </intent-filter>
  </receiver>
Deleting an account



  <receiver
      android:name=".auth.AccountBroadcastReceiver"
      android:enabled="true" >
      <intent-filter>
          <action android:name="android.accounts.LOGIN_ACCOUNTS_CHANGED" />
      </intent-filter>
  </receiver>




  CONS: only info about existing accounts.
  PROS: peace of mind.
Sync lifecycle


   Happy case:
Sync lifecycle


   Happy case:




            requestSync()
Sync lifecycle


   Happy case:


                    onPerformSync()

            requestSync()
Sync lifecycle


   Happy case:


                    onPerformSync()

            requestSync()   onStatusChanged()
Sync lifecycle


   Not-so-happy case:


                    onPerformSync()

            requestSync()   onStatusChanged()
Sync lifecycle


   Not-so-happy case:


                   onPerformSync()

   requestSync()           onStatusChanged()
Sync lifecycle


   Not-so-happy case:


                   onPerformSync()

   requestSync()           cancelSync()
                                +
                        onStatusChanged()
Futureproof your sync
Futureproof your sync



  1. Be lenient on GET
Futureproof your sync



  1. Be lenient on GET
  2. Be strict on POST
Futureproof your sync



  1. Be lenient on GET
  2. Be strict on POST
  3. Have resync in v1.0
?
Thanks.

More Related Content

What's hot

Deep Dive on Amazon Cognito - DevDay Austin 2017
Deep Dive on Amazon Cognito - DevDay Austin 2017Deep Dive on Amazon Cognito - DevDay Austin 2017
Deep Dive on Amazon Cognito - DevDay Austin 2017
Amazon Web Services
 

What's hot (20)

Azure AD B2C Webinar Series: Identity Protocols OIDC and OAuth2 part 1
Azure AD B2C Webinar Series: Identity Protocols OIDC and OAuth2 part 1Azure AD B2C Webinar Series: Identity Protocols OIDC and OAuth2 part 1
Azure AD B2C Webinar Series: Identity Protocols OIDC and OAuth2 part 1
 
(MBL401) Social Logins for Mobile Apps with Amazon Cognito | AWS re:Invent 2014
(MBL401) Social Logins for Mobile Apps with Amazon Cognito | AWS re:Invent 2014(MBL401) Social Logins for Mobile Apps with Amazon Cognito | AWS re:Invent 2014
(MBL401) Social Logins for Mobile Apps with Amazon Cognito | AWS re:Invent 2014
 
Microsoft Graph developer community call-March 2020
Microsoft Graph developer community call-March 2020Microsoft Graph developer community call-March 2020
Microsoft Graph developer community call-March 2020
 
Integrating an App with Amazon Web Services SimpleDB - A Matter of Choices
Integrating an App with Amazon Web Services SimpleDB - A Matter of ChoicesIntegrating an App with Amazon Web Services SimpleDB - A Matter of Choices
Integrating an App with Amazon Web Services SimpleDB - A Matter of Choices
 
Azure AD B2C Webinar Series: Custom Policies Part 1
Azure AD B2C Webinar Series: Custom Policies Part 1Azure AD B2C Webinar Series: Custom Policies Part 1
Azure AD B2C Webinar Series: Custom Policies Part 1
 
Deep Dive on Amazon Cognito - DevDay Austin 2017
Deep Dive on Amazon Cognito - DevDay Austin 2017Deep Dive on Amazon Cognito - DevDay Austin 2017
Deep Dive on Amazon Cognito - DevDay Austin 2017
 
Building Mobile Apps on AWS at Websummit Diublin
Building Mobile Apps on AWS at Websummit DiublinBuilding Mobile Apps on AWS at Websummit Diublin
Building Mobile Apps on AWS at Websummit Diublin
 
Managing Identity and Securing Your Mobile and Web Applications with Amazon C...
Managing Identity and Securing Your Mobile and Web Applications with Amazon C...Managing Identity and Securing Your Mobile and Web Applications with Amazon C...
Managing Identity and Securing Your Mobile and Web Applications with Amazon C...
 
Build Your Mobile App Faster with AWS Mobile Services
Build Your Mobile App Faster with AWS Mobile ServicesBuild Your Mobile App Faster with AWS Mobile Services
Build Your Mobile App Faster with AWS Mobile Services
 
Azure AD B2C Webinar Series: Custom Policies Part 3 Troubleshooting
Azure AD B2C Webinar Series: Custom Policies Part 3 TroubleshootingAzure AD B2C Webinar Series: Custom Policies Part 3 Troubleshooting
Azure AD B2C Webinar Series: Custom Policies Part 3 Troubleshooting
 
Deep Dive on User Sign-up Sign-in with Amazon Cognito - AWS Online Tech Talks
Deep Dive on User Sign-up Sign-in with Amazon Cognito - AWS Online Tech TalksDeep Dive on User Sign-up Sign-in with Amazon Cognito - AWS Online Tech Talks
Deep Dive on User Sign-up Sign-in with Amazon Cognito - AWS Online Tech Talks
 
Authentication and Identity with Amazon Cognito
Authentication and Identity with Amazon CognitoAuthentication and Identity with Amazon Cognito
Authentication and Identity with Amazon Cognito
 
Authentication & Authorization for Connected Mobile & Web Applications using ...
Authentication & Authorization for Connected Mobile & Web Applications using ...Authentication & Authorization for Connected Mobile & Web Applications using ...
Authentication & Authorization for Connected Mobile & Web Applications using ...
 
24032022 Zero Trust for Developers Pub.pdf
24032022 Zero Trust for Developers Pub.pdf24032022 Zero Trust for Developers Pub.pdf
24032022 Zero Trust for Developers Pub.pdf
 
Implement Authorization in your Apps with Microsoft identity platform-June 2020
Implement Authorization in your Apps with Microsoft identity platform-June 2020Implement Authorization in your Apps with Microsoft identity platform-June 2020
Implement Authorization in your Apps with Microsoft identity platform-June 2020
 
Office 365 api vs share point app model
Office 365 api vs share point app modelOffice 365 api vs share point app model
Office 365 api vs share point app model
 
Serverless Patterns: “No server is easier to manage than no server” - AWS Sec...
Serverless Patterns: “No server is easier to manage than no server” - AWS Sec...Serverless Patterns: “No server is easier to manage than no server” - AWS Sec...
Serverless Patterns: “No server is easier to manage than no server” - AWS Sec...
 
Amazon Cognito
Amazon CognitoAmazon Cognito
Amazon Cognito
 
Amazon Cognito Deep Dive
Amazon Cognito Deep DiveAmazon Cognito Deep Dive
Amazon Cognito Deep Dive
 
Cloud-powered Cross-platform Mobile Apps on AWS
Cloud-powered Cross-platform Mobile Apps on AWSCloud-powered Cross-platform Mobile Apps on AWS
Cloud-powered Cross-platform Mobile Apps on AWS
 

Similar to Sync on Android

Dev suite integration
Dev suite integrationDev suite integration
Dev suite integration
iemu
 

Similar to Sync on Android (20)

Build Your Mobile App Faster with AWS Mobile Services (Part 1 - AWS)
Build Your Mobile App Faster with AWS Mobile Services (Part 1 - AWS)Build Your Mobile App Faster with AWS Mobile Services (Part 1 - AWS)
Build Your Mobile App Faster with AWS Mobile Services (Part 1 - AWS)
 
Build high performing mobile apps, faster with AWS
Build high performing mobile apps, faster with AWSBuild high performing mobile apps, faster with AWS
Build high performing mobile apps, faster with AWS
 
Build and Deploy Your Mobile Games
Build and Deploy Your Mobile Games Build and Deploy Your Mobile Games
Build and Deploy Your Mobile Games
 
What's new in the July 2017 Update for Dynamics 365 - Developer features
What's new in the July 2017 Update for Dynamics 365 - Developer featuresWhat's new in the July 2017 Update for Dynamics 365 - Developer features
What's new in the July 2017 Update for Dynamics 365 - Developer features
 
Lightweight Xtext Editors as SWT Widgets
Lightweight Xtext Editors as SWT WidgetsLightweight Xtext Editors as SWT Widgets
Lightweight Xtext Editors as SWT Widgets
 
Introduction to Microservices by Jim Tran, Principal Solutions Architect, AWS
Introduction to Microservices by Jim Tran, Principal Solutions Architect, AWSIntroduction to Microservices by Jim Tran, Principal Solutions Architect, AWS
Introduction to Microservices by Jim Tran, Principal Solutions Architect, AWS
 
MongoDB World 2018: Ch-Ch-Ch-Ch-Changes: Taking Your Stitch Application to th...
MongoDB World 2018: Ch-Ch-Ch-Ch-Changes: Taking Your Stitch Application to th...MongoDB World 2018: Ch-Ch-Ch-Ch-Changes: Taking Your Stitch Application to th...
MongoDB World 2018: Ch-Ch-Ch-Ch-Changes: Taking Your Stitch Application to th...
 
Faites évoluer votre accès aux données avec MongoDB Stitch
Faites évoluer votre accès aux données avec MongoDB StitchFaites évoluer votre accès aux données avec MongoDB Stitch
Faites évoluer votre accès aux données avec MongoDB Stitch
 
Connect + Docker + AWS = Bitbucket Pipelines
Connect + Docker + AWS = Bitbucket PipelinesConnect + Docker + AWS = Bitbucket Pipelines
Connect + Docker + AWS = Bitbucket Pipelines
 
ASP.NET Lecture 6
ASP.NET Lecture 6ASP.NET Lecture 6
ASP.NET Lecture 6
 
Dev suite integration
Dev suite integrationDev suite integration
Dev suite integration
 
(MBL302) Mastering Synchronization Across Mobile Devices, Login Providers, an...
(MBL302) Mastering Synchronization Across Mobile Devices, Login Providers, an...(MBL302) Mastering Synchronization Across Mobile Devices, Login Providers, an...
(MBL302) Mastering Synchronization Across Mobile Devices, Login Providers, an...
 
Introduction to Microservices
Introduction to MicroservicesIntroduction to Microservices
Introduction to Microservices
 
Itb 2021 - Bulding Quick APIs by Gavin Pickin
Itb 2021 - Bulding Quick APIs by Gavin PickinItb 2021 - Bulding Quick APIs by Gavin Pickin
Itb 2021 - Bulding Quick APIs by Gavin Pickin
 
BlackBerry10 apps with Adobe AIR & Apache Flex - BlackBerry JAM Europe
BlackBerry10 apps with Adobe AIR & Apache Flex - BlackBerry JAM EuropeBlackBerry10 apps with Adobe AIR & Apache Flex - BlackBerry JAM Europe
BlackBerry10 apps with Adobe AIR & Apache Flex - BlackBerry JAM Europe
 
Build Your Mobile App Faster with AWS Mobile Services
Build Your Mobile App Faster with AWS Mobile ServicesBuild Your Mobile App Faster with AWS Mobile Services
Build Your Mobile App Faster with AWS Mobile Services
 
Deep Dive into SpaceONE
Deep Dive into SpaceONEDeep Dive into SpaceONE
Deep Dive into SpaceONE
 
Pycon Korea 2018-Sanic을 활용하여 Microservice 구축하기-이재면
Pycon Korea 2018-Sanic을 활용하여 Microservice 구축하기-이재면Pycon Korea 2018-Sanic을 활용하여 Microservice 구축하기-이재면
Pycon Korea 2018-Sanic을 활용하여 Microservice 구축하기-이재면
 
App Modernization with Microsoft Azure
App Modernization with Microsoft AzureApp Modernization with Microsoft Azure
App Modernization with Microsoft Azure
 
Exam 70-488 Developing Microsoft SharePoint Server 2013 Core Solutions Learni...
Exam 70-488 Developing Microsoft SharePoint Server 2013 Core Solutions Learni...Exam 70-488 Developing Microsoft SharePoint Server 2013 Core Solutions Learni...
Exam 70-488 Developing Microsoft SharePoint Server 2013 Core Solutions Learni...
 

Recently uploaded

Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptxHarnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
FIDO Alliance
 
“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf
“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf
“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf
Muhammad Subhan
 
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc
 
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider  Progress from Awareness to Implementation.pptxTales from a Passkey Provider  Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
FIDO Alliance
 

Recently uploaded (20)

Working together SRE & Platform Engineering
Working together SRE & Platform EngineeringWorking together SRE & Platform Engineering
Working together SRE & Platform Engineering
 
The Metaverse: Are We There Yet?
The  Metaverse:    Are   We  There  Yet?The  Metaverse:    Are   We  There  Yet?
The Metaverse: Are We There Yet?
 
ERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage IntacctERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage Intacct
 
ADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptxADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptx
 
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
 
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
 
Intro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptxIntro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptx
 
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptxHarnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
 
“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf
“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf
“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf
 
AI mind or machine power point presentation
AI mind or machine power point presentationAI mind or machine power point presentation
AI mind or machine power point presentation
 
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
 
WebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM PerformanceWebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM Performance
 
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
 
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
 
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
 
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdfIntroduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
 
2024 May Patch Tuesday
2024 May Patch Tuesday2024 May Patch Tuesday
2024 May Patch Tuesday
 
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider  Progress from Awareness to Implementation.pptxTales from a Passkey Provider  Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
 
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdfSimplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
 
WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024
 

Sync on Android

  • 1. Sync ON ANDROID Jerzy Chalupski chalup jerzy@futuresimple.com
  • 2. What we do in general...
  • 3. What we do ALL THE TIME sync, sync, sync, sync
  • 4. Sync ON ANDROID OVERVIEW ARCHITECTURE CONTENT PROVIDER PITFALLS & PROTIPS
  • 5. Sync ON ANDROID OVERVIEW ARCHITECTURE CONTENT PROVIDER PITFALLS & PROTIPS
  • 6. Not exactly the fresh topic... „Developing Android REST client applications” by Virgil Dobjanschi @Google I/O 2010
  • 7. Not exactly the fresh topic... „Synchronizacja danych z serwisami webowymi w Androidzie” by Bartosz Filipowicz @KrakDroid 2011
  • 8. Not exactly the fresh topic... „Synchronizacja danych z serwisami webowymi w Androidzie” by Bartosz Filipowicz @KrakDroid 2011 ...but there is still much confusion
  • 9. AccountManager SyncManager UI Authenticator ContentProvider SyncAdapter ContentResolver
  • 10. „Wat? Why do I need to write all this crap, sync is just fetching data from server” typical reaction
  • 12. Sync provides data sharing offline mode
  • 13. Sync provides data sharing offline mode responsive UI
  • 14. Sync provides data sharing offline mode responsive UI GREAT UX
  • 15. Sync ON ANDROID OVERVIEW ARCHITECTURE CONTENT PROVIDER PITFALLS & PROTIPS
  • 16. ContentProvider 101: CRUD CREATE insert() READ query() UPDATE update() DELETE delete()
  • 17. ContentProvider 101: URI content://com.futuresimple.krakdroid.Provider/datasets/1
  • 18. ContentProvider 101: URI content://com.futuresimple.krakdroid.Provider/datasets/1
  • 19. ContentProvider 101: URI content://com.futuresimple.krakdroid.Provider/datasets/1
  • 20. ContentProvider 101: URI content://com.futuresimple.krakdroid.Provider/datasets/1
  • 21. ContentProvider 101: notifications content://com.futuresimple.krakdroid.Provider/datasets/1 content://com.futuresimple.krakdroid.Provider/solutions content://com.futuresimple.krakdroid.Provider/solutions/1 content://com.futuresimple.krakdroid.Provider/solutions/1/answers/1 content://com.futuresimple.krakdroid.Provider/solutions/1/answers/2 content://com.futuresimple.krakdroid.Provider/solutions/2/answers/1
  • 22. ContentProvider 101: notifications content://com.futuresimple.krakdroid.Provider/datasets/1 content://com.futuresimple.krakdroid.Provider/solutions content://com.futuresimple.krakdroid.Provider/solutions/1 content://com.futuresimple.krakdroid.Provider/solutions/1/answers/1 content://com.futuresimple.krakdroid.Provider/solutions/1/answers/2 content://com.futuresimple.krakdroid.Provider/solutions/2/answers/1 ContentResolver.notifyChange(“content:// com.futuresimple.krakdroid.Provider/datasets/1”);
  • 23. ContentProvider 101: notifications content://com.futuresimple.krakdroid.Provider/datasets/1 content://com.futuresimple.krakdroid.Provider/solutions content://com.futuresimple.krakdroid.Provider/solutions/1 content://com.futuresimple.krakdroid.Provider/solutions/1/answers/1 content://com.futuresimple.krakdroid.Provider/solutions/1/answers/2 content://com.futuresimple.krakdroid.Provider/solutions/2/answers/1 ContentResolver.notifyChange(“content:// com.futuresimple.krakdroid.Provider/solutions/1/answers/1”);
  • 24. Sync ON ANDROID OVERVIEW ARCHITECTURE CONTENT PROVIDER PITFALLS & PROTIPS
  • 25. AccountManager SyncManager UI Authenticator ContentProvider SyncAdapter ContentResolver
  • 26. Authenticator Sync architecture CREATING NEW ACCOUNT AccountManager addAccount() UI SyncManager ContentResolver SyncAdapter ContentProvider
  • 27. Authenticator Sync architecture CREATING NEW ACCOUNT addAccount() AccountManager addAccount() UI SyncManager ContentResolver SyncAdapter ContentProvider
  • 28. Authenticator Sync architecture CREATING NEW ACCOUNT addAccount() AccountManager addAccount() UI SyncManager ContentResolver SyncAdapter ContentProvider
  • 29. Authenticator Sync architecture SHOW SYNCED DATA AccountManager UI query() SyncManager ContentResolver query() SyncAdapter ContentProvider
  • 30. Authenticator Sync architecture REQUEST SYNC AccountManager getAccountsByType() UI SyncManager ContentResolver SyncAdapter ContentProvider
  • 31. Authenticator Sync architecture REQUEST SYNC AccountManager getAccountsByType() UI requestSync() SyncManager ContentResolver SyncAdapter ContentProvider
  • 32. Authenticator Sync architecture REQUEST SYNC AccountManager getAccountsByType() UI requestSync() SyncManager ContentResolver onPerformSync() SyncAdapter ContentProvider
  • 33. Authenticator Sync architecture EDIT DATA AccountManager UI insert() SyncManager ContentResolver insert() SyncAdapter ContentProvider
  • 34. Authenticator Sync architecture EDIT DATA AccountManager UI insert() SyncManager ContentResolver notifyChange() insert() SyncAdapter ContentProvider
  • 35. Authenticator Sync architecture EDIT DATA AccountManager UI insert() SyncManager ContentResolver notifyChange() insert() SyncAdapter ContentProvider
  • 36. Authenticator Sync architecture EDIT DATA AccountManager getAccountsByType() UI insert() SyncManager ContentResolver notifyChange() insert() SyncAdapter ContentProvider
  • 37. Authenticator Sync architecture EDIT DATA AccountManager getAccountsByType() UI insert() SyncManager ContentResolver onPerformSync() notifyChange() insert() SyncAdapter ContentProvider
  • 38. Authenticator Sync architecture POST NEW DATA AccountManager UI SyncManager ContentResolver onPerformSync() SyncAdapter ContentProvider
  • 39. Authenticator Sync architecture POST NEW DATA getAuthToken() AccountManager UI SyncManager ContentResolver onPerformSync() SyncAdapter ContentProvider
  • 40. Authenticator Sync architecture POST NEW DATA getAuthToken() AccountManager UI SyncManager ContentResolver query() onPerformSync() query() SyncAdapter ContentProvider
  • 41. Authenticator Sync architecture POST NEW DATA getAuthToken() AccountManager UI SyncManager ContentResolver query() onPerformSync() query() SyncAdapter POST ContentProvider
  • 42. Authenticator Sync architecture GET NEW DATA AccountManager UI SyncManager ContentResolver onPerformSync() SyncAdapter ContentProvider
  • 43. Authenticator Sync architecture GET NEW DATA getAuthToken() AccountManager UI SyncManager ContentResolver onPerformSync() SyncAdapter ContentProvider
  • 44. Authenticator Sync architecture GET NEW DATA getAuthToken() AccountManager UI SyncManager ContentResolver onPerformSync() SyncAdapter GET ContentProvider
  • 45. Authenticator Sync architecture GET NEW DATA getAuthToken() AccountManager UI SyncManager ContentResolver applyBatch() onPerformSync() applyBatch() SyncAdapter GET ContentProvider
  • 46. Authenticator Sync architecture GET NEW DATA getAuthToken() AccountManager UI SyncManager ContentResolver applyBatch() onPerformSync() notifyChange() applyBatch() SyncAdapter GET ContentProvider
  • 47. Authenticator Sync architecture GET NEW DATA getAuthToken() AccountManager onLoaderFinished() UI SyncManager ContentResolver applyBatch() onPerformSync() notifyChange() applyBatch() SyncAdapter GET ContentProvider
  • 48. Authenticator Sync architecture WIN #1: NO REMOTE I/O IN UI AccountManager UI SyncManager ContentResolver SyncAdapter ContentProvider
  • 49. Authenticator Sync architecture WIN #2: SYNC SCHEDULING AccountManager UI SyncManager ContentResolver SyncAdapter ContentProvider
  • 50. Sync ON ANDROID OVERVIEW ARCHITECTURE CONTENT PROVIDER PITFALLS & PROTIPS
  • 51. IDs in ContentProvider URIs content://com.futuresimple.krakdroid.Provider/datasets/1
  • 52. IDs in ContentProvider URIs content://com.futuresimple.krakdroid.Provider/datasets/1 Plan A: Use local IDs! (BaseColumns._ID)
  • 53. IDs in ContentProvider URIs content://com.futuresimple.krakdroid.Provider/datasets/1 Plan A: Use local IDs! (BaseColumns._ID) ISSUE: still need server-side IDs for relations
  • 54. IDs in ContentProvider URIs content://com.futuresimple.krakdroid.Provider/datasets/1 Plan A: Use local IDs! (BaseColumns._ID) ISSUE: still need server-side IDs for relations ISSUE: conversions between server and local IDs
  • 55. IDs in ContentProvider URIs content://com.futuresimple.krakdroid.Provider/datasets/15002900 Plan B: OK, use server-side IDs!
  • 56. IDs in ContentProvider URIs content://com.futuresimple.krakdroid.Provider/datasets/15002900 Plan B: OK, use server-side IDs! ISSUE: what about offline mode?
  • 57. IDs in ContentProvider URIs content://com.futuresimple.krakdroid.Provider/datasets/-42 content://com.futuresimple.krakdroid.Provider/datasets/15002900 Plan C: OK, let’s mix things up!
  • 58. IDs in ContentProvider URIs content://com.futuresimple.krakdroid.Provider/datasets/-42 content://com.futuresimple.krakdroid.Provider/datasets/15002900 Plan C: OK, let’s mix things up! ISSUE: very tricky implementation
  • 59. IDs in ContentProvider URIs content://com.futuresimple.krakdroid.Provider/datasets/GUID Plan D: GUID
  • 60. IDs in ContentProvider URIs content://com.futuresimple.krakdroid.Provider/datasets/GUID Plan D: GUID ISSUE: needs support on the backend
  • 61. ContentResolver requestSync() vs. notifyChange() requestSync(account, authority, extras) notifyChange(uri, observer, syncToNetwork)
  • 62. ContentResolver requestSync() vs. notifyChange() requestSync(account, authority, extras) notifyChange(uri, observer, syncToNetwork)
  • 63. Deleting an account From your app From system settings From 3rd party app
  • 64. Deleting an account From your app “Where should I From system settings perform user data cleanup?” From 3rd party app
  • 65. Deleting an account @Override getAccountRemovalAllowed()
  • 66. Deleting an account @Override getAccountRemovalAllowed() CONS: depends on current Settings implementation. PROS: exactly the thing you need.
  • 67. Deleting an account <receiver android:name=".auth.AccountBroadcastReceiver" android:enabled="true" > <intent-filter> <action android:name="android.accounts.LOGIN_ACCOUNTS_CHANGED" /> </intent-filter> </receiver>
  • 68. Deleting an account <receiver android:name=".auth.AccountBroadcastReceiver" android:enabled="true" > <intent-filter> <action android:name="android.accounts.LOGIN_ACCOUNTS_CHANGED" /> </intent-filter> </receiver> CONS: only info about existing accounts. PROS: peace of mind.
  • 69. Sync lifecycle Happy case:
  • 70. Sync lifecycle Happy case: requestSync()
  • 71. Sync lifecycle Happy case: onPerformSync() requestSync()
  • 72. Sync lifecycle Happy case: onPerformSync() requestSync() onStatusChanged()
  • 73. Sync lifecycle Not-so-happy case: onPerformSync() requestSync() onStatusChanged()
  • 74. Sync lifecycle Not-so-happy case: onPerformSync() requestSync() onStatusChanged()
  • 75. Sync lifecycle Not-so-happy case: onPerformSync() requestSync() cancelSync() + onStatusChanged()
  • 77. Futureproof your sync 1. Be lenient on GET
  • 78. Futureproof your sync 1. Be lenient on GET 2. Be strict on POST
  • 79. Futureproof your sync 1. Be lenient on GET 2. Be strict on POST 3. Have resync in v1.0
  • 80. ?
  • 81.
  • 82.