I had a similar issue. My headset supports only audio with A2DP and needs to switch to HFP in order for my mic to work.
I switched from pulse audio to pipewire. "Pipewire (WirePlumber >= 0.4.8) [...] supports automatic Bluetooth profile switching (e.g. switching from A2DP to HSP/HFP when an application needs microphone access)."
This was a great solution for my use case. My laptop no longer uses the internal mic when joining MS Teams calls but automatically switches to my headset with HFP.
I am also running Ubuntu 22.04 and installed Pipewire manually.
Install
Install codecs for LDAC (SBC is included out of the box):
$ sudo apt install libldacbt-{abr,enc}2
Install remaining PipeWire packages and WirePlumber as the session
manager:
$ sudo apt install \ libspa-0.2-bluetooth \
pipewire-audio-client-libraries \ pipewire-media-session- \
wireplumber
Notice '-' at the end of 'pipewire-media-session'. This is to remove it in the same command, because 'wireplumber' will be used
instead.
Start WirePlumber for your user:
$ systemctl --user --now enable wireplumber.service
Configure ALSA
Single step. Copy the config file from the PipeWire examples into your
ALSA configuration directory:
$ sudo cp
/usr/share/doc/pipewire/examples/alsa.conf.d/99-pipewire-default.conf
/etc/alsa/conf.d/
PulseAudio
Everything was done automatically by pipewire-pulse package, which
should have been installed by wireplumber package as recommended. If
not, install it yourself. Bluetooth
Just remove this package and Bluetooth will be handled by PipeWire:
$ sudo apt remove pulseaudio-module-bluetooth
Done
Reboot and check if it works by running:
$ LANG=C pactl info | grep '^Server Name'
This is only a workaround and doesn't answer your question directly.