Its a little complex with my case. My phone was keep disconnecting from my car head unit when USB get connected, as the bluetooth seems having conflict when Android Auto starts up automatically. The workaround is that I have to disconnect AA from my car when I don't need it, usually when parking. Then when I want to use AA, I connect my phone with the car and wait until it connects with the head unit, at this point if time AA is not allowed to start, or the disconnect issue will occur. After my phone gets connected to the head unit, I will enable connection to AA from the car end, this fixes the disconnecting issue I faced.
Since I have to disconnect from/connect to AA from my car everytime, it is really annoying me. I am finding a way that forces AA not to start automatically before my phone gets connected to the head unit, and starts AA automatically after that.
Here is the macro I am using.