@@ -110,6 +110,7 @@ public final class BluetoothDeviceProfileState extends StateMachine {
110110 private BluetoothHeadset mHeadsetService ;
111111 private BluetoothPbap mPbapService ;
112112 private boolean mPbapServiceConnected ;
113+ private boolean mAutoConnectionPending ;
113114 private static final String BLUETOOTH_ADMIN_PERM = android .Manifest .permission .BLUETOOTH_ADMIN ;
114115
115116 private BluetoothDevice mDevice ;
@@ -272,6 +273,10 @@ public BluetoothDeviceProfileState(Context context, String address,
272273 public void onServiceConnected (int profile , BluetoothProfile proxy ) {
273274 synchronized (BluetoothDeviceProfileState .this ) {
274275 mHeadsetService = (BluetoothHeadset ) proxy ;
276+ if (mAutoConnectionPending ) {
277+ sendMessage (AUTO_CONNECT_PROFILES );
278+ mAutoConnectionPending = false ;
279+ }
275280 }
276281 }
277282 public void onServiceDisconnected (int profile ) {
@@ -360,8 +365,9 @@ public boolean processMessage(Message message) {
360365 // Don't auto connect to docks.
361366 break ;
362367 } else {
363- if (mHeadsetService != null &&
364- mHeadsetService .getPriority (mDevice ) ==
368+ if (mHeadsetService == null ) {
369+ mAutoConnectionPending = true ;
370+ } else if (mHeadsetService .getPriority (mDevice ) ==
365371 BluetoothHeadset .PRIORITY_AUTO_CONNECT &&
366372 mHeadsetService .getDevicesMatchingConnectionStates (
367373 new int [] {BluetoothProfile .STATE_CONNECTED ,
0 commit comments