在android棉花糖平板电脑';通过usb充电启动

在android棉花糖平板电脑';通过usb充电启动,android,android-6.0-marshmallow,android-reboot,Android,Android 6.0 Marshmallow,Android Reboot,我试着让脚本重新启动平板电脑从充电模式到正常,如果它是通过插入usb充电器启动的。Android init语言非常简单,但实际上它是如何分配的对我来说是相当神秘的 所以我在root上实现了我的_script.sh。 添加到系统文件my_script.sh initrd/my_script.sh 0750 并重新打包boot.img。已验证所有内容都在it位置,访问权限应正确无误 #!/system/bin/sh /system/bin/reboot -c reboot now 然后我在init

我试着让脚本重新启动平板电脑从充电模式到正常,如果它是通过插入usb充电器启动的。Android init语言非常简单,但实际上它是如何分配的对我来说是相当神秘的

所以我在root上实现了我的_script.sh。 添加到系统文件my_script.sh initrd/my_script.sh 0750 并重新打包boot.img。已验证所有内容都在it位置,访问权限应正确无误

#!/system/bin/sh
/system/bin/reboot -c reboot now
然后我在init.rc中

service rebootit /system/bin/sh /my_script.sh
    class main
    user root
    oneshot
然后,我在init.rc的“充电”下添加了以下内容

start rebootit
你知道如何才能做到这一点吗

编辑1。 我试着跟着

service rebootit /system/bin/reboot -c reboot now
    class main
    user root
    oneshot
这就是结果

 [4.648753] init: cannot execve('/system/bin/reboot'): Permission denied
 [4.649167] type=1400 audit(85946.779:4): avc: denied { execute_no_trans } for pid=331 comm="init" path="/system/bin/reboot" dev="mmcblk0p21" ino=730 scontext=u:r:init:s0 tcontext=u:object_r:system_file:s0 tclass=file permissive=0
编辑2。

嗯。取得了一些进展。echo b>/proc/sysrq触发器似乎要重新启动,但现在我需要找到一些变量,当引导到正常模式时,可以使用这些变量来分隔正在运行的脚本。我尝试使用从另一个init文件中找到的这种脚本。只是根据我的需要修改了一下,但还是没有运气

#!/system/bin/sh
bootmode=`getprop ro.bootmode`
if [ "$bootmode" = "charger" ]; then # Reboot the tablet
echo b > /proc/sysrq-trigger
fi
编辑3。解决方案

现在我终于明白了

在init.rc上,我添加了以下内容:

#Check if chargermode and start rebootit service.
on property:ro.bootmode=charger
    start rebootit   
#rebootit service which command reboot
service rebootit /su/bin/su /system/bin/reboot -c reboot now
    user root
    oneshot
并在其之后添加了以下内容:

#Check if chargermode and start rebootit service.
on property:ro.bootmode=charger
    start rebootit   
#rebootit service which command reboot
service rebootit /su/bin/su /system/bin/reboot -c reboot now
    user root
    oneshot

您需要安装SU才能工作

你修改过它然后重新打包了吗?img?是的,我修改过并重新打包了。你是怎么做的?这个设备没有dm verity吗?我找到了在我的设备上解包和打包图像的指南。我使用的平板电脑没有dm验证。