# apparmor.d - Full set of apparmor profiles
# Copyright (C) 2022-2024 Alexandre Pujol <alexandre@pujol.io>
# SPDX-License-Identifier: GPL-2.0-only

abi <abi/3.0>,

include <tunables/global>

@{exec_path} = @{lib}/switcheroo-control
profile switcheroo-control @{exec_path} flags=(attach_disconnected) {
  include <abstractions/base>
  include <abstractions/bus-system>

  capability net_admin,
  capability sys_nice,

  network netlink raw,

  #aa:dbus own bus=system name=net.hadess.SwitcherooControl

  @{exec_path} mr,

  @{run}/udev/data/+drm:card@{int}-* r,   # for screen outputs
  @{run}/udev/data/+pci:* r,              # Identifies all PCI devices (CPU, GPU, Network, Disks, USB, etc.)

  @{run}/udev/data/c226:@{int} r,         # for /dev/dri/card* 

  @{sys}/bus/ r,
  @{sys}/class/ r,
  @{sys}/class/drm/ r,
  @{sys}/devices/@{pci}/boot_vga r,
  @{sys}/devices/@{pci}/uevent r,
  @{sys}/devices/virtual/**/uevent r,

  include if exists <local/switcheroo-control>
}
