Skip to content

Commit 75eaf7d

Browse files
gzh-terryhuangyulong3
authored andcommitted
Adapter: disable safe for both BR/EDR and BLE
bug: v/84965 rootcause: safe disable for BR/EDR does not automatically triger safe disable in BLE. Signed-off-by: Zihao Gao <gaozihao@xiaomi.com>
1 parent 4cf07d5 commit 75eaf7d

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

service/src/adapter_state.c

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,8 @@ static void off_enter(state_machine_t* sm)
216216

217217
stm->ble_enabled = false;
218218
stm->pending_turn_on = false;
219+
stm->turning_off_safe = false;
220+
stm->ble_turning_off_safe = false;
219221
const state_t* prev = hsm_get_previous_state(sm);
220222
if (prev) {
221223
adapter_notify_state_change(hsm_get_state_value(prev), BT_ADAPTER_STATE_OFF);
@@ -457,8 +459,6 @@ static void turning_off_enter(state_machine_t* sm)
457459
adapter_state_machine_t* stm = (adapter_state_machine_t*)sm;
458460
ADAPTER_DBG_ENTER(sm);
459461

460-
stm->turning_off_safe = false;
461-
462462
/* Cancel the timer in safe disable mode */
463463
service_loop_cancel_timer(stm->disable_safe_timer);
464464
stm->disable_safe_timer = NULL;
@@ -476,18 +476,37 @@ static void turning_off_exit(state_machine_t* sm)
476476

477477
static bool turning_off_process_event(state_machine_t* sm, uint32_t event, void* p_data)
478478
{
479+
adapter_state_machine_t* stm = (adapter_state_machine_t*)sm;
480+
479481
ADAPTER_DBG_EVENT(sm, event);
480482

481483
switch (event) {
482484
case BREDR_PROFILE_DISABLED:
483485
bt_sal_disable(PRIMARY_ADAPTER);
484486
break;
485487
case BREDR_DISABLED:
486-
if (adapter_is_support_le()) {
488+
if (!adapter_is_support_le()) {
489+
hsm_transition_to(sm, &off_state);
490+
break;
491+
}
492+
493+
if (!stm->turning_off_safe) {
487494
hsm_transition_to(sm, &ble_turning_off_state);
488495
break;
489496
}
490-
hsm_transition_to(sm, &off_state);
497+
498+
stm->ble_turning_off_safe = true;
499+
adapter_le_disconnect_safe();
500+
501+
stm->disable_safe_timer = service_loop_timer(DISABLE_SAFE_TIMEOUT, 0,
502+
turning_off_safe_timeout_callback, (void*)sm);
503+
504+
break;
505+
case SYS_TURN_OFF_SAFE_TIMEOUT:
506+
case BLE_ACL_ALL_DISCONNECTED:
507+
if (stm->ble_turning_off_safe)
508+
hsm_transition_to(sm, &ble_turning_off_state);
509+
491510
break;
492511
case BREDR_DISABLE_TIMEOUT:
493512
case BREDR_DISABLE_PROFILE_TIMEOUT:
@@ -504,7 +523,9 @@ static void ble_turning_off_enter(state_machine_t* sm)
504523
ADAPTER_DBG_ENTER(sm);
505524
#ifdef CONFIG_BLUETOOTH_BLE_SUPPORT
506525
adapter_state_machine_t* stm = (adapter_state_machine_t*)sm;
507-
stm->ble_turning_off_safe = false;
526+
527+
service_loop_cancel_timer(stm->disable_safe_timer);
528+
stm->disable_safe_timer = NULL;
508529

509530
/* LE profile service shotdown */
510531
service_manager_shutdown(BT_TRANSPORT_BLE);

0 commit comments

Comments
 (0)