6

I have recently installed Ubuntu 20.04.2 on my new laptop. Everything is working fine but there is problem with indicator on top menu. Whenever I plugin my laptop the sound alert for charging is heard on time but the indicator on menu bar takes a lot of time to show that the laptop is charging. And when unplugged the problem is indicator changes very late approx 1 -2 minutes and sound alert is heard on same time when icon changes. Can anyone tell me the solution. I tried reinstalling gnome-power-manager

. It didn't work.

My Laptop is Huawei Matebook 14 AMD ryzen 7

Bibek
  • 111
  • Can you update your question to include the brand and model of computer you’re using? Some notebooks are different from others … –  Feb 19 '21 at 06:25
  • @Matigo I have updated my question. It was previously working correctly. this problem appeared recently someday after installation. – Bibek Feb 19 '21 at 06:27
  • Check the output of dmesg for any possible hint at what is delaying the expected actions. – sancho.s ReinstateMonicaCellio Feb 22 '21 at 10:12
  • I am getting something like " systemd-logind: hibernation is restricted; see man kernel_lockdown.7" on my last dmesg output when battery icon changes to charging " – Bibek Feb 22 '21 at 11:01

2 Answers2

3

This is an issue that I've had on Acer, Apple, and Asus notebooks over the years. I guess this isn't limited to manufacturers that start with the letter "A".

The problem is with the upower service not polling the battery often enough. If you've ever tried to compare your battery status with multiple tools, you will have likely seen discrepancies in the amount of reported power remaining and/or charging status. Unfortunately this isn't something that can be fixed with a quick trip to "Settings" or "dconf Editor", but you can work around this with a script that forces upower to refresh.

First, let's get your battery name. In Terminal, run this command:

upower -e

This should give you something like this:

/org/freedesktop/UPower/devices/line_power_AC
/org/freedesktop/UPower/devices/battery_BAT0
/org/freedesktop/UPower/devices/DisplayDevice

With this, we can see that my battery is aptly named battery_BAT0. I can manually force upower to update its status information with this busctl command:

busctl call --system org.freedesktop.UPower /org/freedesktop/UPower/devices/battery_BAT0 org.freedesktop.UPower.Device Refresh

Note: There is no output when running this command in Terminal, though your status icons might update if you have recently (dis)connected power.

To have this run at regular intervals to keep the battery icon and play a system notification sound within a semi-reasonable amount of time, wrap the busctl call from earlier into a shell script:

#!/bin/bash
while sleep 15; do
   busctl call --system org.freedesktop.UPower /org/freedesktop/UPower/devices/battery_BAT0 org.freedesktop.UPower.Device Refresh
done

Be sure to replace battery_BAT0 with your actual battery name, and change 15 to an interval that you would be satisfied with. I've been running this for a couple of years now and have not seen any performance impact from the script on a 4th-gen Intel Core i5, so your Ryzen 7 should have no qualms with it, either.

To have this run in the background from startup, open "Startup Applications", click "Add", and select the script. Do not forget to make the script executable first, though:

chmod +x poke-upower.sh

Note: You'll probably want a better file name.

This is more of a hack than a complete solution, but it does work for numerous releases of Ubuntu Desktop. I have not yet found the root cause of this issue, though, and none of the Lenovo or Dell devices that I've used have ever shown this behaviour.

Hope this helps

  • The script works but it doesn't work on startup. What might be problem with the startup configuration? – Bibek Feb 23 '21 at 04:59
  • Can you confirm the permissions on the upower script? When you created the startup config, there would have been a file written to your ~/.config/autostart directory. Does the Exec= line match the location of the script? It needs to be the full path. –  Mar 01 '21 at 02:24
  • Thank you so much for this. – user2180794 May 12 '22 at 11:50
3

I know this is an old question, however the problem is still there, at least partially... at least if you think about it as a problem...

There is an issue (actually it's a feature) with the battery icon in gnome: It shows battery status, not the AC adapter status. Battery controller decides if the battery needs to be charged. This means if the battery have high enough charge level (usually around >= 95%) it may decide to keep it that way instead of charging it to 100%. However, there still will be a sound when you plug the AC adapter. This is not an issue, this is by design. Discharge the battery to around 90% and plug the AC in - the icon will change to "charging". It is also easy to check with command line: run cat /sys/class/power_supply/AC0/online in the terminal - it shows 0 or 1 for the AC adapter status; cat /sys/class/power_supply/BAT0/status to see the battery charging status - it shows Charging or Not charging. Latter is what the icon shows in gnome shell.

Another issue is with the polling battery status by upower, well described by @user1091774. I used to have the issue on Acer and Asus laptops, but not any more. I guess it was fixed.

clover
  • 530