I am new to Sailfish OS, having experimented with it first on the PinePhone, and then the OnePlus One. I now am running Sailfish X (version 22.214.171.124) on the Sony Xperia 10+, and have essentially made it my daily driver for now.
That all said, one of the first things that bugged me was that the audio of my Bluetooth headsets was really low. I wanted to share my fix in case anybody else has the same problem. I also want to share it in case anybody else has a better way to go about doing this. While the method I used is easy to implement, I would think there is probably a better way to go about it.
Here is what I came up with.
1.) SSH into your phone, become root (via
devel-su su - or similar), and create a custom udev rule under /etc/udev/rules.d. I created a file called 9999-bt-audio-boost.rules with the following contents, where the 9999 prefix was used so I was assuring it ran last after all other udev rules. I used vi on the OS itself to create the file, but there’s other ways to go about getting the file into place:
ACTION=="add", SUBSYSTEM=="bluetooth", RUN+="/bin/sleep 3", RUN+="/sbin/runuser -l nemo -c 'pactl set-sink-volume @DEFAULT_SINK@ 200%'"
2.) Run the following so that your udev rule will trigger when a Bluetooth device is attached:
udevadm control --reload-rules && udevadm trigger
Now anytime a Bluetooth headset connects to a phone, the volume output for the device will double. Note that in my case anyway, this only really works if you already are listening to music, and it may take a cycle of connecting and disconnecting to get it to take.
Other than hearing the volume increase, you can check if the volume change applied by looking at the output of
pactl list sinks and seeing if the front-left and front-right volumes are at 200%.
Things you can tweak:
1.) The time to sleep before running the pactl command. While 2 seconds worked reliably with one headset of mine, 3 seconds was the only way to have the volume boost happen for another. It is best to test this out while having music actively playing so that the audio boost happening is obvious. You should strive to use the lowest number possible number here.
2.) The volume percentage can be adjusted. While the one device worked well with 175%, the other one only gave me some headroom if I used 200%. Again, the lowest number that allows you to reach the desired usual listening volume with a few volume rocker clicks of headroom should be used.
3.) While @DEFAULT_SINK@ worked properly on my Xperia 10+, it’s possible it won’t work on your device. In my case, the index for the device increments every time the device is connected (until it eventually “rolls over”), and so using @DEFAULT_SINK@ was reliable in my case compared to a fixed number. While I would think other devices would behave similarly, I haven’t gotten around to doing testing on my other devices.
Now, I would have liked to filter this udev rule against some custom attribute common to Bluetooth headsets, but none were present that I could find when looking at the output of
udevadm monitor -e and similar. Because of this, this rule runs anytime a Bluetooth device is connected, regardless if it is an audio device or not (unless the system classifies it in a different device class). While this will not be a problem if you only ever connect custom headsets, it could cause issues if you are not using a Bluetooth headset, but attach some other sort of Bluetooth device. This could then inadvertently perhaps cause your speaker or headphones (via headphone jack) volume to boost. I haven’t tested this, but I wanted to point it out just in case.
I also would have preferred not to put in the 3 second sleep at all since that is a blocking operation for a few seconds, but it was the only reliable and easily-configured way I could come up with for solving this problem.
Thanks for reading, and again, direct me elsewhere if there is a better way of doing this so I can take a look.