Magellan Linux

Contents of /trunk/hal/patches/hal-0.5.10-fix-normalised_rate-if-dis-charging-state-is-unknow.patch

Parent Directory Parent Directory | Revision Log Revision Log


Revision 597 - (show annotations) (download)
Mon May 19 19:05:19 2008 UTC (15 years, 11 months ago) by niro
File size: 3334 byte(s)
-gentoo patches

1 From ea62ec238eed49bf0565559a2a22a49aff46af44 Mon Sep 17 00:00:00 2001
2 From: Danny Kukawka <danny.kukawka@web.de>
3 Date: Thu, 6 Dec 2007 21:23:05 +0100
4 Subject: [PATCH] fix normalised_rate if dis-/charging state is unknown
5
6 This fixes problems with machines which report not the correct charging
7 state in some cases (e.g. battery report 'charged' if on battery). With this
8 patch normalised_rate get set only to 0 if:
9
10 * the battery is not a primary (ACPI) battery
11 * the machines is on AC or
12 * there is in a multi battery system an other primary (ACPI) battery is
13 discharging
14
15 This should fix: https://bugzilla.novell.com/show_bug.cgi?id=258755
16 ---
17 hald/device_pm.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
18 1 files changed, 53 insertions(+), 2 deletions(-)
19
20 diff --git a/hald/device_pm.c b/hald/device_pm.c
21 index e84c4ff..c4fee3b 100644
22 --- a/hald/device_pm.c
23 +++ b/hald/device_pm.c
24 @@ -32,6 +32,7 @@
25
26 #include <glib.h>
27
28 +#include "hald.h"
29 #include "logger.h"
30 #include "util_pm.h"
31 #include "device_pm.h"
32 @@ -127,8 +128,58 @@ device_pm_abstract_props (HalDevice *d)
33 charging = hal_device_property_get_bool (d, "battery.rechargeable.is_charging");
34 discharging = hal_device_property_get_bool (d, "battery.rechargeable.is_discharging");
35
36 - if (!charging && !discharging)
37 - normalised_rate = 0;
38 + if (!charging && !discharging) {
39 + GSList *i;
40 + GSList *devices;
41 + HalDevice *_d;
42 + gboolean online;
43 + const char *bat_type;
44 +
45 + online = FALSE;
46 +
47 + /* check if this is a primary, mean laptop battery */
48 + bat_type = hal_device_property_get_string (d, "battery.type");
49 + if (bat_type != NULL && !strncmp (bat_type, "primary", 7)) {
50 +
51 + /* check if the machine is on AC or on battery */
52 + devices = hal_device_store_match_multiple_key_value_string (hald_get_gdl (),
53 + "info.category",
54 + "ac_adapter");
55 + for (i = devices; i != NULL; i = g_slist_next (i)) {
56 + _d = HAL_DEVICE (i->data);
57 + if (hal_device_has_property (_d, "linux.acpi_type")) {
58 + if (hal_device_property_get_bool (_d, "ac_adapter.present")) {
59 + online = TRUE;
60 + }
61 + }
62 + }
63 + g_slist_free (devices);
64 +
65 + if (online) {
66 + normalised_rate = 0;
67 + } else {
68 + /* check if there is an other battery already discharing, if so: set normalised_rate = 0 */
69 + devices = hal_device_store_match_multiple_key_value_string (hald_get_gdl (),
70 + "info.category",
71 + "battery");
72 + for (i = devices; i != NULL; i = g_slist_next (i)) {
73 + _d = HAL_DEVICE (i->data);
74 + if (hal_device_has_property (_d, "linux.acpi_type")) {
75 + bat_type = hal_device_property_get_string (_d, "battery.type");
76 + if (bat_type != NULL && !strncmp (bat_type, "primary", 7)) {
77 + if (strcmp (hal_device_get_udi(d), hal_device_get_udi(_d)) != 0) {
78 + if (hal_device_property_get_bool (_d, "battery.rechargeable.is_discharging"))
79 + normalised_rate = 0;
80 + }
81 + }
82 + }
83 + }
84 + g_slist_free(devices);
85 + }
86 + } else {
87 + normalised_rate = 0;
88 + }
89 + }
90
91 /* Some laptops report current charge much larger than
92 * full charge when at 100%. Clamp back down to 100%. */
93 --
94 1.5.3.7
95