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

Commit 3b15d68f authored by Jayden Kim's avatar Jayden Kim Committed by Gerrit Code Review
Browse files

Merge changes from topic "offload_socket_aosp" into main

* changes:
  Add conditional privileged permission annotation on pbap client
  Read RFCOMM socket offload capabilities from bluetooth low power proccesor
  Notify offloaded LE COC socket channel info to socket hal
  Determine local mtu for offload LE socket
  Set the initial local credits to 0 for offload LE socket
  Send signal to indicate if app is accepting incoming connection on listen socket
  Add bluetooth offload socket API
  Read socket offload capabilities from bluetooth low power proccesor
  Add low power processor offload manager with socket hal shim
  Add helper functions to get LE L2CAP channel and ACL handle information
parents 811f3370 5615c053
Loading
Loading
Loading
Loading
+6 −0
Original line number Original line Diff line number Diff line
@@ -338,4 +338,10 @@ interface IBluetooth


    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)")
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)")
    oneway void killBluetoothProcess();
    oneway void killBluetoothProcess();

    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)")
    boolean isLeCocSocketOffloadSupported(in AttributionSource source);

    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)")
    boolean isRfcommSocketOffloadSupported(in AttributionSource source);
}
}
+4 −0
Original line number Original line Diff line number Diff line
@@ -29,8 +29,12 @@ interface IBluetoothSocketManager
{
{
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
    @nullable ParcelFileDescriptor connectSocket(in BluetoothDevice device, int type, in @nullable ParcelUuid uuid, int port, int flag);
    @nullable ParcelFileDescriptor connectSocket(in BluetoothDevice device, int type, in @nullable ParcelUuid uuid, int port, int flag);
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
    @nullable ParcelFileDescriptor connectSocketwithOffload(in BluetoothDevice device, int type, in @nullable ParcelUuid uuid, int port, int flag, int dataPath, in String socketName, long hubId, long endpointId, int maximumPacketSize);
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
    @nullable ParcelFileDescriptor createSocketChannel(int type, in @nullable String serviceName, in @nullable ParcelUuid uuid, int port, int flag);
    @nullable ParcelFileDescriptor createSocketChannel(int type, in @nullable String serviceName, in @nullable ParcelUuid uuid, int port, int flag);
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
    @nullable ParcelFileDescriptor createSocketChannelWithOffload(int type, in @nullable String serviceName, in @nullable ParcelUuid uuid, int port, int flag, int dataPath, in String socketName, long hubId, long endpointId, int maximumPacketSize);
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
    void requestMaximumTxDataLength(in BluetoothDevice device);
    void requestMaximumTxDataLength(in BluetoothDevice device);
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
+28 −7
Original line number Original line Diff line number Diff line
@@ -1782,11 +1782,14 @@ static jboolean setBufferLengthMillisNative(JNIEnv* /* env */, jobject /* obj */
}
}


static jint connectSocketNative(JNIEnv* env, jobject /* obj */, jbyteArray address, jint type,
static jint connectSocketNative(JNIEnv* env, jobject /* obj */, jbyteArray address, jint type,
                                jbyteArray uuid, jint port, jint flag, jint callingUid) {
                                jbyteArray uuid, jint port, jint flag, jint callingUid,
                                jint dataPath, jstring socketName, jlong hubId, jlong endPointId,
                                jint maxRxPacketSize) {
  int socket_fd = INVALID_FD;
  int socket_fd = INVALID_FD;
  jbyte* addr = nullptr;
  jbyte* addr = nullptr;
  jbyte* uuidBytes = nullptr;
  jbyte* uuidBytes = nullptr;
  Uuid btUuid;
  Uuid btUuid;
  const char* nativeSocketName = nullptr;


  if (!sBluetoothSocketInterface) {
  if (!sBluetoothSocketInterface) {
    goto done;
    goto done;
@@ -1799,9 +1802,13 @@ static jint connectSocketNative(JNIEnv* env, jobject /* obj */, jbyteArray addre
  }
  }


  btUuid = Uuid::From128BitBE(reinterpret_cast<uint8_t*>(uuidBytes));
  btUuid = Uuid::From128BitBE(reinterpret_cast<uint8_t*>(uuidBytes));
  if (socketName != nullptr) {
    nativeSocketName = env->GetStringUTFChars(socketName, nullptr);
  }
  if (sBluetoothSocketInterface->connect(reinterpret_cast<RawAddress*>(addr), (btsock_type_t)type,
  if (sBluetoothSocketInterface->connect(reinterpret_cast<RawAddress*>(addr), (btsock_type_t)type,
                                         &btUuid, port, &socket_fd, flag,
                                         &btUuid, port, &socket_fd, flag, callingUid,
                                         callingUid) != BT_STATUS_SUCCESS) {
                                         (btsock_data_path_t)dataPath, nativeSocketName, hubId,
                                         endPointId, maxRxPacketSize) != BT_STATUS_SUCCESS) {
    socket_fd = INVALID_FD;
    socket_fd = INVALID_FD;
  }
  }


@@ -1812,16 +1819,21 @@ done:
  if (uuidBytes) {
  if (uuidBytes) {
    env->ReleaseByteArrayElements(uuid, uuidBytes, 0);
    env->ReleaseByteArrayElements(uuid, uuidBytes, 0);
  }
  }
  if (nativeSocketName) {
    env->ReleaseStringUTFChars(socketName, nativeSocketName);
  }
  return socket_fd;
  return socket_fd;
}
}


static jint createSocketChannelNative(JNIEnv* env, jobject /* obj */, jint type,
static jint createSocketChannelNative(JNIEnv* env, jobject /* obj */, jint type,
                                      jstring serviceName, jbyteArray uuid, jint port, jint flag,
                                      jstring serviceName, jbyteArray uuid, jint port, jint flag,
                                      jint callingUid) {
                                      jint callingUid, jint dataPath, jstring socketName,
                                      jlong hubId, jlong endPointId, jint maxRxPacketSize) {
  int socket_fd = INVALID_FD;
  int socket_fd = INVALID_FD;
  jbyte* uuidBytes = nullptr;
  jbyte* uuidBytes = nullptr;
  Uuid btUuid;
  Uuid btUuid;
  const char* nativeServiceName = nullptr;
  const char* nativeServiceName = nullptr;
  const char* nativeSocketName = nullptr;


  if (!sBluetoothSocketInterface) {
  if (!sBluetoothSocketInterface) {
    goto done;
    goto done;
@@ -1835,9 +1847,14 @@ static jint createSocketChannelNative(JNIEnv* env, jobject /* obj */, jint type,
    goto done;
    goto done;
  }
  }
  btUuid = Uuid::From128BitBE(reinterpret_cast<uint8_t*>(uuidBytes));
  btUuid = Uuid::From128BitBE(reinterpret_cast<uint8_t*>(uuidBytes));
  if (socketName != nullptr) {
    nativeSocketName = env->GetStringUTFChars(socketName, nullptr);
  }


  if (sBluetoothSocketInterface->listen((btsock_type_t)type, nativeServiceName, &btUuid, port,
  if (sBluetoothSocketInterface->listen((btsock_type_t)type, nativeServiceName, &btUuid, port,
                                        &socket_fd, flag, callingUid) != BT_STATUS_SUCCESS) {
                                        &socket_fd, flag, callingUid, (btsock_data_path_t)dataPath,
                                        nativeSocketName, hubId, endPointId,
                                        maxRxPacketSize) != BT_STATUS_SUCCESS) {
    socket_fd = INVALID_FD;
    socket_fd = INVALID_FD;
  }
  }


@@ -1848,6 +1865,9 @@ done:
  if (nativeServiceName) {
  if (nativeServiceName) {
    env->ReleaseStringUTFChars(serviceName, nativeServiceName);
    env->ReleaseStringUTFChars(serviceName, nativeServiceName);
  }
  }
  if (nativeSocketName) {
    env->ReleaseStringUTFChars(socketName, nativeSocketName);
  }
  return socket_fd;
  return socket_fd;
}
}


@@ -2267,8 +2287,9 @@ int register_com_android_bluetooth_btservice_AdapterService(JNIEnv* env) {
          {"setBufferLengthMillisNative", "(II)Z",
          {"setBufferLengthMillisNative", "(II)Z",
           reinterpret_cast<void*>(setBufferLengthMillisNative)},
           reinterpret_cast<void*>(setBufferLengthMillisNative)},
          {"getMetricIdNative", "([B)I", reinterpret_cast<void*>(getMetricIdNative)},
          {"getMetricIdNative", "([B)I", reinterpret_cast<void*>(getMetricIdNative)},
          {"connectSocketNative", "([BI[BIII)I", reinterpret_cast<void*>(connectSocketNative)},
          {"connectSocketNative", "([BI[BIIIILjava/lang/String;JJI)I",
          {"createSocketChannelNative", "(ILjava/lang/String;[BIII)I",
           reinterpret_cast<void*>(connectSocketNative)},
          {"createSocketChannelNative", "(ILjava/lang/String;[BIIIILjava/lang/String;JJI)I",
           reinterpret_cast<void*>(createSocketChannelNative)},
           reinterpret_cast<void*>(createSocketChannelNative)},
          {"requestMaximumTxDataLengthNative", "([B)V",
          {"requestMaximumTxDataLengthNative", "([B)V",
           reinterpret_cast<void*>(requestMaximumTxDataLengthNative)},
           reinterpret_cast<void*>(requestMaximumTxDataLengthNative)},
+1 −0
Original line number Original line Diff line number Diff line
@@ -49,6 +49,7 @@ public final class AbstractionLayer {
    static final int BT_PROPERTY_REMOTE_ASHA_CAPABILITY = 0X15;
    static final int BT_PROPERTY_REMOTE_ASHA_CAPABILITY = 0X15;
    static final int BT_PROPERTY_REMOTE_ASHA_TRUNCATED_HISYNCID = 0X16;
    static final int BT_PROPERTY_REMOTE_ASHA_TRUNCATED_HISYNCID = 0X16;
    static final int BT_PROPERTY_REMOTE_MODEL_NUM = 0x17;
    static final int BT_PROPERTY_REMOTE_MODEL_NUM = 0x17;
    static final int BT_PROPERTY_LPP_OFFLOAD_FEATURES = 0x1B;


    public static final int BT_DEVICE_TYPE_BREDR = 0x01;
    public static final int BT_DEVICE_TYPE_BREDR = 0x01;
    public static final int BT_DEVICE_TYPE_BLE = 0x02;
    public static final int BT_DEVICE_TYPE_BLE = 0x02;
+69 −6
Original line number Original line Diff line number Diff line
@@ -195,13 +195,56 @@ public class AdapterNativeInterface {
        return getMetricIdNative(address);
        return getMetricIdNative(address);
    }
    }


    int connectSocket(byte[] address, int type, byte[] uuid, int port, int flag, int callingUid) {
    int connectSocket(
        return connectSocketNative(address, type, uuid, port, flag, callingUid);
            byte[] address,
            int type,
            byte[] uuid,
            int port,
            int flag,
            int callingUid,
            int dataPath,
            String socketName,
            long hubId,
            long endpointId,
            int maximumPacketSize) {
        return connectSocketNative(
                address,
                type,
                uuid,
                port,
                flag,
                callingUid,
                dataPath,
                socketName,
                hubId,
                endpointId,
                maximumPacketSize);
    }
    }


    int createSocketChannel(
    int createSocketChannel(
            int type, String serviceName, byte[] uuid, int port, int flag, int callingUid) {
            int type,
        return createSocketChannelNative(type, serviceName, uuid, port, flag, callingUid);
            String serviceName,
            byte[] uuid,
            int port,
            int flag,
            int callingUid,
            int dataPath,
            String socketName,
            long hubId,
            long endpointId,
            int maximumPacketSize) {
        return createSocketChannelNative(
                type,
                serviceName,
                uuid,
                port,
                flag,
                callingUid,
                dataPath,
                socketName,
                hubId,
                endpointId,
                maximumPacketSize);
    }
    }


    void requestMaximumTxDataLength(byte[] address) {
    void requestMaximumTxDataLength(byte[] address) {
@@ -359,10 +402,30 @@ public class AdapterNativeInterface {
    private native int getMetricIdNative(byte[] address);
    private native int getMetricIdNative(byte[] address);


    private native int connectSocketNative(
    private native int connectSocketNative(
            byte[] address, int type, byte[] uuid, int port, int flag, int callingUid);
            byte[] address,
            int type,
            byte[] uuid,
            int port,
            int flag,
            int callingUid,
            int dataPath,
            String socketName,
            long hubId,
            long endpointId,
            int maximumPacketSize);


    private native int createSocketChannelNative(
    private native int createSocketChannelNative(
            int type, String serviceName, byte[] uuid, int port, int flag, int callingUid);
            int type,
            String serviceName,
            byte[] uuid,
            int port,
            int flag,
            int callingUid,
            int dataPath,
            String socketName,
            long hubId,
            long endpointId,
            int maximumPacketSize);


    private native void requestMaximumTxDataLengthNative(byte[] address);
    private native void requestMaximumTxDataLengthNative(byte[] address);


Loading