diff options
9 files changed, 243 insertions, 258 deletions
diff --git a/android/app/src/com/android/bluetooth/gatt/CallbackInfo.java b/android/app/src/com/android/bluetooth/gatt/CallbackInfo.java index f104b7ee19..fb7f34a602 100644 --- a/android/app/src/com/android/bluetooth/gatt/CallbackInfo.java +++ b/android/app/src/com/android/bluetooth/gatt/CallbackInfo.java @@ -15,46 +15,18 @@ */ package com.android.bluetooth.gatt; +import com.google.protobuf.ByteString; + /** * Helper class that keeps track of callback parameters for app callbacks. These are held during * congestion and reported when congestion clears. */ -public class CallbackInfo { - public String address; - public int status; - public int handle; - public byte[] value; - - static class Builder { - private final String mAddress; - private final int mStatus; - private int mHandle; - private byte[] mValue; - - Builder(String address, int status) { - mAddress = address; - mStatus = status; - } - - Builder setHandle(int handle) { - mHandle = handle; - return this; - } - - Builder setValue(byte[] value) { - mValue = value; - return this; - } - - CallbackInfo build() { - return new CallbackInfo(mAddress, mStatus, mHandle, mValue); - } +record CallbackInfo(String address, int status, int handle, ByteString value) { + CallbackInfo(String address, int status) { + this(address, status, 0, null); } - private CallbackInfo(String address, int status, int handle, byte[] value) { - this.address = address; - this.status = status; - this.handle = handle; - this.value = value; + byte[] valueByteArray() { + return value == null ? null : value.toByteArray(); } } diff --git a/android/app/src/com/android/bluetooth/gatt/GattService.java b/android/app/src/com/android/bluetooth/gatt/GattService.java index f4cf8e5a1b..09c648f2be 100644 --- a/android/app/src/com/android/bluetooth/gatt/GattService.java +++ b/android/app/src/com/android/bluetooth/gatt/GattService.java @@ -75,6 +75,8 @@ import com.android.bluetooth.hid.HidHostService; import com.android.bluetooth.le_scan.ScanController; import com.android.internal.annotations.VisibleForTesting; +import com.google.protobuf.ByteString; + import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -1296,11 +1298,8 @@ public class GattService extends ProfileService { if (queuedStatus == BluetoothGatt.GATT_CONNECTION_CONGESTED) { queuedStatus = BluetoothGatt.GATT_SUCCESS; } - CallbackInfo callbackInfo = - new CallbackInfo.Builder(address, queuedStatus) - .setHandle(handle) - .setValue(data) - .build(); + final ByteString value = ByteString.copyFrom(data); + CallbackInfo callbackInfo = new CallbackInfo(address, queuedStatus, handle, value); app.queueCallback(callbackInfo); } } @@ -1405,20 +1404,20 @@ public class GattService extends ProfileService { if (app == null) { return; } - app.isCongested = congested; - while (!app.isCongested) { - CallbackInfo callbackInfo = app.popQueuedCallback(); - if (callbackInfo == null) { - return; - } + app.isCongested = congested; + while (!app.isCongested) { + CallbackInfo callbackInfo = app.popQueuedCallback(); + if (callbackInfo == null) { + return; + } callbackToApp( () -> app.callback.onCharacteristicWrite( - callbackInfo.address, - callbackInfo.status, - callbackInfo.handle, - callbackInfo.value)); - } + callbackInfo.address(), + callbackInfo.status(), + callbackInfo.handle(), + callbackInfo.valueByteArray())); + } } /************************************************************************** @@ -2563,7 +2562,7 @@ public class GattService extends ProfileService { if (queuedStatus == BluetoothGatt.GATT_CONNECTION_CONGESTED) { queuedStatus = BluetoothGatt.GATT_SUCCESS; } - app.queueCallback(new CallbackInfo.Builder(address, queuedStatus).build()); + app.queueCallback(new CallbackInfo(address, queuedStatus)); } } @@ -2584,7 +2583,7 @@ public class GattService extends ProfileService { callbackToApp( () -> app.callback.onNotificationSent( - callbackInfo.address, callbackInfo.status)); + callbackInfo.address(), callbackInfo.status())); } } diff --git a/android/app/tests/unit/src/com/android/bluetooth/gatt/CallbackInfoTest.java b/android/app/tests/unit/src/com/android/bluetooth/gatt/CallbackInfoTest.java index b23cbc8b8f..ed5d1c1b6b 100644 --- a/android/app/tests/unit/src/com/android/bluetooth/gatt/CallbackInfoTest.java +++ b/android/app/tests/unit/src/com/android/bluetooth/gatt/CallbackInfoTest.java @@ -16,34 +16,49 @@ package com.android.bluetooth.gatt; -import static com.google.common.truth.Truth.assertThat; import androidx.test.filters.SmallTest; import androidx.test.runner.AndroidJUnit4; +import com.google.common.truth.Expect; +import com.google.protobuf.ByteString; + +import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; -import java.util.Arrays; - /** Test cases for {@link CallbackInfo}. */ @SmallTest @RunWith(AndroidJUnit4.class) public class CallbackInfoTest { + @Rule public Expect expect = Expect.create(); + @Test - public void callbackInfoBuilder() { + public void callbackInfo_default() { String address = "TestAddress"; int status = 0; int handle = 1; - byte[] value = "Test Value Byte Array".getBytes(); + ByteString value = ByteString.copyFrom("Test Value Byte Array".getBytes()); + + CallbackInfo callbackInfo = new CallbackInfo(address, status, handle, value); + + expect.that(callbackInfo.address()).isEqualTo(address); + expect.that(callbackInfo.status()).isEqualTo(status); + expect.that(callbackInfo.handle()).isEqualTo(handle); + expect.that(callbackInfo.value()).isEqualTo(value); + } + + @Test + public void callbackInfo_nullValue() { + String address = "TestAddress"; + int status = 0; - CallbackInfo callbackInfo = - new CallbackInfo.Builder(address, status).setHandle(handle).setValue(value).build(); + CallbackInfo callbackInfo = new CallbackInfo(address, status); - assertThat(callbackInfo.address).isEqualTo(address); - assertThat(callbackInfo.status).isEqualTo(status); - assertThat(callbackInfo.handle).isEqualTo(handle); - assertThat(Arrays.equals(callbackInfo.value, value)).isTrue(); + expect.that(callbackInfo.address()).isEqualTo(address); + expect.that(callbackInfo.status()).isEqualTo(status); + expect.that(callbackInfo.value()).isNull(); + expect.that(callbackInfo.valueByteArray()).isNull(); } } diff --git a/framework/tests/bumble/src/android/bluetooth/pairing/PairingWithDiscoveryTest.java b/framework/tests/bumble/src/android/bluetooth/pairing/PairingWithDiscoveryTest.java index f2d9725f3e..ed5dfd0561 100644 --- a/framework/tests/bumble/src/android/bluetooth/pairing/PairingWithDiscoveryTest.java +++ b/framework/tests/bumble/src/android/bluetooth/pairing/PairingWithDiscoveryTest.java @@ -94,12 +94,15 @@ public class PairingWithDiscoveryTest { private static final Duration BOND_INTENT_TIMEOUT = Duration.ofSeconds(10); private static final int DISCOVERY_TIMEOUT = 2000; // 2 seconds private static final int LE_GENERAL_DISCOVERABLE = 2; - private CompletableFuture<BluetoothDevice> mDeviceFound; private final Context mContext = ApplicationProvider.getApplicationContext(); private final BluetoothManager mManager = mContext.getSystemService(BluetoothManager.class); private final BluetoothAdapter mAdapter = mManager.getAdapter(); + private final Map<String, Integer> mActionRegistrationCounts = new HashMap<>(); + private final StreamObserverSpliterator<PairingEvent> mPairingEventStreamObserver = + new StreamObserverSpliterator<>(); + @Rule(order = 0) public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule(); @@ -110,13 +113,9 @@ public class PairingWithDiscoveryTest { public final PandoraDevice mBumble = new PandoraDevice(); private BluetoothDevice mBumbleDevice; - private BluetoothDevice mRemoteLeDevice; private InOrder mInOrder = null; + private CompletableFuture<BluetoothDevice> mDeviceFound; @Mock private BroadcastReceiver mReceiver; - private final Map<String, Integer> mActionRegistrationCounts = new HashMap<>(); - - private final StreamObserverSpliterator<PairingEvent> mPairingEventStreamObserver = - new StreamObserverSpliterator<>(); @SuppressLint("MissingPermission") private final Answer<Void> mIntentHandler = @@ -159,9 +158,6 @@ public class PairingWithDiscoveryTest { mInOrder = inOrder(mReceiver); mBumbleDevice = mBumble.getRemoteDevice(); - mRemoteLeDevice = - mAdapter.getRemoteLeDevice( - Utils.BUMBLE_RANDOM_ADDRESS, BluetoothDevice.ADDRESS_TYPE_RANDOM); for (BluetoothDevice device : mAdapter.getBondedDevices()) { removeBond(device); @@ -174,7 +170,6 @@ public class PairingWithDiscoveryTest { removeBond(device); } mBumbleDevice = null; - mRemoteLeDevice = null; if (getTotalActionRegistrationCounts() > 0) { mContext.unregisterReceiver(mReceiver); mActionRegistrationCounts.clear(); diff --git a/framework/tests/bumble/src/android/bluetooth/sockets/rfcomm/RfcommTest.kt b/framework/tests/bumble/src/android/bluetooth/sockets/rfcomm/RfcommTest.kt index 0336bf0acb..acbd097b25 100644 --- a/framework/tests/bumble/src/android/bluetooth/sockets/rfcomm/RfcommTest.kt +++ b/framework/tests/bumble/src/android/bluetooth/sockets/rfcomm/RfcommTest.kt @@ -131,13 +131,13 @@ class RfcommTest { mFlow = intentFlow(mContext, intentFilter, mScope).shareIn(mScope, SharingStarted.Eagerly) } - /* - Setup: - 1. Initialize host and mRemoteDevice - 2. Override pairing config to enable insecure tests - 3. Disable A2DP, HFP, and HID profiles - 4. Disconnect devices, if they are connected - */ + /** + * Setup: + * - Initialize host and mRemoteDevice + * - Override pairing config (allows insecure tests to run) + * - Disable A2DP, HFP, and HID profiles + * - Disconnect devices, if they are connected + */ @Before fun setUp() { mRemoteDevice = mBumble.remoteDevice @@ -155,11 +155,11 @@ class RfcommTest { } } - /* - TearDown: - 1. remove bond - 2. shutdown host - */ + /** + * TearDown: + * - Remove Bond + * - Shutdown host + */ @After fun tearDown() { if (Settings.Global.getInt(mContext.contentResolver, BLE_SCAN_ALWAYS_AVAILABLE, 0) == 1) { @@ -172,38 +172,38 @@ class RfcommTest { mHost.close() } - /* - Test Steps: - 1. Create an insecure socket - 2. Connect to the socket - 3. Verify that devices are connected. - */ + /** + * Test Steps: + * - Create an insecure socket + * - Connect to the socket + * - Verify that devices are connected. + */ @Test fun clientConnectToOpenServerSocketInsecure() { updateSecurityConfig() startServer { serverId -> createConnectAcceptSocket(isSecure = false, serverId) } } - /* - Test Steps: - 1. Create an secure socket - 2. Connect to the socket - 3. Verify that devices are connected. - */ + /** + * Test Steps: + * - Create an secure socket + * - Connect to the socket + * - Verify that devices are connected. + */ @Test fun clientConnectToOpenServerSocketSecure() { updateSecurityConfig() startServer { serverId -> createConnectAcceptSocket(isSecure = true, serverId) } } - /* - Test Steps: - 1. Create an insecure socket - 2. Connect to the socket - 3. Verify that devices are connected - 4. Write data to socket output stream - 5. Verify bumble received that data - */ + /** + * Test Steps: + * - Create an insecure socket + * - Connect to the socket + * - Verify that devices are connected + * - Write data to socket output stream + * - Verify bumble received that data + */ @Test fun clientSendDataOverInsecureSocket() { updateSecurityConfig() @@ -222,14 +222,14 @@ class RfcommTest { } } - /* - Test Steps: - 1. Create a secure socket - 2. Connect to the socket - 3. Verify that devices are connected - 4. Write data to socket output stream - 5. Verify remote device received that data - */ + /** + * Test Steps: + * - Create a secure socket + * - Connect to the socket + * - Verify that devices are connected + * - Write data to socket output stream + * - Verify remote device received that data + */ @Test fun clientSendDataOverSecureSocket() { updateSecurityConfig() @@ -248,14 +248,14 @@ class RfcommTest { } } - /* - Test Steps: - 1. Create an insecure socket - 2. Connect to the socket - 3. Verify that devices are connected - 4. Send data from remote device - 5. Read and verify data from socket input stream - */ + /** + * Test Steps: + * - Create an insecure socket + * - Connect to the socket + * - Verify that devices are connected + * - Send data from remote device + * - Read and verify data from socket input stream + */ @Test fun clientReceiveDataOverInsecureSocket() { updateSecurityConfig() @@ -275,14 +275,14 @@ class RfcommTest { } } - /* - Test Steps: - 1. Create a secure socket - 2. Connect to the socket - 3. Verify that devices are connected - 4. Send data from remote device - 5. Read and verify data from socket input stream - */ + /** + * Test Steps: + * - Create a secure socket + * - Connect to the socket + * - Verify that devices are connected + * - Send data from remote device + * - Read and verify data from socket input stream + */ @Test fun clientReceiveDataOverSecureSocket() { updateSecurityConfig() @@ -302,15 +302,15 @@ class RfcommTest { } } - /* - Test Steps: - 1. Create insecure socket 1 - 2. Create insecure socket 2 - 3. Remote device initiates connection to socket 1 - 4. Remote device initiates connection to socket 2 - 5. Accept socket 1 and verify connection - 6. Accept socket 2 and verify connection - */ + /** + * Test Steps: + * - Create insecure socket 1 + * - Create insecure socket 2 + * - Remote device initiates connection to socket 1 + * - Remote device initiates connection to socket 2 + * - Accept socket 1 and verify connection + * - Accept socket 2 and verify connection + */ @Test fun connectTwoInsecureClientsSimultaneously() { updateSecurityConfig() @@ -328,13 +328,13 @@ class RfcommTest { } } - /* - Test Steps: - 1. Create insecure socket 1 - 2. Remote device initiates connection to socket 1 - 3. Accept socket 1 and verify connection - 4. Repeat for socket 2 - */ + /** + * Test Steps: + * - Create insecure socket 1 + * - Remote device initiates connection to socket 1 + * - Accept socket 1 and verify connection + * - Repeat for socket 2 + */ @Test fun connectTwoInsecureClientsSequentially() { updateSecurityConfig() @@ -351,15 +351,15 @@ class RfcommTest { } } - /* - Test Steps: - 1. Create secure socket 1 - 2. Create secure socket 2 - 3. Remote device initiates connection to socket 1 - 4. Remote device initiates connection to socket 2 - 5. Accept socket 1 and verify connection - 6. Accept socket 2 and verify connection - */ + /** + * Test Steps: + * - Create secure socket 1 + * - Create secure socket 2 + * - Remote device initiates connection to socket 1 + * - Remote device initiates connection to socket 2 + * - Accept socket 1 and verify connection + * - Accept socket 2 and verify connection + */ @Test fun connectTwoSecureClientsSimultaneously() { updateSecurityConfig() @@ -377,13 +377,13 @@ class RfcommTest { } } - /* - Test Steps: - 1. Create insecure socket 1 - 2. Remote device initiates connection to socket 1 - 3. Accept socket 1 and verify connection - 4. Repeat for socket 2 - */ + /** + * Test Steps: + * - Create insecure socket 1 + * - Remote device initiates connection to socket 1 + * - Accept socket 1 and verify connection + * - Repeat for socket 2 + */ @Test fun connectTwoSecureClientsSequentially() { updateSecurityConfig() @@ -400,13 +400,13 @@ class RfcommTest { } } - /* - Test Steps: - 1. Create insecure socket 1 - 2. Remote device initiates connection to socket 1 - 3. Accept socket 1 and verify connection - 4. Repeat for secure socket 2 - */ + /** + * Test Steps: + * - Create insecure socket 1 + * - Remote device initiates connection to socket 1 + * - Accept socket 1 and verify connection + * - Repeat for secure socket 2 + */ @Test @Ignore("b/380091558") fun connectTwoMixedClientsInsecureThenSecure() { @@ -424,13 +424,13 @@ class RfcommTest { } } - /* - Test Steps: - 1. Create secure socket 2 - 2. Remote device initiates connection to socket 2 - 3. Accept socket 2 and verify connection - 4. Repeat for insecure socket 1 - */ + /** + * Test Steps: + * - Create secure socket 2 + * - Remote device initiates connection to socket 2 + * - Accept socket 2 and verify connection + * - Repeat for insecure socket 1 + */ @Test fun connectTwoMixedClientsSecureThenInsecure() { updateSecurityConfig() @@ -447,11 +447,11 @@ class RfcommTest { } } - /* - Test Steps: - 1. Create listening socket and connect - 2. Disconnect RFCOMM from remote device - */ + /** + * Test Steps: + * - Create listening socket and connect + * - Disconnect RFCOMM from remote device + */ @RequiresFlagsEnabled(Flags.FLAG_TRIGGER_SEC_PROC_ON_INC_ACCESS_REQ) @Test fun serverSecureConnectThenRemoteDisconnect() { @@ -465,11 +465,11 @@ class RfcommTest { Truth.assertThat(serverSock.channel).isEqualTo(-1) // ensure disconnected at RFCOMM Layer } - /* - Test Steps: - 1. Create listening socket and connect - 2. Disconnect RFCOMM from local device - */ + /** + * Test Steps: + * - Create listening socket and connect + * - Disconnect RFCOMM from local device + */ @RequiresFlagsEnabled(Flags.FLAG_TRIGGER_SEC_PROC_ON_INC_ACCESS_REQ) @Test fun serverSecureConnectThenLocalDisconnect() { @@ -481,16 +481,16 @@ class RfcommTest { Truth.assertThat(serverSock.channel).isEqualTo(-1) // ensure disconnected at RFCOMM Layer } - /* - Test Steps: - 1. Disable inquiry and page scan - 2. Create RFCOMM socket - 3. Attempt to connect to socket: expect not connected - 4. Wait 3 seconds - 5. Before page timeout of 5 seconds, close the socket - 6. Enable page scan - 7. Create and connect to an RFCOMM socket - verify proper connection - */ + /** + * Test Steps: + * - Disable inquiry and page scan + * - Create RFCOMM socket + * - Attempt to connect to socket: expect not connected + * - Wait 3 seconds + * - Before page timeout of 5 seconds, close the socket + * - Enable page scan + * - Create and connect to an RFCOMM socket - verify proper connection + */ @RequiresFlagsEnabled(Flags.FLAG_RFCOMM_CANCEL_ONGOING_SDP_ON_CLOSE) @Test fun clientConnectToOpenServerSocketAfterPageTimeout() { @@ -543,14 +543,14 @@ class RfcommTest { startServer { serverId -> createConnectAcceptSocket(isSecure = false, serverId) } } - /* - Test Steps: - 1. Create an insecure socket - 2. Connect to the socket - 3. Verify that devices are connected - 4. Write data to socket output stream - 5. Verify bumble received that data - */ + /** + * Test Steps: + * - Create an insecure socket + * - Connect to the socket + * - Verify that devices are connected + * - Write data to socket output stream + * - Verify bumble received that data + */ @Test @RequiresFlagsEnabled(Flags.FLAG_SOCKET_SETTINGS_API) fun clientSendDataOverInsecureSocketUsingSocketSettings() { @@ -571,14 +571,14 @@ class RfcommTest { } } - /* - Test Steps: - 1. Create an encrypt only socket - 2. Connect to the socket - 3. Verify that devices are connected - 4. Write data to socket output stream - 5. Verify bumble received that data - */ + /** + * Test Steps: + * - Create an encrypt only socket + * - Connect to the socket + * - Verify that devices are connected + * - Write data to socket output stream + * - Verify bumble received that data + */ @Test @RequiresFlagsEnabled(Flags.FLAG_SOCKET_SETTINGS_API) fun clientSendDataOverEncryptedOnlySocketUsingSocketSettings() { @@ -602,14 +602,14 @@ class RfcommTest { } } - /* - Test Steps: - 1. Create an secure socket - 2. Connect to the socket - 3. Verify that devices are connected - 4. Write data to socket output stream - 5. Verify bumble received that data - */ + /** + * Test Steps: + * - Create an secure socket + * - Connect to the socket + * - Verify that devices are connected + * - Write data to socket output stream + * - Verify bumble received that data + */ @Test @RequiresFlagsEnabled(Flags.FLAG_SOCKET_SETTINGS_API) fun clientSendDataOverSecureSocketUsingSocketSettings() { @@ -631,13 +631,13 @@ class RfcommTest { } } - /* - Test Steps: - 1. Create an Rfcomm insecure socket - 2. Verify that Rfcomm socket is connected - 3. Disable Bluetooth to BLE_ON mode - 4. Verify remote devices disconnected based on successful data transmission - */ + /** + * Test Steps: + * - Create an Rfcomm insecure socket + * - Verify that Rfcomm socket is connected + * - Disable Bluetooth to BLE_ON mode + * - Verify remote devices disconnected based on successful data transmission + */ @Test @RequiresFlagsEnabled(Flags.FLAG_DISCONNECT_ACLS_BY_BREDR_DISABLED) fun clientRfcommDeviceDisconnectedOnBleOnMode() { @@ -731,18 +731,6 @@ class RfcommTest { return Pair(socket, connection) } - private fun createConnectAcceptSocket( - isSecure: Boolean, - server: ServerId, - uuid: String = TEST_UUID, - ): Pair<BluetoothSocket, RfcommProto.RfcommConnection> { - val socket = createSocket(mRemoteDevice, isSecure, uuid) - val connection = acceptSocket(server) - Truth.assertThat(socket.isConnected).isTrue() - - return Pair(socket, connection) - } - private fun createClientSocketUsingSocketSettings( uuid: String, remoteDevice: BluetoothDevice, @@ -830,6 +818,18 @@ class RfcommTest { return connectionResponse.connection } + private fun createConnectAcceptSocket( + isSecure: Boolean, + server: ServerId, + uuid: String = TEST_UUID, + ): Pair<BluetoothSocket, RfcommProto.RfcommConnection> { + val socket = createSocket(mRemoteDevice, isSecure, uuid) + val connection = acceptSocket(server) + Truth.assertThat(socket.isConnected).isTrue() + + return Pair(socket, connection) + } + private fun startServer( name: String = TEST_SERVER_NAME, uuid: String = TEST_UUID, diff --git a/system/btif/src/btif_sock_l2cap.cc b/system/btif/src/btif_sock_l2cap.cc index ac1099fec4..d607ff3b74 100644 --- a/system/btif/src/btif_sock_l2cap.cc +++ b/system/btif/src/btif_sock_l2cap.cc @@ -587,8 +587,8 @@ static void on_srv_l2cap_psm_connect_l(tBTA_JV_L2CAP_OPEN* p_open, l2cap_socket* log::info( "Connected to L2CAP connection for device: {}, channel: {}, app_uid: {}, " "id: {}, is_le: {}, socket_id: {}, rx_mtu: {}", - sock->addr, sock->channel, sock->app_uid, sock->id, sock->is_le_coc, accept_rs->socket_id, - accept_rs->rx_mtu); + accept_rs->addr, accept_rs->channel, accept_rs->app_uid, accept_rs->id, + accept_rs->is_le_coc, accept_rs->socket_id, accept_rs->rx_mtu); btif_sock_connection_logger(accept_rs->addr, accept_rs->id, accept_rs->is_le_coc ? BTSOCK_L2CAP_LE : BTSOCK_L2CAP, SOCKET_CONNECTION_STATE_CONNECTED, @@ -1468,8 +1468,8 @@ static void on_srv_l2cap_psm_connect_offload_l(tBTA_JV_L2CAP_OPEN* p_open, l2cap log::info( "Connected to L2CAP connection for device: {}, channel: {}, app_uid: {}, " "id: {}, is_le: {}, socket_id: {}, rx_mtu: {}", - sock->addr, sock->channel, sock->app_uid, sock->id, sock->is_le_coc, accept_rs->socket_id, - accept_rs->rx_mtu); + accept_rs->addr, accept_rs->channel, accept_rs->app_uid, accept_rs->id, + accept_rs->is_le_coc, accept_rs->socket_id, accept_rs->rx_mtu); btif_sock_connection_logger(accept_rs->addr, accept_rs->id, accept_rs->is_le_coc ? BTSOCK_L2CAP_LE : BTSOCK_L2CAP, SOCKET_CONNECTION_STATE_CONNECTED, diff --git a/system/btif/src/btif_sock_rfc.cc b/system/btif/src/btif_sock_rfc.cc index 8af6a1bcf6..929ce8a3cc 100644 --- a/system/btif/src/btif_sock_rfc.cc +++ b/system/btif/src/btif_sock_rfc.cc @@ -655,8 +655,7 @@ static void on_srv_rfc_listen_started(tBTA_JV_RFCOMM_START* p_start, uint32_t id slot->app_uid, slot->scn, 0, 0, slot->service_name); } -static uint32_t on_srv_rfc_connect_offload(tBTA_JV_RFCOMM_SRV_OPEN* p_open, uint32_t id, - rfc_slot_t* srv_rs) { +static uint32_t on_srv_rfc_connect_offload(tBTA_JV_RFCOMM_SRV_OPEN* p_open, rfc_slot_t* srv_rs) { rfc_slot_t* accept_rs; accept_rs = create_srv_accept_rfc_slot(srv_rs, &p_open->rem_bda, p_open->handle, p_open->new_listen_handle); @@ -667,7 +666,7 @@ static uint32_t on_srv_rfc_connect_offload(tBTA_JV_RFCOMM_SRV_OPEN* p_open, uint log::info( "connected to RFCOMM socket connections for device: {}, scn: {}, " "app_uid: {}, id: {}, socket_id: {}", - accept_rs->addr, accept_rs->scn, accept_rs->app_uid, id, accept_rs->socket_id); + accept_rs->addr, accept_rs->scn, accept_rs->app_uid, accept_rs->id, accept_rs->socket_id); btif_sock_connection_logger(accept_rs->addr, accept_rs->id, BTSOCK_RFCOMM, SOCKET_CONNECTION_STATE_CONNECTED, accept_rs->f.server ? SOCKET_ROLE_LISTEN : SOCKET_ROLE_CONNECTION, @@ -713,7 +712,7 @@ static uint32_t on_srv_rfc_connect(tBTA_JV_RFCOMM_SRV_OPEN* p_open, uint32_t id) if (com::android::bluetooth::flags::socket_settings_api() && srv_rs->data_path == BTSOCK_DATA_PATH_HARDWARE_OFFLOAD) { - return on_srv_rfc_connect_offload(p_open, id, srv_rs); + return on_srv_rfc_connect_offload(p_open, srv_rs); } accept_rs = create_srv_accept_rfc_slot(srv_rs, &p_open->rem_bda, p_open->handle, @@ -725,7 +724,7 @@ static uint32_t on_srv_rfc_connect(tBTA_JV_RFCOMM_SRV_OPEN* p_open, uint32_t id) log::info( "connected to RFCOMM socket connections for device: {}, scn: {}, " "app_uid: {}, slot_id: {}, socket_id: {}", - accept_rs->addr, accept_rs->scn, accept_rs->app_uid, id, accept_rs->socket_id); + accept_rs->addr, accept_rs->scn, accept_rs->app_uid, accept_rs->id, accept_rs->socket_id); btif_sock_connection_logger(accept_rs->addr, accept_rs->id, BTSOCK_RFCOMM, SOCKET_CONNECTION_STATE_CONNECTED, accept_rs->f.server ? SOCKET_ROLE_LISTEN : SOCKET_ROLE_CONNECTION, @@ -744,7 +743,7 @@ static uint32_t on_srv_rfc_connect(tBTA_JV_RFCOMM_SRV_OPEN* p_open, uint32_t id) return srv_rs->id; } -static void on_cli_rfc_connect_offload(tBTA_JV_RFCOMM_OPEN* p_open, uint32_t id, rfc_slot_t* slot) { +static void on_cli_rfc_connect_offload(tBTA_JV_RFCOMM_OPEN* p_open, rfc_slot_t* slot) { slot->rfc_port_handle = BTA_JvRfcommGetPortHdl(p_open->handle); slot->addr = p_open->rem_bda; slot->socket_id = btif_rfc_sock_generate_socket_id(); @@ -752,7 +751,7 @@ static void on_cli_rfc_connect_offload(tBTA_JV_RFCOMM_OPEN* p_open, uint32_t id, log::info( "connected to RFCOMM socket connections for device: {}, scn: {}, " "app_uid: {}, id: {}, socket_id: {}", - slot->addr, slot->scn, slot->app_uid, id, slot->socket_id); + slot->addr, slot->scn, slot->app_uid, slot->id, slot->socket_id); btif_sock_connection_logger( slot->addr, slot->id, BTSOCK_RFCOMM, SOCKET_CONNECTION_STATE_CONNECTED, slot->f.server ? SOCKET_ROLE_LISTEN : SOCKET_ROLE_CONNECTION, slot->app_uid, slot->scn, 0, @@ -797,7 +796,7 @@ static void on_cli_rfc_connect(tBTA_JV_RFCOMM_OPEN* p_open, uint32_t id) { if (com::android::bluetooth::flags::socket_settings_api() && slot->data_path == BTSOCK_DATA_PATH_HARDWARE_OFFLOAD) { - on_cli_rfc_connect_offload(p_open, id, slot); + on_cli_rfc_connect_offload(p_open, slot); return; } @@ -808,7 +807,7 @@ static void on_cli_rfc_connect(tBTA_JV_RFCOMM_OPEN* p_open, uint32_t id) { log::info( "connected to RFCOMM socket connections for device: {}, scn: {}, " "app_uid: {}, id: {}, socket_id: {}", - slot->addr, slot->scn, slot->app_uid, id, slot->socket_id); + slot->addr, slot->scn, slot->app_uid, slot->id, slot->socket_id); btif_sock_connection_logger( slot->addr, slot->id, BTSOCK_RFCOMM, SOCKET_CONNECTION_STATE_CONNECTED, slot->f.server ? SOCKET_ROLE_LISTEN : SOCKET_ROLE_CONNECTION, slot->app_uid, slot->scn, 0, diff --git a/system/gd/hci/distance_measurement_manager.cc b/system/gd/hci/distance_measurement_manager.cc index d9b9200552..4fe3449b6b 100644 --- a/system/gd/hci/distance_measurement_manager.cc +++ b/system/gd/hci/distance_measurement_manager.cc @@ -1097,10 +1097,6 @@ struct DistanceMeasurementManager::impl : bluetooth::hal::RangingHalCallback { if (!live_tracker->local_start) { // reset the responder state, as no other event to set the state. live_tracker->state = CsTrackerState::WAIT_FOR_CONFIG_COMPLETE; - } else { - live_tracker->setup_complete = true; - log::info("connection_handle: {}, address: {}, config_id: {}", connection_handle, - live_tracker->address, config_id); } live_tracker->used_config_id = config_id; @@ -1175,6 +1171,8 @@ struct DistanceMeasurementManager::impl : bluetooth::hal::RangingHalCallback { } if (it->second.measurement_ongoing) { + log::debug("cs set up succeed"); + it->second.setup_complete = true; send_le_cs_procedure_enable(connection_handle, Enable::ENABLED); } } diff --git a/system/stack/l2cap/l2c_api.cc b/system/stack/l2cap/l2c_api.cc index 38b9dd030c..04f32105e5 100644 --- a/system/stack/l2cap/l2c_api.cc +++ b/system/stack/l2cap/l2c_api.cc @@ -1211,8 +1211,15 @@ bool L2CA_ConnectFixedChnl(uint16_t fixed_cid, const RawAddress& rem_bda) { // Restore the fixed channel if it was suspended l2cu_fixed_channel_restore(p_lcb, fixed_cid); - (*l2cb.fixed_reg[fixed_cid - L2CAP_FIRST_FIXED_CHNL].pL2CA_FixedConn_Cb)( - fixed_cid, p_lcb->remote_bd_addr, true, 0, p_lcb->transport); + if (!com::android::bluetooth::flags::smp_connection_status_handling_when_no_acl()) { + (*l2cb.fixed_reg[fixed_cid - L2CAP_FIRST_FIXED_CHNL].pL2CA_FixedConn_Cb)( + fixed_cid, p_lcb->remote_bd_addr, true, 0, p_lcb->transport); + return true; + } + if (p_lcb->link_state == LST_CONNECTED) { + (*l2cb.fixed_reg[fixed_cid - L2CAP_FIRST_FIXED_CHNL].pL2CA_FixedConn_Cb)( + fixed_cid, p_lcb->remote_bd_addr, true, 0, p_lcb->transport); + } return true; } |