summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Jakub Rotkiewicz <rotkiewicz@google.com> 2024-02-27 18:15:43 +0000
committer Jakub Rotkiewicz <rotkiewicz@google.com> 2024-04-17 10:12:15 +0000
commitc59c75133423a17cb7c83559a149e06b2e8dc2f4 (patch)
tree09bf6812265c62cb6aca7851295a271391bae48b
parentf4f42a309d814928d0a077e4aa9d949283fb085c (diff)
a2dp_api: allow binding to tA2DP_FIND_CBACK
This change allows to bind custom callback when using A2DP_FindService function. Bug: 296962438 Flag: EXEMPT, mechanical refactor to callback object Test: m com.android.btservices Change-Id: I114b1cce9559cc3c795ee540448841ebf9288de8
-rw-r--r--system/bta/av/bta_av_aact.cc5
-rw-r--r--system/stack/a2dp/a2dp_api.cc10
-rw-r--r--system/stack/a2dp/a2dp_int.h2
-rw-r--r--system/stack/include/a2dp_api.h8
-rw-r--r--system/stack/test/fuzzers/a2dp/a2dpFuzzFunctions.h4
-rw-r--r--system/test/mock/mock_a2dp_api.cc2
-rw-r--r--system/test/mock/mock_stack_a2dp_api.cc2
7 files changed, 19 insertions, 14 deletions
diff --git a/system/bta/av/bta_av_aact.cc b/system/bta/av/bta_av_aact.cc
index b029af1e18..7d11db33d7 100644
--- a/system/bta/av/bta_av_aact.cc
+++ b/system/bta/av/bta_av_aact.cc
@@ -843,8 +843,9 @@ void bta_av_do_disc_a2dp(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data) {
"Initiate SDP discovery for peer {} : uuid_int=0x{:x} sdp_uuid=0x{:x}",
ADDRESS_TO_LOGGABLE_CSTR(p_scb->PeerAddress()), p_scb->uuid_int,
sdp_uuid);
- tA2DP_STATUS find_service_status = A2DP_FindService(
- sdp_uuid, p_scb->PeerAddress(), &db_params, bta_av_a2dp_sdp_cback);
+ tA2DP_STATUS find_service_status =
+ A2DP_FindService(sdp_uuid, p_scb->PeerAddress(), &db_params,
+ base::Bind(bta_av_a2dp_sdp_cback));
if (find_service_status != A2DP_SUCCESS) {
log::error(
"A2DP_FindService() failed for peer {} uuid_int=0x{:x} sdp_uuid=0x{:x} "
diff --git a/system/stack/a2dp/a2dp_api.cc b/system/stack/a2dp/a2dp_api.cc
index bdee82b255..32272ef999 100644
--- a/system/stack/a2dp/a2dp_api.cc
+++ b/system/stack/a2dp/a2dp_api.cc
@@ -149,8 +149,8 @@ static void a2dp_sdp_cback(UNUSED_ATTR const RawAddress& bd_addr,
a2dp_cb.find.service_uuid = 0;
osi_free_and_reset((void**)&a2dp_cb.find.p_db);
/* return info from sdp record in app callback function */
- if (a2dp_cb.find.p_cback != NULL) {
- (*a2dp_cb.find.p_cback)(found, &a2dp_svc, peer_address);
+ if (!a2dp_cb.find.p_cback.is_null()) {
+ a2dp_cb.find.p_cback.Run(found, &a2dp_svc, peer_address);
}
return;
@@ -305,10 +305,10 @@ tA2DP_STATUS A2DP_AddRecord(uint16_t service_uuid, char* p_service_name,
*****************************************************************************/
tA2DP_STATUS A2DP_FindService(uint16_t service_uuid, const RawAddress& bd_addr,
tA2DP_SDP_DB_PARAMS* p_db,
- tA2DP_FIND_CBACK* p_cback) {
+ tA2DP_FIND_CBACK p_cback) {
if ((service_uuid != UUID_SERVCLASS_AUDIO_SOURCE &&
service_uuid != UUID_SERVCLASS_AUDIO_SINK) ||
- p_db == NULL || p_cback == NULL) {
+ p_db == NULL || p_cback.is_null()) {
log::error(
"Cannot find service for peer {} UUID 0x{:04x}: invalid parameters",
ADDRESS_TO_LOGGABLE_CSTR(bd_addr), service_uuid);
@@ -348,7 +348,7 @@ tA2DP_STATUS A2DP_FindService(uint16_t service_uuid, const RawAddress& bd_addr,
if (!get_legacy_stack_sdp_api()->service.SDP_ServiceSearchAttributeRequest(
bd_addr, a2dp_cb.find.p_db, a2dp_sdp_cback)) {
a2dp_cb.find.service_uuid = 0;
- a2dp_cb.find.p_cback = NULL;
+ a2dp_cb.find.p_cback.Reset();
osi_free_and_reset((void**)&a2dp_cb.find.p_db);
log::error("Cannot find service for peer {} UUID 0x{:04x}: SDP error",
ADDRESS_TO_LOGGABLE_CSTR(bd_addr), service_uuid);
diff --git a/system/stack/a2dp/a2dp_int.h b/system/stack/a2dp/a2dp_int.h
index fd0e2bf655..05ae3be468 100644
--- a/system/stack/a2dp/a2dp_int.h
+++ b/system/stack/a2dp/a2dp_int.h
@@ -43,7 +43,7 @@
/* Control block used by A2DP_FindService(). */
typedef struct {
- tA2DP_FIND_CBACK* p_cback; /* pointer to application callback */
+ tA2DP_FIND_CBACK p_cback; /* application callback */
tSDP_DISCOVERY_DB* p_db; /* pointer to discovery database */
uint16_t service_uuid; /* service UUID of search */
} tA2DP_FIND_CB;
diff --git a/system/stack/include/a2dp_api.h b/system/stack/include/a2dp_api.h
index 7f2ab98e24..e6be61cc9d 100644
--- a/system/stack/include/a2dp_api.h
+++ b/system/stack/include/a2dp_api.h
@@ -23,6 +23,8 @@
#ifndef A2DP_API_H
#define A2DP_API_H
+#include <base/functional/callback.h>
+
#include <cstdint>
#include "stack/include/a2dp_constants.h"
@@ -83,8 +85,8 @@ typedef struct {
} tA2DP_Service;
/* This is the callback to notify the result of the SDP discovery process. */
-typedef void(tA2DP_FIND_CBACK)(bool found, tA2DP_Service* p_service,
- const RawAddress& peer_address);
+using tA2DP_FIND_CBACK = base::Callback<void(
+ bool found, tA2DP_Service* p_service, const RawAddress& peer_address)>;
/*****************************************************************************
* external function declarations
@@ -160,7 +162,7 @@ tA2DP_STATUS A2DP_AddRecord(uint16_t service_uuid, char* p_service_name,
*****************************************************************************/
tA2DP_STATUS A2DP_FindService(uint16_t service_uuid, const RawAddress& bd_addr,
tA2DP_SDP_DB_PARAMS* p_db,
- tA2DP_FIND_CBACK* p_cback);
+ tA2DP_FIND_CBACK p_cback);
/******************************************************************************
*
diff --git a/system/stack/test/fuzzers/a2dp/a2dpFuzzFunctions.h b/system/stack/test/fuzzers/a2dp/a2dpFuzzFunctions.h
index 212456e2e4..1a64517ee7 100644
--- a/system/stack/test/fuzzers/a2dp/a2dpFuzzFunctions.h
+++ b/system/stack/test/fuzzers/a2dp/a2dpFuzzFunctions.h
@@ -22,6 +22,7 @@
#include <vector>
#include "a2dp_api.h"
+#include "base/functional/bind.h"
#include "fuzzers/a2dp/a2dpFuzzHelpers.h"
#include "fuzzers/common/commonFuzzHelpers.h"
#include "fuzzers/sdp/sdpFuzzFunctions.h"
@@ -71,7 +72,8 @@ std::vector<std::function<void(FuzzedDataProvider*)>> a2dp_operations = {
const RawAddress bd_addr = generateRawAddress(fdp);
uint16_t service_uuid = fdp->ConsumeBool() ? UUID_SERVCLASS_AUDIO_SOURCE
: UUID_SERVCLASS_AUDIO_SINK;
- A2DP_FindService(service_uuid, bd_addr, &p_db, a2dp_find_callback);
+ A2DP_FindService(service_uuid, bd_addr, &p_db,
+ base::Bind(a2dp_find_callback));
},
// A2DP_GetAvdtpVersion
diff --git a/system/test/mock/mock_a2dp_api.cc b/system/test/mock/mock_a2dp_api.cc
index 0c17cbef48..7dddcc101b 100644
--- a/system/test/mock/mock_a2dp_api.cc
+++ b/system/test/mock/mock_a2dp_api.cc
@@ -31,7 +31,7 @@ tA2DP_STATUS A2DP_AddRecord(uint16_t service_uuid, char* p_service_name,
}
tA2DP_STATUS A2DP_FindService(uint16_t service_uuid, const RawAddress& bd_addr,
tA2DP_SDP_DB_PARAMS* p_db,
- tA2DP_FIND_CBACK* p_cback) {
+ tA2DP_FIND_CBACK p_cback) {
inc_func_call_count(__func__);
return A2DP_SUCCESS;
}
diff --git a/system/test/mock/mock_stack_a2dp_api.cc b/system/test/mock/mock_stack_a2dp_api.cc
index c9f1bec3cf..df0171b2e0 100644
--- a/system/test/mock/mock_stack_a2dp_api.cc
+++ b/system/test/mock/mock_stack_a2dp_api.cc
@@ -35,7 +35,7 @@ tA2DP_STATUS A2DP_AddRecord(uint16_t /* service_uuid */,
tA2DP_STATUS A2DP_FindService(uint16_t /* service_uuid */,
const RawAddress& /* bd_addr */,
tA2DP_SDP_DB_PARAMS* /* p_db */,
- tA2DP_FIND_CBACK* /* p_cback */) {
+ tA2DP_FIND_CBACK /* p_cback */) {
inc_func_call_count(__func__);
return A2DP_SUCCESS;
}