Skip to contentSkip to conversation

HID: input: ignore the battery of Keychron keyboards over Bluetooth

PATCH New Stephen J. Fuhry 1 participant 1 message Oct 14

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 HID: input: ignore the battery of Keychron keyboards over Bluetooth

Keychron keyboards identify as Apple's wired aluminium keyboard, rev B ANSI (05ac:024f), when connected over Bluetooth. hid-apple has bound that ID over Bluetooth since commit ebe0b42a4252 ("HID: apple: Add support for Keychron K1 wireless keyboard"). The Keychron K8 tested here does the same, whichever position its Mac/Windows switch is in.

The report descriptor declares a battery, so hid-input creates a power_supply node for it. The keyboard never answers the battery feature report. Every read of the node blocks for the full 5 second uhid timeout and then returns -ENODATA:

  $ time cat .../power_supply/hid-<addr>-battery/capacity
  cat: ...: No data available
  real    0m5.10s

Anything that enumerates devices pays this on every pass. With the keyboard connected, "udevadm info --export-db" took 10 to 26 seconds; with it disconnected, 0.11 seconds. KDE's Solid library enumerates devices on the GUI thread, so Dolphin and the Plasma panel froze for the same 10 to 26 seconds. upower already gives up on the device and does not list it.

0x024f is a wired-only Apple product, so a Bluetooth device using it is not a genuine Apple keyboard. Ignore its battery so the node is never created. AVOID_QUERY would stop the blocking read, but the K8 does not send the battery in its input reports either. The node would then stay at its initial capacity of 0 with status Unknown, which looks like an empty battery.

---
Tested on 7.2.6 (Debian trixie-backports base) on a ThinkPad T14 Gen 3 with a Keychron K8 paired over Bluetooth: no battery node is created and "udevadm info --export-db" takes 0.12 s with the keyboard connected. The keyboard types normally and hid-apple still binds it.

I have only the K8 to test. If another Keychron model on this ID does answer the battery report, this hides its battery level. I do not know whether any does.

 drivers/hid/hid-input.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/hid/hid-input.c +9 -0
index edd6bbf..380ff8a 100644
@@ -381,6 +381,15 @@ static const struct hid_device_id hid_battery_quirks[] = {
 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_ELECOM,
 		USB_DEVICE_ID_ELECOM_BM084),
 	  HID_BATTERY_QUIRK_IGNORE },
+	/*
+	 * Keychron keyboards in Bluetooth mode reuse the product ID of
+	 * Apple's wired aluminium keyboard. They declare a battery but never
+	 * answer the battery feature report, so each read blocks for the full
+	 * uhid timeout and then fails with -ENODATA.
+	 */
+	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE,
+		USB_DEVICE_ID_APPLE_ALU_REVB_ANSI),
+	  HID_BATTERY_QUIRK_IGNORE },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_SYMBOL,
 		USB_DEVICE_ID_SYMBOL_SCANNER_3),
 	  HID_BATTERY_QUIRK_IGNORE },
Signature · 1 line
2.47.3