From abfd66a9b261c32f0fbefd4c18c488e9eaa1af2b Mon Sep 17 00:00:00 2001 From: Wei-Luan Wang <weiluanwang@google.com> Date: Mon, 11 Sep 2023 03:50:22 +0000 Subject: [PATCH] Migrate LeRandCallback to be base::OnceCallback base::Bind and base::Callback are deprecated. Migrate the usages to proper replacements. The callback of LeRand is expected to be called for receiving the resulting random number. It's called only once so it should be a base::OnceCallback. Bug: 272116782 Test: m . Change-Id: I8dc78f54aae455f089bc29ee814c3e0c0635ba9e --- system/bta/dm/bta_dm_act.cc | 2 +- system/bta/dm/bta_dm_api.cc | 2 +- system/bta/include/bta_api.h | 2 +- system/btif/src/bluetooth.cc | 3 ++- system/btif/src/btif_dm.cc | 2 +- system/device/include/controller.h | 2 +- system/gd/hci/controller.cc | 7 ++++--- system/gd/hci/le_rand_callback.h | 2 +- system/main/shim/acl.cc | 4 ++-- system/main/shim/acl.h | 2 +- system/main/shim/btm_api.cc | 2 +- system/main/shim/btm_api.h | 2 +- system/main/shim/controller.cc | 2 +- 13 files changed, 18 insertions(+), 16 deletions(-) diff --git a/system/bta/dm/bta_dm_act.cc b/system/bta/dm/bta_dm_act.cc index a89a3692e9d..de0ea87d075 100644 --- a/system/bta/dm/bta_dm_act.cc +++ b/system/bta/dm/bta_dm_act.cc @@ -4519,7 +4519,7 @@ void bta_dm_disconnect_all_acls(void) { ******************************************************************************/ void bta_dm_le_rand(LeRandCallback cb) { VLOG(1) << "bta_dm_le_rand in bta_dm_act"; - bluetooth::shim::BTM_LeRand(cb); + bluetooth::shim::BTM_LeRand(std::move(cb)); } /******************************************************************************* diff --git a/system/bta/dm/bta_dm_api.cc b/system/bta/dm/bta_dm_api.cc index f9003731869..ee4f378ad48 100644 --- a/system/bta/dm/bta_dm_api.cc +++ b/system/bta/dm/bta_dm_api.cc @@ -710,7 +710,7 @@ void BTA_DmClearFilterAcceptList(void) { ******************************************************************************/ void BTA_DmLeRand(LeRandCallback cb) { APPL_TRACE_API("BTA_DmLeRand"); - do_in_main_thread(FROM_HERE, base::BindOnce(bta_dm_le_rand, cb)); + do_in_main_thread(FROM_HERE, base::BindOnce(bta_dm_le_rand, std::move(cb))); } /******************************************************************************* diff --git a/system/bta/include/bta_api.h b/system/bta/include/bta_api.h index 0d2095eff54..9c6dda3d104 100644 --- a/system/bta/include/bta_api.h +++ b/system/bta/include/bta_api.h @@ -1341,7 +1341,7 @@ void BTA_DmDisconnectAllAcls(void); ******************************************************************************/ void BTA_DmClearFilterAcceptList(void); -using LeRandCallback = base::Callback<void(uint64_t)>; +using LeRandCallback = base::OnceCallback<void(uint64_t)>; /******************************************************************************* * * Function BTA_DmLeRand diff --git a/system/btif/src/bluetooth.cc b/system/btif/src/bluetooth.cc index 6b3ef639bfe..084da2b9073 100644 --- a/system/btif/src/bluetooth.cc +++ b/system/btif/src/bluetooth.cc @@ -738,7 +738,8 @@ static int le_rand() { if (!interface_ready()) return BT_STATUS_NOT_READY; do_in_main_thread( - FROM_HERE, base::BindOnce(btif_dm_le_rand, base::Bind(&le_rand_btif_cb))); + FROM_HERE, + base::BindOnce(btif_dm_le_rand, base::BindOnce(&le_rand_btif_cb))); return BT_STATUS_SUCCESS; } diff --git a/system/btif/src/btif_dm.cc b/system/btif/src/btif_dm.cc index a45825ac861..8f40781d0f3 100644 --- a/system/btif/src/btif_dm.cc +++ b/system/btif/src/btif_dm.cc @@ -4060,7 +4060,7 @@ void btif_dm_disconnect_all_acls() { void btif_dm_le_rand(LeRandCallback callback) { LOG_VERBOSE("%s: called", __func__); - BTA_DmLeRand(callback); + BTA_DmLeRand(std::move(callback)); } void btif_dm_set_event_filter_connection_setup_all_devices() { diff --git a/system/device/include/controller.h b/system/device/include/controller.h index 9881461bd43..bddf06bcba2 100644 --- a/system/device/include/controller.h +++ b/system/device/include/controller.h @@ -26,7 +26,7 @@ #include "btcore/include/version.h" #include "types/raw_address.h" -using LeRandCallback = base::Callback<void(uint64_t)>; +using LeRandCallback = base::OnceCallback<void(uint64_t)>; typedef struct controller_t { bool (*get_is_ready)(void); diff --git a/system/gd/hci/controller.cc b/system/gd/hci/controller.cc index 78fd6fb8b7f..2c7a433ac9f 100644 --- a/system/gd/hci/controller.cc +++ b/system/gd/hci/controller.cc @@ -621,7 +621,8 @@ struct Controller::impl { std::unique_ptr<LeRandBuilder> packet = LeRandBuilder::Create(); hci_->EnqueueCommand( std::move(packet), - module_.GetHandler()->BindOnceOn(this, &Controller::impl::le_rand_cb<LeRandCompleteView>, cb)); + module_.GetHandler()->BindOnceOn( + this, &Controller::impl::le_rand_cb<LeRandCompleteView>, std::move(cb))); } template <class T> @@ -630,7 +631,7 @@ struct Controller::impl { auto status_view = T::Create(view); ASSERT(status_view.IsValid()); ASSERT(status_view.GetStatus() == ErrorCode::SUCCESS); - cb.Run(status_view.GetRandomNumber()); + std::move(cb).Run(status_view.GetRandomNumber()); } void set_event_filter(std::unique_ptr<SetEventFilterBuilder> packet) { @@ -1220,7 +1221,7 @@ void Controller::Reset() { } void Controller::LeRand(LeRandCallback cb) { - CallOn(impl_.get(), &impl::le_rand, cb); + CallOn(impl_.get(), &impl::le_rand, std::move(cb)); } void Controller::SetEventFilterClearAll() { diff --git a/system/gd/hci/le_rand_callback.h b/system/gd/hci/le_rand_callback.h index 60222e9fe3a..da55c948a3e 100644 --- a/system/gd/hci/le_rand_callback.h +++ b/system/gd/hci/le_rand_callback.h @@ -21,7 +21,7 @@ namespace bluetooth { namespace hci { -using LeRandCallback = common::Callback<void(uint64_t)>; +using LeRandCallback = common::OnceCallback<void(uint64_t)>; } // namespace hci } // namespace bluetooth diff --git a/system/main/shim/acl.cc b/system/main/shim/acl.cc index 5cfb881a973..ea273184298 100644 --- a/system/main/shim/acl.cc +++ b/system/main/shim/acl.cc @@ -1128,7 +1128,7 @@ struct shim::legacy::Acl::impl { } void le_rand(LeRandCallback cb ) { - controller_get_interface()->le_rand(cb); + controller_get_interface()->le_rand(std::move(cb)); } void AddToAddressResolution(const hci::AddressWithType& address_with_type, @@ -1934,7 +1934,7 @@ void shim::legacy::Acl::ClearFilterAcceptList() { } void shim::legacy::Acl::LeRand(LeRandCallback cb) { - handler_->CallOn(pimpl_.get(), &Acl::impl::le_rand, cb); + handler_->CallOn(pimpl_.get(), &Acl::impl::le_rand, std::move(cb)); } void shim::legacy::Acl::AddToAddressResolution( diff --git a/system/main/shim/acl.h b/system/main/shim/acl.h index 335947a51b8..5c08312e7af 100644 --- a/system/main/shim/acl.h +++ b/system/main/shim/acl.h @@ -32,7 +32,7 @@ #include "stack/include/bt_types.h" #include "types/raw_address.h" -using LeRandCallback = base::Callback<void(uint64_t)>; +using LeRandCallback = base::OnceCallback<void(uint64_t)>; namespace bluetooth { namespace shim { diff --git a/system/main/shim/btm_api.cc b/system/main/shim/btm_api.cc index d53774ea1a7..af3a005646a 100644 --- a/system/main/shim/btm_api.cc +++ b/system/main/shim/btm_api.cc @@ -75,7 +75,7 @@ tBTM_STATUS bluetooth::shim::BTM_DisconnectAllAcls() { } tBTM_STATUS bluetooth::shim::BTM_LeRand(LeRandCallback cb) { - Stack::GetInstance()->GetAcl()->LeRand(cb); + Stack::GetInstance()->GetAcl()->LeRand(std::move(cb)); return BTM_SUCCESS; } diff --git a/system/main/shim/btm_api.h b/system/main/shim/btm_api.h index 30665ec4c84..1b21726f3db 100644 --- a/system/main/shim/btm_api.h +++ b/system/main/shim/btm_api.h @@ -1820,7 +1820,7 @@ tBTM_STATUS BTM_DisconnectAllAcls(void); * Returns Return btm status * ******************************************************************************/ -using LeRandCallback = base::Callback<void(uint64_t)>; +using LeRandCallback = base::OnceCallback<void(uint64_t)>; tBTM_STATUS BTM_LeRand(LeRandCallback); /******************************************************************************* diff --git a/system/main/shim/controller.cc b/system/main/shim/controller.cc index dc557f8a92e..7cdde98a85d 100644 --- a/system/main/shim/controller.cc +++ b/system/main/shim/controller.cc @@ -286,7 +286,7 @@ static uint8_t controller_clear_event_mask() { static uint8_t controller_le_rand(LeRandCallback cb) { LOG_VERBOSE("Called!"); - bluetooth::shim::GetController()->LeRand(cb); + bluetooth::shim::GetController()->LeRand(std::move(cb)); return BTM_SUCCESS; } -- GitLab