Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore incorrectly reported batteries and ignore unhandled power_supp… #186

Open
wants to merge 2 commits into
base: lmt-upstream
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions usr/sbin/laptop_mode
Original file line number Diff line number Diff line change
Expand Up @@ -488,14 +488,19 @@ lmt_load_config ()
BATTERY_NOT_DISCHARGING=0
for POWER_SUPPLY in /sys/class/power_supply/* ; do
if [ -f $POWER_SUPPLY/type ] ; then
SYSFS_POWER_SUPPLY=1
SYSFS_POWER_SUPPLY=$(( SYSFS_POWER_SUPPLY + 1 ))
if [ "$(cat $POWER_SUPPLY/type)" = "Mains" ]; then
log "VERBOSE" "Determining power state from $POWER_SUPPLY/online."
if [ "$(cat $POWER_SUPPLY/online)" = 1 ]; then
ON_AC=1
break
fi
elif [ "$(cat $POWER_SUPPLY/type)" = "Battery" ]; then
if [ "$(cat $POWER_SUPPLY/scope)" != "System" ]; then
log "VERBOSE" "Ignoring battery $POWER_SUPPLY, because it is not a system battery"
SYSFS_POWER_SUPPLY=$(( SYSFS_POWER_SUPPLY - 1 ))
continue
fi
log "VERBOSE" "Determining power state from status of battery $POWER_SUPPLY."
#INFO: Because there are and will always be br0ken batteries
if [ "$(cat $POWER_SUPPLY/status)" != "Discharging" ]; then
Expand All @@ -512,11 +517,15 @@ lmt_load_config ()
ON_AC=0
break
fi
else
log "VERBOSE" "Power_supply has unhandled type $(cat $POWER_SUPPLY/type)"
log "VERBOSE" "Ignoring it"
SYSFS_POWER_SUPPLY=$(( SYSFS_POWER_SUPPLY - 1 ))
fi
fi
done

if [ $SYSFS_POWER_SUPPLY = 1 ] ; then
if [ $SYSFS_POWER_SUPPLY -gt 0 ] ; then
# Already found it!
log "VERBOSE" "Not trying other options, already found a power supply."
elif [ $BATTERY_NOT_DISCHARGING = 1 ]; then
Expand Down