How to get the sc-controller to function on 20.04

Apparmor will deny the snap or appimage of sc-controller access to uinput resulting in sc-controller displaying error 1. A deb for 20.04 is not available and the source would require python 2.7.

From /var/log/kern.log

audit: type=1400 audit(1588199484.212:67): apparmor="DENIED" operation="open" profile="snap.sc-controller.sc-controller" name="/sys/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.5/busnum" pid=2067 comm="python2" requested_mask="r" denied_mask="r" fsuid=1000 ouid=0

Solution 1:

Sourced from Best way to access dev uinput on snapcraft.io forum. Thanks to jdstrand and mcphail sc-controller's developer. sc-controller is currently being updated to python3 but until that effort is complete using the snap is a reasonable method to package the 0.4.7 version for 20.04.

Sc-controller needs pretty deep access to devices to function in strict confinement. The following changes to your system posses some risk of allowing a rouge snap to inject keystrokes and mouse events proceed at your own risk.

  1. Add the line /dev/uinput rw, to snap.sc-controller.sc-controller. I added it at line 30, placement and two space indentation seems to matter.

sudo nano /var/lib/snapd/apparmor/profiles/snap.sc-controller.sc-controller

  1. Load the updated apparmor rules into the kernel:
sudo apparmor_parser -r /var/lib/snapd/apparmor/profiles/snap.sc-controller.sc-controller
  1. If you don’t have /etc/udev/rules.d/70-snap.sc-controller.rules on your system, you can test your snap now. If you do, add to it:
# test
KERNEL=="uinput", TAG+="snap_sc-controller"
  1. To apply the rules

Run:

sudo udevadm trigger --subsystem-match=misc # make the rules apply
#snap run --shell yoursnap.cmd  # launch a shell under yoursnap.cmd
  1. In a terminal separate from the snap shell run udevadm and check the TAGS line. it should now include snap_sc-controller
udevadm info /dev/uinput
...
E: TAGS=:snap_sc-controller:uaccess:seat:
  1. Rebooting may be necessary to fully implement the changes, and allow the sc-controller snap to function correctly.