diff options
author | tadvana <tadvana@google.com> | 2022-01-26 10:35:38 -0800 |
---|---|---|
committer | tadvana <tadvana@google.com> | 2022-01-26 10:36:55 -0800 |
commit | f62b536dbf10265f5e03d103ba39bf939716f2b6 (patch) | |
tree | 8e2e2aa1ef76ba021dd682b5de4165bd5637774d /framework/java/android/bluetooth/BluetoothSocket.java | |
parent | 4d912eeccb643ac13016a5999b6bca6349052e5b (diff) |
Introduces mechanism for background rfcomm servers
This change adds a mechanism in the AdapterService which allows it to
register RFCOMM listeners requested by a BluetoothAdapter.
This is so that applications can request the framework to listen for
incoming RFCOMM connections in the background.
Apps can request that the bluetooth manager, via a BluetoothAdapter,
listen on a specific service record, and then transact incoming socket
connections after receiving a notification of availability via a
PendingIntent.
Tag: #feature
Test: Run the CTS Bluetooth Rfcomm Handoff service Test. This requires
two devices.
Bug: 186494155
Ignore-AOSP-First: Need to commit to downstream first in order to
resolve a merge conflict.
Change-Id: Ia0c71969e691e6353f22fe3b7dae4a7500230e03
Diffstat (limited to 'framework/java/android/bluetooth/BluetoothSocket.java')
-rw-r--r-- | framework/java/android/bluetooth/BluetoothSocket.java | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/framework/java/android/bluetooth/BluetoothSocket.java b/framework/java/android/bluetooth/BluetoothSocket.java index 9d58447607..032f9df4f7 100644 --- a/framework/java/android/bluetooth/BluetoothSocket.java +++ b/framework/java/android/bluetooth/BluetoothSocket.java @@ -236,6 +236,33 @@ public final class BluetoothSocket implements Closeable { mOutputStream = new BluetoothOutputStream(this); } + /** + * Creates a BluetoothSocket from a {@link ParcelFileDescriptor}. This is used for when the + * underlying mPfd is transferred to a separate process (e.g. over a binder), and the socket + * must be reconstructed. + * <p> + * The socket should already be connected in this case, so {@link #connect()} should not be + * called. + * + * @param pfd is the {@link ParcelFileDescriptor} for an already connected BluetoothSocket + * @param device is the remote {@link BluetoothDevice} that this socket is connected to + * @param uuid is the service ID that this RFCOMM connection is using + * @throws IOException if socket creation fails. + */ + /*package*/ static BluetoothSocket createSocketFromOpenFd( + ParcelFileDescriptor pfd, BluetoothDevice device, ParcelUuid uuid) throws IOException { + BluetoothSocket bluetoothSocket = + new BluetoothSocket(TYPE_RFCOMM, pfd.getFd(), true, true, device, -1, uuid); + + bluetoothSocket.mPfd = pfd; + bluetoothSocket.mSocket = new LocalSocket(pfd.getFileDescriptor()); + bluetoothSocket.mSocketIS = bluetoothSocket.mSocket.getInputStream(); + bluetoothSocket.mSocketOS = bluetoothSocket.mSocket.getOutputStream(); + bluetoothSocket.mSocketState = SocketState.CONNECTED; + + return bluetoothSocket; + } + private BluetoothSocket(BluetoothSocket s) { if (VDBG) Log.d(TAG, "Creating new Private BluetoothSocket of type: " + s.mType); mUuid = s.mUuid; @@ -718,6 +745,11 @@ public final class BluetoothSocket implements Closeable { } } + /** @hide */ + public ParcelFileDescriptor getParcelFileDescriptor() { + return mPfd; + } + private String convertAddr(final byte[] addr) { return String.format(Locale.US, "%02X:%02X:%02X:%02X:%02X:%02X", addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]); |