@@ -89,7 +89,7 @@ public class BluetoothService extends IBluetooth.Stub {
8989
9090 private int mNativeData ;
9191 private BluetoothEventLoop mEventLoop ;
92- private BluetoothHeadset mBluetoothHeadset ;
92+ private BluetoothHeadset mHeadsetProxy ;
9393 private BluetoothInputDevice mInputDevice ;
9494 private BluetoothPan mPan ;
9595 private boolean mIsAirplaneSensitive ;
@@ -605,6 +605,7 @@ private synchronized void updateSdpRecords() {
605605 }
606606 mBondState .initBondState ();
607607 initProfileState ();
608+ getProfileProxy ();
608609 }
609610
610611 /**
@@ -1766,30 +1767,29 @@ private void dumpProfileState(PrintWriter pw) {
17661767
17671768 private void dumpHeadsetService (PrintWriter pw ) {
17681769 pw .println ("\n --Headset Service--" );
1769- if (mBluetoothHeadset != null ) {
1770- List <BluetoothDevice > deviceList = mBluetoothHeadset .getConnectedDevices ();
1770+ if (mHeadsetProxy != null ) {
1771+ List <BluetoothDevice > deviceList = mHeadsetProxy .getConnectedDevices ();
17711772 if (deviceList .size () == 0 ) {
17721773 pw .println ("No headsets connected" );
17731774 } else {
17741775 BluetoothDevice device = deviceList .get (0 );
17751776 pw .println ("\n getConnectedDevices[0] = " + device );
17761777 dumpHeadsetConnectionState (pw , device );
17771778 pw .println ("getBatteryUsageHint() = " +
1778- mBluetoothHeadset .getBatteryUsageHint (device ));
1779+ mHeadsetProxy .getBatteryUsageHint (device ));
17791780 }
17801781
17811782 deviceList .clear ();
1782- deviceList = mBluetoothHeadset .getDevicesMatchingConnectionStates (new int [] {
1783+ deviceList = mHeadsetProxy .getDevicesMatchingConnectionStates (new int [] {
17831784 BluetoothProfile .STATE_CONNECTED , BluetoothProfile .STATE_DISCONNECTED });
17841785 pw .println ("--Connected and Disconnected Headsets" );
17851786 for (BluetoothDevice device : deviceList ) {
17861787 pw .println (device );
1787- if (mBluetoothHeadset .isAudioConnected (device )) {
1788+ if (mHeadsetProxy .isAudioConnected (device )) {
17881789 pw .println ("SCO audio connected to device:" + device );
17891790 }
17901791 }
17911792 }
1792- mAdapter .closeProfileProxy (BluetoothProfile .HEADSET , mBluetoothHeadset );
17931793 }
17941794
17951795 private void dumpInputDeviceProfile (PrintWriter pw ) {
@@ -1824,7 +1824,6 @@ private void dumpInputDeviceProfile(PrintWriter pw) {
18241824 pw .println (device );
18251825 }
18261826 }
1827- mAdapter .closeProfileProxy (BluetoothProfile .INPUT_DEVICE , mBluetoothHeadset );
18281827 }
18291828
18301829 private void dumpPanProfile (PrintWriter pw ) {
@@ -1862,7 +1861,7 @@ private void dumpPanProfile(PrintWriter pw) {
18621861
18631862 private void dumpHeadsetConnectionState (PrintWriter pw ,
18641863 BluetoothDevice device ) {
1865- switch (mBluetoothHeadset .getConnectionState (device )) {
1864+ switch (mHeadsetProxy .getConnectionState (device )) {
18661865 case BluetoothHeadset .STATE_CONNECTING :
18671866 pw .println ("getConnectionState() = STATE_CONNECTING" );
18681867 break ;
@@ -1884,7 +1883,6 @@ private void dumpApplicationServiceRecords(PrintWriter pw) {
18841883 Integer pid = mServiceRecordToPid .get (handle ).first ;
18851884 pw .println ("\t pid " + pid + " handle " + Integer .toHexString (handle ));
18861885 }
1887- mAdapter .closeProfileProxy (BluetoothProfile .PAN , mBluetoothHeadset );
18881886 }
18891887
18901888 private void dumpAclConnectedDevices (PrintWriter pw ) {
@@ -1927,11 +1925,16 @@ private void dumpKnownDevices(PrintWriter pw) {
19271925 }
19281926 }
19291927
1928+ private void getProfileProxy () {
1929+ mAdapter .getProfileProxy (mContext ,
1930+ mBluetoothProfileServiceListener , BluetoothProfile .HEADSET );
1931+ }
1932+
19301933 private BluetoothProfile .ServiceListener mBluetoothProfileServiceListener =
19311934 new BluetoothProfile .ServiceListener () {
19321935 public void onServiceConnected (int profile , BluetoothProfile proxy ) {
19331936 if (profile == BluetoothProfile .HEADSET ) {
1934- mBluetoothHeadset = (BluetoothHeadset ) proxy ;
1937+ mHeadsetProxy = (BluetoothHeadset ) proxy ;
19351938 } else if (profile == BluetoothProfile .INPUT_DEVICE ) {
19361939 mInputDevice = (BluetoothInputDevice ) proxy ;
19371940 } else if (profile == BluetoothProfile .PAN ) {
@@ -1940,7 +1943,7 @@ public void onServiceConnected(int profile, BluetoothProfile proxy) {
19401943 }
19411944 public void onServiceDisconnected (int profile ) {
19421945 if (profile == BluetoothProfile .HEADSET ) {
1943- mBluetoothHeadset = null ;
1946+ mHeadsetProxy = null ;
19441947 } else if (profile == BluetoothProfile .INPUT_DEVICE ) {
19451948 mInputDevice = null ;
19461949 } else if (profile == BluetoothProfile .PAN ) {
@@ -2424,25 +2427,43 @@ private void autoConnect() {
24242427 }
24252428 }
24262429
2427- public boolean notifyIncomingConnection (String address ) {
2428- BluetoothDeviceProfileState state =
2429- mDeviceProfileState .get (address );
2430+ public boolean notifyIncomingConnection (String address , boolean rejected ) {
2431+ BluetoothDeviceProfileState state = mDeviceProfileState .get (address );
24302432 if (state != null ) {
24312433 Message msg = new Message ();
2432- msg .what = BluetoothDeviceProfileState .CONNECT_HFP_INCOMING ;
2433- state .sendMessage (msg );
2434+ if (rejected ) {
2435+ if (mA2dpService .getPriority (getRemoteDevice (address )) >=
2436+ BluetoothProfile .PRIORITY_ON ) {
2437+ msg .what = BluetoothDeviceProfileState .CONNECT_OTHER_PROFILES ;
2438+ msg .arg1 = BluetoothDeviceProfileState .CONNECT_A2DP_OUTGOING ;
2439+ state .sendMessageDelayed (msg ,
2440+ BluetoothDeviceProfileState .CONNECT_OTHER_PROFILES_DELAY );
2441+ }
2442+ } else {
2443+ msg .what = BluetoothDeviceProfileState .CONNECT_HFP_INCOMING ;
2444+ state .sendMessage (msg );
2445+ }
24342446 return true ;
24352447 }
24362448 return false ;
24372449 }
24382450
2439- /*package*/ boolean notifyIncomingA2dpConnection (String address ) {
2440- BluetoothDeviceProfileState state =
2441- mDeviceProfileState .get (address );
2451+ /*package*/ boolean notifyIncomingA2dpConnection (String address , boolean rejected ) {
2452+ BluetoothDeviceProfileState state = mDeviceProfileState .get (address );
24422453 if (state != null ) {
24432454 Message msg = new Message ();
2444- msg .what = BluetoothDeviceProfileState .CONNECT_A2DP_INCOMING ;
2445- state .sendMessage (msg );
2455+ if (rejected ) {
2456+ if (mHeadsetProxy .getPriority (getRemoteDevice (address )) >=
2457+ BluetoothProfile .PRIORITY_ON ) {
2458+ msg .what = BluetoothDeviceProfileState .CONNECT_OTHER_PROFILES ;
2459+ msg .arg1 = BluetoothDeviceProfileState .CONNECT_HFP_OUTGOING ;
2460+ state .sendMessageDelayed (msg ,
2461+ BluetoothDeviceProfileState .CONNECT_OTHER_PROFILES_DELAY );
2462+ }
2463+ } else {
2464+ msg .what = BluetoothDeviceProfileState .CONNECT_A2DP_INCOMING ;
2465+ state .sendMessage (msg );
2466+ }
24462467 return true ;
24472468 }
24482469 return false ;
0 commit comments