Hi, On Friday 02 August 2013 18:07:53 Shih-Yuan Lee wrote: > From: "Shih-Yuan Lee (FourDollars)" <sy...@canonical.com> > > First, checking the device path. If it contains 'bluetooth', it is a > bluetooth devices. Second, checking if there is an input folder. If there > is mouse folder under the input folder, it is a mouse device. Otherwise, it > is a keyboard device.
Looking at https://launchpadlibrarian.net/133697757/UdevDb.txt (via https://bugs.launchpad.net/ubuntu/+source/gnome-power-manager/+bug/1153488), the issue occurs because the battery is of type "Battery" (POWER_SUPPLY_TYPE_BATTERY in kernel). The problem is not limited to Bluetooth devices, but on any HID device that reports battery. Shouldn't up-device-hid catch these kind of devices? Anyway, if not, then one should check the battery name to determine if it is a battery or some other HID device (like mouse/keyboard/touchpad). All HID batteries are named hid-(something)-battery. (see function hidinput_setup_battery in drivers/hid/hid-input.c, using 3.11-rc7 as reference point). After your patch, power-supply is still "TRUE". It should be FALSE since this mouse is not powering the system. Looking a bit further, things get only more awkward. There is no "scope" attribute, more about this in a follow-up mail with the right persons CC'd. Regards, Peter > --- > src/linux/up-device-supply.c | 52 > +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 > insertions(+), 1 deletion(-) > > diff --git a/src/linux/up-device-supply.c b/src/linux/up-device-supply.c > index bd54801..f310dad 100644 > --- a/src/linux/up-device-supply.c > +++ b/src/linux/up-device-supply.c > @@ -851,9 +851,15 @@ up_device_supply_coldplug (UpDevice *device) > UpDeviceSupply *supply = UP_DEVICE_SUPPLY (device); > gboolean ret = FALSE; > GUdevDevice *native; > + const gchar *file; > const gchar *native_path; > const gchar *scope; > gchar *device_type = NULL; > + gchar *device_path = NULL; > + gchar *dir_name = NULL; > + gchar *input_path = NULL; > + GDir *dir = NULL; > + GError *error = NULL; > UpDeviceKind type = UP_DEVICE_KIND_UNKNOWN; > > up_device_supply_reset_values (supply); > @@ -883,7 +889,51 @@ up_device_supply_coldplug (UpDevice *device) > if (g_ascii_strcasecmp (device_type, "mains") == 0) { > type = UP_DEVICE_KIND_LINE_POWER; > } else if (g_ascii_strcasecmp (device_type, "battery") == 0) { > - type = UP_DEVICE_KIND_BATTERY; > + > + /* Detect if the battery comes from bluetooth keyboard > or mouse. */ > + if (g_strstr_len (native_path, -1, "bluetooth") != > NULL) { > + device_path = sysfs_resolve_link (native_path, > "device"); > + dir_name = g_path_get_dirname (device_path); > + if (dir = g_dir_open (dir_name, 0, &error)) { > + while (file = g_dir_read_name (dir)) { > + /* Check if it is an input > device. */ > + if (g_str_has_prefix (file, > "input")) { > + input_path = > g_build_filename (dir_name, file, NULL); > + break; > + } > + } > + g_dir_close (dir); > + } else { > + g_warning ("Can not open folder %s: > %s", dir_name, error->message); > + g_error_free (error); > + } > + g_free (dir_name); > + g_free (device_path); > + } > + > + if (input_path != NULL) { > + if (dir = g_dir_open (input_path, 0, &error)) { > + while (file = g_dir_read_name (dir)) { > + /* Check if it is a mouse > device. */ > + if (g_str_has_prefix (file, > "mouse")) { > + type = > UP_DEVICE_KIND_MOUSE; > + break; > + } > + } > + g_dir_close (dir); > + } else { > + g_warning ("Can not open folder %s: > %s", input_path, error->message); > + g_error_free (error); > + } > + g_free (input_path); > + if (type == UP_DEVICE_KIND_UNKNOWN) { > + type = UP_DEVICE_KIND_KEYBOARD; > + } > + } > + > + if (type == UP_DEVICE_KIND_UNKNOWN) { > + type = UP_DEVICE_KIND_BATTERY; > + } > } else if (g_ascii_strcasecmp (device_type, "USB") == 0) { > > /* use a heuristic to find the device type */ _______________________________________________ devkit-devel mailing list devkit-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/devkit-devel