From 53f441bf8d89667e099302d506c6f07ed1201db1 Mon Sep 17 00:00:00 2001 From: Nick Pelly Date: Tue, 26 May 2009 19:13:43 -0700 Subject: New BluetoothSocket API. Modeled on blocking java.net.Socket and java.net.ServerSocket library. Public interface is: public final class BluetoothSocket implements Closeable { public static BluetoothSocket createRfcommSocket(String address, int port) throws IOException; public static BluetoothSocket createInsecureRfcommSocket(String address, int port) throws IOException; public void connect() throws IOException; public void close() throws IOException; public String getAddress(); public InputStream getInputStream() throws IOException; public OutputStream getOutputStream() throws IOException; } public final class BluetoothServerSocket implements Closeable { public static BluetoothServerSocket listenUsingRfcommOn(int port) throws IOException; public static BluetoothServerSocket listenUsingUnsecureRfcommOn(int port) throws IOException; public BluetoothSocket accept() throws IOException; public BluetoothSocket accept(int timeout) throws IOException; public void close() throws IOException; } --- .../android/bluetooth/BluetoothServerSocket.java | 124 +++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 framework/java/android/bluetooth/BluetoothServerSocket.java (limited to 'framework/java/android/bluetooth/BluetoothServerSocket.java') diff --git a/framework/java/android/bluetooth/BluetoothServerSocket.java b/framework/java/android/bluetooth/BluetoothServerSocket.java new file mode 100644 index 0000000000..ca467011c9 --- /dev/null +++ b/framework/java/android/bluetooth/BluetoothServerSocket.java @@ -0,0 +1,124 @@ +/* + * Copyright (C) 2009 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.bluetooth; + +import java.io.Closeable; +import java.io.IOException; + +/** + * Server (listening) Bluetooth Socket. + * + * Currently only supports RFCOMM sockets. + * + * RFCOMM is a connection orientated, streaming transport over Bluetooth. It is + * also known as the Serial Port Profile (SPP). + * + * TODO: Consider implementing SCO and L2CAP sockets. + * TODO: Clean up javadoc grammer and formatting. + * TODO: Remove @hide + * @hide + */ +public final class BluetoothServerSocket implements Closeable { + private final BluetoothSocket mSocket; + + /** + * Construct a listening, secure RFCOMM server socket. + * The remote device connecting to this socket will be authenticated and + * communication on this socket will be encrypted. + * Call #accept to retrieve connections to this socket. + * @return An RFCOMM BluetoothServerSocket + * @throws IOException On error, for example Bluetooth not available, or + * insufficient permissions. + */ + public static BluetoothServerSocket listenUsingRfcommOn(int port) throws IOException { + BluetoothServerSocket socket = new BluetoothServerSocket(true, true); + try { + socket.mSocket.bindListenNative(port); + } catch (IOException e) { + try { + socket.close(); + } catch (IOException e2) { } + throw e; + } + return socket; + } + + /** + * Construct an unencrypted, unauthenticated, RFCOMM server socket. + * Call #accept to retrieve connections to this socket. + * @return An RFCOMM BluetoothServerSocket + * @throws IOException On error, for example Bluetooth not available, or + * insufficient permissions. + */ + public static BluetoothServerSocket listenUsingInsecureRfcommOn(int port) throws IOException { + BluetoothServerSocket socket = new BluetoothServerSocket(false, false); + try { + socket.mSocket.bindListenNative(port); + } catch (IOException e) { + try { + socket.close(); + } catch (IOException e2) { } + throw e; + } + return socket; + } + + /** + * Construct a socket for incoming connections. + * @param auth Require the remote device to be authenticated + * @param encrypt Require the connection to be encrypted + * @throws IOException On error, for example Bluetooth not available, or + * insufficient priveleges + */ + private BluetoothServerSocket(boolean auth, boolean encrypt) throws IOException { + mSocket = new BluetoothSocket(-1, auth, encrypt, null, -1); + } + + /** + * Block until a connection is established. + * Returns a connected #BluetoothSocket. This server socket can be reused + * for subsequent incoming connections by calling #accept repeatedly. + * #close can be used to abort this call from another thread. + * @return A connected #BluetoothSocket + * @throws IOException On error, for example this call was aborted + */ + public BluetoothSocket accept() throws IOException { + return accept(-1); + } + + /** + * Block until a connection is established, with timeout. + * Returns a connected #BluetoothSocket. This server socket can be reused + * for subsequent incoming connections by calling #accept repeatedly. + * #close can be used to abort this call from another thread. + * @return A connected #BluetoothSocket + * @throws IOException On error, for example this call was aborted, or + * timeout + */ + public BluetoothSocket accept(int timeout) throws IOException { + return mSocket.acceptNative(timeout); + } + + /** + * Closes this socket. + * This will cause other blocking calls on this socket to immediately + * throw an IOException. + */ + public void close() throws IOException { + mSocket.closeNative(); + } +} -- cgit v1.2.3 From cb32d7c30a5ae45bc6e8a81ae59b1e75bdff0c74 Mon Sep 17 00:00:00 2001 From: Nick Pelly Date: Tue, 2 Jun 2009 15:57:18 -0700 Subject: Implement and expose SCO socket support in BluetoothSocket.java. Implement L2CAP socket support, but do not expose it (untested). NEXT: Switch to Builder style constructor instead of factory method. --- .../android/bluetooth/BluetoothServerSocket.java | 44 +++++++++++++++++----- 1 file changed, 35 insertions(+), 9 deletions(-) (limited to 'framework/java/android/bluetooth/BluetoothServerSocket.java') diff --git a/framework/java/android/bluetooth/BluetoothServerSocket.java b/framework/java/android/bluetooth/BluetoothServerSocket.java index ca467011c9..f3baeab18d 100644 --- a/framework/java/android/bluetooth/BluetoothServerSocket.java +++ b/framework/java/android/bluetooth/BluetoothServerSocket.java @@ -27,7 +27,7 @@ import java.io.IOException; * RFCOMM is a connection orientated, streaming transport over Bluetooth. It is * also known as the Serial Port Profile (SPP). * - * TODO: Consider implementing SCO and L2CAP sockets. + * TODO: Consider exposing L2CAP sockets. * TODO: Clean up javadoc grammer and formatting. * TODO: Remove @hide * @hide @@ -45,9 +45,10 @@ public final class BluetoothServerSocket implements Closeable { * insufficient permissions. */ public static BluetoothServerSocket listenUsingRfcommOn(int port) throws IOException { - BluetoothServerSocket socket = new BluetoothServerSocket(true, true); + BluetoothServerSocket socket = new BluetoothServerSocket( + BluetoothSocket.TYPE_RFCOMM, true, true, port); try { - socket.mSocket.bindListenNative(port); + socket.mSocket.bindListenNative(); } catch (IOException e) { try { socket.close(); @@ -65,9 +66,31 @@ public final class BluetoothServerSocket implements Closeable { * insufficient permissions. */ public static BluetoothServerSocket listenUsingInsecureRfcommOn(int port) throws IOException { - BluetoothServerSocket socket = new BluetoothServerSocket(false, false); + BluetoothServerSocket socket = new BluetoothServerSocket( + BluetoothSocket.TYPE_RFCOMM, false, false, port); try { - socket.mSocket.bindListenNative(port); + socket.mSocket.bindListenNative(); + } catch (IOException e) { + try { + socket.close(); + } catch (IOException e2) { } + throw e; + } + return socket; + } + + /** + * Construct a SCO server socket. + * Call #accept to retrieve connections to this socket. + * @return A SCO BluetoothServerSocket + * @throws IOException On error, for example Bluetooth not available, or + * insufficient permissions. + */ + public static BluetoothServerSocket listenUsingScoOn() throws IOException { + BluetoothServerSocket socket = new BluetoothServerSocket( + BluetoothSocket.TYPE_SCO, false, false, -1); + try { + socket.mSocket.bindListenNative(); } catch (IOException e) { try { socket.close(); @@ -79,13 +102,16 @@ public final class BluetoothServerSocket implements Closeable { /** * Construct a socket for incoming connections. - * @param auth Require the remote device to be authenticated - * @param encrypt Require the connection to be encrypted + * @param type type of socket + * @param auth require the remote device to be authenticated + * @param encrypt require the connection to be encrypted + * @param port remote port * @throws IOException On error, for example Bluetooth not available, or * insufficient priveleges */ - private BluetoothServerSocket(boolean auth, boolean encrypt) throws IOException { - mSocket = new BluetoothSocket(-1, auth, encrypt, null, -1); + private BluetoothServerSocket(int type, boolean auth, boolean encrypt, int port) + throws IOException { + mSocket = new BluetoothSocket(type, -1, auth, encrypt, null, port); } /** -- cgit v1.2.3 From 2d66488e7d7aeb87e4f7385dfe1a6c800c08391b Mon Sep 17 00:00:00 2001 From: Nick Pelly Date: Fri, 14 Aug 2009 18:33:38 -0700 Subject: Bluetooth: API change. Split BluetoothDevice into BluetoothDevice and BluetoothAdapter. BluetoothAdapter: Represents the local BT adapter. Operations on the local adapter (start a scan, etc). BluetoothDevice: Represents a remote BT device. Operations on remote devices (pair, connect, etc). IBluetoothDevice.aidl -> Bluetooth.aidl BluetoothDeviceService.java -> BluetoothDeviceService.java TODO: Javadoc --- .../android/bluetooth/BluetoothServerSocket.java | 69 +--------------------- 1 file changed, 2 insertions(+), 67 deletions(-) (limited to 'framework/java/android/bluetooth/BluetoothServerSocket.java') diff --git a/framework/java/android/bluetooth/BluetoothServerSocket.java b/framework/java/android/bluetooth/BluetoothServerSocket.java index f3baeab18d..8be300b041 100644 --- a/framework/java/android/bluetooth/BluetoothServerSocket.java +++ b/framework/java/android/bluetooth/BluetoothServerSocket.java @@ -33,72 +33,7 @@ import java.io.IOException; * @hide */ public final class BluetoothServerSocket implements Closeable { - private final BluetoothSocket mSocket; - - /** - * Construct a listening, secure RFCOMM server socket. - * The remote device connecting to this socket will be authenticated and - * communication on this socket will be encrypted. - * Call #accept to retrieve connections to this socket. - * @return An RFCOMM BluetoothServerSocket - * @throws IOException On error, for example Bluetooth not available, or - * insufficient permissions. - */ - public static BluetoothServerSocket listenUsingRfcommOn(int port) throws IOException { - BluetoothServerSocket socket = new BluetoothServerSocket( - BluetoothSocket.TYPE_RFCOMM, true, true, port); - try { - socket.mSocket.bindListenNative(); - } catch (IOException e) { - try { - socket.close(); - } catch (IOException e2) { } - throw e; - } - return socket; - } - - /** - * Construct an unencrypted, unauthenticated, RFCOMM server socket. - * Call #accept to retrieve connections to this socket. - * @return An RFCOMM BluetoothServerSocket - * @throws IOException On error, for example Bluetooth not available, or - * insufficient permissions. - */ - public static BluetoothServerSocket listenUsingInsecureRfcommOn(int port) throws IOException { - BluetoothServerSocket socket = new BluetoothServerSocket( - BluetoothSocket.TYPE_RFCOMM, false, false, port); - try { - socket.mSocket.bindListenNative(); - } catch (IOException e) { - try { - socket.close(); - } catch (IOException e2) { } - throw e; - } - return socket; - } - - /** - * Construct a SCO server socket. - * Call #accept to retrieve connections to this socket. - * @return A SCO BluetoothServerSocket - * @throws IOException On error, for example Bluetooth not available, or - * insufficient permissions. - */ - public static BluetoothServerSocket listenUsingScoOn() throws IOException { - BluetoothServerSocket socket = new BluetoothServerSocket( - BluetoothSocket.TYPE_SCO, false, false, -1); - try { - socket.mSocket.bindListenNative(); - } catch (IOException e) { - try { - socket.close(); - } catch (IOException e2) { } - throw e; - } - return socket; - } + /*package*/ final BluetoothSocket mSocket; /** * Construct a socket for incoming connections. @@ -109,7 +44,7 @@ public final class BluetoothServerSocket implements Closeable { * @throws IOException On error, for example Bluetooth not available, or * insufficient priveleges */ - private BluetoothServerSocket(int type, boolean auth, boolean encrypt, int port) + /*package*/ BluetoothServerSocket(int type, boolean auth, boolean encrypt, int port) throws IOException { mSocket = new BluetoothSocket(type, -1, auth, encrypt, null, port); } -- cgit v1.2.3 From 753da539da89aac6762ef2183680205f8fd4e95a Mon Sep 17 00:00:00 2001 From: Nick Pelly Date: Wed, 19 Aug 2009 11:00:00 -0700 Subject: API CHANGE Javadoc, and unhide the first pieces of the Bluetooth API. With this commit there is enough public API to connect and use an RFCOMM connection between Bluetooth devices. --- .../android/bluetooth/BluetoothServerSocket.java | 57 ++++++++++++++-------- 1 file changed, 37 insertions(+), 20 deletions(-) (limited to 'framework/java/android/bluetooth/BluetoothServerSocket.java') diff --git a/framework/java/android/bluetooth/BluetoothServerSocket.java b/framework/java/android/bluetooth/BluetoothServerSocket.java index 8be300b041..e653c23295 100644 --- a/framework/java/android/bluetooth/BluetoothServerSocket.java +++ b/framework/java/android/bluetooth/BluetoothServerSocket.java @@ -20,17 +20,31 @@ import java.io.Closeable; import java.io.IOException; /** - * Server (listening) Bluetooth Socket. + * A listening Bluetooth socket. * - * Currently only supports RFCOMM sockets. + *

The interface for Bluetooth Sockets is similar to that of TCP sockets: + * {@link java.net.Socket} and {@link java.net.ServerSocket}. On the server + * side, use a {@link BluetoothServerSocket} to create a listening server + * socket. It will return a new, connected {@link BluetoothSocket} on an + * accepted connection. On the client side, use the same + * {@link BluetoothSocket} object to both intiate the outgoing connection, + * and to manage the connected socket. * - * RFCOMM is a connection orientated, streaming transport over Bluetooth. It is - * also known as the Serial Port Profile (SPP). + *

The most common type of Bluetooth Socket is RFCOMM. RFCOMM is a + * connection orientated, streaming transport over Bluetooth. It is also known + * as the Serial Port Profile (SPP). * - * TODO: Consider exposing L2CAP sockets. - * TODO: Clean up javadoc grammer and formatting. - * TODO: Remove @hide - * @hide + *

Use {@link BluetoothDevice#createRfcommSocket} to create a new {@link + * BluetoothSocket} ready for an outgoing connection to a remote + * {@link BluetoothDevice}. + * + *

Use {@link BluetoothAdapter#listenUsingRfcommOn} to create a listening + * {@link BluetoothServerSocket} ready for incoming connections to the local + * {@link BluetoothAdapter}. + * + *

{@link BluetoothSocket} and {@link BluetoothServerSocket} are thread + * safe. In particular, {@link #close} will always immediately abort ongoing + * operations and close the socket. */ public final class BluetoothServerSocket implements Closeable { /*package*/ final BluetoothSocket mSocket; @@ -51,11 +65,13 @@ public final class BluetoothServerSocket implements Closeable { /** * Block until a connection is established. - * Returns a connected #BluetoothSocket. This server socket can be reused - * for subsequent incoming connections by calling #accept repeatedly. - * #close can be used to abort this call from another thread. - * @return A connected #BluetoothSocket - * @throws IOException On error, for example this call was aborted + *

Returns a connected {@link BluetoothSocket} on successful connection. + *

Once this call returns, it can be called again to accept subsequent + * incoming connections. + *

{@link #close} can be used to abort this call from another thread. + * @return a connected {@link BluetoothSocket} + * @throws IOException on error, for example this call was aborted, or + * timeout */ public BluetoothSocket accept() throws IOException { return accept(-1); @@ -63,11 +79,12 @@ public final class BluetoothServerSocket implements Closeable { /** * Block until a connection is established, with timeout. - * Returns a connected #BluetoothSocket. This server socket can be reused - * for subsequent incoming connections by calling #accept repeatedly. - * #close can be used to abort this call from another thread. - * @return A connected #BluetoothSocket - * @throws IOException On error, for example this call was aborted, or + *

Returns a connected {@link BluetoothSocket} on successful connection. + *

Once this call returns, it can be called again to accept subsequent + * incoming connections. + *

{@link #close} can be used to abort this call from another thread. + * @return a connected {@link BluetoothSocket} + * @throws IOException on error, for example this call was aborted, or * timeout */ public BluetoothSocket accept(int timeout) throws IOException { @@ -75,8 +92,8 @@ public final class BluetoothServerSocket implements Closeable { } /** - * Closes this socket. - * This will cause other blocking calls on this socket to immediately + * Immediately close this socket, and release all associated resources. + *

Causes blocked calls on this socket in other threads to immediately * throw an IOException. */ public void close() throws IOException { -- cgit v1.2.3 From 4cd2cd92746e80798c79161791a4042251ed356a Mon Sep 17 00:00:00 2001 From: Nick Pelly Date: Wed, 2 Sep 2009 11:51:35 -0700 Subject: Immediately destroy BluetoothSocket's on close(). Unfortunatley, shutdown() on the underlying fd does not actually stop a listening socket from listening. You need to call close() on the fd to do this. There is no way around it. So this means the Java BluetoothSocket code has to call destroyNative() during BluetoothSocket.close(). Since native methods cannot be called after destroyNative(), add a ReadWrite lock and mClosed field to protect access to native methods. This fixes the "resource busy" error when Bluetooth OPP and Bluetooth PBAP tried to resume listening after turning BT off and then on. --- framework/java/android/bluetooth/BluetoothServerSocket.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'framework/java/android/bluetooth/BluetoothServerSocket.java') diff --git a/framework/java/android/bluetooth/BluetoothServerSocket.java b/framework/java/android/bluetooth/BluetoothServerSocket.java index e653c23295..b65084157e 100644 --- a/framework/java/android/bluetooth/BluetoothServerSocket.java +++ b/framework/java/android/bluetooth/BluetoothServerSocket.java @@ -47,6 +47,7 @@ import java.io.IOException; * operations and close the socket. */ public final class BluetoothServerSocket implements Closeable { + /*package*/ final BluetoothSocket mSocket; /** @@ -88,7 +89,7 @@ public final class BluetoothServerSocket implements Closeable { * timeout */ public BluetoothSocket accept(int timeout) throws IOException { - return mSocket.acceptNative(timeout); + return mSocket.accept(timeout); } /** @@ -97,6 +98,6 @@ public final class BluetoothServerSocket implements Closeable { * throw an IOException. */ public void close() throws IOException { - mSocket.closeNative(); + mSocket.close(); } } -- cgit v1.2.3 From ed6f2ce927782e15c662eab48cd95d95e7ef7841 Mon Sep 17 00:00:00 2001 From: Nick Pelly Date: Tue, 8 Sep 2009 10:12:06 -0700 Subject: Add javadoc to explain which permissions are required for Public BT API's. --- framework/java/android/bluetooth/BluetoothServerSocket.java | 3 +++ 1 file changed, 3 insertions(+) (limited to 'framework/java/android/bluetooth/BluetoothServerSocket.java') diff --git a/framework/java/android/bluetooth/BluetoothServerSocket.java b/framework/java/android/bluetooth/BluetoothServerSocket.java index b65084157e..45dc432d33 100644 --- a/framework/java/android/bluetooth/BluetoothServerSocket.java +++ b/framework/java/android/bluetooth/BluetoothServerSocket.java @@ -45,6 +45,9 @@ import java.io.IOException; *

{@link BluetoothSocket} and {@link BluetoothServerSocket} are thread * safe. In particular, {@link #close} will always immediately abort ongoing * operations and close the socket. + * + *

All methods on a {@link BluetoothServerSocket} require + * {@link android.Manifest.permission#BLUETOOTH} */ public final class BluetoothServerSocket implements Closeable { -- cgit v1.2.3 From ee1402d8d697be3aa2858ee35e57db8c3e845a12 Mon Sep 17 00:00:00 2001 From: Nick Pelly Date: Fri, 2 Oct 2009 20:34:18 -0700 Subject: Provide an API for apps to use a dynamic RFCOMM channel and SDP record. Hide listenUsingRfcommOn(int channel) Add listenUsingRfcomm(String name, ParcelUuid uuid) The new API automatically finds a free RFCOMM channel and registers an SDP record with the given uuid and name. The SDP record is automatically removed when the socket is closed, or if the application dies. Apps are prevented from registering SDP records with the uuid of system Bluetooth profiles, such as A2DP, HFP and OPP. Apps are prevented from removing SDP records that they did not create. This is tracked by pid. TODO: Provide an API for the connecting app to look up an SDP record. Bug: 2158900 DrNo: eastham Joke: "What did the dog say to the tree? bark." Change-Id: Ia92f51c34615a7270a403255ad2b8faa98c4a3f5 --- .../java/android/bluetooth/BluetoothServerSocket.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'framework/java/android/bluetooth/BluetoothServerSocket.java') diff --git a/framework/java/android/bluetooth/BluetoothServerSocket.java b/framework/java/android/bluetooth/BluetoothServerSocket.java index 45dc432d33..c14e4c0761 100644 --- a/framework/java/android/bluetooth/BluetoothServerSocket.java +++ b/framework/java/android/bluetooth/BluetoothServerSocket.java @@ -16,6 +16,8 @@ package android.bluetooth; +import android.os.Handler; + import java.io.Closeable; import java.io.IOException; @@ -52,6 +54,8 @@ import java.io.IOException; public final class BluetoothServerSocket implements Closeable { /*package*/ final BluetoothSocket mSocket; + private Handler mHandler; + private int mMessage; /** * Construct a socket for incoming connections. @@ -101,6 +105,16 @@ public final class BluetoothServerSocket implements Closeable { * throw an IOException. */ public void close() throws IOException { + synchronized (this) { + if (mHandler != null) { + mHandler.obtainMessage(mMessage).sendToTarget(); + } + } mSocket.close(); } + + /*package*/ synchronized void setCloseHandler(Handler handler, int message) { + mHandler = handler; + mMessage = message; + } } -- cgit v1.2.3 From 1e79198aafef8cde937694e6fdbd863acf4f7b8a Mon Sep 17 00:00:00 2001 From: Nick Pelly Date: Tue, 6 Oct 2009 16:10:02 +0200 Subject: Fix docs builds. --- framework/java/android/bluetooth/BluetoothServerSocket.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'framework/java/android/bluetooth/BluetoothServerSocket.java') diff --git a/framework/java/android/bluetooth/BluetoothServerSocket.java b/framework/java/android/bluetooth/BluetoothServerSocket.java index c14e4c0761..d126ea48dd 100644 --- a/framework/java/android/bluetooth/BluetoothServerSocket.java +++ b/framework/java/android/bluetooth/BluetoothServerSocket.java @@ -40,7 +40,7 @@ import java.io.IOException; * BluetoothSocket} ready for an outgoing connection to a remote * {@link BluetoothDevice}. * - *

Use {@link BluetoothAdapter#listenUsingRfcommOn} to create a listening + *

Use {@link BluetoothAdapter#listenUsingRfcomm} to create a listening * {@link BluetoothServerSocket} ready for incoming connections to the local * {@link BluetoothAdapter}. * -- cgit v1.2.3 From 07b84cb5bb5283352a27cc0cf651586ed00035a0 Mon Sep 17 00:00:00 2001 From: Nick Pelly Date: Wed, 7 Oct 2009 07:44:03 +0200 Subject: Encourage developers to connect RFCOMM by UUID instead of Channel. Hide createRfcommSocket(int channel) Add createRfcommSocketWithServiceRecord(UUID uuid) Rename listenUsingRfcomm(String,UUID) -> listenUsingRfcommWithServiceRecord(..) Now we have a complete API for developers to make peer-peer RFCOMM connections with hard-coding the limited (30) RFCOMM channels, instead using SDP lookup of an UUID. This commit addresses two serious bugs: - Do not throw IOException on accepting an incoming RFCOMM connection with BluetoothSocket. This was a regression from commit ee1402d8d697be3a - Workaround failure of bluez to update SDP cache when channel changes by trying to use the same RFCOMM channel on the server every time, instead of picking server channels randomly. This is a pretty ugly workaround, and we are still trying to fix the caching issue - but with this workaround we are at least shippable and apps will work at least until they start colliding on the 30 RFCOMM channels. DrNo: eastham Bug: 2158900 Joke: What did the digital watch say to his mom? "Look mom no hands." Change-Id: Ia4879943b83afac06b6f1a3f2391cf1628afce7d --- framework/java/android/bluetooth/BluetoothServerSocket.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'framework/java/android/bluetooth/BluetoothServerSocket.java') diff --git a/framework/java/android/bluetooth/BluetoothServerSocket.java b/framework/java/android/bluetooth/BluetoothServerSocket.java index d126ea48dd..605bdc11e1 100644 --- a/framework/java/android/bluetooth/BluetoothServerSocket.java +++ b/framework/java/android/bluetooth/BluetoothServerSocket.java @@ -36,13 +36,13 @@ import java.io.IOException; * connection orientated, streaming transport over Bluetooth. It is also known * as the Serial Port Profile (SPP). * - *

Use {@link BluetoothDevice#createRfcommSocket} to create a new {@link - * BluetoothSocket} ready for an outgoing connection to a remote + *

Use {@link BluetoothDevice#createRfcommSocketToServiceRecord} to create + * a new {@link BluetoothSocket} ready for an outgoing connection to a remote * {@link BluetoothDevice}. * - *

Use {@link BluetoothAdapter#listenUsingRfcomm} to create a listening - * {@link BluetoothServerSocket} ready for incoming connections to the local - * {@link BluetoothAdapter}. + *

Use {@link BluetoothAdapter#listenUsingRfcommWithServiceRecord} to + * create a listening {@link BluetoothServerSocket} ready for incoming + * connections to the local {@link BluetoothAdapter}. * *

{@link BluetoothSocket} and {@link BluetoothServerSocket} are thread * safe. In particular, {@link #close} will always immediately abort ongoing @@ -68,7 +68,7 @@ public final class BluetoothServerSocket implements Closeable { */ /*package*/ BluetoothServerSocket(int type, boolean auth, boolean encrypt, int port) throws IOException { - mSocket = new BluetoothSocket(type, -1, auth, encrypt, null, port); + mSocket = new BluetoothSocket(type, -1, auth, encrypt, null, port, null); } /** -- cgit v1.2.3 From beef809fa89a5e7955a4c25cf70e00adbcf2e24e Mon Sep 17 00:00:00 2001 From: Scott Main Date: Tue, 3 Nov 2009 18:17:59 -0800 Subject: docs: add more documentation for the bluetooth apis. more descriptions for some of the classes and a new overview and pseudo-code example for using BT APIs in the package summary. --- .../android/bluetooth/BluetoothServerSocket.java | 38 ++++++++++++---------- 1 file changed, 20 insertions(+), 18 deletions(-) (limited to 'framework/java/android/bluetooth/BluetoothServerSocket.java') diff --git a/framework/java/android/bluetooth/BluetoothServerSocket.java b/framework/java/android/bluetooth/BluetoothServerSocket.java index 605bdc11e1..1b23f6c048 100644 --- a/framework/java/android/bluetooth/BluetoothServerSocket.java +++ b/framework/java/android/bluetooth/BluetoothServerSocket.java @@ -27,29 +27,31 @@ import java.io.IOException; *

The interface for Bluetooth Sockets is similar to that of TCP sockets: * {@link java.net.Socket} and {@link java.net.ServerSocket}. On the server * side, use a {@link BluetoothServerSocket} to create a listening server - * socket. It will return a new, connected {@link BluetoothSocket} on an - * accepted connection. On the client side, use the same - * {@link BluetoothSocket} object to both intiate the outgoing connection, - * and to manage the connected socket. + * socket. When a connection is accepted by the {@link BluetoothServerSocket}, + * it will return a new {@link BluetoothSocket} to manage the connection. + * On the client side, use a single {@link BluetoothSocket} to both intiate + * an outgoing connection and to manage the connection. * - *

The most common type of Bluetooth Socket is RFCOMM. RFCOMM is a - * connection orientated, streaming transport over Bluetooth. It is also known - * as the Serial Port Profile (SPP). + *

The most common type of Bluetooth socket is RFCOMM, which is the type + * supported by the Android APIs. RFCOMM is a connection-oriented, streaming + * transport over Bluetooth. It is also known as the Serial Port Profile (SPP). * - *

Use {@link BluetoothDevice#createRfcommSocketToServiceRecord} to create - * a new {@link BluetoothSocket} ready for an outgoing connection to a remote - * {@link BluetoothDevice}. + *

To create a listenting {@link BluetoothServerSocket} that's ready for + * incoming connections, use + * {@link BluetoothAdapter#listenUsingRfcommWithServiceRecord + * BluetoothAdapter.listenUsingRfcommWithServiceRecord()}. Then call + * {@link #accept()} to listen for incoming connection requests. This call + * will block until a connection is established, at which point, it will return + * a {@link BluetoothSocket} to manage the connection. * - *

Use {@link BluetoothAdapter#listenUsingRfcommWithServiceRecord} to - * create a listening {@link BluetoothServerSocket} ready for incoming - * connections to the local {@link BluetoothAdapter}. - * - *

{@link BluetoothSocket} and {@link BluetoothServerSocket} are thread + *

{@link BluetoothServerSocket} is thread * safe. In particular, {@link #close} will always immediately abort ongoing - * operations and close the socket. + * operations and close the server socket. + * + *

Note: + * Requires the {@link android.Manifest.permission#BLUETOOTH} permission. * - *

All methods on a {@link BluetoothServerSocket} require - * {@link android.Manifest.permission#BLUETOOTH} + * {@see BluetoothSocket} */ public final class BluetoothServerSocket implements Closeable { -- cgit v1.2.3 From a7848ce834a484d194d05afd8097ab3014f9b449 Mon Sep 17 00:00:00 2001 From: Scott Main Date: Thu, 19 Nov 2009 17:00:19 -0800 Subject: docs for ESR: add docs to bluetooth explainin that discovery should be cancelled before connecting to a device bug: 2160782,2198463 --- framework/java/android/bluetooth/BluetoothServerSocket.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'framework/java/android/bluetooth/BluetoothServerSocket.java') diff --git a/framework/java/android/bluetooth/BluetoothServerSocket.java b/framework/java/android/bluetooth/BluetoothServerSocket.java index 1b23f6c048..c9c6c0acd9 100644 --- a/framework/java/android/bluetooth/BluetoothServerSocket.java +++ b/framework/java/android/bluetooth/BluetoothServerSocket.java @@ -42,7 +42,11 @@ import java.io.IOException; * BluetoothAdapter.listenUsingRfcommWithServiceRecord()}. Then call * {@link #accept()} to listen for incoming connection requests. This call * will block until a connection is established, at which point, it will return - * a {@link BluetoothSocket} to manage the connection. + * a {@link BluetoothSocket} to manage the connection. Once the {@link + * BluetoothSocket} is acquired, it's a good idea to call {@link #close()} on + * the {@link BluetoothServerSocket} when it's no longer needed for accepting + * connections. Closing the {@link BluetoothServerSocket} will not + * close the returned {@link BluetoothSocket}. * *

{@link BluetoothServerSocket} is thread * safe. In particular, {@link #close} will always immediately abort ongoing @@ -105,6 +109,8 @@ public final class BluetoothServerSocket implements Closeable { * Immediately close this socket, and release all associated resources. *

Causes blocked calls on this socket in other threads to immediately * throw an IOException. + *

Closing the {@link BluetoothServerSocket} will not + * close any {@link BluetoothSocket} received from {@link #accept()}. */ public void close() throws IOException { synchronized (this) { -- cgit v1.2.3 From 04c7138c7c1f36d54fbe33c40644e197248166b9 Mon Sep 17 00:00:00 2001 From: Jake Hamby Date: Tue, 21 Sep 2010 13:39:53 -0700 Subject: Typo fixes in comments and minor code cleanups. * Fix some typos in Javadoc and log messages. * Remove redundant initializer in BluetoothAdapter.readOutOfBandData() * Use canonical "UTF-8" charset name instead of "UTF8" in BluetoothDevice.convertPinToBytes() Change-Id: I58cd5dc48a7ad0053d204c5f590b4b3d438d8672 --- framework/java/android/bluetooth/BluetoothServerSocket.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'framework/java/android/bluetooth/BluetoothServerSocket.java') diff --git a/framework/java/android/bluetooth/BluetoothServerSocket.java b/framework/java/android/bluetooth/BluetoothServerSocket.java index c9c6c0acd9..83e59e266d 100644 --- a/framework/java/android/bluetooth/BluetoothServerSocket.java +++ b/framework/java/android/bluetooth/BluetoothServerSocket.java @@ -29,14 +29,14 @@ import java.io.IOException; * side, use a {@link BluetoothServerSocket} to create a listening server * socket. When a connection is accepted by the {@link BluetoothServerSocket}, * it will return a new {@link BluetoothSocket} to manage the connection. - * On the client side, use a single {@link BluetoothSocket} to both intiate + * On the client side, use a single {@link BluetoothSocket} to both initiate * an outgoing connection and to manage the connection. * *

The most common type of Bluetooth socket is RFCOMM, which is the type * supported by the Android APIs. RFCOMM is a connection-oriented, streaming * transport over Bluetooth. It is also known as the Serial Port Profile (SPP). * - *

To create a listenting {@link BluetoothServerSocket} that's ready for + *

To create a listening {@link BluetoothServerSocket} that's ready for * incoming connections, use * {@link BluetoothAdapter#listenUsingRfcommWithServiceRecord * BluetoothAdapter.listenUsingRfcommWithServiceRecord()}. Then call @@ -70,7 +70,7 @@ public final class BluetoothServerSocket implements Closeable { * @param encrypt require the connection to be encrypted * @param port remote port * @throws IOException On error, for example Bluetooth not available, or - * insufficient priveleges + * insufficient privileges */ /*package*/ BluetoothServerSocket(int type, boolean auth, boolean encrypt, int port) throws IOException { -- cgit v1.2.3 From 48d0cca9df0a6b13a5d4d3f8664ca8be21e60e30 Mon Sep 17 00:00:00 2001 From: Ben Dodson Date: Fri, 8 Jul 2011 14:36:42 -0700 Subject: Get server's listening channel Change-Id: Ia1cb3486a4ba502185efdcf6d7bcf0f37bb55261 --- framework/java/android/bluetooth/BluetoothServerSocket.java | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'framework/java/android/bluetooth/BluetoothServerSocket.java') diff --git a/framework/java/android/bluetooth/BluetoothServerSocket.java b/framework/java/android/bluetooth/BluetoothServerSocket.java index 83e59e266d..acce182189 100644 --- a/framework/java/android/bluetooth/BluetoothServerSocket.java +++ b/framework/java/android/bluetooth/BluetoothServerSocket.java @@ -62,6 +62,7 @@ public final class BluetoothServerSocket implements Closeable { /*package*/ final BluetoothSocket mSocket; private Handler mHandler; private int mMessage; + private final int mChannel; /** * Construct a socket for incoming connections. @@ -74,6 +75,7 @@ public final class BluetoothServerSocket implements Closeable { */ /*package*/ BluetoothServerSocket(int type, boolean auth, boolean encrypt, int port) throws IOException { + mChannel = port; mSocket = new BluetoothSocket(type, -1, auth, encrypt, null, port, null); } @@ -125,4 +127,12 @@ public final class BluetoothServerSocket implements Closeable { mHandler = handler; mMessage = message; } + + /** + * Returns the channel on which this socket is bound. + * @hide + */ + public int getChannel() { + return mChannel; + } } -- cgit v1.2.3 From da4e2ab44781662822e2f8ee1f94f2085309d66d Mon Sep 17 00:00:00 2001 From: Joe Fernandez Date: Tue, 20 Dec 2011 10:38:34 -0800 Subject: docs: Add developer guide cross-references, Project ACRE, round 4 Change-Id: I1b43414aaec8ea217b39a0d780c80a25409d0991 --- framework/java/android/bluetooth/BluetoothServerSocket.java | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'framework/java/android/bluetooth/BluetoothServerSocket.java') diff --git a/framework/java/android/bluetooth/BluetoothServerSocket.java b/framework/java/android/bluetooth/BluetoothServerSocket.java index acce182189..4021f7b61a 100644 --- a/framework/java/android/bluetooth/BluetoothServerSocket.java +++ b/framework/java/android/bluetooth/BluetoothServerSocket.java @@ -55,6 +55,12 @@ import java.io.IOException; *

Note: * Requires the {@link android.Manifest.permission#BLUETOOTH} permission. * + *

+ *

Developer Guides

+ *

For more information about using Bluetooth, read the + * Bluetooth developer guide.

+ *
+ * * {@see BluetoothSocket} */ public final class BluetoothServerSocket implements Closeable { -- cgit v1.2.3 From fab62db7cf9962e90bfe30b85df57b6c621b7310 Mon Sep 17 00:00:00 2001 From: zzy Date: Tue, 3 Apr 2012 19:48:32 -0700 Subject: Added new rfcomm multi accept code --- .../android/bluetooth/BluetoothServerSocket.java | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'framework/java/android/bluetooth/BluetoothServerSocket.java') diff --git a/framework/java/android/bluetooth/BluetoothServerSocket.java b/framework/java/android/bluetooth/BluetoothServerSocket.java index 4021f7b61a..96be8a2fb6 100644 --- a/framework/java/android/bluetooth/BluetoothServerSocket.java +++ b/framework/java/android/bluetooth/BluetoothServerSocket.java @@ -17,6 +17,8 @@ package android.bluetooth; import android.os.Handler; +import android.os.Message; +import android.os.ParcelUuid; import java.io.Closeable; import java.io.IOException; @@ -85,6 +87,22 @@ public final class BluetoothServerSocket implements Closeable { mSocket = new BluetoothSocket(type, -1, auth, encrypt, null, port, null); } + /** + * Construct a socket for incoming connections. + * @param type type of socket + * @param auth require the remote device to be authenticated + * @param encrypt require the connection to be encrypted + * @param uuid uuid + * @throws IOException On error, for example Bluetooth not available, or + * insufficient privileges + */ + /*package*/ BluetoothServerSocket(int type, boolean auth, boolean encrypt, ParcelUuid uuid) + throws IOException { + mSocket = new BluetoothSocket(type, -1, auth, encrypt, null, -1, uuid); + mChannel = mSocket.getPort(); + } + + /** * Block until a connection is established. *

Returns a connected {@link BluetoothSocket} on successful connection. @@ -133,7 +151,9 @@ public final class BluetoothServerSocket implements Closeable { mHandler = handler; mMessage = message; } - + /*package*/ void setServiceName(String ServiceName) { + mSocket.setServiceName(ServiceName); + } /** * Returns the channel on which this socket is bound. * @hide -- cgit v1.2.3 From 9c530c2e37aa238af783db1f1715a60b4b74b02d Mon Sep 17 00:00:00 2001 From: John Spurlock Date: Tue, 19 Nov 2013 16:54:46 -0500 Subject: Remove unused imports from frameworks/base. Change-Id: Ia1f99bd2c1105b0b0f70aa614f1f4a67b2840906 --- framework/java/android/bluetooth/BluetoothServerSocket.java | 1 - 1 file changed, 1 deletion(-) (limited to 'framework/java/android/bluetooth/BluetoothServerSocket.java') diff --git a/framework/java/android/bluetooth/BluetoothServerSocket.java b/framework/java/android/bluetooth/BluetoothServerSocket.java index 96be8a2fb6..bc56e55649 100644 --- a/framework/java/android/bluetooth/BluetoothServerSocket.java +++ b/framework/java/android/bluetooth/BluetoothServerSocket.java @@ -17,7 +17,6 @@ package android.bluetooth; import android.os.Handler; -import android.os.Message; import android.os.ParcelUuid; import java.io.Closeable; -- cgit v1.2.3 From c0a7c93812c39589a1c90a18c93ddb3a4e36205a Mon Sep 17 00:00:00 2001 From: Casper Bonde Date: Thu, 9 Apr 2015 09:24:48 +0200 Subject: OBEX Over L2CAP + SDP search API for BT profiles - Updated OBEX to support SRM - Added support for OBEX over l2cap and SRM. - Minor bugfixes, and reduce CPU load ALOT - Added support to send responses without body data. - Extend BluetoothSocket to support L2CAP - Added functionality to get the channel number needed to be able to create an SDP record with the channel number. - Added interface to get socket type and max packet sizes. - Added interface to perform SDP search and get the resulting SDP record data. Change-Id: I9d37a00ce73dfffc0e3ce03eab5511ba3a86e5b8 --- .../android/bluetooth/BluetoothServerSocket.java | 52 +++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) (limited to 'framework/java/android/bluetooth/BluetoothServerSocket.java') diff --git a/framework/java/android/bluetooth/BluetoothServerSocket.java b/framework/java/android/bluetooth/BluetoothServerSocket.java index bc56e55649..21024a6021 100644 --- a/framework/java/android/bluetooth/BluetoothServerSocket.java +++ b/framework/java/android/bluetooth/BluetoothServerSocket.java @@ -18,6 +18,7 @@ package android.bluetooth; import android.os.Handler; import android.os.ParcelUuid; +import android.util.Log; import java.io.Closeable; import java.io.IOException; @@ -66,10 +67,11 @@ import java.io.IOException; */ public final class BluetoothServerSocket implements Closeable { + private static final String TAG = "BluetoothServerSocket"; /*package*/ final BluetoothSocket mSocket; private Handler mHandler; private int mMessage; - private final int mChannel; + private int mChannel; /** * Construct a socket for incoming connections. @@ -84,6 +86,9 @@ public final class BluetoothServerSocket implements Closeable { throws IOException { mChannel = port; mSocket = new BluetoothSocket(type, -1, auth, encrypt, null, port, null); + if(port == BluetoothAdapter.SOCKET_CHANNEL_AUTO_STATIC_NO_SDP) { + mSocket.setExcludeSdp(true); + } } /** @@ -98,6 +103,7 @@ public final class BluetoothServerSocket implements Closeable { /*package*/ BluetoothServerSocket(int type, boolean auth, boolean encrypt, ParcelUuid uuid) throws IOException { mSocket = new BluetoothSocket(type, -1, auth, encrypt, null, -1, uuid); + // TODO: This is the same as mChannel = -1 - is this intentional? mChannel = mSocket.getPort(); } @@ -153,6 +159,7 @@ public final class BluetoothServerSocket implements Closeable { /*package*/ void setServiceName(String ServiceName) { mSocket.setServiceName(ServiceName); } + /** * Returns the channel on which this socket is bound. * @hide @@ -160,4 +167,47 @@ public final class BluetoothServerSocket implements Closeable { public int getChannel() { return mChannel; } + + /** + * Sets the channel on which future sockets are bound. + * Currently used only when a channel is auto generated. + */ + /*package*/ void setChannel(int newChannel) { + /* TODO: From a design/architecture perspective this is wrong. + * The bind operation should be conducted through this class + * and the resulting port should be kept in mChannel, and + * not set from BluetoothAdapter. */ + if(mSocket != null) { + if(mSocket.getPort() != newChannel) { + Log.w(TAG,"The port set is different that the underlying port. mSocket.getPort(): " + + mSocket.getPort() + " requested newChannel: " + newChannel); + } + } + mChannel = newChannel; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("ServerSocket: Type: "); + switch(mSocket.getConnectionType()) { + case BluetoothSocket.TYPE_RFCOMM: + { + sb.append("TYPE_RFCOMM"); + break; + } + case BluetoothSocket.TYPE_L2CAP: + { + sb.append("TYPE_L2CAP"); + break; + } + case BluetoothSocket.TYPE_SCO: + { + sb.append("TYPE_SCO"); + break; + } + } + sb.append(" Channel: ").append(mChannel); + return sb.toString(); + } } -- cgit v1.2.3 From 60d77c2c9ceea76d7e4e32ab173ef3da64ff607e Mon Sep 17 00:00:00 2001 From: Casper Bonde Date: Tue, 21 Apr 2015 13:12:05 +0200 Subject: Add support for MITM for BluetoothSockets (1/4) This change adds an option to enforce Man-in-the-middle protection for the authentication process. This feature is needed for the Sim Access Profile. Change-Id: Ia3ef0caeb750f88608c9fa6bf6367d1c77de4cf3 Signed-off-by: Casper Bonde --- .../android/bluetooth/BluetoothServerSocket.java | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'framework/java/android/bluetooth/BluetoothServerSocket.java') diff --git a/framework/java/android/bluetooth/BluetoothServerSocket.java b/framework/java/android/bluetooth/BluetoothServerSocket.java index 21024a6021..a80f55c0e4 100644 --- a/framework/java/android/bluetooth/BluetoothServerSocket.java +++ b/framework/java/android/bluetooth/BluetoothServerSocket.java @@ -86,6 +86,26 @@ public final class BluetoothServerSocket implements Closeable { throws IOException { mChannel = port; mSocket = new BluetoothSocket(type, -1, auth, encrypt, null, port, null); + if (port == BluetoothAdapter.SOCKET_CHANNEL_AUTO_STATIC_NO_SDP) { + mSocket.setExcludeSdp(true); + } + } + + /** + * Construct a socket for incoming connections. + * @param type type of socket + * @param auth require the remote device to be authenticated + * @param encrypt require the connection to be encrypted + * @param port remote port + * @param mitm enforce man-in-the-middle protection for authentication. + * @throws IOException On error, for example Bluetooth not available, or + * insufficient privileges + */ + /*package*/ BluetoothServerSocket(int type, boolean auth, boolean encrypt, int port, + boolean mitm) + throws IOException { + mChannel = port; + mSocket = new BluetoothSocket(type, -1, auth, encrypt, null, port, null, mitm); if(port == BluetoothAdapter.SOCKET_CHANNEL_AUTO_STATIC_NO_SDP) { mSocket.setExcludeSdp(true); } -- cgit v1.2.3 From 91276018bd5dd6c61dcd69cd87090ba022b532e7 Mon Sep 17 00:00:00 2001 From: Casper Bonde Date: Fri, 8 May 2015 14:32:24 +0200 Subject: SAP: Make it possible to enforce a 16-digit pin code (4/5) This change enable the posibility to enforce using a 16-digit pin or MITM for a RFCOMM or L2CAP connection. This is needed for the SIM access profile. Change-Id: I3205013f9e758c353381442a86845dab467780f8 Signed-off-by: Casper Bonde --- framework/java/android/bluetooth/BluetoothServerSocket.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'framework/java/android/bluetooth/BluetoothServerSocket.java') diff --git a/framework/java/android/bluetooth/BluetoothServerSocket.java b/framework/java/android/bluetooth/BluetoothServerSocket.java index a80f55c0e4..c15852dcda 100644 --- a/framework/java/android/bluetooth/BluetoothServerSocket.java +++ b/framework/java/android/bluetooth/BluetoothServerSocket.java @@ -98,14 +98,16 @@ public final class BluetoothServerSocket implements Closeable { * @param encrypt require the connection to be encrypted * @param port remote port * @param mitm enforce man-in-the-middle protection for authentication. + * @param min16DigitPin enforce a minimum length of 16 digits for a sec mode 2 connection * @throws IOException On error, for example Bluetooth not available, or * insufficient privileges */ /*package*/ BluetoothServerSocket(int type, boolean auth, boolean encrypt, int port, - boolean mitm) + boolean mitm, boolean min16DigitPin) throws IOException { mChannel = port; - mSocket = new BluetoothSocket(type, -1, auth, encrypt, null, port, null, mitm); + mSocket = new BluetoothSocket(type, -1, auth, encrypt, null, port, null, mitm, + min16DigitPin); if(port == BluetoothAdapter.SOCKET_CHANNEL_AUTO_STATIC_NO_SDP) { mSocket.setExcludeSdp(true); } -- cgit v1.2.3 From f242df2f7ac42405d7d4d83bb745c2bc40088c13 Mon Sep 17 00:00:00 2001 From: Marie Janssen Date: Mon, 20 Jun 2016 10:26:31 -0700 Subject: Fix links to Bluetooth Guide Change-Id: I5798c3d71c7cc9c509e0f7b04fa140168b0fdc11 --- framework/java/android/bluetooth/BluetoothServerSocket.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'framework/java/android/bluetooth/BluetoothServerSocket.java') diff --git a/framework/java/android/bluetooth/BluetoothServerSocket.java b/framework/java/android/bluetooth/BluetoothServerSocket.java index c15852dcda..4860c93840 100644 --- a/framework/java/android/bluetooth/BluetoothServerSocket.java +++ b/framework/java/android/bluetooth/BluetoothServerSocket.java @@ -60,7 +60,7 @@ import java.io.IOException; *

*

Developer Guides

*

For more information about using Bluetooth, read the - * Bluetooth developer guide.

+ * Bluetooth developer guide.

*
* * {@see BluetoothSocket} -- cgit v1.2.3 From 910201beb0bde1dcf6b33e4ec5d1eb60042419d8 Mon Sep 17 00:00:00 2001 From: Jack He Date: Tue, 22 Aug 2017 16:06:54 -0700 Subject: Fix checkstyle errors (1/2) * Automatic style corrections through IDE Bug: 63596319 Test: make checkbuild, no manual changes, no functional changes Change-Id: I2397d55abc34c9b7a9b748bec6137778df3421a7 --- .../android/bluetooth/BluetoothServerSocket.java | 69 +++++++++++----------- 1 file changed, 36 insertions(+), 33 deletions(-) (limited to 'framework/java/android/bluetooth/BluetoothServerSocket.java') diff --git a/framework/java/android/bluetooth/BluetoothServerSocket.java b/framework/java/android/bluetooth/BluetoothServerSocket.java index 4860c93840..7b438bdb4e 100644 --- a/framework/java/android/bluetooth/BluetoothServerSocket.java +++ b/framework/java/android/bluetooth/BluetoothServerSocket.java @@ -75,12 +75,13 @@ public final class BluetoothServerSocket implements Closeable { /** * Construct a socket for incoming connections. - * @param type type of socket - * @param auth require the remote device to be authenticated + * + * @param type type of socket + * @param auth require the remote device to be authenticated * @param encrypt require the connection to be encrypted - * @param port remote port - * @throws IOException On error, for example Bluetooth not available, or - * insufficient privileges + * @param port remote port + * @throws IOException On error, for example Bluetooth not available, or insufficient + * privileges */ /*package*/ BluetoothServerSocket(int type, boolean auth, boolean encrypt, int port) throws IOException { @@ -93,14 +94,15 @@ public final class BluetoothServerSocket implements Closeable { /** * Construct a socket for incoming connections. - * @param type type of socket - * @param auth require the remote device to be authenticated + * + * @param type type of socket + * @param auth require the remote device to be authenticated * @param encrypt require the connection to be encrypted - * @param port remote port - * @param mitm enforce man-in-the-middle protection for authentication. + * @param port remote port + * @param mitm enforce man-in-the-middle protection for authentication. * @param min16DigitPin enforce a minimum length of 16 digits for a sec mode 2 connection - * @throws IOException On error, for example Bluetooth not available, or - * insufficient privileges + * @throws IOException On error, for example Bluetooth not available, or insufficient + * privileges */ /*package*/ BluetoothServerSocket(int type, boolean auth, boolean encrypt, int port, boolean mitm, boolean min16DigitPin) @@ -108,19 +110,20 @@ public final class BluetoothServerSocket implements Closeable { mChannel = port; mSocket = new BluetoothSocket(type, -1, auth, encrypt, null, port, null, mitm, min16DigitPin); - if(port == BluetoothAdapter.SOCKET_CHANNEL_AUTO_STATIC_NO_SDP) { + if (port == BluetoothAdapter.SOCKET_CHANNEL_AUTO_STATIC_NO_SDP) { mSocket.setExcludeSdp(true); } } /** * Construct a socket for incoming connections. - * @param type type of socket - * @param auth require the remote device to be authenticated + * + * @param type type of socket + * @param auth require the remote device to be authenticated * @param encrypt require the connection to be encrypted - * @param uuid uuid - * @throws IOException On error, for example Bluetooth not available, or - * insufficient privileges + * @param uuid uuid + * @throws IOException On error, for example Bluetooth not available, or insufficient + * privileges */ /*package*/ BluetoothServerSocket(int type, boolean auth, boolean encrypt, ParcelUuid uuid) throws IOException { @@ -136,9 +139,9 @@ public final class BluetoothServerSocket implements Closeable { *

Once this call returns, it can be called again to accept subsequent * incoming connections. *

{@link #close} can be used to abort this call from another thread. + * * @return a connected {@link BluetoothSocket} - * @throws IOException on error, for example this call was aborted, or - * timeout + * @throws IOException on error, for example this call was aborted, or timeout */ public BluetoothSocket accept() throws IOException { return accept(-1); @@ -150,9 +153,9 @@ public final class BluetoothServerSocket implements Closeable { *

Once this call returns, it can be called again to accept subsequent * incoming connections. *

{@link #close} can be used to abort this call from another thread. + * * @return a connected {@link BluetoothSocket} - * @throws IOException on error, for example this call was aborted, or - * timeout + * @throws IOException on error, for example this call was aborted, or timeout */ public BluetoothSocket accept(int timeout) throws IOException { return mSocket.accept(timeout); @@ -174,16 +177,19 @@ public final class BluetoothServerSocket implements Closeable { mSocket.close(); } - /*package*/ synchronized void setCloseHandler(Handler handler, int message) { + /*package*/ + synchronized void setCloseHandler(Handler handler, int message) { mHandler = handler; mMessage = message; } + /*package*/ void setServiceName(String ServiceName) { mSocket.setServiceName(ServiceName); } /** * Returns the channel on which this socket is bound. + * * @hide */ public int getChannel() { @@ -199,10 +205,10 @@ public final class BluetoothServerSocket implements Closeable { * The bind operation should be conducted through this class * and the resulting port should be kept in mChannel, and * not set from BluetoothAdapter. */ - if(mSocket != null) { - if(mSocket.getPort() != newChannel) { - Log.w(TAG,"The port set is different that the underlying port. mSocket.getPort(): " - + mSocket.getPort() + " requested newChannel: " + newChannel); + if (mSocket != null) { + if (mSocket.getPort() != newChannel) { + Log.w(TAG, "The port set is different that the underlying port. mSocket.getPort(): " + + mSocket.getPort() + " requested newChannel: " + newChannel); } } mChannel = newChannel; @@ -212,19 +218,16 @@ public final class BluetoothServerSocket implements Closeable { public String toString() { StringBuilder sb = new StringBuilder(); sb.append("ServerSocket: Type: "); - switch(mSocket.getConnectionType()) { - case BluetoothSocket.TYPE_RFCOMM: - { + switch (mSocket.getConnectionType()) { + case BluetoothSocket.TYPE_RFCOMM: { sb.append("TYPE_RFCOMM"); break; } - case BluetoothSocket.TYPE_L2CAP: - { + case BluetoothSocket.TYPE_L2CAP: { sb.append("TYPE_L2CAP"); break; } - case BluetoothSocket.TYPE_SCO: - { + case BluetoothSocket.TYPE_SCO: { sb.append("TYPE_SCO"); break; } -- cgit v1.2.3 From 9e045d26d0128826b40520f523307d8d16473779 Mon Sep 17 00:00:00 2001 From: Jack He Date: Tue, 22 Aug 2017 21:21:23 -0700 Subject: Fix checkstyle errors (2/2) * Manual style corrections with IDE assistance * Variable name refactors are done through IDE * Corrected general style errors such as: - "final private var" -> "private final var" - "&&", "+", "||" should not be at the end of line - Non-static private variable should be like "mVar" - Private static variable should be like "sVar" - Code file should always end with newline - Inherited methods should be annotated with @Override and no @hide tags - Public methods should always have a JavaDoc entry - "int[] array" is preferred over "int array[]" - private methods should be accessed without "this." when there is no name collisions. - "boolean ? true : false" -> boolean - "boolean ? false : true" -> !boolean - "boolean == true" OR "boolean != false" -> boolean - "boolean != true" OR "boolean == false" -> !boolean Bug: 63596319 Test: make checkbuild, no functional changes Change-Id: Iabdc2be912a32dd63a53213d175cf1bfef268ccd --- framework/java/android/bluetooth/BluetoothServerSocket.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'framework/java/android/bluetooth/BluetoothServerSocket.java') diff --git a/framework/java/android/bluetooth/BluetoothServerSocket.java b/framework/java/android/bluetooth/BluetoothServerSocket.java index 7b438bdb4e..58d090dc28 100644 --- a/framework/java/android/bluetooth/BluetoothServerSocket.java +++ b/framework/java/android/bluetooth/BluetoothServerSocket.java @@ -183,8 +183,8 @@ public final class BluetoothServerSocket implements Closeable { mMessage = message; } - /*package*/ void setServiceName(String ServiceName) { - mSocket.setServiceName(ServiceName); + /*package*/ void setServiceName(String serviceName) { + mSocket.setServiceName(serviceName); } /** -- cgit v1.2.3 From d67d5e4f1e8c1afd98f11b11ca8ca26792da9d6b Mon Sep 17 00:00:00 2001 From: Stanley Tng Date: Wed, 22 Nov 2017 16:04:40 -0800 Subject: Added APIs for Connection-oriented channels Experimental and hidden APIs are defined for the Connection-oriented Channel (CoC) features. The APIs using PSM are implemented. Test: Can compile Bug: 70683224 Change-Id: Icdb5fa190b0e21881a60437fa48cd575371ee1e4 --- .../android/bluetooth/BluetoothServerSocket.java | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'framework/java/android/bluetooth/BluetoothServerSocket.java') diff --git a/framework/java/android/bluetooth/BluetoothServerSocket.java b/framework/java/android/bluetooth/BluetoothServerSocket.java index 58d090dc28..ebb7f187ae 100644 --- a/framework/java/android/bluetooth/BluetoothServerSocket.java +++ b/framework/java/android/bluetooth/BluetoothServerSocket.java @@ -68,6 +68,7 @@ import java.io.IOException; public final class BluetoothServerSocket implements Closeable { private static final String TAG = "BluetoothServerSocket"; + private static final boolean DBG = false; /*package*/ final BluetoothSocket mSocket; private Handler mHandler; private int mMessage; @@ -169,6 +170,7 @@ public final class BluetoothServerSocket implements Closeable { * close any {@link BluetoothSocket} received from {@link #accept()}. */ public void close() throws IOException { + if (DBG) Log.d(TAG, "BluetoothServerSocket:close() called. mChannel=" + mChannel); synchronized (this) { if (mHandler != null) { mHandler.obtainMessage(mMessage).sendToTarget(); @@ -196,6 +198,20 @@ public final class BluetoothServerSocket implements Closeable { return mChannel; } + /** + * Returns the assigned dynamic protocol/service multiplexer (PSM) value for the listening L2CAP + * Connection-oriented Channel (CoC) server socket. This server socket must be returned by the + * {#link BluetoothAdapter.listenUsingL2capCoc(int)} or {#link + * BluetoothAdapter.listenUsingInsecureL2capCoc(int)}. The returned value is undefined if this + * method is called on non-L2CAP server sockets. + * + * @return the assigned PSM or LE_PSM value depending on transport + * @hide + */ + public int getPsm() { + return mChannel; + } + /** * Sets the channel on which future sockets are bound. * Currently used only when a channel is auto generated. @@ -227,6 +243,10 @@ public final class BluetoothServerSocket implements Closeable { sb.append("TYPE_L2CAP"); break; } + case BluetoothSocket.TYPE_L2CAP_LE: { + sb.append("TYPE_L2CAP_LE"); + break; + } case BluetoothSocket.TYPE_SCO: { sb.append("TYPE_SCO"); break; -- cgit v1.2.3 From 7d543894e0497651fc160728d659543483500f87 Mon Sep 17 00:00:00 2001 From: Mathew Inwood Date: Wed, 1 Aug 2018 15:07:20 +0100 Subject: Add @UnsupportedAppUsage annotations For packages: android.bluetooth.le android.bluetooth This is an automatically generated CL. See go/UnsupportedAppUsage for more details. Exempted-From-Owner-Approval: Mechanical changes to the codebase which have been approved by Android API council and announced on android-eng@ Bug: 110868826 Test: m Change-Id: Ifcf24c0617acd7facc0e03f30a95c3a6b09b205c Merged-In: I88a1311e27c5f9a5f9d1035db76034f86f650efc --- framework/java/android/bluetooth/BluetoothServerSocket.java | 2 ++ 1 file changed, 2 insertions(+) (limited to 'framework/java/android/bluetooth/BluetoothServerSocket.java') diff --git a/framework/java/android/bluetooth/BluetoothServerSocket.java b/framework/java/android/bluetooth/BluetoothServerSocket.java index ebb7f187ae..ba4b5a5667 100644 --- a/framework/java/android/bluetooth/BluetoothServerSocket.java +++ b/framework/java/android/bluetooth/BluetoothServerSocket.java @@ -16,6 +16,7 @@ package android.bluetooth; +import android.annotation.UnsupportedAppUsage; import android.os.Handler; import android.os.ParcelUuid; import android.util.Log; @@ -69,6 +70,7 @@ public final class BluetoothServerSocket implements Closeable { private static final String TAG = "BluetoothServerSocket"; private static final boolean DBG = false; + @UnsupportedAppUsage /*package*/ final BluetoothSocket mSocket; private Handler mHandler; private int mMessage; -- cgit v1.2.3 From 412cbec0c57647b955747e9b55bce071870b9a1e Mon Sep 17 00:00:00 2001 From: Stanley Tng Date: Fri, 29 Jun 2018 14:05:04 -0700 Subject: Unhide the LE CoC APIs Expose the LE Connection-oriented Channels APIs for applications to use. Test: Run the SL4A ACTS test: BleCocTest Bug: 70683224 Change-Id: I68128bc7154966ec065091c973351f8892da9b4d --- framework/java/android/bluetooth/BluetoothServerSocket.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'framework/java/android/bluetooth/BluetoothServerSocket.java') diff --git a/framework/java/android/bluetooth/BluetoothServerSocket.java b/framework/java/android/bluetooth/BluetoothServerSocket.java index ba4b5a5667..5fc344a14f 100644 --- a/framework/java/android/bluetooth/BluetoothServerSocket.java +++ b/framework/java/android/bluetooth/BluetoothServerSocket.java @@ -203,12 +203,11 @@ public final class BluetoothServerSocket implements Closeable { /** * Returns the assigned dynamic protocol/service multiplexer (PSM) value for the listening L2CAP * Connection-oriented Channel (CoC) server socket. This server socket must be returned by the - * {#link BluetoothAdapter.listenUsingL2capCoc(int)} or {#link - * BluetoothAdapter.listenUsingInsecureL2capCoc(int)}. The returned value is undefined if this + * {#link BluetoothAdapter.listenUsingL2capChannel()} or {#link + * BluetoothAdapter.listenUsingInsecureL2capChannel()}. The returned value is undefined if this * method is called on non-L2CAP server sockets. * * @return the assigned PSM or LE_PSM value depending on transport - * @hide */ public int getPsm() { return mChannel; -- cgit v1.2.3 From ee9e4f6b77d8b9ecd011177e1e6cbd62e0ff2d77 Mon Sep 17 00:00:00 2001 From: Andrew Solovay Date: Tue, 2 Oct 2018 14:14:42 -0700 Subject: docs: Replacing {#link with {@link Several java files had the typo {#link (for cross-references to other Javadocs) instead of the proper {@link format. This was confusing the new doc publish tool (Mivi) since that's the format used for {# Django comments #}. Fixed a couple of links that had other errors (which prevented building once the {# -> {@ was done) and other typos. Replaced throughout the frameworks/base project; I'll need a separate CL for the AndroidX fixes. Staged to: go/dac-stage/reference/android/app/Instrumentation.html go/dac-stage/reference/android/bluetooth/BluetoothAdapter.html go/dac-stage/reference/android/bluetooth/BluetoothDevice.html go/dac-stage/reference/android/bluetooth/BluetoothServerSocket.html go/dac-stage/reference/android/inputmethodservice/InputMethodService.html go/dac-stage/reference/android/view/KeyCharacterMap.html go/dac-stage/reference/android/view/KeyEvent.html go/dac-stage/reference/android/media/AudioManager.html go/dac-stage/reference/android/net/wifi/WifiConfiguration.html (Other files were not in the public Javadocs.) Bug: 111925950 Test: make ds-docs Exempt-From-Owner-Approval: Docs-only change Change-Id: Ia06e1fffd814671289a1caebd5962aedc18a28d7 Merged-In: Ia06e1fffd814671289a1caebd5962aedc18a28d7 --- framework/java/android/bluetooth/BluetoothServerSocket.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'framework/java/android/bluetooth/BluetoothServerSocket.java') diff --git a/framework/java/android/bluetooth/BluetoothServerSocket.java b/framework/java/android/bluetooth/BluetoothServerSocket.java index ebb7f187ae..ca29ef37a2 100644 --- a/framework/java/android/bluetooth/BluetoothServerSocket.java +++ b/framework/java/android/bluetooth/BluetoothServerSocket.java @@ -201,7 +201,7 @@ public final class BluetoothServerSocket implements Closeable { /** * Returns the assigned dynamic protocol/service multiplexer (PSM) value for the listening L2CAP * Connection-oriented Channel (CoC) server socket. This server socket must be returned by the - * {#link BluetoothAdapter.listenUsingL2capCoc(int)} or {#link + * {@link BluetoothAdapter.listenUsingL2capCoc(int)} or {@link * BluetoothAdapter.listenUsingInsecureL2capCoc(int)}. The returned value is undefined if this * method is called on non-L2CAP server sockets. * -- cgit v1.2.3 From 3b28545bacc130289331e3aa6b73124fb547f990 Mon Sep 17 00:00:00 2001 From: Stanley Tng Date: Fri, 19 Apr 2019 14:27:09 -0700 Subject: Add more documentation for LE CoC Added more information into Android SDK for LE Connection-oriented Channels (CoC) so that it matches the corresponding RFComm documentation. Bug: 70683224 Test: Compile Change-Id: I40abde70a7ca6bcd194ee75bd8367c0ed9e97d05 --- .../android/bluetooth/BluetoothServerSocket.java | 35 +++++++++++++--------- 1 file changed, 21 insertions(+), 14 deletions(-) (limited to 'framework/java/android/bluetooth/BluetoothServerSocket.java') diff --git a/framework/java/android/bluetooth/BluetoothServerSocket.java b/framework/java/android/bluetooth/BluetoothServerSocket.java index 4e886250b4..c06b837a9e 100644 --- a/framework/java/android/bluetooth/BluetoothServerSocket.java +++ b/framework/java/android/bluetooth/BluetoothServerSocket.java @@ -35,21 +35,28 @@ import java.io.IOException; * On the client side, use a single {@link BluetoothSocket} to both initiate * an outgoing connection and to manage the connection. * - *

The most common type of Bluetooth socket is RFCOMM, which is the type - * supported by the Android APIs. RFCOMM is a connection-oriented, streaming - * transport over Bluetooth. It is also known as the Serial Port Profile (SPP). + *

For Bluetooth BR/EDR, the most common type of socket is RFCOMM, which is the type supported by + * the Android APIs. RFCOMM is a connection-oriented, streaming transport over Bluetooth BR/EDR. It + * is also known as the Serial Port Profile (SPP). To create a listening + * {@link BluetoothServerSocket} that's ready for incoming Bluetooth BR/EDR connections, use {@link + * BluetoothAdapter#listenUsingRfcommWithServiceRecord + * BluetoothAdapter.listenUsingRfcommWithServiceRecord()}. * - *

To create a listening {@link BluetoothServerSocket} that's ready for - * incoming connections, use - * {@link BluetoothAdapter#listenUsingRfcommWithServiceRecord - * BluetoothAdapter.listenUsingRfcommWithServiceRecord()}. Then call - * {@link #accept()} to listen for incoming connection requests. This call - * will block until a connection is established, at which point, it will return - * a {@link BluetoothSocket} to manage the connection. Once the {@link - * BluetoothSocket} is acquired, it's a good idea to call {@link #close()} on - * the {@link BluetoothServerSocket} when it's no longer needed for accepting - * connections. Closing the {@link BluetoothServerSocket} will not - * close the returned {@link BluetoothSocket}. + *

For Bluetooth LE, the socket uses LE Connection-oriented Channel (CoC). LE CoC is a + * connection-oriented, streaming transport over Bluetooth LE and has a credit-based flow control. + * Correspondingly, use {@link BluetoothAdapter#listenUsingL2capChannel + * BluetoothAdapter.listenUsingL2capChannel()} to create a listening {@link BluetoothServerSocket} + * that's ready for incoming Bluetooth LE CoC connections. For LE CoC, you can use {@link #getPsm()} + * to get the protocol/service multiplexer (PSM) value that the peer needs to use to connect to your + * socket. + * + *

After the listening {@link BluetoothServerSocket} is created, call {@link #accept()} to + * listen for incoming connection requests. This call will block until a connection is established, + * at which point, it will return a {@link BluetoothSocket} to manage the connection. Once the + * {@link BluetoothSocket} is acquired, it's a good idea to call {@link #close()} on the {@link + * BluetoothServerSocket} when it's no longer needed for accepting + * connections. Closing the {@link BluetoothServerSocket} will not close the returned + * {@link BluetoothSocket}. * *

{@link BluetoothServerSocket} is thread * safe. In particular, {@link #close} will always immediately abort ongoing -- cgit v1.2.3 From 147146fb21165bdf7812fa9745ca797b7d12b437 Mon Sep 17 00:00:00 2001 From: Andrei Onea Date: Mon, 17 Jun 2019 11:26:14 +0100 Subject: Document public alternatives to greylisted APIs Add known public alternatives or recommendations for greylisted APIs in Bluetooth. Bug: 135171386 Test: m Change-Id: I86e708be37eb7d1b0fafa2d64283b7f81bc02e51 --- framework/java/android/bluetooth/BluetoothServerSocket.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'framework/java/android/bluetooth/BluetoothServerSocket.java') diff --git a/framework/java/android/bluetooth/BluetoothServerSocket.java b/framework/java/android/bluetooth/BluetoothServerSocket.java index c06b837a9e..3a23808f36 100644 --- a/framework/java/android/bluetooth/BluetoothServerSocket.java +++ b/framework/java/android/bluetooth/BluetoothServerSocket.java @@ -77,7 +77,8 @@ public final class BluetoothServerSocket implements Closeable { private static final String TAG = "BluetoothServerSocket"; private static final boolean DBG = false; - @UnsupportedAppUsage + @UnsupportedAppUsage(publicAlternatives = "Use public {@link BluetoothServerSocket} API " + + "instead.") /*package*/ final BluetoothSocket mSocket; private Handler mHandler; private int mMessage; -- cgit v1.2.3 From d8fe38cc98bb4f49cd0c4ab9d7855f98ee1209f3 Mon Sep 17 00:00:00 2001 From: Artur Satayev Date: Tue, 10 Dec 2019 17:47:52 +0000 Subject: Use new UnsupportedAppUsage annotation. Existing annotations in libcore/ and frameworks/ will deleted after the migration. This also means that any java library that compiles @UnsupportedAppUsage requires a direct dependency on "unsupportedappusage" java_library. Bug: 145132366 Test: m && diff unsupportedappusage_index.csv Change-Id: I6ab53570aca580fbee1fcc927871caa09780f58f Merged-In: I6ab53570aca580fbee1fcc927871caa09780f58f --- framework/java/android/bluetooth/BluetoothServerSocket.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'framework/java/android/bluetooth/BluetoothServerSocket.java') diff --git a/framework/java/android/bluetooth/BluetoothServerSocket.java b/framework/java/android/bluetooth/BluetoothServerSocket.java index 3a23808f36..88c186c88a 100644 --- a/framework/java/android/bluetooth/BluetoothServerSocket.java +++ b/framework/java/android/bluetooth/BluetoothServerSocket.java @@ -16,7 +16,7 @@ package android.bluetooth; -import android.annotation.UnsupportedAppUsage; +import android.compat.annotation.UnsupportedAppUsage; import android.os.Handler; import android.os.ParcelUuid; import android.util.Log; -- cgit v1.2.3 From c5386afbc18b5164c381b1d8e099327953205436 Mon Sep 17 00:00:00 2001 From: Jeff Sharkey Date: Fri, 11 Sep 2020 14:57:21 -0600 Subject: Update language to comply with Android's inclusive language guidance See https://source.android.com/setup/contribute/respectful-code for reference Test: none Bug: 168334533 Exempt-From-Owner-Approval: docs updates Change-Id: I245b8d9cac722da76ea67983738a3cbb9deb68df --- framework/java/android/bluetooth/BluetoothServerSocket.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'framework/java/android/bluetooth/BluetoothServerSocket.java') diff --git a/framework/java/android/bluetooth/BluetoothServerSocket.java b/framework/java/android/bluetooth/BluetoothServerSocket.java index 88c186c88a..5c1bcaf313 100644 --- a/framework/java/android/bluetooth/BluetoothServerSocket.java +++ b/framework/java/android/bluetooth/BluetoothServerSocket.java @@ -110,7 +110,7 @@ public final class BluetoothServerSocket implements Closeable { * @param auth require the remote device to be authenticated * @param encrypt require the connection to be encrypted * @param port remote port - * @param mitm enforce man-in-the-middle protection for authentication. + * @param mitm enforce person-in-the-middle protection for authentication. * @param min16DigitPin enforce a minimum length of 16 digits for a sec mode 2 connection * @throws IOException On error, for example Bluetooth not available, or insufficient * privileges -- cgit v1.2.3 From 8f80e4a05b3f1b227f40de5ec0e9a6297154ffc0 Mon Sep 17 00:00:00 2001 From: Jeff Sharkey Date: Fri, 2 Apr 2021 08:06:09 -0600 Subject: Update Bluetooth API annotations. Recent work has introduced a new "Nearby devices" runtime permission which protects all existing Bluetooth APIs; we've done this by defining a to convert the old BLUETOOTH and BLUETOOTH_ADMIN permissions into one of three new permissions: * BLUETOOTH_ADVERTISE: Required to be able to advertise to nearby Bluetooth devices. * BLUETOOTH_CONNECT: Allows applications to connect to paired bluetooth devices. * BLUETOOTH_SCAN: Required to be able to discover and pair nearby Bluetooth devices. At its core, this change begins updating the Bluetooth APIs to have correct @RequiresPermission indicating which permission is actually enforced internally. To ensure alignment across Binder, the newly added "RequiresPermissionChecker" Error Prone checker was used to discover any inconsistencies, ensuring correctness from server-side enforcement up through to the public APIs. In addition, since developers will continue building apps for both modern and legacy platforms, this change introduces new auto-doc annotations which will emit helpful consistent documentation describing the behavior of older devices that are still using the old permission model. Bug: 183626724 Test: ./build/soong/soong_ui.bash --make-mode Bluetooth RUN_ERROR_PRONE=true Change-Id: I02aa127e8e07f239561f4f2a3bbdfc6fccb82f7f --- framework/java/android/bluetooth/BluetoothServerSocket.java | 3 --- 1 file changed, 3 deletions(-) (limited to 'framework/java/android/bluetooth/BluetoothServerSocket.java') diff --git a/framework/java/android/bluetooth/BluetoothServerSocket.java b/framework/java/android/bluetooth/BluetoothServerSocket.java index 5c1bcaf313..50822354d6 100644 --- a/framework/java/android/bluetooth/BluetoothServerSocket.java +++ b/framework/java/android/bluetooth/BluetoothServerSocket.java @@ -62,9 +62,6 @@ import java.io.IOException; * safe. In particular, {@link #close} will always immediately abort ongoing * operations and close the server socket. * - *

Note: - * Requires the {@link android.Manifest.permission#BLUETOOTH} permission. - * *

*

Developer Guides

*

For more information about using Bluetooth, read the -- cgit v1.2.3 From 5ba8bfca7e9adf5c6d8ee8180aebad6f04037d6c Mon Sep 17 00:00:00 2001 From: Jeff Sharkey Date: Fri, 16 Apr 2021 09:53:23 -0600 Subject: More Bluetooth API annotation updates. This change adds a "BluetoothPermissionChecker" that ensures that all Bluetooth permission annotations are consistent. In addition, it verifies that all Bluetooth public APIs have been audited to be permission protected where relevant. We've currently standardized on saying that APIs that return device or Bluetooth state information (without sharing details about any particular remote Bluetooth device) do not need to be permission protected. This change is only annotations and has no behavior changes. Bug: 183626724 Test: ./build/soong/soong_ui.bash --make-mode Bluetooth RUN_ERROR_PRONE=true Change-Id: Ie80b15b058359bf1e9a6ee881b89cb3e5b584ca1 --- framework/java/android/bluetooth/BluetoothServerSocket.java | 2 ++ 1 file changed, 2 insertions(+) (limited to 'framework/java/android/bluetooth/BluetoothServerSocket.java') diff --git a/framework/java/android/bluetooth/BluetoothServerSocket.java b/framework/java/android/bluetooth/BluetoothServerSocket.java index 50822354d6..bb4e35483f 100644 --- a/framework/java/android/bluetooth/BluetoothServerSocket.java +++ b/framework/java/android/bluetooth/BluetoothServerSocket.java @@ -16,6 +16,7 @@ package android.bluetooth; +import android.annotation.SuppressLint; import android.compat.annotation.UnsupportedAppUsage; import android.os.Handler; import android.os.ParcelUuid; @@ -70,6 +71,7 @@ import java.io.IOException; * * {@see BluetoothSocket} */ +@SuppressLint("AndroidFrameworkBluetoothPermission") public final class BluetoothServerSocket implements Closeable { private static final String TAG = "BluetoothServerSocket"; -- cgit v1.2.3