Request for system-files interfaces (write bluetooth options) for auto-cpufreq

Hi,

As part of auto-cpufreq (Automatic CPU speed & power optimizer for Linux), in latest changes on gnome-power-v2 branch I would like to be able to configure bluetooth to be enabled or disabled on boot.

This functionality is already there for non Snap installs, and this is a bug fix for Snap, as currently it’s not possible to do this with application installed as a Snap.

As part of this request I’ve added etc-bluetooth-conf to plugs definition:

plugs:
   etc-auto-cpufreq-conf:
    interface: system-files
    write:
    - /etc/auto-cpufreq.conf
   etc-bluetooth-conf:
    interface: system-files
    write:
    - /etc/bluetooth/main.conf

For reference, below are the contents of full snapcraft.yaml file as it is in Github repo..

name: auto-cpufreq
base: core20
version: '1.8.0'
summary: Automatic CPU speed & power optimizer for Linux
description: |
  Automatic CPU speed & power optimizer for Linux based on active
  monitoring of laptop's battery state, CPU usage and system load.
  Ultimately allowing you to improve battery life without making
  any compromises.

license: LGPL-3.0
grade: stable
confinement: strict

compression: lzo

parts:
  auto-cpufreq:
    plugin: python
    python-packages:
       - setuptools
       - wheel
    build-packages:
       - gcc
       - python3-dev
    stage-packages:
       - coreutils
       - dmidecode
    source: .

  deploy-scripts:
    plugin: dump
    source: scripts
    organize:
      cpufreqctl.sh: usr/bin/cpufreqctl.auto-cpufreq
      snapdaemon.sh: usr/bin/snapdaemon

plugs:
   etc-auto-cpufreq-conf:
    interface: system-files
    write:
    - /etc/auto-cpufreq.conf
   etc-bluetooth-conf:
    interface: system-files
    write:
    - /etc/bluetooth/main.conf


apps:
  auto-cpufreq:
    command: bin/auto-cpufreq
    environment:
      PYTHONPATH: $SNAP/usr/lib/python3/site-packages:$SNAP/usr/lib/python3/dist-packages:$PYTHONPATH
    plugs:
      - cpu-control
      - system-observe
      - hardware-observe
      - etc-auto-cpufreq-conf
      - etc-bluetooth-conf
    environment:
      LC_ALL: C.UTF-8
      LANG: C.UTF-8
      PKG_MARKER: SNAP

  service:
    command: usr/bin/snapdaemon
    plugs:
      - cpu-control
      - system-observe
      - hardware-observe
    environment:
      LC_ALL: C.UTF-8
      LANG: C.UTF-8
      PKG_MARKER: SNAP
    daemon: simple

Could you please allow this interface for auto-cpufreq so I make a new release and publish this updated version to Snap store?

Thank you,

Adnan

Instead of writing directly to /etc/bluetooth/main.conf would it be possible to use the bluez interface to communicate with bluez and have it enabled / disabled at boot? Since auto-cpufreq is not the owner of this file then it would not be appropriate to grant auto-connection for this file but perhaps this could be allowed to be manually connected.

Regarding /etc/auto-cpufreq.conf - +1 from me for auto-connect of write access to this file named etc-auto-cpufreq-conf as this snap is the clear owner of this file.

If possible I would prefer if things could stay the way they are now, as I’ve already done a lot of code changes to adjust the app to properly work within Snap context. I also don’t know how I could to this with bluez.

I know it could be done by disabling bluetooth service: sudo systemctl disable bluetooth.service, but this doesn’t seem to be possible as I’m trying to get answer in Disabling systemctl service on host from snap.

Just setting (as it is now) AutoEnable=false to /etc/bluetooth/main.conf is simplest way to go, considering auto-cpufreq is targeting all distros (including those not using systemd).

@alexmurray I figured another way to stop bluetooth connections, which is with rfkill and it also seems to do the trick within Snap context.

Hence besides this approval:

Could I also get your approval for network-control interface as part of plugs section? Latest snapcraft file can be found on Github or below:

name: auto-cpufreq
base: core20
version: '1.8.0'
summary: Automatic CPU speed & power optimizer for Linux
description: |
  Automatic CPU speed & power optimizer for Linux based on active
  monitoring of laptop's battery state, CPU usage and system load.
  Ultimately allowing you to improve battery life without making
  any compromises.

license: LGPL-3.0
grade: stable
confinement: strict

compression: lzo

parts:
  auto-cpufreq:
    plugin: python
    python-packages:
       - setuptools
       - wheel
    build-packages:
       - gcc
       - python3-dev
    stage-packages:
       - coreutils
       - dmidecode
       - rfkill
    source: .

  deploy-scripts:
    plugin: dump
    source: scripts
    organize:
      cpufreqctl.sh: usr/bin/cpufreqctl.auto-cpufreq
      snapdaemon.sh: usr/bin/snapdaemon

plugs:
   etc-auto-cpufreq-conf:
    interface: system-files
    write:
    - /etc/auto-cpufreq.conf

apps:
  auto-cpufreq:
    command: bin/auto-cpufreq
    environment:
      PYTHONPATH: $SNAP/usr/lib/python3/site-packages:$SNAP/usr/lib/python3/dist-packages:$PYTHONPATH
      LC_ALL: C.UTF-8
      LANG: C.UTF-8
      PKG_MARKER: SNAP
    plugs:
      - cpu-control
      - system-observe
      - hardware-observe
      - network-control
      - etc-auto-cpufreq-conf

  service:
    command: usr/bin/snapdaemon
    plugs:
      - cpu-control
      - system-observe
      - hardware-observe
      - network-control
      - etc-auto-cpufreq-conf
    environment:
      LC_ALL: C.UTF-8
      LANG: C.UTF-8
      PKG_MARKER: SNAP
    daemon: simple

Thank you!

network-control does seem like a safer option (although it does grant more permissions).

However, this doesn’t feel like core functionality for auto-cpufreq to control bluetooth so I don’t think it is suitable for auto-connection in this case. As such -1 for me for auto-connect of network-control for auto-cpufreq as users can manually connect this if required (and the app could prompt them to do so by checking snapctl is-connected network-control

+1 from me as well for auto-connect system-files with read access to /etc/auto-cpufreq.conf since the snap is the clear owner of such directory. +2 votes for, 0 votes against. Granting the requested auto-connection. @ahodzic I see the latest revision is still indicating read only access, let us know if for any reason you are not willing to have write access anymore and I will revert it to read only.

I agree with @alexmurray and will be -1 as well for auto-connect network-control since it is a very privileged interface and enabling/disabling bluetooth is not a core functionality of auto-cpufreq.

I wanted to have these changes approved before I made code changes. In latest revision auto-cpufreq 1.8.1 (93) it’s set back to write and will be so going forward. Thank you both for the approval.

Rest of the request can be ignored, as I made code changes where if app detects it’s running as a snap, it’ll will inform user how they can disable bluetooth on boot manually outside of snap package context.