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

Commit ea976048 authored by Rahul Arya's avatar Rahul Arya Committed by Gerrit Code Review
Browse files

Merge changes Ia62aacb0,If14d1a97,Ibc470d3f,I94fafe8a,I4868de5c, ...

* changes:
  [Private GATT] Add Arbiter to share ATT channel
  [Private GATT] Mirror GATT server inside rust module
  [Private GATT] Add to libbluetooth
  [Private GATT] Add GATT server + module
  [Private GATT] Add basic ATT transaction implementation
  [Private GATT] Basic GATT skeleton
parents 5c649dc7 4b776904
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -70,6 +70,7 @@ cc_library_shared {
        "libbluetooth-types",
        "libbluetooth",
        "libc++fs",
        "libbluetooth_core_rs_bridge",
    ],
    sanitize: {
        scs: true,
+29 −1
Original line number Diff line number Diff line
@@ -28,6 +28,9 @@
#include "com_android_bluetooth.h"
#include "gd/common/init_flags.h"
#include "hardware/bt_gatt.h"
#include "rust/cxx.h"
#include "src/core/ffi.rs.h"
#include "src/gatt/ffi.rs.h"
#include "utils/Log.h"
#define info(fmt, ...) ALOGI("%s(L%d): " fmt, __func__, __LINE__, ##__VA_ARGS__)
#define debug(fmt, ...) \
@@ -621,6 +624,7 @@ static const btgatt_client_callbacks_t sGattClientCallbacks = {
 */

void btgatts_register_app_cb(int status, int server_if, const Uuid& uuid) {
  bluetooth::gatt::open_server(server_if);
  std::shared_lock<std::shared_mutex> lock(callbacks_mutex);
  CallbackEnv sCallbackEnv(__func__);
  if (!sCallbackEnv.valid() || !mCallbacksObj) return;
@@ -643,6 +647,19 @@ void btgatts_connection_cb(int conn_id, int server_if, int connected,
void btgatts_service_added_cb(int status, int server_if,
                              const btgatt_db_element_t* service,
                              size_t service_count) {
  // mirror the database in rust, now that it's created.
  if (status == 0x00 /* SUCCESS */) {
    auto service_records = rust::Vec<bluetooth::gatt::GattRecord>();
    for (size_t i = 0; i != service_count; ++i) {
      auto& curr_service = service[i];
      service_records.push_back(bluetooth::gatt::GattRecord{
          curr_service.uuid, (bluetooth::gatt::GattRecordType)curr_service.type,
          curr_service.attribute_handle, curr_service.properties,
          curr_service.extended_properties, curr_service.permissions});
    }
    bluetooth::gatt::add_service(server_if, std::move(service_records));
  }

  std::shared_lock<std::shared_mutex> lock(callbacks_mutex);
  CallbackEnv sCallbackEnv(__func__);
  if (!sCallbackEnv.valid() || !mCallbacksObj) return;
@@ -661,6 +678,8 @@ void btgatts_service_added_cb(int status, int server_if,
}

void btgatts_service_stopped_cb(int status, int server_if, int srvc_handle) {
  bluetooth::gatt::remove_service(server_if, srvc_handle);

  std::shared_lock<std::shared_mutex> lock(callbacks_mutex);
  CallbackEnv sCallbackEnv(__func__);
  if (!sCallbackEnv.valid() || !mCallbacksObj) return;
@@ -669,6 +688,8 @@ void btgatts_service_stopped_cb(int status, int server_if, int srvc_handle) {
}

void btgatts_service_deleted_cb(int status, int server_if, int srvc_handle) {
  bluetooth::gatt::remove_service(server_if, srvc_handle);

  std::shared_lock<std::shared_mutex> lock(callbacks_mutex);
  CallbackEnv sCallbackEnv(__func__);
  if (!sCallbackEnv.valid() || !mCallbacksObj) return;
@@ -1290,6 +1311,8 @@ static void initializeNative(JNIEnv* env, jobject object) {
  sGattIf->scanner->RegisterCallbacks(JniScanningCallbacks::GetInstance());

  mCallbacksObj = env->NewGlobalRef(object);

  bluetooth::rust_shim::init();
}

static void cleanupNative(JNIEnv* env, jobject object) {
@@ -1894,6 +1917,7 @@ static void gattServerRegisterAppNative(JNIEnv* env, jobject object,
static void gattServerUnregisterAppNative(JNIEnv* env, jobject object,
                                          jint serverIf) {
  if (!sGattIf) return;
  bluetooth::gatt::close_server(serverIf);
  sGattIf->server->unregister_server(serverIf);
}

@@ -2079,8 +2103,12 @@ static void gattServerSendResponseNative(JNIEnv* env, jobject object,
    env->ReleaseByteArrayElements(val, array, JNI_ABORT);
  }

  if (bluetooth::gatt::is_connection_isolated(conn_id)) {
    // no-op
  } else {
    sGattIf->server->send_response(conn_id, trans_id, status, response);
  }
}

static void advertiseClassInitNative(JNIEnv* env, jclass clazz) {
  method_onAdvertisingSetStarted =
+3 −0
Original line number Diff line number Diff line
@@ -12,6 +12,7 @@ table InitFlagsData {
    gd_hci_enabled:bool (privacy:"Any");
    gd_controller_enabled:bool (privacy:"Any");

    always_use_private_gatt_for_debugging_is_enabled:bool (private:"Any");
    asynchronously_start_l2cap_coc_is_enabled:bool (privacy:"Any");
    btaa_hci_is_enabled:bool (privacy:"Any");
    bta_dm_clear_conn_id_on_client_close_is_enabled:bool (privacy:"Any");
@@ -37,8 +38,10 @@ table InitFlagsData {
    logging_debug_enabled_for_all_is_enabled:bool (privacy:"Any");
    pass_phy_update_callback_is_enabled:bool (privacy:"Any");
    periodic_advertising_adi_is_enabled:bool (privacy:"Any");
    private_gatt_is_enabled:bool (privacy:"Any");
    queue_l2cap_coc_while_encrypting_is_enabled:bool (privacy:"Any");
    redact_log_is_enabled:bool (privacy:"Any");
    rust_event_loop_is_enabled:bool (privacy:"Any");
    sdp_serialization_is_enabled:bool (privacy:"Any");
    sdp_skip_rnr_if_known_is_enabled:bool (privacy:"Any");
    set_min_encryption_is_enabled:bool (privacy:"Any");
+6 −1
Original line number Diff line number Diff line
@@ -33,6 +33,8 @@ flatbuffers::Offset<bluetooth::common::InitFlagsData> bluetooth::dumpsys::InitFl
  builder.add_gd_hci_enabled(true);
  builder.add_gd_controller_enabled(true);

  builder.add_always_use_private_gatt_for_debugging_is_enabled(
      initFlags::always_use_private_gatt_for_debugging_is_enabled());
  builder.add_asynchronously_start_l2cap_coc_is_enabled(initFlags::asynchronously_start_l2cap_coc_is_enabled());
  builder.add_btaa_hci_is_enabled(initFlags::btaa_hci_is_enabled());
  builder.add_bta_dm_clear_conn_id_on_client_close_is_enabled(
@@ -65,8 +67,11 @@ flatbuffers::Offset<bluetooth::common::InitFlagsData> bluetooth::dumpsys::InitFl
  builder.add_logging_debug_enabled_for_all_is_enabled(initFlags::logging_debug_enabled_for_all_is_enabled());
  builder.add_pass_phy_update_callback_is_enabled(initFlags::pass_phy_update_callback_is_enabled());
  builder.add_periodic_advertising_adi_is_enabled(bluetooth::common::init_flags::periodic_advertising_adi_is_enabled());
  builder.add_queue_l2cap_coc_while_encrypting_is_enabled(initFlags::queue_l2cap_coc_while_encrypting_is_enabled());
  builder.add_queue_l2cap_coc_while_encrypting_is_enabled(
      initFlags::queue_l2cap_coc_while_encrypting_is_enabled());
  builder.add_private_gatt_is_enabled(initFlags::private_gatt_is_enabled());
  builder.add_redact_log_is_enabled(initFlags::redact_log_is_enabled());
  builder.add_rust_event_loop_is_enabled(initFlags::rust_event_loop_is_enabled());
  builder.add_sdp_serialization_is_enabled(initFlags::sdp_serialization_is_enabled());
  builder.add_sdp_skip_rnr_if_known_is_enabled(initFlags::sdp_skip_rnr_if_known_is_enabled());
  builder.add_set_min_encryption_is_enabled(bluetooth::common::init_flags::set_min_encryption_is_enabled());
+3 −0
Original line number Diff line number Diff line
@@ -251,6 +251,7 @@ fn parse_hci_adapter(flags: &mut InitFlags, values: Vec<&str>) {
init_flags!(
    // LINT.IfChange
    flags: {
        always_use_private_gatt_for_debugging,
        asynchronously_start_l2cap_coc = true,
        btaa_hci = true,
        bta_dm_clear_conn_id_on_client_close = true,
@@ -274,8 +275,10 @@ init_flags!(
        leaudio_targeted_announcement_reconnection_mode,
        pass_phy_update_callback = true,
        periodic_advertising_adi = true,
        private_gatt,
        queue_l2cap_coc_while_encrypting = true,
        redact_log = true,
        rust_event_loop,
        sdp_serialization = true,
        sdp_skip_rnr_if_known = true,
        set_min_encryption = true,
Loading