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