diff options
author | Treehugger Robot <treehugger-gerrit@google.com> | 2022-01-28 01:44:00 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2022-01-28 01:44:00 +0000 |
commit | a4195e47e41972a8308a66abb8b9995daf6edbcc (patch) | |
tree | fed65680473b8e007e981805b18ea0ea073e02e7 /framework/java/android/bluetooth/BluetoothSocket.java | |
parent | 6ca88d122bd794a1e432f2dc1ae4b785dd4eaa63 (diff) | |
parent | d6f8dbbcfe6fe54c90d9deabe60b1644698f9cd0 (diff) |
Merge "Introduces mechanism for background rfcomm servers" am: 0662f5b93c am: d6f8dbbcfe
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Bluetooth/+/1885648
Change-Id: Iee0e7a37f422586e200c151655c4c3a552afdada
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]); |