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

Commit 5145e1af authored by William Escande's avatar William Escande
Browse files

Hap: prevent setactive on unknow preset

Bug: 371636624
Fix: 371636624
Test: atest avatar:HapTest#test__set_non_existing_preset_as_active__verify_no_crash_and_no_update
Flag: Exempt feature is not shipped yet, fix has end-to-end test
Change-Id: Ifd0ca9e3c262153e4bcff4d5ff321048c8d18e61
parent 2ba6d512
Loading
Loading
Loading
Loading
+12 −5
Original line number Diff line number Diff line
@@ -1566,7 +1566,15 @@ private:

    /* Get the active preset value */
    auto* pp = value;
    STREAM_TO_UINT8(device->currently_active_preset, pp);
    uint8_t active_preset_index;
    STREAM_TO_UINT8(active_preset_index, pp);
    if (active_preset_index != 0 && device->isGattServiceValid() &&
        !device->has_presets.contains(active_preset_index)) {
      log::error("Unknown preset {}. Active preset change is discarded", active_preset_index);
      device->has_journal_.Append(HasJournalRecord(active_preset_index, false));
      return;
    }
    device->currently_active_preset = active_preset_index;

    if (device->isGattServiceValid()) {
      btif_storage_set_leaudio_has_active_preset(device->addr, device->currently_active_preset);
@@ -1579,7 +1587,9 @@ private:
    MarkDeviceValidIfInInitialDiscovery(*device);

    if (device->isGattServiceValid()) {
      if (!pending_group_operation_timeouts_.empty()) {
      if (pending_group_operation_timeouts_.empty()) {
        callbacks_->OnActivePresetSelected(device->addr, device->currently_active_preset);
      } else {
        for (auto it = pending_group_operation_timeouts_.rbegin();
             it != pending_group_operation_timeouts_.rend(); ++it) {
          auto& group_op_coordinator = it->second;
@@ -1615,9 +1625,6 @@ private:
            break;
          }
        }

      } else {
        callbacks_->OnActivePresetSelected(device->addr, device->currently_active_preset);
      }
    }
  }