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

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

btaa: handle wakeup notification

Compare the wakeup reason to verify if Bluetooth was the wakeup source
and record the wakeup event for future processing.

Tag: #feature
Bug: 177228387
Test: verified locally BTAA module receives and parses Bluetooth wakeup
reasons.
BYPASS_LONG_LINES_REASON: consist with gd format

Change-Id: I301d2a372ddaebdf0818e368019cb8043c2034c5
parent 6719d9d9
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -119,6 +119,7 @@ cc_defaults {
    target: {
        linux: {
            srcs: [
                ":BluetoothBtaaSources_linux_generic",
                ":BluetoothOsSources_linux_generic",
            ],
        },
+6 −0
Original line number Diff line number Diff line
@@ -20,3 +20,9 @@ filegroup {
        "host/activity_attribution.cc",
    ],
}
filegroup {
    name: "BluetoothBtaaSources_linux_generic",
    srcs: [
        "linux_generic/attribution_processor.cc",
    ],
}
+1 −0
Original line number Diff line number Diff line
@@ -50,6 +50,7 @@ class ActivityAttribution : public bluetooth::Module {
  ~ActivityAttribution() = default;

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

  static const ModuleFactory Factory;
+17 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@
#include <aidl/android/system/suspend/ISuspendControlService.h>
#include <android/binder_manager.h>

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

@@ -39,6 +40,7 @@ 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");

struct wakelock_callback : public BnWakelockCallback {
  wakelock_callback(ActivityAttribution* module) : module_(module) {}
@@ -57,6 +59,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();
  }

@@ -91,11 +99,16 @@ struct ActivityAttribution::impl {

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

  void on_wakeup() {
    attribution_processor_.OnWakeup();
  }

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

  ActivityAttributionCallback* callback_;
  AttributionProcessor attribution_processor_;
};

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

void ActivityAttribution::OnWakeup() {
  CallOn(pimpl_.get(), &impl::on_wakeup);
}

void ActivityAttribution::RegisterActivityAttributionCallback(ActivityAttributionCallback* callback) {
  CallOn(pimpl_.get(), &impl::register_callback, callback);
}
+31 −0
Original line number Diff line number Diff line
/*
 * Copyright 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#pragma once

namespace bluetooth {
namespace activity_attribution {

class AttributionProcessor {
 public:
  void OnWakeup();

 private:
  bool wakeup_ = false;
};

}  // namespace activity_attribution
}  // namespace bluetooth
Loading