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

Commit 670d7940 authored by Cheney Ni's avatar Cheney Ni
Browse files

BluetoothAudioHAL: Have full initialization for audio hardware objects

Audio frameworks usually check whether a module has specific features by
particular function pointers, and must be null if unsupported. If a
module is not fully initialized, some pointers would be undefined, but
causes abnormal crashes when accessed by audio frameworks.  

Bug: 152379666
Test: manually
Change-Id: Id6a79b651f2acbd35bd509ba36a80adea5c13e05
Merged-In: Id6a79b651f2acbd35bd509ba36a80adea5c13e05
(cherry picked from commit 7397c51ac706d3577b277d7b5bcdc78c78fcc6ac)
parent 87b25366
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -102,7 +102,8 @@ static int adev_get_mic_mute(const struct audio_hw_device* dev, bool* state) {
static int adev_dump(const audio_hw_device_t* device, int fd) { return 0; }

static int adev_close(hw_device_t* device) {
  free(device);
  auto* bluetooth_device = reinterpret_cast<BluetoothAudioDevice*>(device);
  delete bluetooth_device;
  return 0;
}

@@ -111,7 +112,7 @@ static int adev_open(const hw_module_t* module, const char* name,
  LOG(VERBOSE) << __func__ << ": name=[" << name << "]";
  if (strcmp(name, AUDIO_HARDWARE_INTERFACE) != 0) return -EINVAL;

  auto bluetooth_audio_device = new BluetoothAudioDevice;
  auto bluetooth_audio_device = new BluetoothAudioDevice{};
  struct audio_hw_device* adev = &bluetooth_audio_device->audio_device_;
  if (!adev) return -ENOMEM;

+1 −1
Original line number Diff line number Diff line
@@ -635,7 +635,7 @@ int adev_open_output_stream(struct audio_hw_device* dev,
                            struct audio_stream_out** stream_out,
                            const char* address __unused) {
  *stream_out = nullptr;
  auto* out = new BluetoothStreamOut;
  auto* out = new BluetoothStreamOut{};
  if (!out->bluetooth_output_.SetUp(devices)) {
    delete out;
    return -EINVAL;
+2 −2
Original line number Diff line number Diff line
@@ -46,7 +46,7 @@ std::ostream& operator<<(std::ostream& os, const BluetoothStreamState& state);
struct BluetoothStreamOut {
  // Must be the first member so it can be cast from audio_stream
  // or audio_stream_out pointer
  audio_stream_out stream_out_;
  audio_stream_out stream_out_{};
  ::android::bluetooth::audio::BluetoothAudioPortOut bluetooth_output_;
  int64_t last_write_time_us_;
  // Audio PCM Configs
@@ -66,7 +66,7 @@ struct BluetoothStreamOut {
struct BluetoothAudioDevice {
  // Important: device must be first as an audio_hw_device* may be cast to
  // BluetoothAudioDevice* when the type is implicitly known.
  audio_hw_device audio_device_;
  audio_hw_device audio_device_{};
  // protect against device->output and stream_out from being inconsistent
  std::mutex mutex_;
  std::list<BluetoothStreamOut*> opened_stream_outs_ =