Fixing Bluetooth in Ubuntu, Pop!_OS 18.04
This is the common headache that has always come up when I decide to use Linux for work and everyday tasks such as watching youtube, netflix, browsing the tweeter feed and more with my Bluetooth headset. Now, with the arrival of Ubuntu 18.04 and Pop!_OS in particular, I have decided that is time to stop this anomaly. In this post I will describe some of the problems I found and potential solutions.
Bluetooth architecture in Ubuntu 18.04
The whole bluetooth functionality provided in Ubuntu is the result of a set of modules interacting with each other. Bluez, pulseaudio, the Linux kernel, the hardware driver and client applications. For more visit the following link: Bluetooth on modern linux.
Bluetooth won’t be available after the system has gone to sleep
I was having this problem with bluetooth after suspending the system. This was annoying since I could not connect to my bluetooth headset and had to restart the whole system to make it work again. Another common situation was that to make the device work I had to remove the bluetooth device and pair it again. After some research, I found out that one of the root causes was a bug inside the 4.48 version of bluez (the one shipped by default with Ubuntu 18.04). This problem causes unstable behavior during common actions (connect, disconnect, pair) and the situation we are trying to solve. Many bugs have been fixed in bluez 4.49 and 4.50, most of them related to the previously mentioned erratic behaviors .
First of all, open the terminal and check the current bluez version in your system with the following command:
dpkg --status bluez | grep '^Version:'
In my case I received
version: 5.48-0ubuntu0ppa . Add the following repository to get the last version of bluez (5.50 as of June 8/2018):
sudo add-apt-repository ppa:bluetooth/bluez
sudo apt-get update
After running the command you should be able to update to bluez 5.50 via:
sudo apt upgrade
After getting the new bluez version you should have access to bluetooth after system suspension and also get a more stable behaviour during common bluetooth actions such as connection, disconnection or pairing. The following links contain more details about the bugs in bluez 4.48 and potential solutions: bluez bug description and bluez bug solution.
Bluetooth headset playing in profile HSP/HFP (Low quality) instead of A2DP (High Fidelity Playback)
This problem can be solved adding the file configuration needed for the system to detect the right type of bluetooth device. First of all make sure that all the dependencies are installed in the system:
sudo apt install pulseaudio pulseaudio-utils pavucontrol pulseaudio-module-bluetooth
After this verification, edit/create (in Pop!_OS 18.04 this file doesn’t exist) the following audio configuration file:
sudo gedit /etc/bluetooth/audio.conf
Add the following lines:
# This section contains general options
Save the file and restart the bluetooth service.
sudo service bluetooth restart
You are all set. Bluetooth audio should start by default in a2dp (high fidelity) mode. Happy music time!
Bluetooth doesn’t play sounds in bluetooth headset after automated initial pairing when booting
After initial boot of the system, I will turn on my bluetooth headset. The system will pair with the device but won’t play any sound. Using
journalctl -f I get the following messages:
pulseaudio: [pulseaudio] module-bluez5-device.c: Profile a2dp_sink has no transport
pulseaudio: [pulseaudio] module-bluez5-device.c: Refused to switch profile to a2dp_sink: Not connected
Reconnecting the device does the job but this is not a satisfactory solution. Bluetooth devices should work with minimal friction after booting the OS.
My bluetooth headset is a Sony MDR-XB950N1. I found that if after pairing I press the play/pause button, I will have the option A2DP available in the gnome sound manager. I can then go to this menu and set the sound output to my headset. This is not the solution I wanted ( full automation was my goal), but it is good enough for now. I added a quick shortcut to set the output of the bluetooth headset to A2DP once pairing and push-play-button has been completed: included an alias in .bashrc to call the command I need to set A2DP as output:
Then add the following line at the end:
alias soundon = 'pacmd set-card-profile device_name a2dp_sink'
Device_name is a value specific for your device. You can find yours once pairing has been completed with the following command:
You should see something like this:
In this case the device name is bluez_card.10_4F_A8_DF_EF_37 . Use the one you get for your device.
More problems and solutions will be added when they appear.