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
This commit is contained in:
@@ -86,7 +86,7 @@ public final class BluetoothDeviceProfileState extends StateMachine {
|
||||
private static final int CONNECTION_ACCESS_REQUEST_REPLY = 104;
|
||||
private static final int CONNECTION_ACCESS_REQUEST_EXPIRY = 105;
|
||||
|
||||
private static final int CONNECT_OTHER_PROFILES_DELAY = 4000; // 4 secs
|
||||
public static final int CONNECT_OTHER_PROFILES_DELAY = 4000; // 4 secs
|
||||
private static final int CONNECTION_ACCESS_REQUEST_EXPIRY_TIMEOUT = 7000; // 7 secs
|
||||
private static final int CONNECTION_ACCESS_UNDEFINED = -1;
|
||||
private static final long INIT_INCOMING_REJECT_TIMER = 1000; // 1 sec
|
||||
|
||||
@@ -90,7 +90,7 @@ interface IBluetooth
|
||||
|
||||
boolean connectHeadset(String address);
|
||||
boolean disconnectHeadset(String address);
|
||||
boolean notifyIncomingConnection(String address);
|
||||
boolean notifyIncomingConnection(String address, boolean rejected);
|
||||
|
||||
// HID profile APIs
|
||||
boolean connectInputDevice(in BluetoothDevice device);
|
||||
|
||||
@@ -784,11 +784,12 @@ class BluetoothEventLoop {
|
||||
// machine. We don't handle AVCTP signals currently. We only send
|
||||
// intents for AVDTP state changes. We need to handle both of them in
|
||||
// some cases. For now, just don't move to incoming state in this case.
|
||||
mBluetoothService.notifyIncomingA2dpConnection(address);
|
||||
mBluetoothService.notifyIncomingA2dpConnection(address, true);
|
||||
} else {
|
||||
Log.i(TAG, "" + authorized +
|
||||
"Incoming A2DP / AVRCP connection from " + address);
|
||||
mA2dp.allowIncomingConnect(device, authorized);
|
||||
mBluetoothService.notifyIncomingA2dpConnection(address, false);
|
||||
}
|
||||
} else if (BluetoothUuid.isInputDevice(uuid)) {
|
||||
// We can have more than 1 input device connected.
|
||||
|
||||
@@ -89,7 +89,7 @@ public class BluetoothService extends IBluetooth.Stub {
|
||||
|
||||
private int mNativeData;
|
||||
private BluetoothEventLoop mEventLoop;
|
||||
private BluetoothHeadset mBluetoothHeadset;
|
||||
private BluetoothHeadset mHeadsetProxy;
|
||||
private BluetoothInputDevice mInputDevice;
|
||||
private BluetoothPan mPan;
|
||||
private boolean mIsAirplaneSensitive;
|
||||
@@ -605,6 +605,7 @@ public class BluetoothService extends IBluetooth.Stub {
|
||||
}
|
||||
mBondState.initBondState();
|
||||
initProfileState();
|
||||
getProfileProxy();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1766,8 +1767,8 @@ public class BluetoothService extends IBluetooth.Stub {
|
||||
|
||||
private void dumpHeadsetService(PrintWriter pw) {
|
||||
pw.println("\n--Headset Service--");
|
||||
if (mBluetoothHeadset != null) {
|
||||
List<BluetoothDevice> deviceList = mBluetoothHeadset.getConnectedDevices();
|
||||
if (mHeadsetProxy != null) {
|
||||
List<BluetoothDevice> deviceList = mHeadsetProxy.getConnectedDevices();
|
||||
if (deviceList.size() == 0) {
|
||||
pw.println("No headsets connected");
|
||||
} else {
|
||||
@@ -1775,21 +1776,20 @@ public class BluetoothService extends IBluetooth.Stub {
|
||||
pw.println("\ngetConnectedDevices[0] = " + device);
|
||||
dumpHeadsetConnectionState(pw, device);
|
||||
pw.println("getBatteryUsageHint() = " +
|
||||
mBluetoothHeadset.getBatteryUsageHint(device));
|
||||
mHeadsetProxy.getBatteryUsageHint(device));
|
||||
}
|
||||
|
||||
deviceList.clear();
|
||||
deviceList = mBluetoothHeadset.getDevicesMatchingConnectionStates(new int[] {
|
||||
deviceList = mHeadsetProxy.getDevicesMatchingConnectionStates(new int[] {
|
||||
BluetoothProfile.STATE_CONNECTED, BluetoothProfile.STATE_DISCONNECTED});
|
||||
pw.println("--Connected and Disconnected Headsets");
|
||||
for (BluetoothDevice device: deviceList) {
|
||||
pw.println(device);
|
||||
if (mBluetoothHeadset.isAudioConnected(device)) {
|
||||
if (mHeadsetProxy.isAudioConnected(device)) {
|
||||
pw.println("SCO audio connected to device:" + device);
|
||||
}
|
||||
}
|
||||
}
|
||||
mAdapter.closeProfileProxy(BluetoothProfile.HEADSET, mBluetoothHeadset);
|
||||
}
|
||||
|
||||
private void dumpInputDeviceProfile(PrintWriter pw) {
|
||||
@@ -1824,7 +1824,6 @@ public class BluetoothService extends IBluetooth.Stub {
|
||||
pw.println(device);
|
||||
}
|
||||
}
|
||||
mAdapter.closeProfileProxy(BluetoothProfile.INPUT_DEVICE, mBluetoothHeadset);
|
||||
}
|
||||
|
||||
private void dumpPanProfile(PrintWriter pw) {
|
||||
@@ -1862,7 +1861,7 @@ public class BluetoothService extends IBluetooth.Stub {
|
||||
|
||||
private void dumpHeadsetConnectionState(PrintWriter pw,
|
||||
BluetoothDevice device) {
|
||||
switch (mBluetoothHeadset.getConnectionState(device)) {
|
||||
switch (mHeadsetProxy.getConnectionState(device)) {
|
||||
case BluetoothHeadset.STATE_CONNECTING:
|
||||
pw.println("getConnectionState() = STATE_CONNECTING");
|
||||
break;
|
||||
@@ -1884,7 +1883,6 @@ public class BluetoothService extends IBluetooth.Stub {
|
||||
Integer pid = mServiceRecordToPid.get(handle).first;
|
||||
pw.println("\tpid " + pid + " handle " + Integer.toHexString(handle));
|
||||
}
|
||||
mAdapter.closeProfileProxy(BluetoothProfile.PAN, mBluetoothHeadset);
|
||||
}
|
||||
|
||||
private void dumpAclConnectedDevices(PrintWriter pw) {
|
||||
@@ -1927,11 +1925,16 @@ public class BluetoothService extends IBluetooth.Stub {
|
||||
}
|
||||
}
|
||||
|
||||
private void getProfileProxy() {
|
||||
mAdapter.getProfileProxy(mContext,
|
||||
mBluetoothProfileServiceListener, BluetoothProfile.HEADSET);
|
||||
}
|
||||
|
||||
private BluetoothProfile.ServiceListener mBluetoothProfileServiceListener =
|
||||
new BluetoothProfile.ServiceListener() {
|
||||
public void onServiceConnected(int profile, BluetoothProfile proxy) {
|
||||
if (profile == BluetoothProfile.HEADSET) {
|
||||
mBluetoothHeadset = (BluetoothHeadset) proxy;
|
||||
mHeadsetProxy = (BluetoothHeadset) proxy;
|
||||
} else if (profile == BluetoothProfile.INPUT_DEVICE) {
|
||||
mInputDevice = (BluetoothInputDevice) proxy;
|
||||
} else if (profile == BluetoothProfile.PAN) {
|
||||
@@ -1940,7 +1943,7 @@ public class BluetoothService extends IBluetooth.Stub {
|
||||
}
|
||||
public void onServiceDisconnected(int profile) {
|
||||
if (profile == BluetoothProfile.HEADSET) {
|
||||
mBluetoothHeadset = null;
|
||||
mHeadsetProxy = null;
|
||||
} else if (profile == BluetoothProfile.INPUT_DEVICE) {
|
||||
mInputDevice = null;
|
||||
} else if (profile == BluetoothProfile.PAN) {
|
||||
@@ -2424,25 +2427,43 @@ public class BluetoothService extends IBluetooth.Stub {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean notifyIncomingConnection(String address) {
|
||||
BluetoothDeviceProfileState state =
|
||||
mDeviceProfileState.get(address);
|
||||
public boolean notifyIncomingConnection(String address, boolean rejected) {
|
||||
BluetoothDeviceProfileState state = mDeviceProfileState.get(address);
|
||||
if (state != null) {
|
||||
Message msg = new Message();
|
||||
msg.what = BluetoothDeviceProfileState.CONNECT_HFP_INCOMING;
|
||||
state.sendMessage(msg);
|
||||
if (rejected) {
|
||||
if (mA2dpService.getPriority(getRemoteDevice(address)) >=
|
||||
BluetoothProfile.PRIORITY_ON) {
|
||||
msg.what = BluetoothDeviceProfileState.CONNECT_OTHER_PROFILES;
|
||||
msg.arg1 = BluetoothDeviceProfileState.CONNECT_A2DP_OUTGOING;
|
||||
state.sendMessageDelayed(msg,
|
||||
BluetoothDeviceProfileState.CONNECT_OTHER_PROFILES_DELAY);
|
||||
}
|
||||
} else {
|
||||
msg.what = BluetoothDeviceProfileState.CONNECT_HFP_INCOMING;
|
||||
state.sendMessage(msg);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/*package*/ boolean notifyIncomingA2dpConnection(String address) {
|
||||
BluetoothDeviceProfileState state =
|
||||
mDeviceProfileState.get(address);
|
||||
/*package*/ boolean notifyIncomingA2dpConnection(String address, boolean rejected) {
|
||||
BluetoothDeviceProfileState state = mDeviceProfileState.get(address);
|
||||
if (state != null) {
|
||||
Message msg = new Message();
|
||||
msg.what = BluetoothDeviceProfileState.CONNECT_A2DP_INCOMING;
|
||||
state.sendMessage(msg);
|
||||
if (rejected) {
|
||||
if (mHeadsetProxy.getPriority(getRemoteDevice(address)) >=
|
||||
BluetoothProfile.PRIORITY_ON) {
|
||||
msg.what = BluetoothDeviceProfileState.CONNECT_OTHER_PROFILES;
|
||||
msg.arg1 = BluetoothDeviceProfileState.CONNECT_HFP_OUTGOING;
|
||||
state.sendMessageDelayed(msg,
|
||||
BluetoothDeviceProfileState.CONNECT_OTHER_PROFILES_DELAY);
|
||||
}
|
||||
} else {
|
||||
msg.what = BluetoothDeviceProfileState.CONNECT_A2DP_INCOMING;
|
||||
state.sendMessage(msg);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user