Jump to content


Photo

Enabling Facebook Sync in Ice Cream Sandwich

- - - - -

  • Please log in to reply
44 replies to this topic

#1
PaulOBrien

PaulOBrien

    It's My Party

  • Founder
  • PipPipPipPipPipPip
  • 36,345 posts
  • Gender:Male
  • Location:Norwich, UK
  • Devices:All the Nexus!
  • Twitter:@paulobrien
There has been a fair bit written about how Facebook Sync is broken in Ice Cream Sandwich and isn't as straightforward to enable as it was in Gingerbread, so I thought i'd write up my findings. First of all, enabling it is pretty easy when you know how! It's not perfect (contact pictures don't sync for some people, statuses aren't synced etc.) but it's a decent start until Facebook sort themselves out and update their app to work properly and conform to Google's guidelines (don't hold your breath).

I'll talk through the steps for enabling the sync for ROM devs and provide the bits and pieces needed to do so. I specifically decided to try and find a solution that doesn't involve hacking about with the Facebook APK itself. This is because I wanted end users to be able to continue receiving app updates.

<strong class='bbc'>Step 1 - ContactsProvider</strong>

In previous versions of Android, simply making a tweak to the ContactsProvider would allow sync to work. We still need to do this in ICS. If you're working on a disassembled ContactsProvider APK, the file in question is res/values/arrays.xml. In contrast to previous versions, this file doesn't actually exist in the ICS packages, you need to create it. When you do so, the content needs to be as follows:

<pre class='prettyprint'><?xml version="1.0" encoding="utf-8"?><resources> <string-array name="unrestricted_packages"> <item>com.facebook.katana</item> </string-array></resources></pre>
Simply, this adds the Facebook app (com.facebook.katana) to a group which has elevated access to contacts.

I've uploaded a ready-to-go ContactsProvider APK if you'd like to use / take a look at one - <a href='http://www.filefacto...ctsProvider.apk' class='bbc_url' title='External link' rel='nofollow external'>download ContactsProvider.apk</a>

<strong class='bbc'>Step 2 - contact database tweak</strong>

After adding this to ContactsProvider I hoped it would 'just work' but sadly, it didn't. No contacts. Upon digging deeper in logcat, I could see a bunch of errors when it tried to sync the Facebook contacts into the database. Nothing too tricky, just a missing column in the database. The column is_restricted was previously in the contacts database, but is no longer present. Simple enough... we can use a SQLite binary to put the column back in the database. So, I did just that, rebooted and hey presto - contacts syncing!

Now, obviously we don't want users to have to drop to a command line and run a SQLite command, so I built a custom script that is run from /system/etc/init.d on startup that adds the relevant column. This relies on a sqlite3 binary being present in /system/xbin. This is a good way of doing things because init.d is run before any process could be doing anything with the contacts DB. There is a minor issue in that if the contacts DB doesn't exist (e.g. on first boot) it can't work it's magic, and therefore Facebook sync won't work until the user's second boot.

I've uploaded my script for init.d and my sqlite binary (ensure you use one suitable for your device's architecture) if you'd like to use them - <a href='http://www.filefacto...0d/n/99complete' class='bbc_url' title='External link' rel='nofollow external'>download 99complete</a> / <a href='http://www.filefacto...dfd08/n/sqlite3' class='bbc_url' title='External link' rel='nofollow external'>download sqlite3</a>

<strong class='bbc'>And that's it!</strong>

If you have any thoughts / questions, feel free to post them. I'll be updating this post as I tweak / improve the process. Hope this info is useful! If so, and indeed if you use this info, please consider linking back to this page.

Cheers! :)<div style='text-align: center;'><img src='' alt='' /></div><div style='text-align: center;'><img src='' alt='' /></div>

This item was promoted to the News page - click here to view.

  • 1

You can follow me on Twitter - http://twitter.com/paulobrien / Follow MoDaCo on Twitter - http://twitter.com/modaco

Want to donate? MoDaCo is raising money for the Multiple Sclerosis society.

Posted Image


#2
Zapote21

Zapote21

    Newbie

  • Members
  • Pip
  • 7 posts
  • Gender:Male
  • Location:Tampa, FL
  • Devices:Him: SGS3, Her: SGS3
  • Twitter:@Zapote21
Says file deleted due to copyright...

  • 0

#3
PaulOBrien

PaulOBrien

    It's My Party

  • Founder
  • PipPipPipPipPipPip
  • 36,345 posts
  • Gender:Male
  • Location:Norwich, UK
  • Devices:All the Nexus!
  • Twitter:@paulobrien
Fixed links, not sure what happened there!

P

  • 0

You can follow me on Twitter - http://twitter.com/paulobrien / Follow MoDaCo on Twitter - http://twitter.com/modaco

Want to donate? MoDaCo is raising money for the Multiple Sclerosis society.

Posted Image


#4
Zapote21

Zapote21

    Newbie

  • Members
  • Pip
  • 7 posts
  • Gender:Male
  • Location:Tampa, FL
  • Devices:Him: SGS3, Her: SGS3
  • Twitter:@Zapote21
Thanks

  • 0

#5
Dave Rensin

Dave Rensin

    Newbie

  • Members
  • Pip
  • 4 posts
  • Devices:nexus one
I'm getting a INSTALL_PARSE_FAILED_NO_CERTIFICATES when I try to use adb install on the ContactsProvider.apk. Is this not how I should be installing it?

  • 0

#6
Dave Rensin

Dave Rensin

    Newbie

  • Members
  • Pip
  • 4 posts
  • Devices:nexus one
copyright notice/problem is back for the init.d script.

  • 0

#7
PaulOBrien

PaulOBrien

    It's My Party

  • Founder
  • PipPipPipPipPipPip
  • 36,345 posts
  • Gender:Male
  • Location:Norwich, UK
  • Devices:All the Nexus!
  • Twitter:@paulobrien
Links still OK for me, might be hosting issues at Filesonic.

ContactsProvider.apk should go to /system/app, not installed via ADB.

P

  • 0

You can follow me on Twitter - http://twitter.com/paulobrien / Follow MoDaCo on Twitter - http://twitter.com/modaco

Want to donate? MoDaCo is raising money for the Multiple Sclerosis society.

Posted Image


#8
Dave Rensin

Dave Rensin

    Newbie

  • Members
  • Pip
  • 4 posts
  • Devices:nexus one
I'm getting huge FCs having replaced the ContactsProvider.apk in /system/app... I ran 99Complete from a root shell on my Galaxy Nexus, but the facebook app crashes, phone crashes, etc... Do you have the original ContactsProvider.apk for the verizon galaxy nexus?

  • 0

#9
daandman

daandman

    Newbie

  • Members
  • Pip
  • 3 posts
  • Devices:Galaxy Nexus
For the clueless non-devs like me, I don't understand what I'm supposed to do with 99complete & sqlite3?

Edited by daandman, 24 December 2011 - 06:10 PM.

  • 0

#10
neonixxx

neonixxx

    Newbie

  • Members
  • Pip
  • 10 posts
  • Devices:Nexus S
@daandman, You have to copy 99complete into /system/init.d/ and copy sqlite3 into /system/xbin/

That's if I get all this correctly, I've never messed with manually adding startup scripts to an android until just now...


The problem I'm running into is it seems the ContactsProvider.apk is not cooperating with my ICS rom. It "stops" on boot and will fail to load if clicked. com.google.process.gapps will also stop soon after boot. I'm running ICS 4.0.3 on a Nexus S.

I pulled the APK and tried decompiled it myself with APKtool. That went fine, added the arrays.xml file. But then I try to recompile the whole thing and it seems it doesn't produce a META-INF directory, which told me before I even tried it that it wouldn't work, but tried it anyway, of course it didn't lol. Crashed the same way as the one linked to in this post.

  • 0

#11
yetikid234

yetikid234

    Newbie

  • Members
  • Pip
  • 19 posts
  • Devices:ZTE Racer
I'm also having issues with the ContactsProvider.apk crashing, I've had to put the original back on for now. @Paul any chance of a fix for it soon? Getting lots of merry christmas' but don't know who from haha.

  • 0

#12
neonixxx

neonixxx

    Newbie

  • Members
  • Pip
  • 10 posts
  • Devices:Nexus S
Oh and to correct my last post, 99complete goes in /system/etc/init.d/

  • 0

#13
breakingspell

breakingspell

    Newbie

  • Members
  • Pip
  • 3 posts
  • Gender:Male
  • Devices:Google Nexus S
Oh, irony! I was working on my own method of re-enabling Facebook Sync. I sorely miss it from the gingerbread fork i came from. Our progress at http://forum.xda-dev...d.php?t=1386303 wasn't going to steadily, and then a user posted a link here. I had already determined that arrays.xml was missing, had decompiled and built a version with it in /res/values, but seeing that it didn't work, i kind of put it aside.

To test out your method, i used your Contactsprovider.apk, replaced my sqlite3 with yours, and dropped 99complete into /system/etc/init.d/, chmodded it, ran it, and rebooted. Unfortunately, after a forced sync in the Accounts and Sync menu, it didn't update with friends i've had since my last successful sync on gingerbread. In addition, the Sync settings are still absent in the Facebook app.

  • 0

#14
breakingspell

breakingspell

    Newbie

  • Members
  • Pip
  • 3 posts
  • Gender:Male
  • Devices:Google Nexus S
Forgot to mention, i'm running KalimochoAZ's Cyanogenmod 9 Alpha 12 (Android 4.0.1) on my Google Nexus S i9020a. The contactsprovider apk fits in fine, and still works with everything but the facebook syncing.

  • 0

#15
rmk40

rmk40

    Newbie

  • Members
  • Pip
  • 2 posts
  • Devices:HTC Sensation 4G
We can actually eliminate the need for step #2 and associated scripts entirely with a smali edit, which we may as well do, considering the apk is already disassembled at this point:

1. Edit: com.android.providers.contacts/smali/com/android/providers/contacts/ContactsDatabaseHelper.smali

2. Search for line 872, which should look like this:

const-string v0, "CREATE TABLE raw_contacts (_id INTEGER PRIMARY KEY AUTOINCREMENT,account_name STRING DEFAULT NULL, account_type STRING DEFAULT NULL, data_set STRING DEFAULT NULL, sourceid TEXT,raw_contact_is_read_only INTEGER NOT NULL DEFAULT 0,version INTEGER NOT NULL DEFAULT 1,dirty INTEGER NOT NULL DEFAULT 0,deleted INTEGER NOT NULL DEFAULT 0,contact_id INTEGER REFERENCES contacts(_id),aggregation_mode INTEGER NOT NULL DEFAULT 0,aggregation_needed INTEGER NOT NULL DEFAULT 1,custom_ringtone TEXT,send_to_voicemail INTEGER NOT NULL DEFAULT 0,times_contacted INTEGER NOT NULL DEFAULT 0,last_time_contacted INTEGER,starred INTEGER NOT NULL DEFAULT 0,display_name TEXT,display_name_alt TEXT,display_name_source INTEGER NOT NULL DEFAULT 0,phonetic_name TEXT,phonetic_name_style TEXT,sort_key TEXT COLLATE PHONEBOOK,sort_key_alt TEXT COLLATE PHONEBOOK,name_verified INTEGER NOT NULL DEFAULT 0,sync1 TEXT, sync2 TEXT, sync3 TEXT, sync4 TEXT);"

3. Replace it with this:

const-string v0, "CREATE TABLE raw_contacts (_id INTEGER PRIMARY KEY AUTOINCREMENT,account_name STRING DEFAULT NULL, account_type STRING DEFAULT NULL, data_set STRING DEFAULT NULL, sourceid TEXT,raw_contact_is_read_only INTEGER NOT NULL DEFAULT 0,version INTEGER NOT NULL DEFAULT 1,dirty INTEGER NOT NULL DEFAULT 0,deleted INTEGER NOT NULL DEFAULT 0,contact_id INTEGER REFERENCES contacts(_id),aggregation_mode INTEGER NOT NULL DEFAULT 0,aggregation_needed INTEGER NOT NULL DEFAULT 1,custom_ringtone TEXT,send_to_voicemail INTEGER NOT NULL DEFAULT 0,times_contacted INTEGER NOT NULL DEFAULT 0,last_time_contacted INTEGER,starred INTEGER NOT NULL DEFAULT 0,display_name TEXT,display_name_alt TEXT,display_name_source INTEGER NOT NULL DEFAULT 0,phonetic_name TEXT,phonetic_name_style TEXT,sort_key TEXT COLLATE PHONEBOOK,sort_key_alt TEXT COLLATE PHONEBOOK,name_verified INTEGER NOT NULL DEFAULT 0,sync1 TEXT, sync2 TEXT, sync3 TEXT, sync4 TEXT, is_restricted INTEGER);"

4. Rebuild and sign the apk as usual when performing a mod.

That's it, you don't need the init script anymore. The database will initialize properly with the appropriate column in place.

  • 2

#16
jeddy1

jeddy1

    Addict

  • Members
  • PipPipPipPipPip
  • 943 posts
  • Gender:Male
  • Location:Germany
  • Interests:Many
  • Devices:Blade-Lg e720-SE x8
i dont know if u are interested but i have a facebook app which is working for me so if u want it just tell me Posted Image
btw i didnt read any post from here but just the title :).

  • 0
Click + if i´ve helped u :P

#17
jeddy1

jeddy1

    Addict

  • Members
  • PipPipPipPipPip
  • 943 posts
  • Gender:Male
  • Location:Germany
  • Interests:Many
  • Devices:Blade-Lg e720-SE x8
Ah and when i mean working ! - is fully working :)
just to have it is here just open.rar
its called black facebook . i uploaded yesterday also to the blade cm9 thread and is working for all others who tried also
just giving some help for now till the facebook app updates or u can keep it forever
its better than the normal facebook app :)

  • 0
Click + if i´ve helped u :P

#18
neonixxx

neonixxx

    Newbie

  • Members
  • Pip
  • 10 posts
  • Devices:Nexus S
I found out the problem I'm having is because when I decompile ContactsProvider.apk with APKtool, it does not produce the smali directory.

I can't get APkKool to get the smali any system apps from 4.0.3. Does anyone know if this is a known issue? I've registered framework-res.apk from my rom but it still doesn't work.
I've tried searching all over but the best thing I found was this: http://forum.xda-dev...&postcount=1502 but that wasn't my case. And assuming the guys posting in there are able to decompile 4.0.3 system apps just fine, then I'm completely stumped... :S

  • 0

#19
tony moore

tony moore

    Newbie

  • Members
  • Pip
  • 1 posts
  • Devices:Galaxy S2
Not working on CM9 on SGS2

Ah and when i mean working ! - is fully working :)
just to have it is here just open.rar
its called black facebook . i uploaded yesterday also to the blade cm9 thread and is working for all others who tried also
just giving some help for now till the facebook app updates or u can keep it forever
its better than the normal facebook app :)


  • 0

#20
jeddy1

jeddy1

    Addict

  • Members
  • PipPipPipPipPip
  • 943 posts
  • Gender:Male
  • Location:Germany
  • Interests:Many
  • Devices:Blade-Lg e720-SE x8
thats weird
thanks for reply on that btw and i am sorry its not working for your phone .

  • 0
Click + if i´ve helped u :P




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users