Jump to content

Enabling Facebook Sync in Ice Cream Sandwich


Guest PaulOBrien

Recommended Posts

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.filefactory.com/file/c2dfdfe/n/ContactsProvider.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.filefactory.com/file/c2dfd0d/n/99complete' class='bbc_url' title='External link' rel='nofollow external'>download 99complete</a> / <a href='http://www.filefactory.com/file/c2dfd08/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.

Link to comment
Share on other sites

Guest Dave Rensin

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?

Link to comment
Share on other sites

Guest Dave Rensin

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?

Link to comment
Share on other sites

Guest neonixxx

@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.

Link to comment
Share on other sites

Guest yetikid234

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.

Link to comment
Share on other sites

Guest breakingspell

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-developers.com/showthread.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.

Link to comment
Share on other sites

Guest breakingspell

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 biggrin.gif

btw i didnt read any post from here but just the title :).

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

Guest neonixxx

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-developers.com/showpost.php?p=20633881&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

Link to comment
Share on other sites

Guest tony moore

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 :)

Link to comment
Share on other sites

Guest neonixxx

Yeah, I tried the Black Facebook app too and the sync option wasn't there as well. I had assumed the reason it *would* work for people is because the creator/hacker of that app changed the package name and so ContactsProvider wouldn't block it.

Maybe you have to uninstall the official Facebook app first, and then Black Facebook might be able to sync contacts..? I didn't try it, I'm too lazy and rather like the recent Fb app interface despite its sluggishness. But maybe that is why it worked for some and not us.

Edited by neonixxx
Link to comment
Share on other sites

on ICS for blade we had not installed fb app

and the black fb app is working for them bec i dont use fb so much but i tried and it worked for me also

just try what u think guys

sorry i didnt wanted to give u hopes and then nothingblink.gif

Link to comment
Share on other sites

Guest neonixxx

Okay, I finally figured out why I couldn't properly edit the APK. I previously didn't really (at all) understand the ODEX concept, so I didn't realize that the smali contents were in the ContactsProvider.odex file since I'm running the stock 4.0.3 AOSP rom.

So I added the arrays.xml and made the change to ContactsDatabaseHelper.smali that rmk40 suggested, compiled it all back together, and then the newly deodexed APK ran perfectly fine on my phone... but to my disappointment, Facebook sync still doesn't work :|

My only speculation is that in my ContactsDatabaseHelper.smali, that line was "line 892" (there was no 872), and it had a space before the end parenthesis, which should make no difference anyway, but I kept the space when editing.

I learned a good bit by messing with this today, but still haven't accomplished my goal, lol, hopefully soon though. But I fear now I'm really at a dead end as I have no idea what else to attempt.

PS: I've attached my modified ContactsProvider.apk for anyone who might wanna test it or poke around at it. Again, it works on my stock 4.0.3 rom.

ContactsProvidermod.zip

Link to comment
Share on other sites

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.