There is no reason why you can’t close the input stream. You just need to be a lot more careful about how you manipulate it.
I’ve already explained that what you need to do is WHEN you close the stream, you need to manipulate the behavior or any and all functions that this will impact such that they behave in exactly the way they are expected to behave.
So for a more detailed explanation;
Add a new field to your stream_in and stream_out structures. This field will store a boolean value indicating that the stream is closed so that the hardware can be used by HFP.
When you are about to open your own streams, first mark the streams using that new field, then use pcm_close on the pcm’s associated with those streams (don’t close the stream, close the pcm).
You will also need to find EVERYWHERE in the HAL that actually uses pcm’s, and where it would access the pcm, instead just return the expected value but don’t actually let it try touching any pcm.
Once you close the SCO, you need to go through all of the streams that are still present, and RE-OPEN their PCMs – the alsa_device_proxy structure has a pcm_config as its second field.
Finally, if there is anything at all that attempts to OPEN a new stream while you have the SCO running, you need to mark that new stream, and skip the actual pcm_open.