1

I want to let Android OS to boot automatically when the charger connected (for HTC Magic) without pressing power button I found this guide:


Complete boot when charging

If your phone only gets one of those ugly battery symbols when a charger is connected to a powered off phone this is because the init process is interrupted by /system/bin/chargemon. That file is a binary ARM program, I replaced it with a simple script containing only a single line: echo skipping chargemon The file was created and installed with the following steps:

echo "echo skipping chargemon" > chargemon.script

adb pull /system/bin/chargemon chargemon.backup

adb push chargemon.script  /sqlite_stmt_journals

adb shell

$ cd /sqlite_stmt_journals
$ su
# mount -o remount,rw /dev/block/mtdblock0 /system
# cat chargemon.script > /system/bin/chargemon
# chmod 755 /system/bin/chargemon
# reboot -p

When the command su is given above, it might have to be acknowledged in a dialog on the phone screen. The final command reboot -p shuts down the phone. As the USB cable is still connected it will power on again, and if everything has gone fine the phone will complete its boot process without halting with any battery symbol.


But I can't find "chargemon" in System/bin

2

1 Answer 1

1

I got it working - auto boot when charger is plugged in - on my HTC Desire 200. There is no playlpm/lpm/idot/chargemon on these HTC devices. Fortunately there is something similar, /system/bin/zchgd. This is a service that takes care for the charging animation. On this specific device, the charging animation is played even though the phone is powered on (on the lockscreen), it is also played when the phone is powered off while it's on a charger. (BTW: the images for the animation can be found at /system/media/zchrgd.)

As I found out, the zchgd service is started differently when the phone is powered off or on. I just grep through the init scripts, in my case /init.gtou.rc:

service zchgd_offmode /system/bin/zchgd -pseudooffmode
    user root
    group root graphics
    disabled

service zchgd_onmode /system/bin/zchgd -onmode
    user root
    group root graphics

on property:dev.zcharge=true
    start zchgd_onmode

on property:dev.zcharge=false
    stop zchgd_onmode

So, I created a fake zchgd service, a simple sh script that replaces the original service.

Steps:

adb shell
su
mount -o rw,remount,rw /system
cd /system/bin
ls -l zchgd*
mv zchgd zchgd_original
touch zchgd
vi zchgd # <- insert content
chmod 0755 zchgd
chown root.shell zchgd
ls -l zchgd*

Content of my fake service:

#!/system/bin/sh

log -p v -t "zchgdwrapper"  "Starting fake zchgd service; args='$@'"

if [ "$#" -eq 1 ]; then
    case $1 in
    -pseudooffmode)
        log -p v -t "zchgdwrapper"  "PseudoOffMode service"
        while true; do
           sleep 60
           enabled=$(cat /sys/class/power_supply/battery/charging_enabled)
           log -p v -t "zchgdwrapper"  "Checking battery charging enabled; enabled='$enabled'"
           if [ "$enabled" -gt 0 ]; then
               log -p v -t "zchgdwrapper"  "Going to magic-reboot"
               su -c "echo 1 > /proc/sys/kernel/sysrq"
               su -c "echo b > /proc/sysrq-trigger"
               ret=$?
               log -p v -t "zchgdwrapper"  "Magic-reboot issued ret='$ret'"
               sleep 120
               exit 0
           fi
        done
    ;;
    -onmode)
        log -p v -t "zchgdwrapper"  "OnMode service"
        while true; do
          log -p v -t "zchgdwrapper"  "Sleeping beauty"
          sleep 3600 
        done
    ;;
    esac
fi

log -p v -t "zchgdwrapper"  "Not gonna happen - starting the original service"
/system/bin/zchgd_original $@
exit $?

When the service is stared with -pseudooffmode argument, then it checks the battery status periodically (every minute in my case). If the phone is being charged or the battery is full then it will automatically restart the phone. I could not use /system/bin/reboot, I got permission errors, even though I had them... So I restart it with a hack, that two echo lines. The -onmode is there only because, I don't want to see the charging animation even if my phone is powered on.

You can debug the script with adb logcat -s zchgdwrapper. I hope this was helpful!

IMPORTANT

For this to work, you MUST enable Settings/Power/Fast boot option. It won't work if it is disabled, I think without the fast boot option another firmware is booted, but not sure about that.

Also I have this config in SuperSU#, I don't think it is necessary but, here it is:

  • Default Acces < Grant
  • Enable su during boot
  • Trust system user

Further info: https://github.com/tomicooler/htcdesire200autoboot

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .