Skip to content

scripts: policy-bluetooth: sync logic with p-m-s bluez-autoswitch + fix issues

P V requested to merge pvir/wireplumber:policy-bt-fix into master

Fix some issues in the current policy-bluetooth implementation. This changes it to more or less follow the same logic as in p-m-s bluez-autoswitch.

Feel free to squash.


Headset profile saving does not work properly currently (only called on metadata change; if headset-profile == current-profile, it doesn't get saved etc.)

Change it to follow the logic:

  • Each device has a "normal" and "switched" mode. The latter becomes active if a "communication" input stream exists and the current default sink is bluez sink. The switched mode is exited only when there are no "communication" input streams.

  • On transition normal->switched, record current profile as the "saved" profile. Then switch to "headset" profile. If no headset profile was saved previously, pick profile with input direction & highest priority.

  • On transition switched->normal, save currently active profile as the "headset" profile. Then switch back to "saved" profile.


Monitor whether streams are running or suspended. When they are suspended, switch to normal mode.

This is required e.g. for programs such as Teams, which keep recording streams open but inactive for their whole runtime.

Profile restore also needs to be done with a timeout, to avoid switching rapidly when streams are moved between sources.


Monitor streams can be identified based on the stream.monitor property.

They should not be identified based on application name, because that may be localized, and the previous code does not work properly on non-English locale.


The profile index may change, if the set of profiles on the device changes, and is better to not use it for saving long-term.


Only the configured headset profile needs to be persistent, the switched status and saved profile should not persist over wireplumber restart.

When devices appear initially, they should not appear as switched, but recheck switch status.


If the current profile has input route, don't switch to a different profile. Instead, consider the current profile as the new headset profile.

Edited by P V

Merge request reports

Loading