[Q] Power on when plugged in (boot when docked)?

Search This thread

fritz.barnes

Member
Mar 13, 2020
17
1
I have a Samsung Tab A (SM-T510). I have implented the most common recommendation - replace /system/bin/lpm with a script that calls reboot. It isn't working. Does not seem to have any effect.

I instead added a line "echo ${%0} >> /sdcard/mylog" to the lpm file. The lpm script works (syntax okay, line breaks okay, etc.) if I execute it from adb shell, but if I shut down the device and plug it in, it just shows battery animation and does not write anything to mylog.

Permissions on my modified lpm are identical to the original lpm.

Does this mean that /system/bin/lpm -- although it is present -- is not the file that is being called for our purposes? I don't see any of the other file names that people have mentioned - battery*, charge*, kpoc*.

I should have mentioned tablet is rooted with Magisk installed, in case that matters. Sure would appreciate some help if anyone has any ideas.
 
Last edited:

fritz.barnes

Member
Mar 13, 2020
17
1
Tobias Alrøe just pointed out that /sdcard might not be available so early in the boot process, which makes perfect sense.

So if I go back to assuming that lpm is called, I still need to figure out why my replacement script isn't working. Just seems to have no effect at all.

Contents of /system/bin/lpm:
Code:
#!/system/bin/sh
su
/system/bin/reboot

Permissions and line breaks are correct.
 

ahhl

Senior Member
Jul 23, 2007
1,074
114
did you checked after boot, the modified lpm file still there. because some time the modified lpm file got replaced back by stock file.

Sent from my Redmi Note 7 using Tapatalk
 

tehvariance

New member
May 2, 2020
2
2
Thanks. It is still there and unchanged from what I put in it.

I think I'm in the same boat as @fritz.barnes. I've tried every combination of suggestion here but there's something weird going on.

I have a Samsung Galaxy Tab A 10.1 (2019) with unlocked bootloader, TWRP, and root (Magisk).

It appears as if anytime i replace /system/bin/lpm and put in the suggested shell scripts to trigger a reboot, it appears this isn't running at all or incurring some kind of exception.

I was initially really confused because there were other people saying that the script appeared to be working but that it was booting them into recovery/TWRP, and that appeared to be what was happening to me. But after going through so many scenarios, I think there was a reason for that.

1. When I first made the change to /system/bin/lpm after being in USB debugging and from ADB shell, when I turned the tablet off with cord unplugged, then plugged in cord, I got stuck at the initial lightning charge screen that doesn't have the real battery %, etc.
2. When this just got stuck forever and didn't reboot (regularly or into TWRP), I held POWER + VOL DOWN to reboot, then POWER + VOL UP to get back into TWRP. After getting into TWRP, mounting system, and making the similar changes to /system/bin/lpm, it "appeared" to be working in that after powering off with cord unplugged, it would start up when cord plugged in but go immediately into TWRP.
3. I realized later after trying multiple different versions of this file that all kept going into TWRP, if I rebooted regularly into system first with TWRP, then powered off with cord unplugged, then plugged cord in, I was still stuck at the initial lightning charge screen that doesn't have the real battery %, etc.

After all that, I'm assuming the initial lightning charge screen has nothing to do with /system/bin/lpm, and that this shows regardless of what /system/bin/lpm is. But compared to the original /system/bin/lpm behavior of in a few seconds showing correct battery %, my attempts at the shell script /system/bin/lpm probably just appear to be doing nothing (not rebooting) and just keeping me at the initial lightning charge screen.

As I said, I tried multiple different versions of the script throughout this thread and nothing has seemed to work. I have created the file or copied the file in different ways and also verified EOL characters, etc.

Does anyone have any idea what's going on with my situation (and possibly with @fritz.barnes having the same or similar issue that I do) or how to debug this? Is there something that has been altered with reboots by TWRP that requires any sort of Android property to be set or anything? I'm not an Android developer, but I see this in the TWRP source in terms of doing a system reboot, but I'm not fully sure what's going on here.

Code:
case rb_system:
			Update_Intent_File("s");
			sync();
			check_and_run_script("/sbin/rebootsystem.sh", "reboot system");
#ifdef ANDROID_RB_PROPERTY
			return property_set(ANDROID_RB_PROPERTY, "reboot,");
#elif defined(ANDROID_RB_RESTART)
			return android_reboot(ANDROID_RB_RESTART, 0, 0);
#else
			return reboot(RB_AUTOBOOT);
#endif

Thanks!

---------- Post added at 09:48 PM ---------- Previous post was at 09:21 PM ----------

I think I'm in the same boat as @fritz.barnes. I've tried every combination of suggestion here but there's something weird going on.

I have a Samsung Galaxy Tab A 10.1 (2019) with unlocked bootloader, TWRP, and root (Magisk).

It appears as if anytime i replace /system/bin/lpm and put in the suggested shell scripts to trigger a reboot, it appears this isn't running at all or incurring some kind of exception.

I was initially really confused because there were other people saying that the script appeared to be working but that it was booting them into recovery/TWRP, and that appeared to be what was happening to me. But after going through so many scenarios, I think there was a reason for that.

1. When I first made the change to /system/bin/lpm after being in USB debugging and from ADB shell, when I turned the tablet off with cord unplugged, then plugged in cord, I got stuck at the initial lightning charge screen that doesn't have the real battery %, etc.
2. When this just got stuck forever and didn't reboot (regularly or into TWRP), I held POWER + VOL DOWN to reboot, then POWER + VOL UP to get back into TWRP. After getting into TWRP, mounting system, and making the similar changes to /system/bin/lpm, it "appeared" to be working in that after powering off with cord unplugged, it would start up when cord plugged in but go immediately into TWRP.
3. I realized later after trying multiple different versions of this file that all kept going into TWRP, if I rebooted regularly into system first with TWRP, then powered off with cord unplugged, then plugged cord in, I was still stuck at the initial lightning charge screen that doesn't have the real battery %, etc.

After all that, I'm assuming the initial lightning charge screen has nothing to do with /system/bin/lpm, and that this shows regardless of what /system/bin/lpm is. But compared to the original /system/bin/lpm behavior of in a few seconds showing correct battery %, my attempts at the shell script /system/bin/lpm probably just appear to be doing nothing (not rebooting) and just keeping me at the initial lightning charge screen.

As I said, I tried multiple different versions of the script throughout this thread and nothing has seemed to work. I have created the file or copied the file in different ways and also verified EOL characters, etc.

Does anyone have any idea what's going on with my situation (and possibly with @fritz.barnes having the same or similar issue that I do) or how to debug this? Is there something that has been altered with reboots by TWRP that requires any sort of Android property to be set or anything? I'm not an Android developer, but I see this in the TWRP source in terms of doing a system reboot, but I'm not fully sure what's going on here.

Code:
case rb_system:
			Update_Intent_File("s");
			sync();
			check_and_run_script("/sbin/rebootsystem.sh", "reboot system");
#ifdef ANDROID_RB_PROPERTY
			return property_set(ANDROID_RB_PROPERTY, "reboot,");
#elif defined(ANDROID_RB_RESTART)
			return android_reboot(ANDROID_RB_RESTART, 0, 0);
#else
			return reboot(RB_AUTOBOOT);
#endif

Thanks!

Not sure if I'm normally supposed to reply to my own post here, but I have some more information that seems interesting.

If I take the original /system/bin/lpm, make a copy and then use the copy as /system/bin/lpm (and move the original to a different file, i.e. /system/bin/lpm.bak), the copied version of the original binary also seems to not work and keep me at the initial lightning charge screen. I am making sure to chmod 0755 and chown root.shell any copied files as you can see below. The original file has timestamp of 2008-12-31, and this specific file appears to be the only one that will work (and go to the normal charge indicator screen).
aFwCp4k.png


Not sure if this will further help diagnosis anything, but what's going on here? Why with a copy of the original lpm binary does this also result in me being stuck at the initial lightning charge screen? Any ideas?

I'd be willing to send a $50 bounty via Venmo to whoever can help me get this working.
 
Last edited:

ahhl

Senior Member
Jul 23, 2007
1,074
114
I think I'm in the same boat as @fritz.barnes. I've tried every combination of suggestion here but there's something weird going on.

I have a Samsung Galaxy Tab A 10.1 (2019) with unlocked bootloader, TWRP, and root (Magisk).

It appears as if anytime i replace /system/bin/lpm and put in the suggested shell scripts to trigger a reboot, it appears this isn't running at all or incurring some kind of exception.

I was initially really confused because there were other people saying that the script appeared to be working but that it was booting them into recovery/TWRP, and that appeared to be what was happening to me. But after going through so many scenarios, I think there was a reason for that.

1. When I first made the change to /system/bin/lpm after being in USB debugging and from ADB shell, when I turned the tablet off with cord unplugged, then plugged in cord, I got stuck at the initial lightning charge screen that doesn't have the real battery %, etc.
2. When this just got stuck forever and didn't reboot (regularly or into TWRP), I held POWER + VOL DOWN to reboot, then POWER + VOL UP to get back into TWRP. After getting into TWRP, mounting system, and making the similar changes to /system/bin/lpm, it "appeared" to be working in that after powering off with cord unplugged, it would start up when cord plugged in but go immediately into TWRP.
3. I realized later after trying multiple different versions of this file that all kept going into TWRP, if I rebooted regularly into system first with TWRP, then powered off with cord unplugged, then plugged cord in, I was still stuck at the initial lightning charge screen that doesn't have the real battery %, etc.

After all that, I'm assuming the initial lightning charge screen has nothing to do with /system/bin/lpm, and that this shows regardless of what /system/bin/lpm is. But compared to the original /system/bin/lpm behavior of in a few seconds showing correct battery %, my attempts at the shell script /system/bin/lpm probably just appear to be doing nothing (not rebooting) and just keeping me at the initial lightning charge screen.

As I said, I tried multiple different versions of the script throughout this thread and nothing has seemed to work. I have created the file or copied the file in different ways and also verified EOL characters, etc.

Does anyone have any idea what's going on with my situation (and possibly with @fritz.barnes having the same or similar issue that I do) or how to debug this? Is there something that has been altered with reboots by TWRP that requires any sort of Android property to be set or anything? I'm not an Android developer, but I see this in the TWRP source in terms of doing a system reboot, but I'm not fully sure what's going on here.

Code:
case rb_system:
Update_Intent_File("s");
sync();
check_and_run_script("/sbin/rebootsystem.sh", "reboot system");
#ifdef ANDROID_RB_PROPERTY
return property_set(ANDROID_RB_PROPERTY, "reboot,");
#elif defined(ANDROID_RB_RESTART)
return android_reboot(ANDROID_RB_RESTART, 0, 0);
#else
return reboot(RB_AUTOBOOT);
#endif

Thanks!

---------- Post added at 09:48 PM ---------- Previous post was at 09:21 PM ----------



Not sure if I'm normally supposed to reply to my own post here, but I have some more information that seems interesting.

If I take the original /system/bin/lpm, make a copy and then use the copy as /system/bin/lpm (and move the original to a different file, i.e. /system/bin/lpm.bak), the copied version of the original binary also seems to not work and keep me at the initial lightning charge screen. I am making sure to chmod 0755 and chown root.shell any copied files as you can see below. The original file has timestamp of 2008-12-31, and this specific file appears to be the only one that will work (and go to the normal charge indicator screen).
aFwCp4k.png


Not sure if this will further help diagnosis anything, but what's going on here? Why with a copy of the original lpm binary does this also result in me being stuck at the initial lightning charge screen? Any ideas?

I'd be willing to send a $50 bounty via Venmo to whoever can help me get this working.
from my own experience, if something get stuck, it means the comand in tge lpm file is wrong, you have to try different command.

i have successfully auto boot 4 different phone, S4, Mate 7, zenphone6, redmi 6a, they all need to use different command, eventhough i only changing the same file. in my case in init.rc and some by just changing kpoc file.

Sent from my Redmi Note 7 using Tapatalk
 

tehvariance

New member
May 2, 2020
2
2
I think I'm in the same boat as @fritz.barnes. I've tried every combination of suggestion here but there's something weird going on.

I have a Samsung Galaxy Tab A 10.1 (2019) with unlocked bootloader, TWRP, and root (Magisk).

It appears as if anytime i replace /system/bin/lpm and put in the suggested shell scripts to trigger a reboot, it appears this isn't running at all or incurring some kind of exception.

I was initially really confused because there were other people saying that the script appeared to be working but that it was booting them into recovery/TWRP, and that appeared to be what was happening to me. But after going through so many scenarios, I think there was a reason for that.

1. When I first made the change to /system/bin/lpm after being in USB debugging and from ADB shell, when I turned the tablet off with cord unplugged, then plugged in cord, I got stuck at the initial lightning charge screen that doesn't have the real battery %, etc.
2. When this just got stuck forever and didn't reboot (regularly or into TWRP), I held POWER + VOL DOWN to reboot, then POWER + VOL UP to get back into TWRP. After getting into TWRP, mounting system, and making the similar changes to /system/bin/lpm, it "appeared" to be working in that after powering off with cord unplugged, it would start up when cord plugged in but go immediately into TWRP.
3. I realized later after trying multiple different versions of this file that all kept going into TWRP, if I rebooted regularly into system first with TWRP, then powered off with cord unplugged, then plugged cord in, I was still stuck at the initial lightning charge screen that doesn't have the real battery %, etc.

After all that, I'm assuming the initial lightning charge screen has nothing to do with /system/bin/lpm, and that this shows regardless of what /system/bin/lpm is. But compared to the original /system/bin/lpm behavior of in a few seconds showing correct battery %, my attempts at the shell script /system/bin/lpm probably just appear to be doing nothing (not rebooting) and just keeping me at the initial lightning charge screen.

As I said, I tried multiple different versions of the script throughout this thread and nothing has seemed to work. I have created the file or copied the file in different ways and also verified EOL characters, etc.

Does anyone have any idea what's going on with my situation (and possibly with @fritz.barnes having the same or similar issue that I do) or how to debug this? Is there something that has been altered with reboots by TWRP that requires any sort of Android property to be set or anything? I'm not an Android developer, but I see this in the TWRP source in terms of doing a system reboot, but I'm not fully sure what's going on here.

Code:
case rb_system:
			Update_Intent_File("s");
			sync();
			check_and_run_script("/sbin/rebootsystem.sh", "reboot system");
#ifdef ANDROID_RB_PROPERTY
			return property_set(ANDROID_RB_PROPERTY, "reboot,");
#elif defined(ANDROID_RB_RESTART)
			return android_reboot(ANDROID_RB_RESTART, 0, 0);
#else
			return reboot(RB_AUTOBOOT);
#endif

Thanks!

---------- Post added at 09:48 PM ---------- Previous post was at 09:21 PM ----------



Not sure if I'm normally supposed to reply to my own post here, but I have some more information that seems interesting.

If I take the original /system/bin/lpm, make a copy and then use the copy as /system/bin/lpm (and move the original to a different file, i.e. /system/bin/lpm.bak), the copied version of the original binary also seems to not work and keep me at the initial lightning charge screen. I am making sure to chmod 0755 and chown root.shell any copied files as you can see below. The original file has timestamp of 2008-12-31, and this specific file appears to be the only one that will work (and go to the normal charge indicator screen).
aFwCp4k.png


Not sure if this will further help diagnosis anything, but what's going on here? Why with a copy of the original lpm binary does this also result in me being stuck at the initial lightning charge screen? Any ideas?

I'd be willing to send a $50 bounty via Venmo to whoever can help me get this working.

from my own experience, if something get stuck, it means the comand in tge lpm file is wrong, you have to try different command.

i have successfully auto boot 4 different phone, S4, Mate 7, zenphone6, redmi 6a, they all need to use different command, eventhough i only changing the same file. in my case in init.rc and some by just changing kpoc file.

Sent from my Redmi Note 7 using Tapatalk

Hi guys, as a followup after trying again tonight it is working!

I came across a different link where someone posted his "one-liner" for doing this:
mount -o remount,rw /dev/block/platform/dw_mmc.0/by-name/SYSTEM /system && cp /system/bin/lpm /system/bin/lpm_orig && echo "#!/system/bin/sh\n/system/bin/reboot" > /system/bin/lpm

As mentioned previously, with me using Magisk users have reported "/system" mount not existing.

What it looks like it boils down to at least for me, is that every time I was trying this, I was doing a move/rename of the original /system/bin/lpm, then creating a new /system/bin/lpm (as root/root) and then doing a chmod 0755 and a chown to root/shell. Apparently this method did not work for me even though I was seemingly left with the same file with same permissions, but looks like since this person's one-liner does a copy to backup original /system/bin/lpm and then just overwrites the existing file contents with the simple shell shell script to auto-boot, this works!

I'm not sure if my situation is related to Magisk or what, I'm just not very familiar with Android mounts/partitions/etc. but if anyone is having a problem similar to mine, replacing contents of existing file worked for me.
 
  • Like
  • Love
Reactions: himi24 and ivandena

doktor29

Senior Member
Dec 21, 2010
413
63
hello
i need some help with boot on charge on xiaomi device (mix2s)
what i did so far: its stary when usb connected.

But looking for solution like:
- when battery is lower like 20% it will not boot just charge till 20% and then start.

in xiaomi i dont see lpm, playlpm or kpoc file to edit :/
any help ?
 

ivandena

Member
Sep 12, 2008
6
3
Hi guys, as a followup after trying again tonight it is working!

I came across a different link where someone posted his "one-liner" for doing this:


As mentioned previously, with me using Magisk users have reported "/system" mount not existing.

What it looks like it boils down to at least for me, is that every time I was trying this, I was doing a move/rename of the original /system/bin/lpm, then creating a new /system/bin/lpm (as root/root) and then doing a chmod 0755 and a chown to root/shell. Apparently this method did not work for me even though I was seemingly left with the same file with same permissions, but looks like since this person's one-liner does a copy to backup original /system/bin/lpm and then just overwrites the existing file contents with the simple shell shell script to auto-boot, this works!

I'm not sure if my situation is related to Magisk or what, I'm just not very familiar with Android mounts/partitions/etc. but if anyone is having a problem similar to mine, replacing contents of existing file worked for me.

This "one-liner" script work for me too, thx!!
Is there any way to modify this script to speed up the boot?
 

Allexxd

New member
Jan 31, 2015
1
0
Redmi Note 10 Pro
Hi guys, as a followup after trying again tonight it is working!

I came across a different link where someone posted his "one-liner" for doing this:


As mentioned previously, with me using Magisk users have reported "/system" mount not existing.

What it looks like it boils down to at least for me, is that every time I was trying this, I was doing a move/rename of the original /system/bin/lpm, then creating a new /system/bin/lpm (as root/root) and then doing a chmod 0755 and a chown to root/shell. Apparently this method did not work for me even though I was seemingly left with the same file with same permissions, but looks like since this person's one-liner does a copy to backup original /system/bin/lpm and then just overwrites the existing file contents with the simple shell shell script to auto-boot, this works!

I'm not sure if my situation is related to Magisk or what, I'm just not very familiar with Android mounts/partitions/etc. but if anyone is having a problem similar to mine, replacing contents of existing file worked for me.
Hello
can you please explain step by step
 

tojnk

Member
Mar 17, 2011
6
0
Great solution. Made a few modifications to make it work on a Samsung Galaxy S6 (G920F):
  • su -c dd if=/dev/block/platform/15570000.ufs/by-name/BOOT of=/sdcard/boot.img
  • and added a sleep 10 after the last setprop to prevent empty battery boot loops

Hello,

None of the proposed solutions worked for me on Samsung Galaxy Tab A 10.1 (T580) with Android 7 (no boot, black screen, boot to Recovery, etc.), but after much testing, I've found another way to make it work.

Extract boot.img from the rooted device and copy to PC (13540000.dwmmc0 -> T580's boot partition):
adb shell "su -c dd if=/dev/block/platform/13540000.dwmmc0/by-name/BOOT of=/sdcard/boot.img"
adb pull /sdcard/boot.img

Download Android Image Kitchen:
https://forum.xda-developers.com/showthread.php?t=2073775

Drag-and-drop boot.img to unpackimg.bat.

Open ramdisk/init.rc

Search for on charger and add at the end (after write /sys/class/power_supply...):
setprop ro.bootmode "normal"
setprop sys.powerctl "reboot"

Save file and repack image (double click on repackimg.bat).

Rename image-new.img to boot.img

Tar boot.img file (you will need tar for Windows):
tar -cf boot.tar boot.img

Download Odin latest version:
https://samsungodin.com/

Open Odin, click on AP, select boot.tar file.

Reboot device to download mode:
adb reboot download

Click Start on Odin.

After reboot, disconnect and power off device. Reconnect the USB cable and wait.
 
Feb 12, 2018
48
0
44
Buenos Aires
Hi. I have a Samsun J7 Neo ROOT with magisk and original android PIE.
I don't know anything about programming, but I have modified the contents of the LPM file, using the ROOT explorer app.
Delete all your lpm content and try several of the codes published by you. For example this:
#! / system / bin / sh
its
/ system / bin / reboot
I turn off the cell phone, connect the charger, a circle appears with the lightning and then the screen remains black and does not turn on.
Could someone tell me how can I make it turn on when I connect it to a charger?:)
Thank you
Alexander
 

ahhl

Senior Member
Jul 23, 2007
1,074
114
redmi 6a, on android 8, global rom stock (converted from china rom) with magisk 20.4

alecxs
thanks for the link. solve my issues on another redmi 6a, on android 8, global rom stock (converted from china rom) with magisk 20.4
in init.rc file replace

the on charger line from
.....
on charger
class_start charger
to
on charger
exec u:r:magisk:s0 -- /system/bin/reboot

the device will boot twice when plug in charger
 

sblueeye

Member
Jan 11, 2011
6
0
MXIII Auto Power on

Hi,

I have quite an old MXIII TV Box running Android 5.1. It runs a server that I need to keep alive but each power break it shuts down and won't power back on until i manually press the device on button.

Is there any solution out of the above that will automatically power on this device following a power break?

Thanks!
 

ahhl

Senior Member
Jul 23, 2007
1,074
114
Hi,



I have quite an old MXIII TV Box running Android 5.1. It runs a server that I need to keep alive but each power break it shuts down and won't power back on until i manually press the device on button.



Is there any solution out of the above that will automatically power on this device following a power break?



Thanks!
you need to root the device in order to modify certain file.
how to root your device? dont know. you need to ask around

Sent from my Redmi Note 7 using Tapatalk
 

ahhl

Senior Member
Jul 23, 2007
1,074
114
Assuming I already rooted, which file needs to be modified?
usually we search init.rc, some in lpm, some in kpoc_charger file

basically searching for " on charger" line which instruct the system what to do. if you manage to find the "on charger" line any of those file, you need to replace or add command line to reboot.

that instruction are trial and error.
search the whole this thread on what command line to use.

good luck. and share here when you successful

Sent from my Redmi Note 7 using Tapatalk
 

leahcimx

New member
Nov 8, 2020
1
1
Hello all, I've been googling and searching for 2 weeks now trying to figure out how to get my Samsung TabS6 Lite tablet to power on when plugged in. I bought it to install into a dash mounted tablet for my car, and this thread eventually got me there. I wanted to say what I did in case it would help others.

First of all, fastboot oem off-mode-charge 0 did nothing for me. I spent a lot of time trying different PCs/Cables/Drivers etc and though I never found exact confirmation, I suspect Samsung just doesn't allow this functionality in their bootloader.

First I'm using the standard rom except with Magisk having it rooted.
In Magisk I had to go into the settings and let superuser be for "Apps and ADB" and I had to reboot.
Then with ADB on my windows PC I could execute "su" in ADB Shell which let me do the rest of this.

ADB Shell commands
su
mount -o rw,remount /
(i couldn't mount the system directory, but I found a helpful tip somewhere that said mount the root and you can write to the system directory.)
cd system/etc/init
(now i have to create a text file. There's probably a lot better ways to do this, but ultimately I did it this way and could be done all through command prompt in windows, essentially we're creating a .rc file that turns off off mode charging.)

cat > off_mode_charge.rc
(this starts the creation of a text file called "off_mode_charge.rc" I don't think the name of the .rc matters just has to be in the init directory and .rc extension, the next line you'll be typing the lines of the .rc file)
# /system/etc/init/off_mode_charge.rc
(thats the first line, then press enter to do the second line)
on charger
(second line)
setprop sys.powerctl reboot,leaving-off-mode-charging
(third line, with 5 spaces, don't know if the spaces matter thats just how it was formatted when I found it on stack exchange)

Then press Control D to end the file. You should now have an .rc file called off_mode_charge.rc in your init directory and this file essentially tells the system to power on when plugged in. Apparently, all the inits are called at bootloader step. The charge animation still comes up at first, but then it will boot there after.

Finally give that file permissions (don't know if this is necessary but I did it and it worked)

chmod 0755 off_mode_charge.rc
chown root.shell off_mode_charge.rc

Finally set the root system to read only again
mount -o ro,remount /


And that along with a Tasker script to shutdown the tablet when it loses charge has it working for me. I'm just posting this as guest as I'm not a contributor here but I found a lot of this through a combination of
android.stackexchange.com/questions/20021/automatically-power-on-android-when-the-charger-is-connected/221384#221384

and the information posted here.
 
  • Like
Reactions: gmatharu12

ahhl

Senior Member
Jul 23, 2007
1,074
114
another successful auto reboot for Redmi 4x running stock android 7.1.2 mui11
need to change in init.rc the

on charger
class_start charger
with:


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

Top Liked Posts

  • There are no posts matching your filters.
  • 18
    SOLVED: Power on when plugged in (boot when docked)?

    Hey guys, I know that no one else may ever have any use for this, or even care, but I wanted to post an update. I was finally able to get this figured out through some guess work, trial and error, and looking at the work someone else did on a fairly similar project.

    I owe plenty of credit to the fine work done by Chainfire on his project described in this link. His work, while not the same project, demonstrated that something similar to what I wanted to do WAS possible.

    Anyway, to make the tablet boot up when first plugged in- The battery charging indicator that runs when you first plug in the Galaxy Tab is run from the file /system/bin/playlpm. To make it boot automatically, delete the old playlpm (or better yet, rename it to playlpm.bak, just in case) and replace it with the following script.

    /system/bin/playlpm
    Code:
    #!/system/bin/sh
    /system/bin/reboot

    Be sure to set the ownership and permissions the same as the old playlpm. It didn't work for me at first because I had forgotten to give execute permission.

    Thats all that it takes. Most of the time, the Tab should have enough power to go straight to booting. If the battery is really dead, it may flash the charging battery icon a few times, failing to boot until it gets enough charge. It will eventually come on.

    I don't know of any additional side-effects for doing it this way, but there may be some, I don't know what else the stock playlpm is supposed to manage. This worked for my purposes though. Hope it could help someone else.
    5
    Appologies if this has been asked/answered here before. I tried searching, but didn't find any solution. Maybe someone else has stronger Google skills than I.

    Here is what I am trying to do. I'd like to find a way to have the Galaxy Tab power on automatically when it is plugged in to power and begins charging. My company has several Galaxy Tabs (rooted) that are being used for a specialized purpose. They should be plugged in 24/7. However, it is possible that they will lose power, and the battery will eventually run down. When power is restored, I'd like to be sure that they come back on, without any user interaction.

    I don't THINK this is the case, but it is worth asking: Is this a standard Android setting I can change anywhere?

    I assume I will have to modify some code. Right now, I notice that when the Tab is turned off, and you plug it in, the charging indicator shows up and displays the battery levels. To me this indicates that code is running SOMEWHERE as soon as the Tab gets plugged in. I'd like to hijack that, and just have it power on.

    Does anyone know where I should start looking for the code that runs when the device is plugged in? I found a charging.jpg in /mnt/.lfs that seems to be the image that displays, but so far no sign of what code is running. If there is any sort of init script, that would be amazing if someone could point that out.

    Even if you don't know how to accomplish this, if you have any helpful pointers or "take a look at these files" to point me in the right direction, I'd really appreciate it.

    As always guys, thanks for all the help!
    4
    Hello,

    None of the proposed solutions worked for me on Samsung Galaxy Tab A 10.1 (T580) with Android 7 (no boot, black screen, boot to Recovery, etc.), but after much testing, I've found another way to make it work.

    Extract boot.img from the rooted device and copy to PC (13540000.dwmmc0 -> T580's boot partition):
    adb shell "su -c dd if=/dev/block/platform/13540000.dwmmc0/by-name/BOOT of=/sdcard/boot.img"
    adb pull /sdcard/boot.img

    Download Android Image Kitchen:
    https://forum.xda-developers.com/showthread.php?t=2073775

    Drag-and-drop boot.img to unpackimg.bat.

    Open ramdisk/init.rc

    Search for on charger and add at the end (after write /sys/class/power_supply...):
    setprop ro.bootmode "normal"
    setprop sys.powerctl "reboot"

    Save file and repack image (double click on repackimg.bat).

    Rename image-new.img to boot.img

    Tar boot.img file (you will need tar for Windows):
    tar -cf boot.tar boot.img

    Download Odin latest version:
    https://samsungodin.com/

    Open Odin, click on AP, select boot.tar file.

    Reboot device to download mode:
    adb reboot download

    Click Start on Odin.

    After reboot, disconnect and power off device. Reconnect the USB cable and wait.
    2
    I think I'm in the same boat as @fritz.barnes. I've tried every combination of suggestion here but there's something weird going on.

    I have a Samsung Galaxy Tab A 10.1 (2019) with unlocked bootloader, TWRP, and root (Magisk).

    It appears as if anytime i replace /system/bin/lpm and put in the suggested shell scripts to trigger a reboot, it appears this isn't running at all or incurring some kind of exception.

    I was initially really confused because there were other people saying that the script appeared to be working but that it was booting them into recovery/TWRP, and that appeared to be what was happening to me. But after going through so many scenarios, I think there was a reason for that.

    1. When I first made the change to /system/bin/lpm after being in USB debugging and from ADB shell, when I turned the tablet off with cord unplugged, then plugged in cord, I got stuck at the initial lightning charge screen that doesn't have the real battery %, etc.
    2. When this just got stuck forever and didn't reboot (regularly or into TWRP), I held POWER + VOL DOWN to reboot, then POWER + VOL UP to get back into TWRP. After getting into TWRP, mounting system, and making the similar changes to /system/bin/lpm, it "appeared" to be working in that after powering off with cord unplugged, it would start up when cord plugged in but go immediately into TWRP.
    3. I realized later after trying multiple different versions of this file that all kept going into TWRP, if I rebooted regularly into system first with TWRP, then powered off with cord unplugged, then plugged cord in, I was still stuck at the initial lightning charge screen that doesn't have the real battery %, etc.

    After all that, I'm assuming the initial lightning charge screen has nothing to do with /system/bin/lpm, and that this shows regardless of what /system/bin/lpm is. But compared to the original /system/bin/lpm behavior of in a few seconds showing correct battery %, my attempts at the shell script /system/bin/lpm probably just appear to be doing nothing (not rebooting) and just keeping me at the initial lightning charge screen.

    As I said, I tried multiple different versions of the script throughout this thread and nothing has seemed to work. I have created the file or copied the file in different ways and also verified EOL characters, etc.

    Does anyone have any idea what's going on with my situation (and possibly with @fritz.barnes having the same or similar issue that I do) or how to debug this? Is there something that has been altered with reboots by TWRP that requires any sort of Android property to be set or anything? I'm not an Android developer, but I see this in the TWRP source in terms of doing a system reboot, but I'm not fully sure what's going on here.

    Code:
    case rb_system:
    			Update_Intent_File("s");
    			sync();
    			check_and_run_script("/sbin/rebootsystem.sh", "reboot system");
    #ifdef ANDROID_RB_PROPERTY
    			return property_set(ANDROID_RB_PROPERTY, "reboot,");
    #elif defined(ANDROID_RB_RESTART)
    			return android_reboot(ANDROID_RB_RESTART, 0, 0);
    #else
    			return reboot(RB_AUTOBOOT);
    #endif

    Thanks!

    ---------- Post added at 09:48 PM ---------- Previous post was at 09:21 PM ----------



    Not sure if I'm normally supposed to reply to my own post here, but I have some more information that seems interesting.

    If I take the original /system/bin/lpm, make a copy and then use the copy as /system/bin/lpm (and move the original to a different file, i.e. /system/bin/lpm.bak), the copied version of the original binary also seems to not work and keep me at the initial lightning charge screen. I am making sure to chmod 0755 and chown root.shell any copied files as you can see below. The original file has timestamp of 2008-12-31, and this specific file appears to be the only one that will work (and go to the normal charge indicator screen).
    aFwCp4k.png


    Not sure if this will further help diagnosis anything, but what's going on here? Why with a copy of the original lpm binary does this also result in me being stuck at the initial lightning charge screen? Any ideas?

    I'd be willing to send a $50 bounty via Venmo to whoever can help me get this working.

    from my own experience, if something get stuck, it means the comand in tge lpm file is wrong, you have to try different command.

    i have successfully auto boot 4 different phone, S4, Mate 7, zenphone6, redmi 6a, they all need to use different command, eventhough i only changing the same file. in my case in init.rc and some by just changing kpoc file.

    Sent from my Redmi Note 7 using Tapatalk

    Hi guys, as a followup after trying again tonight it is working!

    I came across a different link where someone posted his "one-liner" for doing this:
    mount -o remount,rw /dev/block/platform/dw_mmc.0/by-name/SYSTEM /system && cp /system/bin/lpm /system/bin/lpm_orig && echo "#!/system/bin/sh\n/system/bin/reboot" > /system/bin/lpm

    As mentioned previously, with me using Magisk users have reported "/system" mount not existing.

    What it looks like it boils down to at least for me, is that every time I was trying this, I was doing a move/rename of the original /system/bin/lpm, then creating a new /system/bin/lpm (as root/root) and then doing a chmod 0755 and a chown to root/shell. Apparently this method did not work for me even though I was seemingly left with the same file with same permissions, but looks like since this person's one-liner does a copy to backup original /system/bin/lpm and then just overwrites the existing file contents with the simple shell shell script to auto-boot, this works!

    I'm not sure if my situation is related to Magisk or what, I'm just not very familiar with Android mounts/partitions/etc. but if anyone is having a problem similar to mine, replacing contents of existing file worked for me.
    2
    Found solution that works on Samsung Galaxy Tab A6

    For me the reboot scheme didn't work but what did work was putting into /system/bin/lpm this:
    Code:
    #!/system/bin/sh
    echo b > /proc/sysrq-trigger

    Hope it helps someone :)