Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 572797a3 authored by Liang Li's avatar Liang Li
Browse files

Add RFCOMM socket offload capabilities

Flag: com.android.bluetooth.flags.socket_settings_api
Bug: 342012881
Bug: 374358112
Test: m com.android.btservices
Change-Id: Ia8881d1f96abbf99753672c826345b1838f8fd0e
parent c9f93cdf
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -135,7 +135,7 @@ class AdapterProperties {
    private boolean mIsLeChannelSoundingSupported;

    private int mNumberOfSupportedOffloadedLeCocSockets;
    private int mNumberOfSupportedOffloadedRfcommSockets = 0;
    private int mNumberOfSupportedOffloadedRfcommSockets;

    // Lock for all getters and setters.
    // If finer grained locking is needer, more locks
@@ -1044,12 +1044,12 @@ class AdapterProperties {
    }

    private void updateLppOffloadFeatureSupport(byte[] val) {
        if (val.length < 1) {
        if (val == null || val.length < 2) {
            Log.e(TAG, "BT_PROPERTY_LPP_OFFLOAD_FEATURES: invalid value length");
            return;
        }
        // TODO(b/342012881) Read mNumberOfSupportedOffloadedRfcommSockets from host stack
        mNumberOfSupportedOffloadedLeCocSockets = (0xFF & ((int) val[0]));
        mNumberOfSupportedOffloadedRfcommSockets = (0xFF & ((int) val[1]));

        Log.d(
                TAG,
+10 −7
Original line number Diff line number Diff line
@@ -116,11 +116,8 @@ class BluetoothSocketManagerBinder extends IBluetoothSocketManager.Stub {

        if (dataPath != BluetoothSocketSettings.DATA_PATH_NO_OFFLOAD) {
            mService.enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED, null);
            if (type != BluetoothSocket.TYPE_LE || !mService.isLeCocSocketOffloadSupported()) {
                throw new IllegalStateException("Unsupported socket type for offload " + type);
            }
            enforceSocketOffloadSupport(type);
        }

        String brEdrAddress =
                Flags.identityAddressNullIfNotKnown()
                        ? Utils.getBrEdrAddress(device)
@@ -228,9 +225,7 @@ class BluetoothSocketManagerBinder extends IBluetoothSocketManager.Stub {

        if (dataPath != BluetoothSocketSettings.DATA_PATH_NO_OFFLOAD) {
            mService.enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED, null);
            if (type != BluetoothSocket.TYPE_LE || !mService.isLeCocSocketOffloadSupported()) {
                throw new IllegalStateException("Unsupported socket type for offload " + type);
            }
            enforceSocketOffloadSupport(type);
        }

        Log.i(
@@ -318,6 +313,14 @@ class BluetoothSocketManagerBinder extends IBluetoothSocketManager.Stub {
        }
    }

    private void enforceSocketOffloadSupport(int type) {
        if (!(type == BluetoothSocket.TYPE_LE && mService.isLeCocSocketOffloadSupported())
                && !(type == BluetoothSocket.TYPE_RFCOMM
                        && mService.isRfcommSocketOffloadSupported())) {
            throw new IllegalStateException("Unsupported socket type for offload " + type);
        }
    }

    private static ParcelFileDescriptor marshalFd(int fd) {
        if (fd == INVALID_FD) {
            return null;
+8 −2
Original line number Diff line number Diff line
@@ -28,6 +28,8 @@
#define BTIF_SOCK_RFC_H

#include "btif_uid.h"
#include "hardware/bluetooth.h"
#include "hardware/bt_sock.h"
#include "types/bluetooth/uuid.h"
#include "types/raw_address.h"
bt_status_t btsock_rfc_init(int handle, uid_set_t* set);
@@ -36,9 +38,13 @@ bt_status_t btsock_rfc_control_req(uint8_t dlci, const RawAddress& bd_addr, uint
                                   uint8_t break_signal, uint8_t discard_buffers,
                                   uint8_t break_signal_seq, bool fc);
bt_status_t btsock_rfc_listen(const char* name, const bluetooth::Uuid* uuid, int channel,
                              int* sock_fd, int flags, int app_uid);
                              int* sock_fd, int flags, int app_uid, btsock_data_path_t data_path,
                              const char* socket_name, uint64_t hub_id, uint64_t endpoint_id,
                              int max_rx_packet_size);
bt_status_t btsock_rfc_connect(const RawAddress* bd_addr, const bluetooth::Uuid* uuid, int channel,
                               int* sock_fd, int flags, int app_uid);
                               int* sock_fd, int flags, int app_uid, btsock_data_path_t data_path,
                               const char* socket_name, uint64_t hub_id, uint64_t endpoint_id,
                               int max_rx_packet_size);
void btsock_rfc_signaled(int fd, int flags, uint32_t user_id);
bt_status_t btsock_rfc_disconnect(const RawAddress* bd_addr);

+2 −0
Original line number Diff line number Diff line
@@ -517,6 +517,8 @@ void btif_get_adapter_property(bt_property_type_t type) {
            bluetooth::shim::GetLppOffloadManager()->GetSocketCapabilities();
    lpp_offload_features.number_of_supported_offloaded_le_coc_sockets =
            socket_offload_capabilities.le_coc_capabilities.number_of_supported_sockets;
    lpp_offload_features.number_of_supported_offloaded_rfcomm_sockets =
            socket_offload_capabilities.rfcomm_capabilities.number_of_supported_sockets;
    prop.len = sizeof(bt_lpp_offload_features_t);
    memcpy(prop.val, &lpp_offload_features, prop.len);
  } else {
+4 −2
Original line number Diff line number Diff line
@@ -180,7 +180,8 @@ static bt_status_t btsock_listen(btsock_type_t type, const char* service_name,
                              SOCKET_ROLE_LISTEN, app_uid, channel, 0, 0, service_name);
  switch (type) {
    case BTSOCK_RFCOMM:
      status = btsock_rfc_listen(service_name, service_uuid, channel, sock_fd, flags, app_uid);
      status = btsock_rfc_listen(service_name, service_uuid, channel, sock_fd, flags, app_uid,
                                 data_path, socket_name, hub_id, endpoint_id, max_rx_packet_size);
      break;
    case BTSOCK_L2CAP:
      status = btsock_l2cap_listen(service_name, channel, sock_fd, flags, app_uid, data_path,
@@ -231,7 +232,8 @@ static bt_status_t btsock_connect(const RawAddress* bd_addr, btsock_type_t type,
                              uuid ? uuid->ToString().c_str() : "");
  switch (type) {
    case BTSOCK_RFCOMM:
      status = btsock_rfc_connect(bd_addr, uuid, channel, sock_fd, flags, app_uid);
      status = btsock_rfc_connect(bd_addr, uuid, channel, sock_fd, flags, app_uid, data_path,
                                  socket_name, hub_id, endpoint_id, max_rx_packet_size);
      break;

    case BTSOCK_L2CAP:
Loading