Skip to content

Commit 98f06da

Browse files
author
Matthew Xie
committed
Send CONNECT_OTHER_PROFILE to Device profile for hfp and a2dp incoming connect
Send CONNECT_OTHER_PROFILE to Device profile for low priority hfp and a2dp incoming connect. In the case when HFP autoconnect is off but a2dp autoconnect is on, if HF autoconnect to HFP, phone will reject HFP but connect a2dp. Before this fix, phone reject HFP. A2dp will not get connected unless the HF do media auto-connect, which most carkits do not do. Also do similar change for incoming a2dp connection bug 5091838 Change-Id: Ife1815f527bcd94e0d9ffc645028484fa9c49a43
1 parent 9490fe4 commit 98f06da

File tree

4 files changed

+47
-25
lines changed

4 files changed

+47
-25
lines changed

core/java/android/bluetooth/BluetoothDeviceProfileState.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public final class BluetoothDeviceProfileState extends StateMachine {
8686
private static final int CONNECTION_ACCESS_REQUEST_REPLY = 104;
8787
private static final int CONNECTION_ACCESS_REQUEST_EXPIRY = 105;
8888

89-
private static final int CONNECT_OTHER_PROFILES_DELAY = 4000; // 4 secs
89+
public static final int CONNECT_OTHER_PROFILES_DELAY = 4000; // 4 secs
9090
private static final int CONNECTION_ACCESS_REQUEST_EXPIRY_TIMEOUT = 7000; // 7 secs
9191
private static final int CONNECTION_ACCESS_UNDEFINED = -1;
9292
private static final long INIT_INCOMING_REJECT_TIMER = 1000; // 1 sec

core/java/android/bluetooth/IBluetooth.aidl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ interface IBluetooth
9090

9191
boolean connectHeadset(String address);
9292
boolean disconnectHeadset(String address);
93-
boolean notifyIncomingConnection(String address);
93+
boolean notifyIncomingConnection(String address, boolean rejected);
9494

9595
// HID profile APIs
9696
boolean connectInputDevice(in BluetoothDevice device);

core/java/android/server/BluetoothEventLoop.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -784,11 +784,12 @@ private void onAgentAuthorize(String objectPath, String deviceUuid, int nativeD
784784
// machine. We don't handle AVCTP signals currently. We only send
785785
// intents for AVDTP state changes. We need to handle both of them in
786786
// some cases. For now, just don't move to incoming state in this case.
787-
mBluetoothService.notifyIncomingA2dpConnection(address);
787+
mBluetoothService.notifyIncomingA2dpConnection(address, true);
788788
} else {
789789
Log.i(TAG, "" + authorized +
790790
"Incoming A2DP / AVRCP connection from " + address);
791791
mA2dp.allowIncomingConnect(device, authorized);
792+
mBluetoothService.notifyIncomingA2dpConnection(address, false);
792793
}
793794
} else if (BluetoothUuid.isInputDevice(uuid)) {
794795
// We can have more than 1 input device connected.

core/java/android/server/BluetoothService.java

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -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("\ngetConnectedDevices[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("\tpid " + 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

Comments
 (0)