Auto boot when wall charger is plugged

Moto e4 and Pixel 2 XL:

Get your device into the bootloader (fastboot) and run the following command from a computer connected over USB with Android Tools:

fastboot oem off-mode-charge 0


I was able to get it to work by updating the init.rc file

I found the on charger trigger and added the following lines below it:

setprop ro.bootmode "normal"
setprop sys.powerctl "reboot"

The entire trigger block ends up looking like this

on charger
    class_start charger
    setprop ro.bootmode "normal"
    setprop sys.powerctl "reboot"

You then need to repack and flash the boot image created after the updates.

Connect the device over USB

Power on device and get to bootloader mode

adb reboot bootloader 

To flash boot image execute the following command while in fastboot

fastboot flash boot new-boot.img

Note: This fix will cause the device to reboot when its plugged in even when shutting it off using the power button or software shutdown.

Source: https://forum.xda-developers.com/showthread.php?p=77766638#post77766638

You can see the commit that contains these changes for my project here:

https://github.com/darran-kelinske-fivestars/mkbootimg_tools/commit/c8633a2ec2e1924272fd16a8ed7fa7414bb65544#diff-d0007d763b44198f7c22e2c19609d5bbR606


I also tried replacing charge_only_mode with a sh script that rebooted the phone but only got a red circle with the M (on a Motorola Bionic). Changing the script to the below got it working...Now I get the red circle with the M for a few seconds, then a blank screen, the another red circle with the M, and it boots on up.

#!/system/bin/sh
su -c "/system/bin/reboot -n outofcharge"

At last I got the solution, you can achieve this by deleting system/bin/charge_only_mode file. Please do that at your own risk and before deleting have backup of that file. I got the desired result that was boot when its connected to wall charger and now its working fine. All the best!

Tags:

Android

Su