diff options
author | Richard Hughes <richard@hughsie.com> | 2012-04-18 16:46:41 +0100 |
---|---|---|
committer | Richard Hughes <richard@hughsie.com> | 2012-04-18 16:46:46 +0100 |
commit | 28c8653ed8d43bfdcac4bb09c0fe16b5ac124668 (patch) | |
tree | d8977d218d0cb2474c6a15ff524e58e3a29b8b88 /src/linux/up-device-supply.c | |
parent | 6fb36eb5eb85386d2e1c5d9fb760d68053d8afc5 (diff) |
Never detect HID devices with batteries as power supplies
Some HID devices with batteries (like bluetooth keyboards) have been creating
power supply devices in sysfs since Linux 3.3.
UPower thinks that they are system devices and shuts down the system if they
get low. This is bad.
This is fixed in Linux 3.4, where there is a new 'scope' file that defines if
the device is powering the system.
Helpfully ACPI batteries don't populate the scope value, but soon will.
Add support for the scope attribute now, and default to system devices if it's
missing. Note, you need to be running a 3.4 kernel or a 3.3 with the patch
backported for this to work.
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=806295
Diffstat (limited to 'src/linux/up-device-supply.c')
-rw-r--r-- | src/linux/up-device-supply.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/linux/up-device-supply.c b/src/linux/up-device-supply.c index bc5e973..073c364 100644 --- a/src/linux/up-device-supply.c +++ b/src/linux/up-device-supply.c @@ -845,6 +845,7 @@ up_device_supply_coldplug (UpDevice *device) gboolean ret = FALSE; GUdevDevice *native; const gchar *native_path; + const gchar *scope; gchar *device_type = NULL; UpDeviceKind type = UP_DEVICE_KIND_UNKNOWN; @@ -858,15 +859,24 @@ up_device_supply_coldplug (UpDevice *device) goto out; } + /* try to work out if the device is powering the system */ + scope = g_udev_device_get_sysfs_attr (native, "scope"); + if (g_ascii_strcasecmp (scope, "device") == 0) { + supply->priv->is_power_supply = FALSE; + } else if (g_ascii_strcasecmp (scope, "system") == 0) { + supply->priv->is_power_supply = TRUE; + } else { + g_debug ("taking a guess for power supply scope"); + supply->priv->is_power_supply = TRUE; + } + /* try to detect using the device type */ device_type = up_device_supply_get_string (native_path, "type"); if (device_type != NULL) { if (g_ascii_strcasecmp (device_type, "mains") == 0) { type = UP_DEVICE_KIND_LINE_POWER; - supply->priv->is_power_supply = TRUE; } else if (g_ascii_strcasecmp (device_type, "battery") == 0) { type = UP_DEVICE_KIND_BATTERY; - supply->priv->is_power_supply = TRUE; } else if (g_ascii_strcasecmp (device_type, "USB") == 0) { /* use a heuristic to find the device type */ |