Synchronized access to CarService Bluetooth profile proxy objects

CarBluetoothUserService provides CarService access to bluetooth profile
proxy objects so it can interact with them as the current user and
facilitate policy based bluetooth device management. Proxy connections
and disconnects are asynchronous in nature and can happen at any time,
depending on whats going on in the bluetooth stack. Without synchronized
access to the proxies, we can enter a state where we're servicing a
request and the proxy reference disappears once we've determined it to
exist. This is a classic race condition that causes an NPE, crashing Car
Service. This change fixes that issue by adding a synchronized context
around creation, clearing and accessing of proxy objects.

Bug: b/128434168
Test: Pair two or more bluetooth device to automotive hardware and
automate toggling bluetooth on and off at differing intervals, allowing
the auto connect policy to attempt connections while the BT adapter is
turning off. On an unsychronized system, this will *eventually* expose
the race condition (1/15000 toggles for me). You should observe that the
original NullPointerError no longer appears. Also observe that the
auto-connection attempts do still happen at roughly the same latency.

Change-Id: I4bf3ec81f1f3331c8d421d13a3f00537dc6f05fe
1 file changed