Loading flags/sniff.aconfig 0 → 100644 +8 −0 Original line number Diff line number Diff line package: "com.android.bluetooth.flags" flag { name: "enable_sniff_offload" namespace: "bluetooth" description: "Enable sniff offload feature." bug: "318786790" } system/bta/Android.bp +4 −1 Original line number Diff line number Diff line Loading @@ -305,7 +305,10 @@ cc_test { ":audio_set_scenarios_bfbs", ":audio_set_scenarios_json", ], cflags: ["-Wno-unused-parameter"], cflags: [ "-Wno-macro-redefined", "-Wno-unused-parameter", ], } // bta GATT unit tests Loading system/bta/dm/bta_dm_act.cc +12 −2 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ #define LOG_TAG "bt_bta_dm" #include <android_bluetooth_flags.h> #include <android_bluetooth_sysprop.h> #include <base/location.h> #include <base/logging.h> Loading Loading @@ -86,6 +87,9 @@ static void bta_dm_adjust_roles(bool delay_role_switch); tBTM_CONTRL_STATE bta_dm_pm_obtain_controller_state(void); static void bta_dm_ctrl_features_rd_cmpl_cback(tHCI_STATUS result); static const char kPropertySniffOffloadEnabled[] = "bluetooth.sniff_offload.enabled"; #ifndef BTA_DM_BLE_ADV_CHNL_MAP #define BTA_DM_BLE_ADV_CHNL_MAP \ (BTM_BLE_ADV_CHNL_37 | BTM_BLE_ADV_CHNL_38 | BTM_BLE_ADV_CHNL_39) Loading Loading @@ -287,8 +291,13 @@ void BTA_dm_on_hw_on() { bta_sys_rm_register(bta_dm_rm_cback); /* if sniff is offload, no need to handle it in the stack */ if (IS_FLAG_ENABLED(enable_sniff_offload) && osi_property_get_bool(kPropertySniffOffloadEnabled, false)) { } else { /* initialize bluetooth low power manager */ bta_dm_init_pm(); } bta_dm_disc_gattc_register(); } Loading Loading @@ -1710,6 +1719,7 @@ tBTA_DM_PEER_DEVICE* allocate_device_for(const RawAddress& bd_addr, void bta_dm_init_cb() { ::bta_dm_init_cb(); } void bta_dm_deinit_cb() { ::bta_dm_deinit_cb(); } void BTA_dm_on_hw_on() { ::BTA_dm_on_hw_on(); } } // namespace testing } // namespace legacy Loading system/bta/test/bta_dm_test.cc +51 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,8 @@ #include <base/functional/bind.h> #include <base/location.h> #include <com_android_bluetooth_flags.h> #include <flag_macros.h> #include <gmock/gmock.h> #include <gtest/gtest.h> Loading @@ -36,9 +38,12 @@ #include "test/common/mock_functions.h" #include "test/mock/mock_osi_alarm.h" #include "test/mock/mock_osi_allocator.h" #include "test/mock/mock_osi_properties.h" #include "test/mock/mock_stack_acl.h" #include "test/mock/mock_stack_btm_interface.h" #define TEST_BT com::android::bluetooth::flags using namespace std::chrono_literals; namespace { Loading Loading @@ -213,6 +218,8 @@ void btm_set_local_io_caps(uint8_t io_caps); tBTM_STATUS bta_dm_sp_cback(tBTM_SP_EVT event, tBTM_SP_EVT_DATA* p_data); void BTA_dm_on_hw_on(); } // namespace testing } // namespace legacy } // namespace bluetooth Loading Loading @@ -600,3 +607,47 @@ TEST_F(BtaDmCustomAlarmTest, bta_dm_sniff_cback) { ASSERT_EQ(1, get_func_call_count("alarm_cancel")); ASSERT_EQ(2, get_func_call_count("alarm_set_on_mloop")); } TEST_F_WITH_FLAGS(BtaDmCustomAlarmTest, sniff_offload_feature__enable_flag, REQUIRES_FLAGS_ENABLED(ACONFIG_FLAG(TEST_BT, enable_sniff_offload))) { bool is_property_enabled = true; test::mock::osi_properties::osi_property_get_bool.body = [&](const char* key, bool default_value) -> int { return is_property_enabled; }; // Expect not to trigger bta_dm_init_pm due to both flag and prop are enabled // and reset the value of .srvc_id. is_property_enabled = true; bluetooth::legacy::testing::BTA_dm_on_hw_on(); ASSERT_EQ(0, bta_dm_cb.pm_timer[0].srvc_id[0]); // Expect to trigger bta_dm_init_pm and init the value of .srvc_id to // BTA_ID_MAX. is_property_enabled = false; bluetooth::legacy::testing::BTA_dm_on_hw_on(); ASSERT_EQ((uint8_t)BTA_ID_MAX, bta_dm_cb.pm_timer[0].srvc_id[0]); } TEST_F_WITH_FLAGS(BtaDmCustomAlarmTest, sniff_offload_feature__disable_flag, REQUIRES_FLAGS_DISABLED(ACONFIG_FLAG(TEST_BT, enable_sniff_offload))) { bool is_property_enabled = true; test::mock::osi_properties::osi_property_get_bool.body = [&](const char* key, bool default_value) -> int { return is_property_enabled; }; // Expect to trigger bta_dm_init_pm and init the value of .srvc_id to // BTA_ID_MAX. is_property_enabled = true; bluetooth::legacy::testing::BTA_dm_on_hw_on(); ASSERT_EQ((uint8_t)BTA_ID_MAX, bta_dm_cb.pm_timer[0].srvc_id[0]); // Expect to trigger bta_dm_init_pm and init the value of .srvc_id to // BTA_ID_MAX. is_property_enabled = false; bluetooth::legacy::testing::BTA_dm_on_hw_on(); ASSERT_EQ((uint8_t)BTA_ID_MAX, bta_dm_cb.pm_timer[0].srvc_id[0]); } Loading
flags/sniff.aconfig 0 → 100644 +8 −0 Original line number Diff line number Diff line package: "com.android.bluetooth.flags" flag { name: "enable_sniff_offload" namespace: "bluetooth" description: "Enable sniff offload feature." bug: "318786790" }
system/bta/Android.bp +4 −1 Original line number Diff line number Diff line Loading @@ -305,7 +305,10 @@ cc_test { ":audio_set_scenarios_bfbs", ":audio_set_scenarios_json", ], cflags: ["-Wno-unused-parameter"], cflags: [ "-Wno-macro-redefined", "-Wno-unused-parameter", ], } // bta GATT unit tests Loading
system/bta/dm/bta_dm_act.cc +12 −2 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ #define LOG_TAG "bt_bta_dm" #include <android_bluetooth_flags.h> #include <android_bluetooth_sysprop.h> #include <base/location.h> #include <base/logging.h> Loading Loading @@ -86,6 +87,9 @@ static void bta_dm_adjust_roles(bool delay_role_switch); tBTM_CONTRL_STATE bta_dm_pm_obtain_controller_state(void); static void bta_dm_ctrl_features_rd_cmpl_cback(tHCI_STATUS result); static const char kPropertySniffOffloadEnabled[] = "bluetooth.sniff_offload.enabled"; #ifndef BTA_DM_BLE_ADV_CHNL_MAP #define BTA_DM_BLE_ADV_CHNL_MAP \ (BTM_BLE_ADV_CHNL_37 | BTM_BLE_ADV_CHNL_38 | BTM_BLE_ADV_CHNL_39) Loading Loading @@ -287,8 +291,13 @@ void BTA_dm_on_hw_on() { bta_sys_rm_register(bta_dm_rm_cback); /* if sniff is offload, no need to handle it in the stack */ if (IS_FLAG_ENABLED(enable_sniff_offload) && osi_property_get_bool(kPropertySniffOffloadEnabled, false)) { } else { /* initialize bluetooth low power manager */ bta_dm_init_pm(); } bta_dm_disc_gattc_register(); } Loading Loading @@ -1710,6 +1719,7 @@ tBTA_DM_PEER_DEVICE* allocate_device_for(const RawAddress& bd_addr, void bta_dm_init_cb() { ::bta_dm_init_cb(); } void bta_dm_deinit_cb() { ::bta_dm_deinit_cb(); } void BTA_dm_on_hw_on() { ::BTA_dm_on_hw_on(); } } // namespace testing } // namespace legacy Loading
system/bta/test/bta_dm_test.cc +51 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,8 @@ #include <base/functional/bind.h> #include <base/location.h> #include <com_android_bluetooth_flags.h> #include <flag_macros.h> #include <gmock/gmock.h> #include <gtest/gtest.h> Loading @@ -36,9 +38,12 @@ #include "test/common/mock_functions.h" #include "test/mock/mock_osi_alarm.h" #include "test/mock/mock_osi_allocator.h" #include "test/mock/mock_osi_properties.h" #include "test/mock/mock_stack_acl.h" #include "test/mock/mock_stack_btm_interface.h" #define TEST_BT com::android::bluetooth::flags using namespace std::chrono_literals; namespace { Loading Loading @@ -213,6 +218,8 @@ void btm_set_local_io_caps(uint8_t io_caps); tBTM_STATUS bta_dm_sp_cback(tBTM_SP_EVT event, tBTM_SP_EVT_DATA* p_data); void BTA_dm_on_hw_on(); } // namespace testing } // namespace legacy } // namespace bluetooth Loading Loading @@ -600,3 +607,47 @@ TEST_F(BtaDmCustomAlarmTest, bta_dm_sniff_cback) { ASSERT_EQ(1, get_func_call_count("alarm_cancel")); ASSERT_EQ(2, get_func_call_count("alarm_set_on_mloop")); } TEST_F_WITH_FLAGS(BtaDmCustomAlarmTest, sniff_offload_feature__enable_flag, REQUIRES_FLAGS_ENABLED(ACONFIG_FLAG(TEST_BT, enable_sniff_offload))) { bool is_property_enabled = true; test::mock::osi_properties::osi_property_get_bool.body = [&](const char* key, bool default_value) -> int { return is_property_enabled; }; // Expect not to trigger bta_dm_init_pm due to both flag and prop are enabled // and reset the value of .srvc_id. is_property_enabled = true; bluetooth::legacy::testing::BTA_dm_on_hw_on(); ASSERT_EQ(0, bta_dm_cb.pm_timer[0].srvc_id[0]); // Expect to trigger bta_dm_init_pm and init the value of .srvc_id to // BTA_ID_MAX. is_property_enabled = false; bluetooth::legacy::testing::BTA_dm_on_hw_on(); ASSERT_EQ((uint8_t)BTA_ID_MAX, bta_dm_cb.pm_timer[0].srvc_id[0]); } TEST_F_WITH_FLAGS(BtaDmCustomAlarmTest, sniff_offload_feature__disable_flag, REQUIRES_FLAGS_DISABLED(ACONFIG_FLAG(TEST_BT, enable_sniff_offload))) { bool is_property_enabled = true; test::mock::osi_properties::osi_property_get_bool.body = [&](const char* key, bool default_value) -> int { return is_property_enabled; }; // Expect to trigger bta_dm_init_pm and init the value of .srvc_id to // BTA_ID_MAX. is_property_enabled = true; bluetooth::legacy::testing::BTA_dm_on_hw_on(); ASSERT_EQ((uint8_t)BTA_ID_MAX, bta_dm_cb.pm_timer[0].srvc_id[0]); // Expect to trigger bta_dm_init_pm and init the value of .srvc_id to // BTA_ID_MAX. is_property_enabled = false; bluetooth::legacy::testing::BTA_dm_on_hw_on(); ASSERT_EQ((uint8_t)BTA_ID_MAX, bta_dm_cb.pm_timer[0].srvc_id[0]); }