Android是通过sys伪文件系统中文件来获取手机电池的电量及状态。
路径: /sys/class/power_supply/xxxx/
伪装capacity文件来手动控件电池电量状态, 基本思路是将/sys/class/power_supply/xxxx/作为一个分区的挂载点, 然后在分区创建必要的文件,然后就可以模拟系统低电量状态
#!/system/bin/sh
# create a fake battery level file and copy neccessary file that android use.
touch /data/capacity
echo 50 > /data/capacity
cp /sys/class/power_supply/XXXX/status /data/
cp /sys/class/power_supply/XXXX/temp /data/
cp /sys/class/power_supply/XXXX/health /data/
cp /sys/class/power_supply/XXXX/present /data/
cp /sys/class/power_supply/XXXX/voltage* /data/
# using mount command to get correspond partiton of /data/ directory
# remount partion to /sys/class/power_supply/xxxx
mount -rw -t ext4 /dev/block/mmcblk0pX /sys/class/power_supply/XXXX
# emulate empty battery status need to unplug USB as Android will think it's in charge status when USB plugged.
echo 0 > /data/capacity