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