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

Commit a00318ed authored by Hui Peng's avatar Hui Peng Committed by Automerger Merge Worker
Browse files

Merge "Add mocking support for now function in AttributionProcessor" into...

Merge "Add mocking support for now function in AttributionProcessor" into tm-dev am: a3141b5d am: e2d764ed

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/modules/Bluetooth/+/20617177



Change-Id: I16876c27edb53e662f49d1ae027ebe4c2c4df4e7
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 9a91b012 e2d764ed
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -82,7 +82,20 @@ class AttributionProcessor {
  void Dump(
      std::promise<flatbuffers::Offset<ActivityAttributionData>> promise, flatbuffers::FlatBufferBuilder* fb_builder);

  using ClockType = std::chrono::time_point<std::chrono::system_clock>;
  using NowFunc = ClockType (*)();

  // by default, we use the std::chrono::system_clock::now implementation to
  // get the current timestamp
  AttributionProcessor() : now_func_(std::chrono::system_clock::now) {}
  // in other cases, we may need to use different implementation
  // e.g., for testing purposes
  AttributionProcessor(NowFunc func) : now_func_(func) {}

 private:
  // this function is added for testing support in
  // OnWakelockReleased
  NowFunc now_func_ = std::chrono::system_clock::now;
  bool wakeup_ = false;
  std::unordered_map<AddressActivityKey, BtaaAggregationEntry, AddressActivityKeyHasher> btaa_aggregator_;
  std::unordered_map<AddressActivityKey, BtaaAggregationEntry, AddressActivityKeyHasher> wakelock_duration_aggregator_;
+1 −1
Original line number Diff line number Diff line
@@ -69,7 +69,7 @@ void AttributionProcessor::OnWakelockReleased(uint32_t duration_ms) {
    return;
  }

  auto cur_time = std::chrono::system_clock::now();
  auto cur_time = now_func_();
  for (auto& it : wakelock_duration_aggregator_) {
    it.second.wakelock_duration_ms = (uint64_t)duration_ms * it.second.byte_count / total_byte_count;
    if (btaa_aggregator_.find(it.first) == btaa_aggregator_.end()) {