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

Commit 0eb8ec2e authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge changes I02cc2057,Icb879814,I468ac585,Idf93afcf,If3006967, ...

* changes:
  btaa: Add device-activity aggregation dumpsys data
  btaa: HCI ACL/SCO/ISO data packets process
  btaa: gd: Add wakeup reason dumpsys data
  btaa: attribute wakeup and wakelock duration over processed HCI buckets
  btaa: HCI LE and special event process
  btaa: HCI classic event process
  btaa: HCI command process
  btaa: handle wakelock notification
  btaa: handle wakeup notification
parents 1ccc7a6c 3e61658f
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -119,6 +119,7 @@ cc_defaults {
    target: {
        linux: {
            srcs: [
                ":BluetoothBtaaSources_linux_generic",
                ":BluetoothOsSources_linux_generic",
            ],
        },
@@ -574,6 +575,7 @@ genrule {
    ],
    cmd: "$(location flatc) -I packages/modules/Bluetooth/system/gd -b --schema -o $(genDir) $(in) ",
    srcs: [
        "btaa/activity_attribution.fbs",
        "common/init_flags.fbs",
        "dumpsys_data.fbs",
        "hci/hci_acl_manager.fbs",
@@ -581,6 +583,7 @@ genrule {
        "shim/dumpsys.fbs",
    ],
    out: [
        "activity_attribution.bfbs",
        "init_flags.bfbs",
        "dumpsys.bfbs",
        "dumpsys_data.bfbs",
@@ -596,6 +599,7 @@ genrule {
    ],
    cmd: "$(location flatc) -I packages/modules/Bluetooth/system/gd -o $(genDir) --cpp $(in) ",
    srcs: [
        "btaa/activity_attribution.fbs",
        "common/init_flags.fbs",
        "dumpsys_data.fbs",
        "hci/hci_acl_manager.fbs",
@@ -603,6 +607,7 @@ genrule {
        "shim/dumpsys.fbs",
    ],
    out: [
        "activity_attribution_generated.h",
        "dumpsys_data_generated.h",
        "dumpsys_generated.h",
        "hci_acl_manager_generated.h",
+10 −0
Original line number Diff line number Diff line
@@ -20,3 +20,13 @@ filegroup {
        "host/activity_attribution.cc",
    ],
}

filegroup {
    name: "BluetoothBtaaSources_linux_generic",
    srcs: [
        "linux_generic/attribution_processor.cc",
        "linux_generic/cmd_evt_classification.cc",
        "linux_generic/hci_processor.cc",
        "linux_generic/wakelock_processor.cc",
    ],
}
+29 −0
Original line number Diff line number Diff line
namespace bluetooth.activity_attribution;

attribute "privacy";

table WakeupEntry {
    wakeup_time:string;
    activity:string;
    address:string;
}

table DeviceActivityAggregationEntry {
    address:string;
    activity:string;
    wakeup_count:int;
    byte_count:int;
    wakelock_duration_ms:int;
    creation_time:string;
}

table ActivityAttributionData {
    title_wakeup:string;
    num_wakeup:int;
    wakeup_attribution:[WakeupEntry];
    title_activity:string;
    num_device_activity:int;
    device_activity_aggregation:[DeviceActivityAggregationEntry];
}

root_type ActivityAttributionData;
 No newline at end of file
+9 −2
Original line number Diff line number Diff line
@@ -23,14 +23,17 @@
namespace bluetooth {
namespace activity_attribution {

enum class Activity : uint8_t { UNKNOWN = 0, ADVERTISE, CONNECT, CONTROL, SCAN, HFP, VENDOR };
enum class Activity : uint8_t { UNKNOWN = 0, ACL, ADVERTISE, CONNECT, CONTROL, HFP, ISO, SCAN, VENDOR };

using CreationTime = std::chrono::time_point<std::chrono::system_clock>;

struct BtaaAggregationEntry {
  hci::Address address;
  Activity activity;
  uint16_t wakeup_count;
  uint32_t byte_count;
  uint32_t wakelock_duration;
  uint32_t wakelock_duration_ms;
  CreationTime creation_time;
};

class ActivityAttributionCallback {
@@ -50,6 +53,9 @@ 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);

  static const ModuleFactory Factory;
@@ -59,6 +65,7 @@ class ActivityAttribution : public bluetooth::Module {
  void ListDependencies(ModuleList* list) override;
  void Start() override;
  void Stop() override;
  DumpsysDataFinisher GetDumpsysData(flatbuffers::FlatBufferBuilder* builder) const override;  // Module

 private:
  struct impl;
+69 −2
Original line number Diff line number Diff line
@@ -17,12 +17,16 @@
#define LOG_TAG "btaa"

#include "btaa/activity_attribution.h"
#include "activity_attribution_generated.h"

#include <aidl/android/system/suspend/BnSuspendCallback.h>
#include <aidl/android/system/suspend/BnWakelockCallback.h>
#include <aidl/android/system/suspend/ISuspendControlService.h>
#include <android/binder_manager.h>

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

@@ -39,14 +43,18 @@ namespace activity_attribution {
const ModuleFactory ActivityAttribution::Factory = ModuleFactory([]() { return new ActivityAttribution(); });

static const std::string kBtWakelockName("hal_bluetooth_lock");
static const std::string kBtWakeupReason("hs_uart_wakeup");
static const size_t kHciAclHeaderSize = 4;

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();
  }

@@ -57,6 +65,12 @@ struct wakeup_callback : public BnSuspendCallback {
  wakeup_callback(ActivityAttribution* module) : module_(module) {}

  Status notifyWakeup(bool success, const std::vector<std::string>& wakeup_reasons) override {
    for (auto& wakeup_reason : wakeup_reasons) {
      if (wakeup_reason.find(kBtWakeupReason) != std::string::npos) {
        module_->OnWakeup();
        break;
      }
    }
    return Status::ok();
  }

@@ -89,13 +103,40 @@ struct ActivityAttribution::impl {
    }
  }

  void on_hci_packet(hal::HciPacket packet, hal::SnoopLogger::PacketType type, uint16_t length) {}
  void on_hci_packet(hal::HciPacket packet, hal::SnoopLogger::PacketType type, uint16_t length) {
    attribution_processor_.OnBtaaPackets(std::move(hci_processor_.OnHciPacket(std::move(packet), type, 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();
  }

  void register_callback(ActivityAttributionCallback* callback) {
    callback_ = callback;
  }

  void Dump(
      std::promise<flatbuffers::Offset<ActivityAttributionData>> promise, flatbuffers::FlatBufferBuilder* fb_builder) {
    attribution_processor_.Dump(std::move(promise), fb_builder);
  }

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

void ActivityAttribution::Capture(const hal::HciPacket& packet, hal::SnoopLogger::PacketType type) {
@@ -110,7 +151,7 @@ void ActivityAttribution::Capture(const hal::HciPacket& packet, hal::SnoopLogger
    case hal::SnoopLogger::PacketType::ACL:
    case hal::SnoopLogger::PacketType::SCO:
    case hal::SnoopLogger::PacketType::ISO:
      truncate_length = 0;
      truncate_length = kHciAclHeaderSize;
      break;
  }

@@ -122,6 +163,18 @@ 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);
}

void ActivityAttribution::RegisterActivityAttributionCallback(ActivityAttributionCallback* callback) {
  CallOn(pimpl_.get(), &impl::register_callback, callback);
}
@@ -140,5 +193,19 @@ void ActivityAttribution::Stop() {
  pimpl_.reset();
}

DumpsysDataFinisher ActivityAttribution::GetDumpsysData(flatbuffers::FlatBufferBuilder* fb_builder) const {
  ASSERT(fb_builder != nullptr);

  std::promise<flatbuffers::Offset<ActivityAttributionData>> promise;
  auto future = promise.get_future();
  pimpl_->Dump(std::move(promise), fb_builder);

  auto dumpsys_data = future.get();

  return [dumpsys_data](DumpsysDataBuilder* dumpsys_builder) {
    dumpsys_builder->add_activity_attribution_dumpsys_data(dumpsys_data);
  };
}

}  // namespace activity_attribution
}  // namespace bluetooth
Loading