hal: Branch 'master'

Danny Kukawka dkukawka at kemper.freedesktop.org
Thu Dec 6 12:23:27 PST 2007


 hald/device_pm.c |   55 +++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 53 insertions(+), 2 deletions(-)

New commits:
commit 45ddfd2ecb1e502089dbbb2a7eb04243f93ed561
Author: Danny Kukawka <danny.kukawka at web.de>
Date:   Thu Dec 6 21:23:05 2007 +0100

    fix normalised_rate if dis-/charging state is unknown
    
    This fixes problems with machines which report not the correct charging
    state in some cases (e.g. battery report 'charged' if on battery). With this
    patch normalised_rate get set only to 0 if:
    
    * the battery is not a primary (ACPI) battery
    * the machines is on AC or
    * there is in a multi battery system an other primary (ACPI) battery is
    discharging
    
    This should fix: https://bugzilla.novell.com/show_bug.cgi?id=258755

diff --git a/hald/device_pm.c b/hald/device_pm.c
index e84c4ff..c4fee3b 100644
--- a/hald/device_pm.c
+++ b/hald/device_pm.c
@@ -32,6 +32,7 @@
 
 #include <glib.h>
 
+#include "hald.h"
 #include "logger.h"
 #include "util_pm.h"
 #include "device_pm.h"
@@ -127,8 +128,58 @@ device_pm_abstract_props (HalDevice *d)
 	charging = hal_device_property_get_bool (d, "battery.rechargeable.is_charging");
 	discharging = hal_device_property_get_bool (d, "battery.rechargeable.is_discharging");
 
-	if (!charging && !discharging)
-		normalised_rate = 0;
+	if (!charging && !discharging) {
+	        GSList *i;
+	        GSList *devices;
+        	HalDevice *_d;
+		gboolean online;
+		const char *bat_type;
+
+		online = FALSE;
+
+		/* check if this is a primary, mean laptop battery */
+		bat_type = hal_device_property_get_string (d, "battery.type");
+		if (bat_type != NULL && !strncmp (bat_type, "primary", 7)) { 
+
+			/* check if the machine is on AC or on battery */ 
+	       	 	devices = hal_device_store_match_multiple_key_value_string (hald_get_gdl (),
+                	                                                            "info.category",
+        	               		                                            "ac_adapter");
+			for (i = devices; i != NULL; i = g_slist_next (i)) {
+				_d = HAL_DEVICE (i->data);
+				if (hal_device_has_property (_d, "linux.acpi_type")) {
+					if (hal_device_property_get_bool (_d, "ac_adapter.present")) {
+						online = TRUE; 
+					}
+				}
+			}
+			g_slist_free (devices);
+
+			if (online) {
+				normalised_rate = 0;
+			} else {
+				/* check if there is an other battery already discharing, if so: set normalised_rate = 0 */ 
+				devices = hal_device_store_match_multiple_key_value_string (hald_get_gdl (),
+											    "info.category",
+											    "battery");
+				for (i = devices; i != NULL; i = g_slist_next (i)) {
+					_d = HAL_DEVICE (i->data);
+					if (hal_device_has_property (_d, "linux.acpi_type")) {
+						bat_type = hal_device_property_get_string (_d, "battery.type");
+						if (bat_type != NULL && !strncmp (bat_type, "primary", 7)) {
+							if (strcmp (hal_device_get_udi(d), hal_device_get_udi(_d)) != 0) {
+								if (hal_device_property_get_bool (_d, "battery.rechargeable.is_discharging"))
+									normalised_rate = 0;
+							}	
+						}
+					}
+				}
+				g_slist_free(devices);
+			}
+		} else {
+			normalised_rate = 0;
+		}
+	}
 
 	/* Some laptops report current charge much larger than
 	 * full charge when at 100%.  Clamp back down to 100%. */


More information about the hal-commit mailing list