Wednesday, August 26, 2009

Always discoverable on Android

Something that is starting to annoy me about some of the newer smart phone operating system (I am looking at you iPhoneOS and Android) is that when you tick the box to make your phone discoverable by Bluetooth, it does not stay discoverable. Other operating systems give you an option to switch between hidden, temporally visible or always visible.

After a bit of hacking around on the my phone (a HTC Dream), I have discovered a way to make the Bluetooth stay discoverable. These instructions require adb (the Android Developer Bridge), an a (slightly) nonstandard rom. The reasoning behind requiring the non-standard rom, is that chown under android does weird things.



Remember that this is done at your own risk.

adb remount
adb pull /system/etc/bluez/hcid.conf ./hcid.conf
sed -i'' -e 's/iscan disable/iscan enable/;s/pscan enable;/&\n\n\t\#Make the device stay discoverable for ever\n\tdiscovto 0;/' hcid.conf
adb push hcid.conf /system/etc/bluez/hcid.conf
adb shell chmod 440 /system/etc/bluez/hcid.conf
adb shell busybox chown 1002.1002 /system/etc/bluez/hcid.conf
adb remount
rm -f hcid.conf

HCID_CONFIG="$(adb shell ls /data/misc/hcid/*/config | sed -e 's/\r//g')"
adb pull "$HCID_CONFIG" hcid_config
sed -i'' -e 's/^discovto.*$/discovto 0/' hcid_config
adb push hcid_config "$HCID_CONFIG"
adb shell chmod 644 "$HCID_CONFIG"
adb shell busybox chown 1002.1002 "$HCID_CONFIG"
rm -f hcid_config

After all this is done... Don't forget to power cycle the Bluetooth system (untick, then tick the box for Bluetooth).

6 comments:

  1. Will the modaco ROM be ok for this edit?

    Is this modification possible by using term. emulator directly on the phone (HTC Hero)? If you, what commands (other than remount) are needing modification?

    ReplyDelete
  2. I do not know if this will work on the HTC Hero (or on the modaco ROM) as I own a HTC Dream (this has been tested on both one of JF's and cyanogen's ROMs). I suggest you back up your phone before attempting anything.

    As for running this in a terminal emulator on the phone, it should be possible (I didn't do it due to the amount of typing required). It is also easier to perform this change from linux/mac machine than on the device itself. If you decide to attempt it on the phone, the first step would be to become the root user (using su -).

    Then remount the system partition RW, this should be possible with "mount -o remount,rw /". You will then need to edit the files mentioned in the post by hand: '/system/etc/bluez/hcid.conf' and '/data/misc/hcid/*/config' (your ROM might contain an editor such as vi). After that, just restart the bluetooth subsystem.

    ReplyDelete
  3. Im struggling to get this to work on the Hero. browsing with root/su to /data/misc/hcid/ reveals an empty directory. Would be good if anyone else with a Hero can confirm this as default.

    I have managed to successfully complete up to line 10.

    Any change of getting your appended/modified hcid_config file to try and push back onto my hero? I'll post the results here to share with all.

    Thanks for pointing everyone in the right direction though. Would be nice if the upcoming API had a simple switch for this, or someone could code an app.

    ReplyDelete
  4. Hi, thanks for this helpful trick, however the bit with the chown intrigues me. I have a custom, rooted ROM image flashed onto my phone but chown gives me a "1002 user does not exist" message or something like that. What's the mechanism there? Is this a bug in chown? What is it that the non-standard ROM images do that make it work?

    ReplyDelete
  5. Make sure you are using the busybox chown.

    The chown binary that is normally installed on the device only works with user names (rather than a UID as I am using here).

    ReplyDelete
  6. hcid.conf didn't exist on my cyanogenmod dream, but i edited main.conf which was commented to say "change timeout to zero for always discoverable"

    ReplyDelete