Comment 4 for bug 1767560

Revision history for this message
Matias N. Goldberg (dark-sylinc) wrote :

This bug affects Xubuntu 18.04 but not 17.xx or earlier

It can be easily be reproduced on any desktop machine using https://github.com/hoelzro/linux-fake-battery-module (patch to compile on Xubuntu 18.04 is at the end)

I can see that:

In the range [60; 100] the full battery icon is displayed
In the range [30; 59] an icon that indicates around 60% battery level is displayed.
In the range [10; 30] an icon that indicates around 30-40% battery level is displayed
In the range [0; 9] an orange bar is displayed

Judging from the themes in 17.xx at /usr/share/icons/elementary-xfce/status/48 there's a lot more battery icon variety than what is being displayed (there's icons for 6 ranges!).

As for the fake module, apply this patch:

diff --git a/fake_battery.c b/fake_battery.c
index 2e3c04c..48da386 100644
--- a/fake_battery.c
+++ b/fake_battery.c
@@ -23,6 +23,7 @@
 #include <linux/power_supply.h>

 #include <asm/uaccess.h>
+#include <linux/uaccess.h>

 static int
 fake_battery_get_property1(struct power_supply *psy,
@@ -63,7 +64,6 @@ static int ac_status = 1;

 static char *fake_ac_supplies[] = {
     "BAT0",
- "BAT1",
 };

 static enum power_supply_property fake_battery_properties[] = {
@@ -99,14 +99,6 @@ static struct power_supply_desc descriptions[] = {
         .get_property = fake_battery_get_property1,
     },

- {
- .name = "BAT1",
- .type = POWER_SUPPLY_TYPE_BATTERY,
- .properties = fake_battery_properties,
- .num_properties = ARRAY_SIZE(fake_battery_properties),
- .get_property = fake_battery_get_property2,
- },
-
     {
         .name = "AC0",
         .type = POWER_SUPPLY_TYPE_MAINS,
@@ -220,7 +212,7 @@ handle_charge_changes(int ac_status, struct battery_status *battery)
 static ssize_t
 control_device_write(struct file *file, const char *buffer, size_t count, loff_t *ppos)
 {
- char kbuffer[1024]; /* limited by kernel frame size, 1K should be enough */
+ char kbuffer[512]; /* limited by kernel frame size, 1K should be enough */
     char *buffer_cursor;
     char *newline;
     size_t bytes_left = count;
@@ -232,8 +224,8 @@ control_device_write(struct file *file, const char *buffer, size_t count, loff_t
         return -EINVAL;
     }

- if(count > 1024) {
- printk(KERN_ERR "Too much data provided to /dev/fake_battery (limit 1024 bytes)\n");
+ if(count > 512) {
+ printk(KERN_ERR "Too much data provided to /dev/fake_battery (limit 512 bytes)\n");
         return -EINVAL;
     }

@@ -264,7 +256,7 @@ control_device_write(struct file *file, const char *buffer, size_t count, loff_t

     power_supply_changed(supplies[0]);
     power_supply_changed(supplies[1]);
- power_supply_changed(supplies[2]);
+ //power_supply_changed(supplies[2]);

     return count;
 }

This patch fixes a compilation error, a gcc warning, and disables the 2nd fake battery (by default the git repo creates 2 fake batteries)
And then run:

make
sudo insmod ./fake_battery.ko
echo 'charging = 0' | sudo tee /dev/fake_battery
echo 'capacity0 = 50' | sudo tee /dev/fake_battery