@@ -181,26 +181,58 @@ get_part_hash() {
181181# ---- Power Check ----
182182check_power () {
183183 local power_connected=0
184- # Check all power supplies for a 'Mains' or 'USB' source that is 'online'
184+ local max_battery=0
185+ local has_battery=0
186+
187+ # Scan power supplies for AC power or battery capacity
185188 for supply in /sys/class/power_supply/* ; do
189+ [ -d " $supply " ] || continue
190+
191+ # Check for connected AC / USB charger
186192 if [ -f " $supply /online" ] && [ -f " $supply /type" ]; then
187- type=$( cat " $supply /type" )
188- online=$( cat " $supply /online" )
193+ type=$( cat " $supply /type" 2> /dev/null || true )
194+ online=$( cat " $supply /online" 2> /dev/null || true )
189195 if [[ " $type " == " Mains" || " $type " == " USB" ]] && [ " $online " -eq 1 ]; then
190196 power_connected=1
191- break
197+ fi
198+ fi
199+
200+ # Check battery capacity percentage
201+ if [ -f " $supply /capacity" ]; then
202+ has_battery=1
203+ cap=$( cat " $supply /capacity" 2> /dev/null || echo 0)
204+ if [ " $cap " -gt " $max_battery " ]; then
205+ max_battery=$cap
192206 fi
193207 fi
194208 done
195209
196- if [ " $power_connected " -eq 0 ]; then
197- echo " ------------------------------------------------------------"
198- echo " ERROR: DEVICE IS NOT ON AC POWER "
199- echo " To prevent bricking during the ABL flash, please plug in "
200- echo " your charger/power cable before attempting to flash. "
201- echo " ------------------------------------------------------------"
202- exit 1
210+ # Allow if plugged into AC/USB power
211+ if [ " $power_connected " -eq 1 ]; then
212+ return 0
203213 fi
214+
215+ # Allow if on battery and capacity is >= 10%
216+ if [ " $has_battery " -eq 1 ]; then
217+ if [ " $max_battery " -ge 10 ]; then
218+ return 0
219+ else
220+ echo " ------------------------------------------------------------"
221+ echo " ERROR: BATTERY LEVEL TOO LOW (${max_battery} %) "
222+ echo " To prevent bricking during the ABL flash, your battery must "
223+ echo " be at least 10% or plugged into AC power. "
224+ echo " ------------------------------------------------------------"
225+ exit 1
226+ fi
227+ fi
228+
229+ # Fallback error if power status could not be determined
230+ echo " ------------------------------------------------------------"
231+ echo " ERROR: DEVICE IS NOT ON AC POWER "
232+ echo " To prevent bricking during the ABL flash, please plug in "
233+ echo " your charger/power cable before attempting to flash. "
234+ echo " ------------------------------------------------------------"
235+ exit 1
204236}
205237
206238# Run the power check
0 commit comments