Skip to content

Commit

Permalink
fix(rickysarraf#191): USB-C power supply might not be reported
Browse files Browse the repository at this point in the history
- fixed determination of ON_AC if no AC adapter found
  • Loading branch information
rwappler committed Oct 29, 2022
1 parent 1a4b55c commit 2aacf85
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions usr/sbin/laptop_mode
Original file line number Diff line number Diff line change
Expand Up @@ -486,11 +486,13 @@ lmt_load_config ()
SYSFS_POWER_SUPPLY=0
export ON_AC=0
BATTERY_NOT_DISCHARGING=0
AC_ADAPTER_CONNECTED=0
for POWER_SUPPLY in /sys/class/power_supply/* ; do
if [ -f $POWER_SUPPLY/type ] ; then
SYSFS_POWER_SUPPLY=1
if [ "$(cat $POWER_SUPPLY/type)" = "Mains" ]; then
log "VERBOSE" "Determining power state from $POWER_SUPPLY/online."
AC_ADAPTER_CONNECTED=1
if [ "$(cat $POWER_SUPPLY/online)" = 1 ]; then
ON_AC=1
break
Expand All @@ -516,12 +518,13 @@ lmt_load_config ()
fi
done

if [ ON_AC = 1 -a $SYSFS_POWER_SUPPLY = 1 ] ; then
if [ $SYSFS_POWER_SUPPLY = 1 ] ; then
# Already found it!
log "VERBOSE" "Not trying other options, already found a power supply."
elif [ $BATTERY_NOT_DISCHARGING = 1 ]; then
log "VERBOSE" "Marking it as online ON_AC because we found no AC and the battery is not discharging"
ON_AC=1
if [ $AC_ADAPTER_CONNECTED = 0 -a $BATTERY_NOT_DISCHARGING = 1 ]; then
log "VERBOSE" "No AC adapter found in /sys/class/power_supply and battery is not discharging. Marking it as online AC"
ON_AC=1
fi
elif [ -d /proc/acpi/ac_adapter ] ; then
log "VERBOSE" "Determining power state from /proc/acpi/ac_adapter."
ADAPTERS_FOUND=0
Expand Down

0 comments on commit 2aacf85

Please sign in to comment.