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

Commit a3141b5d authored by Hui Peng's avatar Hui Peng Committed by Android (Google) Code Review
Browse files

Merge "Add mocking support for now function in AttributionProcessor" into tm-dev

parents e6d1eec3 fb9a519e
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()) {