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

Commit 432ea9db authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Start up Rust Module when Gatt Native is being init" into main

parents fdab89a1 10629d7b
Loading
Loading
Loading
Loading
+9 −0
Original line number Original line Diff line number Diff line
@@ -25,6 +25,7 @@
#include <shared_mutex>
#include <shared_mutex>


#include "com_android_bluetooth.h"
#include "com_android_bluetooth.h"
#include "com_android_bluetooth_flags.h"
#include "common/init_flags.h"
#include "common/init_flags.h"
#include "hardware/bt_gatt.h"
#include "hardware/bt_gatt.h"
#include "hardware/bt_gatt_types.h"
#include "hardware/bt_gatt_types.h"
@@ -1279,6 +1280,10 @@ static void initializeNative(JNIEnv* env, jobject object) {
    return;
    return;
  }
  }


  if (com::android::bluetooth::flags::scan_manager_refactor()) {
    btIf->start_rust_module();
  }

  sGattIf->advertiser->RegisterCallbacks(
  sGattIf->advertiser->RegisterCallbacks(
      JniAdvertisingCallbacks::GetInstance());
      JniAdvertisingCallbacks::GetInstance());
  sGattIf->distance_measurement_manager->RegisterDistanceMeasurementCallbacks(
  sGattIf->distance_measurement_manager->RegisterDistanceMeasurementCallbacks(
@@ -1292,6 +1297,10 @@ static void cleanupNative(JNIEnv* env, jobject /* object */) {


  if (!btIf) return;
  if (!btIf) return;


  if (com::android::bluetooth::flags::scan_manager_refactor()) {
    btIf->stop_rust_module();
  }

  if (sGattIf != NULL) {
  if (sGattIf != NULL) {
    sGattIf->cleanup();
    sGattIf->cleanup();
    sGattIf = NULL;
    sGattIf = NULL;
+2 −0
Original line number Original line Diff line number Diff line
@@ -32,6 +32,8 @@ typedef struct {
                               ProfileStartCallback, ProfileStopCallback);
                               ProfileStartCallback, ProfileStopCallback);
  void (*shut_down_stack_async)(ProfileStopCallback);
  void (*shut_down_stack_async)(ProfileStopCallback);
  void (*clean_up_stack)(ProfileStopCallback);
  void (*clean_up_stack)(ProfileStopCallback);
  void (*start_up_rust_module_async)();
  void (*shut_down_rust_module_async)();


  bool (*get_stack_is_running)(void);
  bool (*get_stack_is_running)(void);
} stack_manager_t;
} stack_manager_t;
+10 −0
Original line number Original line Diff line number Diff line
@@ -486,6 +486,14 @@ static void cleanup(void) {
  stack_manager_get_interface()->clean_up_stack(&stop_profiles);
  stack_manager_get_interface()->clean_up_stack(&stop_profiles);
}
}


static void start_rust_module(void) {
  stack_manager_get_interface()->start_up_rust_module_async();
}

static void stop_rust_module(void) {
  stack_manager_get_interface()->shut_down_rust_module_async();
}

bool is_restricted_mode() { return restricted_mode; }
bool is_restricted_mode() { return restricted_mode; }


static bool get_wbs_supported() {
static bool get_wbs_supported() {
@@ -1158,6 +1166,8 @@ EXPORT_SYMBOL bt_interface_t bluetoothInterface = {
    .enable = enable,
    .enable = enable,
    .disable = disable,
    .disable = disable,
    .cleanup = cleanup,
    .cleanup = cleanup,
    .start_rust_module = start_rust_module,
    .stop_rust_module = stop_rust_module,
    .get_adapter_properties = get_adapter_properties,
    .get_adapter_properties = get_adapter_properties,
    .get_adapter_property = get_adapter_property,
    .get_adapter_property = get_adapter_property,
    .set_scan_mode = set_scan_mode,
    .set_scan_mode = set_scan_mode,
+29 −2
Original line number Original line Diff line number Diff line
@@ -128,6 +128,8 @@ static void event_start_up_stack(bluetooth::core::CoreInterface* interface,
static void event_shut_down_stack(ProfileStopCallback stopProfiles);
static void event_shut_down_stack(ProfileStopCallback stopProfiles);
static void event_clean_up_stack(std::promise<void> promise,
static void event_clean_up_stack(std::promise<void> promise,
                                 ProfileStopCallback stopProfiles);
                                 ProfileStopCallback stopProfiles);
static void event_start_up_rust_module();
static void event_shut_down_rust_module();


static void event_signal_stack_up(void* context);
static void event_signal_stack_up(void* context);
static void event_signal_stack_down(void* context);
static void event_signal_stack_down(void* context);
@@ -189,6 +191,14 @@ static void clean_up_stack(ProfileStopCallback stopProfiles) {
  }
  }
}
}


static void start_up_rust_module_async() {
    management_thread.DoInThread(FROM_HERE, base::BindOnce(event_start_up_rust_module));
}

static void shut_down_rust_module_async() {
    management_thread.DoInThread(FROM_HERE, base::BindOnce(event_shut_down_rust_module));
}

static bool get_stack_is_running() { return stack_is_running; }
static bool get_stack_is_running() { return stack_is_running; }


// Internal functions
// Internal functions
@@ -324,7 +334,9 @@ static void event_start_up_stack(bluetooth::core::CoreInterface* interface,
    return;
    return;
  }
  }


  if (!com::android::bluetooth::flags::scan_manager_refactor()) {
    module_start_up(get_local_module(RUST_MODULE));
    module_start_up(get_local_module(RUST_MODULE));
  }
  if (com::android::bluetooth::flags::channel_sounding_in_stack()) {
  if (com::android::bluetooth::flags::channel_sounding_in_stack()) {
    bluetooth::ras::GetRasServer()->Initialize();
    bluetooth::ras::GetRasServer()->Initialize();
    bluetooth::ras::GetRasClient()->Initialize();
    bluetooth::ras::GetRasClient()->Initialize();
@@ -347,7 +359,9 @@ static void event_shut_down_stack(ProfileStopCallback stopProfiles) {
  hack_future = local_hack_future;
  hack_future = local_hack_future;
  stack_is_running = false;
  stack_is_running = false;


  if (!com::android::bluetooth::flags::scan_manager_refactor()) {
    module_shut_down(get_local_module(RUST_MODULE));
    module_shut_down(get_local_module(RUST_MODULE));
  }


  do_in_main_thread(FROM_HERE, base::BindOnce(&btm_ble_scanner_cleanup));
  do_in_main_thread(FROM_HERE, base::BindOnce(&btm_ble_scanner_cleanup));


@@ -383,6 +397,18 @@ static void event_shut_down_stack(ProfileStopCallback stopProfiles) {
  log::info("finished");
  log::info("finished");
}
}


static void event_start_up_rust_module() {
    log::info("is bringing up the Rust module");
    module_start_up(get_local_module(RUST_MODULE));
    log::info("finished");
}

static void event_shut_down_rust_module() {
  log::info("is bringing down the Rust module");
  module_shut_down(get_local_module(RUST_MODULE));
  log::info("finished");
}

static void ensure_stack_is_not_running(ProfileStopCallback stopProfiles) {
static void ensure_stack_is_not_running(ProfileStopCallback stopProfiles) {
  if (stack_is_running) {
  if (stack_is_running) {
    log::warn("found the stack was still running. Bringing it down now.");
    log::warn("found the stack was still running. Bringing it down now.");
@@ -450,6 +476,7 @@ static void ensure_manager_initialized() {


static const stack_manager_t interface = {init_stack, start_up_stack_async,
static const stack_manager_t interface = {init_stack, start_up_stack_async,
                                          shut_down_stack_async, clean_up_stack,
                                          shut_down_stack_async, clean_up_stack,
                                          start_up_rust_module_async, shut_down_rust_module_async,
                                          get_stack_is_running};
                                          get_stack_is_running};


const stack_manager_t* stack_manager_get_interface() {
const stack_manager_t* stack_manager_get_interface() {
+1 −1
Original line number Original line Diff line number Diff line
@@ -32,7 +32,7 @@ typedef void(tBTIF_COPY_CBACK)(uint16_t event, char* p_dest, const char* p_src);
// NOTE: Local re-implementation of functions to avoid thread context switching
// NOTE: Local re-implementation of functions to avoid thread context switching
static bool sStackRunning;
static bool sStackRunning;
bool get_stack_is_running(void) { return sStackRunning; }
bool get_stack_is_running(void) { return sStackRunning; }
static stack_manager_t sStackManager = {nullptr, nullptr, nullptr, nullptr,
static stack_manager_t sStackManager = {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
                                        get_stack_is_running};
                                        get_stack_is_running};
const stack_manager_t* stack_manager_get_interface() { return &sStackManager; }
const stack_manager_t* stack_manager_get_interface() { return &sStackManager; }
bt_status_t do_in_jni_thread(base::OnceClosure task) {
bt_status_t do_in_jni_thread(base::OnceClosure task) {
Loading