summaryrefslogtreecommitdiff
path: root/framework/java/android/bluetooth/BluetoothSocket.java
diff options
context:
space:
mode:
authorTreehugger Robot <treehugger-gerrit@google.com>2022-01-28 01:33:08 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2022-01-28 01:33:08 +0000
commitd6f8dbbcfe6fe54c90d9deabe60b1644698f9cd0 (patch)
treea481fa36fe2cbac3b412176245d3cfc31e5da640 /framework/java/android/bluetooth/BluetoothSocket.java
parentcf7c2303d91c61cb2f44f16deb4815e4f377f3a9 (diff)
parent0662f5b93c50096bc2deba7eca9f7828e2d6701b (diff)
Merge "Introduces mechanism for background rfcomm servers" am: 0662f5b93c
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Bluetooth/+/1885648 Change-Id: I4073bde2f8845d616f5a4a0fa9173db484f5ba92
Diffstat (limited to 'framework/java/android/bluetooth/BluetoothSocket.java')
-rw-r--r--framework/java/android/bluetooth/BluetoothSocket.java32
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]);