# apparmor.d - Full set of apparmor profiles
# Copyright (C) 2018-2022 Mikhail Morfikov
# 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}/{,upower/}upowerd
profile upowerd @{exec_path} flags=(attach_disconnected) {
  include <abstractions/base>
  include <abstractions/bus-system>
  include <abstractions/bus/org.bluez>
  include <abstractions/bus/org.freedesktop.login1>
  include <abstractions/devices-usb>

  network netlink raw,

  #aa:dbus own bus=system name=org.freedesktop.UPower

  @{exec_path} mr,

  /etc/UPower/ r,
  /etc/UPower/UPower.conf r,

  /var/lib/upower/ r,
  /var/lib/upower/history-*.dat{,.*} rw,

  @{run}/udev/data/ r,
  @{run}/udev/data/+acpi:* r,             # for acpi
  @{run}/udev/data/+hid:* r,              # for HID-Compliant Keyboard
  @{run}/udev/data/+i2c:* r,
  @{run}/udev/data/+input:input@{int} r,  # for mouse, keyboard, touchpad
  @{run}/udev/data/+pci:* r,              # Identifies all PCI devices (CPU, GPU, Network, Disks, USB, etc.)
  @{run}/udev/data/+platform:* r,
  @{run}/udev/data/+power_supply* r,
  @{run}/udev/data/+sound:card@{int} r,   # for sound card
  @{run}/udev/data/c10:@{int} r,          # for non-serial mice, misc features
  @{run}/udev/data/c13:@{int}  r,         # for /dev/input/*
  @{run}/udev/data/c116:@{int} r,         # for ALSA

  @{run}/systemd/inhibit/[0-9]*.ref rw,

  @{sys}/bus/hid/devices/ r,
  @{sys}/class/input/ r,
  @{sys}/class/leds/ r,
  @{sys}/class/power_supply/ r,
  @{sys}/class/sound/ r,
  @{sys}/devices/ r,
  @{sys}/devices/**/capabilities/* r,
  @{sys}/devices/**/leds/**/brightness rw,
  @{sys}/devices/**/leds/**/brightness_hw_changed r,
  @{sys}/devices/**/leds/**/max_brightness r,
  @{sys}/devices/**/power_supply/**/* r,
  @{sys}/devices/**/uevent r,
  @{sys}/devices/virtual/dmi/id/product_name r,

  /dev/input/event* r,

  include if exists <local/upowerd>
}

# vim:syntax=apparmor
