Merge tag 'android-14.0.0_r37' into leaf-3.2
Android 14.0.0 release 37
* tag 'android-14.0.0_r37':
leaudio: Fix crash on metadata update
Change-Id: Id4a2082c5a2d3296286ec0ca22851290a34fb259
diff --git a/system/bta/le_audio/audio_hal_client/audio_hal_client.h b/system/bta/le_audio/audio_hal_client/audio_hal_client.h
index 645b4f0..d13f662 100644
--- a/system/bta/le_audio/audio_hal_client/audio_hal_client.h
+++ b/system/bta/le_audio/audio_hal_client/audio_hal_client.h
@@ -105,7 +105,8 @@
virtual ~Callbacks() = default;
virtual void OnAudioSuspend(void) = 0;
virtual void OnAudioResume(void) = 0;
- virtual void OnAudioMetadataUpdate(sink_metadata_v7 sink_metadata) = 0;
+ virtual void OnAudioMetadataUpdate(
+ const std::vector<struct record_track_metadata_v7> sink_metadata) = 0;
base::WeakPtrFactory<Callbacks> weak_factory_{this};
};
@@ -145,8 +146,9 @@
virtual void OnAudioDataReady(const std::vector<uint8_t>& data) = 0;
virtual void OnAudioSuspend(void) = 0;
virtual void OnAudioResume(void) = 0;
- virtual void OnAudioMetadataUpdate(source_metadata_v7 source_metadata,
- DsaMode dsa_mode) = 0;
+ virtual void OnAudioMetadataUpdate(
+ const std::vector<struct playback_track_metadata_v7> source_metadata,
+ DsaMode dsa_mode) = 0;
base::WeakPtrFactory<Callbacks> weak_factory_{this};
};
diff --git a/system/bta/le_audio/audio_hal_client/audio_hal_client_test.cc b/system/bta/le_audio/audio_hal_client/audio_hal_client_test.cc
index 7f0abeb..cd4914a 100644
--- a/system/bta/le_audio/audio_hal_client/audio_hal_client_test.cc
+++ b/system/bta/le_audio/audio_hal_client/audio_hal_client_test.cc
@@ -216,9 +216,11 @@
(override));
MOCK_METHOD((void), OnAudioSuspend, (), (override));
MOCK_METHOD((void), OnAudioResume, (), (override));
- MOCK_METHOD((void), OnAudioMetadataUpdate,
- (source_metadata_v7 source_metadata, DsaMode dsa_mode),
- (override));
+ MOCK_METHOD(
+ (void), OnAudioMetadataUpdate,
+ (const std::vector<struct playback_track_metadata_v7> source_metadata,
+ DsaMode dsa_mode),
+ (override));
};
class MockAudioHalClientEventReceiver
@@ -226,8 +228,10 @@
public:
MOCK_METHOD((void), OnAudioSuspend, (), (override));
MOCK_METHOD((void), OnAudioResume, (), (override));
- MOCK_METHOD((void), OnAudioMetadataUpdate, (sink_metadata_v7 sink_metadata),
- (override));
+ MOCK_METHOD(
+ (void), OnAudioMetadataUpdate,
+ (const std::vector<struct record_track_metadata_v7> sink_metadata),
+ (override));
};
class LeAudioClientAudioTest : public ::testing::Test {
diff --git a/system/bta/le_audio/audio_hal_client/audio_sink_hal_client.cc b/system/bta/le_audio/audio_hal_client/audio_sink_hal_client.cc
index f44218e..7bb8cd7 100644
--- a/system/bta/le_audio/audio_hal_client/audio_sink_hal_client.cc
+++ b/system/bta/le_audio/audio_hal_client/audio_sink_hal_client.cc
@@ -162,11 +162,15 @@
return false;
}
+ std::vector<struct record_track_metadata_v7> metadata(
+ sink_metadata.tracks, sink_metadata.tracks + sink_metadata.track_count);
+
bt_status_t status = do_in_main_thread(
FROM_HERE,
base::BindOnce(
&LeAudioSinkAudioHalClient::Callbacks::OnAudioMetadataUpdate,
- audioSinkCallbacks_->weak_factory_.GetWeakPtr(), sink_metadata));
+ audioSinkCallbacks_->weak_factory_.GetWeakPtr(),
+ std::move(metadata)));
if (status == BT_STATUS_SUCCESS) {
return true;
}
diff --git a/system/bta/le_audio/audio_hal_client/audio_source_hal_client.cc b/system/bta/le_audio/audio_hal_client/audio_source_hal_client.cc
index dedaeba..1ef50f9 100644
--- a/system/bta/le_audio/audio_hal_client/audio_source_hal_client.cc
+++ b/system/bta/le_audio/audio_hal_client/audio_source_hal_client.cc
@@ -299,12 +299,16 @@
return false;
}
+ std::vector<struct playback_track_metadata_v7> metadata(
+ source_metadata.tracks,
+ source_metadata.tracks + source_metadata.track_count);
+
bt_status_t status = do_in_main_thread(
FROM_HERE,
base::BindOnce(
&LeAudioSourceAudioHalClient::Callbacks::OnAudioMetadataUpdate,
- audioSourceCallbacks_->weak_factory_.GetWeakPtr(), source_metadata,
- dsa_mode));
+ audioSourceCallbacks_->weak_factory_.GetWeakPtr(),
+ std::move(metadata), dsa_mode));
if (status == BT_STATUS_SUCCESS) {
return true;
}
diff --git a/system/bta/le_audio/broadcaster/broadcaster.cc b/system/bta/le_audio/broadcaster/broadcaster.cc
index ec295fd..8680a17 100644
--- a/system/bta/le_audio/broadcaster/broadcaster.cc
+++ b/system/bta/le_audio/broadcaster/broadcaster.cc
@@ -1081,8 +1081,9 @@
instance->le_audio_source_hal_client_->ConfirmStreamingRequest();
}
- virtual void OnAudioMetadataUpdate(source_metadata_v7 source_metadata,
- DsaMode dsa_mode) override {
+ virtual void OnAudioMetadataUpdate(
+ const std::vector<struct playback_track_metadata_v7> source_metadata,
+ DsaMode dsa_mode) override {
LOG_INFO();
if (!instance) return;
diff --git a/system/bta/le_audio/broadcaster/broadcaster_test.cc b/system/bta/le_audio/broadcaster/broadcaster_test.cc
index 1d92c1f..8631b74 100644
--- a/system/bta/le_audio/broadcaster/broadcaster_test.cc
+++ b/system/bta/le_audio/broadcaster/broadcaster_test.cc
@@ -609,10 +609,8 @@
tracks_vec.push_back(desc_track);
}
- const source_metadata_v7_t source_metadata = {
- .track_count = tracks_vec.size(), .tracks = tracks_vec.data()};
-
- audio_receiver->OnAudioMetadataUpdate(source_metadata, DsaMode::DISABLED);
+ audio_receiver->OnAudioMetadataUpdate(std::move(tracks_vec),
+ DsaMode::DISABLED);
// Verify ccid
ASSERT_NE(ccid_list.size(), 0u);
diff --git a/system/bta/le_audio/client.cc b/system/bta/le_audio/client.cc
index 7ca3cd4..328e724 100644
--- a/system/bta/le_audio/client.cc
+++ b/system/bta/le_audio/client.cc
@@ -4570,8 +4570,9 @@
return true;
}
- void OnLocalAudioSourceMetadataUpdate(source_metadata_v7 source_metadata,
- DsaMode dsa_mode) {
+ void OnLocalAudioSourceMetadataUpdate(
+ const std::vector<struct playback_track_metadata_v7>& source_metadata,
+ DsaMode dsa_mode) {
if (active_group_id_ == bluetooth::groups::kGroupUnknown) {
LOG(WARNING) << ", cannot start streaming if no active group set";
return;
@@ -4722,7 +4723,8 @@
ToString(contexts_pair.source).c_str());
}
- void OnLocalAudioSinkMetadataUpdate(sink_metadata_v7 sink_metadata) {
+ void OnLocalAudioSinkMetadataUpdate(
+ const std::vector<record_track_metadata_v7>& sink_metadata) {
if (active_group_id_ == bluetooth::groups::kGroupUnknown) {
LOG(WARNING) << ", cannot start streaming if no active group set";
return;
@@ -5837,11 +5839,11 @@
if (instance) instance->OnLocalAudioSourceResume();
}
- void OnAudioMetadataUpdate(source_metadata_v7 source_metadata,
- DsaMode dsa_mode) override {
+ void OnAudioMetadataUpdate(
+ std::vector<struct playback_track_metadata_v7> source_metadata,
+ DsaMode dsa_mode) override {
if (instance)
- instance->OnLocalAudioSourceMetadataUpdate(std::move(source_metadata),
- dsa_mode);
+ instance->OnLocalAudioSourceMetadataUpdate(source_metadata, dsa_mode);
}
};
@@ -5854,9 +5856,9 @@
if (instance) instance->OnLocalAudioSinkResume();
}
- void OnAudioMetadataUpdate(sink_metadata_v7 sink_metadata) override {
- if (instance)
- instance->OnLocalAudioSinkMetadataUpdate(std::move(sink_metadata));
+ void OnAudioMetadataUpdate(
+ std::vector<record_track_metadata_v7> sink_metadata) override {
+ if (instance) instance->OnLocalAudioSinkMetadataUpdate(sink_metadata);
}
};
diff --git a/system/bta/le_audio/le_audio_client_test.cc b/system/bta/le_audio/le_audio_client_test.cc
index c459520..60418b3 100644
--- a/system/bta/le_audio/le_audio_client_test.cc
+++ b/system/bta/le_audio/le_audio_client_test.cc
@@ -1850,9 +1850,6 @@
tracks_vec.push_back(desc_track);
}
- const source_metadata_v7_t source_metadata = {
- .track_count = tracks_vec.size(), .tracks = tracks_vec.data()};
-
ASSERT_NE(nullptr, mock_le_audio_source_hal_client_);
/* Local Source may reconfigure once the metadata is updated */
if (reconfigure_existing_stream) {
@@ -1873,7 +1870,7 @@
}
ASSERT_NE(unicast_source_hal_cb_, nullptr);
- unicast_source_hal_cb_->OnAudioMetadataUpdate(source_metadata,
+ unicast_source_hal_cb_->OnAudioMetadataUpdate(std::move(tracks_vec),
DsaMode::DISABLED);
}
@@ -1914,11 +1911,8 @@
tracks_vec.push_back(desc_track);
}
- const sink_metadata_v7_t sink_metadata = {.track_count = tracks_vec.size(),
- .tracks = tracks_vec.data()};
-
ASSERT_NE(nullptr, unicast_sink_hal_cb_);
- unicast_sink_hal_cb_->OnAudioMetadataUpdate(sink_metadata);
+ unicast_sink_hal_cb_->OnAudioMetadataUpdate(std::move(tracks_vec));
}
void LocalAudioSourceSuspend(void) {
diff --git a/system/bta/le_audio/le_audio_utils.cc b/system/bta/le_audio/le_audio_utils.cc
index 5799459..a028249 100644
--- a/system/bta/le_audio/le_audio_utils.cc
+++ b/system/bta/le_audio/le_audio_utils.cc
@@ -163,19 +163,18 @@
}
AudioContexts GetAudioContextsFromSourceMetadata(
- const source_metadata_v7& source_metadata) {
+ const std::vector<struct playback_track_metadata_v7>& source_metadata) {
AudioContexts track_contexts;
- for (size_t i = 0; i < source_metadata.track_count; i++) {
- auto track = source_metadata.tracks[i].base;
+ for (const auto& entry : source_metadata) {
+ auto track = entry.base;
if (track.content_type == 0 && track.usage == 0) continue;
LOG_INFO("%s: usage=%s(%d), content_type=%s(%d), gain=%f, tag:%s", __func__,
usageToString(track.usage).c_str(), track.usage,
contentTypeToString(track.content_type).c_str(),
- track.content_type, track.gain, source_metadata.tracks[i].tags);
+ track.content_type, track.gain, entry.tags);
- if (isMetadataTagPresent(source_metadata.tracks[i].tags,
- "VX_AOSP_SAMPLESOUND")) {
+ if (isMetadataTagPresent(entry.tags, "VX_AOSP_SAMPLESOUND")) {
track_contexts.set(LeAudioContextType::SOUNDEFFECTS);
} else {
track_contexts.set(
@@ -186,11 +185,11 @@
}
AudioContexts GetAudioContextsFromSinkMetadata(
- const sink_metadata_v7& sink_metadata) {
+ const std::vector<struct record_track_metadata_v7>& sink_metadata) {
AudioContexts all_track_contexts;
- for (size_t i = 0; i < sink_metadata.track_count; i++) {
- auto track = sink_metadata.tracks[i].base;
+ for (const auto& entry : sink_metadata) {
+ auto track = entry.base;
if (track.source == AUDIO_SOURCE_INVALID) continue;
LeAudioContextType track_context;
diff --git a/system/bta/le_audio/le_audio_utils.h b/system/bta/le_audio/le_audio_utils.h
index c15e655..a4feacc 100644
--- a/system/bta/le_audio/le_audio_utils.h
+++ b/system/bta/le_audio/le_audio_utils.h
@@ -34,9 +34,9 @@
types::LeAudioContextType AudioContentToLeAudioContext(
audio_content_type_t content_type, audio_usage_t usage);
types::AudioContexts GetAudioContextsFromSourceMetadata(
- const source_metadata_v7& source_metadata);
+ const std::vector<struct playback_track_metadata_v7>& source_metadata);
types::AudioContexts GetAudioContextsFromSinkMetadata(
- const sink_metadata_v7& sink_metadata);
+ const std::vector<struct record_track_metadata_v7>& sink_metadata);
/* Helpers to get btle_audio_codec_config_t for Java */
bluetooth::le_audio::btle_audio_codec_index_t