Date: Monday, October 28, 2013 @ 14:45:33 Author: jgc Revision: 197687
upgpkg: upower 0.9.23-2 fix FS#37465 by applying upstream patch from 0.9 branch Added: upower/trunk/linux-clamp-percentage-for-overfull-batteries.patch Modified: upower/trunk/PKGBUILD -----------------------------------------------------+ PKGBUILD | 9 +- linux-clamp-percentage-for-overfull-batteries.patch | 72 ++++++++++++++++++ 2 files changed, 78 insertions(+), 3 deletions(-) Modified: PKGBUILD =================================================================== --- PKGBUILD 2013-10-28 11:57:48 UTC (rev 197686) +++ PKGBUILD 2013-10-28 13:45:33 UTC (rev 197687) @@ -3,7 +3,7 @@ pkgname=upower pkgver=0.9.23 -pkgrel=1 +pkgrel=2 pkgdesc="Abstraction for enumerating power devices, listening to device events and querying history and statistics" arch=('i686' 'x86_64') url="http://upower.freedesktop.org" @@ -12,11 +12,14 @@ makedepends=('intltool' 'docbook-xsl' 'gobject-introspection' 'systemd') backup=('etc/UPower/UPower.conf') options=('!libtool') -source=($url/releases/$pkgname-$pkgver.tar.xz) -md5sums=('39cfd97bfaf7d30908f20cf937a57634') +source=($url/releases/$pkgname-$pkgver.tar.xz + linux-clamp-percentage-for-overfull-batteries.patch) +md5sums=('39cfd97bfaf7d30908f20cf937a57634' + 'cd8eeb40c2338d28df46e22529bece62') prepare() { cd $pkgname-$pkgver + patch -Np1 -i ../linux-clamp-percentage-for-overfull-batteries.patch } build() { Added: linux-clamp-percentage-for-overfull-batteries.patch =================================================================== --- linux-clamp-percentage-for-overfull-batteries.patch (rev 0) +++ linux-clamp-percentage-for-overfull-batteries.patch 2013-10-28 13:45:33 UTC (rev 197687) @@ -0,0 +1,72 @@ +From b8fe9902f3c6c50ca6a23e24fcea99582beebc65 Mon Sep 17 00:00:00 2001 +From: Martin Pitt <martinp...@gnome.org> +Date: Tue, 22 Oct 2013 08:02:51 +0000 +Subject: linux: Clamp percentage for overfull batteries + +Some batteries report energy > energy_full and a percentage ("capacity" +attribute) > 100%. Clamp these within 0 and 100% for both plausibility as well +as to avoid setting an out-of-range property which would then become 0%. + +https://launchpad.net/bugs/1240673 +--- +diff --git a/src/linux/integration-test b/src/linux/integration-test +index 8489bf3..4be1922 100755 +--- a/src/linux/integration-test ++++ b/src/linux/integration-test +@@ -442,6 +442,39 @@ class Tests(unittest.TestCase): + self.assertEqual(self.get_dbus_property('OnLowBattery'), False) + self.stop_daemon() + ++ def test_battery_overfull(self): ++ '''battery which reports a > 100% percentage for a full battery''' ++ ++ self.testbed.add_device('power_supply', 'BAT0', None, ++ ['type', 'Battery', ++ 'present', '1', ++ 'status', 'Full', ++ 'current_now', '1000', ++ 'charge_now', '11000000', ++ 'charge_full', '10000000', ++ 'charge_full_design', '11000000', ++ 'capacity', '110', ++ 'voltage_now', '12000000'], []) ++ ++ self.start_daemon() ++ devs = self.proxy.EnumerateDevices() ++ self.assertEqual(len(devs), 1) ++ bat0_up = devs[0] ++ ++ # should clamp percentage ++ self.assertEqual(self.get_dbus_dev_property(bat0_up, 'Percentage'), 100.0) ++ self.assertEqual(self.get_dbus_dev_property(bat0_up, 'IsPresent'), True) ++ self.assertEqual(self.get_dbus_dev_property(bat0_up, 'State'), ++ UP_DEVICE_STATE_FULLY_CHARGED) ++ self.assertEqual(self.get_dbus_dev_property(bat0_up, 'Energy'), 132.0) ++ # should adjust EnergyFull to reality, not what the battery claims ++ self.assertEqual(self.get_dbus_dev_property(bat0_up, 'EnergyFull'), 132.0) ++ self.assertEqual(self.get_dbus_dev_property(bat0_up, 'EnergyFullDesign'), 132.0) ++ self.assertEqual(self.get_dbus_dev_property(bat0_up, 'Voltage'), 12.0) ++ self.assertEqual(self.get_dbus_dev_property(bat0_up, 'PowerSupply'), True) ++ self.assertEqual(self.get_dbus_dev_property(bat0_up, 'Type'), 2) ++ self.stop_daemon() ++ + def test_battery_temperature(self): + '''battery which reports temperature''' + +diff --git a/src/linux/up-device-supply.c b/src/linux/up-device-supply.c +index 8020277..b953d65 100644 +--- a/src/linux/up-device-supply.c ++++ b/src/linux/up-device-supply.c +@@ -708,6 +708,10 @@ up_device_supply_refresh_battery (UpDeviceSupply *supply) + /* get a precise percentage */ + if (sysfs_file_exists (native_path, "capacity")) { + percentage = sysfs_get_double (native_path, "capacity"); ++ if (percentage < 0.0f) ++ percentage = 0.0f; ++ if (percentage > 100.0f) ++ percentage = 100.0f; + /* for devices which provide capacity, but not {energy,charge}_now */ + if (energy < 0.1f && energy_full > 0.0f) + energy = energy_full * percentage / 100; +-- +cgit v0.9.0.2-2-gbebe