Blockstream / green_qt

Blockstream Green App
GNU General Public License v3.0
188 stars 31 forks source link

Green on Linux should check power saving status of Jade #89

Open grubles opened 1 year ago

grubles commented 1 year ago

On a more modern Linux such as Fedora, a default power saving config option prevents newer Jade units from being able to communicate with the Green app, causing it to crash. Older Jades are unaffected because they have a different serial chip.

We should query if the power saving feature is enabled or not and provide an alert to the user that points them to instructions (I'm thinking here is a good home) for how to install appropriate udev rules that disable this feature every time the Jade is plugged into the host machine.

To check if a Jade is plugged in we can look to see if /dev/ttyACM0 exists and then proceed to determining if power saving is enabled.

It's possible for a non-root user to query the state of the power saving feature, even when inside a Flatpak sandbox:

$ cat /sys/bus/usb/devices/1-2/power/control
auto

Note this path is dependent on the user's machine and is very likely to be different across different sets of hardware. But, we can (again, as non-root user) look in each device subdirectory for the idProduct and idVendor files which contain the product and vendor IDs and see if we can find Jade's:

$ pwd
/sys/bus/usb/devices

$ ls -la */idProduct*
-r--r--r--. 1 root root 4096 May 30 07:36 1-10/idProduct
-r--r--r--. 1 root root 4096 May 30 07:36 1-7/idProduct
-r--r--r--. 1 root root 4096 May 30 07:36 1-8/idProduct
-r--r--r--. 1 root root 4096 May 30 07:36 3-1/idProduct
-r--r--r--. 1 root root 4096 May 30 07:36 usb1/idProduct
-r--r--r--. 1 root root 4096 May 30 07:36 usb2/idProduct
-r--r--r--. 1 root root 4096 May 30 07:36 usb3/idProduct
-r--r--r--. 1 root root 4096 May 30 07:36 usb4/idProduct

$ cat 1-10/idProduct
01a2

This particular device is not Jade :(. On to the next one...

I've tested the udev rule below (placed in /etc/udev/rules.d/21-jade.rules) on a couple different Fedora machines successfully.

ATTRS{idProduct}=="55d4", ATTRS{idVendor}=="1a86", SUBSYSTEM=="usb", TEST=="power/control" ATTR{power/control}="on"

This will turn off the power saving automatically any time a Jade is plugged in.

Older Linux distros like Ubuntu 22.04 do not enable the power saving OOTB and are unaffected by this, but future versions might. It's unclear if it's a difference between Linux kernel versions or their configs or if Ubuntu is intentionally turning this off and Fedora leaves it untouched, so it's a good idea to tackle this ahead of time.

SmileyChris commented 1 year ago

Thanks, that udev rule allowed me to finish setting up my jade on Manjaro (it would crash with SIGABRT after double entering the pin every time).