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

Commit a7de2640 authored by Pavlin Radoslavov's avatar Pavlin Radoslavov Committed by Andre Eisenbach
Browse files

Don't destroy BTIF Device Management state during shutdown

Don't call btif_dm_cleanup() during stack shutdown stage,
because it will destroy/free internal state that might be used
later in the shutdown process.
Instead, btif_dm_cleanup() should happen during the stack
cleanup stage.

Also, added an unit test to capture the original issue.

Bug: 27856457
Change-Id: I8575537ad744cf4e6770046b779b6a53de93d66e
parent d50aecf7
Loading
Loading
Loading
Loading
+2 −8
Original line number Diff line number Diff line
@@ -534,8 +534,6 @@ void btif_enable_bluetooth_evt(tBTA_STATUS status)
    }
    else
    {
        btif_dm_cleanup();

        /* cleanup rfcomm & l2cap api */
        btif_sock_cleanup();

@@ -561,17 +559,11 @@ bt_status_t btif_disable_bluetooth(void)
    BTIF_TRACE_DEBUG("BTIF DISABLE BLUETOOTH");

    btif_dm_on_disable();
    btif_dm_cleanup();
    /* cleanup rfcomm & l2cap api */
    btif_sock_cleanup();
    btif_pan_cleanup();
    BTA_DisableBluetooth();

    if (uid_set) {
        uid_set_destroy(uid_set);
        uid_set = NULL;
    }

    return BT_STATUS_SUCCESS;
}

@@ -620,6 +612,8 @@ bt_status_t btif_shutdown_bluetooth(void)
{
    BTIF_TRACE_DEBUG("%s", __FUNCTION__);

    btif_dm_cleanup();

    btif_transfer_context(btif_jni_disassociate, 0, NULL, 0, NULL);

    btif_queue_release();
+4 −1
Original line number Diff line number Diff line
@@ -305,7 +305,10 @@ void btif_dm_init(uid_set_t* set)

void btif_dm_cleanup(void)
{
    if (uid_set) {
        uid_set_destroy(uid_set);
        uid_set = NULL;
    }
    pthread_mutex_destroy(&bond_event_lock);
}

+23 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@

extern "C" {
#include "btcore/include/property.h"
#include "stack/include/bt_types.h"
}

namespace {
@@ -148,4 +149,26 @@ TEST_F(BluetoothTest, AdapterCancelDiscovery) {
  EXPECT_EQ(GetState(), BT_STATE_OFF) << "Adapter did not turn off.";
}

TEST_F(BluetoothTest, AdapterDisableDuringBonding) {
  EXPECT_EQ(GetState(), BT_STATE_OFF)
    << "Test should be run with Adapter disabled";

  bt_bdaddr_t bdaddr = { { 0x22, 0x22, 0x22, 0x22, 0x22, 0x22 } };

  for (int i = 0; i < kTestRepeatCount; ++i) {
    EXPECT_EQ(bt_interface()->enable(), BT_STATUS_SUCCESS);
    semaphore_wait(adapter_state_changed_callback_sem_);
    EXPECT_EQ(GetState(), BT_STATE_ON) <<  "Adapter did not turn on.";

    EXPECT_EQ(bt_interface()->create_bond(&bdaddr, BT_TRANSPORT_BR_EDR),
              BT_STATUS_SUCCESS);

    EXPECT_EQ(bt_interface()->cancel_bond(&bdaddr), BT_STATUS_SUCCESS);

    EXPECT_EQ(bt_interface()->disable(), BT_STATUS_SUCCESS);
    semaphore_wait(adapter_state_changed_callback_sem_);
    EXPECT_EQ(GetState(), BT_STATE_OFF) << "Adapter did not turn off.";
  }
}

}  // bttest