Bug 472657 - Battery widget shows charging icon, and computer will not sleep, even though AC is disconnected
Summary: Battery widget shows charging icon, and computer will not sleep, even though ...
Status: RESOLVED UPSTREAM
Alias: None
Product: Powerdevil
Classification: Plasma
Component: general (show other bugs)
Version: 5.27.6
Platform: Neon Linux
: NOR normal
Target Milestone: ---
Assignee: Plasma Bugs List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-07-26 12:26 UTC by Oded Arbel
Modified: 2024-09-19 07:40 UTC (History)
4 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments
screenshot showing the battery discharging while battery icon shows chargin (67.31 KB, image/png)
2023-07-26 12:26 UTC, Oded Arbel
Details
SCreenshot showing battery tooltip with the charger disconnected (25.00 KB, image/png)
2023-08-13 09:11 UTC, Oded Arbel
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Oded Arbel 2023-07-26 12:26:06 UTC
SUMMARY

The problem manifests on a Dell Precision 5570 - it didn't happen on my previous system which was a Dell Precision 5520 - if I disconnect the AC adapter, the battery icon in the power widget still shows that the computer is connected and with the default energy saving settings - which is to not sleep when AC is connected and closing the lid (which is how I like it) - the computer will not sleep when closing the lid after disconnecting AC power.

STEPS TO REPRODUCE
1. Disconnect AC power
2. close lid

OBSERVED RESULT
Computer does not sleep

EXPECTED RESULT
Computer should sleep

SOFTWARE/OS VERSIONS
Operating System: KDE neon Testing Edition
KDE Plasma Version: 5.27.6
KDE Frameworks Version: 5.109.0
Qt Version: 5.15.10
Kernel Version: 6.2.0-26-generic (64-bit)
Graphics Platform: offscreen
Processors: 20 × 12th Gen Intel® Core™ i7-12700H
Memory: 31.0 GiB of RAM
Graphics Processor: Mesa Intel® Graphics

ADDITIONAL INFORMATION
There are several interesting things going on - first, the system tray is configured for the battery widget to be "shown when relevant", and when I connect the AC - the battery widget goes to the overflow menu, which is the behavior I'd expect if the system knows that it is connected to the AC.

Secondly, UPower shows that it knows that AC is offline:

$ upower -d
Device: /org/freedesktop/UPower/devices/line_power_AC
  native-path:          AC
  power supply:         yes
  updated:              Wed 26 Jul 2023 14:36:16 (21 seconds ago)
  has history:          no
  has statistics:       no
  line-power
    warning-level:       none
    online:              no
    icon-name:          'ac-adapter-symbolic'

so I'd expect powerdevil to also know what is going on. The full upower output is attached below, and there are some weird things in it that may be confusing powerdevil:

---8<---
Device: /org/freedesktop/UPower/devices/line_power_AC
  native-path:          AC
  power supply:         yes
  updated:              Wed 26 Jul 2023 14:36:16 (21 seconds ago)
  has history:          no
  has statistics:       no
  line-power
    warning-level:       none
    online:              no
    icon-name:          'ac-adapter-symbolic'

Device: /org/freedesktop/UPower/devices/battery_BAT0
  native-path:          BAT0
  vendor:               SMP
  model:                DELL P8P1P95
  serial:               2242
  power supply:         yes
  updated:              Wed 26 Jul 2023 14:36:21 (16 seconds ago)
  has history:          yes
  has statistics:       yes
  battery
    present:             yes
    rechargeable:        yes
    state:               discharging
    warning-level:       none
    energy:              53.5458 Wh
    energy-empty:        0 Wh
    energy-full:         54.891 Wh
    energy-full-design:  54.891 Wh
    energy-rate:         40.356 W
    voltage:             11.999 V
    charge-cycles:       N/A
    time to empty:       1.3 hours
    percentage:          97%
    temperature:         28.9 degrees C
    capacity:            100%
    technology:          lithium-polymer
    icon-name:          'battery-full-symbolic'
  History (charge):
    1690371376  97.000  discharging
  History (rate):
    1690371381  40.356  discharging
    1690371380  41.348  discharging
    1690371378  15.698  discharging
    1690371377  11.617  discharging

Device: /org/freedesktop/UPower/devices/line_power_ucsi_source_psy_USBC000o001
  native-path:          ucsi-source-psy-USBC000:001
  power supply:         yes
  updated:              Wed 26 Jul 2023 14:10:43 (1554 seconds ago)
  has history:          no
  has statistics:       no
  line-power
    warning-level:       none
    online:              yes
    icon-name:          'ac-adapter-symbolic'

Device: /org/freedesktop/UPower/devices/line_power_ucsi_source_psy_USBC000o002
  native-path:          ucsi-source-psy-USBC000:002
  power supply:         yes
  updated:              Wed 26 Jul 2023 14:10:43 (1554 seconds ago)
  has history:          no
  has statistics:       no
  line-power
    warning-level:       none
    online:              no
    icon-name:          'ac-adapter-symbolic'

Device: /org/freedesktop/UPower/devices/line_power_ucsi_source_psy_USBC000o003
  native-path:          ucsi-source-psy-USBC000:003
  power supply:         yes
  updated:              Wed 26 Jul 2023 14:10:44 (1553 seconds ago)
  has history:          no
  has statistics:       no
  line-power
    warning-level:       none
    online:              no
    icon-name:          'ac-adapter-symbolic'

Device: /org/freedesktop/UPower/devices/DisplayDevice
  power supply:         yes
  updated:              Wed 26 Jul 2023 14:36:21 (16 seconds ago)
  has history:          no
  has statistics:       no
  battery
    present:             yes
    state:               discharging
    warning-level:       none
    energy:              53.5458 Wh
    energy-full:         54.891 Wh
    energy-rate:         40.356 W
    charge-cycles:       N/A
    time to empty:       1.3 hours
    percentage:          97%
    icon-name:          'battery-full-symbolic'

Daemon:
  daemon-version:  0.99.20
  on-battery:      no
  lid-is-closed:   no
  lid-is-present:  yes
  critical-action: HybridSleep
---8<---
Comment 1 Oded Arbel 2023-07-26 12:26:59 UTC
Created attachment 160528 [details]
screenshot showing the battery discharging while battery icon shows chargin
Comment 2 Natalie Clarius 2023-08-10 19:50:57 UTC
What does the panel battery icon say when you move your mouse over it? Is it "plugged in but still discharging"?
Comment 3 Oded Arbel 2023-08-10 19:56:21 UTC
With current Neon testing (see kinfo below), I can no longer reproduce the issue.

Operating System: KDE neon Testing Edition
KDE Plasma Version: 5.27.7
KDE Frameworks Version: 5.109.0
Qt Version: 5.15.10
Kernel Version: 6.2.0-26-generic (64-bit)
Graphics Platform: offscreen
Processors: 11 × Unknown Type, 9 × 12th Gen Intel® Core™ i7-12700H
Memory: 31.0 GiB of RAM
Graphics Processor: Mesa Intel® Graphics
Comment 4 Oded Arbel 2023-08-13 09:11:13 UTC
Created attachment 160929 [details]
SCreenshot showing battery tooltip with the charger disconnected

(In reply to Natalie Clarius from comment #2)
> What does the panel battery icon say when you move your mouse over it? Is it
> "plugged in but still discharging"?

I was too hasty - last week it appeared to be working well, so I put the "lid close on AC" action back to "blank screen" (I think the default), and this morning when I closed the laptop to go to the office, it did not sleep and overheated in the bag.

Here's a screenshot of  the battery tooltip with the charger *disconnected* - it does say "plugged in but still discharging" but also "the power supply is not powerful enough to charge this battery" - which makes me think that it may be related to the fact that at home (unlike what I have in currently in the office) I use a 60W charger, which the Dell complains is not powerful enough to charge the battery (in the BIOS after reboot), while in effect it works well enough (I don't use the builtin Nvidia GPU almost at all). The Laptop comes with a 130W adapter.

I don't actually know what the battery tooltip says when its connected to my 60W dock at home - but checking a 90W charger and even a 65W one I scrounged from office colleagues, it does not complain about "not powerful enough". I will check if I get this notice with the 60W dock when I get home later.
Comment 5 Oded Arbel 2023-08-15 07:12:10 UTC
(In reply to Oded Arbel from comment #4)
> I don't actually know what the battery tooltip says when its connected to my
> 60W dock at home

I checked and with the "weak" 60W charger, and the battery indicator tooltip does not include the "not powerful enough" notice, so I'm not sure where that came from.

Also, after a reboot - now it looks fine: with the charger disconnected the bettery indicator just says "Battery at XX%" and the computer will sleep when closing the lid - which was also the case when I posted comment #3. Apparently its an issue that comes and goes?
Comment 6 Nate Graham 2023-09-01 16:38:03 UTC
Pretty sure this is unfortunately a kernel bug: https://bugzilla.kernel.org/show_bug.cgi?id=210425.

I'm on 6.4.11 and can't reproduce it anymore, though I was able to in the past.
Comment 7 Oded Arbel 2023-09-01 19:59:02 UTC
(In reply to Nate Graham from comment #6)
> Pretty sure this is unfortunately a kernel bug:
> https://bugzilla.kernel.org/show_bug.cgi?id=210425.
> 
> I'm on 6.4.11 and can't reproduce it anymore, though I was able to in the
> past.

I'm also currently on 6.4.11 (installed using "mainline", and I should really get a new kernel). From what I understand, the issue reported in kernel bug 210425 should have already been fixed in the 6.0 branch (as you yourself has mentioned in comment 46) - so should have been working fine with the 6.2.0 kernel I was using in July.

Also, regarding the original UPower bug you reported, I can see the UPower events on the system D-Bus:

---8<---
signal time=1693597149.313791 sender=:1.31 -> destination=(null destination) serial=8791 path=/org/freedesktop/UPower/devices/line_power_AC; interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
   string "org.freedesktop.UPower.Device"
   array [
      dict entry(
         string "UpdateTime"
         variant             uint64 1693597149
      )
      dict entry(
         string "Online"
         variant             boolean false
      )
   ]
   array [
   ]
signal time=1693597149.440405 sender=:1.31 -> destination=(null destination) serial=8793 path=/org/freedesktop/UPower/devices/battery_BAT0; interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
   string "org.freedesktop.UPower.Device"
   array [
      dict entry(
         string "UpdateTime"
         variant             uint64 1693597149
      )
      dict entry(
         string "IconName"
         variant             string "battery-full-symbolic"
      )
      dict entry(
         string "Voltage"
         variant             double 12.768
      )
      dict entry(
         string "State"
         variant             uint32 2
      )
   ]
   array [
   ]
---8<---

And the issue is about connecting and disconnecting the charger when the system is powered on and not sleeping, so I don't think it relates much to the kernel bug anyway.

I don't think its an issue with Plasma not seeing the UPower event because - as I've noted in the description - the battery icon moves from being shown hidden in the system tray overflow dialog to be visible in the system tray when disconnecting the charger (because it is set to "shown when relevant" in the system tray configuration) - so obviously Plasma sees a change. But then it disobeys UPower when it says - as shown in the `upower -d` output in the bug description, and the D-Bus monitor output above - to show icon "battery-full-symbolic", instead it keeps showing "battery-full-charged-symbolic" (which is what UPower says to show when the charger is connected).
Comment 8 Oded Arbel 2023-09-01 22:12:48 UTC
Reading the UPower ticket's comments more thoroughly - could it be because the new laptop is charging from a USB-C port (there are only USB-C ports on this device) while the older one was using a standard barrel charger?
Comment 9 Oded Arbel 2024-01-19 13:46:23 UTC
This is still an issue I'm having with current Neon testing, Plasma 6.0 RC1, with Kernel 6.5.0-14-generic #14~22.04.1-Ubuntu.

I've noticed a weird thing in `upower -d` output: my laptop does not have a dedicated AC-powered charger (calling it "AC line power" is silly because it's a DC power connection), instead this laptop has 3 USB-C ports (and an SC slot, but that' it). Upower seem to list all USB-C port as possible power connectors, though I normally only connect USB-C 1 (the farthest port from me on the left side) and sometimes USB-C 2 (if I miss the first, it is the other one on the left side).

So here's `upower -d` output when the laptop is *connected* to a USB-C dock (not thunderbolt), trimmed to only show `line_power_AC` and `line_power_usci`:

---8<---
Device: /org/freedesktop/UPower/devices/line_power_AC
  native-path:          AC
  power supply:         yes
  updated:              Fri 19 Jan 2024 14:51:34 (429 seconds ago)
  has history:          no
  has statistics:       no
  line-power
    warning-level:       none
    online:              yes
    icon-name:          'ac-adapter-symbolic'

Device: /org/freedesktop/UPower/devices/line_power_ucsi_source_psy_USBC000o001
  native-path:          ucsi-source-psy-USBC000:001
  power supply:         yes
  updated:              Fri 19 Jan 2024 14:51:34 (429 seconds ago)
  has history:          no
  has statistics:       no
  line-power
    warning-level:       none
    online:              yes
    icon-name:          'ac-adapter-symbolic'

Device: /org/freedesktop/UPower/devices/line_power_ucsi_source_psy_USBC000o002
  native-path:          ucsi-source-psy-USBC000:002
  power supply:         yes
  updated:              Fri 19 Jan 2024 14:51:34 (429 seconds ago)
  has history:          no
  has statistics:       no
  line-power
    warning-level:       none
    online:              no
    icon-name:          'ac-adapter-symbolic'

Device: /org/freedesktop/UPower/devices/line_power_ucsi_source_psy_USBC000o003
  native-path:          ucsi-source-psy-USBC000:003
  power supply:         yes
  updated:              Fri 19 Jan 2024 14:51:34 (429 seconds ago)
  has history:          no
  has statistics:       no
  line-power
    warning-level:       none
    online:              no
    icon-name:          'ac-adapter-symbolic'
---8<---

As far as I understand, "/org/freedesktop/UPower/devices/line_power_AC" is "any connection provides line power" while the separate "org/freedesktop/UPower/devices/line_power_ucsi_source_psy*" devices are "this is the physical connection that can take line power". We can clearly see that AC line power is provided and the first of the 3 USBC devices is "online" - which I think describes my setup correctly.

And here is the relevant output of `upower -d` when the laptop is *not connected*:

---8<---
Device: /org/freedesktop/UPower/devices/line_power_AC
  native-path:          AC
  power supply:         yes
  updated:              Fri 19 Jan 2024 15:00:13 (11 seconds ago)
  has history:          no
  has statistics:       no
  line-power
    warning-level:       none
    online:              no
    icon-name:          'ac-adapter-symbolic'

Device: /org/freedesktop/UPower/devices/line_power_ucsi_source_psy_USBC000o001
  native-path:          ucsi-source-psy-USBC000:001
  power supply:         yes
  updated:              Fri 19 Jan 2024 14:51:34 (530 seconds ago)
  has history:          no
  has statistics:       no
  line-power
    warning-level:       none
    online:              yes
    icon-name:          'ac-adapter-symbolic'
---8<---

As you can see, the "line_power_AC" device is no longer online, though the 1st USBC PSY still reports that it is online!

This reports tracks with the content of the files `/sys/class/power_supply/AC/online` and `/sys/class/power_supply/ucsi-source-psy-USBC000:00*/online`. I've tested several different chargers and docks on different USB-C ports, and while always correctly represents the powered state of the laptop, the USBC PSY "online" files always say 1=1, 2=0, 3=0.

I've found this LKML discussion from 2020: https://lore.kernel.org/all/20201110101519.GC1224435@kuha.fi.intel.com/T/ which seems to describe my situation well, though the kernel I'm using (6.5.0) is supposed to have the patch that is discussed in that thread, and that appeared to resolve the complaint.

It seems to me that Plasma checks if *any* UPower device is "online" to trigger the "on battery" behavior, though it should only take into consideration the overall system state as reported by the "line_power_AC" device.
Comment 10 Aldoo 2024-06-04 14:32:47 UTC
Dell Latitude 5410, Kernel 6.5.0-25-generic with plasma 6.0.4.
I can reproduce previous comment's output: when unplugged, the psy line power, wrongly, reports online, while the main line power correctly reports offline.
The widget icon says the power is connected (wrong) while discharging.
Comment 11 Aldoo 2024-06-04 15:19:39 UTC
The DBUS property "OnBattery" from "/org/freedesktop/UPower" also happens to wrongly report "false" when my laptop is unplugged.
I am not sure I understand exactly how powerdevil works, but it seems likely that it uses this property.
Comment 12 Aldoo 2024-06-04 15:23:39 UTC
One more observation: like OP, the output "upower -d" also ends with:

Daemon:
  daemon-version:  0.99.17
  on-battery:      no
  lid-is-closed:   no
  lid-is-present:  yes
  critical-action: HybridSleep

where we can see that "on-battery" is "no" even when the laptop is unplugged. This is already suspicious, even before powerdevil or dbus is involved.
Comment 13 Aldoo 2024-06-04 15:35:33 UTC
And indeed, it is upower who loops through AC devices to guess whether we are on battery. The code is here : https://gitlab.freedesktop.org/upower/upower/-/blob/master/src/up-daemon.c#L359

So, if I am right, the suggestion to make "on battery" status more robust by only checking the online status of "/org/freedesktop/UPower/devices/line_power_AC" instead of checking all devices should be made upstream (also why the other device wrongly returns "online" is another issue).
Comment 14 Oded Arbel 2024-08-29 11:21:37 UTC
After updating Neon unstable on noble with kernel 6.8.0 (and Plasma 6.1.80, KF 6.6.0, Qt 6.7.2) I cannot reproduce the issue anymore - without the charging cable the battery widget shows a non-charging battery and sleeping on idle on battery works fine.

If no one else can repro, I will close this as UPSTREAM.
Comment 15 Oded Arbel 2024-08-29 11:23:28 UTC
BTW `upower -d` now says here, plugged:

Daemon:
  daemon-version:  1.90.3
  on-battery:      no
  lid-is-closed:   no
  lid-is-present:  yes
  critical-action: PowerOff

unplugged:

Daemon:
  daemon-version:  1.90.3
  on-battery:      yes
  lid-is-closed:   no
  lid-is-present:  yes
  critical-action: PowerOff
Comment 16 EJ M 2024-09-18 16:59:51 UTC
I still have this exact issue (USB-C device says it's online for power, but it's not) intermittently on kernel version 6.8.0-45-generic (64-bit).
(Other versions, Plasma 5.27.11, KF 5.115.0, Qt 5.15.13.)

Is this something that would be fixed by updating to Plasma 6? My understanding from the latest comment is that Oded's upower output now is correct, but I'm not sure if that's a result of our differing versions.
Comment 17 Oded Arbel 2024-09-19 07:40:26 UTC
(In reply to EJ M from comment #16)
> I still have this exact issue (USB-C device says it's online for power, but
> it's not) intermittently on kernel version 6.8.0-45-generic (64-bit).

Can you please post the output of `upower -d` on your system - when it is experiencing the issue?