#!/system/bin/sh
echo "========== 电池健康度分析 =========="

# 1. 获取当前实际满电容量（单位：uAh，需除以1000转mAh）
# 路径常见于 charge_full 或 capacity
CURRENT_FULL=$(cat /sys/class/power_supply/battery/charge_full 2>/dev/null)

# 2. 获取出厂设计容量（单位：uAh）
# 路径常见于 charge_full_design
DESIGN_CAP=$(cat /sys/class/power_supply/battery/charge_full_design 2>/dev/null)

if [ -n "$CURRENT_FULL" ] && [ -n "$DESIGN_CAP" ] && [ $DESIGN_CAP -gt 0 ]; then
    # 计算健康度百分比（保留1位小数）
    HEALTH=$(echo "scale=1; $CURRENT_FULL * 100 / $DESIGN_CAP" | bc)
    echo "设计容量: $(($DESIGN_CAP / 1000)) mAh"
    echo "当前满电: $(($CURRENT_FULL / 1000)) mAh"
    echo -e "电池健康度: ${HEALTH}%"
    
    # 健康度预警
    if (( $(echo "$HEALTH < 80" | bc -l) )); then
        echo "⚠️ 警告：健康度低于80%，建议考虑更换电池"
    fi
else
    echo "❌ 未找到容量数据，请尝试检查手机具体路径"
fi

# 3. 查看循环次数（非所有手机支持）
CYCLE=$(cat /sys/class/power_supply/battery/cycle_count 2>/dev/null)
if [ -n "$CYCLE" ]; then
    echo "循环次数: ${CYCLE} 次"
fi