1 |
ssuominen 14/03/26 08:51:04 |
2 |
|
3 |
Added: |
4 |
upower-0.9.23-clamp_percentage_for_overfull_batt.patch |
5 |
Log: |
6 |
Apply upstream patch for clamping percentage for overfull batteries wrt #504574 by Krzysztof Nowicki and Till Schäfer |
7 |
|
8 |
(Portage version: 2.2.8-r1/cvs/Linux x86_64, signed Manifest commit with key 4868F14D) |
9 |
|
10 |
Revision Changes Path |
11 |
1.1 sys-power/upower/files/upower-0.9.23-clamp_percentage_for_overfull_batt.patch |
12 |
|
13 |
file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/sys-power/upower/files/upower-0.9.23-clamp_percentage_for_overfull_batt.patch?rev=1.1&view=markup |
14 |
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/sys-power/upower/files/upower-0.9.23-clamp_percentage_for_overfull_batt.patch?rev=1.1&content-type=text/plain |
15 |
|
16 |
Index: upower-0.9.23-clamp_percentage_for_overfull_batt.patch |
17 |
=================================================================== |
18 |
From b8fe9902f3c6c50ca6a23e24fcea99582beebc65 Mon Sep 17 00:00:00 2001 |
19 |
From: Martin Pitt <martinpitt@×××××.org> |
20 |
Date: Tue, 22 Oct 2013 08:02:51 +0000 |
21 |
Subject: linux: Clamp percentage for overfull batteries |
22 |
|
23 |
Some batteries report energy > energy_full and a percentage ("capacity" |
24 |
attribute) > 100%. Clamp these within 0 and 100% for both plausibility as well |
25 |
as to avoid setting an out-of-range property which would then become 0%. |
26 |
|
27 |
https://launchpad.net/bugs/1240673 |
28 |
--- |
29 |
diff --git a/src/linux/integration-test b/src/linux/integration-test |
30 |
index 8489bf3..4be1922 100755 |
31 |
--- a/src/linux/integration-test |
32 |
+++ b/src/linux/integration-test |
33 |
@@ -442,6 +442,39 @@ class Tests(unittest.TestCase): |
34 |
self.assertEqual(self.get_dbus_property('OnLowBattery'), False) |
35 |
self.stop_daemon() |
36 |
|
37 |
+ def test_battery_overfull(self): |
38 |
+ '''battery which reports a > 100% percentage for a full battery''' |
39 |
+ |
40 |
+ self.testbed.add_device('power_supply', 'BAT0', None, |
41 |
+ ['type', 'Battery', |
42 |
+ 'present', '1', |
43 |
+ 'status', 'Full', |
44 |
+ 'current_now', '1000', |
45 |
+ 'charge_now', '11000000', |
46 |
+ 'charge_full', '10000000', |
47 |
+ 'charge_full_design', '11000000', |
48 |
+ 'capacity', '110', |
49 |
+ 'voltage_now', '12000000'], []) |
50 |
+ |
51 |
+ self.start_daemon() |
52 |
+ devs = self.proxy.EnumerateDevices() |
53 |
+ self.assertEqual(len(devs), 1) |
54 |
+ bat0_up = devs[0] |
55 |
+ |
56 |
+ # should clamp percentage |
57 |
+ self.assertEqual(self.get_dbus_dev_property(bat0_up, 'Percentage'), 100.0) |
58 |
+ self.assertEqual(self.get_dbus_dev_property(bat0_up, 'IsPresent'), True) |
59 |
+ self.assertEqual(self.get_dbus_dev_property(bat0_up, 'State'), |
60 |
+ UP_DEVICE_STATE_FULLY_CHARGED) |
61 |
+ self.assertEqual(self.get_dbus_dev_property(bat0_up, 'Energy'), 132.0) |
62 |
+ # should adjust EnergyFull to reality, not what the battery claims |
63 |
+ self.assertEqual(self.get_dbus_dev_property(bat0_up, 'EnergyFull'), 132.0) |
64 |
+ self.assertEqual(self.get_dbus_dev_property(bat0_up, 'EnergyFullDesign'), 132.0) |
65 |
+ self.assertEqual(self.get_dbus_dev_property(bat0_up, 'Voltage'), 12.0) |
66 |
+ self.assertEqual(self.get_dbus_dev_property(bat0_up, 'PowerSupply'), True) |
67 |
+ self.assertEqual(self.get_dbus_dev_property(bat0_up, 'Type'), 2) |
68 |
+ self.stop_daemon() |
69 |
+ |
70 |
def test_battery_temperature(self): |
71 |
'''battery which reports temperature''' |
72 |
|
73 |
diff --git a/src/linux/up-device-supply.c b/src/linux/up-device-supply.c |
74 |
index 8020277..b953d65 100644 |
75 |
--- a/src/linux/up-device-supply.c |
76 |
+++ b/src/linux/up-device-supply.c |
77 |
@@ -708,6 +708,10 @@ up_device_supply_refresh_battery (UpDeviceSupply *supply) |
78 |
/* get a precise percentage */ |
79 |
if (sysfs_file_exists (native_path, "capacity")) { |
80 |
percentage = sysfs_get_double (native_path, "capacity"); |
81 |
+ if (percentage < 0.0f) |
82 |
+ percentage = 0.0f; |
83 |
+ if (percentage > 100.0f) |
84 |
+ percentage = 100.0f; |
85 |
/* for devices which provide capacity, but not {energy,charge}_now */ |
86 |
if (energy < 0.1f && energy_full > 0.0f) |
87 |
energy = energy_full * percentage / 100; |
88 |
-- |
89 |
cgit v0.9.0.2-2-gbebe |