Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Auto boot when wall charger is plugged [closed]

Tags:

android

su

I'm Developing an Android Application where it requireds 3 things:-

  1. To keep the App up an running for specific time and then phone will be off (Working Fine)
  2. When phone get charging from outlet, I want phone to power up automatically without hitting any power button. (Not Working with wall Socket, but working when connected to USB cable via Laptop).
  3. After boot my app should start working Automatically (Working Fine)

You Must know :- My phone is Moto E (rooted) and want 2nd step to be done. Tried some codes but that does not work on moto E. When Connected with USB it gives 2 as response and when connected with Wall socket charger it says 1

Any help will be Appreciated

P.S :- Auto Boot working with USB cable connected with Laptop but not with Socket Charger

Update-1: 1- Found fastboot oem off-mode-charge 0 working with Nexus 7 but not on Moto e.

2- Moto e boots when connected to Router (USB Dongle Port)

like image 807
Rohit Avatar asked Oct 10 '14 07:10

Rohit


6 Answers

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!

like image 69
Rohit Avatar answered Oct 14 '22 23:10

Rohit


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

like image 34
Mad Scientist Moses Avatar answered Oct 14 '22 22:10

Mad Scientist Moses


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

like image 38
dazza5000 Avatar answered Oct 14 '22 21:10

dazza5000


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"
like image 24
Frank N Stein Avatar answered Oct 14 '22 22:10

Frank N Stein


On my device Lenovo K7000-Plus, the file need to be modified is kpoc_charger located at /system/bin.

Ipod file not working on my phone which using Android 6.0 ROM, but kpoc_charger works pefectly.

Regards

Hadi

like image 29
Hadi Avatar answered Oct 14 '22 22:10

Hadi


For Lenovo A2010 phone,following worked:

  1. Use file manager phone app from playstore like Total commander(on rooted phone) to goto folder /system/bin/
  2. Copy file kpoc_charger and paste it there as kpoc_charger.bak
  3. Now edit the original file kpoc_charger using total-commander, replace all lines with following code:

    #!/system/bin/sh
    /system/bin/reboot
    
  4. Save it, goto properties and change UID:0 root, GID:2000 shell and permission as 755 (same as properties of other files in /system/bin folder).
  5. Now shutdown phone and plug to charger.
  6. Bazinga!!!! battery icon shows for a sec but phone sucessfully boots into os.
like image 36
Abhishek Verma Avatar answered Oct 14 '22 22:10

Abhishek Verma