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

Commit 86e1aa48 authored by Kyunglyul Hyun's avatar Kyunglyul Hyun
Browse files

vc: Revove pending volume control operations

Per VCS, each volume control operation should be
performed after the previous operation is responded.

As a result, a series of volume control operations
could be delayed.

This CL prevents it by removing pending volume control operations
when setting absolute volume, which is the only use case for now.

Tag: #feature
Bug: 238591929
Test: atest bluetooth_vc_test && manually keep pressing
hardware volume button with BLE headset.

Change-Id: I1aeea13a5db0a9d3ec6c816b74f76a7fd7d76080
parent a72c7b28
Loading
Loading
Loading
Loading
+34 −0
Original line number Diff line number Diff line
@@ -612,6 +612,37 @@ class VolumeControlImpl : public VolumeControl {
    }
  }

  void RemovePendingVolumeControlOperations(std::vector<RawAddress>& devices,
                                            int group_id) {
    for (auto op = ongoing_operations_.begin();
         op != ongoing_operations_.end();) {
      // We only remove operations that don't affect the mute field.
      if (op->IsStarted() ||
          (op->opcode_ != kControlPointOpcodeSetAbsoluteVolume &&
           op->opcode_ != kControlPointOpcodeVolumeUp &&
           op->opcode_ != kControlPointOpcodeVolumeDown)) {
        op++;
        continue;
      }
      if (group_id != bluetooth::groups::kGroupUnknown &&
          op->group_id_ == group_id) {
        op = ongoing_operations_.erase(op);
        continue;
      }
      for (auto const& addr : devices) {
        auto it = find(op->devices_.begin(), op->devices_.end(), addr);
        if (it != op->devices_.end()) {
          op->devices_.erase(it);
        }
      }
      if (op->devices_.empty()) {
        op = ongoing_operations_.erase(op);
      } else {
        op++;
      }
    }
  }

  void OnWriteControlResponse(uint16_t connection_id, tGATT_STATUS status,
                              uint16_t handle, void* data) {
    VolumeControlDevice* device =
@@ -781,6 +812,8 @@ class VolumeControlImpl : public VolumeControl {
      std::vector<RawAddress> devices = {
          std::get<RawAddress>(addr_or_group_id)};

      RemovePendingVolumeControlOperations(devices,
                                           bluetooth::groups::kGroupUnknown);
      PrepareVolumeControlOperation(devices, bluetooth::groups::kGroupUnknown,
                                    false, opcode, arg);
    } else {
@@ -809,6 +842,7 @@ class VolumeControlImpl : public VolumeControl {
        return;
      }

      RemovePendingVolumeControlOperations(devices, group_id);
      PrepareVolumeControlOperation(devices, group_id, false, opcode, arg);
    }