diff options
| author | Dmitry Grinberg <dmitrygr@google.com> | 2013-08-09 15:22:59 -0700 |
|---|---|---|
| committer | Mike Lockwood <lockwood@google.com> | 2013-09-06 12:27:12 -0700 |
| commit | 008ce9e07b5e58c5ab31c5d73ec3d1ad1a6cf605 (patch) | |
| tree | 9012360a9a2cf8af8064e62629424bf7e491f4dd /framework/java/android/bluetooth/BluetoothAdapter.java | |
| parent | c2fe88048c9cf8b7f2fc48b57344f105a7b3f660 (diff) | |
Allow L2CAP sockets
Change-Id: Icb498e6c0430789b6168bec3beb1d4650e4f1238
Diffstat (limited to 'framework/java/android/bluetooth/BluetoothAdapter.java')
| -rw-r--r-- | framework/java/android/bluetooth/BluetoothAdapter.java | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/framework/java/android/bluetooth/BluetoothAdapter.java b/framework/java/android/bluetooth/BluetoothAdapter.java index e062fa8b4e..676fd1f329 100644 --- a/framework/java/android/bluetooth/BluetoothAdapter.java +++ b/framework/java/android/bluetooth/BluetoothAdapter.java @@ -924,6 +924,42 @@ public final class BluetoothAdapter { } /** + * Create a listening, L2CAP Bluetooth socket. + * <p>A remote device connecting to this socket will optionally be + * authenticated and communication on this socket will optionally be + * encrypted. + * <p>Use {@link BluetoothServerSocket#accept} to retrieve incoming + * connections from a listening {@link BluetoothServerSocket}. + * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN} + * @param secure whether security and authentication are required + * @param fixedChannel whether we're looking for a PSM-based connection or a fixed channel + * @param channel L2CAP PSM or channel to use + * @return a listening L2CAP BluetoothServerSocket + * @throws IOException on error, for example Bluetooth not available, or + * insufficient permissions, or channel in use. + * @hide + */ + public BluetoothServerSocket listenUsingL2CapOn(boolean secure, boolean fixedChannel, + int channel) throws IOException { + BluetoothServerSocket socket; + + if (fixedChannel) { + channel |= BluetoothSocket.PORT_MASK_FIXED_CHAN; + } + + socket = new BluetoothServerSocket( + BluetoothSocket.TYPE_L2CAP, secure, secure, channel); + int errno = socket.mSocket.bindListen(); + if (errno != 0) { + //TODO(BT): Throw the same exception error code + // that the previous code was using. + //socket.mSocket.throwErrnoNative(errno); + throw new IOException("Error: " + errno); + } + return socket; + } + + /** * Create a listening, secure RFCOMM Bluetooth socket. * <p>A remote device connecting to this socket will be authenticated and * communication on this socket will be encrypted. |
