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

Commit e084f239 authored by Yun-Hao Chung's avatar Yun-Hao Chung
Browse files

Floss: Increase the cleanup timeout on ChromeOS

When the kernel executes close() on a HCI socket, it calls a
vendor-specific shutdown routine. Some vendors implement this routine by
first performing an HCI reset and waiting up to 10 seconds. This delay
means that stopping the HciHalHost module requires a timeout of at least
10 seconds to prevent premature cleanup due to the timeout, which could
lead to an unexpected sequence of operations and ultimately a crash.

This patch increases the cleanup timeout to 11 seconds on ChromeOS and
enabling other platforms to set their own value.

Bug: 365936141
Tag: #floss
Test: mmm packages/modules/Bluetooth
Test: modify the kernel to create a delay in close socket and observe no
crash on disabling the adapter on ChromeOS.
Flag: EXEMPT, Floss-only changes

Change-Id: I81bfa791e594f1b1c747bb9bcfa32dd2e281f822
parent 535a6b8f
Loading
Loading
Loading
Loading
+4 −5
Original line number Diff line number Diff line
@@ -61,15 +61,12 @@
#include "bta/dm/bta_dm_int.h"
#include "device/include/interop.h"
#include "internal_include/stack_config.h"
#include "os/system_properties.h"
#include "rust/src/core/ffi/module.h"
#include "stack/btm/btm_ble_int.h"
#include "stack/include/ais_api.h"
#include "stack/include/smp_api.h"

#ifndef BT_STACK_CLEANUP_WAIT_MS
#define BT_STACK_CLEANUP_WAIT_MS 1000
#endif

// Validate or respond to various conditional compilation flags

// Once BTA_PAN_INCLUDED is no longer exposed via bt_target.h
@@ -173,7 +170,9 @@ static void clean_up_stack(ProfileStopCallback stopProfiles) {
  management_thread.DoInThread(
          FROM_HERE, base::BindOnce(event_clean_up_stack, std::move(promise), stopProfiles));

  auto status = future.wait_for(std::chrono::milliseconds(BT_STACK_CLEANUP_WAIT_MS));
  auto status = future.wait_for(std::chrono::milliseconds(
          bluetooth::os::GetSystemPropertyUint32("bluetooth.cleanup_timeout",
                                                 /* default_value = */ 1000)));
  if (status == std::future_status::ready) {
    management_thread.ShutDown();
  } else {
+4 −1
Original line number Diff line number Diff line
@@ -29,7 +29,10 @@ std::mutex properties_mutex;
// Properties set along with some default values for Floss.
std::unordered_map<std::string, std::string> properties = {
        {"bluetooth.profile.avrcp.target.enabled", "true"},
        {"bluetooth.gd.start_timeout", "12000"}};
        {"bluetooth.gd.start_timeout", "12000"},
        {"bluetooth.gd.stop_timeout", "12000"},
        /* HCI Reset timeout: 10s + Default cleanup timeout: 1s = 11s */
        {"bluetooth.cleanup_timeout", "11000"}};
}  // namespace

std::optional<std::string> GetSystemProperty(const std::string& property) {
+4 −1
Original line number Diff line number Diff line
@@ -29,7 +29,10 @@ std::mutex properties_mutex;
// Properties set along with some default values for Floss.
std::unordered_map<std::string, std::string> properties = {
        {"bluetooth.profile.avrcp.target.enabled", "true"},
        {"bluetooth.gd.start_timeout", "12000"}};
        {"bluetooth.gd.start_timeout", "12000"},
        {"bluetooth.gd.stop_timeout", "12000"},
        /* HCI Reset timeout: 10s + Default cleanup timeout: 1s = 11s */
        {"bluetooth.cleanup_timeout", "11000"}};
}  // namespace

std::optional<std::string> GetSystemProperty(const std::string& property) {
+1 −1
Original line number Diff line number Diff line
@@ -48,7 +48,7 @@ const ADMIN_SETTINGS_FILE_PATH: &str = "/var/lib/bluetooth/admin_policy.json";
// and BTA_DM_DISABLE_TIMER_RETRIAL_MS
const STACK_TURN_OFF_TIMEOUT_MS: Duration = Duration::from_millis(4000);
// Time bt_stack_manager waits for cleanup
const STACK_CLEANUP_TIMEOUT_MS: Duration = Duration::from_millis(1000);
const STACK_CLEANUP_TIMEOUT_MS: Duration = Duration::from_millis(11000);
// Time bt_stack_manager waits for cleanup profiles
const STACK_CLEANUP_PROFILES_TIMEOUT_MS: Duration = Duration::from_millis(100);
// Extra time to wait before terminating the process