Android:以编程方式打开设备 [英] Android : Turn on a device programmatically

查看:115
本文介绍了Android:以编程方式打开设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一部连接太阳能充电器的智能手机. 白天,它已正确供电.但是在晚上,有时会由于能量不足而自行关闭.

I have a smartphone connected to a solar charger. By day, it is powered correctly. But during the night, sometimes it turns itself off due to the lack of energy.

我的问题是:当电池电量超过一定百分比时,是否可以将其重新打开(以编程方式)? 我正在寻找一种清洁合法的方法.我对缺陷或漏洞利用不感兴趣. 我没有在官方文档中找到任何东西.谢谢.

My question is : It is possible to turn it back on (programmatically), when the battery charge exceeds a certain percentage? I'm looking for a clean and legal way. I'm not interested in flaws or exploits. I found nothing in the official documentation. Thank you.

推荐答案

执行此操作的机制取决于替换电池动画脚本,该脚本在设备关闭但已插入电源时运行,通常显示充电图标电池.脚本的名称因设备而异,但通常位于/system/bin目录中.三星设备通常将脚本称为playlpm,而我所看到的脚本的其他名称包括ipodlpmbattery_charging.这不一定会在所有设备上都有效,因为它远远超出了标准的Android框架-有些设备可能没有等效的脚本,或者它们可能以不同的方式实现.

The mechanism for doing this relies on replacing the battery animation script, which is run while the device is turned off but plugged in, typically displaying an icon of the charging battery. The name of the script varies from device to device, but it is generally located in the /system/bin directory. Samsung devices generally call the script playlpm, and other names for the script that I've seen include ipod, lpm, and battery_charging. This will not necessarily work on every device, because this is well outside of the standard Android framework -- some devices might not have an equivalent script, or they might implement it in a different way.

这可以被描述为漏洞利用",因为它需要root权限并且可以在Linux级别而不是Android框架级别工作,但是目前没有替代方法可以实现此行为.

This could be characterized as an "exploit" in that it requires root and works at the Linux level rather than the Android framework level, but there is currently no alternative for implementing this behavior.

此处描述了进行此更改的一般机制:

The general mechanism for making this change is described here: https://android.stackexchange.com/questions/20021/automatically-power-on-android-when-the-charger-is-connected. Of course it's a good idea to back up the previous battery animation script before you do any of this.

以下脚本已在多个设备(几个三星设备和Verizon Ellipsis 7)上为我工作.基本上,它会检查手机是否已插入交流电源并具有足够的电量.如果是这样,它将启动.如果不是,它将等待N秒,然后重试.副作用是,原始的电池动画脚本将无法运行,并且您将永远不会看到漂亮的充电动画.

The following script has worked for me on multiple devices (several Samsung devices and the Verizon Ellipsis 7). Basically, it checks to see if the phone is plugged into AC power and has enough charge. If so, it boots up. If not, it waits for N seconds and tries again. As a side effect, the original battery animation script won't run, and you won't ever see the pretty charging animation.

#!/system/bin/sh                                                                               

# battery threshold before boot-up (in percent)                                                
bthresh=10

# time to sleep between checks (in seconds)                                                    
sleeptime=600

# file that contains current battery level as integer between 0 and 100                        
cfi=/sys/class/power_supply/battery/capacity
# file that contains 1 if we're plugged in to AC, 0 if not                                     
acfi=/sys/class/power_supply/battery/subsystem/ac/online

# if either file doesn't exist, just do normal sleep+boot                                      
[ ! -f $cfi ] && sleep $sleeptime && /system/bin/reboot
[ ! -f $acfi ] && sleep $sleeptime && /system/bin/reboot

# populate capacity and AC variables                                                           
c=`cat $cfi`
ac=`cat $acfi`

# stop loop if we're not plugged into AC                                                       
until [ "$ac" -eq 0 ]
do
    # if capacity above threshold, boot up                                                     
    if [ "$c" -gt "$bthresh" ]; then
    /system/bin/reboot
    fi

    # wait some time before next check                                                         
    sleep $sleeptime

    # update capacity and AC variables                                                         
    c=`cat $cfi`
    ac=`cat $acfi`
done

这篇关于Android:以编程方式打开设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆