Using contact information,
accounts sync and data submission
model in Android
Alexey Potapov
• Introduction to Contacts Provider
  Structure and Sync Accounts
• Data Modification, Contacts Provider
  Access and Data Consistency
• Determination changes
Contacts Provider Structure




• ContactsContract.Contacts
• ContactsContract.RawContacts
• ContactsContract.Data
ContactsContract.RawContacts

• Sources of raw contacts data
  o Google
  o Facebook
  o etc.
• Important raw contact columns
  o ACCOUNT_NAME
  o ACCOUNT_TYPE
ContactsContract.Data

• Important raw contact columns
• Generic column names
  o Data1 , … , Data16
• Type-specific column names
  o CommonDataKinds.Photo
  o CommonDataKinds.Email
  o etc.
ContactsContract.Contacts
• Neither applications nor
  sync adapters are allowed
  to add contacts
• Contact is representation
  of RawContacts
  aggregation
Contacts Provider Metadata

•   ContactsContract.RawContacts.DIRTY
•   ContactsContract.RawContacts.VERSION
•   ContactsContract.RawContacts.SOURCE_ID
•   ContactsContract.RawContacts.DELETED
•   ContactsContract.Data.DATA_VERSION
Contacts Provider Access and Data
           Consistency
• Contacts Aggregation
• Query contacts and data
• Batch modification
Contacts Aggregation
                               ID=1

              Join      ID=3

ID=1   ID=1
                               ID=2



ID=2   ID=2

                ID=3    ID=1

                                      Separate

                ID=4    ID=2
Query contacts and data

• Lookup Key vs. Contact ID
  Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI,
  String.valueOf(mId));
  ContactsContract.Contacts.getLookupUri(mId, mLookupKey);


• Query entities        API 11

  Uri.withAppendedPath(mContactUri,
  ContactsContract.Contacts.Entity.CONTENT_DIRECTORY);
Batch modification

• Yield points
  o to prevent blocking the system
• Modification back references
  o to use result of a previous operation
• Optimistic concurrency control
  o modification of database without having to lock
     the underlying repository
Determination changes
• ContentObserver
  o onChange(boolean selfChange)
  o onChange(boolean selfChange, Uri uri)   API 16

• Check db modifications by query
  o What we have?
  o What we want?
Short example
SELECT * FROM raw_contacts
    WHERE
        id||‘.’||contact_id||’.’
            ||version
    NOT IN (?)

SELECT * FROM data
    WHERE
        id||‘.’||data_version
    NOT IN (?)

? starred, etc.
Questions ?



      © Alexey Potapov

Using of contact information in android

  • 1.
    Using contact information, accountssync and data submission model in Android Alexey Potapov
  • 2.
    • Introduction toContacts Provider Structure and Sync Accounts • Data Modification, Contacts Provider Access and Data Consistency • Determination changes
  • 3.
    Contacts Provider Structure •ContactsContract.Contacts • ContactsContract.RawContacts • ContactsContract.Data
  • 4.
    ContactsContract.RawContacts • Sources ofraw contacts data o Google o Facebook o etc. • Important raw contact columns o ACCOUNT_NAME o ACCOUNT_TYPE
  • 5.
    ContactsContract.Data • Important rawcontact columns • Generic column names o Data1 , … , Data16 • Type-specific column names o CommonDataKinds.Photo o CommonDataKinds.Email o etc.
  • 6.
    ContactsContract.Contacts • Neither applicationsnor sync adapters are allowed to add contacts • Contact is representation of RawContacts aggregation
  • 7.
    Contacts Provider Metadata • ContactsContract.RawContacts.DIRTY • ContactsContract.RawContacts.VERSION • ContactsContract.RawContacts.SOURCE_ID • ContactsContract.RawContacts.DELETED • ContactsContract.Data.DATA_VERSION
  • 8.
    Contacts Provider Accessand Data Consistency • Contacts Aggregation • Query contacts and data • Batch modification
  • 9.
    Contacts Aggregation ID=1 Join ID=3 ID=1 ID=1 ID=2 ID=2 ID=2 ID=3 ID=1 Separate ID=4 ID=2
  • 10.
    Query contacts anddata • Lookup Key vs. Contact ID Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, String.valueOf(mId)); ContactsContract.Contacts.getLookupUri(mId, mLookupKey); • Query entities API 11 Uri.withAppendedPath(mContactUri, ContactsContract.Contacts.Entity.CONTENT_DIRECTORY);
  • 11.
    Batch modification • Yieldpoints o to prevent blocking the system • Modification back references o to use result of a previous operation • Optimistic concurrency control o modification of database without having to lock the underlying repository
  • 12.
    Determination changes • ContentObserver o onChange(boolean selfChange) o onChange(boolean selfChange, Uri uri) API 16 • Check db modifications by query o What we have? o What we want?
  • 13.
    Short example SELECT *FROM raw_contacts WHERE id||‘.’||contact_id||’.’ ||version NOT IN (?) SELECT * FROM data WHERE id||‘.’||data_version NOT IN (?) ? starred, etc.
  • 14.
    Questions ? © Alexey Potapov