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

Commit a1b88d63 authored by Michael Sun's avatar Michael Sun Committed by Mingguang Xu
Browse files

btaa: handle wakelock notification

Handle wakelock acquire and release notification from system suspend
service and record the wakelock duration upon release.

Tag: #feature
Bug: 177232907
Test: verified locally BTAA can capture and timestamp BT wakelocks
BYPASS_LONG_LINES_REASON: consist with gd format

Change-Id: I51dfdbec62b66d5a93f45d8ea2c52a16ce3beec1
parent 37806813
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -24,5 +24,6 @@ filegroup {
    name: "BluetoothBtaaSources_linux_generic",
    srcs: [
        "linux_generic/attribution_processor.cc",
        "linux_generic/wakelock_processor.cc",
    ],
}
+2 −0
Original line number Diff line number Diff line
@@ -50,6 +50,8 @@ class ActivityAttribution : public bluetooth::Module {
  ~ActivityAttribution() = default;

  void Capture(const hal::HciPacket& packet, hal::SnoopLogger::PacketType type);
  void OnWakelockAcquired();
  void OnWakelockReleased();
  void OnWakeup();
  void RegisterActivityAttributionCallback(ActivityAttributionCallback* callback);

+25 −0
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@
#include <android/binder_manager.h>

#include "btaa/attribution_processor.h"
#include "btaa/wakelock_processor.h"
#include "module.h"
#include "os/log.h"

@@ -46,9 +47,11 @@ struct wakelock_callback : public BnWakelockCallback {
  wakelock_callback(ActivityAttribution* module) : module_(module) {}

  Status notifyAcquired() override {
    module_->OnWakelockAcquired();
    return Status::ok();
  }
  Status notifyReleased() override {
    module_->OnWakelockReleased();
    return Status::ok();
  }

@@ -99,6 +102,19 @@ struct ActivityAttribution::impl {

  void on_hci_packet(hal::HciPacket packet, hal::SnoopLogger::PacketType type, uint16_t length) {}

  void on_wakelock_acquired() {
    wakelock_processor_.OnWakelockAcquired();
  }

  void on_wakelock_released() {
    uint32_t wakelock_duration_ms = 0;

    wakelock_duration_ms = wakelock_processor_.OnWakelockReleased();
    if (wakelock_duration_ms != 0) {
      attribution_processor_.OnWakelockReleased(wakelock_duration_ms);
    }
  }

  void on_wakeup() {
    attribution_processor_.OnWakeup();
  }
@@ -109,6 +125,7 @@ struct ActivityAttribution::impl {

  ActivityAttributionCallback* callback_;
  AttributionProcessor attribution_processor_;
  WakelockProcessor wakelock_processor_;
};

void ActivityAttribution::Capture(const hal::HciPacket& packet, hal::SnoopLogger::PacketType type) {
@@ -135,6 +152,14 @@ void ActivityAttribution::Capture(const hal::HciPacket& packet, hal::SnoopLogger
  CallOn(pimpl_.get(), &impl::on_hci_packet, truncate_packet, type, original_length);
}

void ActivityAttribution::OnWakelockAcquired() {
  CallOn(pimpl_.get(), &impl::on_wakelock_acquired);
}

void ActivityAttribution::OnWakelockReleased() {
  CallOn(pimpl_.get(), &impl::on_wakelock_released);
}

void ActivityAttribution::OnWakeup() {
  CallOn(pimpl_.get(), &impl::on_wakeup);
}
+3 −0
Original line number Diff line number Diff line
@@ -16,11 +16,14 @@

#pragma once

#include <cstdint>

namespace bluetooth {
namespace activity_attribution {

class AttributionProcessor {
 public:
  void OnWakelockReleased(uint32_t duration_ms);
  void OnWakeup();

 private:
+4 −0
Original line number Diff line number Diff line
@@ -23,6 +23,10 @@ namespace activity_attribution {

struct ActivityAttribution::impl {};

void ActivityAttribution::OnWakelockAcquired() {}

void ActivityAttribution::OnWakelockReleased() {}

void ActivityAttribution::OnWakeup() {}

void ActivityAttribution::RegisterActivityAttributionCallback(ActivityAttributionCallback* callback) {}
Loading