summaryrefslogtreecommitdiff
blob: b0a3df1ad169a2559aa34b0ddd540fd26fe68093 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
From 7849ca66af7f74bfdba968e979c4596c9e99ff3d Mon Sep 17 00:00:00 2001
From: Nirbheek Chauhan <nirbheek.chauhan@gmail.com>
Date: Tue, 9 Nov 2010 23:54:27 +0530
Subject: [PATCH] Add Dell laptop battery always-discharging quirk

Once full, some Dell laptop batteries show battery state as "fully-charged" for
a second, and then set battery state as "Discharging". However, the "on-battery"
status is correct. Try to do some guesswork for this case.

Was observed with the following battery:

vendor:               SAMSUNG SDI
model:                DELL U600P04
serial:               0000
technology:           lithium-ion

https://bugs.freedesktop.org/show_bug.cgi?id=31196
---
 src/linux/up-device-supply.c |   40 ++++++++++++++++++++++++++++++++++++++++
 1 files changed, 40 insertions(+), 0 deletions(-)

diff --git a/src/linux/up-device-supply.c b/src/linux/up-device-supply.c
index 341f5df..4294e04 100644
--- a/src/linux/up-device-supply.c
+++ b/src/linux/up-device-supply.c
@@ -402,6 +402,9 @@ up_device_supply_refresh_battery (UpDeviceSupply *supply)
 	UpDeviceState old_state;
 	UpDeviceState state;
 	UpDevice *device = UP_DEVICE (supply);
+	UpDevice *device_tmp;
+	UpDeviceKind type;
+	GPtrArray *devices;
 	const gchar *native_path;
 	GUdevDevice *native;
 	gboolean is_present;
@@ -422,7 +425,9 @@ up_device_supply_refresh_battery (UpDeviceSupply *supply)
 	const gchar *recall_url = NULL;
 	UpDaemon *daemon;
 	gboolean on_battery;
+	gboolean online;
 	guint battery_count;
+	guint i;
 
 	native = G_UDEV_DEVICE (up_device_get_native (device));
 	native_path = g_udev_device_get_sysfs_path (native);
@@ -599,6 +604,41 @@ up_device_supply_refresh_battery (UpDeviceSupply *supply)
 		if (percentage > 100.0f)
 			percentage = 100.0f;
 	}
+	/* some batteries show themselves as 'discharging' once they're full */
+	if (state == UP_DEVICE_STATE_DISCHARGING && percentage == 100.0f) {
+		state = UP_DEVICE_STATE_FULLY_CHARGED;
+		daemon = up_device_get_daemon (device);
+		/* get states of AC power supplies */
+		devices = up_device_list_get_array (up_daemon_get_device_list(daemon));
+		for (i=0; i<devices->len; i++) {
+			device_tmp = (UpDevice *) g_ptr_array_index (devices, i);
+			g_object_get (device_tmp,
+				      "type", &type,
+				      NULL);
+			if (type != UP_DEVICE_KIND_LINE_POWER)
+				continue;
+			ret = up_device_supply_get_online (device_tmp, &online);
+			if (!ret)
+				continue;
+
+			/* print what we're trying */
+			g_debug ("guessing battery state using power supply status:%i",
+				   online);
+
+			/* If any of the power supplies is not online,
+			 * assume it's discharging, and break */
+			if (!online) {
+				state = UP_DEVICE_STATE_DISCHARGING;
+				break;
+			}
+		}
+		/* print what we did */
+		g_debug ("guessed battery state as '%s' using power supply status",
+			   up_device_state_to_string (state));
+
+		g_ptr_array_unref (devices);
+	}
+
 
 	/* the battery isn't charging or discharging, it's just
 	 * sitting there half full doing nothing: try to guess a state */
-- 
1.7.2.2