diff -Nru upower-1.90.2/.gitlab-ci.yml upower-1.90.3/.gitlab-ci.yml --- upower-1.90.2/.gitlab-ci.yml 2023-07-06 08:52:27.000000000 +0000 +++ upower-1.90.3/.gitlab-ci.yml 2024-04-08 05:27:51.000000000 +0000 @@ -63,8 +63,7 @@ before_script: - git clone https://gitlab.gnome.org/GNOME/libgudev.git - cd libgudev - - dnf install -y 'dnf-command(builddep)' - - dnf builddep -y libgudev + - dnf install -y glibc-langpack-fr umockdev-devel - meson _build -Dprefix=/usr - ninja -C _build install - cd .. @@ -119,13 +118,12 @@ - cd .. - git clone https://github.com/martinpitt/umockdev.git - cd umockdev - - dnf install -y 'dnf-command(builddep)' - - dnf builddep -y umockdev + - dnf install -y chrpath libpcap-devel systemd-udev vala - meson _build -Dprefix=/usr - ninja -C _build install - cd .. - cd libgudev - - dnf builddep -y libgudev + - dnf install -y glibc-langpack-fr umockdev-devel - meson _build -Dprefix=/usr - ninja -C _build install - cd .. @@ -148,8 +146,7 @@ stage: test before_script: - cd libgudev - - dnf install -y 'dnf-command(builddep)' - - dnf builddep -y libgudev + - dnf install -y glibc-langpack-fr umockdev-devel - meson _build -Dprefix=/usr - ninja -C _build install - cd .. diff -Nru upower-1.90.2/README upower-1.90.3/README --- upower-1.90.2/README 2023-07-06 08:52:27.000000000 +0000 +++ upower-1.90.3/README 2024-04-08 05:27:51.000000000 +0000 @@ -4,7 +4,7 @@ Requirements: - glib-2.0 >= 2.34.0 + glib-2.0 >= 2.66.0 gio-2.0 >= 2.16.1 gudev-1.0 >= 235 (Linux) libimobiledevice-1.0 >= 0.9.7 (optional) diff -Nru upower-1.90.2/dbus/org.freedesktop.UPower.Device.xml upower-1.90.3/dbus/org.freedesktop.UPower.Device.xml --- upower-1.90.2/dbus/org.freedesktop.UPower.Device.xml 2023-07-06 08:52:27.000000000 +0000 +++ upower-1.90.3/dbus/org.freedesktop.UPower.Device.xml 2024-04-08 05:27:51.000000000 +0000 @@ -335,6 +335,66 @@ 8Phone + + 9Media Player + + + 10Tablet + + + 11Computer + + + 12Gaming Input + + + 13Pen + + + 14Touchpad + + + 15Modem + + + 16Network + + + 17Headset + + + 18Speakers + + + 19Headphones + + + 20Video + + + 21Other Audio + + + 22Remote Control + + + 23Printer + + + 24Scanner + + + 25Camera + + + 26Wearable + + + 27Toy + + + 28Bluetooth Genreic + If the value is set to "Battery", you will need to verify that the diff -Nru upower-1.90.2/dbus/org.freedesktop.UPower.xml upower-1.90.3/dbus/org.freedesktop.UPower.xml --- upower-1.90.2/dbus/org.freedesktop.UPower.xml 2023-07-06 08:52:27.000000000 +0000 +++ upower-1.90.3/dbus/org.freedesktop.UPower.xml 2024-04-08 05:27:51.000000000 +0000 @@ -82,7 +82,7 @@ EnergyFullAmount of energy (measured in Wh) in the power source when it's considered full. - EnergyRateAmount of energy being drained from the source, measured in W. If positive, the source is being discharged, if negative it's being charged. + EnergyRateDischarging/charging rate of the source, measured in Watt. TimeToEmptyNumber of seconds until the power source is considered empty. diff -Nru upower-1.90.2/debian/changelog upower-1.90.3/debian/changelog --- upower-1.90.2/debian/changelog 2024-04-05 08:06:12.000000000 +0000 +++ upower-1.90.3/debian/changelog 2024-04-08 07:42:45.000000000 +0000 @@ -1,20 +1,13 @@ -upower (1.90.2-8build3) noble; urgency=medium +upower (1.90.3-1) unstable; urgency=medium - * No-change rebuild against libplist-2.0-4 + * New upstream version 1.90.3 + * Drop patches, merged upstream + * Bump Build-Depends on meson to (>= 0.60.0) and libglib2.0-dev to (>= 2.66) + as per meson.build + * Switch Build-Depends on pkg-config to pkgconf + * Bump Standards-Version to 4.7.0 - -- Steve Langasek Fri, 05 Apr 2024 08:06:12 +0000 - -upower (1.90.2-8build2) noble; urgency=medium - - * No-change rebuild for CVE-2024-3094 - - -- Steve Langasek Sun, 31 Mar 2024 08:30:56 +0000 - -upower (1.90.2-8build1) noble; urgency=medium - - * No-change rebuild against libglib2.0-0t64 - - -- Steve Langasek Fri, 08 Mar 2024 07:53:57 +0000 + -- Michael Biebl Mon, 08 Apr 2024 09:42:45 +0200 upower (1.90.2-8) unstable; urgency=medium diff -Nru upower-1.90.2/debian/control upower-1.90.3/debian/control --- upower-1.90.2/debian/control 2024-03-08 07:53:57.000000000 +0000 +++ upower-1.90.3/debian/control 2024-04-08 07:42:45.000000000 +0000 @@ -1,28 +1,27 @@ Source: upower Section: admin Priority: optional -Maintainer: Ubuntu Developers -XSBC-Original-Maintainer: Utopia Maintenance Team +Maintainer: Utopia Maintenance Team Uploaders: Michael Biebl , Martin Pitt , Build-Depends: debhelper-compat (= 13), debhelper (>= 13.11.6), dh-sequence-gir, dh-exec, - meson (>= 0.56.0), + meson (>= 0.60.0), gobject-introspection, gtk-doc-tools, gettext (>= 0.19.8), libgirepository1.0-dev, - libglib2.0-dev (>= 2.58), + libglib2.0-dev (>= 2.66), libgudev-1.0-dev (>= 238) [linux-any], libimobiledevice-dev (>= 0.9.7) [linux-any], libkvm-dev [kfreebsd-any], - pkg-config, + pkgconf, systemd-dev [linux-any], xsltproc, Build-Depends-Indep: libglib2.0-doc , -Standards-Version: 4.6.2 +Standards-Version: 4.7.0 Rules-Requires-Root: no Vcs-Git: https://salsa.debian.org/utopia-team/upower.git Vcs-Browser: https://salsa.debian.org/utopia-team/upower/ diff -Nru upower-1.90.2/debian/patches/0001-linux-Adjust-test_bluetooth_le_device-for-dbusmock-0.patch upower-1.90.3/debian/patches/0001-linux-Adjust-test_bluetooth_le_device-for-dbusmock-0.patch --- upower-1.90.2/debian/patches/0001-linux-Adjust-test_bluetooth_le_device-for-dbusmock-0.patch 2023-12-29 05:57:05.000000000 +0000 +++ upower-1.90.3/debian/patches/0001-linux-Adjust-test_bluetooth_le_device-for-dbusmock-0.patch 1970-01-01 00:00:00.000000000 +0000 @@ -1,37 +0,0 @@ -From bd1e4698f480c6b94afa0536fc02e211ae5a87fb Mon Sep 17 00:00:00 2001 -From: Martin Pitt -Date: Thu, 28 Dec 2023 21:13:15 +0100 -Subject: [PATCH] linux: Adjust test_bluetooth_le_device for dbusmock 0.30.1 - -dbusmock 0.30.1 changed the BlueZ template to set the default "Class" -property to `MOCK_PHONE_CLASS` right away instead of in PairDevice() [1]. - -test_bluetooth_le_device() relied on the previous implicit default of a -"0" Class value. Set this explicitly to expect a "generic" device. This -makes the test work with old and current dbusmock versions. - -https://bugs.debian.org/1059467 - -[1] https://github.com/martinpitt/python-dbusmock/pull/192 ---- - src/linux/integration-test.py | 4 +++- - 1 file changed, 3 insertions(+), 1 deletion(-) - -diff --git a/src/linux/integration-test.py b/src/linux/integration-test.py -index e686125..4c071e8 100755 ---- a/src/linux/integration-test.py -+++ b/src/linux/integration-test.py -@@ -2162,7 +2162,9 @@ class Tests(dbusmock.DBusTestCase): - - alias = 'Satechi M1 Mouse' - battery_level = 99 -- device_properties = None -+ device_properties = { -+ 'Class': dbus.UInt32(0, variant_level=1) -+ } - - devs = self._add_bluez_battery_device(alias, device_properties, battery_level) - self.assertEqual(len(devs), 1) --- -2.43.0 - diff -Nru upower-1.90.2/debian/patches/build-make-udevrulesdir-and-udevhwdbdir-as-Linux-onl.patch upower-1.90.3/debian/patches/build-make-udevrulesdir-and-udevhwdbdir-as-Linux-onl.patch --- upower-1.90.2/debian/patches/build-make-udevrulesdir-and-udevhwdbdir-as-Linux-onl.patch 2023-12-29 05:56:31.000000000 +0000 +++ upower-1.90.3/debian/patches/build-make-udevrulesdir-and-udevhwdbdir-as-Linux-onl.patch 1970-01-01 00:00:00.000000000 +0000 @@ -1,84 +0,0 @@ -From 029651a96dfc8e8e1dc6eca79bd3bf23d3aeb5ce Mon Sep 17 00:00:00 2001 -From: Pino Toscano -Date: Thu, 6 Jul 2023 07:17:01 +0200 -Subject: [PATCH] build: make 'udevrulesdir' and 'udevhwdbdir' as Linux-only - -udev is available only on Linux, so limit their usage when the backend -is 'linux'. - -This fixes the build when the backend is different than 'linux', i.e. -typically on non-Linux OSes. ---- - meson.build | 22 +++++++++++----------- - rules/meson.build | 18 ++++++++++-------- - 2 files changed, 21 insertions(+), 19 deletions(-) - -diff --git a/meson.build b/meson.build -index fed3f85..6e398a2 100644 ---- a/meson.build -+++ b/meson.build -@@ -81,23 +81,23 @@ if os_backend == 'linux' - endif - cdata.set10('HAVE_IDEVICE', true) - endif --endif - --historydir = get_option('historydir') --if historydir == '' -- historydir = get_option('prefix') / get_option('localstatedir') / 'lib' / 'upower' --endif -- --udevrulesdir = get_option('udevrulesdir') --if udevrulesdir == 'auto' -+ udevrulesdir = get_option('udevrulesdir') -+ if udevrulesdir == 'auto' - udev_dep = dependency('udev', required: true) - udevrulesdir = udev_dep.get_variable(pkgconfig: 'udev_dir') / 'rules.d' --endif -+ endif - --udevhwdbdir = get_option('udevhwdbdir') --if udevhwdbdir == 'auto' -+ udevhwdbdir = get_option('udevhwdbdir') -+ if udevhwdbdir == 'auto' - udev_dep = dependency('udev', required: true) - udevhwdbdir = udev_dep.get_variable(pkgconfig: 'udev_dir') / 'hwdb.d' -+ endif -+endif -+ -+historydir = get_option('historydir') -+if historydir == '' -+ historydir = get_option('prefix') / get_option('localstatedir') / 'lib' / 'upower' - endif - - dbusdir = get_option('datadir') / 'dbus-1' -diff --git a/rules/meson.build b/rules/meson.build -index 63c344c..b780bb2 100644 ---- a/rules/meson.build -+++ b/rules/meson.build -@@ -7,12 +7,14 @@ hwdb = [ - '95-upower-hid.hwdb', - ] - --install_data( -- rules, -- install_dir: udevrulesdir, --) -+if os_backend == 'linux' -+ install_data( -+ rules, -+ install_dir: udevrulesdir, -+ ) - --install_data( -- hwdb, -- install_dir: udevhwdbdir, --) -+ install_data( -+ hwdb, -+ install_dir: udevhwdbdir, -+ ) -+endif --- -2.40.1 - diff -Nru upower-1.90.2/debian/patches/series upower-1.90.3/debian/patches/series --- upower-1.90.2/debian/patches/series 2023-12-29 05:57:27.000000000 +0000 +++ upower-1.90.3/debian/patches/series 1970-01-01 00:00:00.000000000 +0000 @@ -1,2 +0,0 @@ -0001-linux-Adjust-test_bluetooth_le_device-for-dbusmock-0.patch -build-make-udevrulesdir-and-udevhwdbdir-as-Linux-onl.patch diff -Nru upower-1.90.2/libupower-glib/up-history-item.c upower-1.90.3/libupower-glib/up-history-item.c --- upower-1.90.2/libupower-glib/up-history-item.c 2023-07-06 08:52:27.000000000 +0000 +++ upower-1.90.3/libupower-glib/up-history-item.c 2024-04-08 05:27:51.000000000 +0000 @@ -116,12 +116,12 @@ void up_history_item_set_time_to_present (UpHistoryItem *history_item) { - GTimeVal timeval; + guint64 time_now; g_return_if_fail (UP_IS_HISTORY_ITEM (history_item)); - g_get_current_time (&timeval); - history_item->priv->time = timeval.tv_sec; + time_now = g_get_real_time (); + history_item->priv->time = time_now / 1000000; g_object_notify (G_OBJECT(history_item), "time"); } diff -Nru upower-1.90.2/meson.build upower-1.90.3/meson.build --- upower-1.90.2/meson.build 2023-07-06 08:52:27.000000000 +0000 +++ upower-1.90.3/meson.build 2024-04-08 05:27:51.000000000 +0000 @@ -1,12 +1,12 @@ project('upower', 'c', - version: '1.90.2', + version: '1.90.3', license: 'GPLv2+', default_options: [ 'buildtype=debugoptimized', 'warning_level=1', 'c_std=gnu99', ], - meson_version: '>= 0.56.0') + meson_version: '>= 0.60.0') soversion = 3 current = 1 @@ -30,7 +30,7 @@ cdata.set_quoted('VERSION', meson.project_version()) cdata.set_quoted('PACKAGE_SYSCONF_DIR', get_option('sysconfdir')) -glib_min_version = '2.58' +glib_min_version = '2.66' glib_version_def = 'GLIB_VERSION_@0@_@1@'.format( glib_min_version.split('.')[0], glib_min_version.split('.')[1]) @@ -81,23 +81,23 @@ endif cdata.set10('HAVE_IDEVICE', true) endif -endif -historydir = get_option('historydir') -if historydir == '' - historydir = get_option('prefix') / get_option('localstatedir') / 'lib' / 'upower' -endif - -udevrulesdir = get_option('udevrulesdir') -if udevrulesdir == 'auto' + udevrulesdir = get_option('udevrulesdir') + if udevrulesdir == 'auto' udev_dep = dependency('udev', required: true) udevrulesdir = udev_dep.get_variable(pkgconfig: 'udev_dir') / 'rules.d' -endif + endif -udevhwdbdir = get_option('udevhwdbdir') -if udevhwdbdir == 'auto' + udevhwdbdir = get_option('udevhwdbdir') + if udevhwdbdir == 'auto' udev_dep = dependency('udev', required: true) udevhwdbdir = udev_dep.get_variable(pkgconfig: 'udev_dir') / 'hwdb.d' + endif +endif + +historydir = get_option('historydir') +if historydir == '' + historydir = get_option('prefix') / get_option('localstatedir') / 'lib' / 'upower' endif dbusdir = get_option('datadir') / 'dbus-1' diff -Nru upower-1.90.2/rules/95-upower-hid.hwdb upower-1.90.3/rules/95-upower-hid.hwdb --- upower-1.90.2/rules/95-upower-hid.hwdb 2023-07-06 08:52:27.000000000 +0000 +++ upower-1.90.3/rules/95-upower-hid.hwdb 2024-04-08 05:27:51.000000000 +0000 @@ -38,6 +38,7 @@ # ST Microelectronics usb:v0483pA113* +usb:v0483pA430* UPOWER_BATTERY_TYPE=ups UPOWER_VENDOR=ST Microelectronics @@ -152,7 +153,9 @@ UPOWER_VENDOR=PowerCOM # Liebert +usb:v10AFp0000* usb:v10AFp0001* +usb:v10AFp0002* usb:v10AFp0004* usb:v10AFp0008* UPOWER_BATTERY_TYPE=ups diff -Nru upower-1.90.2/rules/meson.build upower-1.90.3/rules/meson.build --- upower-1.90.2/rules/meson.build 2023-07-06 08:52:27.000000000 +0000 +++ upower-1.90.3/rules/meson.build 2024-04-08 05:27:51.000000000 +0000 @@ -7,12 +7,14 @@ '95-upower-hid.hwdb', ] -install_data( - rules, - install_dir: udevrulesdir, -) +if os_backend == 'linux' + install_data( + rules, + install_dir: udevrulesdir, + ) -install_data( - hwdb, - install_dir: udevhwdbdir, -) + install_data( + hwdb, + install_dir: udevhwdbdir, + ) +endif diff -Nru upower-1.90.2/src/linux/integration-test.py upower-1.90.3/src/linux/integration-test.py --- upower-1.90.2/src/linux/integration-test.py 2023-07-06 08:52:27.000000000 +0000 +++ upower-1.90.3/src/linux/integration-test.py 2024-04-08 05:27:51.000000000 +0000 @@ -200,7 +200,7 @@ env['SYSTEMD_DEVICE_VERIFY_SYSFS'] = '0' self.daemon_log = OutputChecker() - if os.getenv('VALGRIND') != None: + if os.getenv('VALGRIND') is not None: daemon_path = ['valgrind', self.daemon_path, '-v', '-r'] else: daemon_path = [self.daemon_path, '-v', '-r'] @@ -610,7 +610,7 @@ energy_now = 48000000 ac = self.testbed.add_device('power_supply', 'AC', None, ['type', 'Mains', 'online', '0'], []) - bat0 = self.testbed.add_device('power_supply', f'BAT0', None, + bat0 = self.testbed.add_device('power_supply', 'BAT0', None, ['type', 'Battery', 'present', '1', 'status', 'unknown', @@ -1296,7 +1296,7 @@ self.start_daemon() - self.daemon_log.check_line(f"using id: Fake_Battery-80-001", timeout=1) + self.daemon_log.check_line("using id: Fake_Battery-80-001", timeout=1) # Change the serial of the battery self.testbed.set_attribute(bat0, 'energy_full_design', '90000000') @@ -1304,19 +1304,19 @@ self.testbed.uevent(bat0, 'change') # This saves the old history, and then opens a new one - self.daemon_log.check_line_re(f"saved .*/history-time-empty-Fake_Battery-80-001.dat", timeout=1) - self.daemon_log.check_line(f"using id: Fake_Battery-90-002", timeout=1) + self.daemon_log.check_line_re("saved .*/history-time-empty-Fake_Battery-80-001.dat", timeout=1) + self.daemon_log.check_line("using id: Fake_Battery-90-002", timeout=1) # Only happens once - self.daemon_log.check_no_line(f"using id:", wait=1.0) + self.daemon_log.check_no_line("using id:", wait=1.0) # Remove the battery self.testbed.set_attribute(bat0, 'present', '0') self.testbed.uevent(bat0, 'change') # This saves the old history, and does *not* open a new one - self.daemon_log.check_line_re(f"saved .*/history-time-empty-Fake_Battery-90-002.dat", timeout=1) - self.daemon_log.check_no_line(f"using id:", wait=1.0) + self.daemon_log.check_line_re("saved .*/history-time-empty-Fake_Battery-90-002.dat", timeout=1) + self.daemon_log.check_no_line("using id:", wait=1.0) self.stop_daemon() @@ -2162,7 +2162,9 @@ alias = 'Satechi M1 Mouse' battery_level = 99 - device_properties = None + device_properties = { + 'Class': dbus.UInt32(0, variant_level=1) + } devs = self._add_bluez_battery_device(alias, device_properties, battery_level) self.assertEqual(len(devs), 1) @@ -2646,6 +2648,60 @@ self.stop_daemon() + def test_ignore_unknown_power_supply_type(self): + ''' + Ignore devices with unknown power supply type and doesn't look like a charger. + ''' + + # Sample data taken from Fairphone 4, running Linux kernel 4.19 w/ + # vendor patches (abbreviated). + + # Actual battery. + battery = self.testbed.add_device('power_supply', 'battery', None, + ['capacity', '77', + 'charging_enabled', '1', + 'health', 'Good', + 'present', '1', + 'status', 'Charging', + 'technology', 'Li-ion', + 'type', 'Battery', + 'voltage_max', '4400000', + 'voltage_now', '4268584'], []) + + # BMS (should be ignored) + bms = self.testbed.add_device('power_supply', 'bms', None, + ['type', 'BMS', + 'capacity', '77', + 'capacity_raw', '7685', + 'current_avg', '-1677247', + 'current_now', '-1543885', + 'power_avg', '29886557', + 'power_now', '52842898', + 'real_capacity', '77', + 'temp', '300', + 'voltage_avg', '4322887', + 'voltage_max', '4400000', + 'voltage_min', '3400000', + 'voltage_now', '4298363', + 'voltage_ocv', '4102200'], []) + + # "Charge pump master" (not sure what it is either, should be ignored) + charge_pump_master = self.testbed.add_device( + 'power_supply', 'charge_pump_master', None, + ['chip_version', '3', + 'min_icl', '1000000', + 'model_name', 'SMB1398_V2', + 'parallel_mode', '1', + 'parallel_output_mode', '2', + 'type', 'Nothing attached'], []) + + self.start_daemon(warns=True) + devs = self.proxy.EnumerateDevices() + # Only the battery should be listed, not the BMS or charge pump master. + self.assertEqual(len(devs), 1) + + self.stop_daemon() + # # libupower-glib tests (through introspection) # diff -Nru upower-1.90.2/src/linux/up-device-supply-battery.c upower-1.90.3/src/linux/up-device-supply-battery.c --- upower-1.90.2/src/linux/up-device-supply-battery.c 2023-07-06 08:52:27.000000000 +0000 +++ upower-1.90.3/src/linux/up-device-supply-battery.c 2024-04-08 05:27:51.000000000 +0000 @@ -47,10 +47,10 @@ struct _UpDeviceSupplyBattery { + UpDeviceBattery parent; gboolean has_coldplug_values; gboolean coldplug_units; gdouble *energy_old; - GTimeVal *energy_old_timespec; guint energy_old_first; gdouble rate_old; gboolean shown_invalid_voltage_warning; @@ -265,15 +265,10 @@ if (scope != NULL && g_ascii_strcasecmp (scope, "system") != 0) g_warning ("Assuming system scope even though scope is %s", scope); - /* type should be a battery, but also accept unknown if "online" does not exist */ + /* type must be a battery. */ type = g_udev_device_get_sysfs_attr (native, "type"); - if (!type || g_ascii_strcasecmp (type, "battery") != 0) { - if (g_udev_device_has_sysfs_attr (native, "online")) - return FALSE; - - /* this is a good guess as UPS and CSR are not in the kernel */ - g_warning ("Assuming battery as sysfs attribute 'type' is %s", type); - } + if (!type || g_ascii_strcasecmp (type, "battery") != 0) + return FALSE; return TRUE; } diff -Nru upower-1.90.2/src/linux/up-device-supply.c upower-1.90.3/src/linux/up-device-supply.c --- upower-1.90.2/src/linux/up-device-supply.c 2023-07-06 08:52:27.000000000 +0000 +++ upower-1.90.3/src/linux/up-device-supply.c 2024-04-08 05:27:51.000000000 +0000 @@ -594,13 +594,23 @@ /* try to detect using the device type */ type = up_device_supply_guess_type (native, native_path); - /* if reading the device type did not work, use the previous method */ + /* if reading the device type did not work, use heuristic */ if (type == UP_DEVICE_KIND_UNKNOWN) { if (g_udev_device_has_sysfs_attr_uncached (native, "online")) { + g_debug ("'online' attribute was found. " + "Assume it is a line power supply."); type = UP_DEVICE_KIND_LINE_POWER; } else { - /* this is a good guess as UPS and CSR are not in the kernel */ - type = UP_DEVICE_KIND_BATTERY; + /* + * This might be a battery or a UPS, but it might also + * be something else that we really don't know how to + * handle (e.g. BMS, exposed by Android-centric vendor + * kernels in parallel to actual battery). + * + * As such, we have no choice but to assume that we + * can't handle this device, and ignore it. + */ + return FALSE; } } diff -Nru upower-1.90.2/src/meson.build upower-1.90.3/src/meson.build --- upower-1.90.2/src/meson.build 2023-07-06 08:52:27.000000000 +0000 +++ upower-1.90.3/src/meson.build 2024-04-08 05:27:51.000000000 +0000 @@ -81,7 +81,7 @@ # Data/Config files ############# -install_subdir('does-not-exist', install_dir: historydir, strip_directory : true) +install_emptydir(historydir) cdata = configuration_data() cdata.set('libexecdir', get_option('prefix') / get_option('libexecdir')) diff -Nru upower-1.90.2/src/up-device.c upower-1.90.3/src/up-device.c --- upower-1.90.2/src/up-device.c 2023-07-06 08:52:27.000000000 +0000 +++ upower-1.90.3/src/up-device.c 2024-04-08 05:27:51.000000000 +0000 @@ -183,6 +183,19 @@ up_history_set_id (priv->history, id); } +static gboolean +up_device_history_filter (UpDevice *device, UpHistory *history) +{ + UpExportedDevice *skeleton = UP_EXPORTED_DEVICE (device); + + if (up_exported_device_get_state (skeleton) == UP_DEVICE_STATE_UNKNOWN) { + g_debug ("device %s has unknown state, not saving history", + up_exported_device_get_native_path (skeleton)); + return FALSE; + } + return TRUE; +} + static void update_history (UpDevice *device) { @@ -191,6 +204,9 @@ ensure_history (device); + if (!up_device_history_filter (device, priv->history)) + return; + /* save new history */ up_history_set_state (priv->history, up_exported_device_get_state (skeleton)); up_history_set_charge_data (priv->history, up_exported_device_get_percentage (skeleton)); @@ -214,12 +230,16 @@ if (g_strcmp0 (pspec->name, "type") == 0 || g_strcmp0 (pspec->name, "is-present") == 0) { update_icon_name (device); - /* Clearing the history object will force lazily loading. */ - g_clear_object (&priv->history); + /* Clearing the history object for lazily loading when device id was changed. */ + if (priv->history != NULL && + !up_history_is_device_id_equal (priv->history, up_device_get_id(device))) + g_clear_object (&priv->history); } else if (g_strcmp0 (pspec->name, "vendor") == 0 || g_strcmp0 (pspec->name, "model") == 0 || g_strcmp0 (pspec->name, "serial") == 0) { - g_clear_object (&priv->history); + if (priv->history != NULL && + !up_history_is_device_id_equal (priv->history, up_device_get_id(device))) + g_clear_object (&priv->history); } else if (g_strcmp0 (pspec->name, "power-supply") == 0 || g_strcmp0 (pspec->name, "time-to-empty") == 0) { update_warning_level (device); diff -Nru upower-1.90.2/src/up-history.c upower-1.90.3/src/up-history.c --- upower-1.90.2/src/up-history.c 2023-07-06 08:52:27.000000000 +0000 +++ upower-1.90.3/src/up-history.c 2024-04-08 05:27:51.000000000 +0000 @@ -203,7 +203,7 @@ guint i; UpHistoryItem *item; GPtrArray *array_new; - GTimeVal timeval; + gint64 time_now; /* no data */ if (array->len == 0) @@ -217,14 +217,14 @@ /* new data */ array_new = g_ptr_array_new (); - g_get_current_time (&timeval); + time_now = g_get_real_time (); g_debug ("limiting data to last %i seconds", timespan); /* treat the timespan like a range, and search backwards */ timespan *= 0.95f; for (i=array->len-1; i>0; i--) { item = (UpHistoryItem *) g_ptr_array_index (array, i); - if (timeval.tv_sec - up_history_item_get_time (item) < timespan) + if ((time_now / 1000000) - up_history_item_get_time (item) < timespan) g_ptr_array_add (array_new, g_object_ref (item)); } out: @@ -429,12 +429,12 @@ GString *string; gboolean ret = TRUE; GError *error = NULL; - GTimeVal time_now; + gint64 time_now; guint time_item; guint cull_count = 0; /* get current time */ - g_get_current_time (&time_now); + time_now = g_get_real_time (); /* generate data */ string = g_string_new (""); @@ -443,7 +443,7 @@ /* only save entries for the last 24 hours */ time_item = up_history_item_get_time (item); - if (time_now.tv_sec - time_item > history->priv->max_data_age) { + if ((time_now / 1000000) - time_item > history->priv->max_data_age) { cull_count++; continue; } @@ -871,6 +871,20 @@ } /** + * up_history_is_device_id_equal: + **/ +gboolean +up_history_is_device_id_equal(UpHistory *history, const gchar *id) +{ + g_return_val_if_fail (UP_IS_HISTORY (history), FALSE); + + if (!g_strcmp0 (history->priv->id, id)) + return TRUE; + + return FALSE; +} + +/** * up_history_class_init: * @klass: The UpHistoryClass **/ diff -Nru upower-1.90.2/src/up-history.h upower-1.90.3/src/up-history.h --- upower-1.90.2/src/up-history.h 2023-07-06 08:52:27.000000000 +0000 +++ upower-1.90.3/src/up-history.h 2024-04-08 05:27:51.000000000 +0000 @@ -60,6 +60,7 @@ GType up_history_get_type (void); +gboolean up_history_is_device_id_equal (UpHistory *history, const gchar *id); UpHistory *up_history_new (void); GPtrArray *up_history_get_data (UpHistory *history,