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

abi <abi/3.0>,

include <tunables/global>

@{exec_path} = @{bin}/blueman-*
profile blueman @{exec_path} flags=(attach_disconnected) {
  include <abstractions/base>
  include <abstractions/audio-client>
  include <abstractions/bus-session>
  include <abstractions/dconf-write>
  include <abstractions/desktop>
  include <abstractions/fontconfig-cache-read>
  include <abstractions/nameservice-strict>
  include <abstractions/python>
  include <abstractions/thumbnails-cache-read>
  include <abstractions/user-download-strict>

  network inet stream,
  network inet6 stream,
  network netlink raw,
  network bluetooth raw,

  ptrace (read) peer=gjs-console,

  #aa:dbus own bus=session name=org.blueman.Applet
  #aa:dbus own bus=session name=org.blueman.Manager

  @{exec_path} mrix,

  @{sh_path}           rix,
  @{open_path}         rix,

  /usr/share/blueman/{,**} r,

  /var/lib/blueman/network.state r,

  owner @{HOME}/ r,
  owner @{HOME}/bluetooth*/ r,
  owner @{HOME}/bluetooth*/* rw,

  owner @{user_cache_dirs}/blueman-tray-@{int} rw,
  owner @{user_cache_dirs}/blueman-services-@{int} rw,
  owner @{user_cache_dirs}/blueman-adapters-@{int} rw,
  owner @{user_cache_dirs}/blueman-manager-@{int} rw,
  owner @{user_cache_dirs}/blueman-applet-@{int} rw,

  owner @{user_cache_dirs}/obexd/ rw,
  owner @{user_cache_dirs}/obexd/* rw,

        @{PROC}/@{pids}/cmdline r,
  owner @{PROC}/@{pid}/fd/ r,
  owner @{PROC}/@{pid}/mounts r,

  /dev/dri/card@{int} rw,
  /dev/rfkill r,
  /dev/shm/ r,
  /dev/tty rw,

  deny owner @{user_share_dirs}/gvfs-metadata/{,*} r,

  include if exists <local/blueman>
}
