summaryrefslogtreecommitdiffstats
path: root/core/java/android/bluetooth/BluetoothAdapter.java
diff options
context:
space:
mode:
authorJaikumar Ganesh <jaikumar@google.com>2010-12-23 12:57:02 -0800
committerJaikumar Ganesh <jaikumar@google.com>2010-12-23 13:05:23 -0800
commit6eef14a7fcf6b6338f21f760830abf369ca0137d (patch)
tree3ba9df58602dc4b69d9be200908e9c5745766043 /core/java/android/bluetooth/BluetoothAdapter.java
parent057898a9b5d50e0d8eed52bdaa74a5f17bf85c1a (diff)
downloadframeworks_base-6eef14a7fcf6b6338f21f760830abf369ca0137d.zip
frameworks_base-6eef14a7fcf6b6338f21f760830abf369ca0137d.tar.gz
frameworks_base-6eef14a7fcf6b6338f21f760830abf369ca0137d.tar.bz2
Expose insecure rfcomm Bluetooth API.
This complements the secure rfcomm API. The link key is unauthenticated and is subject to MITM attacks. The link key may be encrypted depending on the type of Bluetooth device. This helps apps which don't need the extra security or have their own security layer built on top of the rfcomm link. Change-Id: I71b2fa8de469ef98faa204b4dafac18a8e21d0d9
Diffstat (limited to 'core/java/android/bluetooth/BluetoothAdapter.java')
-rw-r--r--core/java/android/bluetooth/BluetoothAdapter.java38
1 files changed, 37 insertions, 1 deletions
diff --git a/core/java/android/bluetooth/BluetoothAdapter.java b/core/java/android/bluetooth/BluetoothAdapter.java
index 32df4e8..b2185ad 100644
--- a/core/java/android/bluetooth/BluetoothAdapter.java
+++ b/core/java/android/bluetooth/BluetoothAdapter.java
@@ -868,6 +868,42 @@ public final class BluetoothAdapter {
*/
public BluetoothServerSocket listenUsingRfcommWithServiceRecord(String name, UUID uuid)
throws IOException {
+ return createNewRfcommSocketAndRecord(name, uuid, true, true);
+ }
+
+ /**
+ * Create a listening, insecure RFCOMM Bluetooth socket with Service Record.
+ * <p>The link key will be unauthenticated i.e the communication is
+ * vulnerable to Man In the Middle attacks. For Bluetooth 2.1 devices,
+ * the link key will be encrypted, as encryption is mandartory.
+ * For legacy devices (pre Bluetooth 2.1 devices) the link key will not
+ * be encrypted. Use {@link #listenUsingRfcommWithServiceRecord}, if an
+ * encrypted and authenticated communication channel is desired.
+ * <p>Use {@link BluetoothServerSocket#accept} to retrieve incoming
+ * connections from a listening {@link BluetoothServerSocket}.
+ * <p>The system will assign an unused RFCOMM channel to listen on.
+ * <p>The system will also register a Service Discovery
+ * Protocol (SDP) record with the local SDP server containing the specified
+ * UUID, service name, and auto-assigned channel. Remote Bluetooth devices
+ * can use the same UUID to query our SDP server and discover which channel
+ * to connect to. This SDP record will be removed when this socket is
+ * closed, or if this application closes unexpectedly.
+ * <p>Use {@link BluetoothDevice#createRfcommSocketToServiceRecord} to
+ * connect to this socket from another device using the same {@link UUID}.
+ * <p>Requires {@link android.Manifest.permission#BLUETOOTH}
+ * @param name service name for SDP record
+ * @param uuid uuid for SDP record
+ * @return a listening RFCOMM BluetoothServerSocket
+ * @throws IOException on error, for example Bluetooth not available, or
+ * insufficient permissions, or channel in use.
+ */
+ public BluetoothServerSocket listenUsingInsecureRfcommWithServiceRecord(String name, UUID uuid)
+ throws IOException {
+ return createNewRfcommSocketAndRecord(name, uuid, false, false);
+ }
+
+ private BluetoothServerSocket createNewRfcommSocketAndRecord(String name, UUID uuid,
+ boolean auth, boolean encrypt) throws IOException {
RfcommChannelPicker picker = new RfcommChannelPicker(uuid);
BluetoothServerSocket socket;
@@ -881,7 +917,7 @@ public final class BluetoothAdapter {
}
socket = new BluetoothServerSocket(
- BluetoothSocket.TYPE_RFCOMM, true, true, channel);
+ BluetoothSocket.TYPE_RFCOMM, auth, encrypt, channel);
errno = socket.mSocket.bindListen();
if (errno == 0) {
if (DBG) Log.d(TAG, "listening on RFCOMM channel " + channel);