diff --git a/core/java/android/bluetooth/BluetoothDeviceProfileState.java b/core/java/android/bluetooth/BluetoothDeviceProfileState.java index 095cd110eb794..316c474c30e29 100644 --- a/core/java/android/bluetooth/BluetoothDeviceProfileState.java +++ b/core/java/android/bluetooth/BluetoothDeviceProfileState.java @@ -1048,12 +1048,12 @@ public final class BluetoothDeviceProfileState extends StateMachine { break; case CONNECT_HID_INCOMING: if (!accept) { - ret = mService.allowIncomingHidConnect(mDevice, false); + ret = mService.allowIncomingProfileConnect(mDevice, false); sendMessage(TRANSITION_TO_STABLE); updateIncomingAllowedTimer(); } else { writeTimerValue(0); - ret = mService.allowIncomingHidConnect(mDevice, true); + ret = mService.allowIncomingProfileConnect(mDevice, true); } break; default: diff --git a/core/java/android/bluetooth/BluetoothInputDevice.java b/core/java/android/bluetooth/BluetoothInputDevice.java index f6757d9bd3602..282b70a42c814 100644 --- a/core/java/android/bluetooth/BluetoothInputDevice.java +++ b/core/java/android/bluetooth/BluetoothInputDevice.java @@ -308,28 +308,6 @@ public final class BluetoothInputDevice implements BluetoothProfile { return BluetoothProfile.PRIORITY_OFF; } - /** - * Allow or disallow incoming connection - * @param device Input device - * @param allow true / false - * @return Success or Failure of the operation - * @hide - */ - public boolean allowIncomingConnect(BluetoothDevice device, boolean allow) { - if (DBG) log("allowIncomingConnect(" + device + ", " + allow + ")"); - - if (mService == null || !isEnabled() || !isValidDevice(device)) { - return false; - } - try { - mService.allowIncomingHidConnect(device, allow); - } catch (RemoteException e) { - Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable())); - return false; - } - return true; - } - private boolean isEnabled() { if (mAdapter.getState() == BluetoothAdapter.STATE_ON) return true; return false; diff --git a/core/java/android/bluetooth/IBluetooth.aidl b/core/java/android/bluetooth/IBluetooth.aidl index ddede9c7d10a4..48dfed82caad3 100644 --- a/core/java/android/bluetooth/IBluetooth.aidl +++ b/core/java/android/bluetooth/IBluetooth.aidl @@ -85,6 +85,7 @@ interface IBluetooth int addRfcommServiceRecord(in String serviceName, in ParcelUuid uuid, int channel, IBinder b); void removeServiceRecord(int handle); + boolean allowIncomingProfileConnect(in BluetoothDevice device, boolean value); boolean connectHeadset(String address); boolean disconnectHeadset(String address); @@ -98,7 +99,6 @@ interface IBluetooth int getInputDeviceConnectionState(in BluetoothDevice device); boolean setInputDevicePriority(in BluetoothDevice device, int priority); int getInputDevicePriority(in BluetoothDevice device); - boolean allowIncomingHidConnect(in BluetoothDevice device, boolean value); boolean isTetheringOn(); void setBluetoothTethering(boolean value); diff --git a/core/java/android/server/BluetoothEventLoop.java b/core/java/android/server/BluetoothEventLoop.java index 9b9196a43fd4b..afc96768c38d8 100644 --- a/core/java/android/server/BluetoothEventLoop.java +++ b/core/java/android/server/BluetoothEventLoop.java @@ -54,7 +54,6 @@ class BluetoothEventLoop { private final BluetoothAdapter mAdapter; private final BluetoothAdapterStateMachine mBluetoothState; private BluetoothA2dp mA2dp; - private BluetoothInputDevice mInputDevice; private final Context mContext; // The WakeLock is used for bringing up the LCD during a pairing request // from remote device when Android is in Suspend state. @@ -134,15 +133,11 @@ class BluetoothEventLoop { public void onServiceConnected(int profile, BluetoothProfile proxy) { if (profile == BluetoothProfile.A2DP) { mA2dp = (BluetoothA2dp) proxy; - } else if (profile == BluetoothProfile.INPUT_DEVICE) { - mInputDevice = (BluetoothInputDevice) proxy; } } public void onServiceDisconnected(int profile) { if (profile == BluetoothProfile.A2DP) { mA2dp = null; - } else if (profile == BluetoothProfile.INPUT_DEVICE) { - mInputDevice = null; } } }; @@ -803,21 +798,25 @@ class BluetoothEventLoop { "Incoming A2DP / AVRCP connection from " + address); mA2dp.allowIncomingConnect(device, authorized); } - } else if (mInputDevice != null && BluetoothUuid.isInputDevice(uuid)) { + } else if (BluetoothUuid.isInputDevice(uuid)) { // We can have more than 1 input device connected. - authorized = mInputDevice.getPriority(device) > BluetoothInputDevice.PRIORITY_OFF; - if (authorized) { - Log.i(TAG, "First check pass for incoming HID connection from " + address); - // notify profile state change - mBluetoothService.notifyIncomingHidConnection(address); - } else { - Log.i(TAG, "Rejecting incoming HID connection from " + address); - mBluetoothService.allowIncomingHidConnect(device, authorized); - } - } else if (BluetoothUuid.isBnep(uuid) && mBluetoothService.allowIncomingTethering()){ - authorized = true; + authorized = mBluetoothService.getInputDevicePriority(device) > + BluetoothInputDevice.PRIORITY_OFF; + if (authorized) { + Log.i(TAG, "First check pass for incoming HID connection from " + address); + // notify profile state change + mBluetoothService.notifyIncomingHidConnection(address); + } else { + Log.i(TAG, "Rejecting incoming HID connection from " + address); + mBluetoothService.allowIncomingProfileConnect(device, authorized); + } + } else if (BluetoothUuid.isBnep(uuid)) { + // PAN doesn't go to the state machine, accept or reject from here + authorized = mBluetoothService.allowIncomingTethering(); + mBluetoothService.allowIncomingProfileConnect(device, authorized); } else { Log.i(TAG, "Rejecting incoming " + deviceUuid + " connection from " + address); + mBluetoothService.allowIncomingProfileConnect(device, authorized); } log("onAgentAuthorize(" + objectPath + ", " + deviceUuid + ") = " + authorized); } diff --git a/core/java/android/server/BluetoothService.java b/core/java/android/server/BluetoothService.java index 0d95a58b9c1d0..8419f23077c13 100755 --- a/core/java/android/server/BluetoothService.java +++ b/core/java/android/server/BluetoothService.java @@ -2113,7 +2113,16 @@ public class BluetoothService extends IBluetooth.Stub { } } - public boolean allowIncomingHidConnect(BluetoothDevice device, boolean allow) { + /** + * Handle incoming profile acceptance for profiles handled by Bluetooth Service, + * currently PAN and HID. This also is the catch all for all rejections for profiles + * that is not supported. + * + * @param device - Bluetooth Device + * @param allow - true / false + * @return + */ + public boolean allowIncomingProfileConnect(BluetoothDevice device, boolean allow) { mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM, "Need BLUETOOTH_ADMIN permission"); String address = device.getAddress(); @@ -2123,11 +2132,11 @@ public class BluetoothService extends IBluetooth.Stub { Integer data = getAuthorizationAgentRequestData(address); if (data == null) { - Log.w(TAG, "allowIncomingHidConnect(" + device + + Log.w(TAG, "allowIncomingProfileConnect(" + device + ") called but no native data available"); return false; } - if (DBG) log("allowIncomingHidConnect: " + device + " : " + allow + " : " + data); + if (DBG) log("allowIncomingProfileConnect: " + device + " : " + allow + " : " + data); return setAuthorizationNative(address, allow, data.intValue()); }