Loading framework/api/current.txt +4 −4 Original line number Diff line number Diff line Loading @@ -527,10 +527,10 @@ package android.bluetooth { method @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public android.bluetooth.BluetoothGatt connectGatt(android.content.Context, boolean, android.bluetooth.BluetoothGattCallback, int, int); method @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public android.bluetooth.BluetoothGatt connectGatt(android.content.Context, boolean, android.bluetooth.BluetoothGattCallback, int, int, android.os.Handler); method @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public boolean createBond(); method @NonNull @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public android.bluetooth.BluetoothSocket createInsecureL2capChannel(int) throws java.io.IOException; method @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public android.bluetooth.BluetoothSocket createInsecureRfcommSocketToServiceRecord(java.util.UUID) throws java.io.IOException; method @NonNull @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public android.bluetooth.BluetoothSocket createL2capChannel(int) throws java.io.IOException; method @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public android.bluetooth.BluetoothSocket createRfcommSocketToServiceRecord(java.util.UUID) throws java.io.IOException; method @NonNull public android.bluetooth.BluetoothSocket createInsecureL2capChannel(int) throws java.io.IOException; method public android.bluetooth.BluetoothSocket createInsecureRfcommSocketToServiceRecord(java.util.UUID) throws java.io.IOException; method @NonNull public android.bluetooth.BluetoothSocket createL2capChannel(int) throws java.io.IOException; method public android.bluetooth.BluetoothSocket createRfcommSocketToServiceRecord(java.util.UUID) throws java.io.IOException; method public int describeContents(); method @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public boolean fetchUuidsWithSdp(); method public String getAddress(); Loading framework/java/android/bluetooth/BluetoothDevice.java +10 −38 Original line number Diff line number Diff line Loading @@ -1416,8 +1416,7 @@ public final class BluetoothDevice implements Parcelable, Attributable { * * @hide */ @SystemApi public static final int ACTIVE_AUDIO_DEVICE_POLICY_DEFAULT = 0; @SystemApi public static final int ACTIVE_AUDIO_DEVICE_POLICY_DEFAULT = 0; /** * Indicates all profiles active audio device policy is applied to this device Loading Loading @@ -2794,15 +2793,12 @@ public final class BluetoothDevice implements Parcelable, Attributable { */ @UnsupportedAppUsage @RequiresLegacyBluetoothPermission @RequiresBluetoothConnectPermission @RequiresPermission(BLUETOOTH_CONNECT) @SuppressLint("AndroidFrameworkRequiresPermission") public BluetoothSocket createRfcommSocket(int channel) throws IOException { if (!isBluetoothEnabled()) { Log.e(TAG, "Bluetooth is not enabled"); throw new IOException(); } return new BluetoothSocket(BluetoothSocket.TYPE_RFCOMM, true, true, this, channel, null); return new BluetoothSocket(this, BluetoothSocket.TYPE_RFCOMM, true, true, channel, null); } /** Loading Loading @@ -2830,11 +2826,8 @@ public final class BluetoothDevice implements Parcelable, Attributable { * @hide */ @RequiresLegacyBluetoothPermission @RequiresBluetoothConnectPermission @RequiresPermission(BLUETOOTH_CONNECT) @SuppressLint("AndroidFrameworkRequiresPermission") public BluetoothSocket createL2capSocket(int channel) throws IOException { return new BluetoothSocket(BluetoothSocket.TYPE_L2CAP, true, true, this, channel, null); return new BluetoothSocket(this, BluetoothSocket.TYPE_L2CAP, true, true, channel, null); } /** Loading @@ -2855,11 +2848,8 @@ public final class BluetoothDevice implements Parcelable, Attributable { * @hide */ @RequiresLegacyBluetoothPermission @RequiresBluetoothConnectPermission @RequiresPermission(BLUETOOTH_CONNECT) @SuppressLint("AndroidFrameworkRequiresPermission") public BluetoothSocket createInsecureL2capSocket(int channel) throws IOException { return new BluetoothSocket(BluetoothSocket.TYPE_L2CAP, false, false, this, channel, null); return new BluetoothSocket(this, BluetoothSocket.TYPE_L2CAP, false, false, channel, null); } /** Loading Loading @@ -2893,9 +2883,6 @@ public final class BluetoothDevice implements Parcelable, Attributable { * permissions */ @RequiresLegacyBluetoothPermission @RequiresBluetoothConnectPermission @RequiresPermission(BLUETOOTH_CONNECT) @SuppressLint("AndroidFrameworkRequiresPermission") public BluetoothSocket createRfcommSocketToServiceRecord(UUID uuid) throws IOException { if (!isBluetoothEnabled()) { Log.e(TAG, "Bluetooth is not enabled"); Loading @@ -2903,7 +2890,7 @@ public final class BluetoothDevice implements Parcelable, Attributable { } return new BluetoothSocket( BluetoothSocket.TYPE_RFCOMM, true, true, this, -1, new ParcelUuid(uuid)); this, BluetoothSocket.TYPE_RFCOMM, true, true, -1, new ParcelUuid(uuid)); } /** Loading Loading @@ -2936,16 +2923,13 @@ public final class BluetoothDevice implements Parcelable, Attributable { * permissions */ @RequiresLegacyBluetoothPermission @RequiresBluetoothConnectPermission @RequiresPermission(BLUETOOTH_CONNECT) @SuppressLint("AndroidFrameworkRequiresPermission") public BluetoothSocket createInsecureRfcommSocketToServiceRecord(UUID uuid) throws IOException { if (!isBluetoothEnabled()) { Log.e(TAG, "Bluetooth is not enabled"); throw new IOException(); } return new BluetoothSocket( BluetoothSocket.TYPE_RFCOMM, false, false, this, -1, new ParcelUuid(uuid)); this, BluetoothSocket.TYPE_RFCOMM, false, false, -1, new ParcelUuid(uuid)); } /** Loading @@ -2963,15 +2947,12 @@ public final class BluetoothDevice implements Parcelable, Attributable { publicAlternatives = "Use " + "{@link #createInsecureRfcommSocketToServiceRecord} instead.") @RequiresLegacyBluetoothAdminPermission @RequiresBluetoothConnectPermission @RequiresPermission(BLUETOOTH_CONNECT) @SuppressLint("AndroidFrameworkRequiresPermission") public BluetoothSocket createInsecureRfcommSocket(int port) throws IOException { if (!isBluetoothEnabled()) { Log.e(TAG, "Bluetooth is not enabled"); throw new IOException(); } return new BluetoothSocket(BluetoothSocket.TYPE_RFCOMM, false, false, this, port, null); return new BluetoothSocket(this, BluetoothSocket.TYPE_RFCOMM, false, false, port, null); } /** Loading @@ -2985,15 +2966,12 @@ public final class BluetoothDevice implements Parcelable, Attributable { */ @UnsupportedAppUsage @RequiresLegacyBluetoothAdminPermission @RequiresBluetoothConnectPermission @RequiresPermission(BLUETOOTH_CONNECT) @SuppressLint("AndroidFrameworkRequiresPermission") public BluetoothSocket createScoSocket() throws IOException { if (!isBluetoothEnabled()) { Log.e(TAG, "Bluetooth is not enabled"); throw new IOException(); } return new BluetoothSocket(BluetoothSocket.TYPE_SCO, true, true, this, -1, null); return new BluetoothSocket(this, BluetoothSocket.TYPE_SCO, true, true, -1, null); } /** Loading Loading @@ -3197,16 +3175,13 @@ public final class BluetoothDevice implements Parcelable, Attributable { * permissions */ @RequiresLegacyBluetoothPermission @RequiresBluetoothConnectPermission @RequiresPermission(BLUETOOTH_CONNECT) @SuppressLint("AndroidFrameworkRequiresPermission") public @NonNull BluetoothSocket createL2capChannel(int psm) throws IOException { if (!isBluetoothEnabled()) { Log.e(TAG, "createL2capChannel: Bluetooth is not enabled"); throw new IOException(); } if (DBG) Log.d(TAG, "createL2capChannel: psm=" + psm); return new BluetoothSocket(BluetoothSocket.TYPE_L2CAP_LE, true, true, this, psm, null); return new BluetoothSocket(this, BluetoothSocket.TYPE_L2CAP_LE, true, true, psm, null); } /** Loading @@ -3231,9 +3206,6 @@ public final class BluetoothDevice implements Parcelable, Attributable { * permissions */ @RequiresLegacyBluetoothPermission @RequiresBluetoothConnectPermission @RequiresPermission(BLUETOOTH_CONNECT) @SuppressLint("AndroidFrameworkRequiresPermission") public @NonNull BluetoothSocket createInsecureL2capChannel(int psm) throws IOException { if (!isBluetoothEnabled()) { Log.e(TAG, "createInsecureL2capChannel: Bluetooth is not enabled"); Loading @@ -3242,7 +3214,7 @@ public final class BluetoothDevice implements Parcelable, Attributable { if (DBG) { Log.d(TAG, "createInsecureL2capChannel: psm=" + psm); } return new BluetoothSocket(BluetoothSocket.TYPE_L2CAP_LE, false, false, this, psm, null); return new BluetoothSocket(this, BluetoothSocket.TYPE_L2CAP_LE, false, false, psm, null); } /** Loading framework/java/android/bluetooth/BluetoothServerSocket.java +5 −5 Original line number Diff line number Diff line Loading @@ -103,7 +103,7 @@ public final class BluetoothServerSocket implements Closeable { mSocketCreationTimeMillis = System.currentTimeMillis(); mType = type; mChannel = port; mSocket = new BluetoothSocket(type, auth, encrypt, null, port, null); mSocket = new BluetoothSocket(type, auth, encrypt, port, null); if (port == BluetoothAdapter.SOCKET_CHANNEL_AUTO_STATIC_NO_SDP) { mSocket.setExcludeSdp(true); } Loading @@ -117,17 +117,17 @@ 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 person-in-the-middle protection for authentication. * @param pitm 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 */ /*package*/ BluetoothServerSocket( int type, boolean auth, boolean encrypt, int port, boolean mitm, boolean min16DigitPin) int type, boolean auth, boolean encrypt, int port, boolean pitm, boolean min16DigitPin) throws IOException { mSocketCreationTimeMillis = System.currentTimeMillis(); mType = type; mChannel = port; mSocket = new BluetoothSocket(type, auth, encrypt, null, port, null, mitm, min16DigitPin); mSocket = new BluetoothSocket(type, auth, encrypt, port, null, pitm, min16DigitPin); if (port == BluetoothAdapter.SOCKET_CHANNEL_AUTO_STATIC_NO_SDP) { mSocket.setExcludeSdp(true); } Loading @@ -147,7 +147,7 @@ public final class BluetoothServerSocket implements Closeable { throws IOException { mSocketCreationTimeMillis = System.currentTimeMillis(); mType = type; mSocket = new BluetoothSocket(type, auth, encrypt, null, -1, uuid); mSocket = new BluetoothSocket(type, auth, encrypt, -1, uuid); // TODO: This is the same as mChannel = -1 - is this intentional? mChannel = mSocket.getPort(); mSocketCreationLatencyMillis = System.currentTimeMillis() - mSocketCreationTimeMillis; Loading framework/java/android/bluetooth/BluetoothSocket.java +90 −20 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ import static android.Manifest.permission.BLUETOOTH_PRIVILEGED; import static android.Manifest.permission.LOCAL_MAC_ADDRESS; import android.annotation.FlaggedApi; import android.annotation.NonNull; import android.annotation.RequiresNoPermission; import android.annotation.RequiresPermission; import android.annotation.SystemApi; Loading Loading @@ -130,7 +131,7 @@ public final class BluetoothSocket implements Closeable { /*package*/ static final int SEC_FLAG_ENCRYPT = 1; /*package*/ static final int SEC_FLAG_AUTH = 1 << 1; /*package*/ static final int BTSOCK_FLAG_NO_SDP = 1 << 2; /*package*/ static final int SEC_FLAG_AUTH_MITM = 1 << 3; /*package*/ static final int SEC_FLAG_AUTH_PITM = 1 << 3; /*package*/ static final int SEC_FLAG_AUTH_16_DIGIT = 1 << 4; private final int mType; /* one of TYPE_RFCOMM etc */ Loading @@ -146,7 +147,7 @@ public final class BluetoothSocket implements Closeable { private boolean mExcludeSdp = false; /** when true Person-in-the-middle protection will be enabled */ private boolean mAuthMitm = false; private boolean mAuthPitm = false; /** Minimum 16 digit pin for sec mode 2 connections */ private boolean mMin16DigitPin = false; Loading Loading @@ -189,7 +190,6 @@ public final class BluetoothSocket implements Closeable { * @param type type of socket * @param auth require the remote device to be authenticated * @param encrypt require the connection to be encrypted * @param device remote device that this socket can connect to * @param port remote port * @param uuid SDP uuid * @throws IOException On error, for example Bluetooth not available, or insufficient privileges Loading @@ -199,11 +199,10 @@ public final class BluetoothSocket implements Closeable { int type, boolean auth, boolean encrypt, BluetoothDevice device, int port, ParcelUuid uuid) throws IOException { this(type, auth, encrypt, device, port, uuid, false, false); this(type, auth, encrypt, port, uuid, false, false); } /** Loading @@ -212,10 +211,9 @@ public final class BluetoothSocket implements Closeable { * @param type type of socket * @param auth require the remote device to be authenticated * @param encrypt require the connection to be encrypted * @param device remote device that this socket can connect to * @param port remote port * @param uuid SDP uuid * @param mitm enforce person-in-the-middle protection. * @param pitm enforce person-in-the-middle protection. * @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 */ Loading @@ -224,10 +222,9 @@ public final class BluetoothSocket implements Closeable { int type, boolean auth, boolean encrypt, BluetoothDevice device, int port, ParcelUuid uuid, boolean mitm, boolean pitm, boolean min16DigitPin) throws IOException { if (VDBG) Log.d(TAG, "Creating new BluetoothSocket of type: " + type); Loading @@ -246,21 +243,94 @@ public final class BluetoothSocket implements Closeable { } mType = type; mAuth = auth; mAuthMitm = mitm; mAuthPitm = pitm; mMin16DigitPin = min16DigitPin; mEncrypt = encrypt; mDevice = device; mPort = port; // this constructor to be called only from BluetoothServerSocket mDevice = null; mSocketState = SocketState.INIT; if (device == null) { // Server socket mAddress = BluetoothAdapter.getDefaultAdapter().getAddress(); mInputStream = new BluetoothInputStream(this); mOutputStream = new BluetoothOutputStream(this); mSocketCreationLatencyNanos = System.nanoTime() - mSocketCreationTimeNanos; } /** * Construct a BluetoothSocket. * * @param device remote device that this socket can connect to * @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 uuid SDP uuid * @throws IOException On error, for example Bluetooth not available, or insufficient privileges */ /*package*/ BluetoothSocket( BluetoothDevice device, int type, boolean auth, boolean encrypt, int port, ParcelUuid uuid) throws IOException { this(device, type, auth, encrypt, port, uuid, false, false); } /** * Construct a BluetoothSocket. * * @param device remote device that this socket can connect to * @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 uuid SDP uuid * @param pitm enforce person-in-the-middle protection. * @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*/ BluetoothSocket( @NonNull BluetoothDevice device, int type, boolean auth, boolean encrypt, int port, ParcelUuid uuid, boolean pitm, boolean min16DigitPin) throws IOException { if (VDBG) Log.d(TAG, "Creating new BluetoothSocket of type: " + type); mSocketCreationTimeNanos = System.nanoTime(); if (type == BluetoothSocket.TYPE_RFCOMM && uuid == null && port != BluetoothAdapter.SOCKET_CHANNEL_AUTO_STATIC_NO_SDP) { if (port < 1 || port > MAX_RFCOMM_CHANNEL) { throw new IOException("Invalid RFCOMM channel: " + port); } } if (uuid != null) { mUuid = uuid; } else { mUuid = new ParcelUuid(new UUID(0, 0)); } mType = type; mAuth = auth; mAuthPitm = pitm; mMin16DigitPin = min16DigitPin; mEncrypt = encrypt; mDevice = device; mPort = port; mSocketState = SocketState.INIT; // Remote socket mAddress = device.getAddress(); } mInputStream = new BluetoothInputStream(this); mOutputStream = new BluetoothOutputStream(this); mSocketCreationLatencyNanos = System.nanoTime() - mSocketCreationTimeNanos; Loading @@ -282,7 +352,7 @@ public final class BluetoothSocket implements Closeable { /*package*/ static BluetoothSocket createSocketFromOpenFd( ParcelFileDescriptor pfd, BluetoothDevice device, ParcelUuid uuid) throws IOException { BluetoothSocket bluetoothSocket = new BluetoothSocket(TYPE_RFCOMM, true, true, device, -1, uuid); new BluetoothSocket(device, TYPE_RFCOMM, true, true, -1, uuid); bluetoothSocket.mPfd = pfd; bluetoothSocket.mSocket = new LocalSocket(pfd.getFileDescriptor()); Loading @@ -308,7 +378,7 @@ public final class BluetoothSocket implements Closeable { mServiceName = s.mServiceName; mExcludeSdp = s.mExcludeSdp; mAuthMitm = s.mAuthMitm; mAuthPitm = s.mAuthPitm; mMin16DigitPin = s.mMin16DigitPin; mSocketCreationTimeNanos = s.mSocketCreationTimeNanos; mSocketCreationLatencyNanos = s.mSocketCreationLatencyNanos; Loading Loading @@ -356,8 +426,8 @@ public final class BluetoothSocket implements Closeable { if (mExcludeSdp) { flags |= BTSOCK_FLAG_NO_SDP; } if (mAuthMitm) { flags |= SEC_FLAG_AUTH_MITM; if (mAuthPitm) { flags |= SEC_FLAG_AUTH_PITM; } if (mMin16DigitPin) { flags |= SEC_FLAG_AUTH_16_DIGIT; Loading Loading
framework/api/current.txt +4 −4 Original line number Diff line number Diff line Loading @@ -527,10 +527,10 @@ package android.bluetooth { method @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public android.bluetooth.BluetoothGatt connectGatt(android.content.Context, boolean, android.bluetooth.BluetoothGattCallback, int, int); method @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public android.bluetooth.BluetoothGatt connectGatt(android.content.Context, boolean, android.bluetooth.BluetoothGattCallback, int, int, android.os.Handler); method @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public boolean createBond(); method @NonNull @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public android.bluetooth.BluetoothSocket createInsecureL2capChannel(int) throws java.io.IOException; method @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public android.bluetooth.BluetoothSocket createInsecureRfcommSocketToServiceRecord(java.util.UUID) throws java.io.IOException; method @NonNull @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public android.bluetooth.BluetoothSocket createL2capChannel(int) throws java.io.IOException; method @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public android.bluetooth.BluetoothSocket createRfcommSocketToServiceRecord(java.util.UUID) throws java.io.IOException; method @NonNull public android.bluetooth.BluetoothSocket createInsecureL2capChannel(int) throws java.io.IOException; method public android.bluetooth.BluetoothSocket createInsecureRfcommSocketToServiceRecord(java.util.UUID) throws java.io.IOException; method @NonNull public android.bluetooth.BluetoothSocket createL2capChannel(int) throws java.io.IOException; method public android.bluetooth.BluetoothSocket createRfcommSocketToServiceRecord(java.util.UUID) throws java.io.IOException; method public int describeContents(); method @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public boolean fetchUuidsWithSdp(); method public String getAddress(); Loading
framework/java/android/bluetooth/BluetoothDevice.java +10 −38 Original line number Diff line number Diff line Loading @@ -1416,8 +1416,7 @@ public final class BluetoothDevice implements Parcelable, Attributable { * * @hide */ @SystemApi public static final int ACTIVE_AUDIO_DEVICE_POLICY_DEFAULT = 0; @SystemApi public static final int ACTIVE_AUDIO_DEVICE_POLICY_DEFAULT = 0; /** * Indicates all profiles active audio device policy is applied to this device Loading Loading @@ -2794,15 +2793,12 @@ public final class BluetoothDevice implements Parcelable, Attributable { */ @UnsupportedAppUsage @RequiresLegacyBluetoothPermission @RequiresBluetoothConnectPermission @RequiresPermission(BLUETOOTH_CONNECT) @SuppressLint("AndroidFrameworkRequiresPermission") public BluetoothSocket createRfcommSocket(int channel) throws IOException { if (!isBluetoothEnabled()) { Log.e(TAG, "Bluetooth is not enabled"); throw new IOException(); } return new BluetoothSocket(BluetoothSocket.TYPE_RFCOMM, true, true, this, channel, null); return new BluetoothSocket(this, BluetoothSocket.TYPE_RFCOMM, true, true, channel, null); } /** Loading Loading @@ -2830,11 +2826,8 @@ public final class BluetoothDevice implements Parcelable, Attributable { * @hide */ @RequiresLegacyBluetoothPermission @RequiresBluetoothConnectPermission @RequiresPermission(BLUETOOTH_CONNECT) @SuppressLint("AndroidFrameworkRequiresPermission") public BluetoothSocket createL2capSocket(int channel) throws IOException { return new BluetoothSocket(BluetoothSocket.TYPE_L2CAP, true, true, this, channel, null); return new BluetoothSocket(this, BluetoothSocket.TYPE_L2CAP, true, true, channel, null); } /** Loading @@ -2855,11 +2848,8 @@ public final class BluetoothDevice implements Parcelable, Attributable { * @hide */ @RequiresLegacyBluetoothPermission @RequiresBluetoothConnectPermission @RequiresPermission(BLUETOOTH_CONNECT) @SuppressLint("AndroidFrameworkRequiresPermission") public BluetoothSocket createInsecureL2capSocket(int channel) throws IOException { return new BluetoothSocket(BluetoothSocket.TYPE_L2CAP, false, false, this, channel, null); return new BluetoothSocket(this, BluetoothSocket.TYPE_L2CAP, false, false, channel, null); } /** Loading Loading @@ -2893,9 +2883,6 @@ public final class BluetoothDevice implements Parcelable, Attributable { * permissions */ @RequiresLegacyBluetoothPermission @RequiresBluetoothConnectPermission @RequiresPermission(BLUETOOTH_CONNECT) @SuppressLint("AndroidFrameworkRequiresPermission") public BluetoothSocket createRfcommSocketToServiceRecord(UUID uuid) throws IOException { if (!isBluetoothEnabled()) { Log.e(TAG, "Bluetooth is not enabled"); Loading @@ -2903,7 +2890,7 @@ public final class BluetoothDevice implements Parcelable, Attributable { } return new BluetoothSocket( BluetoothSocket.TYPE_RFCOMM, true, true, this, -1, new ParcelUuid(uuid)); this, BluetoothSocket.TYPE_RFCOMM, true, true, -1, new ParcelUuid(uuid)); } /** Loading Loading @@ -2936,16 +2923,13 @@ public final class BluetoothDevice implements Parcelable, Attributable { * permissions */ @RequiresLegacyBluetoothPermission @RequiresBluetoothConnectPermission @RequiresPermission(BLUETOOTH_CONNECT) @SuppressLint("AndroidFrameworkRequiresPermission") public BluetoothSocket createInsecureRfcommSocketToServiceRecord(UUID uuid) throws IOException { if (!isBluetoothEnabled()) { Log.e(TAG, "Bluetooth is not enabled"); throw new IOException(); } return new BluetoothSocket( BluetoothSocket.TYPE_RFCOMM, false, false, this, -1, new ParcelUuid(uuid)); this, BluetoothSocket.TYPE_RFCOMM, false, false, -1, new ParcelUuid(uuid)); } /** Loading @@ -2963,15 +2947,12 @@ public final class BluetoothDevice implements Parcelable, Attributable { publicAlternatives = "Use " + "{@link #createInsecureRfcommSocketToServiceRecord} instead.") @RequiresLegacyBluetoothAdminPermission @RequiresBluetoothConnectPermission @RequiresPermission(BLUETOOTH_CONNECT) @SuppressLint("AndroidFrameworkRequiresPermission") public BluetoothSocket createInsecureRfcommSocket(int port) throws IOException { if (!isBluetoothEnabled()) { Log.e(TAG, "Bluetooth is not enabled"); throw new IOException(); } return new BluetoothSocket(BluetoothSocket.TYPE_RFCOMM, false, false, this, port, null); return new BluetoothSocket(this, BluetoothSocket.TYPE_RFCOMM, false, false, port, null); } /** Loading @@ -2985,15 +2966,12 @@ public final class BluetoothDevice implements Parcelable, Attributable { */ @UnsupportedAppUsage @RequiresLegacyBluetoothAdminPermission @RequiresBluetoothConnectPermission @RequiresPermission(BLUETOOTH_CONNECT) @SuppressLint("AndroidFrameworkRequiresPermission") public BluetoothSocket createScoSocket() throws IOException { if (!isBluetoothEnabled()) { Log.e(TAG, "Bluetooth is not enabled"); throw new IOException(); } return new BluetoothSocket(BluetoothSocket.TYPE_SCO, true, true, this, -1, null); return new BluetoothSocket(this, BluetoothSocket.TYPE_SCO, true, true, -1, null); } /** Loading Loading @@ -3197,16 +3175,13 @@ public final class BluetoothDevice implements Parcelable, Attributable { * permissions */ @RequiresLegacyBluetoothPermission @RequiresBluetoothConnectPermission @RequiresPermission(BLUETOOTH_CONNECT) @SuppressLint("AndroidFrameworkRequiresPermission") public @NonNull BluetoothSocket createL2capChannel(int psm) throws IOException { if (!isBluetoothEnabled()) { Log.e(TAG, "createL2capChannel: Bluetooth is not enabled"); throw new IOException(); } if (DBG) Log.d(TAG, "createL2capChannel: psm=" + psm); return new BluetoothSocket(BluetoothSocket.TYPE_L2CAP_LE, true, true, this, psm, null); return new BluetoothSocket(this, BluetoothSocket.TYPE_L2CAP_LE, true, true, psm, null); } /** Loading @@ -3231,9 +3206,6 @@ public final class BluetoothDevice implements Parcelable, Attributable { * permissions */ @RequiresLegacyBluetoothPermission @RequiresBluetoothConnectPermission @RequiresPermission(BLUETOOTH_CONNECT) @SuppressLint("AndroidFrameworkRequiresPermission") public @NonNull BluetoothSocket createInsecureL2capChannel(int psm) throws IOException { if (!isBluetoothEnabled()) { Log.e(TAG, "createInsecureL2capChannel: Bluetooth is not enabled"); Loading @@ -3242,7 +3214,7 @@ public final class BluetoothDevice implements Parcelable, Attributable { if (DBG) { Log.d(TAG, "createInsecureL2capChannel: psm=" + psm); } return new BluetoothSocket(BluetoothSocket.TYPE_L2CAP_LE, false, false, this, psm, null); return new BluetoothSocket(this, BluetoothSocket.TYPE_L2CAP_LE, false, false, psm, null); } /** Loading
framework/java/android/bluetooth/BluetoothServerSocket.java +5 −5 Original line number Diff line number Diff line Loading @@ -103,7 +103,7 @@ public final class BluetoothServerSocket implements Closeable { mSocketCreationTimeMillis = System.currentTimeMillis(); mType = type; mChannel = port; mSocket = new BluetoothSocket(type, auth, encrypt, null, port, null); mSocket = new BluetoothSocket(type, auth, encrypt, port, null); if (port == BluetoothAdapter.SOCKET_CHANNEL_AUTO_STATIC_NO_SDP) { mSocket.setExcludeSdp(true); } Loading @@ -117,17 +117,17 @@ 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 person-in-the-middle protection for authentication. * @param pitm 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 */ /*package*/ BluetoothServerSocket( int type, boolean auth, boolean encrypt, int port, boolean mitm, boolean min16DigitPin) int type, boolean auth, boolean encrypt, int port, boolean pitm, boolean min16DigitPin) throws IOException { mSocketCreationTimeMillis = System.currentTimeMillis(); mType = type; mChannel = port; mSocket = new BluetoothSocket(type, auth, encrypt, null, port, null, mitm, min16DigitPin); mSocket = new BluetoothSocket(type, auth, encrypt, port, null, pitm, min16DigitPin); if (port == BluetoothAdapter.SOCKET_CHANNEL_AUTO_STATIC_NO_SDP) { mSocket.setExcludeSdp(true); } Loading @@ -147,7 +147,7 @@ public final class BluetoothServerSocket implements Closeable { throws IOException { mSocketCreationTimeMillis = System.currentTimeMillis(); mType = type; mSocket = new BluetoothSocket(type, auth, encrypt, null, -1, uuid); mSocket = new BluetoothSocket(type, auth, encrypt, -1, uuid); // TODO: This is the same as mChannel = -1 - is this intentional? mChannel = mSocket.getPort(); mSocketCreationLatencyMillis = System.currentTimeMillis() - mSocketCreationTimeMillis; Loading
framework/java/android/bluetooth/BluetoothSocket.java +90 −20 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ import static android.Manifest.permission.BLUETOOTH_PRIVILEGED; import static android.Manifest.permission.LOCAL_MAC_ADDRESS; import android.annotation.FlaggedApi; import android.annotation.NonNull; import android.annotation.RequiresNoPermission; import android.annotation.RequiresPermission; import android.annotation.SystemApi; Loading Loading @@ -130,7 +131,7 @@ public final class BluetoothSocket implements Closeable { /*package*/ static final int SEC_FLAG_ENCRYPT = 1; /*package*/ static final int SEC_FLAG_AUTH = 1 << 1; /*package*/ static final int BTSOCK_FLAG_NO_SDP = 1 << 2; /*package*/ static final int SEC_FLAG_AUTH_MITM = 1 << 3; /*package*/ static final int SEC_FLAG_AUTH_PITM = 1 << 3; /*package*/ static final int SEC_FLAG_AUTH_16_DIGIT = 1 << 4; private final int mType; /* one of TYPE_RFCOMM etc */ Loading @@ -146,7 +147,7 @@ public final class BluetoothSocket implements Closeable { private boolean mExcludeSdp = false; /** when true Person-in-the-middle protection will be enabled */ private boolean mAuthMitm = false; private boolean mAuthPitm = false; /** Minimum 16 digit pin for sec mode 2 connections */ private boolean mMin16DigitPin = false; Loading Loading @@ -189,7 +190,6 @@ public final class BluetoothSocket implements Closeable { * @param type type of socket * @param auth require the remote device to be authenticated * @param encrypt require the connection to be encrypted * @param device remote device that this socket can connect to * @param port remote port * @param uuid SDP uuid * @throws IOException On error, for example Bluetooth not available, or insufficient privileges Loading @@ -199,11 +199,10 @@ public final class BluetoothSocket implements Closeable { int type, boolean auth, boolean encrypt, BluetoothDevice device, int port, ParcelUuid uuid) throws IOException { this(type, auth, encrypt, device, port, uuid, false, false); this(type, auth, encrypt, port, uuid, false, false); } /** Loading @@ -212,10 +211,9 @@ public final class BluetoothSocket implements Closeable { * @param type type of socket * @param auth require the remote device to be authenticated * @param encrypt require the connection to be encrypted * @param device remote device that this socket can connect to * @param port remote port * @param uuid SDP uuid * @param mitm enforce person-in-the-middle protection. * @param pitm enforce person-in-the-middle protection. * @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 */ Loading @@ -224,10 +222,9 @@ public final class BluetoothSocket implements Closeable { int type, boolean auth, boolean encrypt, BluetoothDevice device, int port, ParcelUuid uuid, boolean mitm, boolean pitm, boolean min16DigitPin) throws IOException { if (VDBG) Log.d(TAG, "Creating new BluetoothSocket of type: " + type); Loading @@ -246,21 +243,94 @@ public final class BluetoothSocket implements Closeable { } mType = type; mAuth = auth; mAuthMitm = mitm; mAuthPitm = pitm; mMin16DigitPin = min16DigitPin; mEncrypt = encrypt; mDevice = device; mPort = port; // this constructor to be called only from BluetoothServerSocket mDevice = null; mSocketState = SocketState.INIT; if (device == null) { // Server socket mAddress = BluetoothAdapter.getDefaultAdapter().getAddress(); mInputStream = new BluetoothInputStream(this); mOutputStream = new BluetoothOutputStream(this); mSocketCreationLatencyNanos = System.nanoTime() - mSocketCreationTimeNanos; } /** * Construct a BluetoothSocket. * * @param device remote device that this socket can connect to * @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 uuid SDP uuid * @throws IOException On error, for example Bluetooth not available, or insufficient privileges */ /*package*/ BluetoothSocket( BluetoothDevice device, int type, boolean auth, boolean encrypt, int port, ParcelUuid uuid) throws IOException { this(device, type, auth, encrypt, port, uuid, false, false); } /** * Construct a BluetoothSocket. * * @param device remote device that this socket can connect to * @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 uuid SDP uuid * @param pitm enforce person-in-the-middle protection. * @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*/ BluetoothSocket( @NonNull BluetoothDevice device, int type, boolean auth, boolean encrypt, int port, ParcelUuid uuid, boolean pitm, boolean min16DigitPin) throws IOException { if (VDBG) Log.d(TAG, "Creating new BluetoothSocket of type: " + type); mSocketCreationTimeNanos = System.nanoTime(); if (type == BluetoothSocket.TYPE_RFCOMM && uuid == null && port != BluetoothAdapter.SOCKET_CHANNEL_AUTO_STATIC_NO_SDP) { if (port < 1 || port > MAX_RFCOMM_CHANNEL) { throw new IOException("Invalid RFCOMM channel: " + port); } } if (uuid != null) { mUuid = uuid; } else { mUuid = new ParcelUuid(new UUID(0, 0)); } mType = type; mAuth = auth; mAuthPitm = pitm; mMin16DigitPin = min16DigitPin; mEncrypt = encrypt; mDevice = device; mPort = port; mSocketState = SocketState.INIT; // Remote socket mAddress = device.getAddress(); } mInputStream = new BluetoothInputStream(this); mOutputStream = new BluetoothOutputStream(this); mSocketCreationLatencyNanos = System.nanoTime() - mSocketCreationTimeNanos; Loading @@ -282,7 +352,7 @@ public final class BluetoothSocket implements Closeable { /*package*/ static BluetoothSocket createSocketFromOpenFd( ParcelFileDescriptor pfd, BluetoothDevice device, ParcelUuid uuid) throws IOException { BluetoothSocket bluetoothSocket = new BluetoothSocket(TYPE_RFCOMM, true, true, device, -1, uuid); new BluetoothSocket(device, TYPE_RFCOMM, true, true, -1, uuid); bluetoothSocket.mPfd = pfd; bluetoothSocket.mSocket = new LocalSocket(pfd.getFileDescriptor()); Loading @@ -308,7 +378,7 @@ public final class BluetoothSocket implements Closeable { mServiceName = s.mServiceName; mExcludeSdp = s.mExcludeSdp; mAuthMitm = s.mAuthMitm; mAuthPitm = s.mAuthPitm; mMin16DigitPin = s.mMin16DigitPin; mSocketCreationTimeNanos = s.mSocketCreationTimeNanos; mSocketCreationLatencyNanos = s.mSocketCreationLatencyNanos; Loading Loading @@ -356,8 +426,8 @@ public final class BluetoothSocket implements Closeable { if (mExcludeSdp) { flags |= BTSOCK_FLAG_NO_SDP; } if (mAuthMitm) { flags |= SEC_FLAG_AUTH_MITM; if (mAuthPitm) { flags |= SEC_FLAG_AUTH_PITM; } if (mMin16DigitPin) { flags |= SEC_FLAG_AUTH_16_DIGIT; Loading