Monday, July 1, 2013

ADB Whitelist Issue and Android 4.2.2

I managed to get my hands on a Galaxy S 4, which comes out of the box with 4.2.2. It was working great, but for some reason, possibly due to reflashing the device after a soft brick, every time I connected my laptop to my phone it would ask if i want to whitelist the laptop i am using. Every. Single. Time.

In Android 4.2.2 the team introduced a new security measure called ADB whitelisting. This allows the user to dictate whether or not a computer can run adb commands on the device. This is a good feature because adb can be rather dangerous, as it has slightly escalated permissions from a normal app running on a device. Some of the permissions adb has can be dangerous, such as rebooting the phone into recovery or the bootloaders etc.

So with this welcome feature, i had no issue with allowing my laptop on the device. They even included a tick box for 'Remember this computer'. However as i said, for some reason, after the reflash, the device would just not remember my laptop. This is extremely annoying as every time i want to test an app on my phone i have to allow the device to connect.

So i did a little research and found out that the keys of the laptops are stored in a location on the device, namely: /data/misc/adb/adb_keys

This little file was giving me endless hassles.

To solve my problem, i copied my laptops public adb key, located at ~/.android/adbkey.pub , onto my sdcard using 'adb push  ~/.android/adbkey.pub /storage/sdcard0/adb_keys'
Then I ran 'adb shell', giving me access to the phones filesystem.
I ran 'su', but i don't think this is actually necessary.
Finally i copied the adb_keys into '/data/misc/adb/' using cp, the exact command is 'cp /storage/sdcard0/adb_keys /data/misc/adb/adb_keys'
Then i restarted adb and boom! It works now.

If you can't use cp, you can try cat, the command will be slightly different, 'cat /storage/sdcard0/adb_keys > /data/misc/adb/adb_keys'

It's a very silly issue i had, but at least there is a work around.
Hope this helps.